diff options
author | Jean-Michel Trivi <jmtrivi@google.com> | 2014-09-05 11:20:11 -0700 |
---|---|---|
committer | Jean-Michel Trivi <jmtrivi@google.com> | 2014-09-05 11:58:39 -0700 |
commit | 640adb3cf89cc9b826372009fad8c9b3d120482e (patch) | |
tree | e51644f1d307b920cf35e364c7d7562a604ef9a5 | |
parent | f2a2d0d6731174f5ce2a7b9d6dfd96dd7f1727a4 (diff) | |
download | frameworks_av-640adb3cf89cc9b826372009fad8c9b3d120482e.zip frameworks_av-640adb3cf89cc9b826372009fad8c9b3d120482e.tar.gz frameworks_av-640adb3cf89cc9b826372009fad8c9b3d120482e.tar.bz2 |
Cache audio attributes when player not available
Cache the audio attributes stored in a Parcel in the client-side
MediaPlayer object if they are set through setParameter()
before the server-side MediaPlayer is available. Apply them when
the player is prepared.
Bug 17280746
Change-Id: I72f1a7fc4e2b076fae8cbdede77a2f74e98b2a03
-rw-r--r-- | include/media/mediaplayer.h | 1 | ||||
-rw-r--r-- | media/libmedia/mediaplayer.cpp | 21 |
2 files changed, 20 insertions, 2 deletions
diff --git a/include/media/mediaplayer.h b/include/media/mediaplayer.h index 2442219..9cc208e 100644 --- a/include/media/mediaplayer.h +++ b/include/media/mediaplayer.h @@ -278,6 +278,7 @@ private: bool mPrepareSync; status_t mPrepareStatus; audio_stream_type_t mStreamType; + Parcel* mAudioAttributesParcel; bool mLoop; float mLeftVolume; float mRightVolume; diff --git a/media/libmedia/mediaplayer.cpp b/media/libmedia/mediaplayer.cpp index 6cd377a..9611ac7 100644 --- a/media/libmedia/mediaplayer.cpp +++ b/media/libmedia/mediaplayer.cpp @@ -50,6 +50,7 @@ MediaPlayer::MediaPlayer() mListener = NULL; mCookie = NULL; mStreamType = AUDIO_STREAM_MUSIC; + mAudioAttributesParcel = NULL; mCurrentPosition = -1; mSeekPosition = -1; mCurrentState = MEDIA_PLAYER_IDLE; @@ -68,6 +69,10 @@ MediaPlayer::MediaPlayer() MediaPlayer::~MediaPlayer() { ALOGV("destructor"); + if (mAudioAttributesParcel != NULL) { + delete mAudioAttributesParcel; + mAudioAttributesParcel = NULL; + } AudioSystem::releaseAudioSessionId(mAudioSessionId, -1); disconnect(); IPCThreadState::self()->flushCommands(); @@ -237,6 +242,9 @@ status_t MediaPlayer::prepareAsync_l() { if ( (mPlayer != 0) && ( mCurrentState & ( MEDIA_PLAYER_INITIALIZED | MEDIA_PLAYER_STOPPED) ) ) { mPlayer->setAudioStreamType(mStreamType); + if (mAudioAttributesParcel != NULL) { + mPlayer->setParameter(KEY_PARAMETER_AUDIO_ATTRIBUTES, *mAudioAttributesParcel); + } mCurrentState = MEDIA_PLAYER_PREPARING; return mPlayer->prepareAsync(); } @@ -662,8 +670,17 @@ status_t MediaPlayer::setParameter(int key, const Parcel& request) if (mPlayer != NULL) { return mPlayer->setParameter(key, request); } - ALOGV("setParameter: no active player"); - return INVALID_OPERATION; + switch (key) { + case KEY_PARAMETER_AUDIO_ATTRIBUTES: + // no player, save the marshalled audio attributes + if (mAudioAttributesParcel != NULL) { delete mAudioAttributesParcel; }; + mAudioAttributesParcel = new Parcel(); + mAudioAttributesParcel->appendFrom(&request, 0, request.dataSize()); + return OK; + default: + ALOGV("setParameter: no active player"); + return INVALID_OPERATION; + } } status_t MediaPlayer::getParameter(int key, Parcel *reply) |