author Jean-Yves Avenard <>
Mon, 28 Sep 2015 09:48:42 +1000
changeset 607014 10db198e218b83f0637a2ba59667d22ad2521119
parent 607013 0123f6fe9832325693b692f1b9e1ede0fbf5f63e
child 607016 a3f53f03e16d1a3bdf71c2f4a97ebd9c51567456
permissions -rw-r--r--
Bug 1208917: Fix VP9 decoding with recent version of libav. r=kentuckyfriedtakahe Recent libav do not require a codec parser to decode VP9.

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at */

#ifndef __FFmpegH264Decoder_h__
#define __FFmpegH264Decoder_h__

#include "FFmpegDataDecoder.h"

namespace mozilla

template <int V>
class FFmpegH264Decoder : public FFmpegDataDecoder<V>

template <>
class FFmpegH264Decoder<LIBAV_VER> : public FFmpegDataDecoder<LIBAV_VER>
  typedef mozilla::layers::Image Image;
  typedef mozilla::layers::ImageContainer ImageContainer;

  enum DecodeResult {

  FFmpegH264Decoder(FlushableTaskQueue* aTaskQueue,
                    MediaDataDecoderCallback* aCallback,
                    const VideoInfo& aConfig,
                    ImageContainer* aImageContainer);
  virtual ~FFmpegH264Decoder();

  virtual nsRefPtr<InitPromise> Init() override;
  virtual nsresult Input(MediaRawData* aSample) override;
  virtual void ProcessDrain() override;
  static AVCodecID GetCodecId(const nsACString& aMimeType);

  void DecodeFrame(MediaRawData* aSample);
  DecodeResult DoDecodeFrame(MediaRawData* aSample);
  DecodeResult DoDecodeFrame(MediaRawData* aSample, uint8_t* aData, int aSize);
  void DoDrain();
  void OutputDelayedFrames();

   * This method allocates a buffer for FFmpeg's decoder, wrapped in an Image.
   * Currently it only supports Planar YUV420, which appears to be the only
   * non-hardware accelerated image format that FFmpeg's H264 decoder is
   * capable of outputting.
  int AllocateYUV420PVideoBuffer(AVCodecContext* aCodecContext,
                                 AVFrame* aFrame);

  static int AllocateBufferCb(AVCodecContext* aCodecContext, AVFrame* aFrame);
  static void ReleaseBufferCb(AVCodecContext* aCodecContext, AVFrame* aFrame);
  int64_t GetPts(const AVPacket& packet);

  nsRefPtr<ImageContainer> mImageContainer;
  uint32_t mDisplayWidth;
  uint32_t mDisplayHeight;

} // namespace mozilla

#endif // __FFmpegH264Decoder_h__