From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../webrtc/libwebrtcglue/WebrtcVideoCodecFactory.h | 124 +++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 dom/media/webrtc/libwebrtcglue/WebrtcVideoCodecFactory.h (limited to 'dom/media/webrtc/libwebrtcglue/WebrtcVideoCodecFactory.h') diff --git a/dom/media/webrtc/libwebrtcglue/WebrtcVideoCodecFactory.h b/dom/media/webrtc/libwebrtcglue/WebrtcVideoCodecFactory.h new file mode 100644 index 0000000000..ef5765043f --- /dev/null +++ b/dom/media/webrtc/libwebrtcglue/WebrtcVideoCodecFactory.h @@ -0,0 +1,124 @@ +/* -*- 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 -- cgit v1.2.3