/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef DOM_MEDIA_WEBRTC_LIBWEBRTCGLUE_WEBRTCVIDEOCODECFACTORY_H_ #define DOM_MEDIA_WEBRTC_LIBWEBRTCGLUE_WEBRTCVIDEOCODECFACTORY_H_ #include "api/video_codecs/video_decoder_factory.h" #include "api/video_codecs/video_encoder_factory.h" #include "MediaEventSource.h" #include "PerformanceRecorder.h" namespace mozilla { class GmpPluginNotifierInterface { virtual void DisconnectAll() = 0; virtual MediaEventSource& CreatedGmpPluginEvent() = 0; virtual MediaEventSource& ReleasedGmpPluginEvent() = 0; }; class GmpPluginNotifier : public GmpPluginNotifierInterface { public: explicit GmpPluginNotifier(nsCOMPtr aOwningThread) : mOwningThread(std::move(aOwningThread)), mCreatedGmpPluginEvent(mOwningThread), mReleasedGmpPluginEvent(mOwningThread) {} ~GmpPluginNotifier() = default; void DisconnectAll() override { MOZ_ASSERT(mOwningThread->IsOnCurrentThread()); mCreatedGmpPluginEvent.DisconnectAll(); mReleasedGmpPluginEvent.DisconnectAll(); } MediaEventSource& CreatedGmpPluginEvent() override { return mCreatedGmpPluginEvent; } MediaEventSource& ReleasedGmpPluginEvent() override { return mReleasedGmpPluginEvent; } protected: const nsCOMPtr mOwningThread; MediaEventForwarder mCreatedGmpPluginEvent; MediaEventForwarder mReleasedGmpPluginEvent; }; class WebrtcVideoDecoderFactory : public GmpPluginNotifier, public webrtc::VideoDecoderFactory { public: WebrtcVideoDecoderFactory(nsCOMPtr aOwningThread, std::string aPCHandle, TrackingId aTrackingId) : GmpPluginNotifier(std::move(aOwningThread)), mPCHandle(std::move(aPCHandle)), mTrackingId(std::move(aTrackingId)) {} std::vector GetSupportedFormats() const override { MOZ_CRASH("Unexpected call"); return std::vector(); } std::unique_ptr CreateVideoDecoder( const webrtc::SdpVideoFormat& aFormat) override; private: const std::string mPCHandle; const TrackingId mTrackingId; }; class WebrtcVideoEncoderFactory : public GmpPluginNotifierInterface, public webrtc::VideoEncoderFactory { class InternalFactory : public GmpPluginNotifier, public webrtc::VideoEncoderFactory { public: InternalFactory(nsCOMPtr aOwningThread, std::string aPCHandle) : GmpPluginNotifier(std::move(aOwningThread)), mPCHandle(std::move(aPCHandle)) {} std::vector GetSupportedFormats() const override { MOZ_CRASH("Unexpected call"); return std::vector(); } std::unique_ptr CreateVideoEncoder( const webrtc::SdpVideoFormat& aFormat) override; bool Supports(const webrtc::SdpVideoFormat& aFormat); private: const std::string mPCHandle; }; public: explicit WebrtcVideoEncoderFactory( nsCOMPtr aOwningThread, std::string aPCHandle) : mInternalFactory(MakeUnique(std::move(aOwningThread), std::move(aPCHandle))) {} std::vector GetSupportedFormats() const override { MOZ_CRASH("Unexpected call"); return std::vector(); } std::unique_ptr CreateVideoEncoder( const webrtc::SdpVideoFormat& aFormat) override; void DisconnectAll() override { mInternalFactory->DisconnectAll(); } MediaEventSource& CreatedGmpPluginEvent() override { return mInternalFactory->CreatedGmpPluginEvent(); } MediaEventSource& ReleasedGmpPluginEvent() override { return mInternalFactory->ReleasedGmpPluginEvent(); } private: const UniquePtr mInternalFactory; }; } // namespace mozilla #endif