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 
7 #if !defined(WMFVideoMFTManager_h_)
8 #define WMFVideoMFTManager_h_
9 
10 #include "WMF.h"
11 #include "MFTDecoder.h"
12 #include "nsAutoPtr.h"
13 #include "nsRect.h"
14 #include "WMFMediaDataDecoder.h"
15 #include "mozilla/RefPtr.h"
16 
17 namespace mozilla {
18 
19 class DXVA2Manager;
20 
21 class WMFVideoMFTManager : public MFTManager {
22 public:
23   WMFVideoMFTManager(const VideoInfo& aConfig,
24                      layers::KnowsCompositor* aKnowsCompositor,
25                      layers::ImageContainer* aImageContainer,
26                      bool aDXVAEnabled);
27   ~WMFVideoMFTManager();
28 
29   bool Init();
30 
31   HRESULT Input(MediaRawData* aSample) override;
32 
33   HRESULT Output(int64_t aStreamOffset, RefPtr<MediaData>& aOutput) override;
34 
35   void Shutdown() override;
36 
37   bool IsHardwareAccelerated(nsACString& aFailureReason) const override;
38 
GetType()39   TrackInfo::TrackType GetType() override {
40     return TrackInfo::kVideoTrack;
41   }
42 
GetDescriptionName()43   const char* GetDescriptionName() const override
44   {
45     nsCString failureReason;
46     return IsHardwareAccelerated(failureReason)
47       ? "wmf hardware video decoder" : "wmf software video decoder";
48   }
49 
Flush()50   void Flush() override
51   {
52     MFTManager::Flush();
53     mDraining = false;
54     mSamplesCount = 0;
55   }
56 
Drain()57   void Drain() override
58   {
59     MFTManager::Drain();
60     mDraining = true;
61   }
62 
63 private:
64 
65   bool ValidateVideoInfo();
66 
67   bool InitializeDXVA(bool aForceD3D9);
68 
69   bool InitInternal(bool aForceD3D9);
70 
71   HRESULT ConfigureVideoFrameGeometry();
72 
73   HRESULT CreateBasicVideoFrame(IMFSample* aSample,
74                                 int64_t aStreamOffset,
75                                 VideoData** aOutVideoData);
76 
77   HRESULT CreateD3DVideoFrame(IMFSample* aSample,
78                               int64_t aStreamOffset,
79                               VideoData** aOutVideoData);
80 
81   HRESULT SetDecoderMediaTypes();
82 
83   bool CanUseDXVA(IMFMediaType* aType);
84 
85   // Video frame geometry.
86   VideoInfo mVideoInfo;
87   uint32_t mVideoStride;
88   nsIntSize mImageSize;
89 
90   RefPtr<layers::ImageContainer> mImageContainer;
91   RefPtr<layers::KnowsCompositor> mKnowsCompositor;
92   nsAutoPtr<DXVA2Manager> mDXVA2Manager;
93 
94   RefPtr<IMFSample> mLastInput;
95   float mLastDuration;
96   int64_t mLastTime = 0;
97   bool mDraining = false;
98   int64_t mSamplesCount = 0;
99 
100   bool mDXVAEnabled;
101   bool mUseHwAccel;
102 
103   nsCString mDXVAFailureReason;
104 
105   enum StreamType {
106     Unknown,
107     H264,
108     VP8,
109     VP9
110   };
111 
112   StreamType mStreamType;
113 
114   const GUID& GetMFTGUID();
115   const GUID& GetMediaSubtypeGUID();
116 
117   uint32_t mNullOutputCount;
118   bool mGotValidOutputAfterNullOutput;
119   bool mGotExcessiveNullOutput;
120   bool mIsValid;
121 };
122 
123 } // namespace mozilla
124 
125 #endif // WMFVideoMFTManager_h_
126