Fix issue 2378022: AudioService should direct volume control to STREAM_VOICE_CALL stream when STREAM_VOICE_CALL stream is active.
Modified AudioService.getActiveStreamType() so that STREAM_VOICE_CALL is selected when a track using this stream type is playing. Chanded isMusicActive() for a more generic isStreamActive(stream) method in AudioSystem, IAudioFlinger and AudioFlinger.
This commit is contained in:
@@ -64,10 +64,10 @@ android_media_AudioSystem_isMicrophoneMuted(JNIEnv *env, jobject thiz)
|
||||
}
|
||||
|
||||
static jboolean
|
||||
android_media_AudioSystem_isMusicActive(JNIEnv *env, jobject thiz)
|
||||
android_media_AudioSystem_isStreamActive(JNIEnv *env, jobject thiz, jint stream)
|
||||
{
|
||||
bool state = false;
|
||||
AudioSystem::isMusicActive(&state);
|
||||
AudioSystem::isStreamActive(stream, &state);
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ static JNINativeMethod gMethods[] = {
|
||||
{"getParameters", "(Ljava/lang/String;)Ljava/lang/String;", (void *)android_media_AudioSystem_getParameters},
|
||||
{"muteMicrophone", "(Z)I", (void *)android_media_AudioSystem_muteMicrophone},
|
||||
{"isMicrophoneMuted", "()Z", (void *)android_media_AudioSystem_isMicrophoneMuted},
|
||||
{"isMusicActive", "()Z", (void *)android_media_AudioSystem_isMusicActive},
|
||||
{"isStreamActive", "(I)Z", (void *)android_media_AudioSystem_isStreamActive},
|
||||
{"setDeviceConnectionState", "(IILjava/lang/String;)I", (void *)android_media_AudioSystem_setDeviceConnectionState},
|
||||
{"getDeviceConnectionState", "(ILjava/lang/String;)I", (void *)android_media_AudioSystem_getDeviceConnectionState},
|
||||
{"setPhoneState", "(I)I", (void *)android_media_AudioSystem_setPhoneState},
|
||||
|
||||
@@ -194,8 +194,8 @@ public:
|
||||
// set audio mode in audio hardware (see AudioSystem::audio_mode)
|
||||
static status_t setMode(int mode);
|
||||
|
||||
// returns true if tracks are active on AudioSystem::MUSIC stream
|
||||
static status_t isMusicActive(bool *state);
|
||||
// returns true in *state if tracks are active on the specified stream
|
||||
static status_t isStreamActive(int stream, bool *state);
|
||||
|
||||
// set/get audio hardware parameters. The function accepts a list of parameters
|
||||
// key value pairs in the form: key1=value1;key2=value2;...
|
||||
|
||||
@@ -97,8 +97,8 @@ public:
|
||||
virtual status_t setMicMute(bool state) = 0;
|
||||
virtual bool getMicMute() const = 0;
|
||||
|
||||
// is a music stream active?
|
||||
virtual bool isMusicActive() const = 0;
|
||||
// is any track active on this stream?
|
||||
virtual bool isStreamActive(int stream) const = 0;
|
||||
|
||||
virtual status_t setParameters(int ioHandle, const String8& keyValuePairs) = 0;
|
||||
virtual String8 getParameters(int ioHandle, const String8& keys) = 0;
|
||||
|
||||
@@ -544,11 +544,11 @@ bool AudioFlinger::streamMute(int stream) const
|
||||
return mStreamTypes[stream].mute;
|
||||
}
|
||||
|
||||
bool AudioFlinger::isMusicActive() const
|
||||
bool AudioFlinger::isStreamActive(int stream) const
|
||||
{
|
||||
Mutex::Autolock _l(mLock);
|
||||
for (uint32_t i = 0; i < mPlaybackThreads.size(); i++) {
|
||||
if (mPlaybackThreads.valueAt(i)->isMusicActive()) {
|
||||
if (mPlaybackThreads.valueAt(i)->isStreamActive(stream)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1071,7 +1071,7 @@ bool AudioFlinger::PlaybackThread::streamMute(int stream) const
|
||||
return mStreamTypes[stream].mute;
|
||||
}
|
||||
|
||||
bool AudioFlinger::PlaybackThread::isMusicActive() const
|
||||
bool AudioFlinger::PlaybackThread::isStreamActive(int stream) const
|
||||
{
|
||||
Mutex::Autolock _l(mLock);
|
||||
size_t count = mActiveTracks.size();
|
||||
@@ -1079,7 +1079,7 @@ bool AudioFlinger::PlaybackThread::isMusicActive() const
|
||||
sp<Track> t = mActiveTracks[i].promote();
|
||||
if (t == 0) continue;
|
||||
Track* const track = t.get();
|
||||
if (t->type() == AudioSystem::MUSIC)
|
||||
if (t->type() == stream)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -100,7 +100,7 @@ public:
|
||||
virtual status_t setMicMute(bool state);
|
||||
virtual bool getMicMute() const;
|
||||
|
||||
virtual bool isMusicActive() const;
|
||||
virtual bool isStreamActive(int stream) const;
|
||||
|
||||
virtual status_t setParameters(int ioHandle, const String8& keyValuePairs);
|
||||
virtual String8 getParameters(int ioHandle, const String8& keys);
|
||||
@@ -506,7 +506,7 @@ private:
|
||||
virtual float streamVolume(int stream) const;
|
||||
virtual bool streamMute(int stream) const;
|
||||
|
||||
bool isMusicActive() const;
|
||||
bool isStreamActive(int stream) const;
|
||||
|
||||
sp<Track> createTrack_l(
|
||||
const sp<AudioFlinger::Client>& client,
|
||||
|
||||
@@ -924,7 +924,7 @@ public class AudioManager {
|
||||
* @return true if any music tracks are active.
|
||||
*/
|
||||
public boolean isMusicActive() {
|
||||
return AudioSystem.isMusicActive();
|
||||
return AudioSystem.isStreamActive(STREAM_MUSIC);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -957,10 +957,10 @@ public class AudioService extends IAudioService.Stub {
|
||||
if (AudioSystem.getForceUse(AudioSystem.FOR_COMMUNICATION) == AudioSystem.FORCE_BT_SCO) {
|
||||
// Log.v(TAG, "getActiveStreamType: Forcing STREAM_BLUETOOTH_SCO...");
|
||||
return AudioSystem.STREAM_BLUETOOTH_SCO;
|
||||
} else if (isOffhook) {
|
||||
} else if (isOffhook || AudioSystem.isStreamActive(AudioSystem.STREAM_VOICE_CALL)) {
|
||||
// Log.v(TAG, "getActiveStreamType: Forcing STREAM_VOICE_CALL...");
|
||||
return AudioSystem.STREAM_VOICE_CALL;
|
||||
} else if (AudioSystem.isMusicActive()) {
|
||||
} else if (AudioSystem.isStreamActive(AudioSystem.STREAM_MUSIC)) {
|
||||
// Log.v(TAG, "getActiveStreamType: Forcing STREAM_MUSIC...");
|
||||
return AudioSystem.STREAM_MUSIC;
|
||||
} else if (suggestedStreamType == AudioManager.USE_DEFAULT_STREAM_TYPE) {
|
||||
@@ -1366,7 +1366,7 @@ public class AudioService extends IAudioService.Stub {
|
||||
// Force creation of new IAudioflinger interface
|
||||
if (!mMediaServerOk) {
|
||||
Log.e(TAG, "Media server died.");
|
||||
AudioSystem.isMusicActive();
|
||||
AudioSystem.isStreamActive(AudioSystem.STREAM_MUSIC);
|
||||
sendMsg(mAudioHandler, MSG_MEDIA_SERVER_DIED, SHARED_MSG, SENDMSG_NOOP, 0, 0,
|
||||
null, 500);
|
||||
}
|
||||
|
||||
@@ -153,11 +153,11 @@ public class AudioSystem
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks whether any music is active.
|
||||
* Checks whether the specified stream type is active.
|
||||
*
|
||||
* return true if any music tracks are active.
|
||||
* return true if any track playing on this stream is active.
|
||||
*/
|
||||
public static native boolean isMusicActive();
|
||||
public static native boolean isStreamActive(int stream);
|
||||
|
||||
/*
|
||||
* Sets a group generic audio configuration parameters. The use of these parameters
|
||||
|
||||
@@ -170,10 +170,10 @@ status_t AudioSystem::setMode(int mode)
|
||||
}
|
||||
|
||||
|
||||
status_t AudioSystem::isMusicActive(bool* state) {
|
||||
status_t AudioSystem::isStreamActive(int stream, bool* state) {
|
||||
const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
|
||||
if (af == 0) return PERMISSION_DENIED;
|
||||
*state = af->isMusicActive();
|
||||
*state = af->isStreamActive(stream);
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ enum {
|
||||
SET_MODE,
|
||||
SET_MIC_MUTE,
|
||||
GET_MIC_MUTE,
|
||||
IS_MUSIC_ACTIVE,
|
||||
IS_STREAM_ACTIVE,
|
||||
SET_PARAMETERS,
|
||||
GET_PARAMETERS,
|
||||
REGISTER_CLIENT,
|
||||
@@ -286,11 +286,12 @@ public:
|
||||
return reply.readInt32();
|
||||
}
|
||||
|
||||
virtual bool isMusicActive() const
|
||||
virtual bool isStreamActive(int stream) const
|
||||
{
|
||||
Parcel data, reply;
|
||||
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
|
||||
remote()->transact(IS_MUSIC_ACTIVE, data, &reply);
|
||||
data.writeInt32(stream);
|
||||
remote()->transact(IS_STREAM_ACTIVE, data, &reply);
|
||||
return reply.readInt32();
|
||||
}
|
||||
|
||||
@@ -599,9 +600,10 @@ status_t BnAudioFlinger::onTransact(
|
||||
reply->writeInt32( getMicMute() );
|
||||
return NO_ERROR;
|
||||
} break;
|
||||
case IS_MUSIC_ACTIVE: {
|
||||
case IS_STREAM_ACTIVE: {
|
||||
CHECK_INTERFACE(IAudioFlinger, data, reply);
|
||||
reply->writeInt32( isMusicActive() );
|
||||
int stream = data.readInt32();
|
||||
reply->writeInt32( isStreamActive(stream) );
|
||||
return NO_ERROR;
|
||||
} break;
|
||||
case SET_PARAMETERS: {
|
||||
|
||||
Reference in New Issue
Block a user