From c2923ca934d28338e263a711cab3372bfd6812ce Mon Sep 17 00:00:00 2001 From: Liong Sauw Ming Date: Tue, 23 Aug 2016 09:13:28 +0000 Subject: Fixed #1956: Support for setting audio input source capability in Android JNI audio device git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5426 74dad513-b988-da41-8d7b-12977e46ad98 --- pjmedia/include/pjmedia/audiodev.h | 39 ++++++++++++++++++-------- pjmedia/src/pjmedia-audiodev/android_jni_dev.c | 10 ++++++- 2 files changed, 37 insertions(+), 12 deletions(-) (limited to 'pjmedia') diff --git a/pjmedia/include/pjmedia/audiodev.h b/pjmedia/include/pjmedia/audiodev.h index 473c9fd1..b0779291 100644 --- a/pjmedia/include/pjmedia/audiodev.h +++ b/pjmedia/include/pjmedia/audiodev.h @@ -181,10 +181,11 @@ typedef enum pjmedia_aud_dev_cap PJMEDIA_AUD_DEV_CAP_OUTPUT_SIGNAL_METER = 64, /** - * Support for audio input routing. The value of this capability is an - * integer containing #pjmedia_aud_dev_route enumeration. + * Support for audio input routing/source. The value of this capability + * is an integer containing #pjmedia_aud_dev_route enumeration. */ PJMEDIA_AUD_DEV_CAP_INPUT_ROUTE = 128, + PJMEDIA_AUD_DEV_CAP_INPUT_SOURCE = 128, /** * Support for audio output routing (e.g. loudspeaker vs earpiece). The @@ -236,14 +237,15 @@ typedef enum pjmedia_aud_dev_cap /** - * This enumeration describes audio routing setting. + * This enumeration describes audio routing/source setting. */ typedef enum pjmedia_aud_dev_route { /** - * Default route, it is the default audio route of the audio framework - * backend, as in opening audio device without specifying any route - * setting or with specifying neutral route setting. + * Default route/source, it is the default audio route/source of + * the audio framework backend, as in opening audio device without + * specifying any route/source setting or with specifying neutral + * route/source setting. */ PJMEDIA_AUD_DEV_ROUTE_DEFAULT = 0, @@ -254,7 +256,21 @@ typedef enum pjmedia_aud_dev_route PJMEDIA_AUD_DEV_ROUTE_EARPIECE = 2, /** Route to paired Bluetooth device */ - PJMEDIA_AUD_DEV_ROUTE_BLUETOOTH = 4 + PJMEDIA_AUD_DEV_ROUTE_BLUETOOTH = 4, + + /** + * Custom audio route/source, specific to each audio device + * backend. + * + * For Android JNI audio device, the default is + * VOICE_COMMUNICATION (7). To change it to another value, set + * the input source capability of pjmedia_aud_param accordingly. + * For example: + * pjmedia_aud_param_set_cap(¶m, PJMEDIA_AUD_DEV_CAP_INPUT_SOURCE, + * // 4 is VOICE_CALL + * PJMEDIA_AUD_DEV_ROUTE_CUSTOM | 4); + */ + PJMEDIA_AUD_DEV_ROUTE_CUSTOM = 128 } pjmedia_aud_dev_route; @@ -299,9 +315,9 @@ typedef struct pjmedia_aud_dev_info unsigned caps; /** - * Supported audio device routes, as bitmask combination of + * Supported audio device routes/sources, as bitmask combination of * #pjmedia_aud_dev_route. The value may be zero if the device - * does not support audio routing. + * does not support changing audio routes/sources. */ unsigned routes; @@ -435,8 +451,9 @@ typedef struct pjmedia_aud_param unsigned output_vol; /** - * Set the audio input route. This setting is optional, and will only be - * used if PJMEDIA_AUD_DEV_CAP_INPUT_ROUTE is set in the flags. + * Set the audio input route/source. This setting is optional, and + * will only be used if PJMEDIA_AUD_DEV_CAP_INPUT_ROUTE/ + * PJMEDIA_AUD_DEV_CAP_INPUT_SOURCE is set in the flags. */ pjmedia_aud_dev_route input_route; diff --git a/pjmedia/src/pjmedia-audiodev/android_jni_dev.c b/pjmedia/src/pjmedia-audiodev/android_jni_dev.c index 610cd9ed..b6b47ad0 100644 --- a/pjmedia/src/pjmedia-audiodev/android_jni_dev.c +++ b/pjmedia/src/pjmedia-audiodev/android_jni_dev.c @@ -483,9 +483,11 @@ static pj_status_t android_get_dev_info(pjmedia_aud_dev_factory *f, pj_ansi_strcpy(info->name, "Android JNI"); info->default_samples_per_sec = 8000; - info->caps = PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING; + info->caps = PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING | + PJMEDIA_AUD_DEV_CAP_INPUT_SOURCE; info->input_count = 1; info->output_count = 1; + info->routes = PJMEDIA_AUD_DEV_ROUTE_CUSTOM; return PJ_SUCCESS; } @@ -666,6 +668,12 @@ static pj_status_t android_create_stream(pjmedia_aud_dev_factory *f, jobject record_obj; int mic_source = 0; /* DEFAULT: default audio source */ + if ((param->flags & PJMEDIA_AUD_DEV_CAP_INPUT_SOURCE) && + (param->input_route & PJMEDIA_AUD_DEV_ROUTE_CUSTOM)) + { + mic_source = param->input_route & ~PJMEDIA_AUD_DEV_ROUTE_CUSTOM; + } + /* Get pointer to the constructor */ constructor_method = (*jni_env)->GetMethodID(jni_env, stream->record_class, -- cgit v1.2.3