GMPVideoDecoder.h (4561B)
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 #include "mozilla/layers/KnowsCompositor.h" 8 #if !defined(GMPVideoDecoder_h_) 9 # define GMPVideoDecoder_h_ 10 11 # include "GMPVideoDecoderProxy.h" 12 # include "ImageContainer.h" 13 # include "MediaDataDecoderProxy.h" 14 # include "MediaInfo.h" 15 # include "PerformanceRecorder.h" 16 # include "PlatformDecoderModule.h" 17 # include "ReorderQueue.h" 18 # include "mozIGeckoMediaPluginService.h" 19 # include "mozilla/StaticString.h" 20 # include "nsClassHashtable.h" 21 22 namespace mozilla { 23 24 struct MOZ_STACK_CLASS GMPVideoDecoderParams { 25 explicit GMPVideoDecoderParams(const CreateDecoderParams& aParams); 26 27 const VideoInfo& mConfig; 28 layers::ImageContainer* mImageContainer; 29 GMPCrashHelper* mCrashHelper; 30 layers::KnowsCompositor* mKnowsCompositor; 31 const Maybe<TrackingId> mTrackingId; 32 }; 33 34 DDLoggedTypeDeclNameAndBase(GMPVideoDecoder, MediaDataDecoder); 35 36 class GMPVideoDecoder final : public MediaDataDecoder, 37 public GMPVideoDecoderCallbackProxy, 38 public DecoderDoctorLifeLogger<GMPVideoDecoder> { 39 public: 40 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GMPVideoDecoder, final); 41 42 explicit GMPVideoDecoder(const GMPVideoDecoderParams& aParams); 43 44 RefPtr<InitPromise> Init() override; 45 RefPtr<DecodePromise> Decode(MediaRawData* aSample) override; 46 RefPtr<DecodePromise> Drain() override; 47 RefPtr<FlushPromise> Flush() override; 48 RefPtr<ShutdownPromise> Shutdown() override; 49 nsCString GetDescriptionName() const override { 50 return "gmp video decoder"_ns; 51 } 52 nsCString GetCodecName() const override; 53 ConversionRequired NeedsConversion() const override { 54 return mConvertToAnnexB ? ConversionRequired::kNeedAnnexB 55 : ConversionRequired::kNeedAVCC; 56 } 57 bool CanDecodeBatch() const override { return mCanDecodeBatch; } 58 59 // GMPVideoDecoderCallbackProxy 60 // All those methods are called on the GMP thread. 61 void Decoded(GMPVideoi420Frame* aDecodedFrame) override; 62 void ReceivedDecodedReferenceFrame(const uint64_t aPictureId) override; 63 void ReceivedDecodedFrame(const uint64_t aPictureId) override; 64 void InputDataExhausted() override; 65 void DrainComplete() override; 66 void ResetComplete() override; 67 void Error(GMPErr aErr) override; 68 void Terminated() override; 69 70 protected: 71 virtual void InitTags(nsTArray<nsCString>& aTags); 72 virtual nsCString GetNodeId(); 73 virtual GMPUniquePtr<GMPVideoEncodedFrame> CreateFrame(MediaRawData* aSample); 74 virtual const VideoInfo& GetConfig() const; 75 void ProcessReorderQueue(MozPromiseHolder<DecodePromise>& aPromise, 76 StaticString aMethodName); 77 78 private: 79 ~GMPVideoDecoder() = default; 80 81 class GMPInitDoneCallback : public GetGMPVideoDecoderCallback { 82 public: 83 explicit GMPInitDoneCallback(GMPVideoDecoder* aDecoder) 84 : mDecoder(aDecoder) {} 85 86 void Done(GMPVideoDecoderProxy* aGMP, GMPVideoHost* aHost) override { 87 mDecoder->GMPInitDone(aGMP, aHost); 88 } 89 90 private: 91 RefPtr<GMPVideoDecoder> mDecoder; 92 }; 93 void GMPInitDone(GMPVideoDecoderProxy* aGMP, GMPVideoHost* aHost); 94 void Teardown(const MediaResult& aResult, StaticString aCallSite); 95 96 const VideoInfo mConfig; 97 nsCOMPtr<mozIGeckoMediaPluginService> mMPS; 98 GMPVideoDecoderProxy* mGMP; 99 GMPVideoHost* mHost; 100 bool mConvertNALUnitLengths; 101 MozPromiseHolder<InitPromise> mInitPromise; 102 RefPtr<GMPCrashHelper> mCrashHelper; 103 104 struct SampleMetadata { 105 explicit SampleMetadata(MediaRawData* aSample) 106 : mOffset(aSample->mOffset), mKeyframe(aSample->mKeyframe) {} 107 int64_t mOffset; 108 bool mKeyframe; 109 }; 110 111 nsClassHashtable<nsUint64HashKey, SampleMetadata> mSamples; 112 RefPtr<layers::ImageContainer> mImageContainer; 113 RefPtr<layers::KnowsCompositor> mKnowsCompositor; 114 PerformanceRecorderMulti<DecodeStage> mPerformanceRecorder; 115 const Maybe<TrackingId> mTrackingId; 116 117 uint32_t mMaxRefFrames = 0; 118 ReorderQueue mReorderQueue; 119 DecodedData mUnorderedData; 120 121 MozPromiseHolder<DecodePromise> mDecodePromise; 122 MozPromiseHolder<DecodePromise> mDrainPromise; 123 MozPromiseHolder<FlushPromise> mFlushPromise; 124 bool mConvertToAnnexB = false; 125 bool mCanDecodeBatch = false; 126 bool mReorderFrames = true; 127 }; 128 129 } // namespace mozilla 130 131 #endif // GMPVideoDecoder_h_