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
--- 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);
}
}