Bug 1139779: Part4. Make FFmpeg video decoder use AVCC. r=edwin a=lsblakk
authorJean-Yves Avenard <jyavenard@mozilla.com>
Tue, 10 Mar 2015 21:19:42 +1100
changeset 248172 7b7b5e77e5e19e96ec3aa84e812dfa98cf122322
parent 248171 20b06ff42ed20303b113094ec95cd87a0f61f9e8
child 248173 d1e899435508368c98080813bd31c7ca817ae630
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)
reviewersedwin, lsblakk
bugs1139779
milestone38.0a2
Bug 1139779: Part4. Make FFmpeg video decoder use AVCC. r=edwin a=lsblakk FFmpeg h264 decoder doesn't handle change of SPS in-band and only use the first found.
dom/media/fmp4/PlatformDecoderModule.cpp
dom/media/fmp4/ffmpeg/FFmpegDecoderModule.h
dom/media/fmp4/ffmpeg/FFmpegH264Decoder.cpp
--- a/dom/media/fmp4/PlatformDecoderModule.cpp
+++ b/dom/media/fmp4/PlatformDecoderModule.cpp
@@ -144,19 +144,20 @@ PlatformDecoderModule::CreatePDM()
     return CreateBlankDecoderModule();
   }
 #ifdef XP_WIN
   nsRefPtr<PlatformDecoderModule> m(new WMFDecoderModule());
   return m.forget();
 #endif
 #ifdef MOZ_FFMPEG
   if (sFFmpegDecoderEnabled) {
-    nsRefPtr<PlatformDecoderModule> m(FFmpegRuntimeLinker::CreateDecoderModule());
+    nsRefPtr<PlatformDecoderModule> m = FFmpegRuntimeLinker::CreateDecoderModule();
     if (m) {
-      return m.forget();
+      nsRefPtr<PlatformDecoderModule> m2(new AVCCDecoderModule(m));
+      return m2.forget();
     }
   }
 #endif
 #ifdef MOZ_APPLEMEDIA
   nsRefPtr<PlatformDecoderModule> m(new AVCCDecoderModule(new AppleDecoderModule()));
   return m.forget();
 #endif
 #ifdef MOZ_GONK_MEDIACODEC
--- a/dom/media/fmp4/ffmpeg/FFmpegDecoderModule.h
+++ b/dom/media/fmp4/ffmpeg/FFmpegDecoderModule.h
@@ -58,13 +58,18 @@ public:
     return FFmpegAudioDecoder<V>::GetCodecId(aMimeType) != AV_CODEC_ID_NONE;
   }
 
   virtual bool SupportsVideoMimeType(const char* aMimeType) MOZ_OVERRIDE
   {
     return FFmpegH264Decoder<V>::GetCodecId(aMimeType) != AV_CODEC_ID_NONE;
   }
 
+  virtual bool DecoderNeedsAVCC(const mp4_demuxer::VideoDecoderConfig& aConfig) MOZ_OVERRIDE
+  {
+    return true;
+  }
+
 };
 
 } // namespace mozilla
 
 #endif // __FFmpegDecoderModule_h__
--- a/dom/media/fmp4/ffmpeg/FFmpegH264Decoder.cpp
+++ b/dom/media/fmp4/ffmpeg/FFmpegH264Decoder.cpp
@@ -31,16 +31,17 @@ FFmpegH264Decoder<LIBAV_VER>::FFmpegH264
   ImageContainer* aImageContainer)
   : 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
@@ -56,22 +57,16 @@ FFmpegH264Decoder<LIBAV_VER>::Init()
 }
 
 FFmpegH264Decoder<LIBAV_VER>::DecodeResult
 FFmpegH264Decoder<LIBAV_VER>::DoDecodeFrame(mp4_demuxer::MP4Sample* aSample)
 {
   AVPacket packet;
   av_init_packet(&packet);
 
-  if (!mp4_demuxer::AnnexB::ConvertSampleToAnnexB(aSample)) {
-    NS_WARNING("FFmpeg h264 decoder failed to convert sample to Annex B.");
-    mCallback->Error();
-    return DecodeResult::DECODE_ERROR;
-  }
-
   if (!aSample->Pad(FF_INPUT_BUFFER_PADDING_SIZE)) {
     NS_WARNING("FFmpeg h264 decoder failed to allocate sample.");
     mCallback->Error();
     return DecodeResult::DECODE_ERROR;
   }
 
   packet.data = aSample->data;
   packet.size = aSample->size;