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(MFTDecoder_h_) 8 #define MFTDecoder_h_ 9 10 #include "WMF.h" 11 #include "mozilla/RefPtr.h" 12 #include "mozilla/ReentrantMonitor.h" 13 #include "nsIThread.h" 14 15 namespace mozilla { 16 17 class MFTDecoder final { 18 ~MFTDecoder(); 19 20 public: 21 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MFTDecoder) 22 23 MFTDecoder(); 24 25 // Creates the MFT. First thing to do as part of setup. 26 // 27 // Params: 28 // - aMFTClsID the clsid used by CoCreateInstance to instantiate the 29 // decoder MFT. 30 HRESULT Create(const GUID& aMFTClsID); 31 32 // Sets the input and output media types. Call after Init(). 33 // 34 // Params: 35 // - aInputType needs at least major and minor types set. 36 // - aOutputType needs at least major and minor types set. 37 // This is used to select the matching output type out 38 // of all the available output types of the MFT. 39 typedef HRESULT (*ConfigureOutputCallback)(IMFMediaType* aOutputType, void* aData); 40 HRESULT SetMediaTypes(IMFMediaType* aInputType, 41 IMFMediaType* aOutputType, 42 ConfigureOutputCallback aCallback = nullptr, 43 void* aData = nullptr); 44 45 // Returns the MFT's IMFAttributes object. 46 already_AddRefed<IMFAttributes> GetAttributes(); 47 48 // Retrieves the media type being output. This may not be valid until 49 // the first sample is decoded. 50 HRESULT GetOutputMediaType(RefPtr<IMFMediaType>& aMediaType); 51 52 // Submits data into the MFT for processing. 53 // 54 // Returns: 55 // - MF_E_NOTACCEPTING if the decoder can't accept input. The data 56 // must be resubmitted after Output() stops producing output. 57 HRESULT Input(const uint8_t* aData, 58 uint32_t aDataSize, 59 int64_t aTimestampUsecs); 60 HRESULT Input(IMFSample* aSample); 61 62 HRESULT CreateInputSample(const uint8_t* aData, 63 uint32_t aDataSize, 64 int64_t aTimestampUsecs, 65 RefPtr<IMFSample>* aOutSample); 66 67 // Retrieves output from the MFT. Call this once Input() returns 68 // MF_E_NOTACCEPTING. Some MFTs with hardware acceleration (the H.264 69 // decoder MFT in particular) can't handle it if clients hold onto 70 // references to the output IMFSample, so don't do that. 71 // 72 // Returns: 73 // - MF_E_TRANSFORM_STREAM_CHANGE if the underlying stream output 74 // type changed. Retrieve the output media type and reconfig client, 75 // else you may misinterpret the MFT's output. 76 // - MF_E_TRANSFORM_NEED_MORE_INPUT if no output can be produced 77 // due to lack of input. 78 // - S_OK if an output frame is produced. 79 HRESULT Output(RefPtr<IMFSample>* aOutput); 80 81 // Sends a flush message to the MFT. This causes it to discard all 82 // input data. Use before seeking. 83 HRESULT Flush(); 84 85 // Sends a message to the MFT. 86 HRESULT SendMFTMessage(MFT_MESSAGE_TYPE aMsg, ULONG_PTR aData); 87 88 89 HRESULT SetDecoderOutputType(ConfigureOutputCallback aCallback, void* aData); 90 private: 91 92 93 HRESULT CreateOutputSample(RefPtr<IMFSample>* aOutSample); 94 95 MFT_INPUT_STREAM_INFO mInputStreamInfo; 96 MFT_OUTPUT_STREAM_INFO mOutputStreamInfo; 97 98 RefPtr<IMFTransform> mDecoder; 99 100 RefPtr<IMFMediaType> mOutputType; 101 102 // True if the IMFTransform allocates the samples that it returns. 103 bool mMFTProvidesOutputSamples; 104 105 // True if we need to mark the next sample as a discontinuity. 106 bool mDiscontinuity; 107 }; 108 109 } // namespace mozilla 110 111 #endif 112