diff options
author | Chong Zhang <chz@google.com> | 2014-08-08 15:22:35 -0700 |
---|---|---|
committer | Chong Zhang <chz@google.com> | 2014-08-08 15:22:35 -0700 |
commit | ced1c2f8f6c422063092f5cc5c675ccdebb2dc10 (patch) | |
tree | cab0a795dc8f7210d51aaf036585e06d20f19179 | |
parent | a19f33e4e50cda5d5953fa0cc662502262ac9dfd (diff) | |
download | frameworks_av-ced1c2f8f6c422063092f5cc5c675ccdebb2dc10.zip frameworks_av-ced1c2f8f6c422063092f5cc5c675ccdebb2dc10.tar.gz frameworks_av-ced1c2f8f6c422063092f5cc5c675ccdebb2dc10.tar.bz2 |
some clean up of video size change notification
need to consider rotation when notifying video size change after
initial prepare, in addition to after an output format change.
Bug: 16870964
Change-Id: Icd1c9e901ac932e720ce95b8a983c0edcf251c35
7 files changed, 109 insertions, 97 deletions
diff --git a/media/libmediaplayerservice/nuplayer/GenericSource.cpp b/media/libmediaplayerservice/nuplayer/GenericSource.cpp index 1616448..6676461 100644 --- a/media/libmediaplayerservice/nuplayer/GenericSource.cpp +++ b/media/libmediaplayerservice/nuplayer/GenericSource.cpp @@ -228,13 +228,7 @@ void NuPlayer::GenericSource::prepareAsync() { } if (mVideoTrack.mSource != NULL) { - sp<MetaData> meta = mVideoTrack.mSource->getFormat(); - - int32_t width, height; - CHECK(meta->findInt32(kKeyWidth, &width)); - CHECK(meta->findInt32(kKeyHeight, &height)); - - notifyVideoSizeChanged(width, height); + notifyVideoSizeChanged(getFormat(false /* audio */)); } notifyFlagsChanged( diff --git a/media/libmediaplayerservice/nuplayer/HTTPLiveSource.cpp b/media/libmediaplayerservice/nuplayer/HTTPLiveSource.cpp index e8431e9..c713d39 100644 --- a/media/libmediaplayerservice/nuplayer/HTTPLiveSource.cpp +++ b/media/libmediaplayerservice/nuplayer/HTTPLiveSource.cpp @@ -210,9 +210,9 @@ void NuPlayer::HTTPLiveSource::onSessionNotify(const sp<AMessage> &msg) { int32_t height; if (format != NULL && format->findInt32("width", &width) && format->findInt32("height", &height)) { - notifyVideoSizeChanged(width, height); + notifyVideoSizeChanged(format); } else { - notifyVideoSizeChanged(0, 0); + notifyVideoSizeChanged(); } uint32_t flags = FLAG_CAN_PAUSE; diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp index fe115c6..6f6c9d9 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp +++ b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp @@ -852,60 +852,10 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) { mRenderer->signalAudioSinkChanged(); } else { // video + sp<AMessage> inputFormat = + mSource->getFormat(false /* audio */); - int32_t width, height; - CHECK(format->findInt32("width", &width)); - CHECK(format->findInt32("height", &height)); - - int32_t cropLeft, cropTop, cropRight, cropBottom; - CHECK(format->findRect( - "crop", - &cropLeft, &cropTop, &cropRight, &cropBottom)); - - int32_t displayWidth = cropRight - cropLeft + 1; - int32_t displayHeight = cropBottom - cropTop + 1; - - ALOGV("Video output format changed to %d x %d " - "(crop: %d x %d @ (%d, %d))", - width, height, - displayWidth, - displayHeight, - cropLeft, cropTop); - - sp<AMessage> videoInputFormat = - mSource->getFormat(false /* audio */); - - // Take into account sample aspect ratio if necessary: - int32_t sarWidth, sarHeight; - if (videoInputFormat->findInt32("sar-width", &sarWidth) - && videoInputFormat->findInt32( - "sar-height", &sarHeight)) { - ALOGV("Sample aspect ratio %d : %d", - sarWidth, sarHeight); - - displayWidth = (displayWidth * sarWidth) / sarHeight; - - ALOGV("display dimensions %d x %d", - displayWidth, displayHeight); - } - - int32_t rotationDegrees; - if (!videoInputFormat->findInt32( - "rotation-degrees", &rotationDegrees)) { - rotationDegrees = 0; - } - - if (rotationDegrees == 90 || rotationDegrees == 270) { - notifyListener( - MEDIA_SET_VIDEO_SIZE, - displayHeight, - displayWidth); - } else { - notifyListener( - MEDIA_SET_VIDEO_SIZE, - displayWidth, - displayHeight); - } + updateVideoSize(inputFormat, format); } } else if (what == Decoder::kWhatShutdownCompleted) { ALOGV("%s shutdown completed", audio ? "audio" : "video"); @@ -1383,6 +1333,72 @@ void NuPlayer::renderBuffer(bool audio, const sp<AMessage> &msg) { mRenderer->queueBuffer(audio, buffer, reply); } +void NuPlayer::updateVideoSize( + const sp<AMessage> &inputFormat, + const sp<AMessage> &outputFormat) { + if (inputFormat == NULL) { + ALOGW("Unknown video size, reporting 0x0!"); + notifyListener(MEDIA_SET_VIDEO_SIZE, 0, 0); + return; + } + + int32_t displayWidth, displayHeight; + int32_t cropLeft, cropTop, cropRight, cropBottom; + + if (outputFormat != NULL) { + int32_t width, height; + CHECK(outputFormat->findInt32("width", &width)); + CHECK(outputFormat->findInt32("height", &height)); + + int32_t cropLeft, cropTop, cropRight, cropBottom; + CHECK(outputFormat->findRect( + "crop", + &cropLeft, &cropTop, &cropRight, &cropBottom)); + + displayWidth = cropRight - cropLeft + 1; + displayHeight = cropBottom - cropTop + 1; + + ALOGV("Video output format changed to %d x %d " + "(crop: %d x %d @ (%d, %d))", + width, height, + displayWidth, + displayHeight, + cropLeft, cropTop); + } else { + CHECK(inputFormat->findInt32("width", &displayWidth)); + CHECK(inputFormat->findInt32("height", &displayHeight)); + + ALOGV("Video input format %d x %d", displayWidth, displayHeight); + } + + // Take into account sample aspect ratio if necessary: + int32_t sarWidth, sarHeight; + if (inputFormat->findInt32("sar-width", &sarWidth) + && inputFormat->findInt32("sar-height", &sarHeight)) { + ALOGV("Sample aspect ratio %d : %d", sarWidth, sarHeight); + + displayWidth = (displayWidth * sarWidth) / sarHeight; + + ALOGV("display dimensions %d x %d", displayWidth, displayHeight); + } + + int32_t rotationDegrees; + if (!inputFormat->findInt32("rotation-degrees", &rotationDegrees)) { + rotationDegrees = 0; + } + + if (rotationDegrees == 90 || rotationDegrees == 270) { + int32_t tmp = displayWidth; + displayWidth = displayHeight; + displayHeight = tmp; + } + + notifyListener( + MEDIA_SET_VIDEO_SIZE, + displayWidth, + displayHeight); +} + void NuPlayer::notifyListener(int msg, int ext1, int ext2, const Parcel *in) { if (mDriver == NULL) { return; @@ -1441,19 +1457,19 @@ void NuPlayer::flushDecoder(bool audio, bool needShutdown) { } } -sp<AMessage> NuPlayer::Source::getFormat(bool audio) { - sp<MetaData> meta = getFormatMeta(audio); +void NuPlayer::queueDecoderShutdown( + bool audio, bool video, const sp<AMessage> &reply) { + ALOGI("queueDecoderShutdown audio=%d, video=%d", audio, video); - if (meta == NULL) { - return NULL; - } + mDeferredActions.push_back( + new ShutdownDecoderAction(audio, video)); - sp<AMessage> msg = new AMessage; + mDeferredActions.push_back( + new SimpleAction(&NuPlayer::performScanSources)); - if(convertMetaDataToMessage(meta, &msg) == OK) { - return msg; - } - return NULL; + mDeferredActions.push_back(new PostMessageAction(reply)); + + processDeferredActions(); } status_t NuPlayer::setVideoScalingMode(int32_t mode) { @@ -1729,11 +1745,10 @@ void NuPlayer::onSourceNotify(const sp<AMessage> &msg) { case Source::kWhatVideoSizeChanged: { - int32_t width, height; - CHECK(msg->findInt32("width", &width)); - CHECK(msg->findInt32("height", &height)); + sp<AMessage> format; + CHECK(msg->findMessage("format", &format)); - notifyListener(MEDIA_SET_VIDEO_SIZE, width, height); + updateVideoSize(format); break; } @@ -1889,6 +1904,21 @@ void NuPlayer::sendTimedTextData(const sp<ABuffer> &buffer) { } //////////////////////////////////////////////////////////////////////////////// +sp<AMessage> NuPlayer::Source::getFormat(bool audio) { + sp<MetaData> meta = getFormatMeta(audio); + + if (meta == NULL) { + return NULL; + } + + sp<AMessage> msg = new AMessage; + + if(convertMetaDataToMessage(meta, &msg) == OK) { + return msg; + } + return NULL; +} + void NuPlayer::Source::notifyFlagsChanged(uint32_t flags) { sp<AMessage> notify = dupNotify(); notify->setInt32("what", kWhatFlagsChanged); @@ -1896,11 +1926,10 @@ void NuPlayer::Source::notifyFlagsChanged(uint32_t flags) { notify->post(); } -void NuPlayer::Source::notifyVideoSizeChanged(int32_t width, int32_t height) { +void NuPlayer::Source::notifyVideoSizeChanged(const sp<AMessage> &format) { sp<AMessage> notify = dupNotify(); notify->setInt32("what", kWhatVideoSizeChanged); - notify->setInt32("width", width); - notify->setInt32("height", height); + notify->setMessage("format", format); notify->post(); } @@ -1915,19 +1944,4 @@ void NuPlayer::Source::onMessageReceived(const sp<AMessage> & /* msg */) { TRESPASS(); } -void NuPlayer::queueDecoderShutdown( - bool audio, bool video, const sp<AMessage> &reply) { - ALOGI("queueDecoderShutdown audio=%d, video=%d", audio, video); - - mDeferredActions.push_back( - new ShutdownDecoderAction(audio, video)); - - mDeferredActions.push_back( - new SimpleAction(&NuPlayer::performScanSources)); - - mDeferredActions.push_back(new PostMessageAction(reply)); - - processDeferredActions(); -} - } // namespace android diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.h b/media/libmediaplayerservice/nuplayer/NuPlayer.h index 8bcf10e..486b7cc 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayer.h +++ b/media/libmediaplayerservice/nuplayer/NuPlayer.h @@ -167,6 +167,10 @@ private: status_t instantiateDecoder(bool audio, sp<Decoder> *decoder); + void updateVideoSize( + const sp<AMessage> &inputFormat, + const sp<AMessage> &outputFormat = NULL); + status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg); void renderBuffer(bool audio, const sp<AMessage> &msg); diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerSource.h b/media/libmediaplayerservice/nuplayer/NuPlayerSource.h index 0ec017e..06bbbec 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayerSource.h +++ b/media/libmediaplayerservice/nuplayer/NuPlayerSource.h @@ -110,7 +110,7 @@ protected: sp<AMessage> dupNotify() const { return mNotify->dup(); } void notifyFlagsChanged(uint32_t flags); - void notifyVideoSizeChanged(int32_t width, int32_t height); + void notifyVideoSizeChanged(const sp<AMessage> &format = NULL); void notifyPrepared(status_t err = OK); private: diff --git a/media/libmediaplayerservice/nuplayer/RTSPSource.cpp b/media/libmediaplayerservice/nuplayer/RTSPSource.cpp index 2338b23..a911f6c 100644 --- a/media/libmediaplayerservice/nuplayer/RTSPSource.cpp +++ b/media/libmediaplayerservice/nuplayer/RTSPSource.cpp @@ -356,7 +356,7 @@ void NuPlayer::RTSPSource::onMessageReceived(const sp<AMessage> &msg) { { onConnected(); - notifyVideoSizeChanged(0, 0); + notifyVideoSizeChanged(); uint32_t flags = 0; diff --git a/media/libmediaplayerservice/nuplayer/StreamingSource.cpp b/media/libmediaplayerservice/nuplayer/StreamingSource.cpp index 28f0d50..2e9a29a 100644 --- a/media/libmediaplayerservice/nuplayer/StreamingSource.cpp +++ b/media/libmediaplayerservice/nuplayer/StreamingSource.cpp @@ -44,7 +44,7 @@ NuPlayer::StreamingSource::~StreamingSource() { } void NuPlayer::StreamingSource::prepareAsync() { - notifyVideoSizeChanged(0, 0); + notifyVideoSizeChanged(); notifyFlagsChanged(0); notifyPrepared(); } |