From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- dom/media/webrtc/libwebrtcglue/WebrtcCallWrapper.h | 114 +++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 dom/media/webrtc/libwebrtcglue/WebrtcCallWrapper.h (limited to 'dom/media/webrtc/libwebrtcglue/WebrtcCallWrapper.h') diff --git a/dom/media/webrtc/libwebrtcglue/WebrtcCallWrapper.h b/dom/media/webrtc/libwebrtcglue/WebrtcCallWrapper.h new file mode 100644 index 0000000000..17054c5f75 --- /dev/null +++ b/dom/media/webrtc/libwebrtcglue/WebrtcCallWrapper.h @@ -0,0 +1,114 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* 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_WEBRTCCALLWRAPPER_H_ +#define DOM_MEDIA_WEBRTC_LIBWEBRTCGLUE_WEBRTCCALLWRAPPER_H_ + +#include + +#include "domstubs.h" +#include "jsapi/RTCStatsReport.h" +#include "nsISupportsImpl.h" +#include "SystemTime.h" + +// libwebrtc includes +#include "api/video/builtin_video_bitrate_allocator_factory.h" +#include "call/call.h" +#include "call/call_config.h" + +namespace mozilla { +class AbstractThread; +class MediaSessionConduit; +class SharedWebrtcState; + +namespace media { +class ShutdownBlockingTicket; +} + +// Wrap the webrtc.org Call class adding mozilla add/ref support. +class WebrtcCallWrapper { + public: + typedef webrtc::CallConfig Config; + + static RefPtr Create( + const dom::RTCStatsTimestampMaker& aTimestampMaker, + UniquePtr aShutdownTicket, + const RefPtr& aSharedState); + + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WebrtcCallWrapper) + + // Don't allow copying/assigning. + WebrtcCallWrapper(const WebrtcCallWrapper&) = delete; + void operator=(const WebrtcCallWrapper&) = delete; + + void SetCall(UniquePtr aCall); + + webrtc::Call* Call() const; + + void UnsetRemoteSSRC(uint32_t aSsrc); + + // Idempotent. + void RegisterConduit(MediaSessionConduit* conduit); + + // Idempotent. + void UnregisterConduit(MediaSessionConduit* conduit); + + // Allow destroying the Call instance on the Call worker thread. + // + // Note that shutdown is blocked until the Call instance is destroyed. + // + // This CallWrapper is designed to be sharable, and is held by several objects + // that are cycle-collectable. TaskQueueWrapper that the Call instances use + // for worker threads are based off SharedThreadPools, and will block + // xpcom-shutdown-threads until destroyed. The Call instance however will hold + // on to its worker threads until destruction. + // + // If the last ref to this CallWrapper is held to cycle collector shutdown we + // end up in a deadlock where cycle collector shutdown is required to destroy + // the SharedThreadPool that is blocking xpcom-shutdown-threads from finishing + // and triggering cycle collector shutdown. + // + // It would be nice to have the invariant where this class is immutable to the + // degree that mCall is const, but given the above that is not possible. + void Destroy(); + + const dom::RTCStatsTimestampMaker& GetTimestampMaker() const; + + protected: + virtual ~WebrtcCallWrapper(); + + WebrtcCallWrapper(RefPtr aSharedState, + UniquePtr + aVideoBitrateAllocatorFactory, + UniquePtr aEventLog, + UniquePtr aTaskQueueFactory, + const dom::RTCStatsTimestampMaker& aTimestampMaker, + UniquePtr aShutdownTicket); + + const RefPtr mSharedState; + + // Allows conduits to know about one another, to avoid remote SSRC + // collisions. + std::set> mConduits; + RTCStatsTimestampMakerRealtimeClock mClock; + UniquePtr mShutdownTicket; + + public: + const RefPtr mCallThread; + const RefPtr mAudioDecoderFactory; + const UniquePtr + mVideoBitrateAllocatorFactory; + const UniquePtr mEventLog; + const UniquePtr mTaskQueueFactory; + + protected: + // Call worker thread only. + UniquePtr mCall; +}; + +} // namespace mozilla + +#endif -- cgit v1.2.3