Bug 1219134: P1. Fix pts calculation in FFmpeg video decoder. r=edwin a=sylvestre
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 30 Oct 2015 12:47:38 +1100
changeset 296667 ce3f2c696251
parent 296666 d3b021968c63
child 296668 dc997e552ee6
push id5279
push userjyavenard@mozilla.com
push date2015-11-09 13:25 +0000
treeherdermozilla-beta@0056c6a320b7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersedwin, sylvestre
bugs1219134
milestone43.0
Bug 1219134: P1. Fix pts calculation in FFmpeg video decoder. r=edwin a=sylvestre This is the primary reason why we got no pts returned (pts were set to 0) when using early version of LibAV. Apparently you are expected to set the pts when allocating the buffer of a frame. This is undocumented, but both LibAV and FFmpeg do so internally. So do the same.
dom/media/platforms/ffmpeg/FFmpegH264Decoder.cpp
--- a/dom/media/platforms/ffmpeg/FFmpegH264Decoder.cpp
+++ b/dom/media/platforms/ffmpeg/FFmpegH264Decoder.cpp
@@ -11,18 +11,16 @@
 #include "ImageContainer.h"
 
 #include "MediaInfo.h"
 
 #include "FFmpegH264Decoder.h"
 #include "FFmpegLog.h"
 #include "mozilla/PodOperations.h"
 
-#define GECKO_FRAME_TYPE 0x00093CC0
-
 typedef mozilla::layers::Image Image;
 typedef mozilla::layers::PlanarYCbCrImage PlanarYCbCrImage;
 
 namespace mozilla
 {
 
 FFmpegH264Decoder<LIBAV_VER>::FFmpegH264Decoder(
   FlushableTaskQueue* aTaskQueue, MediaDataDecoderCallback* aCallback,
@@ -312,25 +310,29 @@ FFmpegH264Decoder<LIBAV_VER>::AllocateYU
     edgeWidth * aFrame->linesize[0] + edgeWidth,
     edgeWidth / 2 * aFrame->linesize[1] + edgeWidth / 2,
     edgeWidth / 2 * aFrame->linesize[2] + edgeWidth / 2 };
 
   for (uint32_t i = 0; i < 3; i++) {
     aFrame->data[i] = buffer + offsets[i] + planesEdgeWidth[i];
   }
 
-  // Unused, but needs to be non-zero to keep ffmpeg happy.
-  aFrame->type = GECKO_FRAME_TYPE;
-
   aFrame->extended_data = aFrame->data;
   aFrame->width = aCodecContext->width;
   aFrame->height = aCodecContext->height;
 
   aFrame->opaque = static_cast<void*>(image.forget().take());
 
+  aFrame->type = FF_BUFFER_TYPE_USER;
+  aFrame->reordered_opaque = aCodecContext->reordered_opaque;
+#if LIBAVCODEC_VERSION_MAJOR == 53
+  if (aCodecContext->pkt) {
+    aFrame->pkt_pts = aCodecContext->pkt->pts;
+  }
+#endif
   return 0;
 }
 
 nsresult
 FFmpegH264Decoder<LIBAV_VER>::Input(MediaRawData* aSample)
 {
   nsCOMPtr<nsIRunnable> runnable(
     NS_NewRunnableMethodWithArg<nsRefPtr<MediaRawData>>(