Bug 1206979: P3. Request S16 audio for libav 0.8 and earlier. r=edwin draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Tue, 22 Sep 2015 15:33:20 +1000
changeset 607017 e7f024256858ad39d3a97ca1954d0b4629c804dc
parent 607016 a3f53f03e16d1a3bdf71c2f4a97ebd9c51567456
child 607018 0f0c80770df0e00c745a6b217adf52281acc5f52
push id93006
push userjyavenard@mozilla.com
push dateThu, 15 Oct 2015 05:15:33 +0000
treeherdertry@45ea2a01301e [default view] [failures only]
reviewersedwin
bugs1206979
milestone43.0a2
Bug 1206979: P3. Request S16 audio for libav 0.8 and earlier. r=edwin
dom/media/platforms/ffmpeg/FFmpegDataDecoder.cpp
--- a/dom/media/platforms/ffmpeg/FFmpegDataDecoder.cpp
+++ b/dom/media/platforms/ffmpeg/FFmpegDataDecoder.cpp
@@ -8,16 +8,17 @@
 
 #include <string.h>
 #include <unistd.h>
 
 #include "FFmpegLibs.h"
 #include "FFmpegLog.h"
 #include "FFmpegDataDecoder.h"
 #include "prsystem.h"
+#include "FFmpegDecoderModule.h"
 
 namespace mozilla
 {
 
 bool FFmpegDataDecoder<LIBAV_VER>::sFFmpegInitDone = false;
 StaticMutex FFmpegDataDecoder<LIBAV_VER>::sMonitor;
 
 FFmpegDataDecoder<LIBAV_VER>::FFmpegDataDecoder(FlushableTaskQueue* aTaskQueue,
@@ -90,17 +91,21 @@ FFmpegDataDecoder<LIBAV_VER>::InitDecode
   if (!(mCodecContext = avcodec_alloc_context3(codec))) {
     NS_WARNING("Couldn't init ffmpeg context");
     return NS_ERROR_FAILURE;
   }
 
   mCodecContext->opaque = this;
 
   // FFmpeg takes this as a suggestion for what format to use for audio samples.
-  mCodecContext->request_sample_fmt = AV_SAMPLE_FMT_FLT;
+  uint32_t major, minor;
+  FFmpegDecoderModule<LIBAV_VER>::GetVersion(major, minor);
+  // LibAV 0.8 produces rubbish float interlaved samples, request 16 bits audio.
+  mCodecContext->request_sample_fmt = major == 53 && minor <= 34 ?
+    AV_SAMPLE_FMT_S16 : AV_SAMPLE_FMT_FLT;
 
   // FFmpeg will call back to this to negotiate a video pixel format.
   mCodecContext->get_format = ChoosePixelFormat;
 
   mCodecContext->thread_count = PR_GetNumberOfProcessors();
   mCodecContext->thread_type = FF_THREAD_SLICE | FF_THREAD_FRAME;
   mCodecContext->thread_safe_callbacks = false;