Skip to content

Commit 2ba92c7

Browse files
committed
do not merge bug 3370834 Cherrypick from master
Cherripick from master CL 79833, 79417, 78864, 80332, 87500 Add new audio mode and recording source for audio communications other than telelphony. The audio mode MODE_IN_CALL signals the system the device a phone call is currently underway. There was no way for audio video chat or VoIP applications to signal a call is underway, but not using the telephony resources. This change introduces a new mode to address this. Changes in other parts of the system (java and native) are required to take this new mode into account. The generic AudioPolicyManager is updated to not use its phone state variable directly, but to use two new convenience methods, isInCall() and isStateInCall(int) instead. Add a recording source used to designate a recording stream for voice communications such as VoIP. Update the platform-independent audio policy manager to pass the nature of the audio recording source to the audio policy client interface through the AudioPolicyClientInterface::setParameters() method. SIP calls should set the audio mode to MODE_IN_COMMUNICATION, Audio mode MODE_IN_CALL is reserved for telephony. SIP: Enable built-in echo canceler if available. 1. Always initialize AudioRecord with VOICE_COMMUNICATION. 2. If echo canceler is available, disable our echo suppressor. Note that this CL is intentionally not correcting the getAudioSourceMax() return value in MediaRecorder.java as the new source is hidden here. Change-Id: Ie68cd03c50553101aa2ad838fe9459b2cf151bc8
1 parent 138757d commit 2ba92c7

File tree

14 files changed

+87
-39
lines changed

14 files changed

+87
-39
lines changed

include/media/AudioSystem.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ class AudioSystem
156156
MODE_NORMAL = 0,
157157
MODE_RINGTONE,
158158
MODE_IN_CALL,
159+
MODE_IN_COMMUNICATION,
159160
NUM_MODES // not a valid entry, denotes end-of-list
160161
};
161162

@@ -466,19 +467,22 @@ class AudioParameter {
466467
AudioParameter(const String8& keyValuePairs);
467468
virtual ~AudioParameter();
468469

469-
// reserved parameter keys for changeing standard parameters with setParameters() function.
470+
// reserved parameter keys for changing standard parameters with setParameters() function.
470471
// Using these keys is mandatory for AudioFlinger to properly monitor audio output/input
471472
// configuration changes and act accordingly.
472473
// keyRouting: to change audio routing, value is an int in AudioSystem::audio_devices
473474
// keySamplingRate: to change sampling rate routing, value is an int
474475
// keyFormat: to change audio format, value is an int in AudioSystem::audio_format
475476
// keyChannels: to change audio channel configuration, value is an int in AudioSystem::audio_channels
476477
// keyFrameCount: to change audio output frame count, value is an int
478+
// keyInputSource: to change audio input source, value is an int in audio_source
479+
// (defined in media/mediarecorder.h)
477480
static const char *keyRouting;
478481
static const char *keySamplingRate;
479482
static const char *keyFormat;
480483
static const char *keyChannels;
481484
static const char *keyFrameCount;
485+
static const char *keyInputSource;
482486

483487
String8 toString();
484488

include/media/EffectApi.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,9 +602,9 @@ enum audio_device_e {
602602

603603
// Audio mode
604604
enum audio_mode_e {
605-
AUDIO_MODE_NORMAL, // phone idle
606-
AUDIO_MODE_RINGTONE, // phone ringing
607-
AUDIO_MODE_IN_CALL // phone call connected
605+
AUDIO_MODE_NORMAL, // device idle
606+
AUDIO_MODE_RINGTONE, // device ringing
607+
AUDIO_MODE_IN_CALL // audio call connected (VoIP or telephony)
608608
};
609609

610610
// Values for "accessMode" field of buffer_config_t:

include/media/mediarecorder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ enum audio_source {
4444
AUDIO_SOURCE_VOICE_CALL = 4,
4545
AUDIO_SOURCE_CAMCORDER = 5,
4646
AUDIO_SOURCE_VOICE_RECOGNITION = 6,
47-
AUDIO_SOURCE_MAX = AUDIO_SOURCE_VOICE_RECOGNITION,
47+
AUDIO_SOURCE_VOICE_COMMUNICATION = 7,
48+
AUDIO_SOURCE_MAX = AUDIO_SOURCE_VOICE_COMMUNICATION,
4849

4950
AUDIO_SOURCE_LIST_END // must be last - used to validate audio source type
5051
};

media/java/android/media/AudioManager.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,9 +966,14 @@ public int getMode() {
966966
*/
967967
public static final int MODE_RINGTONE = AudioSystem.MODE_RINGTONE;
968968
/**
969-
* In call audio mode. A call is established.
969+
* In call audio mode. A telephony call is established.
970970
*/
971971
public static final int MODE_IN_CALL = AudioSystem.MODE_IN_CALL;
972+
/**
973+
* @hide
974+
* In communication audio mode. An audio/video chat or VoIP call is established.
975+
*/
976+
public static final int MODE_IN_COMMUNICATION = AudioSystem.MODE_IN_COMMUNICATION;
972977

973978
/* Routing bits for setRouting/getRouting API */
974979
/**

media/java/android/media/AudioRecord.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ private void audioParamCheck(int audioSource, int sampleRateInHz,
252252
//--------------
253253
// audio source
254254
if ( (audioSource < MediaRecorder.AudioSource.DEFAULT) ||
255-
(audioSource > MediaRecorder.getAudioSourceMax()) ) {
255+
(audioSource > MediaRecorder.AudioSource.VOICE_COMMUNICATION) ) {
256+
//(audioSource > MediaRecorder.getAudioSourceMax()) ) {
256257
throw (new IllegalArgumentException("Invalid audio source."));
257258
} else {
258259
mRecordSource = audioSource;

media/java/android/media/AudioService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ public void setMode(int mode, IBinder cb) {
708708
return;
709709
}
710710

711-
if (mode < AudioSystem.MODE_CURRENT || mode > AudioSystem.MODE_IN_CALL) {
711+
if (mode < AudioSystem.MODE_CURRENT || mode >= AudioSystem.NUM_MODES) {
712712
return;
713713
}
714714

@@ -2259,6 +2259,7 @@ public void onReceive(Context context, Intent intent) {
22592259
// add modify the phone app to take advantage of the new API
22602260
synchronized(mRingingLock) {
22612261
if (mIsRinging || (getMode() == AudioSystem.MODE_IN_CALL) ||
2262+
(getMode() == AudioSystem.MODE_IN_COMMUNICATION) ||
22622263
(getMode() == AudioSystem.MODE_RINGTONE) ) {
22632264
return;
22642265
}

media/java/android/media/AudioSystem.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ public static int getMode() {
106106
public static final int MODE_NORMAL = 0;
107107
public static final int MODE_RINGTONE = 1;
108108
public static final int MODE_IN_CALL = 2;
109-
public static final int NUM_MODES = 3;
109+
public static final int MODE_IN_COMMUNICATION = 3;
110+
public static final int NUM_MODES = 4;
110111

111112

112113
/* Routing bits for setRouting/getRouting API */

media/java/android/media/MediaRecorder.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ private AudioSource() {}
145145
/** Microphone audio source tuned for voice recognition if available, behaves like
146146
* {@link #DEFAULT} otherwise. */
147147
public static final int VOICE_RECOGNITION = 6;
148+
149+
/**
150+
* @hide
151+
* Microphone audio source tuned for voice communications such as VoIP. It
152+
* will for instance take advantage of echo cancellation or automatic gain control
153+
* if available. It otherwise behaves like {@link #DEFAULT} if no voice processing
154+
* is available.
155+
*/
156+
public static final int VOICE_COMMUNICATION = 7;
148157
}
149158

150159
/**

media/libmedia/AudioSystem.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,7 @@ const char *AudioParameter::keySamplingRate = "sampling_rate";
835835
const char *AudioParameter::keyFormat = "format";
836836
const char *AudioParameter::keyChannels = "channels";
837837
const char *AudioParameter::keyFrameCount = "frame_count";
838+
const char *AudioParameter::keyInputSource = "input_source";
838839

839840
AudioParameter::AudioParameter(const String8& keyValuePairs)
840841
{

services/audioflinger/AudioFlinger.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5810,7 +5810,8 @@ uint32_t AudioFlinger::EffectModule::deviceAudioSystemToEffectApi(uint32_t devic
58105810
const uint32_t AudioFlinger::EffectModule::sModeConvTable[] = {
58115811
AUDIO_MODE_NORMAL, // AudioSystem::MODE_NORMAL
58125812
AUDIO_MODE_RINGTONE, // AudioSystem::MODE_RINGTONE
5813-
AUDIO_MODE_IN_CALL // AudioSystem::MODE_IN_CALL
5813+
AUDIO_MODE_IN_CALL, // AudioSystem::MODE_IN_CALL
5814+
AUDIO_MODE_IN_CALL // AudioSystem::MODE_IN_COMMUNICATION, same conversion as for MODE_IN_CALL
58145815
};
58155816

58165817
int AudioFlinger::EffectModule::modeAudioSystemToEffectApi(uint32_t mode)

0 commit comments

Comments
 (0)