Commit 506e600c authored by François Grisez's avatar François Grisez
Browse files

Add functions to the API to set/get volume gain of the mouth and the speaker

parent 9ad7e893
......@@ -546,18 +546,68 @@ static MS2_INLINE void audio_stream_enable_adaptive_jittcomp(AudioStream *stream
media_stream_enable_adaptive_jittcomp(&stream->ms, enabled);
}
/**
* @deprecated Use audio_stream_set_rtp_output_gain_db() intead.
*/
MS2_PUBLIC void audio_stream_set_mic_gain_db(AudioStream *stream, float gain_db);
/**
* deprecated
* */
* @deprecated Use audio_stream_set_rtp_output_gain_db() intead.
*/
MS2_PUBLIC void audio_stream_set_mic_gain(AudioStream *stream, float gain);
/**
* @brief Set value of applied gain before sending on network.
*
* @param stream The audio stream.
* @param gain_db Gain in dB
*/
MS2_PUBLIC void audio_stream_set_rtp_output_gain_db(AudioStream *stream, float gain_db);
/**
* enable/disable rtp stream
* */
MS2_PUBLIC void audio_stream_mute_rtp(AudioStream *stream, bool_t val);
/**
* @brief Set microphone volume gain.
* If the sound backend supports it, the set volume gain will be synchronized
* with the host system mixer.
*
* @param stream The audio stream.
* @param gain Percentage of the max supported volume gain. Valid values are in [0.0 : 1.0].
*/
MS2_PUBLIC void audio_stream_set_sound_card_input_gain(AudioStream *stream, double gain);
/**
* @brief Get microphone volume gain.
*
* @param stream The audio stream.
* @return double Volume gain in percentage of the max suppored gain.
* Valid returned values are in [0.0 : 1.0]. A negative value is returned in case of failure.
*/
MS2_PUBLIC double audio_stream_get_sound_card_input_gain(const AudioStream *stream);
/**
* @brief Set speaker volume gain.
* If the sound backend supports it, the set volume gain will be synchronized
* with the host system mixer.
*
* @param stream The audio stream.
* @param gain Percentage of the max supported volume gain. Valid values are in [0.0 : 1.0].
*/
MS2_PUBLIC void audio_stream_set_sound_card_output_gain(AudioStream *stream, double volume);
/**
* @brief Get speaker volume gain.
*
* @param stream The audio stream.
* @return Volume gain in percentage of the max suppored gain.
* Valid returned values are in [0.0 : 1.0]. A negative value is returned in case of failure.
*/
MS2_PUBLIC double audio_stream_get_sound_card_output_gain(const AudioStream *stream);
/**
* enable noise gate, must be done before start()
* */
......
......@@ -271,8 +271,18 @@ typedef enum _MSRecorderState MSRecorderState;
/** Interface definitions for audio capture */
/* Start numbering from the end for hacks */
#define MS_AUDIO_CAPTURE_SET_VOLUME_GAIN \
MS_FILTER_METHOD(MSFilterAudioCaptureInterface, 0, double)
#define MS_AUDIO_CAPTURE_GET_VOLUME_GAIN \
MS_FILTER_METHOD(MSFilterAudioCaptureInterface, 1, double)
#define MS_AUDIO_CAPTURE_FORCE_SPEAKER_STATE \
MS_FILTER_METHOD(MSFilterAudioCaptureInterface, 255, bool_t)
/** Interface definitions for audio playback */
#define MS_AUDIO_PLAYBACK_SET_VOLUME_GAIN \
MS_FILTER_METHOD(MSFilterAudioPlaybackInterface, 0, double)
#define MS_AUDIO_PLAYBACK_GET_VOLUME_GAIN \
MS_FILTER_METHOD(MSFilterAudioPlaybackInterface, 1, double)
/** Interface definitions for audio encoder */
#define MS_AUDIO_ENCODER_SET_PTIME \
......
......@@ -1410,19 +1410,7 @@ void audio_stream_enable_noise_gate(AudioStream *stream, bool_t val){
}
void audio_stream_set_mic_gain_db(AudioStream *stream, float gain_db) {
float gain = gain_db;
#ifdef ANDROID
SoundDeviceDescription *device = sound_device_description_get();
if (device && device->hacks) {
gain += device->hacks->mic_gain;
ms_message("Applying %f db to mic gain based on parameter and audio hack value in device table", gain);
}
#endif
if (stream->volsend){
ms_filter_call_method(stream->volsend, MS_VOLUME_SET_DB_GAIN, &gain);
} else ms_warning("Could not apply gain: gain control wasn't activated. "
"Use audio_stream_enable_gain_control() before starting the stream.");
audio_stream_set_rtp_output_gain_db(stream, gain_db);
}
void audio_stream_set_mic_gain(AudioStream *stream, float gain){
......@@ -1432,6 +1420,58 @@ void audio_stream_set_mic_gain(AudioStream *stream, float gain){
"Use audio_stream_enable_gain_control() before starting the stream.");
}
void audio_stream_set_sound_card_input_gain(AudioStream *stream, double volume) {
if (stream->soundread) {
if(ms_filter_implements_interface(stream->soundread, MSFilterAudioCaptureInterface)) {
ms_filter_call_method(stream->soundread, MS_AUDIO_CAPTURE_SET_VOLUME_GAIN, &volume);
}
} else {
ms_error("Cannot set input volume: no input filter");
}
}
double audio_stream_get_sound_card_input_gain(const AudioStream *stream) {
double volume;
if(stream->soundread == NULL) {
ms_error("Cannot get input volume: no input filter");
return -1.0;
}
if(!ms_filter_implements_interface(stream->soundread, MSFilterAudioCaptureInterface)) {
return -1.0;
}
if(ms_filter_call_method(stream->soundread, MS_AUDIO_CAPTURE_GET_VOLUME_GAIN, &volume) < 0) {
volume = -1.0;
}
return volume;
}
void audio_stream_set_sound_card_output_gain(AudioStream *stream, double volume) {
if (stream->soundwrite) {
if(ms_filter_implements_interface(stream->soundwrite, MSFilterAudioPlaybackInterface)) {
ms_filter_call_method(stream->soundwrite, MS_AUDIO_PLAYBACK_SET_VOLUME_GAIN, &volume);
}
} else {
ms_error("Cannot set output volume: no output filter");
}
}
double audio_stream_get_sound_card_output_gain(const AudioStream *stream) {
double volume;
if(stream->soundwrite == NULL) {
ms_error("Cannot get output volume: no output filter");
return -1.0;
}
if(!ms_filter_implements_interface(stream->soundwrite, MSFilterAudioCaptureInterface)) {
return -1.0;
}
if(ms_filter_call_method(stream->soundwrite, MS_AUDIO_PLAYBACK_GET_VOLUME_GAIN, &volume) < 0) {
volume = -1.0;
}
return volume;
}
void audio_stream_enable_equalizer(AudioStream *stream, bool_t enabled){
stream->eq_active=enabled;
if (stream->equalizer){
......@@ -1554,6 +1594,22 @@ int audio_stream_send_dtmf(AudioStream *stream, char dtmf)
return 0;
}
void audio_stream_set_rtp_output_gain_db(AudioStream *stream, float gain_db) {
float gain = gain_db;
#ifdef ANDROID
SoundDeviceDescription *device = sound_device_description_get();
if (device && device->hacks) {
gain += device->hacks->mic_gain;
ms_message("Applying %f db to mic gain based on parameter and audio hack value in device table", gain);
}
#endif
if (stream->volsend){
ms_filter_call_method(stream->volsend, MS_VOLUME_SET_DB_GAIN, &gain);
} else ms_warning("Could not apply gain: gain control wasn't activated. "
"Use audio_stream_enable_gain_control() before starting the stream.");
}
void audio_stream_mute_rtp(AudioStream *stream, bool_t val)
{
if (stream->ms.rtpsend){
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment