michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #if !defined(WMFReader_h_) michael@0: #define WMFReader_h_ michael@0: michael@0: #include "WMF.h" michael@0: #include "MediaDecoderReader.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "mozilla/RefPtr.h" michael@0: #include "nsRect.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: class WMFByteStream; michael@0: class WMFSourceReaderCallback; michael@0: class DXVA2Manager; michael@0: michael@0: namespace dom { michael@0: class TimeRanges; michael@0: } michael@0: michael@0: // Decoder backend for reading H.264/AAC in MP4/M4A, and MP3 files using michael@0: // Windows Media Foundation. michael@0: class WMFReader : public MediaDecoderReader michael@0: { michael@0: public: michael@0: WMFReader(AbstractMediaDecoder* aDecoder); michael@0: michael@0: virtual ~WMFReader(); michael@0: michael@0: nsresult Init(MediaDecoderReader* aCloneDonor) MOZ_OVERRIDE; michael@0: michael@0: bool DecodeAudioData() MOZ_OVERRIDE; michael@0: bool DecodeVideoFrame(bool &aKeyframeSkip, michael@0: int64_t aTimeThreshold) MOZ_OVERRIDE; michael@0: michael@0: bool HasAudio() MOZ_OVERRIDE; michael@0: bool HasVideo() MOZ_OVERRIDE; michael@0: michael@0: nsresult ReadMetadata(MediaInfo* aInfo, michael@0: MetadataTags** aTags) MOZ_OVERRIDE; michael@0: michael@0: nsresult Seek(int64_t aTime, michael@0: int64_t aStartTime, michael@0: int64_t aEndTime, michael@0: int64_t aCurrentTime) MOZ_OVERRIDE; michael@0: private: michael@0: michael@0: HRESULT CreateSourceReader(); michael@0: HRESULT ConfigureAudioDecoder(); michael@0: HRESULT ConfigureVideoDecoder(); michael@0: HRESULT ConfigureVideoFrameGeometry(IMFMediaType* aMediaType); michael@0: void GetSupportedAudioCodecs(const GUID** aCodecs, uint32_t* aNumCodecs); michael@0: michael@0: HRESULT CreateBasicVideoFrame(IMFSample* aSample, michael@0: int64_t aTimestampUsecs, michael@0: int64_t aDurationUsecs, michael@0: int64_t aOffsetBytes, michael@0: VideoData** aOutVideoData); michael@0: michael@0: HRESULT CreateD3DVideoFrame(IMFSample* aSample, michael@0: int64_t aTimestampUsecs, michael@0: int64_t aDurationUsecs, michael@0: int64_t aOffsetBytes, michael@0: VideoData** aOutVideoData); michael@0: michael@0: // Attempt to initialize DXVA. Returns true on success. michael@0: bool InitializeDXVA(); michael@0: michael@0: RefPtr mSourceReader; michael@0: RefPtr mByteStream; michael@0: RefPtr mSourceReaderCallback; michael@0: nsAutoPtr mDXVA2Manager; michael@0: michael@0: // Region inside the video frame that makes up the picture. Pixels outside michael@0: // of this region should not be rendered. michael@0: nsIntRect mPictureRegion; michael@0: michael@0: uint32_t mAudioChannels; michael@0: uint32_t mAudioBytesPerSample; michael@0: uint32_t mAudioRate; michael@0: michael@0: uint32_t mVideoWidth; michael@0: uint32_t mVideoHeight; michael@0: uint32_t mVideoStride; michael@0: michael@0: // The offset, in audio frames, at which playback started since the michael@0: // last discontinuity. michael@0: int64_t mAudioFrameOffset; michael@0: // The number of audio frames that we've played since the last michael@0: // discontinuity. michael@0: int64_t mAudioFrameSum; michael@0: // True if we need to re-initialize mAudioFrameOffset and mAudioFrameSum michael@0: // from the next audio packet we decode. This happens after a seek, since michael@0: // WMF doesn't mark a stream as having a discontinuity after a seek(0). michael@0: bool mMustRecaptureAudioPosition; michael@0: michael@0: bool mHasAudio; michael@0: bool mHasVideo; michael@0: bool mUseHwAccel; michael@0: michael@0: // We can't call WMFDecoder::IsMP3Supported() on non-main threads, since it michael@0: // checks a pref, so we cache its value in mIsMP3Enabled and use that on michael@0: // the decode thread. michael@0: const bool mIsMP3Enabled; michael@0: michael@0: bool mCOMInitialized; michael@0: }; michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif