|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 #if !defined(WMFReader_h_) |
|
7 #define WMFReader_h_ |
|
8 |
|
9 #include "WMF.h" |
|
10 #include "MediaDecoderReader.h" |
|
11 #include "nsAutoPtr.h" |
|
12 #include "mozilla/RefPtr.h" |
|
13 #include "nsRect.h" |
|
14 |
|
15 namespace mozilla { |
|
16 |
|
17 class WMFByteStream; |
|
18 class WMFSourceReaderCallback; |
|
19 class DXVA2Manager; |
|
20 |
|
21 namespace dom { |
|
22 class TimeRanges; |
|
23 } |
|
24 |
|
25 // Decoder backend for reading H.264/AAC in MP4/M4A, and MP3 files using |
|
26 // Windows Media Foundation. |
|
27 class WMFReader : public MediaDecoderReader |
|
28 { |
|
29 public: |
|
30 WMFReader(AbstractMediaDecoder* aDecoder); |
|
31 |
|
32 virtual ~WMFReader(); |
|
33 |
|
34 nsresult Init(MediaDecoderReader* aCloneDonor) MOZ_OVERRIDE; |
|
35 |
|
36 bool DecodeAudioData() MOZ_OVERRIDE; |
|
37 bool DecodeVideoFrame(bool &aKeyframeSkip, |
|
38 int64_t aTimeThreshold) MOZ_OVERRIDE; |
|
39 |
|
40 bool HasAudio() MOZ_OVERRIDE; |
|
41 bool HasVideo() MOZ_OVERRIDE; |
|
42 |
|
43 nsresult ReadMetadata(MediaInfo* aInfo, |
|
44 MetadataTags** aTags) MOZ_OVERRIDE; |
|
45 |
|
46 nsresult Seek(int64_t aTime, |
|
47 int64_t aStartTime, |
|
48 int64_t aEndTime, |
|
49 int64_t aCurrentTime) MOZ_OVERRIDE; |
|
50 private: |
|
51 |
|
52 HRESULT CreateSourceReader(); |
|
53 HRESULT ConfigureAudioDecoder(); |
|
54 HRESULT ConfigureVideoDecoder(); |
|
55 HRESULT ConfigureVideoFrameGeometry(IMFMediaType* aMediaType); |
|
56 void GetSupportedAudioCodecs(const GUID** aCodecs, uint32_t* aNumCodecs); |
|
57 |
|
58 HRESULT CreateBasicVideoFrame(IMFSample* aSample, |
|
59 int64_t aTimestampUsecs, |
|
60 int64_t aDurationUsecs, |
|
61 int64_t aOffsetBytes, |
|
62 VideoData** aOutVideoData); |
|
63 |
|
64 HRESULT CreateD3DVideoFrame(IMFSample* aSample, |
|
65 int64_t aTimestampUsecs, |
|
66 int64_t aDurationUsecs, |
|
67 int64_t aOffsetBytes, |
|
68 VideoData** aOutVideoData); |
|
69 |
|
70 // Attempt to initialize DXVA. Returns true on success. |
|
71 bool InitializeDXVA(); |
|
72 |
|
73 RefPtr<IMFSourceReader> mSourceReader; |
|
74 RefPtr<WMFByteStream> mByteStream; |
|
75 RefPtr<WMFSourceReaderCallback> mSourceReaderCallback; |
|
76 nsAutoPtr<DXVA2Manager> mDXVA2Manager; |
|
77 |
|
78 // Region inside the video frame that makes up the picture. Pixels outside |
|
79 // of this region should not be rendered. |
|
80 nsIntRect mPictureRegion; |
|
81 |
|
82 uint32_t mAudioChannels; |
|
83 uint32_t mAudioBytesPerSample; |
|
84 uint32_t mAudioRate; |
|
85 |
|
86 uint32_t mVideoWidth; |
|
87 uint32_t mVideoHeight; |
|
88 uint32_t mVideoStride; |
|
89 |
|
90 // The offset, in audio frames, at which playback started since the |
|
91 // last discontinuity. |
|
92 int64_t mAudioFrameOffset; |
|
93 // The number of audio frames that we've played since the last |
|
94 // discontinuity. |
|
95 int64_t mAudioFrameSum; |
|
96 // True if we need to re-initialize mAudioFrameOffset and mAudioFrameSum |
|
97 // from the next audio packet we decode. This happens after a seek, since |
|
98 // WMF doesn't mark a stream as having a discontinuity after a seek(0). |
|
99 bool mMustRecaptureAudioPosition; |
|
100 |
|
101 bool mHasAudio; |
|
102 bool mHasVideo; |
|
103 bool mUseHwAccel; |
|
104 |
|
105 // We can't call WMFDecoder::IsMP3Supported() on non-main threads, since it |
|
106 // checks a pref, so we cache its value in mIsMP3Enabled and use that on |
|
107 // the decode thread. |
|
108 const bool mIsMP3Enabled; |
|
109 |
|
110 bool mCOMInitialized; |
|
111 }; |
|
112 |
|
113 } // namespace mozilla |
|
114 |
|
115 #endif |