From a0d0ba51ad60a68117a0ee78e37ab78715b8a069 Mon Sep 17 00:00:00 2001 From: Chong Zhang Date: Fri, 10 Apr 2015 22:41:56 -0700 Subject: HLS: parse stream resolution and set maxWidth/maxHeight bug: 20160436 Change-Id: Ic3adb84d3c65cc65f62fc509a99d09602db862a1 --- media/libstagefright/Utils.cpp | 20 ++++++++++++++++++++ media/libstagefright/httplive/LiveSession.cpp | 19 +++++++++++++++++++ media/libstagefright/httplive/LiveSession.h | 2 ++ media/libstagefright/httplive/M3UParser.cpp | 23 +++++++++++++++++++++++ 4 files changed, 64 insertions(+) (limited to 'media') diff --git a/media/libstagefright/Utils.cpp b/media/libstagefright/Utils.cpp index 8506e37..dfe8ad1 100644 --- a/media/libstagefright/Utils.cpp +++ b/media/libstagefright/Utils.cpp @@ -166,6 +166,16 @@ status_t convertMetaDataToMessage( msg->setInt32("max-input-size", maxInputSize); } + int32_t maxWidth; + if (meta->findInt32(kKeyMaxWidth, &maxWidth)) { + msg->setInt32("max-width", maxWidth); + } + + int32_t maxHeight; + if (meta->findInt32(kKeyMaxHeight, &maxHeight)) { + msg->setInt32("max-height", maxHeight); + } + int32_t rotationDegrees; if (meta->findInt32(kKeyRotation, &rotationDegrees)) { msg->setInt32("rotation-degrees", rotationDegrees); @@ -568,6 +578,16 @@ void convertMessageToMetaData(const sp &msg, sp &meta) { meta->setInt32(kKeyMaxInputSize, maxInputSize); } + int32_t maxWidth; + if (msg->findInt32("max-width", &maxWidth)) { + meta->setInt32(kKeyMaxWidth, maxWidth); + } + + int32_t maxHeight; + if (msg->findInt32("max-height", &maxHeight)) { + meta->setInt32(kKeyMaxHeight, maxHeight); + } + // reassemble the csd data into its original form sp csd0; if (msg->findBuffer("csd-0", &csd0)) { diff --git a/media/libstagefright/httplive/LiveSession.cpp b/media/libstagefright/httplive/LiveSession.cpp index 74f58e9..4886000 100644 --- a/media/libstagefright/httplive/LiveSession.cpp +++ b/media/libstagefright/httplive/LiveSession.cpp @@ -171,6 +171,8 @@ LiveSession::LiveSession( mOrigBandwidthIndex(-1), mLastBandwidthBps(-1ll), mBandwidthEstimator(new BandwidthEstimator()), + mMaxWidth(720), + mMaxHeight(480), mStreamMask(0), mNewStreamMask(0), mSwapMask(0), @@ -345,6 +347,9 @@ status_t LiveSession::getStreamFormat(StreamType stream, sp *format) { if (stream == STREAMTYPE_AUDIO) { // set AAC input buffer size to 32K bytes (256kbps x 1sec) meta->setInt32(kKeyMaxInputSize, 32 * 1024); + } else if (stream == STREAMTYPE_VIDEO) { + meta->setInt32(kKeyMaxWidth, mMaxWidth); + meta->setInt32(kKeyMaxHeight, mMaxHeight); } return convertMetaDataToMessage(meta, format); @@ -847,6 +852,9 @@ void LiveSession::onConnect(const sp &msg) { size_t initialBandwidth = 0; size_t initialBandwidthIndex = 0; + int32_t maxWidth = 0; + int32_t maxHeight = 0; + if (mPlaylist->isVariantPlaylist()) { Vector itemsWithVideo; for (size_t i = 0; i < mPlaylist->size(); ++i) { @@ -860,6 +868,14 @@ void LiveSession::onConnect(const sp &msg) { CHECK(meta->findInt32("bandwidth", (int32_t *)&item.mBandwidth)); + int32_t width, height; + if (meta->findInt32("width", &width)) { + maxWidth = max(maxWidth, width); + } + if (meta->findInt32("height", &height)) { + maxHeight = max(maxHeight, height); + } + mBandwidthItems.push(item); if (mPlaylist->hasType(i, "video")) { itemsWithVideo.push(item); @@ -893,6 +909,9 @@ void LiveSession::onConnect(const sp &msg) { mBandwidthItems.push(item); } + mMaxWidth = maxWidth > 0 ? maxWidth : mMaxWidth; + mMaxHeight = maxHeight > 0 ? maxHeight : mMaxHeight; + mPlaylist->pickRandomMediaItems(); changeConfiguration( 0ll /* timeUs */, initialBandwidthIndex, false /* pickTrack */); diff --git a/media/libstagefright/httplive/LiveSession.h b/media/libstagefright/httplive/LiveSession.h index 9117bb1..ed74bc2 100644 --- a/media/libstagefright/httplive/LiveSession.h +++ b/media/libstagefright/httplive/LiveSession.h @@ -191,6 +191,8 @@ private: sp mBandwidthEstimator; sp mPlaylist; + int32_t mMaxWidth; + int32_t mMaxHeight; sp mFetcherLooper; KeyedVector mFetcherInfos; diff --git a/media/libstagefright/httplive/M3UParser.cpp b/media/libstagefright/httplive/M3UParser.cpp index 7bb7f2c..ef9145c 100644 --- a/media/libstagefright/httplive/M3UParser.cpp +++ b/media/libstagefright/httplive/M3UParser.cpp @@ -808,6 +808,29 @@ status_t M3UParser::parseStreamInf( *meta = new AMessage; } (*meta)->setString(key.c_str(), codecs.c_str()); + } else if (!strcasecmp("resolution", key.c_str())) { + const char *s = val.c_str(); + char *end; + unsigned long width = strtoul(s, &end, 10); + + if (end == s || *end != 'x') { + // malformed + continue; + } + + s = end + 1; + unsigned long height = strtoul(s, &end, 10); + + if (end == s || *end != '\0') { + // malformed + continue; + } + + if (meta->get() == NULL) { + *meta = new AMessage; + } + (*meta)->setInt32("width", width); + (*meta)->setInt32("height", height); } else if (!strcasecmp("audio", key.c_str()) || !strcasecmp("video", key.c_str()) || !strcasecmp("subtitles", key.c_str())) { -- cgit v1.1