Bug 1280346: [mp4] Always use SPS dimensions if available. r?gerald draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 22 Aug 2016 06:39:41 +1000
changeset 403731 567dac4ee19e5a64d66fe369ef81b6964ed299ed
parent 403717 e59fdd0ae36a44106cd0b42dd094b97f52bbeee9
child 528983 6f0648a3a5bc287849b88770a19be8c208cf902a
push id26993
push userbmo:jyavenard@mozilla.com
push dateMon, 22 Aug 2016 02:02:19 +0000
reviewersgerald
bugs1280346
milestone51.0a1
Bug 1280346: [mp4] Always use SPS dimensions if available. r?gerald H264 decoders always use those anyway, so may as well use them in the demuxer if SPS NAL is available. This guarantees that we have correct dimensions when reading the MP4 metadata, and will have the side benefit that when loadedmetadata is fired, the dimensions provided at the time will be final; not having to wait to decode the first frame. MozReview-Commit-ID: 3j70Xqw8jJY
dom/media/fmp4/MP4Demuxer.cpp
media/libstagefright/binding/DecoderData.cpp
--- a/dom/media/fmp4/MP4Demuxer.cpp
+++ b/dom/media/fmp4/MP4Demuxer.cpp
@@ -231,22 +231,32 @@ MP4TrackDemuxer::MP4TrackDemuxer(MP4Demu
                                   mStream,
                                   mInfo->mTrackId,
                                   mInfo->IsAudio()))
   , mIterator(MakeUnique<mp4_demuxer::SampleIterator>(mIndex))
   , mNeedReIndex(true)
 {
   EnsureUpToDateIndex(); // Force update of index
 
+  VideoInfo* videoInfo = mInfo->GetAsVideoInfo();
   // Collect telemetry from h264 AVCC SPS.
-  if (mInfo->GetAsVideoInfo() &&
+  if (videoInfo &&
       (mInfo->mMimeType.EqualsLiteral("video/mp4") ||
        mInfo->mMimeType.EqualsLiteral("video/avc"))) {
-    mNeedSPSForTelemetry =
-      AccumulateSPSTelemetry(mInfo->GetAsVideoInfo()->mExtraData);
+    RefPtr<MediaByteBuffer> extraData = videoInfo->mExtraData;
+    mNeedSPSForTelemetry = AccumulateSPSTelemetry(extraData);
+    mp4_demuxer::SPSData spsdata;
+    if (mp4_demuxer::H264::DecodeSPSFromExtraData(extraData, spsdata) &&
+        spsdata.pic_width > 0 && spsdata.pic_height > 0 &&
+        mp4_demuxer::H264::EnsureSPSIsSane(spsdata)) {
+      videoInfo->mImage.width = spsdata.pic_width;
+      videoInfo->mImage.height = spsdata.pic_height;
+      videoInfo->mDisplay.width = spsdata.display_width;
+      videoInfo->mDisplay.height = spsdata.display_height;
+    }
   } else {
     // No SPS to be found.
     mNeedSPSForTelemetry = false;
   }
 }
 
 UniquePtr<TrackInfo>
 MP4TrackDemuxer::GetInfo() const
--- a/media/libstagefright/binding/DecoderData.cpp
+++ b/media/libstagefright/binding/DecoderData.cpp
@@ -205,12 +205,13 @@ MP4VideoInfo::Update(const mp4parse_trac
   mImage.width = video->image_width;
   mImage.height = video->image_height;
 }
 #endif
 
 bool
 MP4VideoInfo::IsValid() const
 {
-  return mDisplay.width > 0 && mDisplay.height > 0;
+  return (mDisplay.width > 0 && mDisplay.height > 0) ||
+    (mImage.width > 0 && mImage.height > 0);
 }
 
 }