WMFVideoMFTManager.h (4801B)
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 "MFTDecoder.h" 11 # include "MediaResult.h" 12 # include "PerformanceRecorder.h" 13 # include "WMF.h" 14 # include "WMFDecoderModule.h" 15 # include "WMFMediaDataDecoder.h" 16 # include "mozilla/RefPtr.h" 17 # include "mozilla/gfx/Rect.h" 18 19 namespace mozilla { 20 21 class DXVA2Manager; 22 23 class WMFVideoMFTManager : public MFTManager { 24 public: 25 WMFVideoMFTManager(const VideoInfo& aConfig, 26 layers::KnowsCompositor* aKnowsCompositor, 27 layers::ImageContainer* aImageContainer, float aFramerate, 28 const CreateDecoderParams::OptionSet& aOptions, 29 bool aDXVAEnabled, Maybe<TrackingId> aTrackingId); 30 ~WMFVideoMFTManager(); 31 32 MediaResult Init(); 33 34 HRESULT Input(MediaRawData* aSample) override; 35 36 HRESULT Output(int64_t aStreamOffset, RefPtr<MediaData>& aOutput) override; 37 38 void Flush() override; 39 40 void Shutdown() override; 41 42 bool IsHardwareAccelerated(nsACString& aFailureReason) const override; 43 44 TrackInfo::TrackType GetType() override { return TrackInfo::kVideoTrack; } 45 46 nsCString GetDescriptionName() const override; 47 48 nsCString GetCodecName() const override; 49 50 MediaDataDecoder::ConversionRequired NeedsConversion() const override { 51 return mStreamType == WMFStreamType::H264 || 52 mStreamType == WMFStreamType::HEVC 53 ? MediaDataDecoder::ConversionRequired::kNeedAnnexB 54 : MediaDataDecoder::ConversionRequired::kNeedNone; 55 } 56 57 bool UseZeroCopyVideoFrame() const override; 58 59 private: 60 MediaResult ValidateVideoInfo(); 61 62 bool InitializeDXVA(); 63 64 MediaResult InitInternal(); 65 66 HRESULT CreateBasicVideoFrame(IMFSample* aSample, int64_t aStreamOffset, 67 VideoData** aOutVideoData); 68 69 HRESULT CreateD3DVideoFrame(IMFSample* aSample, int64_t aStreamOffset, 70 VideoData** aOutVideoData); 71 72 HRESULT SetDecoderMediaTypes(const GUID& aFallbackSubType); 73 74 bool CanUseDXVA(IMFMediaType* aInputType, IMFMediaType* aOutputType); 75 76 GUID GetOutputSubtype() const; 77 78 // Gets the duration from aSample, and if an unknown or invalid duration is 79 // returned from WMF, this instead returns the last known input duration. 80 // The sample duration is unknown per `IMFSample::GetSampleDuration` docs 81 // 'If the retrieved duration is zero, or if the method returns 82 // MF_E_NO_SAMPLE_DURATION, the duration is unknown'. The same API also 83 // suggests it may return other unspecified error codes, so we handle those 84 // too. It also returns a signed int, but since a negative duration doesn't 85 // make sense, we also handle that case. 86 media::TimeUnit GetSampleDurationOrLastKnownDuration( 87 IMFSample* aSample) const; 88 89 bool IsHDR() const { 90 return gfx::IsHDRTransferFunction( 91 mVideoInfo.mTransferFunction.refOr(gfx::TransferFunction::BT709)); 92 } 93 94 // Video frame geometry. 95 const VideoInfo mVideoInfo; 96 const gfx::IntSize mImageSize; 97 const WMFStreamType mStreamType; 98 99 // The size we update from the IMFMediaType which might include paddings when 100 // the stream format changes. This is only used for software decoding. 101 gfx::IntSize mSoftwareImageSize; 102 103 // The picture size we update from the IMFMediaType when the stream format 104 // changes. We assume it's equal to the image size by default (no cropping). 105 // This is only used for software decoding. 106 gfx::IntSize mSoftwarePictureSize; 107 108 uint32_t mVideoStride; 109 Maybe<gfx::YUVColorSpace> mColorSpace; 110 gfx::ColorRange mColorRange; 111 gfx::ColorDepth mColorDepth; 112 113 RefPtr<layers::ImageContainer> mImageContainer; 114 RefPtr<layers::KnowsCompositor> mKnowsCompositor; 115 UniquePtr<DXVA2Manager> mDXVA2Manager; 116 117 media::TimeUnit mLastDuration; 118 119 bool mDXVAEnabled; 120 bool mUseHwAccel; 121 122 bool mZeroCopyNV12Texture; 123 124 nsCString mDXVAFailureReason; 125 126 const GUID& GetMediaSubtypeGUID(); 127 128 uint32_t mNullOutputCount = 0; 129 bool mGotValidOutputAfterNullOutput = false; 130 bool mGotExcessiveNullOutput = false; 131 bool mIsValid = true; 132 bool mIMFUsable = false; 133 const float mFramerate; 134 const bool mLowLatency; 135 const bool mKeepOriginalPts; 136 137 PerformanceRecorderMulti<DecodeStage> mPerformanceRecorder; 138 const Maybe<TrackingId> mTrackingId; 139 // Sorted array of pts of input frames, from the encoded input packets, for 140 // error recovery. 141 nsTArray<int64_t> mPTSQueue; 142 }; 143 144 } // namespace mozilla 145 146 #endif // WMFVideoMFTManager_h_