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 GMPVideoEncoderParent_h_ 7 #define GMPVideoEncoderParent_h_ 8 9 #include "mozilla/RefPtr.h" 10 #include "gmp-video-encode.h" 11 #include "mozilla/gmp/PGMPVideoEncoderParent.h" 12 #include "GMPMessageUtils.h" 13 #include "GMPSharedMemManager.h" 14 #include "GMPUtils.h" 15 #include "GMPVideoHost.h" 16 #include "GMPVideoEncoderProxy.h" 17 #include "GMPCrashHelperHolder.h" 18 19 namespace mozilla { 20 namespace gmp { 21 22 class GMPContentParent; 23 24 class GMPVideoEncoderParent : public GMPVideoEncoderProxy, 25 public PGMPVideoEncoderParent, 26 public GMPSharedMemManager, 27 public GMPCrashHelperHolder { 28 public: 29 NS_INLINE_DECL_REFCOUNTING(GMPVideoEncoderParent) 30 31 explicit GMPVideoEncoderParent(GMPContentParent* aPlugin); 32 33 GMPVideoHostImpl& Host(); 34 void Shutdown(); 35 36 // GMPVideoEncoderProxy 37 void Close() override; 38 GMPErr InitEncode(const GMPVideoCodec& aCodecSettings, 39 const nsTArray<uint8_t>& aCodecSpecific, 40 GMPVideoEncoderCallbackProxy* aCallback, 41 int32_t aNumberOfCores, uint32_t aMaxPayloadSize) override; 42 GMPErr Encode(GMPUniquePtr<GMPVideoi420Frame> aInputFrame, 43 const nsTArray<uint8_t>& aCodecSpecificInfo, 44 const nsTArray<GMPVideoFrameType>& aFrameTypes) override; 45 GMPErr SetChannelParameters(uint32_t aPacketLoss, uint32_t aRTT) override; 46 GMPErr SetRates(uint32_t aNewBitRate, uint32_t aFrameRate) override; 47 GMPErr SetPeriodicKeyFrames(bool aEnable) override; GetPluginId()48 uint32_t GetPluginId() const override { return mPluginId; } 49 50 // GMPSharedMemManager Alloc(size_t aSize,Shmem::SharedMemory::SharedMemoryType aType,Shmem * aMem)51 bool Alloc(size_t aSize, Shmem::SharedMemory::SharedMemoryType aType, 52 Shmem* aMem) override { 53 #ifdef GMP_SAFE_SHMEM 54 return AllocShmem(aSize, aType, aMem); 55 #else 56 return AllocUnsafeShmem(aSize, aType, aMem); 57 #endif 58 } Dealloc(Shmem & aMem)59 void Dealloc(Shmem& aMem) override { DeallocShmem(aMem); } 60 61 private: ~GMPVideoEncoderParent()62 virtual ~GMPVideoEncoderParent(){}; 63 64 // PGMPVideoEncoderParent 65 void ActorDestroy(ActorDestroyReason aWhy) override; 66 mozilla::ipc::IPCResult RecvEncoded( 67 const GMPVideoEncodedFrameData& aEncodedFrame, 68 InfallibleTArray<uint8_t>&& aCodecSpecificInfo) override; 69 mozilla::ipc::IPCResult RecvError(const GMPErr& aError) override; 70 mozilla::ipc::IPCResult RecvShutdown() override; 71 mozilla::ipc::IPCResult RecvParentShmemForPool(Shmem&& aFrameBuffer) override; 72 mozilla::ipc::IPCResult AnswerNeedShmem(const uint32_t& aEncodedBufferSize, 73 Shmem* aMem) override; 74 mozilla::ipc::IPCResult Recv__delete__() override; 75 76 bool mIsOpen; 77 bool mShuttingDown; 78 bool mActorDestroyed; 79 RefPtr<GMPContentParent> mPlugin; 80 GMPVideoEncoderCallbackProxy* mCallback; 81 GMPVideoHostImpl mVideoHost; 82 const uint32_t mPluginId; 83 }; 84 85 } // namespace gmp 86 } // namespace mozilla 87 88 #endif // GMPVideoEncoderParent_h_ 89