author Ehsan Akhgari <>
Sat, 21 Mar 2015 12:28:04 -0400
changeset 234933 ac4464790ec4896a5188fa50cfc69ae0ffeddc08
parent 224306 e073609378c7be5f8b7af7f24e813597a9f31937
child 240463 29bf41172acdd5a120955f63983a6625dff84f5a
permissions -rw-r--r--
Bug 1145631 - Part 1: Replace MOZ_OVERRIDE and MOZ_FINAL with override and final in the tree; r=froydnj This patch was automatically generated using the following script: function convert() { echo "Converting $1 to $2..." find . \ ! -wholename "*/.git*" \ ! -wholename "obj-ff-dbg*" \ -type f \ \( -iname "*.cpp" \ -o -iname "*.h" \ -o -iname "*.c" \ -o -iname "*.cc" \ -o -iname "*.idl" \ -o -iname "*.ipdl" \ -o -iname "*.ipdlh" \ -o -iname "*.mm" \) | \ xargs -n 1 sed -i -e "s/\b$1\b/$2/g" } convert MOZ_OVERRIDE override convert MOZ_FINAL final

/* -*- 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 */
#if !defined(WMFReader_h_)
#define WMFReader_h_

#include "WMF.h"
#include "MediaDecoderReader.h"
#include "nsAutoPtr.h"
#include "mozilla/RefPtr.h"
#include "nsRect.h"

namespace mozilla {

class WMFByteStream;
class WMFSourceReaderCallback;
class DXVA2Manager;

namespace dom {
class TimeRanges;

// Decoder backend for reading H.264/AAC in MP4/M4A, and MP3 files using
// Windows Media Foundation.
class WMFReader : public MediaDecoderReader
  WMFReader(AbstractMediaDecoder* aDecoder);

  virtual ~WMFReader();

  nsresult Init(MediaDecoderReader* aCloneDonor) override;

  bool DecodeAudioData() override;
  bool DecodeVideoFrame(bool &aKeyframeSkip,
                        int64_t aTimeThreshold) override;

  bool HasAudio() override;
  bool HasVideo() override;

  nsresult ReadMetadata(MediaInfo* aInfo,
                        MetadataTags** aTags) override;

  Seek(int64_t aTime, int64_t aEndTime) override;

  bool IsMediaSeekable() override;

  HRESULT CreateSourceReader();
  HRESULT ConfigureAudioDecoder();
  HRESULT ConfigureVideoDecoder();
  HRESULT ConfigureVideoFrameGeometry(IMFMediaType* aMediaType);
  void GetSupportedAudioCodecs(const GUID** aCodecs, uint32_t* aNumCodecs);

  HRESULT CreateBasicVideoFrame(IMFSample* aSample,
                                int64_t aTimestampUsecs,
                                int64_t aDurationUsecs,
                                int64_t aOffsetBytes,
                                VideoData** aOutVideoData);

  HRESULT CreateD3DVideoFrame(IMFSample* aSample,
                              int64_t aTimestampUsecs,
                              int64_t aDurationUsecs,
                              int64_t aOffsetBytes,
                              VideoData** aOutVideoData);

  // Attempt to initialize DXVA. Returns true on success.
  bool InitializeDXVA();  

  nsresult SeekInternal(int64_t aTime);

  RefPtr<IMFSourceReader> mSourceReader;
  RefPtr<WMFByteStream> mByteStream;
  RefPtr<WMFSourceReaderCallback> mSourceReaderCallback;
  nsAutoPtr<DXVA2Manager> mDXVA2Manager;

  // Region inside the video frame that makes up the picture. Pixels outside
  // of this region should not be rendered.
  nsIntRect mPictureRegion;

  uint32_t mAudioChannels;
  uint32_t mAudioBytesPerSample;
  uint32_t mAudioRate;

  uint32_t mVideoWidth;
  uint32_t mVideoHeight;
  uint32_t mVideoStride;

  // The offset, in audio frames, at which playback started since the
  // last discontinuity.
  int64_t mAudioFrameOffset;
  // The number of audio frames that we've played since the last
  // discontinuity.
  int64_t mAudioFrameSum;
  // True if we need to re-initialize mAudioFrameOffset and mAudioFrameSum
  // from the next audio packet we decode. This happens after a seek, since
  // WMF doesn't mark a stream as having a discontinuity after a seek(0).
  bool mMustRecaptureAudioPosition;

  bool mHasAudio;
  bool mHasVideo;
  bool mUseHwAccel;

  // We can't call WMFDecoder::IsMP3Supported() on non-main threads, since it
  // checks a pref, so we cache its value in mIsMP3Enabled and use that on
  // the decode thread.
  const bool mIsMP3Enabled;

  bool mCOMInitialized;

} // namespace mozilla