Bug 1275339 - [ffmpeg] Don't assume AVFrame has a constant size.
authorJean-Yves Avenard <jyavenard@mozilla.com>
Sat, 11 Jun 2016 11:04:06 +0100
changeset 377759 1bafbbad7fa45220c76dfae1f0419026408d221a
parent 377758 a7affa37fb9c6e535ddc5abfc746edc19daa28c9
child 377760 9ddfddc33c569553a8cbf96cd99277d176f253dd
push id20857
push userbmo:james@hoppipolla.co.uk
push dateSun, 12 Jun 2016 16:59:39 +0000
bugs1275339
milestone50.0a1
Bug 1275339 - [ffmpeg] Don't assume AVFrame has a constant size. An AVFrame has a different size between FFmpeg 0.10 and LibAV 0.8 though both have the same version number. Forgot to add the fixes (twice now :( ) MozReview-Commit-ID: DR3b3fqSngh
dom/media/platforms/ffmpeg/FFmpegDataDecoder.cpp
dom/media/platforms/ffmpeg/FFmpegLibWrapper.cpp
dom/media/platforms/ffmpeg/FFmpegLibWrapper.h
--- a/dom/media/platforms/ffmpeg/FFmpegDataDecoder.cpp
+++ b/dom/media/platforms/ffmpeg/FFmpegDataDecoder.cpp
@@ -180,18 +180,17 @@ FFmpegDataDecoder<LIBAV_VER>::ProcessShu
   if (mCodecContext) {
     mLib->avcodec_close(mCodecContext);
     mLib->av_freep(&mCodecContext);
 #if LIBAVCODEC_VERSION_MAJOR >= 55
     mLib->av_frame_free(&mFrame);
 #elif LIBAVCODEC_VERSION_MAJOR == 54
     mLib->avcodec_free_frame(&mFrame);
 #else
-    delete mFrame;
-    mFrame = nullptr;
+    mLib->av_freep(&mFrame);
 #endif
   }
 }
 
 AVFrame*
 FFmpegDataDecoder<LIBAV_VER>::PrepareFrame()
 {
   MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
@@ -203,19 +202,18 @@ FFmpegDataDecoder<LIBAV_VER>::PrepareFra
   }
 #elif LIBAVCODEC_VERSION_MAJOR == 54
   if (mFrame) {
     mLib->avcodec_get_frame_defaults(mFrame);
   } else {
     mFrame = mLib->avcodec_alloc_frame();
   }
 #else
-  delete mFrame;
-  mFrame = new AVFrame;
-  mLib->avcodec_get_frame_defaults(mFrame);
+  mLib->av_freep(&mFrame);
+  mFrame = mLib->avcodec_alloc_frame();
 #endif
   return mFrame;
 }
 
 /* static */ AVCodec*
 FFmpegDataDecoder<LIBAV_VER>::FindAVCodec(FFmpegLibWrapper* aLib,
                                           AVCodecID aCodec)
 {
--- a/dom/media/platforms/ffmpeg/FFmpegLibWrapper.cpp
+++ b/dom/media/platforms/ffmpeg/FFmpegLibWrapper.cpp
@@ -104,21 +104,21 @@ FFmpegLibWrapper::Link()
   AV_FUNC(avcodec_find_decoder, AV_FUNC_AVCODEC_ALL)
   AV_FUNC(avcodec_flush_buffers, AV_FUNC_AVCODEC_ALL)
   AV_FUNC(avcodec_open2, AV_FUNC_AVCODEC_ALL)
   AV_FUNC(avcodec_register_all, AV_FUNC_AVCODEC_ALL)
   AV_FUNC(av_init_packet, AV_FUNC_AVCODEC_ALL)
   AV_FUNC(av_parser_init, AV_FUNC_AVCODEC_ALL)
   AV_FUNC(av_parser_close, AV_FUNC_AVCODEC_ALL)
   AV_FUNC(av_parser_parse2, AV_FUNC_AVCODEC_ALL)
+  AV_FUNC(avcodec_alloc_frame, (AV_FUNC_53 | AV_FUNC_54))
   AV_FUNC(avcodec_get_frame_defaults, (AV_FUNC_53 | AV_FUNC_54))
   AV_FUNC(av_log_set_level, AV_FUNC_AVUTIL_ALL)
   AV_FUNC(av_malloc, AV_FUNC_AVUTIL_ALL)
   AV_FUNC(av_freep, AV_FUNC_AVUTIL_ALL)
-  AV_FUNC(avcodec_alloc_frame, AV_FUNC_AVUTIL_54)
   AV_FUNC(avcodec_free_frame, AV_FUNC_AVUTIL_54)
   AV_FUNC(av_frame_alloc, (AV_FUNC_AVUTIL_55 | AV_FUNC_AVUTIL_56 | AV_FUNC_AVUTIL_57))
   AV_FUNC(av_frame_free, (AV_FUNC_AVUTIL_55 | AV_FUNC_AVUTIL_56 | AV_FUNC_AVUTIL_57))
   AV_FUNC(av_frame_unref, (AV_FUNC_AVUTIL_55 | AV_FUNC_AVUTIL_56 | AV_FUNC_AVUTIL_57))
 #undef AV_FUNC
 
   avcodec_register_all();
 #ifdef DEBUG
--- a/dom/media/platforms/ffmpeg/FFmpegLibWrapper.h
+++ b/dom/media/platforms/ffmpeg/FFmpegLibWrapper.h
@@ -47,25 +47,25 @@ struct FFmpegLibWrapper
   int (*avcodec_open2)(AVCodecContext *avctx, const AVCodec* codec, AVDictionary** options);
   void (*avcodec_register_all)();
   void (*av_init_packet)(AVPacket* pkt);
   AVCodecParserContext* (*av_parser_init)(int codec_id);
   void (*av_parser_close)(AVCodecParserContext* s);
   int (*av_parser_parse2)(AVCodecParserContext* s, AVCodecContext* avctx, uint8_t** poutbuf, int* poutbuf_size, const uint8_t* buf, int buf_size, int64_t pts, int64_t dts, int64_t pos);
 
   // only used in libavcodec <= 54
+  AVFrame* (*avcodec_alloc_frame)();
   void (*avcodec_get_frame_defaults)(AVFrame* pic);
 
   // libavutil
   void (*av_log_set_level)(int level);
   void*	(*av_malloc)(size_t size);
   void (*av_freep)(void *ptr);
 
   // libavutil v54 only
-  AVFrame* (*avcodec_alloc_frame)();
   void (*avcodec_free_frame)(AVFrame** frame);
 
   // libavutil v55 and later only
   AVFrame* (*av_frame_alloc)();
   void (*av_frame_free)(AVFrame** frame);
   void (*av_frame_unref)(AVFrame* frame);
 
   PRLibrary* mAVCodecLib;