RemoteMediaManagerParent.h (4433B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 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 #ifndef include_dom_media_ipc_RemoteMediaManagerParent_h 7 #define include_dom_media_ipc_RemoteMediaManagerParent_h 8 9 #include "GPUVideoImage.h" 10 #include "mozilla/PRemoteMediaManagerParent.h" 11 #include "mozilla/dom/ipc/IdType.h" 12 #include "mozilla/layers/VideoBridgeChild.h" 13 14 namespace mozilla { 15 16 class PDMFactory; 17 class PMFCDMParent; 18 class PMFMediaEngineParent; 19 20 class RemoteMediaManagerParent final : public PRemoteMediaManagerParent, 21 public layers::IGPUVideoSurfaceManager { 22 friend class PRemoteMediaManagerParent; 23 24 public: 25 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RemoteMediaManagerParent, override) 26 27 static bool CreateForContent(Endpoint<PRemoteMediaManagerParent>&& aEndpoint, 28 dom::ContentParentId aContentId); 29 30 static bool CreateVideoBridgeToOtherProcess( 31 Endpoint<layers::PVideoBridgeChild>&& aEndpoint); 32 33 // Must be called on manager thread. 34 // Store the image so that it can be used out of process. Will be released 35 // when DeallocateSurfaceDescriptor is called. 36 void StoreImage(const SurfaceDescriptorGPUVideo& aSD, layers::Image* aImage, 37 layers::TextureClient* aTexture); 38 39 // IGPUVideoSurfaceManager methods 40 already_AddRefed<gfx::SourceSurface> Readback( 41 const SurfaceDescriptorGPUVideo& aSD) override { 42 MOZ_ASSERT_UNREACHABLE("Not usable from the parent"); 43 return nullptr; 44 } 45 already_AddRefed<layers::Image> TransferToImage( 46 const SurfaceDescriptorGPUVideo& aSD, const gfx::IntSize& aSize, 47 const gfx::ColorDepth& aColorDepth, gfx::YUVColorSpace aYUVColorSpace, 48 gfx::ColorSpace2 aColorPrimaries, gfx::TransferFunction aTransferFunction, 49 gfx::ColorRange aColorRange) override; 50 void DeallocateSurfaceDescriptor( 51 const SurfaceDescriptorGPUVideo& aSD) override; 52 53 void OnSetCurrent(const SurfaceDescriptorGPUVideo& aSD) override { 54 MOZ_ASSERT_UNREACHABLE("Not usable from the parent"); 55 } 56 57 static bool StartupThreads(); 58 static void ShutdownThreads(); 59 60 static void ShutdownVideoBridge(); 61 62 bool OnManagerThread(); 63 static void Dispatch(already_AddRefed<nsIRunnable> aRunnable); 64 65 // Can be called from manager thread only 66 PDMFactory& EnsurePDMFactory(); 67 68 const dom::ContentParentId& GetContentId() const { return mContentId; } 69 70 protected: 71 PRemoteDecoderParent* AllocPRemoteDecoderParent( 72 const RemoteDecoderInfoIPDL& aRemoteDecoderInfo, 73 const CreateDecoderParams::OptionSet& aOptions, 74 const Maybe<layers::TextureFactoryIdentifier>& aIdentifier, 75 const Maybe<uint64_t>& aMediaEngineId, 76 const Maybe<TrackingId>& aTrackingId, PRemoteCDMParent* aCDM); 77 bool DeallocPRemoteDecoderParent(PRemoteDecoderParent* actor); 78 79 already_AddRefed<PRemoteEncoderParent> AllocPRemoteEncoderParent( 80 const EncoderConfig& aConfig); 81 82 PMFMediaEngineParent* AllocPMFMediaEngineParent(); 83 bool DeallocPMFMediaEngineParent(PMFMediaEngineParent* actor); 84 85 PMFCDMParent* AllocPMFCDMParent(const nsAString& aKeySystem); 86 bool DeallocPMFCDMParent(PMFCDMParent* actor); 87 88 PRemoteCDMParent* AllocPRemoteCDMParent(const nsAString& aKeySystem); 89 90 mozilla::ipc::IPCResult RecvReadback(const SurfaceDescriptorGPUVideo& aSD, 91 SurfaceDescriptor* aResult); 92 mozilla::ipc::IPCResult RecvDeallocateSurfaceDescriptorGPUVideo( 93 const SurfaceDescriptorGPUVideo& aSD); 94 mozilla::ipc::IPCResult RecvOnSetCurrent( 95 const SurfaceDescriptorGPUVideo& aSD); 96 97 void ActorDestroy(mozilla::ipc::IProtocol::ActorDestroyReason) override; 98 99 private: 100 RemoteMediaManagerParent(nsISerialEventTarget* aThread, 101 dom::ContentParentId aContentId); 102 ~RemoteMediaManagerParent(); 103 104 void Open(Endpoint<PRemoteMediaManagerParent>&& aEndpoint); 105 106 std::map<uint64_t, RefPtr<layers::Image>> mImageMap; 107 std::map<uint64_t, RefPtr<layers::TextureClient>> mTextureMap; 108 109 nsCOMPtr<nsISerialEventTarget> mThread; 110 RefPtr<PDMFactory> mPDMFactory; 111 dom::ContentParentId mContentId; 112 }; 113 114 } // namespace mozilla 115 116 #endif // include_dom_media_ipc_RemoteMediaManagerParent_h