Bug 1139779: Part5. Move picture/display size calculations in AVCC wrapper. r=rillian a=lsblakk
authorJean-Yves Avenard <jyavenard@mozilla.com>
Tue, 10 Mar 2015 21:19:42 +1100
changeset 248173 d1e899435508368c98080813bd31c7ca817ae630
parent 248172 7b7b5e77e5e19e96ec3aa84e812dfa98cf122322
child 248174 4acd7286be9e3a4b207629722127875828da836f
push id7776
push usercpearce@mozilla.com
push dateWed, 18 Mar 2015 03:12:44 +0000
treeherdermozilla-aurora@4acd7286be9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian, lsblakk
bugs1139779
milestone38.0a2
Bug 1139779: Part5. Move picture/display size calculations in AVCC wrapper. r=rillian a=lsblakk
dom/media/fmp4/AVCCDecoderModule.cpp
dom/media/fmp4/apple/AppleVDADecoder.cpp
dom/media/fmp4/ffmpeg/FFmpegH264Decoder.cpp
--- a/dom/media/fmp4/AVCCDecoderModule.cpp
+++ b/dom/media/fmp4/AVCCDecoderModule.cpp
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "AVCCDecoderModule.h"
 #include "ImageContainer.h"
 #include "MediaTaskQueue.h"
 #include "mp4_demuxer/DecoderData.h"
 #include "mp4_demuxer/AnnexB.h"
+#include "mp4_demuxer/H264.h"
 
 namespace mozilla
 {
 
 class AVCCMediaDataDecoder : public MediaDataDecoder {
 public:
 
   AVCCMediaDataDecoder(PlatformDecoderModule* aPDM,
@@ -190,16 +191,24 @@ AVCCMediaDataDecoder::CreateDecoder()
 nsresult
 AVCCMediaDataDecoder::CreateDecoderAndInit(mp4_demuxer::MP4Sample* aSample)
 {
   nsRefPtr<mp4_demuxer::ByteBuffer> extra_data =
     mp4_demuxer::AnnexB::ExtractExtraData(aSample);
   if (!mp4_demuxer::AnnexB::HasSPS(extra_data)) {
     return NS_ERROR_NOT_INITIALIZED;
   }
+  mp4_demuxer::SPSData spsdata;
+  if (mp4_demuxer::H264::DecodeSPSFromExtraData(extra_data, spsdata) &&
+      spsdata.pic_width > 0 && spsdata.pic_height > 0) {
+    mCurrentConfig.image_width = spsdata.pic_width;
+    mCurrentConfig.image_height = spsdata.pic_height;
+    mCurrentConfig.display_width = spsdata.display_width;
+    mCurrentConfig.display_height = spsdata.display_height;
+  }
   mCurrentConfig.extra_data = extra_data;
 
   nsresult rv = CreateDecoder();
   NS_ENSURE_SUCCESS(rv, rv);
   return Init();
 }
 
 nsresult
--- a/dom/media/fmp4/apple/AppleVDADecoder.cpp
+++ b/dom/media/fmp4/apple/AppleVDADecoder.cpp
@@ -34,36 +34,32 @@ namespace mozilla {
 
 AppleVDADecoder::AppleVDADecoder(const mp4_demuxer::VideoDecoderConfig& aConfig,
                                FlushableMediaTaskQueue* aVideoTaskQueue,
                                MediaDataDecoderCallback* aCallback,
                                layers::ImageContainer* aImageContainer)
   : mTaskQueue(aVideoTaskQueue)
   , mCallback(aCallback)
   , mImageContainer(aImageContainer)
+  , mPictureWidth(aConfig.image_width)
+  , mPictureHeight(aConfig.image_height)
+  , mDisplayWidth(aConfig.display_width)
+  , mDisplayHeight(aConfig.display_height)
   , mDecoder(nullptr)
   , mIs106(!nsCocoaFeatures::OnLionOrLater())
 {
   MOZ_COUNT_CTOR(AppleVDADecoder);
   // TODO: Verify aConfig.mime_type.
 
   // Retrieve video dimensions from H264 SPS NAL.
   mPictureWidth = aConfig.image_width;
-  mPictureHeight = aConfig.image_height;
-  mDisplayWidth = aConfig.display_width;
-  mDisplayHeight = aConfig.display_height;
   mExtraData = aConfig.extra_data;
   mMaxRefFrames = 4;
   mp4_demuxer::SPSData spsdata;
-  if (mp4_demuxer::H264::DecodeSPSFromExtraData(mExtraData, spsdata) &&
-      spsdata.pic_width && spsdata.pic_height) {
-    mPictureWidth = spsdata.pic_width;
-    mPictureHeight = spsdata.pic_height;
-    mDisplayWidth = spsdata.display_width;
-    mDisplayHeight = spsdata.display_height;
+  if (mp4_demuxer::H264::DecodeSPSFromExtraData(mExtraData, spsdata)) {
     // max_num_ref_frames determines the size of the sliding window
     // we need to queue that many frames in order to guarantee proper
     // pts frames ordering. Use a minimum of 4 to ensure proper playback of
     // non compliant videos.
     mMaxRefFrames =
       std::min(std::max(mMaxRefFrames, spsdata.max_num_ref_frames + 1), 16u);
   }
 
--- a/dom/media/fmp4/ffmpeg/FFmpegH264Decoder.cpp
+++ b/dom/media/fmp4/ffmpeg/FFmpegH264Decoder.cpp
@@ -5,18 +5,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "MediaTaskQueue.h"
 #include "nsThreadUtils.h"
 #include "nsAutoPtr.h"
 #include "ImageContainer.h"
 
 #include "mp4_demuxer/mp4_demuxer.h"
-#include "mp4_demuxer/AnnexB.h"
-#include "mp4_demuxer/H264.h"
 
 #include "FFmpegH264Decoder.h"
 
 #define GECKO_FRAME_TYPE 0x00093CC0
 
 typedef mozilla::layers::Image Image;
 typedef mozilla::layers::PlanarYCbCrImage PlanarYCbCrImage;
 
@@ -32,21 +30,16 @@ FFmpegH264Decoder<LIBAV_VER>::FFmpegH264
   : FFmpegDataDecoder(aTaskQueue, GetCodecId(aConfig.mime_type))
   , mCallback(aCallback)
   , mImageContainer(aImageContainer)
   , mDisplayWidth(aConfig.display_width)
   , mDisplayHeight(aConfig.display_height)
 {
   MOZ_COUNT_CTOR(FFmpegH264Decoder);
   mExtraData = aConfig.extra_data;
-  mp4_demuxer::SPSData spsdata;
-  if (mp4_demuxer::H264::DecodeSPSFromExtraData(aConfig.extra_data, spsdata)) {
-    mDisplayWidth = spsdata.display_width;
-    mDisplayHeight = spsdata.display_height;
-  }
 }
 
 nsresult
 FFmpegH264Decoder<LIBAV_VER>::Init()
 {
   nsresult rv = FFmpegDataDecoder::Init();
   NS_ENSURE_SUCCESS(rv, rv);