diff options
-rw-r--r-- | media/libstagefright/AwesomePlayer.cpp | 94 | ||||
-rw-r--r-- | media/libstagefright/MP3Extractor.cpp | 8 | ||||
-rw-r--r-- | media/libstagefright/include/AwesomePlayer.h | 11 |
3 files changed, 75 insertions, 38 deletions
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp index ab65b44..5090c39 100644 --- a/media/libstagefright/AwesomePlayer.cpp +++ b/media/libstagefright/AwesomePlayer.cpp @@ -297,13 +297,11 @@ status_t AwesomePlayer::setDataSource_l(const sp<MediaExtractor> &extractor) { CHECK(meta->findCString(kKeyMIMEType, &mime)); if (!haveVideo && !strncasecmp(mime, "video/", 6)) { - if (setVideoSource(extractor->getTrack(i)) == OK) { - haveVideo = true; - } + setVideoSource(extractor->getTrack(i)); + haveVideo = true; } else if (!haveAudio && !strncasecmp(mime, "audio/", 6)) { - if (setAudioSource(extractor->getTrack(i)) == OK) { - haveAudio = true; - } + setAudioSource(extractor->getTrack(i)); + haveAudio = true; } if (haveAudio && haveVideo) { @@ -331,6 +329,9 @@ void AwesomePlayer::reset_l() { } mPrefetcher.clear(); + mAudioTrack.clear(); + mVideoTrack.clear(); + // Shutdown audio first, so that the respone to the reset request // appears to happen instantaneously as far as the user is concerned // If we did this later, audio would continue playing while we @@ -699,32 +700,34 @@ status_t AwesomePlayer::getVideoDimensions( return OK; } -status_t AwesomePlayer::setAudioSource(sp<MediaSource> source) { - if (source == NULL) { - return UNKNOWN_ERROR; - } +void AwesomePlayer::setAudioSource(sp<MediaSource> source) { + CHECK(source != NULL); if (mPrefetcher != NULL) { source = mPrefetcher->addSource(source); } - sp<MetaData> meta = source->getFormat(); + mAudioTrack = source; +} + +status_t AwesomePlayer::initAudioDecoder() { + sp<MetaData> meta = mAudioTrack->getFormat(); const char *mime; CHECK(meta->findCString(kKeyMIMEType, &mime)); if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_RAW)) { - mAudioSource = source; + mAudioSource = mAudioTrack; } else { mAudioSource = OMXCodec::Create( - mClient.interface(), source->getFormat(), + mClient.interface(), mAudioTrack->getFormat(), false, // createEncoder - source); + mAudioTrack); } if (mAudioSource != NULL) { int64_t durationUs; - if (source->getFormat()->findInt64(kKeyDuration, &durationUs)) { + if (mAudioTrack->getFormat()->findInt64(kKeyDuration, &durationUs)) { if (mDurationUs < 0 || durationUs > mDurationUs) { mDurationUs = durationUs; } @@ -734,30 +737,32 @@ status_t AwesomePlayer::setAudioSource(sp<MediaSource> source) { return mAudioSource != NULL ? OK : UNKNOWN_ERROR; } -status_t AwesomePlayer::setVideoSource(sp<MediaSource> source) { - if (source == NULL) { - return UNKNOWN_ERROR; - } +void AwesomePlayer::setVideoSource(sp<MediaSource> source) { + CHECK(source != NULL); if (mPrefetcher != NULL) { source = mPrefetcher->addSource(source); } + mVideoTrack = source; +} + +status_t AwesomePlayer::initVideoDecoder() { mVideoSource = OMXCodec::Create( - mClient.interface(), source->getFormat(), + mClient.interface(), mVideoTrack->getFormat(), false, // createEncoder - source); + mVideoTrack); if (mVideoSource != NULL) { int64_t durationUs; - if (source->getFormat()->findInt64(kKeyDuration, &durationUs)) { + if (mVideoTrack->getFormat()->findInt64(kKeyDuration, &durationUs)) { if (mDurationUs < 0 || durationUs > mDurationUs) { mDurationUs = durationUs; } } - CHECK(source->getFormat()->findInt32(kKeyWidth, &mVideoWidth)); - CHECK(source->getFormat()->findInt32(kKeyHeight, &mVideoHeight)); + CHECK(mVideoTrack->getFormat()->findInt32(kKeyWidth, &mVideoWidth)); + CHECK(mVideoTrack->getFormat()->findInt32(kKeyHeight, &mVideoHeight)); mVideoSource->start(); } @@ -1045,6 +1050,19 @@ status_t AwesomePlayer::finishSetDataSource_l() { return setDataSource_l(extractor); } +void AwesomePlayer::abortPrepare(status_t err) { + CHECK(err != OK); + + if (mIsAsyncPrepare) { + notifyListener_l(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err); + } + + mPrepareResult = err; + mFlags &= ~PREPARING; + mAsyncPrepareEvent = NULL; + mPreparedCondition.broadcast(); +} + void AwesomePlayer::onPrepareAsyncEvent() { { Mutex::Autolock autoLock(mLock); @@ -1053,15 +1071,7 @@ void AwesomePlayer::onPrepareAsyncEvent() { status_t err = finishSetDataSource_l(); if (err != OK) { - if (mIsAsyncPrepare) { - notifyListener_l(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err); - } - - mPrepareResult = err; - mFlags &= ~PREPARING; - mAsyncPrepareEvent = NULL; - mPreparedCondition.broadcast(); - + abortPrepare(err); return; } } @@ -1081,6 +1091,24 @@ void AwesomePlayer::onPrepareAsyncEvent() { Mutex::Autolock autoLock(mLock); + if (mVideoTrack != NULL && mVideoSource == NULL) { + status_t err = initVideoDecoder(); + + if (err != OK) { + abortPrepare(err); + return; + } + } + + if (mAudioTrack != NULL && mAudioSource == NULL) { + status_t err = initAudioDecoder(); + + if (err != OK) { + abortPrepare(err); + return; + } + } + if (mIsAsyncPrepare) { if (mVideoWidth < 0 || mVideoHeight < 0) { notifyListener_l(MEDIA_SET_VIDEO_SIZE, 0, 0); diff --git a/media/libstagefright/MP3Extractor.cpp b/media/libstagefright/MP3Extractor.cpp index ab38bca..c168771 100644 --- a/media/libstagefright/MP3Extractor.cpp +++ b/media/libstagefright/MP3Extractor.cpp @@ -36,8 +36,10 @@ namespace android { // Everything must match except for -// protection, bitrate, padding, private bits and mode extension. -static const uint32_t kMask = 0xfffe0ccf; +// protection, bitrate, padding, private bits, mode extension, +// copyright bit, original bit and emphasis. +// Yes ... there are things that must indeed match... +static const uint32_t kMask = 0xfffe0cc0; static bool get_mp3_frame_size( uint32_t header, size_t *frame_size, @@ -669,7 +671,7 @@ status_t MP3Source::read( } // Lost sync. - LOGV("lost sync!\n"); + LOGV("lost sync! header = 0x%08x, old header = 0x%08x\n", header, mFixedHeader); off_t pos = mCurrentPos; if (!Resync(mDataSource, mFixedHeader, &pos, NULL)) { diff --git a/media/libstagefright/include/AwesomePlayer.h b/media/libstagefright/include/AwesomePlayer.h index 3590987..7106524 100644 --- a/media/libstagefright/include/AwesomePlayer.h +++ b/media/libstagefright/include/AwesomePlayer.h @@ -112,10 +112,12 @@ private: sp<DataSource> mFileSource; + sp<MediaSource> mVideoTrack; sp<MediaSource> mVideoSource; sp<AwesomeRenderer> mVideoRenderer; bool mVideoRendererIsPreview; + sp<MediaSource> mAudioTrack; sp<MediaSource> mAudioSource; AudioPlayer *mAudioPlayer; int64_t mDurationUs; @@ -199,8 +201,11 @@ private: void cancelPlayerEvents(bool keepBufferingGoing = false); - status_t setAudioSource(sp<MediaSource> source); - status_t setVideoSource(sp<MediaSource> source); + void setAudioSource(sp<MediaSource> source); + status_t initAudioDecoder(); + + void setVideoSource(sp<MediaSource> source); + status_t initVideoDecoder(); void onStreamDone(); @@ -210,6 +215,8 @@ private: void onBufferingUpdate(); void onCheckAudioStatus(); void onPrepareAsyncEvent(); + void abortPrepare(status_t err); + status_t finishSetDataSource_l(); AwesomePlayer(const AwesomePlayer &); |