Set the piid for the MediaPlayer AudioTrack
This enables the mapping between piid and portId in the AudioService.
The mapping is used for the playback mute notifications.
Test: dumpsys audio & atest android.media.audio.cts.AudioPlaybackConfigurationTest
Bug: 235521198
Change-Id: I60f0b154f7464fe6012e546c0a30e65220482181
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp
index 2a50fc2..ceea2f4 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp
@@ -26,6 +26,7 @@
#include "NuPlayer.h"
#include "NuPlayerSource.h"
+#include <audiomanager/AudioManager.h>
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/ALooper.h>
#include <media/stagefright/foundation/AUtils.h>
@@ -85,6 +86,7 @@
mMediaClock(new MediaClock),
mPlayer(new NuPlayer(pid, mMediaClock)),
mPlayerFlags(0),
+ mCachedPlayerIId(PLAYER_PIID_INVALID),
mMetricsItem(NULL),
mClientUid(-1),
mAtEOS(false),
@@ -804,6 +806,16 @@
return mPlayer->getSelectedTrack(type, reply);
}
+ case INVOKE_ID_SET_PLAYER_IID:
+ {
+ Mutex::Autolock autoLock(mAudioSinkLock);
+ mCachedPlayerIId = request.readInt32();
+ if (mAudioSink != nullptr) {
+ mAudioSink->setPlayerIId(mCachedPlayerIId);
+ }
+ return OK;
+ }
+
default:
{
return INVALID_OPERATION;
@@ -812,8 +824,12 @@
}
void NuPlayerDriver::setAudioSink(const sp<AudioSink> &audioSink) {
+ Mutex::Autolock autoLock(mAudioSinkLock);
mPlayer->setAudioSink(audioSink);
mAudioSink = audioSink;
+ if (mCachedPlayerIId != PLAYER_PIID_INVALID) {
+ mAudioSink->setPlayerIId(mCachedPlayerIId);
+ }
}
status_t NuPlayerDriver::setParameter(
@@ -1027,6 +1043,7 @@
if (mState != STATE_RESET_IN_PROGRESS) {
if (mAutoLoop) {
audio_stream_type_t streamType = AUDIO_STREAM_MUSIC;
+ Mutex::Autolock autoLock(mAudioSinkLock);
if (mAudioSink != NULL) {
streamType = mAudioSink->getAudioStreamType();
}
@@ -1037,6 +1054,7 @@
}
if (mLooping || mAutoLoop) {
mPlayer->seekToAsync(0);
+ Mutex::Autolock autoLock(mAudioSinkLock);
if (mAudioSink != NULL) {
// The renderer has stopped the sink at the end in order to play out
// the last little bit of audio. If we're looping, we need to restart it.