Loading media/libstagefright/AwesomePlayer.cpp +63 −24 Original line number Diff line number Diff line Loading @@ -794,10 +794,19 @@ status_t AwesomePlayer::play_l() { mAudioPlayer = new AudioPlayer(mAudioSink, this); mAudioPlayer->setSource(mAudioSource); // We've already started the MediaSource in order to enable // the prefetcher to read its data. status_t err = mAudioPlayer->start( true /* sourceAlreadyStarted */); mTimeSource = mAudioPlayer; deferredAudioSeek = true; mWatchForAudioSeekComplete = false; mWatchForAudioEOS = true; } } CHECK(!(mFlags & AUDIO_RUNNING)); if (mVideoSource == NULL) { status_t err = startAudioPlayer_l(); if (err != OK) { delete mAudioPlayer; Loading @@ -806,22 +815,12 @@ status_t AwesomePlayer::play_l() { mFlags &= ~(PLAYING | FIRST_FRAME); if (mDecryptHandle != NULL) { mDrmManagerClient->setPlaybackStatus(mDecryptHandle, Playback::STOP, 0); mDrmManagerClient->setPlaybackStatus( mDecryptHandle, Playback::STOP, 0); } return err; } mTimeSource = mAudioPlayer; deferredAudioSeek = true; mWatchForAudioSeekComplete = false; mWatchForAudioEOS = true; } } else { mAudioPlayer->resume(); } } Loading Loading @@ -853,6 +852,36 @@ status_t AwesomePlayer::play_l() { return OK; } status_t AwesomePlayer::startAudioPlayer_l() { CHECK(!(mFlags & AUDIO_RUNNING)); if (mAudioSource == NULL || mAudioPlayer == NULL) { return OK; } if (!(mFlags & AUDIOPLAYER_STARTED)) { mFlags |= AUDIOPLAYER_STARTED; // We've already started the MediaSource in order to enable // the prefetcher to read its data. status_t err = mAudioPlayer->start( true /* sourceAlreadyStarted */); if (err != OK) { notifyListener_l(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err); return err; } } else { mAudioPlayer->resume(); } mFlags |= AUDIO_RUNNING; mWatchForAudioEOS = true; return OK; } void AwesomePlayer::notifyVideoSize_l() { sp<MetaData> meta = mVideoSource->getFormat(); Loading Loading @@ -954,7 +983,7 @@ status_t AwesomePlayer::pause_l(bool at_eos) { cancelPlayerEvents(true /* keepBufferingGoing */); if (mAudioPlayer != NULL) { if (mAudioPlayer != NULL && (mFlags & AUDIO_RUNNING)) { if (at_eos) { // If we played the audio stream to completion we // want to make sure that all samples remaining in the audio Loading @@ -963,6 +992,8 @@ status_t AwesomePlayer::pause_l(bool at_eos) { } else { mAudioPlayer->pause(); } mFlags &= ~AUDIO_RUNNING; } mFlags &= ~PLAYING; Loading Loading @@ -1195,9 +1226,7 @@ void AwesomePlayer::finishSeekIfNecessary(int64_t videoTimeUs) { // requested seek time instead. mAudioPlayer->seekTo(videoTimeUs < 0 ? mSeekTimeUs : videoTimeUs); mAudioPlayer->resume(); mWatchForAudioSeekComplete = true; mWatchForAudioEOS = true; } else if (!mSeekNotificationSent) { // If we're playing video only, report seek complete now, // otherwise audio player will notify us later. Loading Loading @@ -1241,8 +1270,10 @@ void AwesomePlayer::onVideoEvent() { // locations, we'll "pause" the audio source, causing it to // stop reading input data until a subsequent seek. if (mAudioPlayer != NULL) { if (mAudioPlayer != NULL && (mFlags & AUDIO_RUNNING)) { mAudioPlayer->pause(); mFlags &= ~AUDIO_RUNNING; } mAudioSource->pause(); } Loading Loading @@ -1312,6 +1343,14 @@ void AwesomePlayer::onVideoEvent() { bool wasSeeking = mSeeking; finishSeekIfNecessary(timeUs); if (mAudioPlayer != NULL && !(mFlags & (AUDIO_RUNNING | SEEK_PREVIEW))) { status_t err = startAudioPlayer_l(); if (err != OK) { LOGE("Startung the audio player failed w/ err %d", err); return; } } TimeSource *ts = (mFlags & AUDIO_AT_EOS) ? &mSystemTimeSource : mTimeSource; if (mFlags & FIRST_FRAME) { Loading media/libstagefright/include/AwesomePlayer.h +5 −0 Original line number Diff line number Diff line Loading @@ -121,6 +121,9 @@ private: // We're triggering a single video event to display the first frame // after the seekpoint. SEEK_PREVIEW = 4096, AUDIO_RUNNING = 8192, AUDIOPLAYER_STARTED = 16384, }; mutable Mutex mLock; Loading Loading @@ -256,6 +259,8 @@ private: void finishSeekIfNecessary(int64_t videoTimeUs); void ensureCacheIsFetching_l(); status_t startAudioPlayer_l(); AwesomePlayer(const AwesomePlayer &); AwesomePlayer &operator=(const AwesomePlayer &); }; Loading Loading
media/libstagefright/AwesomePlayer.cpp +63 −24 Original line number Diff line number Diff line Loading @@ -794,10 +794,19 @@ status_t AwesomePlayer::play_l() { mAudioPlayer = new AudioPlayer(mAudioSink, this); mAudioPlayer->setSource(mAudioSource); // We've already started the MediaSource in order to enable // the prefetcher to read its data. status_t err = mAudioPlayer->start( true /* sourceAlreadyStarted */); mTimeSource = mAudioPlayer; deferredAudioSeek = true; mWatchForAudioSeekComplete = false; mWatchForAudioEOS = true; } } CHECK(!(mFlags & AUDIO_RUNNING)); if (mVideoSource == NULL) { status_t err = startAudioPlayer_l(); if (err != OK) { delete mAudioPlayer; Loading @@ -806,22 +815,12 @@ status_t AwesomePlayer::play_l() { mFlags &= ~(PLAYING | FIRST_FRAME); if (mDecryptHandle != NULL) { mDrmManagerClient->setPlaybackStatus(mDecryptHandle, Playback::STOP, 0); mDrmManagerClient->setPlaybackStatus( mDecryptHandle, Playback::STOP, 0); } return err; } mTimeSource = mAudioPlayer; deferredAudioSeek = true; mWatchForAudioSeekComplete = false; mWatchForAudioEOS = true; } } else { mAudioPlayer->resume(); } } Loading Loading @@ -853,6 +852,36 @@ status_t AwesomePlayer::play_l() { return OK; } status_t AwesomePlayer::startAudioPlayer_l() { CHECK(!(mFlags & AUDIO_RUNNING)); if (mAudioSource == NULL || mAudioPlayer == NULL) { return OK; } if (!(mFlags & AUDIOPLAYER_STARTED)) { mFlags |= AUDIOPLAYER_STARTED; // We've already started the MediaSource in order to enable // the prefetcher to read its data. status_t err = mAudioPlayer->start( true /* sourceAlreadyStarted */); if (err != OK) { notifyListener_l(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err); return err; } } else { mAudioPlayer->resume(); } mFlags |= AUDIO_RUNNING; mWatchForAudioEOS = true; return OK; } void AwesomePlayer::notifyVideoSize_l() { sp<MetaData> meta = mVideoSource->getFormat(); Loading Loading @@ -954,7 +983,7 @@ status_t AwesomePlayer::pause_l(bool at_eos) { cancelPlayerEvents(true /* keepBufferingGoing */); if (mAudioPlayer != NULL) { if (mAudioPlayer != NULL && (mFlags & AUDIO_RUNNING)) { if (at_eos) { // If we played the audio stream to completion we // want to make sure that all samples remaining in the audio Loading @@ -963,6 +992,8 @@ status_t AwesomePlayer::pause_l(bool at_eos) { } else { mAudioPlayer->pause(); } mFlags &= ~AUDIO_RUNNING; } mFlags &= ~PLAYING; Loading Loading @@ -1195,9 +1226,7 @@ void AwesomePlayer::finishSeekIfNecessary(int64_t videoTimeUs) { // requested seek time instead. mAudioPlayer->seekTo(videoTimeUs < 0 ? mSeekTimeUs : videoTimeUs); mAudioPlayer->resume(); mWatchForAudioSeekComplete = true; mWatchForAudioEOS = true; } else if (!mSeekNotificationSent) { // If we're playing video only, report seek complete now, // otherwise audio player will notify us later. Loading Loading @@ -1241,8 +1270,10 @@ void AwesomePlayer::onVideoEvent() { // locations, we'll "pause" the audio source, causing it to // stop reading input data until a subsequent seek. if (mAudioPlayer != NULL) { if (mAudioPlayer != NULL && (mFlags & AUDIO_RUNNING)) { mAudioPlayer->pause(); mFlags &= ~AUDIO_RUNNING; } mAudioSource->pause(); } Loading Loading @@ -1312,6 +1343,14 @@ void AwesomePlayer::onVideoEvent() { bool wasSeeking = mSeeking; finishSeekIfNecessary(timeUs); if (mAudioPlayer != NULL && !(mFlags & (AUDIO_RUNNING | SEEK_PREVIEW))) { status_t err = startAudioPlayer_l(); if (err != OK) { LOGE("Startung the audio player failed w/ err %d", err); return; } } TimeSource *ts = (mFlags & AUDIO_AT_EOS) ? &mSystemTimeSource : mTimeSource; if (mFlags & FIRST_FRAME) { Loading
media/libstagefright/include/AwesomePlayer.h +5 −0 Original line number Diff line number Diff line Loading @@ -121,6 +121,9 @@ private: // We're triggering a single video event to display the first frame // after the seekpoint. SEEK_PREVIEW = 4096, AUDIO_RUNNING = 8192, AUDIOPLAYER_STARTED = 16384, }; mutable Mutex mLock; Loading Loading @@ -256,6 +259,8 @@ private: void finishSeekIfNecessary(int64_t videoTimeUs); void ensureCacheIsFetching_l(); status_t startAudioPlayer_l(); AwesomePlayer(const AwesomePlayer &); AwesomePlayer &operator=(const AwesomePlayer &); }; Loading