1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef WidevineVideoDecoder_h_ 7 #define WidevineVideoDecoder_h_ 8 9 #include "stddef.h" 10 #include "content_decryption_module.h" 11 #include "gmp-api/gmp-video-decode.h" 12 #include "gmp-api/gmp-video-host.h" 13 #include "MediaData.h" 14 #include "nsISupportsImpl.h" 15 #include "nsTArray.h" 16 #include "WidevineDecryptor.h" 17 #include "WidevineVideoFrame.h" 18 #include <map> 19 #include <deque> 20 21 namespace mozilla { 22 23 class WidevineVideoDecoder : public GMPVideoDecoder { 24 public: 25 26 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WidevineVideoDecoder) 27 28 WidevineVideoDecoder(GMPVideoHost* aVideoHost, 29 RefPtr<CDMWrapper> aCDMWrapper); 30 void InitDecode(const GMPVideoCodec& aCodecSettings, 31 const uint8_t* aCodecSpecific, 32 uint32_t aCodecSpecificLength, 33 GMPVideoDecoderCallback* aCallback, 34 int32_t aCoreCount) override; 35 void Decode(GMPVideoEncodedFrame* aInputFrame, 36 bool aMissingFrames, 37 const uint8_t* aCodecSpecificInfo, 38 uint32_t aCodecSpecificInfoLength, 39 int64_t aRenderTimeMs = -1) override; 40 void Reset() override; 41 void Drain() override; 42 void DecodingComplete() override; 43 44 private: 45 46 ~WidevineVideoDecoder(); 47 CDM()48 cdm::ContentDecryptionModule_8* CDM() const { 49 // CDM should only be accessed before 'DecodingComplete'. 50 MOZ_ASSERT(mCDMWrapper); 51 // CDMWrapper ensure the CDM is non-null, no need to check again. 52 return mCDMWrapper->GetCDM(); 53 } 54 55 bool ReturnOutput(WidevineVideoFrame& aFrame); 56 void CompleteReset(); 57 58 GMPVideoHost* mVideoHost; 59 RefPtr<CDMWrapper> mCDMWrapper; 60 RefPtr<MediaByteBuffer> mExtraData; 61 RefPtr<MediaByteBuffer> mAnnexB; 62 GMPVideoDecoderCallback* mCallback; 63 std::map<uint64_t, uint64_t> mFrameDurations; 64 bool mSentInput; 65 GMPVideoCodecType mCodecType; 66 // Frames waiting on allocation 67 std::deque<WidevineVideoFrame> mFrameAllocationQueue; 68 // Number of calls of ReturnOutput currently in progress. 69 int32_t mReturnOutputCallDepth; 70 // If we're waiting to drain. Used to prevent drain completing while 71 // ReturnOutput calls are still on the stack. 72 bool mDrainPending; 73 // If a reset is being performed. Used to track if ReturnOutput should 74 // dump current frame. 75 bool mResetInProgress; 76 }; 77 78 } // namespace mozilla 79 80 #endif // WidevineVideoDecoder_h_ 81