Line data Source code
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 : {
25 : public:
26 :
27 0 : NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WidevineVideoDecoder)
28 :
29 : WidevineVideoDecoder(GMPVideoHost* aVideoHost,
30 : RefPtr<CDMWrapper> aCDMWrapper);
31 : void InitDecode(const GMPVideoCodec& aCodecSettings,
32 : const uint8_t* aCodecSpecific,
33 : uint32_t aCodecSpecificLength,
34 : GMPVideoDecoderCallback* aCallback,
35 : int32_t aCoreCount) override;
36 : void Decode(GMPVideoEncodedFrame* aInputFrame,
37 : bool aMissingFrames,
38 : const uint8_t* aCodecSpecificInfo,
39 : uint32_t aCodecSpecificInfoLength,
40 : int64_t aRenderTimeMs = -1) override;
41 : void Reset() override;
42 : void Drain() override;
43 : void DecodingComplete() override;
44 :
45 : private:
46 :
47 : ~WidevineVideoDecoder();
48 :
49 0 : cdm::ContentDecryptionModule_8* CDM() const
50 : {
51 : // CDM should only be accessed before 'DecodingComplete'.
52 0 : MOZ_ASSERT(mCDMWrapper);
53 : // CDMWrapper ensure the CDM is non-null, no need to check again.
54 0 : return mCDMWrapper->GetCDM();
55 : }
56 :
57 : bool ReturnOutput(WidevineVideoFrame& aFrame);
58 : void CompleteReset();
59 :
60 : GMPVideoHost* mVideoHost;
61 : RefPtr<CDMWrapper> mCDMWrapper;
62 : GMPVideoDecoderCallback* mCallback = nullptr;
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 : cdm::Size mCodedSize;
77 : };
78 :
79 : } // namespace mozilla
80 :
81 : #endif // WidevineVideoDecoder_h_
|