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 --- dom/media/webrtc/jsapi/MediaTransportHandler.h | 167 +++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 dom/media/webrtc/jsapi/MediaTransportHandler.h (limited to 'dom/media/webrtc/jsapi/MediaTransportHandler.h') diff --git a/dom/media/webrtc/jsapi/MediaTransportHandler.h b/dom/media/webrtc/jsapi/MediaTransportHandler.h new file mode 100644 index 0000000000..a776cb6fd7 --- /dev/null +++ b/dom/media/webrtc/jsapi/MediaTransportHandler.h @@ -0,0 +1,167 @@ +/* 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 _MTRANSPORTHANDLER_H__ +#define _MTRANSPORTHANDLER_H__ + +#include "mozilla/RefPtr.h" +#include "nsISupportsImpl.h" +#include "transport/sigslot.h" +#include "transport/transportlayer.h" // Need the State enum +#include "transport/dtlsidentity.h" // For DtlsDigest +#include "mozilla/dom/RTCPeerConnectionBinding.h" +#include "mozilla/dom/RTCConfigurationBinding.h" +#include "transport/nricectx.h" // Need some enums +#include "common/CandidateInfo.h" +#include "transport/nr_socket_proxy_config.h" +#include "RTCStatsReport.h" + +#include "nsString.h" + +#include +#include +#include + +namespace mozilla { +class DtlsIdentity; +class NrIceCtx; +class NrIceMediaStream; +class NrIceResolver; +class TransportFlow; +class RTCStatsQuery; + +namespace dom { +struct RTCStatsReportInternal; +} + +class MediaTransportHandler { + public: + // Creates either a MediaTransportHandlerSTS or a MediaTransportHandlerIPC, + // as appropriate. If you want signals to fire on a specific thread, pass + // the event target here, otherwise they will fire on whatever is convenient. + // Note: This also determines what thread the state cache is updated on! + // Don't call GetState on any other thread! + static already_AddRefed Create( + nsISerialEventTarget* aCallbackThread); + + explicit MediaTransportHandler(nsISerialEventTarget* aCallbackThread) + : mCallbackThread(aCallbackThread) {} + + // Exposed so we can synchronously validate ICE servers from PeerConnection + static nsresult ConvertIceServers( + const nsTArray& aIceServers, + std::vector* aStunServers, + std::vector* aTurnServers); + + typedef MozPromise, nsresult, true> IceLogPromise; + + virtual void Initialize() {} + + // There's a wrinkle here; the ICE logging is not separated out by + // MediaTransportHandler. These are a little more like static methods, but + // to avoid needing yet another IPC interface, we bolt them on here. + virtual RefPtr GetIceLog(const nsCString& aPattern) = 0; + virtual void ClearIceLog() = 0; + virtual void EnterPrivateMode() = 0; + virtual void ExitPrivateMode() = 0; + + virtual void CreateIceCtx(const std::string& aName) = 0; + + virtual nsresult SetIceConfig(const nsTArray& aIceServers, + dom::RTCIceTransportPolicy aIcePolicy) = 0; + + // We will probably be able to move the proxy lookup stuff into + // this class once we move mtransport to its own process. + virtual void SetProxyConfig(NrSocketProxyConfig&& aProxyConfig) = 0; + + virtual void EnsureProvisionalTransport(const std::string& aTransportId, + const std::string& aLocalUfrag, + const std::string& aLocalPwd, + int aComponentCount) = 0; + + virtual void SetTargetForDefaultLocalAddressLookup( + const std::string& aTargetIp, uint16_t aTargetPort) = 0; + + // We set default-route-only as late as possible because it depends on what + // capture permissions have been granted on the window, which could easily + // change between Init (ie; when the PC is created) and StartIceGathering + // (ie; when we set the local description). + virtual void StartIceGathering(bool aDefaultRouteOnly, + bool aObfuscateHostAddresses, + // TODO: It probably makes sense to look + // this up internally + const nsTArray& aStunAddrs) = 0; + + virtual void ActivateTransport( + const std::string& aTransportId, const std::string& aLocalUfrag, + const std::string& aLocalPwd, size_t aComponentCount, + const std::string& aUfrag, const std::string& aPassword, + const nsTArray& aKeyDer, const nsTArray& aCertDer, + SSLKEAType aAuthType, bool aDtlsClient, const DtlsDigestList& aDigests, + bool aPrivacyRequested) = 0; + + virtual void RemoveTransportsExcept( + const std::set& aTransportIds) = 0; + + virtual void StartIceChecks(bool aIsControlling, + const std::vector& aIceOptions) = 0; + + virtual void SendPacket(const std::string& aTransportId, + MediaPacket&& aPacket) = 0; + + virtual void AddIceCandidate(const std::string& aTransportId, + const std::string& aCandidate, + const std::string& aUFrag, + const std::string& aObfuscatedAddress) = 0; + + virtual void UpdateNetworkState(bool aOnline) = 0; + + virtual RefPtr GetIceStats( + const std::string& aTransportId, DOMHighResTimeStamp aNow) = 0; + + sigslot::signal2 SignalCandidate; + sigslot::signal2 SignalAlpnNegotiated; + sigslot::signal1 SignalGatheringStateChange; + sigslot::signal1 SignalConnectionStateChange; + + sigslot::signal2 SignalPacketReceived; + sigslot::signal2 + SignalEncryptedSending; + sigslot::signal2 SignalStateChange; + sigslot::signal2 + SignalRtcpStateChange; + + NS_INLINE_DECL_THREADSAFE_REFCOUNTING_WITH_DESTROY(MediaTransportHandler, + Destroy()) + + TransportLayer::State GetState(const std::string& aTransportId, + bool aRtcp) const; + + protected: + void OnCandidate(const std::string& aTransportId, + const CandidateInfo& aCandidateInfo); + void OnAlpnNegotiated(const std::string& aAlpn); + void OnGatheringStateChange(dom::RTCIceGatheringState aState); + void OnConnectionStateChange(dom::RTCIceConnectionState aState); + void OnPacketReceived(const std::string& aTransportId, + const MediaPacket& aPacket); + void OnEncryptedSending(const std::string& aTransportId, + const MediaPacket& aPacket); + void OnStateChange(const std::string& aTransportId, + TransportLayer::State aState); + void OnRtcpStateChange(const std::string& aTransportId, + TransportLayer::State aState); + virtual void Destroy() = 0; + virtual ~MediaTransportHandler() = default; + std::map mStateCache; + std::map mRtcpStateCache; + RefPtr mCallbackThread; +}; + +void TokenizeCandidate(const std::string& aCandidate, + std::vector& aTokens); + +} // namespace mozilla + +#endif //_MTRANSPORTHANDLER_H__ -- cgit v1.2.3