From 4672721b7e3cf1d3397b6b926725d077828086d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Mon, 2 Dec 2024 22:26:13 +0300 Subject: [PATCH 01/69] add LIB_WEBAPI_CALL --- include/rtc_types.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/rtc_types.h b/include/rtc_types.h index 017386d071..b202b175b4 100644 --- a/include/rtc_types.h +++ b/include/rtc_types.h @@ -3,12 +3,16 @@ #ifdef LIB_WEBRTC_API_EXPORTS #define LIB_WEBRTC_API __declspec(dllexport) +#define LIB_WEBAPI_CALL __stdcall #elif defined(LIB_WEBRTC_API_DLL) #define LIB_WEBRTC_API __declspec(dllimport) +#define LIB_WEBAPI_CALL #elif !defined(WIN32) #define LIB_WEBRTC_API __attribute__((visibility("default"))) +#define LIB_WEBAPI_CALL #else #define LIB_WEBRTC_API +#define LIB_WEBAPI_CALL #endif #include "base/fixed_size_function.h" From c3c39237ab18ec84f1222cf4564cee321c8bea41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Mon, 2 Dec 2024 22:38:16 +0300 Subject: [PATCH 02/69] =?UTF-8?q?Geri=20=C3=A7ekme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/rtc_types.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/include/rtc_types.h b/include/rtc_types.h index b202b175b4..017386d071 100644 --- a/include/rtc_types.h +++ b/include/rtc_types.h @@ -3,16 +3,12 @@ #ifdef LIB_WEBRTC_API_EXPORTS #define LIB_WEBRTC_API __declspec(dllexport) -#define LIB_WEBAPI_CALL __stdcall #elif defined(LIB_WEBRTC_API_DLL) #define LIB_WEBRTC_API __declspec(dllimport) -#define LIB_WEBAPI_CALL #elif !defined(WIN32) #define LIB_WEBRTC_API __attribute__((visibility("default"))) -#define LIB_WEBAPI_CALL #else #define LIB_WEBRTC_API -#define LIB_WEBAPI_CALL #endif #include "base/fixed_size_function.h" From 92ae88ae67451c4226667fe07877a9be3e87fb27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Wed, 4 Dec 2024 11:03:32 +0300 Subject: [PATCH 03/69] First interop methods added. --- BUILD.gn | 9 +++++ include/interop_api.h | 73 ++++++++++++++++++++++++++++++++++++++++ src/libwebrtc_interop.cc | 33 ++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 include/interop_api.h create mode 100644 src/libwebrtc_interop.cc diff --git a/BUILD.gn b/BUILD.gn index bcb7ce7ac1..76b4115b59 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1,6 +1,7 @@ import("../webrtc.gni") declare_args() { + libwebrtc_interop = true libwebrtc_intel_media_sdk = false libwebrtc_desktop_capture = true } @@ -148,6 +149,14 @@ rtc_shared_library("libwebrtc") { "src/rtc_video_track_impl.cc", "src/rtc_video_track_impl.h", ] + + # for interop methods + if (is_win && libwebrtc_interop) { + sources += [ + "include/interop_api.h", + "src/libwebrtc_interop.cc", + ] + } # intel media sdk if (is_win && libwebrtc_intel_media_sdk) { diff --git a/include/interop_api.h b/include/interop_api.h new file mode 100644 index 0000000000..5e30ac0932 --- /dev/null +++ b/include/interop_api.h @@ -0,0 +1,73 @@ +#ifndef LIB_WEBRTC_INTROP_API_HXX +#define LIB_WEBRTC_INTROP_API_HXX + +#ifdef LIB_WEBRTC_API_EXPORTS +#define LIB_WEBRTC_CALL __stdcall +#elif defined(LIB_WEBRTC_API_DLL) +#define LIB_WEBRTC_CALL __stdcall +#else +#define LIB_WEBRTC_CALL +#endif + +#include "rtc_types.h" + +extern "C" { + +/// 32-bit boolean for interop API. +enum class rtcBool32 : int { kTrue = -1, kFalse = 0 }; + +/// Opaque handle to a native interop object. +using rtcObjectHandle = void*; + +/// Opaque handle to a native reference-counted interop object. +using rtcRefCountedObjectHandle = rtcObjectHandle; + +/// Opaque handle to a native RTCPeerConnectionFactory interop object. +using rtcPeerConnectionFactoryHandle = rtcRefCountedObjectHandle; + +/** + * @brief Initializes the WebRTC PeerConnectionFactory and threads. + * + * Initializes the WebRTC PeerConnectionFactory and threads. This method is + * thread-safe and can be called from any thread. It initializes SSL and + * creates three threads: worker_thread, signaling_thread and network_thread. + * + * @return kTrue if initialization is successful, kFalse otherwise. + */ +LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL +LibWebRTC_Initialize() noexcept; + +/** + * @brief Creates a new WebRTC PeerConnectionFactory. + * + * Creates a new WebRTC PeerConnectionFactory. This method is thread-safe and + * can be called from any thread. It creates a new instance of the + * RTCPeerConnectionFactoryImpl class and initializes it. + * + * @return A scoped_refptr object that points to the newly created + * RTCPeerConnectionFactory. + */ +LIB_WEBRTC_API rtcPeerConnectionFactoryHandle LIB_WEBRTC_CALL +LibWebRTC_CreateRTCPeerConnectionFactory() noexcept; + +/** + * @brief Terminates the WebRTC PeerConnectionFactory and threads. + * + * Terminates the WebRTC PeerConnectionFactory and threads. This method is + * thread-safe and can be called from any thread. It cleans up SSL and stops + * and destroys the three threads: worker_thread, signaling_thread and + * network_thread. + * + */ +LIB_WEBRTC_API void LIB_WEBRTC_CALL +LibWebRTC_Terminate() noexcept; + +/** + * Release a pointer. + */ +LIB_WEBRTC_API int LIB_WEBRTC_CALL +LibWebRTC_Release(rtcRefCountedObjectHandle handle) noexcept; + +} // extern "C" + +#endif // LIB_WEBRTC_INTROP_API_HXX \ No newline at end of file diff --git a/src/libwebrtc_interop.cc b/src/libwebrtc_interop.cc new file mode 100644 index 0000000000..8bf5044a46 --- /dev/null +++ b/src/libwebrtc_interop.cc @@ -0,0 +1,33 @@ +#include "interop_api.h" +#include "rtc_peerconnection_factory.h" +#include "libwebrtc.h" + +using namespace libwebrtc; + +rtcBool32 LIB_WEBRTC_CALL LibWebRTC_Initialize() noexcept +{ + return LibWebRTC::Initialize() + ? rtcBool32::kTrue + : rtcBool32::kFalse; +} + +rtcPeerConnectionFactoryHandle LIB_WEBRTC_CALL LibWebRTC_CreateRTCPeerConnectionFactory() noexcept +{ + scoped_refptr p = LibWebRTC::CreateRTCPeerConnectionFactory(); + p->AddRef(); + return static_cast(p.get()); +} + +void LIB_WEBRTC_CALL LibWebRTC_Terminate() noexcept +{ + LibWebRTC::Terminate(); +} + +int LIB_WEBRTC_CALL LibWebRTC_Release(rtcRefCountedObjectHandle handle) noexcept +{ + if (handle == NULL) { + return -1; + } + scoped_refptr p = static_cast(handle); + return p->Release(); +} \ No newline at end of file From 789ed0c239600f80935afcb63fc683b14d404ae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Wed, 4 Dec 2024 13:26:14 +0300 Subject: [PATCH 04/69] add ref_counted_object --- BUILD.gn | 3 ++- include/interop_api.h | 8 +++++++- src/{ => interop}/libwebrtc_interop.cc | 0 src/interop/ref_counted_object_interop.cc | 21 +++++++++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) rename src/{ => interop}/libwebrtc_interop.cc (100%) create mode 100644 src/interop/ref_counted_object_interop.cc diff --git a/BUILD.gn b/BUILD.gn index 76b4115b59..2b53c591cc 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -154,7 +154,8 @@ rtc_shared_library("libwebrtc") { if (is_win && libwebrtc_interop) { sources += [ "include/interop_api.h", - "src/libwebrtc_interop.cc", + "src/interop/ref_counted_object_interop.cc", + "src/interop/libwebrtc_interop.cc", ] } diff --git a/include/interop_api.h b/include/interop_api.h index 5e30ac0932..4482e20261 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -62,11 +62,17 @@ LibWebRTC_CreateRTCPeerConnectionFactory() noexcept; LIB_WEBRTC_API void LIB_WEBRTC_CALL LibWebRTC_Terminate() noexcept; +/** + * Add ref a pointer. + */ +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RefCountedObject_AddRef(rtcRefCountedObjectHandle handle) noexcept; + /** * Release a pointer. */ LIB_WEBRTC_API int LIB_WEBRTC_CALL -LibWebRTC_Release(rtcRefCountedObjectHandle handle) noexcept; +RefCountedObject_Release(rtcRefCountedObjectHandle handle) noexcept; } // extern "C" diff --git a/src/libwebrtc_interop.cc b/src/interop/libwebrtc_interop.cc similarity index 100% rename from src/libwebrtc_interop.cc rename to src/interop/libwebrtc_interop.cc diff --git a/src/interop/ref_counted_object_interop.cc b/src/interop/ref_counted_object_interop.cc new file mode 100644 index 0000000000..d6fe1eb2d5 --- /dev/null +++ b/src/interop/ref_counted_object_interop.cc @@ -0,0 +1,21 @@ +#include "interop_api.h" + +using namespace libwebrtc; + +int LIB_WEBRTC_CALL RefCountedObject_AddRef(rtcRefCountedObjectHandle handle) noexcept +{ + if (handle == NULL) { + return -1; + } + scoped_refptr p = static_cast(handle); + return p->AddRef(); +} + +int LIB_WEBRTC_CALL RefCountedObject_Release(rtcRefCountedObjectHandle handle) noexcept +{ + if (handle == NULL) { + return -1; + } + scoped_refptr p = static_cast(handle); + return p->Release(); +} \ No newline at end of file From c6a550c14a04f72a24ef32b369d553945803d14d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Wed, 4 Dec 2024 13:30:36 +0300 Subject: [PATCH 05/69] bugfix --- src/interop/libwebrtc_interop.cc | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/interop/libwebrtc_interop.cc b/src/interop/libwebrtc_interop.cc index 8bf5044a46..4722482635 100644 --- a/src/interop/libwebrtc_interop.cc +++ b/src/interop/libwebrtc_interop.cc @@ -22,12 +22,3 @@ void LIB_WEBRTC_CALL LibWebRTC_Terminate() noexcept { LibWebRTC::Terminate(); } - -int LIB_WEBRTC_CALL LibWebRTC_Release(rtcRefCountedObjectHandle handle) noexcept -{ - if (handle == NULL) { - return -1; - } - scoped_refptr p = static_cast(handle); - return p->Release(); -} \ No newline at end of file From d931b251cc4831325c54c496601b41d47474d0f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Thu, 5 Dec 2024 03:28:08 +0300 Subject: [PATCH 06/69] minor fix refCount --- src/interop/libwebrtc_interop.cc | 3 +-- src/interop/ref_counted_object_interop.cc | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/interop/libwebrtc_interop.cc b/src/interop/libwebrtc_interop.cc index 4722482635..ab96ef4fa1 100644 --- a/src/interop/libwebrtc_interop.cc +++ b/src/interop/libwebrtc_interop.cc @@ -14,8 +14,7 @@ rtcBool32 LIB_WEBRTC_CALL LibWebRTC_Initialize() noexcept rtcPeerConnectionFactoryHandle LIB_WEBRTC_CALL LibWebRTC_CreateRTCPeerConnectionFactory() noexcept { scoped_refptr p = LibWebRTC::CreateRTCPeerConnectionFactory(); - p->AddRef(); - return static_cast(p.get()); + return static_cast(p.release()); } void LIB_WEBRTC_CALL LibWebRTC_Terminate() noexcept diff --git a/src/interop/ref_counted_object_interop.cc b/src/interop/ref_counted_object_interop.cc index d6fe1eb2d5..90a0146de9 100644 --- a/src/interop/ref_counted_object_interop.cc +++ b/src/interop/ref_counted_object_interop.cc @@ -7,7 +7,7 @@ int LIB_WEBRTC_CALL RefCountedObject_AddRef(rtcRefCountedObjectHandle handle) no if (handle == NULL) { return -1; } - scoped_refptr p = static_cast(handle); + RefCountInterface* p = static_cast(handle); return p->AddRef(); } @@ -16,6 +16,6 @@ int LIB_WEBRTC_CALL RefCountedObject_Release(rtcRefCountedObjectHandle handle) n if (handle == NULL) { return -1; } - scoped_refptr p = static_cast(handle); + RefCountInterface* p = static_cast(handle); return p->Release(); } \ No newline at end of file From 3e025a4ad895aa881e2af1b6b41cef192799310b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Thu, 5 Dec 2024 22:47:33 +0300 Subject: [PATCH 07/69] add rtc_peerconnection_factory_interop.cc --- BUILD.gn | 1 + include/interop_api.h | 331 ++++++++++++++++++ src/interop/ref_counted_object_interop.cc | 4 +- .../rtc_peerconnection_factory_interop.cc | 320 +++++++++++++++++ 4 files changed, 654 insertions(+), 2 deletions(-) create mode 100644 src/interop/rtc_peerconnection_factory_interop.cc diff --git a/BUILD.gn b/BUILD.gn index 2b53c591cc..45a645c31a 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -156,6 +156,7 @@ rtc_shared_library("libwebrtc") { "include/interop_api.h", "src/interop/ref_counted_object_interop.cc", "src/interop/libwebrtc_interop.cc", + "src/interop/rtc_peerconnection_factory_interop.cc", ] } diff --git a/include/interop_api.h b/include/interop_api.h index 4482e20261..64af3f30fc 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -11,11 +11,146 @@ #include "rtc_types.h" +#define CHECK_POINTER_EX(p, r) if ((p) == nullptr) { return (r); } +#define CHECK_POINTER(p) CHECK_POINTER_EX((p), rtcResultU4::kInvalidPointer) +#define CHECK_OUT_POINTER(p) if ((p) != nullptr) { *(p) = nullptr; } else { return rtcResultU4::kInvalidPointer; } +#define CHECK_NATIVE_HANDLE(h) CHECK_POINTER_EX((h), rtcResultU4::kInvalidNativeHandle) + extern "C" { +/// Types used from libwebrtc. +using IceTransportsType = libwebrtc::IceTransportsType; +using BundlePolicy = libwebrtc::BundlePolicy; +using RtcpMuxPolicy = libwebrtc::RtcpMuxPolicy; +using CandidateNetworkPolicy = libwebrtc::CandidateNetworkPolicy; +using TcpCandidatePolicy = libwebrtc::TcpCandidatePolicy; +using MediaSecurityType = libwebrtc::MediaSecurityType; +using SdpSemantics = libwebrtc::SdpSemantics; +using RTCMediaType = libwebrtc::RTCMediaType; + /// 32-bit boolean for interop API. enum class rtcBool32 : int { kTrue = -1, kFalse = 0 }; +/// 32-bit result enumerator +enum class rtcResultU4 : unsigned int { + /// The operation was successful. + kSuccess = 0, + + // + // Generic errors + // + + /// Unknown internal error. + /// This is generally the fallback value when no other error code applies. + kUnknownError = 0x80000000, + + /// A parameter passed to the API function was invalid. + kInvalidParameter = 0x80000001, + + /// The operation cannot be performed in the current state. + kInvalidOperation = 0x80000002, + + /// A call was made to an API function on the wrong thread. + /// This is generally related to platforms with thread affinity like UWP. + kWrongThread = 0x80000003, + + /// An object was not found. + kNotFound = 0x80000004, + + /// An interop handle referencing a native object instance is invalid, + /// although the API function was expecting a valid object. + kInvalidNativeHandle = 0x80000005, + + /// The API object is not initialized, and cannot as a result perform the + /// given operation. + kNotInitialized = 0x80000006, + + /// The current operation is not supported by the implementation. + kUnsupported = 0x80000007, + + /// An argument was passed to the API function with a value out of the + /// expected range. + kOutOfRange = 0x80000008, + + /// The buffer provided by the caller was too small for the operation to + /// complete successfully. + kBufferTooSmall = 0x80000009, + + // + // Peer connection (0x1xx) + // + + /// The peer connection is closed, but the current operation requires an open + /// peer connection. + kPeerConnectionClosed = 0x80000101, + + // + // Data (0x3xx) + // + + /// The SCTP handshake for data channels encryption was not performed, because + /// the connection was established before any data channel was added to it. + /// Due to limitations in the implementation, without SCTP handshake data + /// channels cannot be used, and therefor applications expecting to use data + /// channels must open at least a single channel before establishing a peer + /// connection (calling |CreateOffer()|). + kSctpNotNegotiated = 0x80000301, + + /// The specified data channel ID is invalid. + kInvalidDataChannelId = 0x80000302, + + // + // Media (0x4xx) + // + + /// Some audio-only function was called on a video-only object or vice-versa. + /// For example, trying to get the local audio track of a video transceiver. + kInvalidMediaKind = 0x80000401, + + /// The internal audio resampler used in the audio track read buffer doesn't + /// support the specified input/output frequency ratio. Use a different output + /// frequency for the current audio source to solve the issue. + kAudioResamplingNotSupported = 0x80000402, + + /// Error rtcResultU4 for a null or invalid pointer. + kInvalidPointer = 0x80004003, +}; // end enum class rtcResultU4 + +struct rtcIceServer { + const char* uri = nullptr; + const char* username = nullptr; + const char* password = nullptr; +}; + +struct rtcPeerConnectionConfiguration { + rtcIceServer ice_servers[libwebrtc::kMaxIceServerSize]; + IceTransportsType type = IceTransportsType::kAll; + BundlePolicy bundle_policy = BundlePolicy::kBundlePolicyBalanced; + RtcpMuxPolicy rtcp_mux_policy = RtcpMuxPolicy::kRtcpMuxPolicyRequire; + CandidateNetworkPolicy candidate_network_policy = + CandidateNetworkPolicy::kCandidateNetworkPolicyAll; + TcpCandidatePolicy tcp_candidate_policy = + TcpCandidatePolicy::kTcpCandidatePolicyEnabled; + + int ice_candidate_pool_size = 0; + + MediaSecurityType srtp_type = MediaSecurityType::kDTLS_SRTP; + SdpSemantics sdp_semantics = SdpSemantics::kUnifiedPlan; + rtcBool32 offer_to_receive_audio = rtcBool32::kTrue; + rtcBool32 offer_to_receive_video = rtcBool32::kTrue; + + rtcBool32 disable_ipv6 = rtcBool32::kFalse; + rtcBool32 disable_ipv6_on_wifi = rtcBool32::kFalse; + int max_ipv6_networks = 5; + rtcBool32 disable_link_local_networks = rtcBool32::kFalse; + int screencast_min_bitrate = -1; + + // private + rtcBool32 use_rtp_mux = rtcBool32::kTrue; + uint32_t local_audio_bandwidth = 128; + uint32_t local_video_bandwidth = 512; +}; + /// Opaque handle to a native interop object. using rtcObjectHandle = void*; @@ -25,6 +160,49 @@ using rtcRefCountedObjectHandle = rtcObjectHandle; /// Opaque handle to a native RTCPeerConnectionFactory interop object. using rtcPeerConnectionFactoryHandle = rtcRefCountedObjectHandle; +/// Opaque handle to a native RTCPeerConnection interop object. +using rtcPeerConnectionHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCAudioDevice interop object. +using rtcAudioDeviceHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCVideoDevice interop object. +using rtcVideoDeviceHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCAudioSource interop object. +using rtcAudioSourceHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCVideoSource interop object. +using rtcVideoSourceHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCVideoCapturer interop object. +using rtcVideoCapturerHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCMediaConstraints interop object. +using rtcMediaConstraintsHandle = rtcRefCountedObjectHandle; + +#ifdef RTC_DESKTOP_DEVICE +/// Opaque handle to a native RTCDesktopDevice interop object. +using rtcDesktopDeviceHandle = rtcRefCountedObjectHandle; +/// Opaque handle to a native RTCDesktopCapturer interop object. +using rtcDesktopCapturerHandle = rtcRefCountedObjectHandle; +#endif + +/// Opaque handle to a native RTCMediaStream interop object. +using rtcMediaStreamHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCRtpCapabilities interop object. +using rtcRtpCapabilitiesHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCMediaTrack interop object. +using rtcMediaTrackHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCAudioTrack interop object. +using rtcAudioTrackHandle = rtcMediaTrackHandle; + +/// Opaque handle to a native RTCVideoTrack interop object. +using rtcVideoTrackHandle = rtcMediaTrackHandle; + /** * @brief Initializes the WebRTC PeerConnectionFactory and threads. * @@ -74,6 +252,159 @@ RefCountedObject_AddRef(rtcRefCountedObjectHandle handle) noexcept; LIB_WEBRTC_API int LIB_WEBRTC_CALL RefCountedObject_Release(rtcRefCountedObjectHandle handle) noexcept; +/** + * Initializes the RTCPeerConnectionFactor object. + * If the LibWebRTC_Initialize method has been called; + * do not use this method. + */ +LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_Initialize( + rtcPeerConnectionFactoryHandle factory +) noexcept; + +/** + * Terminates the RTCPeerConnectionFactor object. + */ +LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_Terminate( + rtcPeerConnectionFactoryHandle factory +) noexcept; + +/** + * Creates a new instance of the RTCPeerConnection object. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_Create( + rtcPeerConnectionFactoryHandle factory, + const rtcPeerConnectionConfiguration* configuration, + rtcMediaConstraintsHandle constraints, + rtcPeerConnectionHandle* pRetVal) noexcept; + +/** + * Removes the RTCPeerConnection object from the factory. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_Delete( + rtcPeerConnectionFactoryHandle factory, + rtcPeerConnectionHandle handle +) noexcept; + +/** + * Provides RTCAudioDevice object for list audio devices. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_GetAudioDevice( + rtcPeerConnectionFactoryHandle factory, + rtcAudioDeviceHandle* pRetVal +) noexcept; + +/** + * Provides RTCVideoDevice object for list video devices. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_GetVideoDevice( + rtcPeerConnectionFactoryHandle factory, + rtcVideoDeviceHandle* pRetVal +) noexcept; + +#ifdef RTC_DESKTOP_DEVICE +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_GetDesktopDevice( + rtcPeerConnectionFactoryHandle factory, + rtcDesktopDeviceHandle* pRetVal +) noexcept; +#endif // RTC_DESKTOP_DEVICE + +/** + * Creates a new instance of the RTCAudioSource object. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_CreateAudioSource( + rtcPeerConnectionFactoryHandle factory, + const char* audio_source_label, + rtcAudioSourceHandle* pRetVal +) noexcept; + +/** + * Creates a new instance of the RTCVideoSource object. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_CreateVideoSource( + rtcPeerConnectionFactoryHandle factory, + rtcVideoCapturerHandle capturer, + const char* video_source_label, + rtcMediaConstraintsHandle constraints, + rtcVideoSourceHandle* pRetVal +) noexcept; + +#ifdef RTC_DESKTOP_DEVICE +/** + * Creates a new instance of the RTCVideoSource object. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_CreateDesktopSource( + rtcPeerConnectionFactoryHandle factory, + rtcDesktopCapturerHandle capturer, + const char* video_source_label, + rtcMediaConstraintsHandle constraints, + rtcVideoSourceHandle* pRetVal +) noexcept; +#endif // RTC_DESKTOP_DEVICE + +/** + * Creates a new instance of the RTCAudioTrack object. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_CreateAudioTrack( + rtcPeerConnectionFactoryHandle factory, + rtcAudioSourceHandle source, + const char* track_id, + rtcAudioTrackHandle* pRetVal +) noexcept; + +/** + * Creates a new instance of the RTCVideoTrack object. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_CreateVideoTrack( + rtcPeerConnectionFactoryHandle factory, + rtcVideoSourceHandle source, + const char* track_id, + rtcVideoTrackHandle* pRetVal +) noexcept; + +/** + * Creates a new instance of the RTCMediaStream object. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_CreateStream( + rtcPeerConnectionFactoryHandle factory, + const char* stream_id, + rtcMediaStreamHandle* pRetVal +) noexcept; + +/** + * Returns an RTCRtpCapabilities object containing the + * sender's capabilities. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_GetRtpSenderCapabilities( + rtcPeerConnectionFactoryHandle factory, + RTCMediaType media_type, + rtcRtpCapabilitiesHandle* pRetVal +) noexcept; + +/** + * Returns an RTCRtpCapabilities object containing the + * receiver's capabilities. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_GetRtpReceiverCapabilities( + rtcPeerConnectionFactoryHandle factory, + RTCMediaType media_type, + rtcRtpCapabilitiesHandle* pRetVal +) noexcept; + } // extern "C" #endif // LIB_WEBRTC_INTROP_API_HXX \ No newline at end of file diff --git a/src/interop/ref_counted_object_interop.cc b/src/interop/ref_counted_object_interop.cc index 90a0146de9..16a2cc3924 100644 --- a/src/interop/ref_counted_object_interop.cc +++ b/src/interop/ref_counted_object_interop.cc @@ -4,7 +4,7 @@ using namespace libwebrtc; int LIB_WEBRTC_CALL RefCountedObject_AddRef(rtcRefCountedObjectHandle handle) noexcept { - if (handle == NULL) { + if (handle == nullptr) { return -1; } RefCountInterface* p = static_cast(handle); @@ -13,7 +13,7 @@ int LIB_WEBRTC_CALL RefCountedObject_AddRef(rtcRefCountedObjectHandle handle) no int LIB_WEBRTC_CALL RefCountedObject_Release(rtcRefCountedObjectHandle handle) noexcept { - if (handle == NULL) { + if (handle == nullptr) { return -1; } RefCountInterface* p = static_cast(handle); diff --git a/src/interop/rtc_peerconnection_factory_interop.cc b/src/interop/rtc_peerconnection_factory_interop.cc new file mode 100644 index 0000000000..4563bac3d5 --- /dev/null +++ b/src/interop/rtc_peerconnection_factory_interop.cc @@ -0,0 +1,320 @@ +#include "src/rtc_mediaconstraints_impl.h" +#include "src/rtc_peerconnection_factory_impl.h" + +#include "interop_api.h" + +using namespace libwebrtc; + +string string_from_cstr(const char* source) +{ + return (source) ? string(source) : string(); +} + +RTCConfiguration CreateRtcConfiguration(const rtcPeerConnectionConfiguration* configuration) +{ + RTCConfiguration result; + if (configuration == nullptr) { + return result; + } + + for (int i = 0; i < kMaxIceServerSize; i++) { + result.ice_servers[i].uri = string_from_cstr(configuration->ice_servers[i].uri); + result.ice_servers[i].username = string_from_cstr(configuration->ice_servers[i].username); + result.ice_servers[i].password = string_from_cstr(configuration->ice_servers[i].password); + } + result.type = configuration->type; + result.bundle_policy = configuration->bundle_policy; + result.rtcp_mux_policy = configuration->rtcp_mux_policy; + result.candidate_network_policy = configuration->candidate_network_policy; + result.tcp_candidate_policy = configuration->tcp_candidate_policy; + result.ice_candidate_pool_size = configuration->ice_candidate_pool_size; + result.srtp_type = configuration->srtp_type; + result.sdp_semantics = configuration->sdp_semantics; + result.offer_to_receive_audio = configuration->offer_to_receive_audio != rtcBool32::kFalse; + result.offer_to_receive_video = configuration->offer_to_receive_video != rtcBool32::kFalse; + result.disable_ipv6 = configuration->disable_ipv6 != rtcBool32::kFalse; + result.disable_ipv6_on_wifi = configuration->disable_ipv6_on_wifi != rtcBool32::kFalse; + result.max_ipv6_networks = configuration->max_ipv6_networks; + result.disable_link_local_networks = configuration->disable_link_local_networks != rtcBool32::kFalse; + result.screencast_min_bitrate = configuration->screencast_min_bitrate; + result.use_rtp_mux = configuration->use_rtp_mux != rtcBool32::kFalse; + result.local_audio_bandwidth = configuration->local_audio_bandwidth; + result.local_video_bandwidth = configuration->local_video_bandwidth; + + return result; +} + +rtcBool32 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_Initialize( + rtcPeerConnectionFactoryHandle factory +) noexcept +{ + if (factory == nullptr) { + return rtcBool32::kFalse; + } + + scoped_refptr pFactory = static_cast(factory); + return pFactory->Initialize() + ? rtcBool32::kTrue + : rtcBool32::kFalse; +} // end RTCPeerConnectionFactory_Initialize + +rtcBool32 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_Terminate( + rtcPeerConnectionFactoryHandle factory +) noexcept +{ + if (factory == nullptr) { + return rtcBool32::kFalse; + } + + scoped_refptr pFactory = static_cast(factory); + return pFactory->Terminate() + ? rtcBool32::kTrue + : rtcBool32::kFalse; +} // end RTCPeerConnectionFactory_Terminate + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_Create( + rtcPeerConnectionFactoryHandle factory, + const rtcPeerConnectionConfiguration* configuration, + rtcMediaConstraintsHandle constraints, + rtcPeerConnectionHandle* pRetVal) noexcept +{ + CHECK_OUT_POINTER(pRetVal); + CHECK_NATIVE_HANDLE(factory); + + RTCConfiguration rtcConfig = CreateRtcConfiguration(configuration); + scoped_refptr pFactory = static_cast(factory); + scoped_refptr media_constraints = (constraints == nullptr) + ? RTCMediaConstraints::Create() + : scoped_refptr(static_cast(constraints)); + scoped_refptr peer_connection = pFactory->Create(rtcConfig, media_constraints); + + /// The 'release' operation preserves the pointer. + *pRetVal = static_cast(peer_connection.release()); + return rtcResultU4::kSuccess; +} // end RTCPeerConnectionFactory_Create + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_Delete( + rtcPeerConnectionFactoryHandle factory, + rtcPeerConnectionHandle handle +) noexcept +{ + CHECK_NATIVE_HANDLE(factory); + CHECK_POINTER_EX(handle, rtcResultU4::kInvalidParameter); + + scoped_refptr pFactory = static_cast(factory); + scoped_refptr peer_connection = static_cast(handle); + pFactory->Delete(peer_connection); + + return rtcResultU4::kSuccess; +} // end RTCPeerConnectionFactory_Delete + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_GetAudioDevice( + rtcPeerConnectionFactoryHandle factory, + rtcAudioDeviceHandle* pRetVal +) noexcept +{ + CHECK_OUT_POINTER(pRetVal); + CHECK_NATIVE_HANDLE(factory); + + scoped_refptr pFactory = static_cast(factory); + scoped_refptr audio_device = pFactory->GetAudioDevice(); + + /// The 'release' operation preserves the pointer. + *pRetVal = static_cast(audio_device.release()); + return rtcResultU4::kSuccess; +} // end RTCPeerConnectionFactory_GetAudioDevice + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_GetVideoDevice( + rtcPeerConnectionFactoryHandle factory, + rtcVideoDeviceHandle* pRetVal +) noexcept +{ + CHECK_OUT_POINTER(pRetVal); + CHECK_NATIVE_HANDLE(factory); + + scoped_refptr pFactory = static_cast(factory); + scoped_refptr video_device = pFactory->GetVideoDevice(); + + *pRetVal = static_cast(video_device.release()); + return rtcResultU4::kSuccess; +} // end RTCPeerConnectionFactory_GetVideoDevice + +#ifdef RTC_DESKTOP_DEVICE +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_GetDesktopDevice( + rtcPeerConnectionFactoryHandle factory, + rtcDesktopDeviceHandle* pRetVal +) noexcept +{ + CHECK_OUT_POINTER(pRetVal); + CHECK_NATIVE_HANDLE(factory); + + scoped_refptr pFactory = static_cast(factory); + scoped_refptr desktop_device = pFactory->GetDesktopDevice(); + + *pRetVal = static_cast(desktop_device.release()); + return rtcResultU4::kSuccess; +} // end RTCPeerConnectionFactory_GetDesktopDevice +#endif // RTC_DESKTOP_DEVICE + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_CreateAudioSource( + rtcPeerConnectionFactoryHandle factory, + const char* audio_source_label, + rtcAudioSourceHandle* pRetVal +) noexcept +{ + CHECK_OUT_POINTER(pRetVal); + CHECK_NATIVE_HANDLE(factory); + + scoped_refptr pFactory = static_cast(factory); + scoped_refptr audio_source = pFactory->CreateAudioSource(string_from_cstr(audio_source_label)); + + *pRetVal = static_cast(audio_source.release()); + return rtcResultU4::kSuccess; +} // end RTCPeerConnectionFactory_CreateAudioSource + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_CreateVideoSource( + rtcPeerConnectionFactoryHandle factory, + rtcVideoCapturerHandle capturer, + const char* video_source_label, + rtcMediaConstraintsHandle constraints, + rtcVideoSourceHandle* pRetVal +) noexcept +{ + CHECK_OUT_POINTER(pRetVal); + CHECK_NATIVE_HANDLE(factory); + CHECK_POINTER_EX(capturer, rtcResultU4::kInvalidParameter); + + scoped_refptr pFactory = static_cast(factory); + scoped_refptr video_capturer = static_cast(capturer); + /// A null value is accepted for 'constraints'. + scoped_refptr media_constraints = static_cast(constraints); + scoped_refptr video_source = pFactory->CreateVideoSource(video_capturer, string_from_cstr(video_source_label), media_constraints); + + *pRetVal = static_cast(video_source.release()); + return rtcResultU4::kSuccess; +} // end RTCPeerConnectionFactory_CreateVideoSource + +#ifdef RTC_DESKTOP_DEVICE +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_CreateDesktopSource( + rtcPeerConnectionFactoryHandle factory, + rtcDesktopCapturerHandle capturer, + const char* video_source_label, + rtcMediaConstraintsHandle constraints, + rtcVideoSourceHandle* pRetVal +) noexcept +{ + CHECK_OUT_POINTER(pRetVal); + CHECK_NATIVE_HANDLE(factory); + CHECK_POINTER_EX(capturer, rtcResultU4::kInvalidParameter); + + scoped_refptr pFactory = static_cast(factory); + scoped_refptr desktop_capturer = static_cast(capturer); + /// A null value is accepted for 'constraints'. + scoped_refptr media_constraints = static_cast(constraints); + scoped_refptr video_source = pFactory->CreateDesktopSource(desktop_capturer, string_from_cstr(video_source_label), media_constraints); + + *pRetVal = static_cast(video_source.release()); + return rtcResultU4::kSuccess; +} // end RTCPeerConnectionFactory_CreateDesktopSource +#endif // RTC_DESKTOP_DEVICE + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_CreateAudioTrack( + rtcPeerConnectionFactoryHandle factory, + rtcAudioSourceHandle source, + const char* track_id, + rtcAudioTrackHandle* pRetVal +) noexcept +{ + CHECK_OUT_POINTER(pRetVal); + CHECK_NATIVE_HANDLE(factory); + CHECK_POINTER_EX(source, rtcResultU4::kInvalidParameter); + + scoped_refptr pFactory = static_cast(factory); + scoped_refptr audio_source = static_cast(source); + scoped_refptr audio_track = pFactory->CreateAudioTrack(audio_source, string_from_cstr(track_id)); + + *pRetVal = static_cast(audio_track.release()); + return rtcResultU4::kSuccess; +} // end RTCPeerConnectionFactory_CreateAudioTrack + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_CreateVideoTrack( + rtcPeerConnectionFactoryHandle factory, + rtcVideoSourceHandle source, + const char* track_id, + rtcVideoTrackHandle* pRetVal +) noexcept +{ + CHECK_OUT_POINTER(pRetVal); + CHECK_NATIVE_HANDLE(factory); + CHECK_POINTER_EX(source, rtcResultU4::kInvalidParameter); + + scoped_refptr pFactory = static_cast(factory); + scoped_refptr video_source = static_cast(source); + scoped_refptr video_track = pFactory->CreateVideoTrack(video_source, string_from_cstr(track_id)); + + *pRetVal = static_cast(video_track.release()); + return rtcResultU4::kSuccess; +} // end RTCPeerConnectionFactory_CreateVideoTrack + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_CreateStream( + rtcPeerConnectionFactoryHandle factory, + const char* stream_id, + rtcMediaStreamHandle* pRetVal +) noexcept +{ + CHECK_OUT_POINTER(pRetVal); + CHECK_NATIVE_HANDLE(factory); + + scoped_refptr pFactory = static_cast(factory); + scoped_refptr media_stream = pFactory->CreateStream(string_from_cstr(stream_id)); + + *pRetVal = static_cast(media_stream.release()); + return rtcResultU4::kSuccess; +} // end RTCPeerConnectionFactory_CreateStream + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_GetRtpSenderCapabilities( + rtcPeerConnectionFactoryHandle factory, + RTCMediaType media_type, + rtcRtpCapabilitiesHandle* pRetVal +) noexcept +{ + CHECK_OUT_POINTER(pRetVal); + CHECK_NATIVE_HANDLE(factory); + + scoped_refptr pFactory = static_cast(factory); + scoped_refptr rtp_capabilities = pFactory->GetRtpSenderCapabilities(media_type); + + *pRetVal = static_cast(rtp_capabilities.release()); + return rtcResultU4::kSuccess; +} // end RTCPeerConnectionFactory_GetRtpSenderCapabilities + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_GetRtpReceiverCapabilities( + rtcPeerConnectionFactoryHandle factory, + RTCMediaType media_type, + rtcRtpCapabilitiesHandle* pRetVal +) noexcept +{ + CHECK_OUT_POINTER(pRetVal); + CHECK_NATIVE_HANDLE(factory); + + scoped_refptr pFactory = static_cast(factory); + scoped_refptr rtp_capabilities = pFactory->GetRtpReceiverCapabilities(media_type); + + *pRetVal = static_cast(rtp_capabilities.release()); + return rtcResultU4::kSuccess; +} // end RTCPeerConnectionFactory_GetRtpReceiverCapabilities From 8cc2e33f2b1aad7b9f82c3b042b3d1ce22c26b8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Fri, 6 Dec 2024 16:55:28 +0300 Subject: [PATCH 08/69] restore RTCPeerConnectionFactory_Create method --- include/interop_api.h | 10 ++++++++-- .../rtc_peerconnection_factory_interop.cc | 17 +++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/interop_api.h b/include/interop_api.h index 64af3f30fc..1cab0027f1 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -252,6 +252,12 @@ RefCountedObject_AddRef(rtcRefCountedObjectHandle handle) noexcept; LIB_WEBRTC_API int LIB_WEBRTC_CALL RefCountedObject_Release(rtcRefCountedObjectHandle handle) noexcept; +/** + * Creates a new instance of the RTCPeerConnectionFactor object. + */ +LIB_WEBRTC_API rtcPeerConnectionFactoryHandle LIB_WEBRTC_CALL +RTCPeerConnectionFactory_Create() noexcept; + /** * Initializes the RTCPeerConnectionFactor object. * If the LibWebRTC_Initialize method has been called; @@ -274,7 +280,7 @@ RTCPeerConnectionFactory_Terminate( * Creates a new instance of the RTCPeerConnection object. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCPeerConnectionFactory_Create( +RTCPeerConnectionFactory_CreatePeerConnection( rtcPeerConnectionFactoryHandle factory, const rtcPeerConnectionConfiguration* configuration, rtcMediaConstraintsHandle constraints, @@ -284,7 +290,7 @@ RTCPeerConnectionFactory_Create( * Removes the RTCPeerConnection object from the factory. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCPeerConnectionFactory_Delete( +RTCPeerConnectionFactory_DeletePeerConnection( rtcPeerConnectionFactoryHandle factory, rtcPeerConnectionHandle handle ) noexcept; diff --git a/src/interop/rtc_peerconnection_factory_interop.cc b/src/interop/rtc_peerconnection_factory_interop.cc index 4563bac3d5..ab8e82dc6b 100644 --- a/src/interop/rtc_peerconnection_factory_interop.cc +++ b/src/interop/rtc_peerconnection_factory_interop.cc @@ -44,6 +44,15 @@ RTCConfiguration CreateRtcConfiguration(const rtcPeerConnectionConfiguration* co return result; } +rtcPeerConnectionFactoryHandle LIB_WEBRTC_CALL +RTCPeerConnectionFactory_Create() noexcept +{ + scoped_refptr rtc_peerconnection_factory = + scoped_refptr( + new RefCountedObject()); + return static_cast(rtc_peerconnection_factory.release()); +} // end RTCPeerConnectionFactory_Create + rtcBool32 LIB_WEBRTC_CALL RTCPeerConnectionFactory_Initialize( rtcPeerConnectionFactoryHandle factory @@ -75,7 +84,7 @@ RTCPeerConnectionFactory_Terminate( } // end RTCPeerConnectionFactory_Terminate rtcResultU4 LIB_WEBRTC_CALL -RTCPeerConnectionFactory_Create( +RTCPeerConnectionFactory_CreatePeerConnection( rtcPeerConnectionFactoryHandle factory, const rtcPeerConnectionConfiguration* configuration, rtcMediaConstraintsHandle constraints, @@ -94,10 +103,10 @@ RTCPeerConnectionFactory_Create( /// The 'release' operation preserves the pointer. *pRetVal = static_cast(peer_connection.release()); return rtcResultU4::kSuccess; -} // end RTCPeerConnectionFactory_Create +} // end RTCPeerConnectionFactory_CreatePeerConnection rtcResultU4 LIB_WEBRTC_CALL -RTCPeerConnectionFactory_Delete( +RTCPeerConnectionFactory_DeletePeerConnection( rtcPeerConnectionFactoryHandle factory, rtcPeerConnectionHandle handle ) noexcept @@ -110,7 +119,7 @@ RTCPeerConnectionFactory_Delete( pFactory->Delete(peer_connection); return rtcResultU4::kSuccess; -} // end RTCPeerConnectionFactory_Delete +} // end RTCPeerConnectionFactory_DeletePeerConnection rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_GetAudioDevice( From 7c212c3a1ce5892da9f7ebf536bc86f0d36faaa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Fri, 6 Dec 2024 18:14:59 +0300 Subject: [PATCH 09/69] Added rtc_mediaconstraints_interop.cc --- BUILD.gn | 1 + include/interop_api.h | 6 ++++++ src/interop/rtc_mediaconstraints_interop.cc | 12 ++++++++++++ 3 files changed, 19 insertions(+) create mode 100644 src/interop/rtc_mediaconstraints_interop.cc diff --git a/BUILD.gn b/BUILD.gn index 45a645c31a..bfc26652f6 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -156,6 +156,7 @@ rtc_shared_library("libwebrtc") { "include/interop_api.h", "src/interop/ref_counted_object_interop.cc", "src/interop/libwebrtc_interop.cc", + "src/interop/rtc_mediaconstraints_interop.cc", "src/interop/rtc_peerconnection_factory_interop.cc", ] } diff --git a/include/interop_api.h b/include/interop_api.h index 1cab0027f1..0e21283a69 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -252,6 +252,12 @@ RefCountedObject_AddRef(rtcRefCountedObjectHandle handle) noexcept; LIB_WEBRTC_API int LIB_WEBRTC_CALL RefCountedObject_Release(rtcRefCountedObjectHandle handle) noexcept; +/** + * Creates a new instance of the RTCMediaConstraints object. + */ +LIB_WEBRTC_API rtcMediaConstraintsHandle LIB_WEBRTC_CALL +MediaConstraints_Create() noexcept; + /** * Creates a new instance of the RTCPeerConnectionFactor object. */ diff --git a/src/interop/rtc_mediaconstraints_interop.cc b/src/interop/rtc_mediaconstraints_interop.cc new file mode 100644 index 0000000000..7b9f9ae6b5 --- /dev/null +++ b/src/interop/rtc_mediaconstraints_interop.cc @@ -0,0 +1,12 @@ +#include "rtc_mediaconstraints.h" +#include "src/rtc_mediaconstraints_impl.h" +#include "interop_api.h" + +using namespace libwebrtc; + +rtcMediaConstraintsHandle LIB_WEBRTC_CALL +MediaConstraints_Create() noexcept +{ + scoped_refptr media_constraints = RTCMediaConstraints::Create(); + return static_cast(media_constraints.release()); +} \ No newline at end of file From f847d80d24700c22720bac9bee54c3462a6357eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Fri, 6 Dec 2024 18:36:19 +0300 Subject: [PATCH 10/69] Updated portable.h --- include/base/portable.h | 6 +++- include/interop_api.h | 12 +++++++ src/interop/rtc_mediaconstraints_interop.cc | 32 +++++++++++++++++++ .../rtc_peerconnection_factory_interop.cc | 23 ++++++------- 4 files changed, 58 insertions(+), 15 deletions(-) diff --git a/include/base/portable.h b/include/base/portable.h index b403af9cd3..66f7356a52 100644 --- a/include/base/portable.h +++ b/include/base/portable.h @@ -49,7 +49,11 @@ class string { LIB_PORTABLE_API void init(const char* str, size_t len); LIB_PORTABLE_API void destroy(); - inline string(const char* str) { init(str, strlen(str)); } + inline string(const char* str) + { + const char* strTemp = str ? str : "\0"; + init(strTemp, strlen(strTemp)); + } inline string(const std::string& str) { init(str.c_str(), str.length()); } diff --git a/include/interop_api.h b/include/interop_api.h index 0e21283a69..d6e8bca8c8 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -258,6 +258,18 @@ RefCountedObject_Release(rtcRefCountedObjectHandle handle) noexcept; LIB_WEBRTC_API rtcMediaConstraintsHandle LIB_WEBRTC_CALL MediaConstraints_Create() noexcept; +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +MediaConstraints_AddMandatoryConstraint( + rtcMediaConstraintsHandle handle, + const char* key, + const char* value) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +MediaConstraints_AddOptionalConstraint( + rtcMediaConstraintsHandle handle, + const char* key, + const char* value) noexcept; + /** * Creates a new instance of the RTCPeerConnectionFactor object. */ diff --git a/src/interop/rtc_mediaconstraints_interop.cc b/src/interop/rtc_mediaconstraints_interop.cc index 7b9f9ae6b5..8e6965823a 100644 --- a/src/interop/rtc_mediaconstraints_interop.cc +++ b/src/interop/rtc_mediaconstraints_interop.cc @@ -9,4 +9,36 @@ MediaConstraints_Create() noexcept { scoped_refptr media_constraints = RTCMediaConstraints::Create(); return static_cast(media_constraints.release()); +} + +rtcResultU4 LIB_WEBRTC_CALL +MediaConstraints_AddMandatoryConstraint( + rtcMediaConstraintsHandle handle, + const char* key, + const char* value) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(key, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(value, rtcResultU4::kInvalidParameter); + + scoped_refptr media_constraints = static_cast(handle); + media_constraints->AddMandatoryConstraint(string(key), string(value)); + + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +MediaConstraints_AddOptionalConstraint( + rtcMediaConstraintsHandle handle, + const char* key, + const char* value) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(key, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(value, rtcResultU4::kInvalidParameter); + + scoped_refptr media_constraints = static_cast(handle); + media_constraints->AddOptionalConstraint(string(key), string(value)); + + return rtcResultU4::kSuccess; } \ No newline at end of file diff --git a/src/interop/rtc_peerconnection_factory_interop.cc b/src/interop/rtc_peerconnection_factory_interop.cc index ab8e82dc6b..e575217871 100644 --- a/src/interop/rtc_peerconnection_factory_interop.cc +++ b/src/interop/rtc_peerconnection_factory_interop.cc @@ -5,11 +5,6 @@ using namespace libwebrtc; -string string_from_cstr(const char* source) -{ - return (source) ? string(source) : string(); -} - RTCConfiguration CreateRtcConfiguration(const rtcPeerConnectionConfiguration* configuration) { RTCConfiguration result; @@ -18,9 +13,9 @@ RTCConfiguration CreateRtcConfiguration(const rtcPeerConnectionConfiguration* co } for (int i = 0; i < kMaxIceServerSize; i++) { - result.ice_servers[i].uri = string_from_cstr(configuration->ice_servers[i].uri); - result.ice_servers[i].username = string_from_cstr(configuration->ice_servers[i].username); - result.ice_servers[i].password = string_from_cstr(configuration->ice_servers[i].password); + result.ice_servers[i].uri = string(configuration->ice_servers[i].uri); + result.ice_servers[i].username = string(configuration->ice_servers[i].username); + result.ice_servers[i].password = string(configuration->ice_servers[i].password); } result.type = configuration->type; result.bundle_policy = configuration->bundle_policy; @@ -183,7 +178,7 @@ RTCPeerConnectionFactory_CreateAudioSource( CHECK_NATIVE_HANDLE(factory); scoped_refptr pFactory = static_cast(factory); - scoped_refptr audio_source = pFactory->CreateAudioSource(string_from_cstr(audio_source_label)); + scoped_refptr audio_source = pFactory->CreateAudioSource(string(audio_source_label)); *pRetVal = static_cast(audio_source.release()); return rtcResultU4::kSuccess; @@ -206,7 +201,7 @@ RTCPeerConnectionFactory_CreateVideoSource( scoped_refptr video_capturer = static_cast(capturer); /// A null value is accepted for 'constraints'. scoped_refptr media_constraints = static_cast(constraints); - scoped_refptr video_source = pFactory->CreateVideoSource(video_capturer, string_from_cstr(video_source_label), media_constraints); + scoped_refptr video_source = pFactory->CreateVideoSource(video_capturer, string(video_source_label), media_constraints); *pRetVal = static_cast(video_source.release()); return rtcResultU4::kSuccess; @@ -230,7 +225,7 @@ RTCPeerConnectionFactory_CreateDesktopSource( scoped_refptr desktop_capturer = static_cast(capturer); /// A null value is accepted for 'constraints'. scoped_refptr media_constraints = static_cast(constraints); - scoped_refptr video_source = pFactory->CreateDesktopSource(desktop_capturer, string_from_cstr(video_source_label), media_constraints); + scoped_refptr video_source = pFactory->CreateDesktopSource(desktop_capturer, string(video_source_label), media_constraints); *pRetVal = static_cast(video_source.release()); return rtcResultU4::kSuccess; @@ -251,7 +246,7 @@ RTCPeerConnectionFactory_CreateAudioTrack( scoped_refptr pFactory = static_cast(factory); scoped_refptr audio_source = static_cast(source); - scoped_refptr audio_track = pFactory->CreateAudioTrack(audio_source, string_from_cstr(track_id)); + scoped_refptr audio_track = pFactory->CreateAudioTrack(audio_source, string(track_id)); *pRetVal = static_cast(audio_track.release()); return rtcResultU4::kSuccess; @@ -271,7 +266,7 @@ RTCPeerConnectionFactory_CreateVideoTrack( scoped_refptr pFactory = static_cast(factory); scoped_refptr video_source = static_cast(source); - scoped_refptr video_track = pFactory->CreateVideoTrack(video_source, string_from_cstr(track_id)); + scoped_refptr video_track = pFactory->CreateVideoTrack(video_source, string(track_id)); *pRetVal = static_cast(video_track.release()); return rtcResultU4::kSuccess; @@ -288,7 +283,7 @@ RTCPeerConnectionFactory_CreateStream( CHECK_NATIVE_HANDLE(factory); scoped_refptr pFactory = static_cast(factory); - scoped_refptr media_stream = pFactory->CreateStream(string_from_cstr(stream_id)); + scoped_refptr media_stream = pFactory->CreateStream(string(stream_id)); *pRetVal = static_cast(media_stream.release()); return rtcResultU4::kSuccess; From acf2e3486f78eb3134109eefa9676ad9a1a6a67e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Sat, 7 Dec 2024 03:21:15 +0300 Subject: [PATCH 11/69] Added LibWebRTC_GetErrorMessage method --- include/interop_api.h | 38 ++++++++------- src/interop/libwebrtc_interop.cc | 81 ++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 16 deletions(-) diff --git a/include/interop_api.h b/include/interop_api.h index d6e8bca8c8..36d8fb7dc5 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -241,19 +241,25 @@ LIB_WEBRTC_API void LIB_WEBRTC_CALL LibWebRTC_Terminate() noexcept; /** - * Add ref a pointer. + * @brief Returns the error message text for the specified 'code' value. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +LibWebRTC_GetErrorMessage(rtcResultU4 code, char** pRetVal) noexcept; + +/** + * @brief Add ref a pointer. */ LIB_WEBRTC_API int LIB_WEBRTC_CALL RefCountedObject_AddRef(rtcRefCountedObjectHandle handle) noexcept; /** - * Release a pointer. + * @brief Release a pointer. */ LIB_WEBRTC_API int LIB_WEBRTC_CALL RefCountedObject_Release(rtcRefCountedObjectHandle handle) noexcept; /** - * Creates a new instance of the RTCMediaConstraints object. + * @brief Creates a new instance of the RTCMediaConstraints object. */ LIB_WEBRTC_API rtcMediaConstraintsHandle LIB_WEBRTC_CALL MediaConstraints_Create() noexcept; @@ -271,13 +277,13 @@ MediaConstraints_AddOptionalConstraint( const char* value) noexcept; /** - * Creates a new instance of the RTCPeerConnectionFactor object. + * @brief Creates a new instance of the RTCPeerConnectionFactor object. */ LIB_WEBRTC_API rtcPeerConnectionFactoryHandle LIB_WEBRTC_CALL RTCPeerConnectionFactory_Create() noexcept; /** - * Initializes the RTCPeerConnectionFactor object. + * @brief Initializes the RTCPeerConnectionFactor object. * If the LibWebRTC_Initialize method has been called; * do not use this method. */ @@ -287,7 +293,7 @@ RTCPeerConnectionFactory_Initialize( ) noexcept; /** - * Terminates the RTCPeerConnectionFactor object. + * @brief Terminates the RTCPeerConnectionFactor object. */ LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL RTCPeerConnectionFactory_Terminate( @@ -295,7 +301,7 @@ RTCPeerConnectionFactory_Terminate( ) noexcept; /** - * Creates a new instance of the RTCPeerConnection object. + * @brief Creates a new instance of the RTCPeerConnection object. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_CreatePeerConnection( @@ -305,7 +311,7 @@ RTCPeerConnectionFactory_CreatePeerConnection( rtcPeerConnectionHandle* pRetVal) noexcept; /** - * Removes the RTCPeerConnection object from the factory. + * @brief Removes the RTCPeerConnection object from the factory. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_DeletePeerConnection( @@ -314,7 +320,7 @@ RTCPeerConnectionFactory_DeletePeerConnection( ) noexcept; /** - * Provides RTCAudioDevice object for list audio devices. + * @brief Provides RTCAudioDevice object for list audio devices. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_GetAudioDevice( @@ -323,7 +329,7 @@ RTCPeerConnectionFactory_GetAudioDevice( ) noexcept; /** - * Provides RTCVideoDevice object for list video devices. + * @brief Provides RTCVideoDevice object for list video devices. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_GetVideoDevice( @@ -340,7 +346,7 @@ RTCPeerConnectionFactory_GetDesktopDevice( #endif // RTC_DESKTOP_DEVICE /** - * Creates a new instance of the RTCAudioSource object. + * @brief Creates a new instance of the RTCAudioSource object. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_CreateAudioSource( @@ -350,7 +356,7 @@ RTCPeerConnectionFactory_CreateAudioSource( ) noexcept; /** - * Creates a new instance of the RTCVideoSource object. + * @brief Creates a new instance of the RTCVideoSource object. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_CreateVideoSource( @@ -363,7 +369,7 @@ RTCPeerConnectionFactory_CreateVideoSource( #ifdef RTC_DESKTOP_DEVICE /** - * Creates a new instance of the RTCVideoSource object. + * @brief Creates a new instance of the RTCVideoSource object. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_CreateDesktopSource( @@ -376,7 +382,7 @@ RTCPeerConnectionFactory_CreateDesktopSource( #endif // RTC_DESKTOP_DEVICE /** - * Creates a new instance of the RTCAudioTrack object. + * @brief Creates a new instance of the RTCAudioTrack object. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_CreateAudioTrack( @@ -387,7 +393,7 @@ RTCPeerConnectionFactory_CreateAudioTrack( ) noexcept; /** - * Creates a new instance of the RTCVideoTrack object. + * @brief Creates a new instance of the RTCVideoTrack object. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_CreateVideoTrack( @@ -398,7 +404,7 @@ RTCPeerConnectionFactory_CreateVideoTrack( ) noexcept; /** - * Creates a new instance of the RTCMediaStream object. + * @brief Creates a new instance of the RTCMediaStream object. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_CreateStream( diff --git a/src/interop/libwebrtc_interop.cc b/src/interop/libwebrtc_interop.cc index ab96ef4fa1..f668a63118 100644 --- a/src/interop/libwebrtc_interop.cc +++ b/src/interop/libwebrtc_interop.cc @@ -21,3 +21,84 @@ void LIB_WEBRTC_CALL LibWebRTC_Terminate() noexcept { LibWebRTC::Terminate(); } + +rtcResultU4 LIB_WEBRTC_CALL +LibWebRTC_GetErrorMessage(rtcResultU4 code, char** pBuffer, unsigned int cchBuffer) noexcept +{ + CHECK_POINTER(pBuffer); + if (cchBuffer == 0) { + return rtcResultU4::kBufferTooSmall; + } + memset(pBuffer, 0x0, cchBuffer); + + char szBuffer[256] = {0}; + const char* message = ""; + switch (code) + { + case rtcResultU4::kSuccess: + message = "The operation was successful."; + break; + case rtcResultU4::kUnknownError: + message = "Unknown internal error."; + break; + case rtcResultU4::kInvalidParameter: + message = "A parameter passed to the API function was invalid."; + break; + case rtcResultU4::kInvalidOperation: + message = "The operation cannot be performed in the current state."; + break; + case rtcResultU4::kWrongThread: + message = "A call was made to an API function on the wrong thread."; + break; + case rtcResultU4::kNotFound: + message = "An object was not found."; + break; + case rtcResultU4::kInvalidNativeHandle: + message = "An interop handle referencing a native object instance is invalid, although the API function was expecting a valid object."; + break; + case rtcResultU4::kNotInitialized: + message = "The API object is not initialized, and cannot as a result perform the given operation."; + break; + case rtcResultU4::kUnsupported: + message = "The current operation is not supported by the implementation."; + break; + case rtcResultU4::kOutOfRange: + message = "An argument was passed to the API function with a value out of the expected range."; + break; + case rtcResultU4::kBufferTooSmall: + message = "The buffer provided by the caller was too small for the operation to complete successfully."; + break; + case rtcResultU4::kPeerConnectionClosed: + message = "The peer connection is closed, but the current operation requires an open peer connection."; + break; + case rtcResultU4::kSctpNotNegotiated: + message = "The SCTP handshake for data channels encryption was not performed."; + break; + case rtcResultU4::kInvalidDataChannelId: + message = "The specified data channel ID is invalid."; + break; + case rtcResultU4::kInvalidMediaKind: + message = "Some audio-only function was called on a video-only object or vice-versa."; + break; + case rtcResultU4::kAudioResamplingNotSupported: + message= "The internal audio resampler used in the audio track read buffer doesn't support the specified input/output frequency ratio. Use a different output frequency for the current audio source to solve the issue."; + break; + case rtcResultU4::kInvalidPointer: + message = "A null or invalid pointer."; + break; + default: + snprintf(szBuffer, sizeof(szBuffer), "Undefined error: 0x%X", static_cast(code)); + message = (const char*)szBuffer; + break; + } + + unsigned int cchMessage = (unsigned int)strlen(message) + 1; + unsigned int cchLen = cchMessage < cchBuffer + ? cchMessage + : cchBuffer; + strncpy(*pBuffer, message, cchLen); + + return cchMessage > cchBuffer + ? rtcResultU4::kBufferTooSmall + : rtcResultU4::kSuccess; +} From 7910b08d9e6e93ba36ccab24a9f800405058a035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Sat, 7 Dec 2024 03:24:50 +0300 Subject: [PATCH 12/69] Bugfix --- include/interop_api.h | 6 +++++- src/interop/libwebrtc_interop.cc | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/interop_api.h b/include/interop_api.h index 36d8fb7dc5..ed3b2f2ae0 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -244,7 +244,11 @@ LibWebRTC_Terminate() noexcept; * @brief Returns the error message text for the specified 'code' value. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -LibWebRTC_GetErrorMessage(rtcResultU4 code, char** pRetVal) noexcept; +LibWebRTC_GetErrorMessage( + rtcResultU4 code, + char** pBuffer, + unsigned int cchBuffer +) noexcept; /** * @brief Add ref a pointer. diff --git a/src/interop/libwebrtc_interop.cc b/src/interop/libwebrtc_interop.cc index f668a63118..8b604e79a8 100644 --- a/src/interop/libwebrtc_interop.cc +++ b/src/interop/libwebrtc_interop.cc @@ -23,7 +23,11 @@ void LIB_WEBRTC_CALL LibWebRTC_Terminate() noexcept } rtcResultU4 LIB_WEBRTC_CALL -LibWebRTC_GetErrorMessage(rtcResultU4 code, char** pBuffer, unsigned int cchBuffer) noexcept +LibWebRTC_GetErrorMessage( + rtcResultU4 code, + char** pBuffer, + unsigned int cchBuffer +) noexcept { CHECK_POINTER(pBuffer); if (cchBuffer == 0) { From 64ec05433ed670bbb9c5fd8f184673c863f95964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Sat, 7 Dec 2024 04:01:20 +0300 Subject: [PATCH 13/69] Bugfix --- include/interop_api.h | 2 +- src/interop/libwebrtc_interop.cc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/interop_api.h b/include/interop_api.h index ed3b2f2ae0..ddae8c492f 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -246,7 +246,7 @@ LibWebRTC_Terminate() noexcept; LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL LibWebRTC_GetErrorMessage( rtcResultU4 code, - char** pBuffer, + char* pBuffer, unsigned int cchBuffer ) noexcept; diff --git a/src/interop/libwebrtc_interop.cc b/src/interop/libwebrtc_interop.cc index 8b604e79a8..59dcbff768 100644 --- a/src/interop/libwebrtc_interop.cc +++ b/src/interop/libwebrtc_interop.cc @@ -25,7 +25,7 @@ void LIB_WEBRTC_CALL LibWebRTC_Terminate() noexcept rtcResultU4 LIB_WEBRTC_CALL LibWebRTC_GetErrorMessage( rtcResultU4 code, - char** pBuffer, + char* pBuffer, unsigned int cchBuffer ) noexcept { @@ -100,7 +100,7 @@ LibWebRTC_GetErrorMessage( unsigned int cchLen = cchMessage < cchBuffer ? cchMessage : cchBuffer; - strncpy(*pBuffer, message, cchLen); + strncpy(pBuffer, message, cchLen); return cchMessage > cchBuffer ? rtcResultU4::kBufferTooSmall From 0c60df80c4c50394a815d617ef8c9bac4a265fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Mon, 9 Dec 2024 12:34:38 +0300 Subject: [PATCH 14/69] Pre definitions regarding the use of desktop devices have been edited. --- include/interop_api.h | 12 ++++++------ src/interop/rtc_peerconnection_factory_interop.cc | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/interop_api.h b/include/interop_api.h index ddae8c492f..a1fa3f05a5 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -181,12 +181,12 @@ using rtcVideoCapturerHandle = rtcRefCountedObjectHandle; /// Opaque handle to a native RTCMediaConstraints interop object. using rtcMediaConstraintsHandle = rtcRefCountedObjectHandle; -#ifdef RTC_DESKTOP_DEVICE +#if defined(WEBRTC_WIN) && defined(RTC_DESKTOP_DEVICE) /// Opaque handle to a native RTCDesktopDevice interop object. using rtcDesktopDeviceHandle = rtcRefCountedObjectHandle; /// Opaque handle to a native RTCDesktopCapturer interop object. using rtcDesktopCapturerHandle = rtcRefCountedObjectHandle; -#endif +#endif // defined(WEBRTC_WIN) && defined(RTC_DESKTOP_DEVICE) /// Opaque handle to a native RTCMediaStream interop object. using rtcMediaStreamHandle = rtcRefCountedObjectHandle; @@ -341,13 +341,13 @@ RTCPeerConnectionFactory_GetVideoDevice( rtcVideoDeviceHandle* pRetVal ) noexcept; -#ifdef RTC_DESKTOP_DEVICE +#if defined(WEBRTC_WIN) && defined(RTC_DESKTOP_DEVICE) LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_GetDesktopDevice( rtcPeerConnectionFactoryHandle factory, rtcDesktopDeviceHandle* pRetVal ) noexcept; -#endif // RTC_DESKTOP_DEVICE +#endif // defined(WEBRTC_WIN) && defined(RTC_DESKTOP_DEVICE) /** * @brief Creates a new instance of the RTCAudioSource object. @@ -371,7 +371,7 @@ RTCPeerConnectionFactory_CreateVideoSource( rtcVideoSourceHandle* pRetVal ) noexcept; -#ifdef RTC_DESKTOP_DEVICE +#if defined(WEBRTC_WIN) && defined(RTC_DESKTOP_DEVICE) /** * @brief Creates a new instance of the RTCVideoSource object. */ @@ -383,7 +383,7 @@ RTCPeerConnectionFactory_CreateDesktopSource( rtcMediaConstraintsHandle constraints, rtcVideoSourceHandle* pRetVal ) noexcept; -#endif // RTC_DESKTOP_DEVICE +#endif // defined(WEBRTC_WIN) && defined(RTC_DESKTOP_DEVICE) /** * @brief Creates a new instance of the RTCAudioTrack object. diff --git a/src/interop/rtc_peerconnection_factory_interop.cc b/src/interop/rtc_peerconnection_factory_interop.cc index e575217871..9db4f46bb2 100644 --- a/src/interop/rtc_peerconnection_factory_interop.cc +++ b/src/interop/rtc_peerconnection_factory_interop.cc @@ -149,7 +149,7 @@ RTCPeerConnectionFactory_GetVideoDevice( return rtcResultU4::kSuccess; } // end RTCPeerConnectionFactory_GetVideoDevice -#ifdef RTC_DESKTOP_DEVICE +#if defined(WEBRTC_WIN) && defined(RTC_DESKTOP_DEVICE) rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_GetDesktopDevice( rtcPeerConnectionFactoryHandle factory, @@ -165,7 +165,7 @@ RTCPeerConnectionFactory_GetDesktopDevice( *pRetVal = static_cast(desktop_device.release()); return rtcResultU4::kSuccess; } // end RTCPeerConnectionFactory_GetDesktopDevice -#endif // RTC_DESKTOP_DEVICE +#endif // defined(WEBRTC_WIN) && defined(RTC_DESKTOP_DEVICE) rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_CreateAudioSource( @@ -207,7 +207,7 @@ RTCPeerConnectionFactory_CreateVideoSource( return rtcResultU4::kSuccess; } // end RTCPeerConnectionFactory_CreateVideoSource -#ifdef RTC_DESKTOP_DEVICE +#if defined(WEBRTC_WIN) && defined(RTC_DESKTOP_DEVICE) rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_CreateDesktopSource( rtcPeerConnectionFactoryHandle factory, @@ -230,7 +230,7 @@ RTCPeerConnectionFactory_CreateDesktopSource( *pRetVal = static_cast(video_source.release()); return rtcResultU4::kSuccess; } // end RTCPeerConnectionFactory_CreateDesktopSource -#endif // RTC_DESKTOP_DEVICE +#endif // defined(WEBRTC_WIN) && defined(RTC_DESKTOP_DEVICE) rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_CreateAudioTrack( From 0535d5d8348b5e1cfd24de8dfbdc635608b1c8b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Mon, 9 Dec 2024 14:10:51 +0300 Subject: [PATCH 15/69] I will revert the last commit. --- include/interop_api.h | 12 ++++++------ src/interop/rtc_peerconnection_factory_interop.cc | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/interop_api.h b/include/interop_api.h index a1fa3f05a5..b54299e3f4 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -181,12 +181,12 @@ using rtcVideoCapturerHandle = rtcRefCountedObjectHandle; /// Opaque handle to a native RTCMediaConstraints interop object. using rtcMediaConstraintsHandle = rtcRefCountedObjectHandle; -#if defined(WEBRTC_WIN) && defined(RTC_DESKTOP_DEVICE) +#ifdef RTC_DESKTOP_DEVICE /// Opaque handle to a native RTCDesktopDevice interop object. using rtcDesktopDeviceHandle = rtcRefCountedObjectHandle; /// Opaque handle to a native RTCDesktopCapturer interop object. using rtcDesktopCapturerHandle = rtcRefCountedObjectHandle; -#endif // defined(WEBRTC_WIN) && defined(RTC_DESKTOP_DEVICE) +#endif // RTC_DESKTOP_DEVICE /// Opaque handle to a native RTCMediaStream interop object. using rtcMediaStreamHandle = rtcRefCountedObjectHandle; @@ -341,13 +341,13 @@ RTCPeerConnectionFactory_GetVideoDevice( rtcVideoDeviceHandle* pRetVal ) noexcept; -#if defined(WEBRTC_WIN) && defined(RTC_DESKTOP_DEVICE) +#ifdef RTC_DESKTOP_DEVICE LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_GetDesktopDevice( rtcPeerConnectionFactoryHandle factory, rtcDesktopDeviceHandle* pRetVal ) noexcept; -#endif // defined(WEBRTC_WIN) && defined(RTC_DESKTOP_DEVICE) +#endif // RTC_DESKTOP_DEVICE /** * @brief Creates a new instance of the RTCAudioSource object. @@ -371,7 +371,7 @@ RTCPeerConnectionFactory_CreateVideoSource( rtcVideoSourceHandle* pRetVal ) noexcept; -#if defined(WEBRTC_WIN) && defined(RTC_DESKTOP_DEVICE) +#ifdef RTC_DESKTOP_DEVICE /** * @brief Creates a new instance of the RTCVideoSource object. */ @@ -383,7 +383,7 @@ RTCPeerConnectionFactory_CreateDesktopSource( rtcMediaConstraintsHandle constraints, rtcVideoSourceHandle* pRetVal ) noexcept; -#endif // defined(WEBRTC_WIN) && defined(RTC_DESKTOP_DEVICE) +#endif // RTC_DESKTOP_DEVICE /** * @brief Creates a new instance of the RTCAudioTrack object. diff --git a/src/interop/rtc_peerconnection_factory_interop.cc b/src/interop/rtc_peerconnection_factory_interop.cc index 9db4f46bb2..e575217871 100644 --- a/src/interop/rtc_peerconnection_factory_interop.cc +++ b/src/interop/rtc_peerconnection_factory_interop.cc @@ -149,7 +149,7 @@ RTCPeerConnectionFactory_GetVideoDevice( return rtcResultU4::kSuccess; } // end RTCPeerConnectionFactory_GetVideoDevice -#if defined(WEBRTC_WIN) && defined(RTC_DESKTOP_DEVICE) +#ifdef RTC_DESKTOP_DEVICE rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_GetDesktopDevice( rtcPeerConnectionFactoryHandle factory, @@ -165,7 +165,7 @@ RTCPeerConnectionFactory_GetDesktopDevice( *pRetVal = static_cast(desktop_device.release()); return rtcResultU4::kSuccess; } // end RTCPeerConnectionFactory_GetDesktopDevice -#endif // defined(WEBRTC_WIN) && defined(RTC_DESKTOP_DEVICE) +#endif // RTC_DESKTOP_DEVICE rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_CreateAudioSource( @@ -207,7 +207,7 @@ RTCPeerConnectionFactory_CreateVideoSource( return rtcResultU4::kSuccess; } // end RTCPeerConnectionFactory_CreateVideoSource -#if defined(WEBRTC_WIN) && defined(RTC_DESKTOP_DEVICE) +#ifdef RTC_DESKTOP_DEVICE rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_CreateDesktopSource( rtcPeerConnectionFactoryHandle factory, @@ -230,7 +230,7 @@ RTCPeerConnectionFactory_CreateDesktopSource( *pRetVal = static_cast(video_source.release()); return rtcResultU4::kSuccess; } // end RTCPeerConnectionFactory_CreateDesktopSource -#endif // defined(WEBRTC_WIN) && defined(RTC_DESKTOP_DEVICE) +#endif // RTC_DESKTOP_DEVICE rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_CreateAudioTrack( From 1a5ac11a3e2b0bd9a1cb24a4f8167ddc31ae726b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Mon, 9 Dec 2024 19:12:24 +0300 Subject: [PATCH 16/69] Added rtc_audio_device_interop.cc --- BUILD.gn | 1 + include/interop_api.h | 203 ++++++++++++++++++++- src/interop/libwebrtc_interop.cc | 8 +- src/interop/rtc_audio_device_interop.cc | 233 ++++++++++++++++++++++++ 4 files changed, 436 insertions(+), 9 deletions(-) create mode 100644 src/interop/rtc_audio_device_interop.cc diff --git a/BUILD.gn b/BUILD.gn index bfc26652f6..bada7390f1 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -158,6 +158,7 @@ rtc_shared_library("libwebrtc") { "src/interop/libwebrtc_interop.cc", "src/interop/rtc_mediaconstraints_interop.cc", "src/interop/rtc_peerconnection_factory_interop.cc", + "src/interop/rtc_audio_device_interop.cc", ] } diff --git a/include/interop_api.h b/include/interop_api.h index b54299e3f4..7100339f98 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -11,10 +11,11 @@ #include "rtc_types.h" -#define CHECK_POINTER_EX(p, r) if ((p) == nullptr) { return (r); } -#define CHECK_POINTER(p) CHECK_POINTER_EX((p), rtcResultU4::kInvalidPointer) -#define CHECK_OUT_POINTER(p) if ((p) != nullptr) { *(p) = nullptr; } else { return rtcResultU4::kInvalidPointer; } -#define CHECK_NATIVE_HANDLE(h) CHECK_POINTER_EX((h), rtcResultU4::kInvalidNativeHandle) +#define CHECK_POINTER_EX(p, r) if ((p) == nullptr) { return (r); } +#define CHECK_POINTER(p) CHECK_POINTER_EX(p, rtcResultU4::kInvalidPointer) +#define CHECK_OUT_POINTER(p) if ((p) != nullptr) { *(p) = nullptr; } else { return rtcResultU4::kInvalidPointer; } +#define CHECK_NATIVE_HANDLE(h) CHECK_POINTER_EX(h, rtcResultU4::kInvalidNativeHandle) +#define ZERO_MEMORY(p,sz) if ((sz) > 0) { memset((void*)(p), 0, (size_t)(sz)); } extern "C" { @@ -203,6 +204,13 @@ using rtcAudioTrackHandle = rtcMediaTrackHandle; /// Opaque handle to a native RTCVideoTrack interop object. using rtcVideoTrackHandle = rtcMediaTrackHandle; + +/* + * ---------------------------------------------------------------------- + * LibWebRTC interop methods + * ---------------------------------------------------------------------- + */ + /** * @brief Initializes the WebRTC PeerConnectionFactory and threads. * @@ -250,6 +258,13 @@ LibWebRTC_GetErrorMessage( unsigned int cchBuffer ) noexcept; + +/* + * ---------------------------------------------------------------------- + * RefCountedObject interop methods + * ---------------------------------------------------------------------- + */ + /** * @brief Add ref a pointer. */ @@ -262,6 +277,13 @@ RefCountedObject_AddRef(rtcRefCountedObjectHandle handle) noexcept; LIB_WEBRTC_API int LIB_WEBRTC_CALL RefCountedObject_Release(rtcRefCountedObjectHandle handle) noexcept; + +/* + * ---------------------------------------------------------------------- + * MediaConstraints interop methods + * ---------------------------------------------------------------------- + */ + /** * @brief Creates a new instance of the RTCMediaConstraints object. */ @@ -280,6 +302,13 @@ MediaConstraints_AddOptionalConstraint( const char* key, const char* value) noexcept; + +/* + * ---------------------------------------------------------------------- + * RTCPeerConnectionFactory interop methods + * ---------------------------------------------------------------------- + */ + /** * @brief Creates a new instance of the RTCPeerConnectionFactor object. */ @@ -439,6 +468,172 @@ RTCPeerConnectionFactory_GetRtpReceiverCapabilities( rtcRtpCapabilitiesHandle* pRetVal ) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCAudioDevice interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Audio device change callback delegate + */ +using rtcRTCAudioDeviceChangeCallback = void(LIB_WEBRTC_CALL*)(); + +/** + * Returns the number of playout devices available. + * + * @param audiDevice - Audio device handle + * @return int - The number of playout devices available. + */ +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RTCAudioDevice_PlayoutDevices( + rtcAudioDeviceHandle audiDevice +) noexcept; + +/** + * Returns the number of recording devices available. + * + * @param audiDevice - Audio device handle + * @return int - The number of recording devices available. + */ +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RTCAudioDevice_RecordingDevices( + rtcAudioDeviceHandle audiDevice +) noexcept; + +/** + * Retrieves the name and GUID of the specified playout device. + * + * @param audiDevice - Audio device handle + * @param index - The index of the device. + * @param pOutName - The device name. + * @param cchOutName - The size of the name. + * @param pOutGuid - The device GUID. + * @param cchOutGuid - The size of the guid. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_PlayoutDeviceName( + rtcAudioDeviceHandle audiDevice, + int index, + char* pOutName, + int cchOutName, + char* pOutGuid, + int cchOutGuid +) noexcept; + +/** + * Retrieves the name and GUID of the specified recording device. + * + * @param audiDevice - Audio device handle + * @param index - The index of the device. + * @param pOutName - The device name. + * @param cchOutName - The size of the name. + * @param pOutGuid - The device GUID. + * @param cchOutGuid - The size of the guid. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_RecordingDeviceName( + rtcAudioDeviceHandle audiDevice, + int index, + char* pOutName, + int cchOutName, + char* pOutGuid, + int cchOutGuid +) noexcept; + +/** + * Sets the playout device to use. + * + * @param audiDevice - Audio device handle + * @param index - The index of the device. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_SetPlayoutDevice( + rtcAudioDeviceHandle audiDevice, + int index +) noexcept; + +/** + * Sets the recording device to use. + * + * @param audiDevice - Audio device handle + * @param index - The index of the device. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_SetRecordingDevice( + rtcAudioDeviceHandle audiDevice, + int index +) noexcept; + +/** + * The callback was invoked when the audio device changed. + * + * @param audiDevice - Audio device handle + * @param deviceChangeCallback - Callback delegate + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_RegisterDeviceChangeCallback( + rtcAudioDeviceHandle audiDevice, + rtcRTCAudioDeviceChangeCallback deviceChangeCallback +) noexcept; + +/** + * Sets the microphone volume level. + * + * @param audiDevice - Audio device handle + * @param volume - Volume level + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_SetMicrophoneVolume( + rtcAudioDeviceHandle audiDevice, + unsigned int volume +) noexcept; + +/** + * Gets the microphone volume level. + * + * @param audiDevice - Audio device handle + * @param volume - Volume level + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_GetMicrophoneVolume( + rtcAudioDeviceHandle audiDevice, + unsigned int* volume +) noexcept; + +/** + * Sets the speaker volume level. + * + * @param audiDevice - Audio device handle + * @param volume - Volume level + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_SetSpeakerVolume( + rtcAudioDeviceHandle audiDevice, + unsigned int volume +) noexcept; + +/** + * Gets the speaker volume level. + * + * @param audiDevice - Audio device handle + * @param volume - Volume level + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_GetSpeakerVolume( + rtcAudioDeviceHandle audiDevice, + unsigned int* volume +) noexcept; + } // extern "C" #endif // LIB_WEBRTC_INTROP_API_HXX \ No newline at end of file diff --git a/src/interop/libwebrtc_interop.cc b/src/interop/libwebrtc_interop.cc index 59dcbff768..85906e6c67 100644 --- a/src/interop/libwebrtc_interop.cc +++ b/src/interop/libwebrtc_interop.cc @@ -96,11 +96,9 @@ LibWebRTC_GetErrorMessage( break; } - unsigned int cchMessage = (unsigned int)strlen(message) + 1; - unsigned int cchLen = cchMessage < cchBuffer - ? cchMessage - : cchBuffer; - strncpy(pBuffer, message, cchLen); + unsigned int cchMessage = (unsigned int)strlen(message); + unsigned int cchLen = std::min(cchMessage, cchBuffer); + strncpy(pBuffer, (const char*)message, (size_t)cchLen); return cchMessage > cchBuffer ? rtcResultU4::kBufferTooSmall diff --git a/src/interop/rtc_audio_device_interop.cc b/src/interop/rtc_audio_device_interop.cc new file mode 100644 index 0000000000..2d577e1042 --- /dev/null +++ b/src/interop/rtc_audio_device_interop.cc @@ -0,0 +1,233 @@ +#include "rtc_audio_device.h" +//#include "src/rtc_audio_device_impl.h" +#include "interop_api.h" + +using namespace libwebrtc; + +int LIB_WEBRTC_CALL +RTCAudioDevice_PlayoutDevices( + rtcAudioDeviceHandle audiDevice +) noexcept +{ + CHECK_POINTER_EX(audiDevice, 0); + scoped_refptr pAudioDevice = static_cast(audiDevice); + return (int)pAudioDevice->PlayoutDevices(); +} // end RTCAudioDevice_PlayoutDevices + +int LIB_WEBRTC_CALL +RTCAudioDevice_RecordingDevices( + rtcAudioDeviceHandle audiDevice +) noexcept +{ + CHECK_POINTER_EX(audiDevice, 0); + scoped_refptr pAudioDevice = static_cast(audiDevice); + return (int)pAudioDevice->RecordingDevices(); +} // end RTCAudioDevice_RecordingDevices + +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_PlayoutDeviceName( + rtcAudioDeviceHandle audiDevice, + int index, + char* pOutName, + int cchOutName, + char* pOutGuid, + int cchOutGuid +) noexcept +{ + CHECK_NATIVE_HANDLE(audiDevice); + CHECK_POINTER(pOutName); + CHECK_POINTER(pOutGuid); + if (cchOutName <= 0 && cchOutGuid <= 0) { + return rtcResultU4::kBufferTooSmall; + } + ZERO_MEMORY(pOutName, cchOutName); + ZERO_MEMORY(pOutGuid, cchOutGuid); + + char szName[RTCAudioDevice::kAdmMaxDeviceNameSize] = {0}; + char szGuid[RTCAudioDevice::kAdmMaxGuidSize] = {0}; + scoped_refptr pAudioDevice = static_cast(audiDevice); + + rtcResultU4 result = (rtcResultU4)pAudioDevice->PlayoutDeviceName((uint16_t)index, szName, szGuid); + if (result != rtcResultU4::kSuccess) { + return result; + } + + int nSrcNameLen = ((int)strlen(szName)); + if (nSrcNameLen > cchOutName) { + result = rtcResultU4::kBufferTooSmall; + } + int nSrcGuidLen = ((int)strlen(szGuid)); + if (nSrcGuidLen > cchOutGuid) { + result = rtcResultU4::kBufferTooSmall; + } + + int nNameLen = std::min(cchOutName, nSrcNameLen); + if (nNameLen > 0) { + strncpy(pOutName, (const char*)szName, nNameLen); + pOutName[nNameLen] = '\0'; + } + + int nGuidLen = std::min(cchOutGuid, nSrcGuidLen); + if (nGuidLen > 0) { + strncpy(pOutGuid, (const char*)szGuid, nGuidLen); + pOutGuid[nGuidLen] = '\0'; + } + + return result; +} // end RTCAudioDevice_PlayoutDeviceName + +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_RecordingDeviceName( + rtcAudioDeviceHandle audiDevice, + int index, + char* pOutName, + int cchOutName, + char* pOutGuid, + int cchOutGuid +) noexcept +{ + CHECK_NATIVE_HANDLE(audiDevice); + CHECK_POINTER(pOutName); + CHECK_POINTER(pOutGuid); + if (cchOutName <= 0 && cchOutGuid <= 0) { + return rtcResultU4::kBufferTooSmall; + } + ZERO_MEMORY(pOutName, cchOutName); + ZERO_MEMORY(pOutGuid, cchOutGuid); + + char szName[RTCAudioDevice::kAdmMaxDeviceNameSize] = {0}; + char szGuid[RTCAudioDevice::kAdmMaxGuidSize] = {0}; + scoped_refptr pAudioDevice = static_cast(audiDevice); + + rtcResultU4 result = (rtcResultU4)pAudioDevice->RecordingDeviceName((uint16_t)index, szName, szGuid); + if (result != rtcResultU4::kSuccess) { + return result; + } + + int nSrcNameLen = ((int)strlen(szName)); + if (nSrcNameLen > cchOutName) { + result = rtcResultU4::kBufferTooSmall; + } + int nSrcGuidLen = ((int)strlen(szGuid)); + if (nSrcGuidLen > cchOutGuid) { + result = rtcResultU4::kBufferTooSmall; + } + + int nNameLen = std::min(cchOutName, nSrcNameLen); + if (nNameLen > 0) { + strncpy(pOutName, (const char*)szName, nNameLen); + pOutName[nNameLen] = '\0'; + } + + int nGuidLen = std::min(cchOutGuid, nSrcGuidLen); + if (nGuidLen > 0) { + strncpy(pOutGuid, (const char*)szGuid, nGuidLen); + pOutGuid[nGuidLen] = '\0'; + } + + return result; +} // end RTCAudioDevice_RecordingDeviceName + +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_SetPlayoutDevice( + rtcAudioDeviceHandle audiDevice, + int index +) noexcept +{ + CHECK_NATIVE_HANDLE(audiDevice); + + scoped_refptr pAudioDevice = static_cast(audiDevice); + int nCount = (int)pAudioDevice->PlayoutDevices(); + if (index < 0 || index >= nCount) { + return rtcResultU4::kOutOfRange; + } + return (rtcResultU4)pAudioDevice->SetPlayoutDevice((uint16_t)index); +} // end RTCAudioDevice_SetPlayoutDevice + +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_SetRecordingDevice( + rtcAudioDeviceHandle audiDevice, + int index +) noexcept +{ + CHECK_NATIVE_HANDLE(audiDevice); + + scoped_refptr pAudioDevice = static_cast(audiDevice); + int nCount = (int)pAudioDevice->RecordingDevices(); + if (index < 0 || index >= nCount) { + return rtcResultU4::kOutOfRange; + } + return (rtcResultU4)pAudioDevice->SetRecordingDevice((uint16_t)index); +} // end RTCAudioDevice_SetRecordingDevice + +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_RegisterDeviceChangeCallback( + rtcAudioDeviceHandle audiDevice, + rtcRTCAudioDeviceChangeCallback deviceChangeCallback +) noexcept +{ + CHECK_NATIVE_HANDLE(audiDevice); + + scoped_refptr pAudioDevice = static_cast(audiDevice); + RTCAudioDevice::OnDeviceChangeCallback cb; + if (deviceChangeCallback == nullptr) { + cb = nullptr; + } + else { + cb = [deviceChangeCallback](void) { + if (deviceChangeCallback) { + deviceChangeCallback(); + } + }; + } + rtcResultU4 result = (rtcResultU4)pAudioDevice->OnDeviceChange(cb); + return result; +} // end RTCAudioDevice_RegisterDeviceChangeCallback + +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_SetMicrophoneVolume( + rtcAudioDeviceHandle audiDevice, + unsigned int volume +) noexcept +{ + CHECK_NATIVE_HANDLE(audiDevice); + scoped_refptr pAudioDevice = static_cast(audiDevice); + rtcResultU4 result = (rtcResultU4)pAudioDevice->SetMicrophoneVolume(volume); + return result; +} // end RTCAudioDevice_SetMicrophoneVolume + +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_GetMicrophoneVolume( + rtcAudioDeviceHandle audiDevice, + unsigned int* volume +) noexcept +{ + CHECK_NATIVE_HANDLE(audiDevice); + scoped_refptr pAudioDevice = static_cast(audiDevice); + rtcResultU4 result = (rtcResultU4)pAudioDevice->MicrophoneVolume(*volume); + return result; +} // end RTCAudioDevice_GetMicrophoneVolume + +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_SetSpeakerVolume( + rtcAudioDeviceHandle audiDevice, + unsigned int volume +) noexcept +{ + CHECK_NATIVE_HANDLE(audiDevice); + scoped_refptr pAudioDevice = static_cast(audiDevice); + rtcResultU4 result = (rtcResultU4)pAudioDevice->SetSpeakerVolume(volume); + return result; +} // end RTCAudioDevice_SetSpeakerVolume + +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_GetSpeakerVolume( + rtcAudioDeviceHandle audiDevice, + unsigned int* volume +) noexcept +{ + CHECK_NATIVE_HANDLE(audiDevice); + scoped_refptr pAudioDevice = static_cast(audiDevice); + rtcResultU4 result = (rtcResultU4)pAudioDevice->SpeakerVolume(*volume); + return result; +} // end RTCAudioDevice_GetSpeakerVolume From c5fae2e53f44ca36285c69cff0fb53f89cf8cad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Tue, 10 Dec 2024 14:34:41 +0300 Subject: [PATCH 17/69] Added rtc_video_device_interop.cc --- BUILD.gn | 1 + include/interop_api.h | 65 +++++++++++++++++++++++ src/interop/rtc_audio_device_interop.cc | 1 - src/interop/rtc_video_device_interop.cc | 69 +++++++++++++++++++++++++ 4 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 src/interop/rtc_video_device_interop.cc diff --git a/BUILD.gn b/BUILD.gn index bada7390f1..77073f7558 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -159,6 +159,7 @@ rtc_shared_library("libwebrtc") { "src/interop/rtc_mediaconstraints_interop.cc", "src/interop/rtc_peerconnection_factory_interop.cc", "src/interop/rtc_audio_device_interop.cc", + "src/interop/rtc_video_device_interop.cc", ] } diff --git a/include/interop_api.h b/include/interop_api.h index 7100339f98..288a402902 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -634,6 +634,71 @@ RTCAudioDevice_GetSpeakerVolume( unsigned int* volume ) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCVideoDevice interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Returns the number of video devices available. + * + * @param videoDevice - Video device handle + * @return int - The number of video devices available. + */ +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RTCVideoDevice_NumberOfDevices( + rtcVideoDeviceHandle videoDevice +) noexcept; + +/** + * Returns information about video device with the specified index. + * + * @param videoDevice - Video device handle + * @param index - The index of the device. + * @param pOutDeviceNameUTF8 - Device name + * @param cchOutDeviceNameUTF8 - The size of the name. + * @param pOutDeviceUniqueIdUTF8 - Device id + * @param cchOutDeviceUniqueIdUTF8 - The size of the id. + * @param pOutProductUniqueIdUTF8 - Device product id + * @param cchOutProductUniqueIdUTF8 - The size of the product id. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoDevice_GetDeviceName( + rtcVideoDeviceHandle videoDevice, + int index, + char* pOutDeviceNameUTF8, + int cchOutDeviceNameUTF8, + char* pOutDeviceUniqueIdUTF8, + int cchOutDeviceUniqueIdUTF8, + char* pOutProductUniqueIdUTF8 = 0, + int cchOutProductUniqueIdUTF8 = 0 +) noexcept; + +/** + * Creates a new instance of the RTCVideoCapturer object. + * + * @param videoDevice - Video device handle + * @param name - Video capturer name (for logs) + * @param index - The index of the video device. + * @param width - Video frame width + * @param height - Video frame height + * @param target_fps - Target frame per second + * @param pOutRetVal - Handle for the RTCVideoCapturer object to be created. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoDevice_CreateVideoCapturer( + rtcVideoDeviceHandle videoDevice, + const char* name, + int index, + int width, + int height, + int target_fps, + rtcVideoCapturerHandle* pOutRetVal +) noexcept; + } // extern "C" #endif // LIB_WEBRTC_INTROP_API_HXX \ No newline at end of file diff --git a/src/interop/rtc_audio_device_interop.cc b/src/interop/rtc_audio_device_interop.cc index 2d577e1042..300acba538 100644 --- a/src/interop/rtc_audio_device_interop.cc +++ b/src/interop/rtc_audio_device_interop.cc @@ -1,5 +1,4 @@ #include "rtc_audio_device.h" -//#include "src/rtc_audio_device_impl.h" #include "interop_api.h" using namespace libwebrtc; diff --git a/src/interop/rtc_video_device_interop.cc b/src/interop/rtc_video_device_interop.cc new file mode 100644 index 0000000000..ae3063266b --- /dev/null +++ b/src/interop/rtc_video_device_interop.cc @@ -0,0 +1,69 @@ +#include "rtc_video_device.h" +#include "interop_api.h" + +using namespace libwebrtc; + +int LIB_WEBRTC_CALL +RTCVideoDevice_NumberOfDevices( + rtcVideoDeviceHandle videoDevice +) noexcept +{ + CHECK_POINTER_EX(videoDevice, 0); + scoped_refptr pVideoDevice = static_cast(videoDevice); + return (int)pVideoDevice->NumberOfDevices(); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoDevice_GetDeviceName( + rtcVideoDeviceHandle videoDevice, + int index, + char* pOutDeviceNameUTF8, + int cchOutDeviceNameUTF8, + char* pOutDeviceUniqueIdUTF8, + int cchOutDeviceUniqueIdUTF8, + char* pOutProductUniqueIdUTF8, + int cchOutProductUniqueIdUTF8 +) noexcept +{ + CHECK_NATIVE_HANDLE(videoDevice); + ZERO_MEMORY(pOutDeviceNameUTF8, cchOutDeviceNameUTF8); + ZERO_MEMORY(pOutDeviceUniqueIdUTF8, cchOutDeviceUniqueIdUTF8); + ZERO_MEMORY(pOutProductUniqueIdUTF8, cchOutProductUniqueIdUTF8); + + scoped_refptr pVideoDevice = static_cast(videoDevice); + rtcResultU4 result = (rtcResultU4)pVideoDevice->GetDeviceName( + (uint32_t)index, + pOutDeviceNameUTF8, (uint32_t)cchOutDeviceNameUTF8, + pOutDeviceUniqueIdUTF8, (uint32_t)cchOutDeviceUniqueIdUTF8, + pOutProductUniqueIdUTF8, (uint32_t)cchOutProductUniqueIdUTF8 + ); + + return result; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoDevice_CreateVideoCapturer( + rtcVideoDeviceHandle videoDevice, + const char* name, + int index, + int width, + int height, + int target_fps, + rtcVideoCapturerHandle* pOutRetVal +) noexcept +{ + CHECK_NATIVE_HANDLE(videoDevice); + scoped_refptr pVideoDevice = static_cast(videoDevice); + scoped_refptr pVideoCapturer = pVideoDevice->Create( + name, + (uint32_t)index, + (size_t)width, + (size_t)height, + (size_t)target_fps + ); + if (pVideoCapturer == nullptr) { + return rtcResultU4::kUnknownError; + } + *pOutRetVal = static_cast(pVideoCapturer.release()); + return rtcResultU4::kSuccess; +} From ec89f5ed1f9e98d353174c65425bb81a08d83c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Tue, 10 Dec 2024 15:07:11 +0300 Subject: [PATCH 18/69] Added RTCVideoCapturer interop methods --- include/interop_api.h | 39 +++++++++++++++++++++++++ src/interop/rtc_video_device_interop.cc | 35 ++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/include/interop_api.h b/include/interop_api.h index 288a402902..d182bdb137 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -699,6 +699,45 @@ RTCVideoDevice_CreateVideoCapturer( rtcVideoCapturerHandle* pOutRetVal ) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCVideoCapturer interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Starts video capturing. + * + * @param videoCapturer - Video capturer handle + * @return rtcBool32 - rtcBool32::kTrue if successful, otherwise rtcBool32::kFalse + */ +LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL +RTCVideoCapturer_StartCapture( + rtcVideoCapturerHandle videoCapturer +) noexcept; + +/** + * Returns whether the capture state has been initialized. + * + * @param videoCapturer - Video capturer handle + * @return rtcBool32 - rtcBool32::kTrue if started, otherwise rtcBool32::kFalse + */ +LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL +RTCVideoCapturer_CaptureStarted( + rtcVideoCapturerHandle videoCapturer +) noexcept; + +/** + * Stops video capture. + * + * @param videoCapturer - Video capturer handle + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoCapturer_StopCapture( + rtcVideoCapturerHandle videoCapturer +) noexcept; + } // extern "C" #endif // LIB_WEBRTC_INTROP_API_HXX \ No newline at end of file diff --git a/src/interop/rtc_video_device_interop.cc b/src/interop/rtc_video_device_interop.cc index ae3063266b..6f4c322b5c 100644 --- a/src/interop/rtc_video_device_interop.cc +++ b/src/interop/rtc_video_device_interop.cc @@ -67,3 +67,38 @@ RTCVideoDevice_CreateVideoCapturer( *pOutRetVal = static_cast(pVideoCapturer.release()); return rtcResultU4::kSuccess; } + +rtcBool32 LIB_WEBRTC_CALL +RTCVideoCapturer_StartCapture( + rtcVideoCapturerHandle videoCapturer +) noexcept +{ + CHECK_POINTER_EX(videoCapturer, rtcBool32::kFalse); + scoped_refptr pVideoCapturer = static_cast(videoCapturer); + return pVideoCapturer->StartCapture() + ? rtcBool32::kTrue + : rtcBool32::kFalse; +} + +rtcBool32 LIB_WEBRTC_CALL +RTCVideoCapturer_CaptureStarted( + rtcVideoCapturerHandle videoCapturer +) noexcept +{ + CHECK_POINTER_EX(videoCapturer, rtcBool32::kFalse); + scoped_refptr pVideoCapturer = static_cast(videoCapturer); + return pVideoCapturer->CaptureStarted() + ? rtcBool32::kTrue + : rtcBool32::kFalse; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoCapturer_StopCapture( + rtcVideoCapturerHandle videoCapturer +) noexcept +{ + CHECK_NATIVE_HANDLE(videoCapturer); + scoped_refptr pVideoCapturer = static_cast(videoCapturer); + pVideoCapturer->StopCapture(); + return rtcResultU4::kSuccess; +} From 91299b199d383f2aa360eb5f0756ca1e547b6f3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Wed, 11 Dec 2024 16:25:44 +0300 Subject: [PATCH 19/69] Added rtc_desktop_device_interop.cc --- BUILD.gn | 1 + include/interop_api.h | 43 +++++++++++++++++++ src/interop/rtc_desktop_device_interop.cc | 50 +++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 src/interop/rtc_desktop_device_interop.cc diff --git a/BUILD.gn b/BUILD.gn index 77073f7558..85029c72a0 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -160,6 +160,7 @@ rtc_shared_library("libwebrtc") { "src/interop/rtc_peerconnection_factory_interop.cc", "src/interop/rtc_audio_device_interop.cc", "src/interop/rtc_video_device_interop.cc", + "src/interop/rtc_desktop_device_interop.cc", ] } diff --git a/include/interop_api.h b/include/interop_api.h index d182bdb137..1e26ca2e71 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -28,6 +28,7 @@ using TcpCandidatePolicy = libwebrtc::TcpCandidatePolicy; using MediaSecurityType = libwebrtc::MediaSecurityType; using SdpSemantics = libwebrtc::SdpSemantics; using RTCMediaType = libwebrtc::RTCMediaType; +using DesktopType = libwebrtc::DesktopType; /// 32-bit boolean for interop API. enum class rtcBool32 : int { kTrue = -1, kFalse = 0 }; @@ -187,6 +188,10 @@ using rtcMediaConstraintsHandle = rtcRefCountedObjectHandle; using rtcDesktopDeviceHandle = rtcRefCountedObjectHandle; /// Opaque handle to a native RTCDesktopCapturer interop object. using rtcDesktopCapturerHandle = rtcRefCountedObjectHandle; +/// Opaque handle to a native MediaSource interop object. +using rtcDesktopMediaSourceHandle = rtcRefCountedObjectHandle; +/// Opaque handle to a native RTCDesktopMediaList interop object. +using rtcDesktopMediaListHandle = rtcRefCountedObjectHandle; #endif // RTC_DESKTOP_DEVICE /// Opaque handle to a native RTCMediaStream interop object. @@ -738,6 +743,44 @@ RTCVideoCapturer_StopCapture( rtcVideoCapturerHandle videoCapturer ) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCDesktopDevice interop methods + * ---------------------------------------------------------------------- + */ +#ifdef RTC_DESKTOP_DEVICE +/** + * Create desktop capturer + * + * @param desktopDevice - Desktop device handle + * @param source - Media source handle + * @param pOutRetVal - Returns the created desktop capture handle. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopDevice_CreateDesktopCapturer( + rtcDesktopDeviceHandle desktopDevice, + rtcDesktopMediaSourceHandle source, + rtcDesktopCapturerHandle* pOutRetVal +) noexcept; + +/** + * Returns the desktop media list. + * + * @param desktopDevice - Desktop device handle + * @param type - Desktop type + * @param pOutRetVal - Returns the created desktop media list handle. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopDevice_GetDesktopMediaList( + rtcDesktopDeviceHandle desktopDevice, + DesktopType type, + rtcDesktopMediaListHandle* pOutRetVal +) noexcept; + +#endif // RTC_DESKTOP_DEVICE + } // extern "C" #endif // LIB_WEBRTC_INTROP_API_HXX \ No newline at end of file diff --git a/src/interop/rtc_desktop_device_interop.cc b/src/interop/rtc_desktop_device_interop.cc new file mode 100644 index 0000000000..9319a0736e --- /dev/null +++ b/src/interop/rtc_desktop_device_interop.cc @@ -0,0 +1,50 @@ +#include "rtc_desktop_media_list.h" +#include "rtc_desktop_capturer.h" +#include "rtc_desktop_device.h" +#include "interop_api.h" + +using namespace libwebrtc; + +#ifdef RTC_DESKTOP_DEVICE + +rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopDevice_CreateDesktopCapturer( + rtcDesktopDeviceHandle desktopDevice, + rtcDesktopMediaSourceHandle source, + rtcDesktopCapturerHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + CHECK_NATIVE_HANDLE(desktopDevice); + CHECK_POINTER_EX(source, rtcResultU4::kInvalidParameter); + + scoped_refptr pDesktopDevice = static_cast(desktopDevice); + scoped_refptr pSource = static_cast(source); + scoped_refptr pDesktopCapturer = pDesktopDevice->CreateDesktopCapturer(pSource); + if (pDesktopCapturer == nullptr) { + return rtcResultU4::kUnknownError; + } + *pOutRetVal = static_cast(pDesktopCapturer.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopDevice_GetDesktopMediaList( + rtcDesktopDeviceHandle desktopDevice, + DesktopType type, + rtcDesktopMediaListHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + CHECK_NATIVE_HANDLE(desktopDevice); + + scoped_refptr pDesktopDevice = static_cast(desktopDevice); + scoped_refptr pMediaList = pDesktopDevice->GetDesktopMediaList(type); + if (pMediaList == nullptr) { + return rtcResultU4::kUnknownError; + } + *pOutRetVal = static_cast(pMediaList.release()); + return rtcResultU4::kSuccess; +} + +#endif // RTC_DESKTOP_DEVICE From 1f9f37ca6791fee04fb176d06ec5b7293f061925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Wed, 11 Dec 2024 19:54:54 +0300 Subject: [PATCH 20/69] Added rtc_desktop_media_list_interop.cc --- BUILD.gn | 1 + include/interop_api.h | 10 +++++++++- src/interop/rtc_desktop_media_list_interop.cc | 10 ++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/interop/rtc_desktop_media_list_interop.cc diff --git a/BUILD.gn b/BUILD.gn index 85029c72a0..88ca731235 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -160,6 +160,7 @@ rtc_shared_library("libwebrtc") { "src/interop/rtc_peerconnection_factory_interop.cc", "src/interop/rtc_audio_device_interop.cc", "src/interop/rtc_video_device_interop.cc", + "src/interop/rtc_desktop_media_list_interop.cc", "src/interop/rtc_desktop_device_interop.cc", ] } diff --git a/include/interop_api.h b/include/interop_api.h index 1e26ca2e71..97bc0c092c 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -743,12 +743,20 @@ RTCVideoCapturer_StopCapture( rtcVideoCapturerHandle videoCapturer ) noexcept; +#ifdef RTC_DESKTOP_DEVICE + +/* + * ---------------------------------------------------------------------- + * RTCDesktopMediaList interop methods + * ---------------------------------------------------------------------- + */ + /* * ---------------------------------------------------------------------- * RTCDesktopDevice interop methods * ---------------------------------------------------------------------- */ -#ifdef RTC_DESKTOP_DEVICE + /** * Create desktop capturer * diff --git a/src/interop/rtc_desktop_media_list_interop.cc b/src/interop/rtc_desktop_media_list_interop.cc new file mode 100644 index 0000000000..ba303aafb8 --- /dev/null +++ b/src/interop/rtc_desktop_media_list_interop.cc @@ -0,0 +1,10 @@ +#include "rtc_desktop_media_list.h" +#include "interop_api.h" + +using namespace libwebrtc; + +#ifdef RTC_DESKTOP_DEVICE + + + +#endif // RTC_DESKTOP_DEVICE From fe46679581df4ceea8a466cde1d4250bd2eed959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Thu, 12 Dec 2024 19:48:25 +0300 Subject: [PATCH 21/69] Added callbacks rtc_desktop_media_list_interop.cc --- include/interop_api.h | 177 +++++++++++++++--- src/interop/rtc_audio_device_interop.cc | 2 +- src/interop/rtc_desktop_media_list_interop.cc | 103 ++++++++++ .../rtc_peerconnection_factory_interop.cc | 4 +- src/rtc_desktop_media_list_impl.cc | 71 ++++++- src/rtc_desktop_media_list_impl.h | 20 ++ 6 files changed, 338 insertions(+), 39 deletions(-) diff --git a/include/interop_api.h b/include/interop_api.h index 97bc0c092c..df72be5450 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -20,15 +20,15 @@ extern "C" { /// Types used from libwebrtc. -using IceTransportsType = libwebrtc::IceTransportsType; -using BundlePolicy = libwebrtc::BundlePolicy; -using RtcpMuxPolicy = libwebrtc::RtcpMuxPolicy; -using CandidateNetworkPolicy = libwebrtc::CandidateNetworkPolicy; -using TcpCandidatePolicy = libwebrtc::TcpCandidatePolicy; -using MediaSecurityType = libwebrtc::MediaSecurityType; -using SdpSemantics = libwebrtc::SdpSemantics; -using RTCMediaType = libwebrtc::RTCMediaType; -using DesktopType = libwebrtc::DesktopType; +using rtcIceTransportsType = libwebrtc::IceTransportsType; +using rtcBundlePolicy = libwebrtc::BundlePolicy; +using rtcRtcpMuxPolicy = libwebrtc::RtcpMuxPolicy; +using rtcCandidateNetworkPolicy = libwebrtc::CandidateNetworkPolicy; +using rtcTcpCandidatePolicy = libwebrtc::TcpCandidatePolicy; +using rtcMediaSecurityType = libwebrtc::MediaSecurityType; +using rtcSdpSemantics = libwebrtc::SdpSemantics; +using rtcMediaType = libwebrtc::RTCMediaType; +using rtcDesktopType = libwebrtc::DesktopType; /// 32-bit boolean for interop API. enum class rtcBool32 : int { kTrue = -1, kFalse = 0 }; @@ -126,18 +126,18 @@ struct rtcIceServer { struct rtcPeerConnectionConfiguration { rtcIceServer ice_servers[libwebrtc::kMaxIceServerSize]; - IceTransportsType type = IceTransportsType::kAll; - BundlePolicy bundle_policy = BundlePolicy::kBundlePolicyBalanced; - RtcpMuxPolicy rtcp_mux_policy = RtcpMuxPolicy::kRtcpMuxPolicyRequire; - CandidateNetworkPolicy candidate_network_policy = - CandidateNetworkPolicy::kCandidateNetworkPolicyAll; - TcpCandidatePolicy tcp_candidate_policy = - TcpCandidatePolicy::kTcpCandidatePolicyEnabled; + rtcIceTransportsType type = rtcIceTransportsType::kAll; + rtcBundlePolicy bundle_policy = rtcBundlePolicy::kBundlePolicyBalanced; + rtcRtcpMuxPolicy rtcp_mux_policy = rtcRtcpMuxPolicy::kRtcpMuxPolicyRequire; + rtcCandidateNetworkPolicy candidate_network_policy = + rtcCandidateNetworkPolicy::kCandidateNetworkPolicyAll; + rtcTcpCandidatePolicy tcp_candidate_policy = + rtcTcpCandidatePolicy::kTcpCandidatePolicyEnabled; int ice_candidate_pool_size = 0; - MediaSecurityType srtp_type = MediaSecurityType::kDTLS_SRTP; - SdpSemantics sdp_semantics = SdpSemantics::kUnifiedPlan; + rtcMediaSecurityType srtp_type = rtcMediaSecurityType::kDTLS_SRTP; + rtcSdpSemantics sdp_semantics = rtcSdpSemantics::kUnifiedPlan; rtcBool32 offer_to_receive_audio = rtcBool32::kTrue; rtcBool32 offer_to_receive_video = rtcBool32::kTrue; @@ -183,16 +183,20 @@ using rtcVideoCapturerHandle = rtcRefCountedObjectHandle; /// Opaque handle to a native RTCMediaConstraints interop object. using rtcMediaConstraintsHandle = rtcRefCountedObjectHandle; -#ifdef RTC_DESKTOP_DEVICE /// Opaque handle to a native RTCDesktopDevice interop object. using rtcDesktopDeviceHandle = rtcRefCountedObjectHandle; + /// Opaque handle to a native RTCDesktopCapturer interop object. using rtcDesktopCapturerHandle = rtcRefCountedObjectHandle; + /// Opaque handle to a native MediaSource interop object. using rtcDesktopMediaSourceHandle = rtcRefCountedObjectHandle; + /// Opaque handle to a native RTCDesktopMediaList interop object. using rtcDesktopMediaListHandle = rtcRefCountedObjectHandle; -#endif // RTC_DESKTOP_DEVICE + +/// Opaque handle to a native MediaListObserver interop object. +using rtcDesktopMediaListObserverHandle = rtcObjectHandle; /// Opaque handle to a native RTCMediaStream interop object. using rtcMediaStreamHandle = rtcRefCountedObjectHandle; @@ -209,6 +213,34 @@ using rtcAudioTrackHandle = rtcMediaTrackHandle; /// Opaque handle to a native RTCVideoTrack interop object. using rtcVideoTrackHandle = rtcMediaTrackHandle; +/* ---------------------------------------------------------------- */ + +/** + * Audio device change callback delegate + */ +using rtcAudioDeviceChangeDelegate = void(LIB_WEBRTC_CALL*)(); + +/** + * Callback delegate for MediaListObserve. + */ +using rtcMediaListObserverDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, + rtcDesktopMediaSourceHandle source +); + +/** + * Callback delegate structure for MediaListObserve. + */ +struct rtcMediaListObserverCallbacks { + rtcMediaListObserverDelegate MediaSourceAdded{}; + rtcObjectHandle user_data_added{}; + rtcMediaListObserverDelegate MediaSourceRemoved{}; + rtcObjectHandle user_data_removed{}; + rtcMediaListObserverDelegate MediaSourceNameChanged{}; + rtcObjectHandle user_data_name_changed{}; + rtcMediaListObserverDelegate MediaSourceThumbnailChanged{}; + rtcObjectHandle user_data_thumbnail_changed{}; +}; /* * ---------------------------------------------------------------------- @@ -458,7 +490,7 @@ RTCPeerConnectionFactory_CreateStream( LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_GetRtpSenderCapabilities( rtcPeerConnectionFactoryHandle factory, - RTCMediaType media_type, + rtcMediaType media_type, rtcRtpCapabilitiesHandle* pRetVal ) noexcept; @@ -469,7 +501,7 @@ RTCPeerConnectionFactory_GetRtpSenderCapabilities( LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_GetRtpReceiverCapabilities( rtcPeerConnectionFactoryHandle factory, - RTCMediaType media_type, + rtcMediaType media_type, rtcRtpCapabilitiesHandle* pRetVal ) noexcept; @@ -479,11 +511,6 @@ RTCPeerConnectionFactory_GetRtpReceiverCapabilities( * ---------------------------------------------------------------------- */ -/** - * Audio device change callback delegate - */ -using rtcRTCAudioDeviceChangeCallback = void(LIB_WEBRTC_CALL*)(); - /** * Returns the number of playout devices available. * @@ -584,7 +611,7 @@ RTCAudioDevice_SetRecordingDevice( LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCAudioDevice_RegisterDeviceChangeCallback( rtcAudioDeviceHandle audiDevice, - rtcRTCAudioDeviceChangeCallback deviceChangeCallback + rtcAudioDeviceChangeDelegate deviceChangeCallback ) noexcept; /** @@ -751,6 +778,98 @@ RTCVideoCapturer_StopCapture( * ---------------------------------------------------------------------- */ +/** + * Registers callback delegates for MediaListObserve. + * + * @param hMediaList - Desktop media list handle + * @param rtcMediaListObserverCallbacks - Callback delegate structure for MediaListObserve. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopMediaList_RegisterMediaListObserver( + rtcDesktopMediaListHandle hMediaList, + rtcMediaListObserverCallbacks* callbacks +) noexcept; + +/** + * Unregisters callback delegates for MediaListObserve. + * + * @param hMediaList - Desktop media list handle + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopMediaList_DeRegisterMediaListObserver +( + rtcDesktopMediaListHandle hMediaList +) noexcept; + +/** + * Returns the desktop type for the MediaListObserve. + * + * @param hMediaList - Desktop media list handle + * @return rtcDesktopType - 0 if successful, otherwise an -1 + */ +LIB_WEBRTC_API rtcDesktopType LIB_WEBRTC_CALL +RTCDesktopMediaList_GetType( + rtcDesktopMediaListHandle hMediaList +) noexcept; + +/** + * Updates media sources. + * + * @param hMediaList - Desktop media list handle + * @param force_reload - Force reloads media sources. + * @param get_thumbnail - Enables thumbnail get. + * @return int - Returns the number of sources. + */ +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RTCDesktopMediaList_UpdateSourceList( + rtcDesktopMediaListHandle hMediaList, + rtcBool32 force_reload = rtcBool32::kFalse, + rtcBool32 get_thumbnail = rtcBool32::kTrue +) noexcept; + +/** + * Returns the current number of media sources. + * + * @param hMediaList - Desktop media list handle + * @return int - Returns the number of sources. + */ +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RTCDesktopMediaList_GetSourceCount( + rtcDesktopMediaListHandle hMediaList +) noexcept; + +/** + * Returns the media source whose index is specified. + * + * @param hMediaList - Desktop media list handle + * @param index - Media source index + * @param pOutRetVal - Returns the media source handle. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopMediaList_GetSource( + rtcDesktopMediaListHandle hMediaList, + int index, + rtcDesktopMediaSourceHandle* pOutRetVal +) noexcept; + +/** + * Gets the thumbnail. + * + * @param hMediaList - Desktop media list handle + * @param source - Media source handle + * @param notify - Triggers the callback method. + * @return rtcBool32 - kTrue if successful, otherwise an kFalse. + */ +LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL +RTCDesktopMediaList_GetThumbnail( + rtcDesktopMediaListHandle hMediaList, + rtcDesktopMediaSourceHandle hSource, + rtcBool32 notify = rtcBool32::kFalse +) noexcept; + /* * ---------------------------------------------------------------------- * RTCDesktopDevice interop methods @@ -783,7 +902,7 @@ RTCDesktopDevice_CreateDesktopCapturer( LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCDesktopDevice_GetDesktopMediaList( rtcDesktopDeviceHandle desktopDevice, - DesktopType type, + rtcDesktopType type, rtcDesktopMediaListHandle* pOutRetVal ) noexcept; diff --git a/src/interop/rtc_audio_device_interop.cc b/src/interop/rtc_audio_device_interop.cc index 300acba538..3acbcc7a06 100644 --- a/src/interop/rtc_audio_device_interop.cc +++ b/src/interop/rtc_audio_device_interop.cc @@ -162,7 +162,7 @@ RTCAudioDevice_SetRecordingDevice( rtcResultU4 LIB_WEBRTC_CALL RTCAudioDevice_RegisterDeviceChangeCallback( rtcAudioDeviceHandle audiDevice, - rtcRTCAudioDeviceChangeCallback deviceChangeCallback + rtcAudioDeviceChangeDelegate deviceChangeCallback ) noexcept { CHECK_NATIVE_HANDLE(audiDevice); diff --git a/src/interop/rtc_desktop_media_list_interop.cc b/src/interop/rtc_desktop_media_list_interop.cc index ba303aafb8..c85ad9181f 100644 --- a/src/interop/rtc_desktop_media_list_interop.cc +++ b/src/interop/rtc_desktop_media_list_interop.cc @@ -1,10 +1,113 @@ #include "rtc_desktop_media_list.h" #include "interop_api.h" +#include "src/rtc_desktop_media_list_impl.h" using namespace libwebrtc; #ifdef RTC_DESKTOP_DEVICE +rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopMediaList_RegisterMediaListObserver( + rtcDesktopMediaListHandle hMediaList, + rtcMediaListObserverCallbacks* callbacks +) noexcept +{ + CHECK_NATIVE_HANDLE(hMediaList); + CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); + + MediaListObserver* pObserver = static_cast(new MediaListObserverImpl(callbacks)); + scoped_refptr pMediaList = static_cast(hMediaList); + pMediaList->RegisterMediaListObserver(pObserver); + return rtcResultU4::kSuccess; +} +rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopMediaList_DeRegisterMediaListObserver +( + rtcDesktopMediaListHandle hMediaList +) noexcept +{ + CHECK_NATIVE_HANDLE(hMediaList); + + scoped_refptr pMediaList = static_cast(hMediaList); + MediaListObserverImpl* pObserverImpl = static_cast(pMediaList->GetObserver()); + pMediaList->DeRegisterMediaListObserver(); + if (pObserverImpl) { + delete pObserverImpl; + } + return rtcResultU4::kSuccess; +} + +rtcDesktopType LIB_WEBRTC_CALL +RTCDesktopMediaList_GetType( + rtcDesktopMediaListHandle hMediaList +) noexcept +{ + CHECK_POINTER_EX(hMediaList, static_cast(-1)); + + scoped_refptr pMediaList = static_cast(hMediaList); + rtcDesktopType desktopType = static_cast(pMediaList->type()); + return desktopType; +} + +int LIB_WEBRTC_CALL +RTCDesktopMediaList_UpdateSourceList( + rtcDesktopMediaListHandle hMediaList, + rtcBool32 force_reload /*= rtcBool32::kFalse*/, + rtcBool32 get_thumbnail /*= rtcBool32::kTrue*/ +) noexcept +{ + CHECK_POINTER_EX(hMediaList, -1); + + scoped_refptr pMediaList = static_cast(hMediaList); + int result = (int)pMediaList->UpdateSourceList( + force_reload != rtcBool32::kFalse, + get_thumbnail != rtcBool32::kFalse + ); + return result; +} + +int LIB_WEBRTC_CALL +RTCDesktopMediaList_GetSourceCount( + rtcDesktopMediaListHandle hMediaList +) noexcept +{ + CHECK_POINTER_EX(hMediaList, -1); + + scoped_refptr pMediaList = static_cast(hMediaList); + return pMediaList->GetSourceCount(); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopMediaList_GetSource( + rtcDesktopMediaListHandle hMediaList, + int index, + rtcDesktopMediaSourceHandle* pOutRetVal +) noexcept +{ + CHECK_NATIVE_HANDLE(hMediaList); + + scoped_refptr pMediaList = static_cast(hMediaList); + scoped_refptr source = pMediaList->GetSource(index); + *pOutRetVal = static_cast(source.release()); + return rtcResultU4::kSuccess; +} + +rtcBool32 LIB_WEBRTC_CALL +RTCDesktopMediaList_GetThumbnail( + rtcDesktopMediaListHandle hMediaList, + rtcDesktopMediaSourceHandle hSource, + rtcBool32 notify /*= rtcBool32::kFalse*/ +) noexcept +{ + CHECK_POINTER_EX(hMediaList, rtcBool32::kFalse); + CHECK_POINTER_EX(hSource, rtcBool32::kFalse); + + scoped_refptr pMediaList = static_cast(hMediaList); + scoped_refptr pSource = static_cast(hSource); + return pMediaList->GetThumbnail(pSource, notify != rtcBool32::kFalse) + ? rtcBool32::kTrue + : rtcBool32::kFalse; +} #endif // RTC_DESKTOP_DEVICE diff --git a/src/interop/rtc_peerconnection_factory_interop.cc b/src/interop/rtc_peerconnection_factory_interop.cc index e575217871..b2979ed336 100644 --- a/src/interop/rtc_peerconnection_factory_interop.cc +++ b/src/interop/rtc_peerconnection_factory_interop.cc @@ -292,7 +292,7 @@ RTCPeerConnectionFactory_CreateStream( rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_GetRtpSenderCapabilities( rtcPeerConnectionFactoryHandle factory, - RTCMediaType media_type, + rtcMediaType media_type, rtcRtpCapabilitiesHandle* pRetVal ) noexcept { @@ -309,7 +309,7 @@ RTCPeerConnectionFactory_GetRtpSenderCapabilities( rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_GetRtpReceiverCapabilities( rtcPeerConnectionFactoryHandle factory, - RTCMediaType media_type, + rtcMediaType media_type, rtcRtpCapabilitiesHandle* pRetVal ) noexcept { diff --git a/src/rtc_desktop_media_list_impl.cc b/src/rtc_desktop_media_list_impl.cc index 68aa783834..efe8c0c99e 100644 --- a/src/rtc_desktop_media_list_impl.cc +++ b/src/rtc_desktop_media_list_impl.cc @@ -15,6 +15,7 @@ */ #include "rtc_desktop_media_list_impl.h" +#include "interop_api.h" #include "internal/jpeg_util.h" #include "rtc_base/checks.h" @@ -66,7 +67,7 @@ int32_t RTCDesktopMediaListImpl::UpdateSourceList(bool force_reload, if (observer_) { auto source_ptr = source.get(); signaling_thread_->BlockingCall( - [&, source_ptr]() { observer_->OnMediaSourceRemoved(source_ptr); }); + [&, source_ptr]() { if (observer_) { observer_->OnMediaSourceRemoved(source_ptr); } }); } } sources_.clear(); @@ -90,7 +91,7 @@ int32_t RTCDesktopMediaListImpl::UpdateSourceList(bool force_reload, if (observer_) { auto source = (*(sources_.begin() + i)).get(); signaling_thread_->BlockingCall( - [&, source]() { observer_->OnMediaSourceRemoved(source); }); + [&, source]() { if (observer_) { observer_->OnMediaSourceRemoved(source); } }); } sources_.erase(sources_.begin() + i); --i; @@ -110,7 +111,7 @@ int32_t RTCDesktopMediaListImpl::UpdateSourceList(bool force_reload, GetThumbnail(source, true); if (observer_) { signaling_thread_->BlockingCall( - [&, source]() { observer_->OnMediaSourceAdded(source); }); + [&, source]() { if (observer_) { observer_->OnMediaSourceAdded(source); }}); } } } @@ -142,7 +143,7 @@ int32_t RTCDesktopMediaListImpl::UpdateSourceList(bool force_reload, if (observer_) { auto source = sources_[pos].get(); signaling_thread_->BlockingCall( - [&, source]() { observer_->OnMediaSourceNameChanged(source); }); + [&, source]() { if (observer_) { observer_->OnMediaSourceNameChanged(source); }}); } } ++pos; @@ -166,9 +167,7 @@ bool RTCDesktopMediaListImpl::GetThumbnail(scoped_refptr source, auto old_thumbnail = source_impl->thumbnail(); source_impl->SaveCaptureResult(result, std::move(frame)); if (observer_ && notify) { - signaling_thread_->BlockingCall([&, source_impl]() { - observer_->OnMediaSourceThumbnailChanged(source_impl); - }); + signaling_thread_->BlockingCall([&, source_impl]() { if (observer_) { observer_->OnMediaSourceThumbnailChanged(source_impl); }}); } }); capturer_->CaptureFrame(); @@ -252,4 +251,62 @@ void MediaSourceImpl::SaveCaptureResult( #endif } +/** + * MediaListObserverImpl + */ + +MediaListObserverImpl::MediaListObserverImpl(void* callbacks /* rtcMediaListObserverCallbacks* */) + : callbacks_(callbacks) +{ + if (callbacks) { + size_t nSize = sizeof(rtcMediaListObserverCallbacks); + callbacks_ = malloc(nSize); + memcpy(callbacks_, (const void*)callbacks, nSize); + } +} + +MediaListObserverImpl::~MediaListObserverImpl() +{ + if (callbacks_) { + free(callbacks_); + } + callbacks_ = nullptr; +} + +void MediaListObserverImpl::OnMediaSourceAdded(scoped_refptr source) +{ + if (callbacks_) { + rtcMediaListObserverCallbacks* pCallbacks = static_cast(callbacks_); + rtcDesktopMediaSourceHandle pSource = static_cast(source.release()); + pCallbacks->MediaSourceAdded(pCallbacks->user_data_added, pSource); + } +} + +void MediaListObserverImpl::OnMediaSourceRemoved(scoped_refptr source) +{ + if (callbacks_) { + rtcMediaListObserverCallbacks* pCallbacks = static_cast(callbacks_); + rtcDesktopMediaSourceHandle pSource = static_cast(source.release()); + pCallbacks->MediaSourceRemoved(pCallbacks->user_data_removed, pSource); + } +} + +void MediaListObserverImpl::OnMediaSourceNameChanged(scoped_refptr source) +{ + if (callbacks_) { + rtcMediaListObserverCallbacks* pCallbacks = static_cast(callbacks_); + rtcDesktopMediaSourceHandle pSource = static_cast(source.release()); + pCallbacks->MediaSourceNameChanged(pCallbacks->user_data_name_changed, pSource); + } +} + +void MediaListObserverImpl::OnMediaSourceThumbnailChanged(scoped_refptr source) +{ + if (callbacks_) { + rtcMediaListObserverCallbacks* pCallbacks = static_cast(callbacks_); + rtcDesktopMediaSourceHandle pSource = static_cast(source.release()); + pCallbacks->MediaSourceThumbnailChanged(pCallbacks->user_data_thumbnail_changed, pSource); + } +} + } // namespace libwebrtc diff --git a/src/rtc_desktop_media_list_impl.h b/src/rtc_desktop_media_list_impl.h index bfd6561bc7..c2ee2bad7d 100644 --- a/src/rtc_desktop_media_list_impl.h +++ b/src/rtc_desktop_media_list_impl.h @@ -68,6 +68,24 @@ class MediaSourceImpl : public MediaSource { DesktopType type_; }; +class MediaListObserverImpl : public MediaListObserver +{ + public: + MediaListObserverImpl(void* callbacks /* rtcMediaListObserverCallbacks* */); + ~MediaListObserverImpl(); + + void OnMediaSourceAdded(scoped_refptr source) override; + + void OnMediaSourceRemoved(scoped_refptr source) override; + + void OnMediaSourceNameChanged(scoped_refptr source) override; + + void OnMediaSourceThumbnailChanged(scoped_refptr source) override; + + private: + void* callbacks_; +}; + class RTCDesktopMediaListImpl : public RTCDesktopMediaList { public: enum CaptureState { CS_RUNNING, CS_STOPPED, CS_FAILED }; @@ -95,6 +113,8 @@ class RTCDesktopMediaListImpl : public RTCDesktopMediaList { bool GetThumbnail(scoped_refptr source, bool notify = false) override; + MediaListObserver* GetObserver() { return observer_; } + private: class CallbackProxy : public webrtc::DesktopCapturer::Callback { public: From a861abd752ebeb207fa7eedcc95c4b352ba72f5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Mon, 16 Dec 2024 15:58:45 +0300 Subject: [PATCH 22/69] Added MediaSource interop methods --- include/interop_api.h | 55 +++++++++++ src/interop/rtc_desktop_media_list_interop.cc | 95 +++++++++++++++++++ src/rtc_desktop_media_list_impl.h | 2 +- 3 files changed, 151 insertions(+), 1 deletion(-) diff --git a/include/interop_api.h b/include/interop_api.h index df72be5450..999eeea8a9 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -13,6 +13,8 @@ #define CHECK_POINTER_EX(p, r) if ((p) == nullptr) { return (r); } #define CHECK_POINTER(p) CHECK_POINTER_EX(p, rtcResultU4::kInvalidPointer) +#define RESET_OUT_POINTER_EX(p,v) if ((p) != nullptr) { *(p) = (v); } +#define RESET_OUT_POINTER(p) RESET_OUT_POINTER_EX(p, nullptr) #define CHECK_OUT_POINTER(p) if ((p) != nullptr) { *(p) = nullptr; } else { return rtcResultU4::kInvalidPointer; } #define CHECK_NATIVE_HANDLE(h) CHECK_POINTER_EX(h, rtcResultU4::kInvalidNativeHandle) #define ZERO_MEMORY(p,sz) if ((sz) > 0) { memset((void*)(p), 0, (size_t)(sz)); } @@ -870,6 +872,59 @@ RTCDesktopMediaList_GetThumbnail( rtcBool32 notify = rtcBool32::kFalse ) noexcept; +/* + * ---------------------------------------------------------------------- + * MediaSource interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Provides id, name and type information about the media source. + * + * @param mediaSource - Media source handle + * @param pOutId - Media source id + * @param cchOutId - The size of the id. + * @param pOutName - Media source name + * @param cchOutName - The size of the name. + * @param pOutType - The desktop type of media source + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +MediaSource_GetInfo( + rtcDesktopMediaSourceHandle mediaSource, + char* pOutId, int cchOutId, + char* pOutName, int cchOutName, + rtcDesktopType* pOutType +) noexcept; + +/** + * Updates the media source thumbnail. + * + * @param mediaSource - Media source handle + * @return rtcBool32 - kTrue if successful, otherwise kFalse + */ +LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL +MediaSource_UpdateThumbnail( + rtcDesktopMediaSourceHandle mediaSource +) noexcept; + +/** + * Returns the thumbnail of the media source, jpeg format. + * At the end of the process, the 'refSizeOfBuffer' value + * gives the actual size of the buffer area. + * + * @param mediaSource - Media source handle + * @param pBuffer - Address of the buffer area for the thumbnail. + * @param refSizeOfBuffer - The size of the thumbnail buffer. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +MediaSource_GetThumbnail( + rtcDesktopMediaSourceHandle mediaSource, + unsigned char* pBuffer, + int* refSizeOfBuffer +) noexcept; + /* * ---------------------------------------------------------------------- * RTCDesktopDevice interop methods diff --git a/src/interop/rtc_desktop_media_list_interop.cc b/src/interop/rtc_desktop_media_list_interop.cc index c85ad9181f..4eefce08e5 100644 --- a/src/interop/rtc_desktop_media_list_interop.cc +++ b/src/interop/rtc_desktop_media_list_interop.cc @@ -6,6 +6,12 @@ using namespace libwebrtc; #ifdef RTC_DESKTOP_DEVICE +/* + * ---------------------------------------------------------------------- + * RTCDesktopMediaList interop methods + * ---------------------------------------------------------------------- + */ + rtcResultU4 LIB_WEBRTC_CALL RTCDesktopMediaList_RegisterMediaListObserver( rtcDesktopMediaListHandle hMediaList, @@ -110,4 +116,93 @@ RTCDesktopMediaList_GetThumbnail( : rtcBool32::kFalse; } +/* + * ---------------------------------------------------------------------- + * MediaSource interop methods + * ---------------------------------------------------------------------- + */ + +rtcResultU4 LIB_WEBRTC_CALL +MediaSource_GetInfo( + rtcDesktopMediaSourceHandle mediaSource, + char* pOutId, int cchOutId, + char* pOutName, int cchOutName, + rtcDesktopType* pOutType +) noexcept +{ + CHECK_NATIVE_HANDLE(mediaSource); + RESET_OUT_POINTER_EX(pOutId, '\0'); + RESET_OUT_POINTER_EX(pOutName, '\0'); + RESET_OUT_POINTER_EX(pOutType, static_cast(-1)); + + rtcResultU4 result = rtcResultU4::kSuccess; + size_t cchLen; + string szTmp; + scoped_refptr pMediaSource = static_cast(mediaSource); + + if (pOutId && cchOutId > 0) { + ZERO_MEMORY(pOutId, cchOutId); + szTmp = pMediaSource->id(); + if (szTmp.size() > (size_t)cchOutId) { + result = rtcResultU4::kBufferTooSmall; + } + cchLen = std::min(szTmp.size(), (size_t)cchOutId); + strncpy(pOutId, szTmp.c_string(), cchLen); + } + + if (pOutName && cchOutName > 0) { + ZERO_MEMORY(pOutName, cchOutName); + szTmp = pMediaSource->name(); + if (szTmp.size() > (size_t)cchOutName) { + result = rtcResultU4::kBufferTooSmall; + } + cchLen = std::min(szTmp.size(), (size_t)cchOutName); + strncpy(pOutName, szTmp.c_string(), cchLen); + } + + if (pOutType) { + *pOutType = static_cast(pMediaSource->type()); + } + + return result; +} + +rtcBool32 LIB_WEBRTC_CALL +MediaSource_UpdateThumbnail( + rtcDesktopMediaSourceHandle mediaSource +) noexcept +{ + CHECK_POINTER_EX(mediaSource, rtcBool32::kFalse); + scoped_refptr pMediaSource = static_cast(mediaSource); + return pMediaSource->UpdateThumbnail() + ? rtcBool32::kTrue + : rtcBool32::kFalse; +} + +rtcResultU4 LIB_WEBRTC_CALL +MediaSource_GetThumbnail( + rtcDesktopMediaSourceHandle mediaSource, + unsigned char* pBuffer, + int* refSizeOfBuffer +) noexcept +{ + CHECK_NATIVE_HANDLE(mediaSource); + size_t szDstBuffer = static_cast(*refSizeOfBuffer); + RESET_OUT_POINTER_EX(refSizeOfBuffer, 0); + + scoped_refptr pMediaSource = static_cast(mediaSource); + portable::vector buffer = pMediaSource->thumbnail(); + + size_t szSrcSize = buffer.size(); + *refSizeOfBuffer = static_cast(szSrcSize); + if (pBuffer) { + if (szSrcSize > szDstBuffer) { + return rtcResultU4::kBufferTooSmall; + } + memcpy((void*)pBuffer, (const void*)buffer.data(), szSrcSize); + } + + return rtcResultU4::kSuccess; +} + #endif // RTC_DESKTOP_DEVICE diff --git a/src/rtc_desktop_media_list_impl.h b/src/rtc_desktop_media_list_impl.h index c2ee2bad7d..7a4d3dc358 100644 --- a/src/rtc_desktop_media_list_impl.h +++ b/src/rtc_desktop_media_list_impl.h @@ -83,7 +83,7 @@ class MediaListObserverImpl : public MediaListObserver void OnMediaSourceThumbnailChanged(scoped_refptr source) override; private: - void* callbacks_; + void* callbacks_ /* rtcMediaListObserverCallbacks* */; }; class RTCDesktopMediaListImpl : public RTCDesktopMediaList { From 661a7a3d2c010b0cb511c4836a5e793e218e51bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Mon, 16 Dec 2024 16:07:08 +0300 Subject: [PATCH 23/69] Updated ReadMe.md --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9f1d5af7d4..1c633e737e 100644 --- a/README.md +++ b/README.md @@ -48,8 +48,13 @@ gclient sync Confirm that it is currently in the `src`. -```bash -git clone https://github.com/webrtc-sdk/libwebrtc +```patch +- git clone https://github.com/webrtc-sdk/libwebrtc ++ git clone https://github.com/gerd0gdu/libwebrtc +``` + +```batch +git clone https://github.com/gerd0gdu/libwebrtc ``` ### Modify webrtc's src/BUILD.gn file and add libwebrtc to group("default"). From 904e05228f0da41b8820509cca807e1068951ed8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Mon, 16 Dec 2024 21:10:44 +0300 Subject: [PATCH 24/69] Added media track interop methods --- BUILD.gn | 4 +- include/interop_api.h | 93 +++++++++++++++++++++++ src/interop/rtc_audio_device_interop.cc | 6 ++ src/interop/rtc_audio_track_interop.cc | 19 +++++ src/interop/rtc_media_track_interop.cc | 99 +++++++++++++++++++++++++ src/interop/rtc_video_device_interop.cc | 12 +++ src/interop/rtc_video_track_interop.cc | 4 + 7 files changed, 236 insertions(+), 1 deletion(-) create mode 100644 src/interop/rtc_audio_track_interop.cc create mode 100644 src/interop/rtc_media_track_interop.cc create mode 100644 src/interop/rtc_video_track_interop.cc diff --git a/BUILD.gn b/BUILD.gn index 88ca731235..09e9d5245c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -158,9 +158,11 @@ rtc_shared_library("libwebrtc") { "src/interop/libwebrtc_interop.cc", "src/interop/rtc_mediaconstraints_interop.cc", "src/interop/rtc_peerconnection_factory_interop.cc", + "src/interop/rtc_media_track_interop.cc", "src/interop/rtc_audio_device_interop.cc", + "src/interop/rtc_audio_track_interop.cc", "src/interop/rtc_video_device_interop.cc", - "src/interop/rtc_desktop_media_list_interop.cc", + "src/interop/rtc_video_track_interop.cc", "src/interop/rtc_desktop_device_interop.cc", ] } diff --git a/include/interop_api.h b/include/interop_api.h index 999eeea8a9..4e1d7fa363 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -35,6 +35,8 @@ using rtcDesktopType = libwebrtc::DesktopType; /// 32-bit boolean for interop API. enum class rtcBool32 : int { kTrue = -1, kFalse = 0 }; +enum class rtcTrackState : int { kUnknown = -1, kLive = 0, kEnded = 1 }; + /// 32-bit result enumerator enum class rtcResultU4 : unsigned int { /// The operation was successful. @@ -668,6 +670,97 @@ RTCAudioDevice_GetSpeakerVolume( unsigned int* volume ) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCMediaTrack interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Returns the track state. + * + * @param mediaTrack - Media track handle + * @return rtcTrackState - Track state enum + */ +LIB_WEBRTC_API rtcTrackState LIB_WEBRTC_CALL +RTCMediaTrack_GetState( + rtcMediaTrackHandle mediaTrack +) noexcept; + +/** + * Returns the track kind. (video, audio, vs.) + * + * @param mediaTrack - Media track handle + * @param pOutKind - Media track kind + * @param cchOutKind - The size of the kind + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCMediaTrack_GetKind( + rtcMediaTrackHandle mediaTrack, + char* pOutKind, + int cchOutKind +) noexcept; + +/** + * Returns the track id. + * + * @param mediaTrack - Media track handle + * @param pOutId - Media track id + * @param cchOutId - The size of the id + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCMediaTrack_GetId( + rtcMediaTrackHandle mediaTrack, + char* pOutId, + int cchOutId +) noexcept; + +/** + * Returns the enable/disable status of the track. + * + * @param mediaTrack - Media track handle + * @return rtcBool32 - kTrue if enabled, otherwise disabled + */ +LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL +RTCMediaTrack_GetEnabled( + rtcMediaTrackHandle mediaTrack +) noexcept; + +/** + * Sets the enable/disable of the track. + * + * @param mediaTrack - Media track handle + * @param enabled - Media track enable/disable value + * @return rtcBool32 - kTrue if the property has changed, otherwise kFalse + */ +LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL +RTCMediaTrack_SetEnabled( + rtcMediaTrackHandle mediaTrack, + rtcBool32 enabled +) noexcept; + +/* + * ---------------------------------------------------------------------- + * RTCAudioTrack interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Sets the volume of the audio track. + * + * @param audioTrack - Audio track handle + * @param volume - volume in [0-10] + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCAudioTrack_SetVolume( + rtcAudioTrackHandle audioTrack, + double volume +) noexcept; + + /* * ---------------------------------------------------------------------- * RTCVideoDevice interop methods diff --git a/src/interop/rtc_audio_device_interop.cc b/src/interop/rtc_audio_device_interop.cc index 3acbcc7a06..dccc4ebb3e 100644 --- a/src/interop/rtc_audio_device_interop.cc +++ b/src/interop/rtc_audio_device_interop.cc @@ -3,6 +3,12 @@ using namespace libwebrtc; +/* + * ---------------------------------------------------------------------- + * RTCAudioDevice interop methods + * ---------------------------------------------------------------------- + */ + int LIB_WEBRTC_CALL RTCAudioDevice_PlayoutDevices( rtcAudioDeviceHandle audiDevice diff --git a/src/interop/rtc_audio_track_interop.cc b/src/interop/rtc_audio_track_interop.cc new file mode 100644 index 0000000000..b954cf6fab --- /dev/null +++ b/src/interop/rtc_audio_track_interop.cc @@ -0,0 +1,19 @@ +#include "rtc_audio_track.h" +#include "interop_api.h" + +using namespace libwebrtc; + +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioTrack_SetVolume( + rtcAudioTrackHandle audioTrack, + double volume +) noexcept +{ + CHECK_NATIVE_HANDLE(audioTrack); + + if (volume < 0) volume = 0; + if (volume > 10) volume = 10; + scoped_refptr pAudioTrack = static_cast(audioTrack); + pAudioTrack->SetVolume(volume); + return rtcResultU4::kSuccess; +} diff --git a/src/interop/rtc_media_track_interop.cc b/src/interop/rtc_media_track_interop.cc new file mode 100644 index 0000000000..073853dc65 --- /dev/null +++ b/src/interop/rtc_media_track_interop.cc @@ -0,0 +1,99 @@ +#include "rtc_media_track.h" +#include "interop_api.h" + +using namespace libwebrtc; + +rtcTrackState LIB_WEBRTC_CALL +RTCMediaTrack_GetState( + rtcMediaTrackHandle mediaTrack +) noexcept +{ + CHECK_POINTER_EX(mediaTrack, rtcTrackState::kUnknown); + scoped_refptr pMediaTrack = static_cast(mediaTrack); + return static_cast(pMediaTrack->state()); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCMediaTrack_GetKind( + rtcMediaTrackHandle mediaTrack, + char* pOutKind, + int cchOutKind +) noexcept +{ + CHECK_NATIVE_HANDLE(mediaTrack); + if (cchOutKind <= 0) { + return rtcResultU4::kBufferTooSmall; + } + ZERO_MEMORY(pOutKind, cchOutKind); + + rtcResultU4 result = rtcResultU4::kSuccess; + scoped_refptr pMediaTrack = static_cast(mediaTrack); + string kind = pMediaTrack->kind(); + size_t dstSize = static_cast(cchOutKind); + size_t srcSize = kind.size(); + if (srcSize > dstSize) { + result = rtcResultU4::kBufferTooSmall; + } + + size_t len = std::min(dstSize, srcSize); + if (len > 0) { + strncpy(pOutKind, kind.c_string(), len); + } + + return result; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCMediaTrack_GetId( + rtcMediaTrackHandle mediaTrack, + char* pOutId, + int cchOutId +) noexcept +{ + CHECK_NATIVE_HANDLE(mediaTrack); + if (cchOutId <= 0) { + return rtcResultU4::kBufferTooSmall; + } + ZERO_MEMORY(pOutId, cchOutId); + + rtcResultU4 result = rtcResultU4::kSuccess; + scoped_refptr pMediaTrack = static_cast(mediaTrack); + string id = pMediaTrack->id(); + size_t dstSize = static_cast(cchOutId); + size_t srcSize = id.size(); + if (srcSize > dstSize) { + result = rtcResultU4::kBufferTooSmall; + } + + size_t len = std::min(dstSize, srcSize); + if (len > 0) { + strncpy(pOutId, id.c_string(), len); + } + + return result; +} + +rtcBool32 LIB_WEBRTC_CALL +RTCMediaTrack_GetEnabled( + rtcMediaTrackHandle mediaTrack +) noexcept +{ + CHECK_POINTER_EX(mediaTrack, rtcBool32::kFalse); + scoped_refptr pMediaTrack = static_cast(mediaTrack); + return pMediaTrack->enabled() + ? rtcBool32::kTrue + : rtcBool32::kFalse; +} + +rtcBool32 LIB_WEBRTC_CALL +RTCMediaTrack_SetEnabled( + rtcMediaTrackHandle mediaTrack, + rtcBool32 enabled +) noexcept +{ + CHECK_POINTER_EX(mediaTrack, rtcBool32::kFalse); + scoped_refptr pMediaTrack = static_cast(mediaTrack); + return pMediaTrack->set_enabled(enabled != rtcBool32::kFalse) + ? rtcBool32::kTrue + : rtcBool32::kFalse; +} diff --git a/src/interop/rtc_video_device_interop.cc b/src/interop/rtc_video_device_interop.cc index 6f4c322b5c..14ec2ea499 100644 --- a/src/interop/rtc_video_device_interop.cc +++ b/src/interop/rtc_video_device_interop.cc @@ -3,6 +3,12 @@ using namespace libwebrtc; +/* + * ---------------------------------------------------------------------- + * RTCVideoDevice interop methods + * ---------------------------------------------------------------------- + */ + int LIB_WEBRTC_CALL RTCVideoDevice_NumberOfDevices( rtcVideoDeviceHandle videoDevice @@ -68,6 +74,12 @@ RTCVideoDevice_CreateVideoCapturer( return rtcResultU4::kSuccess; } +/* + * ---------------------------------------------------------------------- + * RTCVideoCapturer interop methods + * ---------------------------------------------------------------------- + */ + rtcBool32 LIB_WEBRTC_CALL RTCVideoCapturer_StartCapture( rtcVideoCapturerHandle videoCapturer diff --git a/src/interop/rtc_video_track_interop.cc b/src/interop/rtc_video_track_interop.cc new file mode 100644 index 0000000000..d43b890fd1 --- /dev/null +++ b/src/interop/rtc_video_track_interop.cc @@ -0,0 +1,4 @@ +#include "rtc_video_track.h" +#include "interop_api.h" + +using namespace libwebrtc; \ No newline at end of file From 069c161637fba247d186962f1c1bbb3a19061954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Tue, 17 Dec 2024 13:40:07 +0300 Subject: [PATCH 25/69] Added rtc_video_renderer_interop.cc --- BUILD.gn | 2 ++ src/interop/rtc_video_frame_interop.cc | 4 ++++ src/interop/rtc_video_renderer_interop.cc | 4 ++++ 3 files changed, 10 insertions(+) create mode 100644 src/interop/rtc_video_frame_interop.cc create mode 100644 src/interop/rtc_video_renderer_interop.cc diff --git a/BUILD.gn b/BUILD.gn index 09e9d5245c..fa313fdd3b 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -163,6 +163,8 @@ rtc_shared_library("libwebrtc") { "src/interop/rtc_audio_track_interop.cc", "src/interop/rtc_video_device_interop.cc", "src/interop/rtc_video_track_interop.cc", + "src/interop/rtc_video_frame_interop.cc", + "src/interop/rtc_video_renderer_interop.cc", "src/interop/rtc_desktop_device_interop.cc", ] } diff --git a/src/interop/rtc_video_frame_interop.cc b/src/interop/rtc_video_frame_interop.cc new file mode 100644 index 0000000000..f3c4cd0d8d --- /dev/null +++ b/src/interop/rtc_video_frame_interop.cc @@ -0,0 +1,4 @@ +#include "rtc_video_frame.h" +#include "interop_api.h" + +using namespace libwebrtc; \ No newline at end of file diff --git a/src/interop/rtc_video_renderer_interop.cc b/src/interop/rtc_video_renderer_interop.cc new file mode 100644 index 0000000000..12e93d7807 --- /dev/null +++ b/src/interop/rtc_video_renderer_interop.cc @@ -0,0 +1,4 @@ +#include "rtc_video_renderer.h" +#include "interop_api.h" + +using namespace libwebrtc; \ No newline at end of file From 5161a928a5d3920ff39dc42713da0a8fb20e374e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Tue, 17 Dec 2024 18:44:46 +0300 Subject: [PATCH 26/69] Added video frame interop methods --- include/interop_api.h | 126 ++++++++++++++++++++++++- src/interop/rtc_video_frame_interop.cc | 125 +++++++++++++++++++++++- 2 files changed, 246 insertions(+), 5 deletions(-) diff --git a/include/interop_api.h b/include/interop_api.h index 4e1d7fa363..f6e06c9bb1 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -33,9 +33,31 @@ using rtcMediaType = libwebrtc::RTCMediaType; using rtcDesktopType = libwebrtc::DesktopType; /// 32-bit boolean for interop API. -enum class rtcBool32 : int { kTrue = -1, kFalse = 0 }; +enum class rtcBool32 : int { + kTrue = -1, + kFalse = 0 +}; + +enum class rtcTrackState : int { + kUnknown = -1, + kLive = 0, + kEnded = 1 +}; -enum class rtcTrackState : int { kUnknown = -1, kLive = 0, kEnded = 1 }; +enum class rtcVideoFrameType : int { + kUnknown = -1, + kARGB = 0, + kBGRA = 1, + kABGR = 2, + kRGBA = 3 +}; + +enum class rtcVideoRotation : int { + kVideoRotation_0 = 0, + kVideoRotation_90 = 90, + kVideoRotation_180 = 180, + kVideoRotation_270 = 270 +}; /// 32-bit result enumerator enum class rtcResultU4 : unsigned int { @@ -126,7 +148,7 @@ struct rtcIceServer { const char* uri = nullptr; const char* username = nullptr; const char* password = nullptr; -}; +}; // end struct rtcIceServer struct rtcPeerConnectionConfiguration { rtcIceServer ice_servers[libwebrtc::kMaxIceServerSize]; @@ -155,7 +177,22 @@ struct rtcPeerConnectionConfiguration { rtcBool32 use_rtp_mux = rtcBool32::kTrue; uint32_t local_audio_bandwidth = 128; uint32_t local_video_bandwidth = 512; -}; +}; // end struct rtcPeerConnectionConfiguration + +struct rtcVideoFrameDatas { + // frame width in pixel + int width = 0; + // frame height in pixel + int height = 0; + // The YUV starting address of the frame buffer. + const unsigned char* data_y = nullptr; + const unsigned char* data_u = nullptr; + const unsigned char* data_v = nullptr; + // The stride of the YUV + int stride_y = 0; + int stride_u = 0; + int stride_v = 0; +}; // end struct rtcVideoFrameDatas /// Opaque handle to a native interop object. using rtcObjectHandle = void*; @@ -217,6 +254,12 @@ using rtcAudioTrackHandle = rtcMediaTrackHandle; /// Opaque handle to a native RTCVideoTrack interop object. using rtcVideoTrackHandle = rtcMediaTrackHandle; +/// Opaque handle to a native RTCVideoFrame interop object. +using rtcVideoFrameHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCVideoRenderer interop object. +using rtcVideoRendererHandle = rtcRefCountedObjectHandle; // ??? + /* ---------------------------------------------------------------- */ /** @@ -865,6 +908,81 @@ RTCVideoCapturer_StopCapture( rtcVideoCapturerHandle videoCapturer ) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCVideoFrame interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Creates a new instance of the video frame. (i420) + * + * @param width - Frame width + * @param height - Frame height + * @param buffer - Frame buffer + * @param length - The size of the frame buffer + * @param pOutRetVal - Handle for the created video frame class. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_Create1( + int width, int height, + const unsigned char* buffer, int length, + rtcVideoFrameHandle* pOutRetVal +) noexcept; + +/** + * Creates a new instance of the video frame. (i420) + * + * @param frameDatas - Frame datas + * @param pOutRetVal - Handle for the created video frame handle. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_Create2( + const rtcVideoFrameDatas* frameDatas, + rtcVideoFrameHandle* pOutRetVal +) noexcept; + +/** + * Creates a copy of the video frame. + * + * @param videoFrame - Source video frame handle + * @param pOutRetVal - Handle for the created video frame handle. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_Copy( + rtcVideoFrameHandle videoFrame, + rtcVideoFrameHandle* pOutRetVal +) noexcept; + +/** + * Returns the datas of the video frame. + * + * @param videoFrame - Source video frame handle + * @param refFrameDatas - The frame datas. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_GetFrameDatas( + rtcVideoFrameHandle videoFrame, + rtcVideoFrameDatas* refFrameDatas +) noexcept; + +/** + * Returns the rotation of the video frame. (See: rtcVideoRotation) + * + * @param videoFrame - Source video frame handle + * @param pRotation - The frame rotation value. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_GetRotation( + rtcVideoFrameHandle videoFrame, + rtcVideoRotation* pOutRetVal +) noexcept; + #ifdef RTC_DESKTOP_DEVICE /* diff --git a/src/interop/rtc_video_frame_interop.cc b/src/interop/rtc_video_frame_interop.cc index f3c4cd0d8d..fd62aea5be 100644 --- a/src/interop/rtc_video_frame_interop.cc +++ b/src/interop/rtc_video_frame_interop.cc @@ -1,4 +1,127 @@ #include "rtc_video_frame.h" #include "interop_api.h" -using namespace libwebrtc; \ No newline at end of file +using namespace libwebrtc; + +/* + * ---------------------------------------------------------------------- + * RTCVideoFrame interop methods + * ---------------------------------------------------------------------- + */ + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_Create1( + int width, int height, + const unsigned char* buffer, int length, + rtcVideoFrameHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + + if (width < 2 + || (width % 4) != 0 + || height < 2 + || buffer == nullptr + || length < 6) + { + return rtcResultU4::kInvalidParameter; + } + + int nCalcLen = width * height + (((width >> 1) * (height >> 1)) << 1); + if (nCalcLen != length) { + return rtcResultU4::kOutOfRange; + } + + scoped_refptr pvf = RTCVideoFrame::Create( + width, height, + buffer, length + ); + CHECK_POINTER_EX(pvf, rtcResultU4::kUnknownError); + *pOutRetVal = static_cast(pvf.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_Create2( + const rtcVideoFrameDatas* frameDatas, + rtcVideoFrameHandle* pOutRetVal +) noexcept +{ + if (frameDatas == nullptr + || frameDatas->width < 2 + || (frameDatas->width % 4) != 0 + || frameDatas->height < 2 + || frameDatas->data_y == nullptr + || frameDatas->data_u == nullptr + || frameDatas->data_v == nullptr + || frameDatas->stride_y < 1 + || frameDatas->stride_y < 1 + || frameDatas->stride_v < 1) + { + return rtcResultU4::kInvalidParameter; + } + + scoped_refptr pvf = RTCVideoFrame::Create( + frameDatas->width, frameDatas->height, + frameDatas->data_y, frameDatas->stride_y, + frameDatas->data_u, frameDatas->stride_u, + frameDatas->data_v, frameDatas->stride_v + ); + CHECK_POINTER_EX(pvf, rtcResultU4::kUnknownError); + *pOutRetVal = static_cast(pvf.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_Copy( + rtcVideoFrameHandle videoFrame, + rtcVideoFrameHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + CHECK_NATIVE_HANDLE(videoFrame); + + scoped_refptr pvf = static_cast(videoFrame); + scoped_refptr pvfCopy = pvf->Copy(); + CHECK_POINTER_EX(pvfCopy, rtcResultU4::kUnknownError); + *pOutRetVal = static_cast(pvfCopy.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_GetFrameDatas( + rtcVideoFrameHandle videoFrame, + rtcVideoFrameDatas* refFrameDatas +) noexcept +{ + CHECK_POINTER(refFrameDatas); + ZERO_MEMORY(refFrameDatas, sizeof(rtcVideoFrameDatas)); + + scoped_refptr pvf = static_cast(videoFrame); + + refFrameDatas->width = pvf->width(); + refFrameDatas->height = pvf->height(); + refFrameDatas->data_y = static_cast(pvf->DataY()); + refFrameDatas->data_u = static_cast(pvf->DataU()); + refFrameDatas->data_v = static_cast(pvf->DataV()); + refFrameDatas->stride_y = pvf->StrideY(); + refFrameDatas->stride_u = pvf->StrideU(); + refFrameDatas->stride_v = pvf->StrideV(); + + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_GetRotation( + rtcVideoFrameHandle videoFrame, + rtcVideoRotation* pOutRetVal +) noexcept +{ + CHECK_POINTER(pOutRetVal); + *pOutRetVal = rtcVideoRotation::kVideoRotation_0; + CHECK_NATIVE_HANDLE(videoFrame); + + scoped_refptr pvf = static_cast(videoFrame); + *pOutRetVal = static_cast(pvf->rotation()); + return rtcResultU4::kSuccess; +} From 7b778e50a2fb4e0ebe0f7723b7b2f476900d78c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Tue, 17 Dec 2024 20:58:15 +0300 Subject: [PATCH 27/69] Added video frame interop methods --- include/interop_api.h | 21 +++++++++++++++++++ src/interop/rtc_video_frame_interop.cc | 29 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/include/interop_api.h b/include/interop_api.h index f6e06c9bb1..01bc3f377f 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -983,6 +983,27 @@ RTCVideoFrame_GetRotation( rtcVideoRotation* pOutRetVal ) noexcept; +/** + * Converts the video frame to RGB colorspace. + * + * @param videoFrame - Source video frame handle + * @param type - Type of destination video frame buffer. + * @param dst_argb - Destination video frame buffer. + * @param dst_stride_argb - Stride of destination video frame buffer. + * @param dest_width - Width of destination video frame buffer. + * @param dest_height - Height of destination video frame buffer. + * @return int - Size of destination + */ +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RTCVideoFrame_ConvertToARGB( + rtcVideoFrameHandle videoFrame, + rtcVideoFrameType type, + unsigned char* dst_argb, + int dst_stride_argb, + int dest_width, + int dest_height +) noexcept; + #ifdef RTC_DESKTOP_DEVICE /* diff --git a/src/interop/rtc_video_frame_interop.cc b/src/interop/rtc_video_frame_interop.cc index fd62aea5be..5c52a22629 100644 --- a/src/interop/rtc_video_frame_interop.cc +++ b/src/interop/rtc_video_frame_interop.cc @@ -125,3 +125,32 @@ RTCVideoFrame_GetRotation( *pOutRetVal = static_cast(pvf->rotation()); return rtcResultU4::kSuccess; } + +int LIB_WEBRTC_CALL +RTCVideoFrame_ConvertToARGB( + rtcVideoFrameHandle videoFrame, + rtcVideoFrameType type, + unsigned char* dst_argb, + int dst_stride_argb, + int dest_width, + int dest_height +) noexcept +{ + CHECK_POINTER_EX(videoFrame, 0); + if (dst_argb == nullptr + || dest_width < 2 + || dest_height < 2 + || dst_stride_argb < 12) + { + return 0; + } + + scoped_refptr pvf = static_cast(videoFrame); + return pvf->ConvertToARGB( + static_cast(type), + static_cast(dst_argb), + dst_stride_argb, + dest_width, + dest_height + ); +} From 0c19d853f8ba336ead4365bb0f9fffa7cf5e414f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Wed, 18 Dec 2024 12:47:41 +0300 Subject: [PATCH 28/69] Added rtc_video_renderer_impl.h, .cc --- BUILD.gn | 2 + include/interop_api.h | 67 +++++++++++++++++++++++ include/rtc_video_renderer.h | 8 ++- src/interop/rtc_video_renderer_interop.cc | 65 +++++++++++++++++++++- src/rtc_video_renderer_impl.cc | 54 ++++++++++++++++++ src/rtc_video_renderer_impl.h | 29 ++++++++++ 6 files changed, 223 insertions(+), 2 deletions(-) create mode 100644 src/rtc_video_renderer_impl.cc create mode 100644 src/rtc_video_renderer_impl.h diff --git a/BUILD.gn b/BUILD.gn index fa313fdd3b..0db7144b33 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -142,6 +142,8 @@ rtc_shared_library("libwebrtc") { "src/rtc_video_device_impl.h", "src/rtc_video_frame_impl.cc", "src/rtc_video_frame_impl.h", + "src/rtc_video_renderer_impl.cc", + "src/rtc_video_renderer_impl.h", "src/rtc_video_sink_adapter.cc", "src/rtc_video_sink_adapter.h", "src/rtc_video_source_impl.cc", diff --git a/include/interop_api.h b/include/interop_api.h index 01bc3f377f..1237561a59 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -289,6 +289,14 @@ struct rtcMediaListObserverCallbacks { rtcObjectHandle user_data_thumbnail_changed{}; }; +/** + * Callback OnFrame delegate for RTCVideoRenderer. + */ +using rtcVideoRendererFrameDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, + rtcVideoFrameHandle frame +); + /* * ---------------------------------------------------------------------- * LibWebRTC interop methods @@ -1004,6 +1012,65 @@ RTCVideoFrame_ConvertToARGB( int dest_height ) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCVideoRenderer interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Creates a new instance of the video renderer. + * + * @param pOutRetVal - Video renderer handle. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoRenderer_Create( + rtcVideoRendererHandle* pOutRetVal +) noexcept; + +/** + * Registers the callback method for the video renderer. + * + * @param videoRenderer - Video renderer handle. + * @param userData - User data handle + * @param callback - Callback method for OnFrame + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoRenderer_RegisterFrameCallback( + rtcVideoRendererHandle videoRenderer, + rtcObjectHandle userData, + rtcVideoRendererFrameDelegate callback +) noexcept; + +/** + * UnRegisters the callback method for the video renderer. + * + * @param videoRenderer - Video renderer handle. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoRenderer_UnRegisterFrameCallback( + rtcVideoRendererHandle videoRenderer +) noexcept; + +#if defined(DEBUG) || defined(_DEBUG) +/** + * It is used for testing purposes to trigger + * the OnRender callback method. + * + * @param videoRenderer - Video renderer handle. + * @param videoFrame - Video frame handle. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoRenderer_FireOnFrame( + rtcVideoRendererHandle videoRenderer, + rtcVideoFrameHandle videoFrame +) noexcept; +#endif // DEBUG or _DEBUG + #ifdef RTC_DESKTOP_DEVICE /* diff --git a/include/rtc_video_renderer.h b/include/rtc_video_renderer.h index 7e81d463f6..a7089cb941 100644 --- a/include/rtc_video_renderer.h +++ b/include/rtc_video_renderer.h @@ -6,11 +6,17 @@ namespace libwebrtc { template -class RTCVideoRenderer { +class RTCVideoRenderer : public RefCountInterface { public: virtual ~RTCVideoRenderer() {} virtual void OnFrame(VideoFrameT frame) = 0; + + virtual void RegisterFrameCallback(void* user_data /* rtcObjectHandle */, void* callback /* rtcVideoRendererFrameDelegate */) = 0; + virtual void UnRegisterFrameCallback() = 0; + + public: + LIB_WEBRTC_API static scoped_refptr> Create(); }; } // namespace libwebrtc diff --git a/src/interop/rtc_video_renderer_interop.cc b/src/interop/rtc_video_renderer_interop.cc index 12e93d7807..5f40af489b 100644 --- a/src/interop/rtc_video_renderer_interop.cc +++ b/src/interop/rtc_video_renderer_interop.cc @@ -1,4 +1,67 @@ #include "rtc_video_renderer.h" +#include "rtc_video_frame.h" #include "interop_api.h" -using namespace libwebrtc; \ No newline at end of file +using namespace libwebrtc; + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoRenderer_Create( + rtcVideoRendererHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + + scoped_refptr>> p = + RTCVideoRenderer>::Create(); + if (p == nullptr) { + return rtcResultU4::kUnknownError; + } + *pOutRetVal = static_cast(p.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoRenderer_RegisterFrameCallback( + rtcVideoRendererHandle videoRenderer, + rtcObjectHandle userData, + rtcVideoRendererFrameDelegate callback +) noexcept +{ + CHECK_NATIVE_HANDLE(videoRenderer); + + scoped_refptr>> p = + static_cast>*>(videoRenderer); + p->RegisterFrameCallback(static_cast(userData), reinterpret_cast(callback)); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoRenderer_UnRegisterFrameCallback( + rtcVideoRendererHandle videoRenderer +) noexcept +{ + CHECK_NATIVE_HANDLE(videoRenderer); + + scoped_refptr>> p = + static_cast>*>(videoRenderer); + p->UnRegisterFrameCallback(); + return rtcResultU4::kSuccess; +} + +#if defined(DEBUG) || defined(_DEBUG) +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoRenderer_FireOnFrame( + rtcVideoRendererHandle videoRenderer, + rtcVideoFrameHandle videoFrame +) noexcept +{ + CHECK_NATIVE_HANDLE(videoRenderer); + CHECK_NATIVE_HANDLE(videoFrame); + + scoped_refptr>> vr = + static_cast>*>(videoRenderer); + scoped_refptr vf = static_cast(videoFrame); + vr->OnFrame(vf); + return rtcResultU4::kSuccess; +} +#endif // DEBUG or _DEBUG diff --git a/src/rtc_video_renderer_impl.cc b/src/rtc_video_renderer_impl.cc new file mode 100644 index 0000000000..0ad2af413e --- /dev/null +++ b/src/rtc_video_renderer_impl.cc @@ -0,0 +1,54 @@ +#include "rtc_video_renderer_impl.h" + +#include "interop_api.h" +#include "rtc_base/logging.h" + +namespace libwebrtc { + +RTCVideoRendererImpl::RTCVideoRendererImpl() + : user_data_(nullptr) + , callback_(nullptr) +{ + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor " << (void*)this; +} + +RTCVideoRendererImpl::~RTCVideoRendererImpl() +{ + user_data_ = nullptr; + callback_ = nullptr; + RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; +} + +void RTCVideoRendererImpl::OnFrame(scoped_refptr frame) +{ + if (callback_) { + void* pFrame = static_cast(frame.release()); + callback_(user_data_, pFrame); + } +} + +void RTCVideoRendererImpl::RegisterFrameCallback(void* user_data /* rtcObjectHandle */, void* callback /* rtcVideoRendererFrameDelegate */) +{ + RTC_LOG(LS_INFO) << __FUNCTION__ << ": RegisterFrameCallback " << callback; + user_data_ = user_data; + callback_ = reinterpret_cast(callback); +} + +void RTCVideoRendererImpl::UnRegisterFrameCallback() +{ + RTC_LOG(LS_INFO) << __FUNCTION__; + user_data_ = nullptr; + callback_ = nullptr; +} + +template <> +scoped_refptr>> RTCVideoRenderer>::Create() +{ + scoped_refptr video_renderer = + scoped_refptr( + new RefCountedObject()); + + return video_renderer; +} + +} // namespace libwebrtc diff --git a/src/rtc_video_renderer_impl.h b/src/rtc_video_renderer_impl.h new file mode 100644 index 0000000000..516f25d5ed --- /dev/null +++ b/src/rtc_video_renderer_impl.h @@ -0,0 +1,29 @@ +#ifndef LIB_WEBRTC_VIDEO_RENDERER_IMPL_HXX +#define LIB_WEBRTC_VIDEO_RENDERER_IMPL_HXX + +#include "rtc_video_renderer.h" +#include "rtc_video_frame.h" + +namespace libwebrtc { + +class RTCVideoRendererImpl : public RTCVideoRenderer> { + public: + typedef fixed_size_function OnFrameCallback; + + public: + RTCVideoRendererImpl(); + virtual ~RTCVideoRendererImpl(); + + void OnFrame(scoped_refptr frame) override; + + void RegisterFrameCallback(void* user_data /* rtcObjectHandle */, void* callback /* rtcVideoRendererFrameDelegate */) override; + void UnRegisterFrameCallback() override; + + private: + void* user_data_ = nullptr; + OnFrameCallback callback_ = nullptr; +}; // end class RTCVideoRendererImpl + +} // end namespace libwebrtc + +#endif // LIB_WEBRTC_VIDEO_RENDERER_IMPL_HXX From ffb7dbbcf265faf366295a13270125534e087046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Wed, 18 Dec 2024 13:42:35 +0300 Subject: [PATCH 29/69] Added rtc_video_track_interop methods --- include/interop_api.h | 33 +++++++++++++++++++++++ src/interop/rtc_video_track_interop.cc | 36 +++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/include/interop_api.h b/include/interop_api.h index 1237561a59..8ecd156572 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -1071,6 +1071,39 @@ RTCVideoRenderer_FireOnFrame( ) noexcept; #endif // DEBUG or _DEBUG +/* + * ---------------------------------------------------------------------- + * RTCVideoTrack interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Adds a video renderer to the video track for frame callback operations. + * + * @param videoTrack - Video track handle. + * @param videoRenderer - Video renderer handle. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoTrack_AddRenderer( + rtcVideoTrackHandle videoTrack, + rtcVideoRendererHandle videoRenderer +) noexcept; + +/** + * Removes the video renderer that is already attached to + * the video track for frame callback operations. + * + * @param videoTrack - Video track handle. + * @param videoRenderer - Video renderer handle. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoTrack_RemoveRenderer( + rtcVideoTrackHandle videoTrack, + rtcVideoRendererHandle videoRenderer +) noexcept; + #ifdef RTC_DESKTOP_DEVICE /* diff --git a/src/interop/rtc_video_track_interop.cc b/src/interop/rtc_video_track_interop.cc index d43b890fd1..c0c45429bf 100644 --- a/src/interop/rtc_video_track_interop.cc +++ b/src/interop/rtc_video_track_interop.cc @@ -1,4 +1,38 @@ #include "rtc_video_track.h" #include "interop_api.h" +#include "rtc_video_frame.h" +#include "rtc_video_renderer.h" -using namespace libwebrtc; \ No newline at end of file +using namespace libwebrtc; + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoTrack_AddRenderer( + rtcVideoTrackHandle videoTrack, + rtcVideoRendererHandle videoRenderer +) noexcept +{ + CHECK_NATIVE_HANDLE(videoTrack); + CHECK_NATIVE_HANDLE(videoRenderer); + + scoped_refptr pVideoTrack = static_cast(videoTrack); + RTCVideoRenderer>* pVideoRenderer = + static_cast>*>(videoRenderer); + pVideoTrack->AddRenderer(pVideoRenderer); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoTrack_RemoveRenderer( + rtcVideoTrackHandle videoTrack, + rtcVideoRendererHandle videoRenderer +) noexcept +{ + CHECK_NATIVE_HANDLE(videoTrack); + CHECK_NATIVE_HANDLE(videoRenderer); + + scoped_refptr pVideoTrack = static_cast(videoTrack); + RTCVideoRenderer>* pVideoRenderer = + static_cast>*>(videoRenderer); + pVideoTrack->RemoveRenderer(pVideoRenderer); + return rtcResultU4::kSuccess; +} From 322006bc4dd98352ae86c557dcfe45ebc1cc609b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Thu, 19 Dec 2024 11:33:11 +0300 Subject: [PATCH 30/69] Added timestamp for video frame --- include/interop_api.h | 47 ++++++++++++++++++++++- include/rtc_video_frame.h | 7 ++++ src/interop/rtc_video_frame_interop.cc | 52 +++++++++++++++++++++++++- src/rtc_video_frame_impl.cc | 13 +++++++ src/rtc_video_frame_impl.h | 4 +- 5 files changed, 117 insertions(+), 6 deletions(-) diff --git a/include/interop_api.h b/include/interop_api.h index 8ecd156572..eadd389b98 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -32,6 +32,9 @@ using rtcSdpSemantics = libwebrtc::SdpSemantics; using rtcMediaType = libwebrtc::RTCMediaType; using rtcDesktopType = libwebrtc::DesktopType; +/// 64-bit timestamp for interop API. +using rtcTimestamp = long long; + /// 32-bit boolean for interop API. enum class rtcBool32 : int { kTrue = -1, @@ -923,7 +926,22 @@ RTCVideoCapturer_StopCapture( */ /** - * Creates a new instance of the video frame. (i420) + * Creates a new instance of an empty video frame. (i420) + * + * @param width - Frame width + * @param height - Frame height + * @param pOutRetVal - Handle for the created video frame class. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_Create0( + int width, int height, + rtcVideoFrameHandle* pOutRetVal +) noexcept; + +/** + * Creates a new instance of the video frame + * from the specified source buffer. (i420) * * @param width - Frame width * @param height - Frame height @@ -940,7 +958,8 @@ RTCVideoFrame_Create1( ) noexcept; /** - * Creates a new instance of the video frame. (i420) + * Creates a new instance of the video frame + * from the specified frame datas. (i420) * * @param frameDatas - Frame datas * @param pOutRetVal - Handle for the created video frame handle. @@ -991,6 +1010,30 @@ RTCVideoFrame_GetRotation( rtcVideoRotation* pOutRetVal ) noexcept; +/** + * Returns a timestamp in microseconds. + * + * @param videoFrame - Source video frame handle + * @return rtcTimestamp - Timestamp in microseconds. + */ +LIB_WEBRTC_API rtcTimestamp LIB_WEBRTC_CALL +RTCVideoFrame_GetTimestampInMicroseconds( + rtcVideoFrameHandle videoFrame +) noexcept; + +/** + * Sets the timestamp in microseconds. + * + * @param videoFrame - Source video frame handle + * @param timestampInMicroseconds - Timestamp in microseconds. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_SetTimestampInMicroseconds( + rtcVideoFrameHandle videoFrame, + rtcTimestamp timestampInMicroseconds +) noexcept; + /** * Converts the video frame to RGB colorspace. * diff --git a/include/rtc_video_frame.h b/include/rtc_video_frame.h index a69023f052..3be8013deb 100644 --- a/include/rtc_video_frame.h +++ b/include/rtc_video_frame.h @@ -17,6 +17,9 @@ class RTCVideoFrame : public RefCountInterface { }; public: + LIB_WEBRTC_API static scoped_refptr Create( + int width, int height); + LIB_WEBRTC_API static scoped_refptr Create( int width, int height, const uint8_t* buffer, int length); @@ -44,6 +47,10 @@ class RTCVideoFrame : public RefCountInterface { virtual int StrideU() const = 0; virtual int StrideV() const = 0; + // System monotonic clock, same timebase as rtc::TimeMicros(). + virtual int64_t timestamp_us() const = 0; + virtual void set_timestamp_us(int64_t timestamp_us) = 0; + virtual int ConvertToARGB(Type type, uint8_t* dst_argb, int dst_stride_argb, int dest_width, int dest_height) = 0; diff --git a/src/interop/rtc_video_frame_interop.cc b/src/interop/rtc_video_frame_interop.cc index 5c52a22629..aadbf24de9 100644 --- a/src/interop/rtc_video_frame_interop.cc +++ b/src/interop/rtc_video_frame_interop.cc @@ -9,6 +9,29 @@ using namespace libwebrtc; * ---------------------------------------------------------------------- */ +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_Create0( + int width, int height, + rtcVideoFrameHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + + if (width < 2 + || (width % 4) != 0 + || height < 2) + { + return rtcResultU4::kInvalidParameter; + } + + scoped_refptr pvf = RTCVideoFrame::Create( + width, height + ); + CHECK_POINTER_EX(pvf, rtcResultU4::kUnknownError); + *pOutRetVal = static_cast(pvf.release()); + return rtcResultU4::kSuccess; +} + rtcResultU4 LIB_WEBRTC_CALL RTCVideoFrame_Create1( int width, int height, @@ -26,8 +49,8 @@ RTCVideoFrame_Create1( { return rtcResultU4::kInvalidParameter; } - - int nCalcLen = width * height + (((width >> 1) * (height >> 1)) << 1); + + int nCalcLen = (width * height * 3) / 2; if (nCalcLen != length) { return rtcResultU4::kOutOfRange; } @@ -126,6 +149,31 @@ RTCVideoFrame_GetRotation( return rtcResultU4::kSuccess; } +rtcTimestamp LIB_WEBRTC_CALL +RTCVideoFrame_GetTimestampInMicroseconds( + rtcVideoFrameHandle videoFrame +) noexcept +{ + CHECK_POINTER_EX(videoFrame, static_cast(0LL)); + + scoped_refptr pvf = static_cast(videoFrame); + rtcTimestamp retVal = static_cast(pvf->timestamp_us()); + return retVal; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_SetTimestampInMicroseconds( + rtcVideoFrameHandle videoFrame, + rtcTimestamp timestampInMicroseconds +) noexcept +{ + CHECK_NATIVE_HANDLE(videoFrame); + + scoped_refptr pvf = static_cast(videoFrame); + pvf->set_timestamp_us(static_cast(timestampInMicroseconds)); + return rtcResultU4::kSuccess; +} + int LIB_WEBRTC_CALL RTCVideoFrame_ConvertToARGB( rtcVideoFrameHandle videoFrame, diff --git a/src/rtc_video_frame_impl.cc b/src/rtc_video_frame_impl.cc index 3c14db17a3..ca26c290c1 100644 --- a/src/rtc_video_frame_impl.cc +++ b/src/rtc_video_frame_impl.cc @@ -111,6 +111,19 @@ libwebrtc::RTCVideoFrame::VideoRotation VideoFrameBufferImpl::rotation() { return RTCVideoFrame::kVideoRotation_0; } +scoped_refptr RTCVideoFrame::Create(int width, int height) { + RTC_DCHECK(width > 1); + RTC_DCHECK(height > 1); + + rtc::scoped_refptr i420_buffer = webrtc::I420Buffer::Create( + width, height); + + scoped_refptr frame = + scoped_refptr( + new RefCountedObject(i420_buffer)); + return frame; +} + scoped_refptr RTCVideoFrame::Create(int width, int height, const uint8_t* buffer, int length) { diff --git a/src/rtc_video_frame_impl.h b/src/rtc_video_frame_impl.h index 3af6845abb..9b341f667b 100644 --- a/src/rtc_video_frame_impl.h +++ b/src/rtc_video_frame_impl.h @@ -42,8 +42,8 @@ class VideoFrameBufferImpl : public RTCVideoFrame { rtc::scoped_refptr buffer() { return buffer_; } // System monotonic clock, same timebase as rtc::TimeMicros(). - int64_t timestamp_us() const { return timestamp_us_; } - void set_timestamp_us(int64_t timestamp_us) { timestamp_us_ = timestamp_us; } + int64_t timestamp_us() const override{ return timestamp_us_; } + void set_timestamp_us(int64_t timestamp_us) override { timestamp_us_ = timestamp_us; } virtual RTCVideoFrame::VideoRotation rotation() override; From f37ba79532dc6ca9aab9950ddc9b387ab3bc3969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Thu, 19 Dec 2024 12:40:55 +0300 Subject: [PATCH 31/69] Updated BUILD.gn --- BUILD.gn | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/BUILD.gn b/BUILD.gn index 0db7144b33..e517b7e624 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -167,8 +167,14 @@ rtc_shared_library("libwebrtc") { "src/interop/rtc_video_track_interop.cc", "src/interop/rtc_video_frame_interop.cc", "src/interop/rtc_video_renderer_interop.cc", - "src/interop/rtc_desktop_device_interop.cc", ] + + if (libwebrtc_desktop_capture) { + sources += [ + "src/interop/rtc_desktop_media_list_interop.cc", + "src/interop/rtc_desktop_device_interop.cc", + ] + } } # intel media sdk From a4e5727c1bcb5c4b04822b5e01c570b7bf592ae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Fri, 20 Dec 2024 15:30:38 +0300 Subject: [PATCH 32/69] Added class, struct and enum types. --- BUILD.gn | 3 + include/interop_api.h | 1157 ++++++++++++++------------- include/rtc_ice_candidate.h | 3 +- include/rtc_peerconnection.h | 1 + include/rtc_sdp_parse_error.h | 27 + include/rtc_session_description.h | 3 +- include/rtc_types.h | 14 +- src/rtc_ice_candidate_impl.cc | 9 +- src/rtc_peerconnection_impl.cc | 5 +- src/rtc_sdp_parse_error_impl.cc | 30 + src/rtc_sdp_parse_error_impl.h | 29 + src/rtc_session_description_impl.cc | 9 +- 12 files changed, 737 insertions(+), 553 deletions(-) create mode 100644 include/rtc_sdp_parse_error.h create mode 100644 src/rtc_sdp_parse_error_impl.cc create mode 100644 src/rtc_sdp_parse_error_impl.h diff --git a/BUILD.gn b/BUILD.gn index e517b7e624..83f32863b5 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -76,6 +76,7 @@ rtc_shared_library("libwebrtc") { "include/rtc_dtls_transport.h", "include/rtc_dtmf_sender.h", "include/rtc_frame_cryptor.h", + "include/rtc_sdp_parse_error.h", "include/rtc_ice_candidate.h", "include/rtc_media_stream.h", "include/rtc_media_track.h", @@ -116,6 +117,8 @@ rtc_shared_library("libwebrtc") { "src/rtc_dtmf_sender_impl.h", "src/rtc_frame_cryptor_impl.cc", "src/rtc_frame_cryptor_impl.h", + "src/rtc_sdp_parse_error_impl.cc", + "src/rtc_sdp_parse_error_impl.h", "src/rtc_ice_candidate_impl.cc", "src/rtc_ice_candidate_impl.h", "src/rtc_media_stream_impl.cc", diff --git a/include/interop_api.h b/include/interop_api.h index eadd389b98..18a0929c2e 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -11,13 +11,28 @@ #include "rtc_types.h" -#define CHECK_POINTER_EX(p, r) if ((p) == nullptr) { return (r); } -#define CHECK_POINTER(p) CHECK_POINTER_EX(p, rtcResultU4::kInvalidPointer) -#define RESET_OUT_POINTER_EX(p,v) if ((p) != nullptr) { *(p) = (v); } -#define RESET_OUT_POINTER(p) RESET_OUT_POINTER_EX(p, nullptr) -#define CHECK_OUT_POINTER(p) if ((p) != nullptr) { *(p) = nullptr; } else { return rtcResultU4::kInvalidPointer; } -#define CHECK_NATIVE_HANDLE(h) CHECK_POINTER_EX(h, rtcResultU4::kInvalidNativeHandle) -#define ZERO_MEMORY(p,sz) if ((sz) > 0) { memset((void*)(p), 0, (size_t)(sz)); } +#define CHECK_POINTER_EX(p, r) \ + if ((p) == nullptr) { \ + return (r); \ + } +#define CHECK_POINTER(p) CHECK_POINTER_EX(p, rtcResultU4::kInvalidPointer) +#define RESET_OUT_POINTER_EX(p, v) \ + if ((p) != nullptr) { \ + *(p) = (v); \ + } +#define RESET_OUT_POINTER(p) RESET_OUT_POINTER_EX(p, nullptr) +#define CHECK_OUT_POINTER(p) \ + if ((p) != nullptr) { \ + *(p) = nullptr; \ + } else { \ + return rtcResultU4::kInvalidPointer; \ + } +#define CHECK_NATIVE_HANDLE(h) \ + CHECK_POINTER_EX(h, rtcResultU4::kInvalidNativeHandle) +#define ZERO_MEMORY(p, sz) \ + if ((sz) > 0) { \ + memset((void*)(p), 0, (size_t)(sz)); \ + } extern "C" { @@ -32,20 +47,15 @@ using rtcSdpSemantics = libwebrtc::SdpSemantics; using rtcMediaType = libwebrtc::RTCMediaType; using rtcDesktopType = libwebrtc::DesktopType; -/// 64-bit timestamp for interop API. +/// 64-bit timestamp for interop API. using rtcTimestamp = long long; /// 32-bit boolean for interop API. -enum class rtcBool32 : int { - kTrue = -1, - kFalse = 0 -}; +enum class rtcBool32 : int { kTrue = -1, kFalse = 0 }; -enum class rtcTrackState : int { - kUnknown = -1, - kLive = 0, - kEnded = 1 -}; +enum class rtcKeyRing : int { kMinSize = 1, kDefaultSize = 16, kMaxSize = 256 }; + +enum class rtcTrackState : int { kUnknown = -1, kLive = 0, kEnded = 1 }; enum class rtcVideoFrameType : int { kUnknown = -1, @@ -62,140 +72,304 @@ enum class rtcVideoRotation : int { kVideoRotation_270 = 270 }; +enum class rtcDataChannelState : int { + kConnecting = 0, + kOpen = 1, + kClosing = 2, + kClosed = 3 +}; + +enum class rtcDataChannelProtocol : int { kSCTP = 0, kQUIC = 1 }; + +enum class rtcDtlsTransportState : int { + kNew = 0, // Has not started negotiating yet. + kConnecting = 1, // In the process of negotiating a secure connection. + kConnected = 2, // Completed negotiation and verified fingerprints. + kClosed = 3, // Intentionally closed. + kFailed = 4, // Failure due to an error or failing to verify a remote + // fingerprint. + kNumValues = 5 +}; + +enum class rtcFrameCryptionAlgorithm : int { kAesGcm = 0, kAesCbc = 1 }; + +enum class rtcFrameCryptionState : int { + kNew = 0, + kOk = 1, + kEncryptionFailed = 2, + kDecryptionFailed = 3, + kMissingKey = 4, + kKeyRatcheted = 5, + kInternalError = 6 +}; + +enum class rtcSessionDescriptionErrorType : int { + kPeerConnectionInitFailed = 0, + kCreatePeerConnectionFailed = 1, + kSDPParseFailed = 2 +}; + +enum class rtcPeerConnectionState : int { + kNew = 0, + kConnecting = 1, + kConnected = 2, + kDisconnected = 3, + kFailed = 4, + kClosed = 5 +}; + +enum class rtcSignalingState : int { + kStable = 0, + kHaveLocalOffer = 1, + kHaveRemoteOffer = 2, + kHaveLocalPrAnswer = 3, + kHaveRemotePrAnswer = 4, + kClosed = 5 +}; + +enum class rtcIceGatheringState : int { + kNew = 0, + kGathering = 1, + kComplete = 2 +}; + +enum class rtcIceConnectionState : int { + kNew = 0, + kChecking = 1, + kCompleted = 2, + kConnected = 3, + kFailed = 4, + kDisconnected = 5, + kClosed = 6, + kMax = 7 +}; + +enum class rtcStatsMemberType : int { + kBool = 0, // bool + kInt32 = 1, // int32_t + kUint32 = 2, // uint32_t + kInt64 = 3, // int64_t + kUint64 = 4, // uint64_t + kDouble = 5, // double + kString = 6, // std::string + + kSequenceBool = 7, // std::vector + kSequenceInt32 = 8, // std::vector + kSequenceUint32 = 9, // std::vector + kSequenceInt64 = 10, // std::vector + kSequenceUint64 = 11, // std::vector + kSequenceDouble = 12, // std::vector + kSequenceString = 13, // std::vector + + kMapStringUint64 = 14, // std::map + kMapStringDouble = 15 // std::map +}; + +enum class rtcRtpTransceiverDirection : int { + kSendRecv = 0, + kSendOnly = 1, + kRecvOnly = 2, + kInactive = 3, + kStopped = 4 +}; + +enum class rtcFecMechanism : int { + kRED = 0, + kRED_AND_ULPFEC = 1, + kFLEXFEC = 2 +}; + +enum class rtcRtcpFeedbackType : int { + kCCM = 0, + kLNTF = 1, + kNACK = 2, + kREMB = 3, + kTRANSPORT_CC = 4 +}; + +enum class rtcRtcpFeedbackMessageType : int { + kGENERIC_NACK = 0, + kPLI = 1, + kFIR = 2 +}; + +enum class rtcDtxStatus : int { + kDISABLED = 0, + kENABLED = 1 +}; + +enum class rtcDegradationPreference : int { + kDISABLED = 0, + kMAINTAIN_FRAMERATE = 1, + kMAINTAIN_RESOLUTION = 2, + kBALANCED = 3 +}; + +enum class rtcNetworkPriority : int { + kVeryLow = 0, + kLow = 1, + kMedium = 2, + kHigh = 3 +}; + /// 32-bit result enumerator enum class rtcResultU4 : unsigned int { - /// The operation was successful. - kSuccess = 0, + /// The operation was successful. + kSuccess = 0, - // - // Generic errors - // + // + // Generic errors + // - /// Unknown internal error. - /// This is generally the fallback value when no other error code applies. - kUnknownError = 0x80000000, + /// Unknown internal error. + /// This is generally the fallback value when no other error code applies. + kUnknownError = 0x80000000, - /// A parameter passed to the API function was invalid. - kInvalidParameter = 0x80000001, + /// A parameter passed to the API function was invalid. + kInvalidParameter = 0x80000001, - /// The operation cannot be performed in the current state. - kInvalidOperation = 0x80000002, + /// The operation cannot be performed in the current state. + kInvalidOperation = 0x80000002, - /// A call was made to an API function on the wrong thread. - /// This is generally related to platforms with thread affinity like UWP. - kWrongThread = 0x80000003, + /// A call was made to an API function on the wrong thread. + /// This is generally related to platforms with thread affinity like UWP. + kWrongThread = 0x80000003, - /// An object was not found. - kNotFound = 0x80000004, + /// An object was not found. + kNotFound = 0x80000004, - /// An interop handle referencing a native object instance is invalid, - /// although the API function was expecting a valid object. - kInvalidNativeHandle = 0x80000005, + /// An interop handle referencing a native object instance is invalid, + /// although the API function was expecting a valid object. + kInvalidNativeHandle = 0x80000005, - /// The API object is not initialized, and cannot as a result perform the - /// given operation. - kNotInitialized = 0x80000006, + /// The API object is not initialized, and cannot as a result perform the + /// given operation. + kNotInitialized = 0x80000006, - /// The current operation is not supported by the implementation. - kUnsupported = 0x80000007, + /// The current operation is not supported by the implementation. + kUnsupported = 0x80000007, - /// An argument was passed to the API function with a value out of the - /// expected range. - kOutOfRange = 0x80000008, + /// An argument was passed to the API function with a value out of the + /// expected range. + kOutOfRange = 0x80000008, - /// The buffer provided by the caller was too small for the operation to - /// complete successfully. - kBufferTooSmall = 0x80000009, + /// The buffer provided by the caller was too small for the operation to + /// complete successfully. + kBufferTooSmall = 0x80000009, - // - // Peer connection (0x1xx) - // + // + // Peer connection (0x1xx) + // - /// The peer connection is closed, but the current operation requires an open - /// peer connection. - kPeerConnectionClosed = 0x80000101, + /// The peer connection is closed, but the current operation requires an open + /// peer connection. + kPeerConnectionClosed = 0x80000101, - // - // Data (0x3xx) - // + // + // Data (0x3xx) + // - /// The SCTP handshake for data channels encryption was not performed, because - /// the connection was established before any data channel was added to it. - /// Due to limitations in the implementation, without SCTP handshake data - /// channels cannot be used, and therefor applications expecting to use data - /// channels must open at least a single channel before establishing a peer - /// connection (calling |CreateOffer()|). - kSctpNotNegotiated = 0x80000301, + /// The SCTP handshake for data channels encryption was not performed, because + /// the connection was established before any data channel was added to it. + /// Due to limitations in the implementation, without SCTP handshake data + /// channels cannot be used, and therefor applications expecting to use data + /// channels must open at least a single channel before establishing a peer + /// connection (calling |CreateOffer()|). + kSctpNotNegotiated = 0x80000301, - /// The specified data channel ID is invalid. - kInvalidDataChannelId = 0x80000302, + /// The specified data channel ID is invalid. + kInvalidDataChannelId = 0x80000302, - // - // Media (0x4xx) - // + // + // Media (0x4xx) + // - /// Some audio-only function was called on a video-only object or vice-versa. - /// For example, trying to get the local audio track of a video transceiver. - kInvalidMediaKind = 0x80000401, + /// Some audio-only function was called on a video-only object or vice-versa. + /// For example, trying to get the local audio track of a video transceiver. + kInvalidMediaKind = 0x80000401, - /// The internal audio resampler used in the audio track read buffer doesn't - /// support the specified input/output frequency ratio. Use a different output - /// frequency for the current audio source to solve the issue. - kAudioResamplingNotSupported = 0x80000402, + /// The internal audio resampler used in the audio track read buffer doesn't + /// support the specified input/output frequency ratio. Use a different output + /// frequency for the current audio source to solve the issue. + kAudioResamplingNotSupported = 0x80000402, - /// Error rtcResultU4 for a null or invalid pointer. - kInvalidPointer = 0x80004003, -}; // end enum class rtcResultU4 + /// Error rtcResultU4 for a null or invalid pointer. + kInvalidPointer = 0x80004003, +}; // end enum class rtcResultU4 struct rtcIceServer { - const char* uri = nullptr; - const char* username = nullptr; - const char* password = nullptr; -}; // end struct rtcIceServer + const char* uri = nullptr; + const char* username = nullptr; + const char* password = nullptr; +}; // end struct rtcIceServer struct rtcPeerConnectionConfiguration { - rtcIceServer ice_servers[libwebrtc::kMaxIceServerSize]; - rtcIceTransportsType type = rtcIceTransportsType::kAll; - rtcBundlePolicy bundle_policy = rtcBundlePolicy::kBundlePolicyBalanced; - rtcRtcpMuxPolicy rtcp_mux_policy = rtcRtcpMuxPolicy::kRtcpMuxPolicyRequire; - rtcCandidateNetworkPolicy candidate_network_policy = - rtcCandidateNetworkPolicy::kCandidateNetworkPolicyAll; - rtcTcpCandidatePolicy tcp_candidate_policy = - rtcTcpCandidatePolicy::kTcpCandidatePolicyEnabled; - - int ice_candidate_pool_size = 0; - - rtcMediaSecurityType srtp_type = rtcMediaSecurityType::kDTLS_SRTP; - rtcSdpSemantics sdp_semantics = rtcSdpSemantics::kUnifiedPlan; - rtcBool32 offer_to_receive_audio = rtcBool32::kTrue; - rtcBool32 offer_to_receive_video = rtcBool32::kTrue; - - rtcBool32 disable_ipv6 = rtcBool32::kFalse; - rtcBool32 disable_ipv6_on_wifi = rtcBool32::kFalse; - int max_ipv6_networks = 5; - rtcBool32 disable_link_local_networks = rtcBool32::kFalse; - int screencast_min_bitrate = -1; - - // private - rtcBool32 use_rtp_mux = rtcBool32::kTrue; - uint32_t local_audio_bandwidth = 128; - uint32_t local_video_bandwidth = 512; -}; // end struct rtcPeerConnectionConfiguration + rtcIceServer ice_servers[libwebrtc::kMaxIceServerSize]; + rtcIceTransportsType type = rtcIceTransportsType::kAll; + rtcBundlePolicy bundle_policy = rtcBundlePolicy::kBundlePolicyBalanced; + rtcRtcpMuxPolicy rtcp_mux_policy = rtcRtcpMuxPolicy::kRtcpMuxPolicyRequire; + rtcCandidateNetworkPolicy candidate_network_policy = + rtcCandidateNetworkPolicy::kCandidateNetworkPolicyAll; + rtcTcpCandidatePolicy tcp_candidate_policy = + rtcTcpCandidatePolicy::kTcpCandidatePolicyEnabled; + + int ice_candidate_pool_size = 0; + + rtcMediaSecurityType srtp_type = rtcMediaSecurityType::kDTLS_SRTP; + rtcSdpSemantics sdp_semantics = rtcSdpSemantics::kUnifiedPlan; + rtcBool32 offer_to_receive_audio = rtcBool32::kTrue; + rtcBool32 offer_to_receive_video = rtcBool32::kTrue; + + rtcBool32 disable_ipv6 = rtcBool32::kFalse; + rtcBool32 disable_ipv6_on_wifi = rtcBool32::kFalse; + int max_ipv6_networks = 5; + rtcBool32 disable_link_local_networks = rtcBool32::kFalse; + int screencast_min_bitrate = -1; + + // private + rtcBool32 use_rtp_mux = rtcBool32::kTrue; + uint32_t local_audio_bandwidth = 128; + uint32_t local_video_bandwidth = 512; +}; // end struct rtcPeerConnectionConfiguration struct rtcVideoFrameDatas { - // frame width in pixel - int width = 0; - // frame height in pixel - int height = 0; - // The YUV starting address of the frame buffer. - const unsigned char* data_y = nullptr; - const unsigned char* data_u = nullptr; - const unsigned char* data_v = nullptr; - // The stride of the YUV - int stride_y = 0; - int stride_u = 0; - int stride_v = 0; -}; // end struct rtcVideoFrameDatas + // frame width in pixel + int width = 0; + // frame height in pixel + int height = 0; + // The YUV starting address of the frame buffer. + const unsigned char* data_y = nullptr; + const unsigned char* data_u = nullptr; + const unsigned char* data_v = nullptr; + // The stride of the YUV + int stride_y = 0; + int stride_u = 0; + int stride_v = 0; +}; // end struct rtcVideoFrameDatas + +struct rtcDataChannelInit { + rtcBool32 ordered = rtcBool32::kTrue; + rtcBool32 reliable = rtcBool32::kTrue; + int maxRetransmitTime = -1; + int maxRetransmits = -1; + rtcDataChannelProtocol protocol = + rtcDataChannelProtocol::kSCTP; // kSCTP | kQUIC + rtcBool32 negotiated = rtcBool32::kFalse; + int id = 0; +}; // end struct rtcDataChannelInit + +struct rtcKeyProviderOptions { + rtcBool32 shared_key = rtcBool32::kFalse; + unsigned char* ratchet_salt = nullptr; + int ratchet_salt_len = 0; + unsigned char* uncrypted_magic_bytes = nullptr; + int uncrypted_magic_bytes_len = 0; + int ratchet_window_size = 0; + int failure_tolerance = -1; + // The size of the key ring. between 1 and 255. + int key_ring_size = static_cast(rtcKeyRing::kDefaultSize); + rtcBool32 discard_frame_when_cryptor_not_ready = rtcBool32::kFalse; +}; // end struct rtcKeyProviderOptions /// Opaque handle to a native interop object. using rtcObjectHandle = void*; @@ -206,6 +380,9 @@ using rtcRefCountedObjectHandle = rtcObjectHandle; /// Opaque handle to a native RTCPeerConnectionFactory interop object. using rtcPeerConnectionFactoryHandle = rtcRefCountedObjectHandle; +/// Opaque handle to a native RTCPeerConnectionObserver interop object. +using rtcPeerConnectionObserverHandle = rtcObjectHandle; + /// Opaque handle to a native RTCPeerConnection interop object. using rtcPeerConnectionHandle = rtcRefCountedObjectHandle; @@ -245,9 +422,6 @@ using rtcDesktopMediaListObserverHandle = rtcObjectHandle; /// Opaque handle to a native RTCMediaStream interop object. using rtcMediaStreamHandle = rtcRefCountedObjectHandle; -/// Opaque handle to a native RTCRtpCapabilities interop object. -using rtcRtpCapabilitiesHandle = rtcRefCountedObjectHandle; - /// Opaque handle to a native RTCMediaTrack interop object. using rtcMediaTrackHandle = rtcRefCountedObjectHandle; @@ -261,7 +435,100 @@ using rtcVideoTrackHandle = rtcMediaTrackHandle; using rtcVideoFrameHandle = rtcRefCountedObjectHandle; /// Opaque handle to a native RTCVideoRenderer interop object. -using rtcVideoRendererHandle = rtcRefCountedObjectHandle; // ??? +using rtcVideoRendererHandle = rtcRefCountedObjectHandle; // ??? + +/// Opaque handle to a native RTCDataChannel interop object. +using rtcDataChannelHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCDataChannelObserver interop object. +using rtcDataChannelObserverHandle = rtcObjectHandle; + +/// Opaque handle to a native RTCDtlsTransportInformation interop object. +using rtcDtlsTransportInformationHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCDtlsTransportObserver interop object. +using rtcDtlsTransportObserverHandle = rtcObjectHandle; + +/// Opaque handle to a native RTCDtlsTransport interop object. +using rtcDtlsTransportHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCDtmfSenderObserver interop object. +using rtcDtmfSenderObserverHandle = rtcObjectHandle; + +/// Opaque handle to a native RTCDtmfSender interop object. +using rtcDtmfSenderHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native KeyProvider interop object. +using rtcKeyProviderHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCFrameCryptorObserver interop object. +using rtcFrameCryptorObserverHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCFrameCryptor interop object. +using rtcFrameCryptorHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCSdpParseError interop object. +using rtcSdpParseErrorHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCIceCandidate interop object. +using rtcIceCandidateHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native IceTransport interop object. +using rtcIceTransportHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCStatsMember interop object. +using rtcStatsMemberHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native MediaRTCStats interop object. +using rtcMediaRTCStatsHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCRtpCodecCapability interop object. +using rtcRtpCodecCapabilityHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCRtpHeaderExtensionCapability interop object. +using rtcRtpHeaderExtensionCapabilityHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCRtpCapabilities interop object. +using rtcRtpCapabilitiesHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCRtcpFeedback interop object. +using rtcRtcpFeedbackHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCRtpExtension interop object. +using rtcRtpExtensionHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RtpFecParameters interop object. +using rtcRtpFecParametersHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCRtpCodecParameters interop object. +using rtcRtpCodecParametersHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCRtcpParameters interop object. +using rtcRtcpParametersHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCRtpEncodingParameters interop object. +using rtcRtpEncodingParametersHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCRtpParameters interop object. +using rtcRtpParametersHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCRtpReceiverObserver interop object. +using rtcRtpReceiverObserverHandle = rtcObjectHandle; + +/// Opaque handle to a native RTCRtpReceiver interop object. +using rtcRtpReceiverHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCRtpSender interop object. +using rtcRtpSenderHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCRtpTransceiverInit interop object. +using rtcRtpTransceiverInitHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCRtpTransceiver interop object. +using rtcRtpTransceiverHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCSessionDescription interop object. +using rtcSessionDescriptionHandle = rtcRefCountedObjectHandle; /* ---------------------------------------------------------------- */ @@ -271,39 +538,35 @@ using rtcVideoRendererHandle = rtcRefCountedObjectHandle; // ??? using rtcAudioDeviceChangeDelegate = void(LIB_WEBRTC_CALL*)(); /** - * Callback delegate for MediaListObserve. + * Callback delegate for MediaListObserver. */ using rtcMediaListObserverDelegate = void(LIB_WEBRTC_CALL*)( - rtcObjectHandle user_data, - rtcDesktopMediaSourceHandle source -); + rtcObjectHandle user_data, rtcDesktopMediaSourceHandle source); /** - * Callback delegate structure for MediaListObserve. + * Callback delegate structure for MediaListObserver. */ struct rtcMediaListObserverCallbacks { - rtcMediaListObserverDelegate MediaSourceAdded{}; - rtcObjectHandle user_data_added{}; - rtcMediaListObserverDelegate MediaSourceRemoved{}; - rtcObjectHandle user_data_removed{}; - rtcMediaListObserverDelegate MediaSourceNameChanged{}; - rtcObjectHandle user_data_name_changed{}; - rtcMediaListObserverDelegate MediaSourceThumbnailChanged{}; - rtcObjectHandle user_data_thumbnail_changed{}; + rtcMediaListObserverDelegate MediaSourceAdded{}; + rtcObjectHandle user_data_added{}; + rtcMediaListObserverDelegate MediaSourceRemoved{}; + rtcObjectHandle user_data_removed{}; + rtcMediaListObserverDelegate MediaSourceNameChanged{}; + rtcObjectHandle user_data_name_changed{}; + rtcMediaListObserverDelegate MediaSourceThumbnailChanged{}; + rtcObjectHandle user_data_thumbnail_changed{}; }; /** * Callback OnFrame delegate for RTCVideoRenderer. */ using rtcVideoRendererFrameDelegate = void(LIB_WEBRTC_CALL*)( - rtcObjectHandle user_data, - rtcVideoFrameHandle frame -); + rtcObjectHandle user_data, rtcVideoFrameHandle frame); /* - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * LibWebRTC interop methods - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ /** @@ -315,8 +578,7 @@ using rtcVideoRendererFrameDelegate = void(LIB_WEBRTC_CALL*)( * * @return kTrue if initialization is successful, kFalse otherwise. */ -LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL -LibWebRTC_Initialize() noexcept; +LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL LibWebRTC_Initialize() noexcept; /** * @brief Creates a new WebRTC PeerConnectionFactory. @@ -340,24 +602,18 @@ LibWebRTC_CreateRTCPeerConnectionFactory() noexcept; * network_thread. * */ -LIB_WEBRTC_API void LIB_WEBRTC_CALL -LibWebRTC_Terminate() noexcept; +LIB_WEBRTC_API void LIB_WEBRTC_CALL LibWebRTC_Terminate() noexcept; /** * @brief Returns the error message text for the specified 'code' value. */ -LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -LibWebRTC_GetErrorMessage( - rtcResultU4 code, - char* pBuffer, - unsigned int cchBuffer -) noexcept; - +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL LibWebRTC_GetErrorMessage( + rtcResultU4 code, char* pBuffer, unsigned int cchBuffer) noexcept; /* - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * RefCountedObject interop methods - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ /** @@ -372,11 +628,10 @@ RefCountedObject_AddRef(rtcRefCountedObjectHandle handle) noexcept; LIB_WEBRTC_API int LIB_WEBRTC_CALL RefCountedObject_Release(rtcRefCountedObjectHandle handle) noexcept; - /* - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * MediaConstraints interop methods - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ /** @@ -386,22 +641,19 @@ LIB_WEBRTC_API rtcMediaConstraintsHandle LIB_WEBRTC_CALL MediaConstraints_Create() noexcept; LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -MediaConstraints_AddMandatoryConstraint( - rtcMediaConstraintsHandle handle, - const char* key, - const char* value) noexcept; +MediaConstraints_AddMandatoryConstraint(rtcMediaConstraintsHandle handle, + const char* key, + const char* value) noexcept; LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -MediaConstraints_AddOptionalConstraint( - rtcMediaConstraintsHandle handle, - const char* key, - const char* value) noexcept; - +MediaConstraints_AddOptionalConstraint(rtcMediaConstraintsHandle handle, + const char* key, + const char* value) noexcept; /* - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * RTCPeerConnectionFactory interop methods - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ /** @@ -415,18 +667,14 @@ RTCPeerConnectionFactory_Create() noexcept; * If the LibWebRTC_Initialize method has been called; * do not use this method. */ -LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL -RTCPeerConnectionFactory_Initialize( - rtcPeerConnectionFactoryHandle factory -) noexcept; +LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL RTCPeerConnectionFactory_Initialize( + rtcPeerConnectionFactoryHandle factory) noexcept; /** * @brief Terminates the RTCPeerConnectionFactor object. */ -LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL -RTCPeerConnectionFactory_Terminate( - rtcPeerConnectionFactoryHandle factory -) noexcept; +LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL RTCPeerConnectionFactory_Terminate( + rtcPeerConnectionFactoryHandle factory) noexcept; /** * @brief Creates a new instance of the RTCPeerConnection object. @@ -444,56 +692,45 @@ RTCPeerConnectionFactory_CreatePeerConnection( LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_DeletePeerConnection( rtcPeerConnectionFactoryHandle factory, - rtcPeerConnectionHandle handle -) noexcept; + rtcPeerConnectionHandle handle) noexcept; /** * @brief Provides RTCAudioDevice object for list audio devices. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCPeerConnectionFactory_GetAudioDevice( - rtcPeerConnectionFactoryHandle factory, - rtcAudioDeviceHandle* pRetVal -) noexcept; +RTCPeerConnectionFactory_GetAudioDevice(rtcPeerConnectionFactoryHandle factory, + rtcAudioDeviceHandle* pRetVal) noexcept; /** * @brief Provides RTCVideoDevice object for list video devices. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCPeerConnectionFactory_GetVideoDevice( - rtcPeerConnectionFactoryHandle factory, - rtcVideoDeviceHandle* pRetVal -) noexcept; +RTCPeerConnectionFactory_GetVideoDevice(rtcPeerConnectionFactoryHandle factory, + rtcVideoDeviceHandle* pRetVal) noexcept; #ifdef RTC_DESKTOP_DEVICE LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_GetDesktopDevice( rtcPeerConnectionFactoryHandle factory, - rtcDesktopDeviceHandle* pRetVal -) noexcept; -#endif // RTC_DESKTOP_DEVICE + rtcDesktopDeviceHandle* pRetVal) noexcept; +#endif // RTC_DESKTOP_DEVICE /** * @brief Creates a new instance of the RTCAudioSource object. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_CreateAudioSource( - rtcPeerConnectionFactoryHandle factory, - const char* audio_source_label, - rtcAudioSourceHandle* pRetVal -) noexcept; + rtcPeerConnectionFactoryHandle factory, const char* audio_source_label, + rtcAudioSourceHandle* pRetVal) noexcept; /** * @brief Creates a new instance of the RTCVideoSource object. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_CreateVideoSource( - rtcPeerConnectionFactoryHandle factory, - rtcVideoCapturerHandle capturer, - const char* video_source_label, - rtcMediaConstraintsHandle constraints, - rtcVideoSourceHandle* pRetVal -) noexcept; + rtcPeerConnectionFactoryHandle factory, rtcVideoCapturerHandle capturer, + const char* video_source_label, rtcMediaConstraintsHandle constraints, + rtcVideoSourceHandle* pRetVal) noexcept; #ifdef RTC_DESKTOP_DEVICE /** @@ -501,45 +738,34 @@ RTCPeerConnectionFactory_CreateVideoSource( */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_CreateDesktopSource( - rtcPeerConnectionFactoryHandle factory, - rtcDesktopCapturerHandle capturer, - const char* video_source_label, - rtcMediaConstraintsHandle constraints, - rtcVideoSourceHandle* pRetVal -) noexcept; -#endif // RTC_DESKTOP_DEVICE + rtcPeerConnectionFactoryHandle factory, rtcDesktopCapturerHandle capturer, + const char* video_source_label, rtcMediaConstraintsHandle constraints, + rtcVideoSourceHandle* pRetVal) noexcept; +#endif // RTC_DESKTOP_DEVICE /** * @brief Creates a new instance of the RTCAudioTrack object. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_CreateAudioTrack( - rtcPeerConnectionFactoryHandle factory, - rtcAudioSourceHandle source, - const char* track_id, - rtcAudioTrackHandle* pRetVal -) noexcept; + rtcPeerConnectionFactoryHandle factory, rtcAudioSourceHandle source, + const char* track_id, rtcAudioTrackHandle* pRetVal) noexcept; /** * @brief Creates a new instance of the RTCVideoTrack object. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_CreateVideoTrack( - rtcPeerConnectionFactoryHandle factory, - rtcVideoSourceHandle source, - const char* track_id, - rtcVideoTrackHandle* pRetVal -) noexcept; + rtcPeerConnectionFactoryHandle factory, rtcVideoSourceHandle source, + const char* track_id, rtcVideoTrackHandle* pRetVal) noexcept; /** * @brief Creates a new instance of the RTCMediaStream object. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCPeerConnectionFactory_CreateStream( - rtcPeerConnectionFactoryHandle factory, - const char* stream_id, - rtcMediaStreamHandle* pRetVal -) noexcept; +RTCPeerConnectionFactory_CreateStream(rtcPeerConnectionFactoryHandle factory, + const char* stream_id, + rtcMediaStreamHandle* pRetVal) noexcept; /** * Returns an RTCRtpCapabilities object containing the @@ -547,10 +773,8 @@ RTCPeerConnectionFactory_CreateStream( */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_GetRtpSenderCapabilities( - rtcPeerConnectionFactoryHandle factory, - rtcMediaType media_type, - rtcRtpCapabilitiesHandle* pRetVal -) noexcept; + rtcPeerConnectionFactoryHandle factory, rtcMediaType media_type, + rtcRtpCapabilitiesHandle* pRetVal) noexcept; /** * Returns an RTCRtpCapabilities object containing the @@ -558,15 +782,13 @@ RTCPeerConnectionFactory_GetRtpSenderCapabilities( */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_GetRtpReceiverCapabilities( - rtcPeerConnectionFactoryHandle factory, - rtcMediaType media_type, - rtcRtpCapabilitiesHandle* pRetVal -) noexcept; + rtcPeerConnectionFactoryHandle factory, rtcMediaType media_type, + rtcRtpCapabilitiesHandle* pRetVal) noexcept; /* - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * RTCAudioDevice interop methods - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ /** @@ -576,9 +798,7 @@ RTCPeerConnectionFactory_GetRtpReceiverCapabilities( * @return int - The number of playout devices available. */ LIB_WEBRTC_API int LIB_WEBRTC_CALL -RTCAudioDevice_PlayoutDevices( - rtcAudioDeviceHandle audiDevice -) noexcept; +RTCAudioDevice_PlayoutDevices(rtcAudioDeviceHandle audiDevice) noexcept; /** * Returns the number of recording devices available. @@ -587,9 +807,7 @@ RTCAudioDevice_PlayoutDevices( * @return int - The number of recording devices available. */ LIB_WEBRTC_API int LIB_WEBRTC_CALL -RTCAudioDevice_RecordingDevices( - rtcAudioDeviceHandle audiDevice -) noexcept; +RTCAudioDevice_RecordingDevices(rtcAudioDeviceHandle audiDevice) noexcept; /** * Retrieves the name and GUID of the specified playout device. @@ -602,15 +820,9 @@ RTCAudioDevice_RecordingDevices( * @param cchOutGuid - The size of the guid. * @return rtcResultU4 - 0 if successful, otherwise an error code. */ -LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCAudioDevice_PlayoutDeviceName( - rtcAudioDeviceHandle audiDevice, - int index, - char* pOutName, - int cchOutName, - char* pOutGuid, - int cchOutGuid -) noexcept; +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCAudioDevice_PlayoutDeviceName( + rtcAudioDeviceHandle audiDevice, int index, char* pOutName, int cchOutName, + char* pOutGuid, int cchOutGuid) noexcept; /** * Retrieves the name and GUID of the specified recording device. @@ -623,15 +835,9 @@ RTCAudioDevice_PlayoutDeviceName( * @param cchOutGuid - The size of the guid. * @return rtcResultU4 - 0 if successful, otherwise an error code. */ -LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCAudioDevice_RecordingDeviceName( - rtcAudioDeviceHandle audiDevice, - int index, - char* pOutName, - int cchOutName, - char* pOutGuid, - int cchOutGuid -) noexcept; +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCAudioDevice_RecordingDeviceName( + rtcAudioDeviceHandle audiDevice, int index, char* pOutName, int cchOutName, + char* pOutGuid, int cchOutGuid) noexcept; /** * Sets the playout device to use. @@ -640,11 +846,8 @@ RTCAudioDevice_RecordingDeviceName( * @param index - The index of the device. * @return rtcResultU4 - 0 if successful, otherwise an error code. */ -LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCAudioDevice_SetPlayoutDevice( - rtcAudioDeviceHandle audiDevice, - int index -) noexcept; +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCAudioDevice_SetPlayoutDevice( + rtcAudioDeviceHandle audiDevice, int index) noexcept; /** * Sets the recording device to use. @@ -653,15 +856,12 @@ RTCAudioDevice_SetPlayoutDevice( * @param index - The index of the device. * @return rtcResultU4 - 0 if successful, otherwise an error code. */ -LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCAudioDevice_SetRecordingDevice( - rtcAudioDeviceHandle audiDevice, - int index -) noexcept; +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCAudioDevice_SetRecordingDevice( + rtcAudioDeviceHandle audiDevice, int index) noexcept; /** * The callback was invoked when the audio device changed. - * + * * @param audiDevice - Audio device handle * @param deviceChangeCallback - Callback delegate * @return rtcResultU4 - 0 if successful, otherwise an error code. @@ -669,156 +869,124 @@ RTCAudioDevice_SetRecordingDevice( LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCAudioDevice_RegisterDeviceChangeCallback( rtcAudioDeviceHandle audiDevice, - rtcAudioDeviceChangeDelegate deviceChangeCallback -) noexcept; + rtcAudioDeviceChangeDelegate deviceChangeCallback) noexcept; /** * Sets the microphone volume level. - * + * * @param audiDevice - Audio device handle * @param volume - Volume level * @return rtcResultU4 - 0 if successful, otherwise an error code. */ -LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCAudioDevice_SetMicrophoneVolume( - rtcAudioDeviceHandle audiDevice, - unsigned int volume -) noexcept; +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCAudioDevice_SetMicrophoneVolume( + rtcAudioDeviceHandle audiDevice, unsigned int volume) noexcept; /** * Gets the microphone volume level. - * + * * @param audiDevice - Audio device handle * @param volume - Volume level * @return rtcResultU4 - 0 if successful, otherwise an error code. */ -LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCAudioDevice_GetMicrophoneVolume( - rtcAudioDeviceHandle audiDevice, - unsigned int* volume -) noexcept; +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCAudioDevice_GetMicrophoneVolume( + rtcAudioDeviceHandle audiDevice, unsigned int* volume) noexcept; /** * Sets the speaker volume level. - * + * * @param audiDevice - Audio device handle * @param volume - Volume level * @return rtcResultU4 - 0 if successful, otherwise an error code. */ -LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCAudioDevice_SetSpeakerVolume( - rtcAudioDeviceHandle audiDevice, - unsigned int volume -) noexcept; +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCAudioDevice_SetSpeakerVolume( + rtcAudioDeviceHandle audiDevice, unsigned int volume) noexcept; /** * Gets the speaker volume level. - * + * * @param audiDevice - Audio device handle * @param volume - Volume level * @return rtcResultU4 - 0 if successful, otherwise an error code. */ -LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCAudioDevice_GetSpeakerVolume( - rtcAudioDeviceHandle audiDevice, - unsigned int* volume -) noexcept; +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCAudioDevice_GetSpeakerVolume( + rtcAudioDeviceHandle audiDevice, unsigned int* volume) noexcept; /* - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * RTCMediaTrack interop methods - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ /** * Returns the track state. - * + * * @param mediaTrack - Media track handle * @return rtcTrackState - Track state enum */ LIB_WEBRTC_API rtcTrackState LIB_WEBRTC_CALL -RTCMediaTrack_GetState( - rtcMediaTrackHandle mediaTrack -) noexcept; +RTCMediaTrack_GetState(rtcMediaTrackHandle mediaTrack) noexcept; /** * Returns the track kind. (video, audio, vs.) - * + * * @param mediaTrack - Media track handle * @param pOutKind - Media track kind * @param cchOutKind - The size of the kind * @return rtcResultU4 - 0 if successful, otherwise an error code. */ -LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCMediaTrack_GetKind( - rtcMediaTrackHandle mediaTrack, - char* pOutKind, - int cchOutKind -) noexcept; +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCMediaTrack_GetKind( + rtcMediaTrackHandle mediaTrack, char* pOutKind, int cchOutKind) noexcept; /** * Returns the track id. - * + * * @param mediaTrack - Media track handle * @param pOutId - Media track id * @param cchOutId - The size of the id * @return rtcResultU4 - 0 if successful, otherwise an error code. */ -LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCMediaTrack_GetId( - rtcMediaTrackHandle mediaTrack, - char* pOutId, - int cchOutId -) noexcept; +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCMediaTrack_GetId( + rtcMediaTrackHandle mediaTrack, char* pOutId, int cchOutId) noexcept; /** * Returns the enable/disable status of the track. - * + * * @param mediaTrack - Media track handle * @return rtcBool32 - kTrue if enabled, otherwise disabled */ LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL -RTCMediaTrack_GetEnabled( - rtcMediaTrackHandle mediaTrack -) noexcept; +RTCMediaTrack_GetEnabled(rtcMediaTrackHandle mediaTrack) noexcept; /** * Sets the enable/disable of the track. - * + * * @param mediaTrack - Media track handle * @param enabled - Media track enable/disable value * @return rtcBool32 - kTrue if the property has changed, otherwise kFalse */ -LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL -RTCMediaTrack_SetEnabled( - rtcMediaTrackHandle mediaTrack, - rtcBool32 enabled -) noexcept; +LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL RTCMediaTrack_SetEnabled( + rtcMediaTrackHandle mediaTrack, rtcBool32 enabled) noexcept; /* - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * RTCAudioTrack interop methods - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ /** * Sets the volume of the audio track. - * + * * @param audioTrack - Audio track handle * @param volume - volume in [0-10] * @return rtcResultU4 - 0 if successful, otherwise an error code. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCAudioTrack_SetVolume( - rtcAudioTrackHandle audioTrack, - double volume -) noexcept; - +RTCAudioTrack_SetVolume(rtcAudioTrackHandle audioTrack, double volume) noexcept; /* - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * RTCVideoDevice interop methods - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ /** @@ -828,13 +996,11 @@ RTCAudioTrack_SetVolume( * @return int - The number of video devices available. */ LIB_WEBRTC_API int LIB_WEBRTC_CALL -RTCVideoDevice_NumberOfDevices( - rtcVideoDeviceHandle videoDevice -) noexcept; +RTCVideoDevice_NumberOfDevices(rtcVideoDeviceHandle videoDevice) noexcept; /** * Returns information about video device with the specified index. - * + * * @param videoDevice - Video device handle * @param index - The index of the device. * @param pOutDeviceNameUTF8 - Device name @@ -845,21 +1011,15 @@ RTCVideoDevice_NumberOfDevices( * @param cchOutProductUniqueIdUTF8 - The size of the product id. * @return rtcResultU4 - 0 if successful, otherwise an error code. */ -LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCVideoDevice_GetDeviceName( - rtcVideoDeviceHandle videoDevice, - int index, - char* pOutDeviceNameUTF8, - int cchOutDeviceNameUTF8, - char* pOutDeviceUniqueIdUTF8, - int cchOutDeviceUniqueIdUTF8, - char* pOutProductUniqueIdUTF8 = 0, - int cchOutProductUniqueIdUTF8 = 0 -) noexcept; +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCVideoDevice_GetDeviceName( + rtcVideoDeviceHandle videoDevice, int index, char* pOutDeviceNameUTF8, + int cchOutDeviceNameUTF8, char* pOutDeviceUniqueIdUTF8, + int cchOutDeviceUniqueIdUTF8, char* pOutProductUniqueIdUTF8 = 0, + int cchOutProductUniqueIdUTF8 = 0) noexcept; /** * Creates a new instance of the RTCVideoCapturer object. - * + * * @param videoDevice - Video device handle * @param name - Video capturer name (for logs) * @param index - The index of the video device. @@ -869,80 +1029,65 @@ RTCVideoDevice_GetDeviceName( * @param pOutRetVal - Handle for the RTCVideoCapturer object to be created. * @return rtcResultU4 - 0 if successful, otherwise an error code. */ -LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCVideoDevice_CreateVideoCapturer( - rtcVideoDeviceHandle videoDevice, - const char* name, - int index, - int width, - int height, - int target_fps, - rtcVideoCapturerHandle* pOutRetVal -) noexcept; +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCVideoDevice_CreateVideoCapturer( + rtcVideoDeviceHandle videoDevice, const char* name, int index, int width, + int height, int target_fps, rtcVideoCapturerHandle* pOutRetVal) noexcept; /* - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * RTCVideoCapturer interop methods - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ /** * Starts video capturing. - * + * * @param videoCapturer - Video capturer handle - * @return rtcBool32 - rtcBool32::kTrue if successful, otherwise rtcBool32::kFalse + * @return rtcBool32 - rtcBool32::kTrue if successful, otherwise + * rtcBool32::kFalse */ LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL -RTCVideoCapturer_StartCapture( - rtcVideoCapturerHandle videoCapturer -) noexcept; +RTCVideoCapturer_StartCapture(rtcVideoCapturerHandle videoCapturer) noexcept; /** * Returns whether the capture state has been initialized. - * + * * @param videoCapturer - Video capturer handle * @return rtcBool32 - rtcBool32::kTrue if started, otherwise rtcBool32::kFalse */ LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL -RTCVideoCapturer_CaptureStarted( - rtcVideoCapturerHandle videoCapturer -) noexcept; +RTCVideoCapturer_CaptureStarted(rtcVideoCapturerHandle videoCapturer) noexcept; /** * Stops video capture. - * + * * @param videoCapturer - Video capturer handle * @return rtcResultU4 - 0 if successful, otherwise an error code. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCVideoCapturer_StopCapture( - rtcVideoCapturerHandle videoCapturer -) noexcept; +RTCVideoCapturer_StopCapture(rtcVideoCapturerHandle videoCapturer) noexcept; /* - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * RTCVideoFrame interop methods - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ /** * Creates a new instance of an empty video frame. (i420) - * + * * @param width - Frame width * @param height - Frame height * @param pOutRetVal - Handle for the created video frame class. * @return rtcResultU4 - 0 if successful, otherwise an error code. */ -LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCVideoFrame_Create0( - int width, int height, - rtcVideoFrameHandle* pOutRetVal -) noexcept; +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCVideoFrame_Create0( + int width, int height, rtcVideoFrameHandle* pOutRetVal) noexcept; /** * Creates a new instance of the video frame * from the specified source buffer. (i420) - * + * * @param width - Frame width * @param height - Frame height * @param buffer - Frame buffer @@ -951,79 +1096,64 @@ RTCVideoFrame_Create0( * @return rtcResultU4 - 0 if successful, otherwise an error code. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCVideoFrame_Create1( - int width, int height, - const unsigned char* buffer, int length, - rtcVideoFrameHandle* pOutRetVal -) noexcept; +RTCVideoFrame_Create1(int width, int height, const unsigned char* buffer, + int length, rtcVideoFrameHandle* pOutRetVal) noexcept; /** * Creates a new instance of the video frame * from the specified frame datas. (i420) - * + * * @param frameDatas - Frame datas * @param pOutRetVal - Handle for the created video frame handle. * @return rtcResultU4 - 0 if successful, otherwise an error code. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCVideoFrame_Create2( - const rtcVideoFrameDatas* frameDatas, - rtcVideoFrameHandle* pOutRetVal -) noexcept; +RTCVideoFrame_Create2(const rtcVideoFrameDatas* frameDatas, + rtcVideoFrameHandle* pOutRetVal) noexcept; /** * Creates a copy of the video frame. - * + * * @param videoFrame - Source video frame handle * @param pOutRetVal - Handle for the created video frame handle. * @return rtcResultU4 - 0 if successful, otherwise an error code. */ -LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCVideoFrame_Copy( - rtcVideoFrameHandle videoFrame, - rtcVideoFrameHandle* pOutRetVal -) noexcept; +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCVideoFrame_Copy( + rtcVideoFrameHandle videoFrame, rtcVideoFrameHandle* pOutRetVal) noexcept; /** * Returns the datas of the video frame. - * + * * @param videoFrame - Source video frame handle * @param refFrameDatas - The frame datas. * @return rtcResultU4 - 0 if successful, otherwise an error code. */ -LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCVideoFrame_GetFrameDatas( - rtcVideoFrameHandle videoFrame, - rtcVideoFrameDatas* refFrameDatas -) noexcept; +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCVideoFrame_GetFrameDatas( + rtcVideoFrameHandle videoFrame, rtcVideoFrameDatas* refFrameDatas) noexcept; /** * Returns the rotation of the video frame. (See: rtcVideoRotation) - * + * * @param videoFrame - Source video frame handle * @param pRotation - The frame rotation value. * @return rtcResultU4 - 0 if successful, otherwise an error code. */ -LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCVideoFrame_GetRotation( - rtcVideoFrameHandle videoFrame, - rtcVideoRotation* pOutRetVal -) noexcept; +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCVideoFrame_GetRotation( + rtcVideoFrameHandle videoFrame, rtcVideoRotation* pOutRetVal) noexcept; /** * Returns a timestamp in microseconds. - * + * * @param videoFrame - Source video frame handle * @return rtcTimestamp - Timestamp in microseconds. */ LIB_WEBRTC_API rtcTimestamp LIB_WEBRTC_CALL RTCVideoFrame_GetTimestampInMicroseconds( - rtcVideoFrameHandle videoFrame -) noexcept; + rtcVideoFrameHandle videoFrame) noexcept; /** * Sets the timestamp in microseconds. - * + * * @param videoFrame - Source video frame handle * @param timestampInMicroseconds - Timestamp in microseconds. * @return rtcResultU4 - 0 if successful, otherwise an error code. @@ -1031,12 +1161,11 @@ RTCVideoFrame_GetTimestampInMicroseconds( LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCVideoFrame_SetTimestampInMicroseconds( rtcVideoFrameHandle videoFrame, - rtcTimestamp timestampInMicroseconds -) noexcept; + rtcTimestamp timestampInMicroseconds) noexcept; /** * Converts the video frame to RGB colorspace. - * + * * @param videoFrame - Source video frame handle * @param type - Type of destination video frame buffer. * @param dst_argb - Destination video frame buffer. @@ -1045,36 +1174,29 @@ RTCVideoFrame_SetTimestampInMicroseconds( * @param dest_height - Height of destination video frame buffer. * @return int - Size of destination */ -LIB_WEBRTC_API int LIB_WEBRTC_CALL -RTCVideoFrame_ConvertToARGB( - rtcVideoFrameHandle videoFrame, - rtcVideoFrameType type, - unsigned char* dst_argb, - int dst_stride_argb, - int dest_width, - int dest_height -) noexcept; +LIB_WEBRTC_API int LIB_WEBRTC_CALL RTCVideoFrame_ConvertToARGB( + rtcVideoFrameHandle videoFrame, rtcVideoFrameType type, + unsigned char* dst_argb, int dst_stride_argb, int dest_width, + int dest_height) noexcept; /* - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * RTCVideoRenderer interop methods - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ /** * Creates a new instance of the video renderer. - * + * * @param pOutRetVal - Video renderer handle. * @return rtcResultU4 - 0 if successful, otherwise an error code. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCVideoRenderer_Create( - rtcVideoRendererHandle* pOutRetVal -) noexcept; +RTCVideoRenderer_Create(rtcVideoRendererHandle* pOutRetVal) noexcept; /** * Registers the callback method for the video renderer. - * + * * @param videoRenderer - Video renderer handle. * @param userData - User data handle * @param callback - Callback method for OnFrame @@ -1082,180 +1204,157 @@ RTCVideoRenderer_Create( */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCVideoRenderer_RegisterFrameCallback( - rtcVideoRendererHandle videoRenderer, - rtcObjectHandle userData, - rtcVideoRendererFrameDelegate callback -) noexcept; + rtcVideoRendererHandle videoRenderer, rtcObjectHandle userData, + rtcVideoRendererFrameDelegate callback) noexcept; /** * UnRegisters the callback method for the video renderer. - * + * * @param videoRenderer - Video renderer handle. * @return rtcResultU4 - 0 if successful, otherwise an error code. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCVideoRenderer_UnRegisterFrameCallback( - rtcVideoRendererHandle videoRenderer -) noexcept; + rtcVideoRendererHandle videoRenderer) noexcept; #if defined(DEBUG) || defined(_DEBUG) /** * It is used for testing purposes to trigger * the OnRender callback method. - * + * * @param videoRenderer - Video renderer handle. * @param videoFrame - Video frame handle. * @return rtcResultU4 - 0 if successful, otherwise an error code. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCVideoRenderer_FireOnFrame( - rtcVideoRendererHandle videoRenderer, - rtcVideoFrameHandle videoFrame -) noexcept; -#endif // DEBUG or _DEBUG +RTCVideoRenderer_FireOnFrame(rtcVideoRendererHandle videoRenderer, + rtcVideoFrameHandle videoFrame) noexcept; +#endif // DEBUG or _DEBUG /* - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * RTCVideoTrack interop methods - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ /** * Adds a video renderer to the video track for frame callback operations. - * + * * @param videoTrack - Video track handle. * @param videoRenderer - Video renderer handle. * @return rtcResultU4 - 0 if successful, otherwise an error code. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCVideoTrack_AddRenderer( - rtcVideoTrackHandle videoTrack, - rtcVideoRendererHandle videoRenderer -) noexcept; +RTCVideoTrack_AddRenderer(rtcVideoTrackHandle videoTrack, + rtcVideoRendererHandle videoRenderer) noexcept; /** * Removes the video renderer that is already attached to * the video track for frame callback operations. - * + * * @param videoTrack - Video track handle. * @param videoRenderer - Video renderer handle. * @return rtcResultU4 - 0 if successful, otherwise an error code. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCVideoTrack_RemoveRenderer( - rtcVideoTrackHandle videoTrack, - rtcVideoRendererHandle videoRenderer -) noexcept; +RTCVideoTrack_RemoveRenderer(rtcVideoTrackHandle videoTrack, + rtcVideoRendererHandle videoRenderer) noexcept; #ifdef RTC_DESKTOP_DEVICE /* - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * RTCDesktopMediaList interop methods - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ /** * Registers callback delegates for MediaListObserve. - * + * * @param hMediaList - Desktop media list handle - * @param rtcMediaListObserverCallbacks - Callback delegate structure for MediaListObserve. + * @param rtcMediaListObserverCallbacks - Callback delegate structure for + * MediaListObserve. * @return rtcResultU4 - 0 if successful, otherwise an error code. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCDesktopMediaList_RegisterMediaListObserver( rtcDesktopMediaListHandle hMediaList, - rtcMediaListObserverCallbacks* callbacks -) noexcept; + rtcMediaListObserverCallbacks* callbacks) noexcept; /** * Unregisters callback delegates for MediaListObserve. - * + * * @param hMediaList - Desktop media list handle * @return rtcResultU4 - 0 if successful, otherwise an error code. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCDesktopMediaList_DeRegisterMediaListObserver -( - rtcDesktopMediaListHandle hMediaList -) noexcept; +RTCDesktopMediaList_DeRegisterMediaListObserver( + rtcDesktopMediaListHandle hMediaList) noexcept; /** * Returns the desktop type for the MediaListObserve. - * + * * @param hMediaList - Desktop media list handle * @return rtcDesktopType - 0 if successful, otherwise an -1 */ LIB_WEBRTC_API rtcDesktopType LIB_WEBRTC_CALL -RTCDesktopMediaList_GetType( - rtcDesktopMediaListHandle hMediaList -) noexcept; +RTCDesktopMediaList_GetType(rtcDesktopMediaListHandle hMediaList) noexcept; /** * Updates media sources. - * + * * @param hMediaList - Desktop media list handle * @param force_reload - Force reloads media sources. * @param get_thumbnail - Enables thumbnail get. * @return int - Returns the number of sources. */ -LIB_WEBRTC_API int LIB_WEBRTC_CALL -RTCDesktopMediaList_UpdateSourceList( +LIB_WEBRTC_API int LIB_WEBRTC_CALL RTCDesktopMediaList_UpdateSourceList( rtcDesktopMediaListHandle hMediaList, rtcBool32 force_reload = rtcBool32::kFalse, - rtcBool32 get_thumbnail = rtcBool32::kTrue -) noexcept; + rtcBool32 get_thumbnail = rtcBool32::kTrue) noexcept; /** * Returns the current number of media sources. - * + * * @param hMediaList - Desktop media list handle * @return int - Returns the number of sources. */ -LIB_WEBRTC_API int LIB_WEBRTC_CALL -RTCDesktopMediaList_GetSourceCount( - rtcDesktopMediaListHandle hMediaList -) noexcept; +LIB_WEBRTC_API int LIB_WEBRTC_CALL RTCDesktopMediaList_GetSourceCount( + rtcDesktopMediaListHandle hMediaList) noexcept; /** * Returns the media source whose index is specified. - * + * * @param hMediaList - Desktop media list handle * @param index - Media source index * @param pOutRetVal - Returns the media source handle. * @return rtcResultU4 - 0 if successful, otherwise an error code. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCDesktopMediaList_GetSource( - rtcDesktopMediaListHandle hMediaList, - int index, - rtcDesktopMediaSourceHandle* pOutRetVal -) noexcept; +RTCDesktopMediaList_GetSource(rtcDesktopMediaListHandle hMediaList, int index, + rtcDesktopMediaSourceHandle* pOutRetVal) noexcept; /** * Gets the thumbnail. - * + * * @param hMediaList - Desktop media list handle * @param source - Media source handle * @param notify - Triggers the callback method. * @return rtcBool32 - kTrue if successful, otherwise an kFalse. */ -LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL -RTCDesktopMediaList_GetThumbnail( - rtcDesktopMediaListHandle hMediaList, - rtcDesktopMediaSourceHandle hSource, - rtcBool32 notify = rtcBool32::kFalse -) noexcept; +LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL RTCDesktopMediaList_GetThumbnail( + rtcDesktopMediaListHandle hMediaList, rtcDesktopMediaSourceHandle hSource, + rtcBool32 notify = rtcBool32::kFalse) noexcept; /* - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * MediaSource interop methods - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ /** * Provides id, name and type information about the media source. - * + * * @param mediaSource - Media source handle * @param pOutId - Media source id * @param cchOutId - The size of the id. @@ -1264,51 +1363,42 @@ RTCDesktopMediaList_GetThumbnail( * @param pOutType - The desktop type of media source * @return rtcResultU4 - 0 if successful, otherwise an error code. */ -LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -MediaSource_GetInfo( - rtcDesktopMediaSourceHandle mediaSource, - char* pOutId, int cchOutId, - char* pOutName, int cchOutName, - rtcDesktopType* pOutType -) noexcept; +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL MediaSource_GetInfo( + rtcDesktopMediaSourceHandle mediaSource, char* pOutId, int cchOutId, + char* pOutName, int cchOutName, rtcDesktopType* pOutType) noexcept; /** * Updates the media source thumbnail. - * + * * @param mediaSource - Media source handle * @return rtcBool32 - kTrue if successful, otherwise kFalse */ LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL -MediaSource_UpdateThumbnail( - rtcDesktopMediaSourceHandle mediaSource -) noexcept; +MediaSource_UpdateThumbnail(rtcDesktopMediaSourceHandle mediaSource) noexcept; /** * Returns the thumbnail of the media source, jpeg format. * At the end of the process, the 'refSizeOfBuffer' value * gives the actual size of the buffer area. - * + * * @param mediaSource - Media source handle * @param pBuffer - Address of the buffer area for the thumbnail. * @param refSizeOfBuffer - The size of the thumbnail buffer. * @return rtcResultU4 - 0 if successful, otherwise an error code. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -MediaSource_GetThumbnail( - rtcDesktopMediaSourceHandle mediaSource, - unsigned char* pBuffer, - int* refSizeOfBuffer -) noexcept; +MediaSource_GetThumbnail(rtcDesktopMediaSourceHandle mediaSource, + unsigned char* pBuffer, int* refSizeOfBuffer) noexcept; /* - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * RTCDesktopDevice interop methods - * ---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ /** * Create desktop capturer - * + * * @param desktopDevice - Desktop device handle * @param source - Media source handle * @param pOutRetVal - Returns the created desktop capture handle. @@ -1316,28 +1406,23 @@ MediaSource_GetThumbnail( */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCDesktopDevice_CreateDesktopCapturer( - rtcDesktopDeviceHandle desktopDevice, - rtcDesktopMediaSourceHandle source, - rtcDesktopCapturerHandle* pOutRetVal -) noexcept; + rtcDesktopDeviceHandle desktopDevice, rtcDesktopMediaSourceHandle source, + rtcDesktopCapturerHandle* pOutRetVal) noexcept; /** * Returns the desktop media list. - * + * * @param desktopDevice - Desktop device handle * @param type - Desktop type * @param pOutRetVal - Returns the created desktop media list handle. * @return rtcResultU4 - 0 if successful, otherwise an error code. */ -LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCDesktopDevice_GetDesktopMediaList( - rtcDesktopDeviceHandle desktopDevice, - rtcDesktopType type, - rtcDesktopMediaListHandle* pOutRetVal -) noexcept; +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCDesktopDevice_GetDesktopMediaList( + rtcDesktopDeviceHandle desktopDevice, rtcDesktopType type, + rtcDesktopMediaListHandle* pOutRetVal) noexcept; -#endif // RTC_DESKTOP_DEVICE +#endif // RTC_DESKTOP_DEVICE -} // extern "C" +} // extern "C" #endif // LIB_WEBRTC_INTROP_API_HXX \ No newline at end of file diff --git a/include/rtc_ice_candidate.h b/include/rtc_ice_candidate.h index 82da46edb4..0bbbc9423d 100644 --- a/include/rtc_ice_candidate.h +++ b/include/rtc_ice_candidate.h @@ -2,6 +2,7 @@ #define LIB_WEBRTC_RTC_ICE_CANDIDATE_HXX #include "rtc_types.h" +#include "rtc_sdp_parse_error.h" namespace libwebrtc { @@ -9,7 +10,7 @@ class RTCIceCandidate : public RefCountInterface { public: static LIB_WEBRTC_API scoped_refptr Create( const string sdp, const string sdp_mid, int sdp_mline_index, - SdpParseError* error); + RTCSdpParseError* error); public: virtual const string candidate() const = 0; diff --git a/include/rtc_peerconnection.h b/include/rtc_peerconnection.h index 35ea2ad3ea..39811a9a61 100644 --- a/include/rtc_peerconnection.h +++ b/include/rtc_peerconnection.h @@ -3,6 +3,7 @@ #include "rtc_audio_track.h" #include "rtc_data_channel.h" +#include "rtc_sdp_parse_error.h" #include "rtc_ice_candidate.h" #include "rtc_media_stream.h" #include "rtc_mediaconstraints.h" diff --git a/include/rtc_sdp_parse_error.h b/include/rtc_sdp_parse_error.h new file mode 100644 index 0000000000..8cda63fd6a --- /dev/null +++ b/include/rtc_sdp_parse_error.h @@ -0,0 +1,27 @@ +#ifndef LIB_WEBRTC_RTC_SDP_PARSE_ERROR_HXX +#define LIB_WEBRTC_RTC_SDP_PARSE_ERROR_HXX + +#include "rtc_types.h" + +namespace libwebrtc { + +class RTCSdpParseError : public RefCountInterface { + public: + static LIB_WEBRTC_API scoped_refptr Create(); + + public: + // The sdp line that causes the error. + virtual const string line() const = 0; + virtual void set_line(const string value) = 0; + + // Explains the error. + virtual const string description() const = 0; + virtual void set_description(const string value) = 0; + + protected: + virtual ~RTCSdpParseError() {} +}; + +} // namespace libwebrtc + +#endif // LIB_WEBRTC_RTC_SDP_PARSE_ERROR_HXX diff --git a/include/rtc_session_description.h b/include/rtc_session_description.h index 84aa2abbc9..bd4ad743f4 100644 --- a/include/rtc_session_description.h +++ b/include/rtc_session_description.h @@ -2,6 +2,7 @@ #define LIB_WEBRTC_RTC_SESSION_DESCRIPTION_HXX #include "rtc_types.h" +#include "rtc_sdp_parse_error.h" namespace libwebrtc { @@ -10,7 +11,7 @@ class RTCSessionDescription : public RefCountInterface { enum SdpType { kOffer = 0, kPrAnswer, kAnswer }; static LIB_WEBRTC_API scoped_refptr Create( - const string type, const string sdp, SdpParseError* error); + const string type, const string sdp, RTCSdpParseError* error); public: virtual const string sdp() const = 0; diff --git a/include/rtc_types.h b/include/rtc_types.h index 017386d071..d98a2f4e51 100644 --- a/include/rtc_types.h +++ b/include/rtc_types.h @@ -98,13 +98,13 @@ struct RTCConfiguration { uint32_t local_video_bandwidth = 512; }; -struct SdpParseError { - public: - // The sdp line that causes the error. - string line; - // Explains the error. - string description; -}; +// struct SdpParseError { +// public: +// // The sdp line that causes the error. +// string line; +// // Explains the error. +// string description; +// }; enum DesktopType { kScreen, kWindow }; diff --git a/src/rtc_ice_candidate_impl.cc b/src/rtc_ice_candidate_impl.cc index e52829db47..c8359d9d30 100644 --- a/src/rtc_ice_candidate_impl.cc +++ b/src/rtc_ice_candidate_impl.cc @@ -1,17 +1,20 @@ #include "rtc_ice_candidate_impl.h" +#include "rtc_sdp_parse_error.h" namespace libwebrtc { scoped_refptr RTCIceCandidate::Create(const string sdp, const string sdp_mid, int sdp_mline_index, - SdpParseError* error) { + RTCSdpParseError* error) { webrtc::SdpParseError sdp_error; std::unique_ptr rtc_candidate( webrtc::CreateIceCandidate(to_std_string(sdp_mid), sdp_mline_index, to_std_string(sdp), &sdp_error)); - error->description = sdp_error.description; - error->line = sdp_error.line; + if (error) { + error->set_description(sdp_error.description); + error->set_line(sdp_error.line); + } if (rtc_candidate) { return scoped_refptr( new RefCountedObject(std::move(rtc_candidate))); diff --git a/src/rtc_peerconnection_impl.cc b/src/rtc_peerconnection_impl.cc index 609287bdcf..6ff2241ee9 100644 --- a/src/rtc_peerconnection_impl.cc +++ b/src/rtc_peerconnection_impl.cc @@ -8,6 +8,7 @@ #include "pc/media_session.h" #include "rtc_base/logging.h" #include "rtc_data_channel_impl.h" +#include "rtc_sdp_parse_error_impl.h" #include "rtc_ice_candidate_impl.h" #include "rtc_media_stream_impl.h" #include "rtc_mediaconstraints_impl.h" @@ -336,10 +337,10 @@ void RTCPeerConnectionImpl::OnIceCandidate( std::string cand_sdp; if (observer_ && candidate->ToString(&cand_sdp)) { - SdpParseError error; + scoped_refptr error = RTCSdpParseError::Create(); scoped_refptr cand = RTCIceCandidate::Create(cand_sdp.c_str(), candidate->sdp_mid().c_str(), - candidate->sdp_mline_index(), &error); + candidate->sdp_mline_index(), error); observer_->OnIceCandidate(cand); } diff --git a/src/rtc_sdp_parse_error_impl.cc b/src/rtc_sdp_parse_error_impl.cc new file mode 100644 index 0000000000..d39bf89175 --- /dev/null +++ b/src/rtc_sdp_parse_error_impl.cc @@ -0,0 +1,30 @@ +#include "rtc_sdp_parse_error_impl.h" + +namespace libwebrtc { + +scoped_refptr RTCSdpParseError::Create() { + return scoped_refptr( + new RefCountedObject()); +} + +RTCSdpParseErrorImpl::RTCSdpParseErrorImpl() + : line_(), description_() { +} + +const string RTCSdpParseErrorImpl::line() const { + return line_; +} + +void RTCSdpParseErrorImpl::set_line(const string value) { + line_ = value.std_string(); +} + +const string RTCSdpParseErrorImpl::description() const { + return description_; +} + +void RTCSdpParseErrorImpl::set_description(const string value) { + description_ = value.std_string(); +} + +} // namespace libwebrtc \ No newline at end of file diff --git a/src/rtc_sdp_parse_error_impl.h b/src/rtc_sdp_parse_error_impl.h new file mode 100644 index 0000000000..2b2a4b1d22 --- /dev/null +++ b/src/rtc_sdp_parse_error_impl.h @@ -0,0 +1,29 @@ +#ifndef LIB_WEBRTC_RTC_SDP_PARSE_ERROR_IMPL_HXX +#define LIB_WEBRTC_RTC_SDP_PARSE_ERROR_IMPL_HXX + +#include "rtc_sdp_parse_error.h" +#include "rtc_types.h" + +namespace libwebrtc { + +class RTCSdpParseErrorImpl : public RTCSdpParseError { + public: + RTCSdpParseErrorImpl(); + + virtual const string line() const override; + virtual void set_line(const string value) override; + + virtual const string description() const override; + virtual void set_description(const string value) override; + + protected: + virtual ~RTCSdpParseErrorImpl() {} + + private: + std::string line_; // The sdp line that causes the error. + std::string description_; // Explains the error. +}; + +} // namespace libwebrtc + +#endif // LIB_WEBRTC_RTC_SDP_PARSE_ERROR_IMPL_HXX \ No newline at end of file diff --git a/src/rtc_session_description_impl.cc b/src/rtc_session_description_impl.cc index b2345116b8..5b18ce6390 100644 --- a/src/rtc_session_description_impl.cc +++ b/src/rtc_session_description_impl.cc @@ -1,15 +1,18 @@ #include "rtc_session_description_impl.h" +#include "rtc_sdp_parse_error.h" namespace libwebrtc { scoped_refptr RTCSessionDescription::Create( - const string type, const string sdp, SdpParseError* error) { + const string type, const string sdp, RTCSdpParseError* error) { webrtc::SdpParseError sdp_error; std::unique_ptr rtc_description( webrtc::CreateSessionDescription(to_std_string(type), to_std_string(sdp), &sdp_error)); - error->description = sdp_error.description; - error->line = sdp_error.line; + if (error) { + error->set_description(sdp_error.description); + error->set_line(sdp_error.line); + } if (rtc_description) { return scoped_refptr( new RefCountedObject( From 952e060f233aa4591c760a82f3fcdd593066b6a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Fri, 20 Dec 2024 17:53:14 +0300 Subject: [PATCH 33/69] Restore --- include/interop_api.h | 195 +++++++++++++++++++++--------------------- 1 file changed, 96 insertions(+), 99 deletions(-) diff --git a/include/interop_api.h b/include/interop_api.h index 18a0929c2e..feae0847b6 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -58,158 +58,155 @@ enum class rtcKeyRing : int { kMinSize = 1, kDefaultSize = 16, kMaxSize = 256 }; enum class rtcTrackState : int { kUnknown = -1, kLive = 0, kEnded = 1 }; enum class rtcVideoFrameType : int { - kUnknown = -1, - kARGB = 0, - kBGRA = 1, - kABGR = 2, - kRGBA = 3 + kUnknown = -1, + kARGB = 0, + kBGRA = 1, + kABGR = 2, + kRGBA = 3 }; enum class rtcVideoRotation : int { - kVideoRotation_0 = 0, - kVideoRotation_90 = 90, - kVideoRotation_180 = 180, - kVideoRotation_270 = 270 + kVideoRotation_0 = 0, + kVideoRotation_90 = 90, + kVideoRotation_180 = 180, + kVideoRotation_270 = 270 }; enum class rtcDataChannelState : int { - kConnecting = 0, - kOpen = 1, - kClosing = 2, - kClosed = 3 + kConnecting = 0, + kOpen = 1, + kClosing = 2, + kClosed = 3 }; enum class rtcDataChannelProtocol : int { kSCTP = 0, kQUIC = 1 }; enum class rtcDtlsTransportState : int { - kNew = 0, // Has not started negotiating yet. - kConnecting = 1, // In the process of negotiating a secure connection. - kConnected = 2, // Completed negotiation and verified fingerprints. - kClosed = 3, // Intentionally closed. - kFailed = 4, // Failure due to an error or failing to verify a remote - // fingerprint. - kNumValues = 5 + kNew = 0, // Has not started negotiating yet. + kConnecting = 1, // In the process of negotiating a secure connection. + kConnected = 2, // Completed negotiation and verified fingerprints. + kClosed = 3, // Intentionally closed. + kFailed = 4, // Failure due to an error or failing to verify a remote + // fingerprint. + kNumValues = 5 }; enum class rtcFrameCryptionAlgorithm : int { kAesGcm = 0, kAesCbc = 1 }; enum class rtcFrameCryptionState : int { - kNew = 0, - kOk = 1, - kEncryptionFailed = 2, - kDecryptionFailed = 3, - kMissingKey = 4, - kKeyRatcheted = 5, - kInternalError = 6 + kNew = 0, + kOk = 1, + kEncryptionFailed = 2, + kDecryptionFailed = 3, + kMissingKey = 4, + kKeyRatcheted = 5, + kInternalError = 6 }; enum class rtcSessionDescriptionErrorType : int { - kPeerConnectionInitFailed = 0, - kCreatePeerConnectionFailed = 1, - kSDPParseFailed = 2 + kPeerConnectionInitFailed = 0, + kCreatePeerConnectionFailed = 1, + kSDPParseFailed = 2 }; enum class rtcPeerConnectionState : int { - kNew = 0, - kConnecting = 1, - kConnected = 2, - kDisconnected = 3, - kFailed = 4, - kClosed = 5 + kNew = 0, + kConnecting = 1, + kConnected = 2, + kDisconnected = 3, + kFailed = 4, + kClosed = 5 }; enum class rtcSignalingState : int { - kStable = 0, - kHaveLocalOffer = 1, - kHaveRemoteOffer = 2, - kHaveLocalPrAnswer = 3, - kHaveRemotePrAnswer = 4, - kClosed = 5 + kStable = 0, + kHaveLocalOffer = 1, + kHaveRemoteOffer = 2, + kHaveLocalPrAnswer = 3, + kHaveRemotePrAnswer = 4, + kClosed = 5 }; enum class rtcIceGatheringState : int { - kNew = 0, - kGathering = 1, - kComplete = 2 + kNew = 0, + kGathering = 1, + kComplete = 2 }; enum class rtcIceConnectionState : int { - kNew = 0, - kChecking = 1, - kCompleted = 2, - kConnected = 3, - kFailed = 4, - kDisconnected = 5, - kClosed = 6, - kMax = 7 + kNew = 0, + kChecking = 1, + kCompleted = 2, + kConnected = 3, + kFailed = 4, + kDisconnected = 5, + kClosed = 6, + kMax = 7 }; enum class rtcStatsMemberType : int { - kBool = 0, // bool - kInt32 = 1, // int32_t - kUint32 = 2, // uint32_t - kInt64 = 3, // int64_t - kUint64 = 4, // uint64_t - kDouble = 5, // double - kString = 6, // std::string - - kSequenceBool = 7, // std::vector - kSequenceInt32 = 8, // std::vector - kSequenceUint32 = 9, // std::vector - kSequenceInt64 = 10, // std::vector - kSequenceUint64 = 11, // std::vector - kSequenceDouble = 12, // std::vector - kSequenceString = 13, // std::vector - - kMapStringUint64 = 14, // std::map - kMapStringDouble = 15 // std::map + kBool = 0, // bool + kInt32 = 1, // int32_t + kUint32 = 2, // uint32_t + kInt64 = 3, // int64_t + kUint64 = 4, // uint64_t + kDouble = 5, // double + kString = 6, // std::string + + kSequenceBool = 7, // std::vector + kSequenceInt32 = 8, // std::vector + kSequenceUint32 = 9, // std::vector + kSequenceInt64 = 10, // std::vector + kSequenceUint64 = 11, // std::vector + kSequenceDouble = 12, // std::vector + kSequenceString = 13, // std::vector + + kMapStringUint64 = 14, // std::map + kMapStringDouble = 15 // std::map }; enum class rtcRtpTransceiverDirection : int { - kSendRecv = 0, - kSendOnly = 1, - kRecvOnly = 2, - kInactive = 3, - kStopped = 4 + kSendRecv = 0, + kSendOnly = 1, + kRecvOnly = 2, + kInactive = 3, + kStopped = 4 }; enum class rtcFecMechanism : int { - kRED = 0, - kRED_AND_ULPFEC = 1, - kFLEXFEC = 2 + kRED = 0, + kRED_AND_ULPFEC = 1, + kFLEXFEC = 2 }; enum class rtcRtcpFeedbackType : int { - kCCM = 0, - kLNTF = 1, - kNACK = 2, - kREMB = 3, - kTRANSPORT_CC = 4 + kCCM = 0, + kLNTF = 1, + kNACK = 2, + kREMB = 3, + kTRANSPORT_CC = 4 }; enum class rtcRtcpFeedbackMessageType : int { - kGENERIC_NACK = 0, - kPLI = 1, - kFIR = 2 + kGENERIC_NACK = 0, + kPLI = 1, + kFIR = 2 }; -enum class rtcDtxStatus : int { - kDISABLED = 0, - kENABLED = 1 -}; +enum class rtcDtxStatus : int { kDISABLED = 0, kENABLED = 1 }; enum class rtcDegradationPreference : int { - kDISABLED = 0, - kMAINTAIN_FRAMERATE = 1, - kMAINTAIN_RESOLUTION = 2, - kBALANCED = 3 + kDISABLED = 0, + kMAINTAIN_FRAMERATE = 1, + kMAINTAIN_RESOLUTION = 2, + kBALANCED = 3 }; enum class rtcNetworkPriority : int { - kVeryLow = 0, - kLow = 1, - kMedium = 2, - kHigh = 3 + kVeryLow = 0, + kLow = 1, + kMedium = 2, + kHigh = 3 }; /// 32-bit result enumerator From 6838584a156d247e73bf1bf55b5971046ffd6bc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Sat, 21 Dec 2024 17:35:12 +0300 Subject: [PATCH 34/69] Added data channel interop methods --- BUILD.gn | 1 + include/interop_api.h | 93 +++++++++++++---- src/interop/rtc_data_channel_interop.cc | 130 ++++++++++++++++++++++++ src/rtc_data_channel_impl.cc | 49 +++++++++ src/rtc_data_channel_impl.h | 15 +++ src/rtc_desktop_media_list_impl.cc | 2 +- 6 files changed, 269 insertions(+), 21 deletions(-) create mode 100644 src/interop/rtc_data_channel_interop.cc diff --git a/BUILD.gn b/BUILD.gn index 83f32863b5..aaf12a01ee 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -170,6 +170,7 @@ rtc_shared_library("libwebrtc") { "src/interop/rtc_video_track_interop.cc", "src/interop/rtc_video_frame_interop.cc", "src/interop/rtc_video_renderer_interop.cc", + "src/interop/rtc_data_channel_interop.cc", ] if (libwebrtc_desktop_capture) { diff --git a/include/interop_api.h b/include/interop_api.h index feae0847b6..220c969427 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -53,7 +53,7 @@ using rtcTimestamp = long long; /// 32-bit boolean for interop API. enum class rtcBool32 : int { kTrue = -1, kFalse = 0 }; -enum class rtcKeyRing : int { kMinSize = 1, kDefaultSize = 16, kMaxSize = 256 }; +enum class rtcKeyRingSize : int { kMin = 1, kDefault = 16, kMax = 256 }; enum class rtcTrackState : int { kUnknown = -1, kLive = 0, kEnded = 1 }; @@ -364,7 +364,7 @@ struct rtcKeyProviderOptions { int ratchet_window_size = 0; int failure_tolerance = -1; // The size of the key ring. between 1 and 255. - int key_ring_size = static_cast(rtcKeyRing::kDefaultSize); + rtcKeyRingSize key_ring_size = rtcKeyRingSize::kDefault; rtcBool32 discard_frame_when_cryptor_not_ready = rtcBool32::kFalse; }; // end struct rtcKeyProviderOptions @@ -377,9 +377,6 @@ using rtcRefCountedObjectHandle = rtcObjectHandle; /// Opaque handle to a native RTCPeerConnectionFactory interop object. using rtcPeerConnectionFactoryHandle = rtcRefCountedObjectHandle; -/// Opaque handle to a native RTCPeerConnectionObserver interop object. -using rtcPeerConnectionObserverHandle = rtcObjectHandle; - /// Opaque handle to a native RTCPeerConnection interop object. using rtcPeerConnectionHandle = rtcRefCountedObjectHandle; @@ -413,9 +410,6 @@ using rtcDesktopMediaSourceHandle = rtcRefCountedObjectHandle; /// Opaque handle to a native RTCDesktopMediaList interop object. using rtcDesktopMediaListHandle = rtcRefCountedObjectHandle; -/// Opaque handle to a native MediaListObserver interop object. -using rtcDesktopMediaListObserverHandle = rtcObjectHandle; - /// Opaque handle to a native RTCMediaStream interop object. using rtcMediaStreamHandle = rtcRefCountedObjectHandle; @@ -437,21 +431,12 @@ using rtcVideoRendererHandle = rtcRefCountedObjectHandle; // ??? /// Opaque handle to a native RTCDataChannel interop object. using rtcDataChannelHandle = rtcRefCountedObjectHandle; -/// Opaque handle to a native RTCDataChannelObserver interop object. -using rtcDataChannelObserverHandle = rtcObjectHandle; - /// Opaque handle to a native RTCDtlsTransportInformation interop object. using rtcDtlsTransportInformationHandle = rtcRefCountedObjectHandle; -/// Opaque handle to a native RTCDtlsTransportObserver interop object. -using rtcDtlsTransportObserverHandle = rtcObjectHandle; - /// Opaque handle to a native RTCDtlsTransport interop object. using rtcDtlsTransportHandle = rtcRefCountedObjectHandle; -/// Opaque handle to a native RTCDtmfSenderObserver interop object. -using rtcDtmfSenderObserverHandle = rtcObjectHandle; - /// Opaque handle to a native RTCDtmfSender interop object. using rtcDtmfSenderHandle = rtcRefCountedObjectHandle; @@ -509,9 +494,6 @@ using rtcRtpEncodingParametersHandle = rtcRefCountedObjectHandle; /// Opaque handle to a native RTCRtpParameters interop object. using rtcRtpParametersHandle = rtcRefCountedObjectHandle; -/// Opaque handle to a native RTCRtpReceiverObserver interop object. -using rtcRtpReceiverObserverHandle = rtcObjectHandle; - /// Opaque handle to a native RTCRtpReceiver interop object. using rtcRtpReceiverHandle = rtcRefCountedObjectHandle; @@ -560,6 +542,28 @@ struct rtcMediaListObserverCallbacks { using rtcVideoRendererFrameDelegate = void(LIB_WEBRTC_CALL*)( rtcObjectHandle user_data, rtcVideoFrameHandle frame); +/** + * Callback OnStateChange delegate for RTCDataChannelObserver. + */ +using rtcDataChannelObserverStateChangeDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, rtcDataChannelState state); + +/** + * Callback OnMessage delegate for RTCDataChannelObserver. + */ +using rtcDataChannelObserverMessageDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, const char* buffer, int length, rtcBool32 binary); + +/** + * Callback delegate structure for RTCDataChannelObserver. + */ +struct rtcDataChannelObserverCallbacks { + rtcDataChannelObserverStateChangeDelegate StateChange{}; + rtcObjectHandle user_data_state_change{}; + rtcDataChannelObserverMessageDelegate Message{}; + rtcObjectHandle user_data_message{}; +}; + /* * ---------------------------------------------------------------------- * LibWebRTC interop methods @@ -1420,6 +1424,55 @@ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCDesktopDevice_GetDesktopMediaList( #endif // RTC_DESKTOP_DEVICE +/* + * ---------------------------------------------------------------------- + * RTCDataChannel interop methods + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDataChannel_Send( + rtcDataChannelHandle dataChannel, + const unsigned char* data, + int data_size, + rtcBool32 binary = rtcBool32::kFalse +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDataChannel_Close( + rtcDataChannelHandle dataChannel +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDataChannel_RegisterObserver( + rtcDataChannelHandle dataChannel, + rtcDataChannelObserverCallbacks* callbacks +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDataChannel_UnregisterObserver( + rtcDataChannelHandle dataChannel +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDataChannel_GetLabel( + rtcDataChannelHandle dataChannel, + char* label, + int label_size +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDataChannel_GetId( + rtcDataChannelHandle dataChannel, + int* id +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDataChannel_GetState( + rtcDataChannelHandle dataChannel, + rtcDataChannelState* state +) noexcept; + } // extern "C" #endif // LIB_WEBRTC_INTROP_API_HXX \ No newline at end of file diff --git a/src/interop/rtc_data_channel_interop.cc b/src/interop/rtc_data_channel_interop.cc new file mode 100644 index 0000000000..f8d83cd9c2 --- /dev/null +++ b/src/interop/rtc_data_channel_interop.cc @@ -0,0 +1,130 @@ +#include "rtc_data_channel.h" +#include "interop_api.h" +#include "src/rtc_data_channel_impl.h" + +using namespace libwebrtc; + +rtcResultU4 LIB_WEBRTC_CALL +RTCDataChannel_Send( + rtcDataChannelHandle dataChannel, + const unsigned char* data, + int data_size, + rtcBool32 binary /*= rtcBool32::kFalse*/ +) noexcept +{ + CHECK_NATIVE_HANDLE(dataChannel); + + scoped_refptr pDataChannel = static_cast(dataChannel); + pDataChannel->Send( + static_cast(data), + data_size, + binary != rtcBool32::kFalse + ); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDataChannel_Close( + rtcDataChannelHandle dataChannel +) noexcept +{ + CHECK_NATIVE_HANDLE(dataChannel); + + scoped_refptr pDataChannel = static_cast(dataChannel); + RTCDataChannelObserverImpl* pObserverImpl = static_cast(pDataChannel->GetObserver()); + pDataChannel->Close(); + if (pObserverImpl) { + delete pObserverImpl; + } + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDataChannel_RegisterObserver( + rtcDataChannelHandle dataChannel, + rtcDataChannelObserverCallbacks* callbacks +) noexcept +{ + CHECK_NATIVE_HANDLE(dataChannel); + CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); + + RTCDataChannelObserver* pObserver = static_cast(new RTCDataChannelObserverImpl(callbacks)); + scoped_refptr pDataChannel = static_cast(dataChannel); + pDataChannel->RegisterObserver(pObserver); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDataChannel_UnregisterObserver( + rtcDataChannelHandle dataChannel +) noexcept +{ + CHECK_NATIVE_HANDLE(dataChannel); + + scoped_refptr pDataChannel = static_cast(dataChannel); + RTCDataChannelObserverImpl* pObserverImpl = static_cast(pDataChannel->GetObserver()); + pDataChannel->UnregisterObserver(); + if (pObserverImpl) { + delete pObserverImpl; + } + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDataChannel_GetLabel( + rtcDataChannelHandle dataChannel, + char* label, + int label_size +) noexcept +{ + CHECK_NATIVE_HANDLE(dataChannel); + CHECK_POINTER(label); + if (label_size < 1) { + return rtcResultU4::kInvalidParameter; + } + ZERO_MEMORY(label, label_size); + + rtcResultU4 result = rtcResultU4::kSuccess; + scoped_refptr pDataChannel = static_cast(dataChannel); + string sLabel = pDataChannel->label(); + if (sLabel.size() > 0) { + size_t dstSize = static_cast(label_size); + size_t len = std::min(dstSize, sLabel.size()); + if (sLabel.size() > len) { + result = rtcResultU4::kBufferTooSmall; + } + strncpy(label, sLabel.c_string(), len); + } + + return result; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDataChannel_GetId( + rtcDataChannelHandle dataChannel, + int* id +) noexcept +{ + CHECK_NATIVE_HANDLE(dataChannel); + CHECK_POINTER(id); + RESET_OUT_POINTER_EX(id, 0); + + scoped_refptr pDataChannel = static_cast(dataChannel); + *id = pDataChannel->id(); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDataChannel_GetState( + rtcDataChannelHandle dataChannel, + rtcDataChannelState* state +) noexcept +{ + CHECK_NATIVE_HANDLE(dataChannel); + CHECK_POINTER(state); + RESET_OUT_POINTER_EX(state, static_cast(-1)); + + scoped_refptr pDataChannel = static_cast(dataChannel); + *state = static_cast(pDataChannel->state()); + return rtcResultU4::kSuccess; +} \ No newline at end of file diff --git a/src/rtc_data_channel_impl.cc b/src/rtc_data_channel_impl.cc index 1d2bedfd5b..4a71277d07 100644 --- a/src/rtc_data_channel_impl.cc +++ b/src/rtc_data_channel_impl.cc @@ -1,7 +1,56 @@ #include "rtc_data_channel_impl.h" +#include "interop_api.h" namespace libwebrtc { +/** + * class RTCDataChannelObserverImpl + */ + +RTCDataChannelObserverImpl::RTCDataChannelObserverImpl(void* callbacks /* rtcDataChannelObserverCallbacks* */) + : callbacks_(nullptr) +{ + if (callbacks) { + size_t nSize = sizeof(rtcDataChannelObserverCallbacks); + callbacks_ = malloc(nSize); + memcpy(callbacks_, (const void*)callbacks, nSize); + } +} + +RTCDataChannelObserverImpl::~RTCDataChannelObserverImpl() +{ + if (callbacks_) { + free(callbacks_); + } + callbacks_ = nullptr; +} + +void RTCDataChannelObserverImpl::OnStateChange(RTCDataChannelState state) +{ + if (callbacks_) { + rtcDataChannelObserverCallbacks* pCallbacks = static_cast(callbacks_); + pCallbacks->StateChange( + pCallbacks->user_data_state_change, + static_cast(state)); + } +} + +void RTCDataChannelObserverImpl::OnMessage(const char* buffer, int length, bool binary) +{ + if (callbacks_) { + rtcDataChannelObserverCallbacks* pCallbacks = static_cast(callbacks_); + pCallbacks->Message( + pCallbacks->user_data_message, + buffer, + length, + binary ? rtcBool32::kTrue : rtcBool32::kFalse); + } +} + +/** + * class RTCDataChannelImpl + */ + RTCDataChannelImpl::RTCDataChannelImpl( rtc::scoped_refptr rtc_data_channel) : rtc_data_channel_(rtc_data_channel), crit_sect_(new webrtc::Mutex()) { diff --git a/src/rtc_data_channel_impl.h b/src/rtc_data_channel_impl.h index 7dda67d90f..00a59d7ff2 100644 --- a/src/rtc_data_channel_impl.h +++ b/src/rtc_data_channel_impl.h @@ -8,6 +8,19 @@ namespace libwebrtc { +class RTCDataChannelObserverImpl : public RTCDataChannelObserver +{ + public: + RTCDataChannelObserverImpl(void* callbacks /* rtcDataChannelObserverCallbacks* */); + ~RTCDataChannelObserverImpl(); + + void OnStateChange(RTCDataChannelState state) override; + void OnMessage(const char* buffer, int length, bool binary) override; + + private: + void* callbacks_ /* rtcDataChannelObserverCallbacks* */; +}; + class RTCDataChannelImpl : public RTCDataChannel, public webrtc::DataChannelObserver { public: @@ -33,6 +46,8 @@ class RTCDataChannelImpl : public RTCDataChannel, return rtc_data_channel_; } + RTCDataChannelObserver* GetObserver() { return observer_; } + protected: virtual ~RTCDataChannelImpl(); diff --git a/src/rtc_desktop_media_list_impl.cc b/src/rtc_desktop_media_list_impl.cc index efe8c0c99e..b8d96637eb 100644 --- a/src/rtc_desktop_media_list_impl.cc +++ b/src/rtc_desktop_media_list_impl.cc @@ -256,7 +256,7 @@ void MediaSourceImpl::SaveCaptureResult( */ MediaListObserverImpl::MediaListObserverImpl(void* callbacks /* rtcMediaListObserverCallbacks* */) - : callbacks_(callbacks) + : callbacks_(nullptr) { if (callbacks) { size_t nSize = sizeof(rtcMediaListObserverCallbacks); From f04f0ed893031945f19d7f91bcc98004021a5034 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Sun, 22 Dec 2024 17:03:44 +0300 Subject: [PATCH 35/69] Added sdp_parse_error_interop methods --- BUILD.gn | 1 + include/interop_api.h | 43 +++++++ src/interop/libwebrtc_interop.cc | 10 +- src/interop/rtc_audio_device_interop.cc | 2 + src/interop/rtc_data_channel_interop.cc | 7 +- src/interop/rtc_desktop_media_list_interop.cc | 9 +- src/interop/rtc_media_track_interop.cc | 7 +- src/interop/rtc_sdp_parse_error_interop.cc | 105 ++++++++++++++++++ 8 files changed, 174 insertions(+), 10 deletions(-) create mode 100644 src/interop/rtc_sdp_parse_error_interop.cc diff --git a/BUILD.gn b/BUILD.gn index aaf12a01ee..8927ccd8f0 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -161,6 +161,7 @@ rtc_shared_library("libwebrtc") { "include/interop_api.h", "src/interop/ref_counted_object_interop.cc", "src/interop/libwebrtc_interop.cc", + "src/interop/rtc_sdp_parse_error_interop.cc", "src/interop/rtc_mediaconstraints_interop.cc", "src/interop/rtc_peerconnection_factory_interop.cc", "src/interop/rtc_media_track_interop.cc", diff --git a/include/interop_api.h b/include/interop_api.h index 220c969427..fd9b93f6ff 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -1473,6 +1473,49 @@ RTCDataChannel_GetState( rtcDataChannelState* state ) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCSdpParseError interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Creates a new instance of the RTCSdpParseError. + * + * @param pOutRetVal - Handle of RTCSdpParseError + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCSdpParseError_Create( + rtcSdpParseErrorHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCSdpParseError_GetLine( + rtcSdpParseErrorHandle sdpParseError, + char* value, + int sz_value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCSdpParseError_SetLine( + rtcSdpParseErrorHandle sdpParseError, + const char* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCSdpParseError_GetDescription( + rtcSdpParseErrorHandle sdpParseError, + char* value, + int sz_value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCSdpParseError_SetDescription( + rtcSdpParseErrorHandle sdpParseError, + const char* value +) noexcept; + } // extern "C" #endif // LIB_WEBRTC_INTROP_API_HXX \ No newline at end of file diff --git a/src/interop/libwebrtc_interop.cc b/src/interop/libwebrtc_interop.cc index 85906e6c67..f0c9d18fa0 100644 --- a/src/interop/libwebrtc_interop.cc +++ b/src/interop/libwebrtc_interop.cc @@ -33,7 +33,7 @@ LibWebRTC_GetErrorMessage( if (cchBuffer == 0) { return rtcResultU4::kBufferTooSmall; } - memset(pBuffer, 0x0, cchBuffer); + ZERO_MEMORY(pBuffer, cchBuffer); char szBuffer[256] = {0}; const char* message = ""; @@ -97,10 +97,12 @@ LibWebRTC_GetErrorMessage( } unsigned int cchMessage = (unsigned int)strlen(message); - unsigned int cchLen = std::min(cchMessage, cchBuffer); - strncpy(pBuffer, (const char*)message, (size_t)cchLen); + unsigned int cchLen = std::min(cchMessage, cchBuffer - 1); + if (cchLen > 0) { + strncpy(pBuffer, message, (size_t)cchLen); + } - return cchMessage > cchBuffer + return cchMessage > cchLen ? rtcResultU4::kBufferTooSmall : rtcResultU4::kSuccess; } diff --git a/src/interop/rtc_audio_device_interop.cc b/src/interop/rtc_audio_device_interop.cc index dccc4ebb3e..2b5c1bffd5 100644 --- a/src/interop/rtc_audio_device_interop.cc +++ b/src/interop/rtc_audio_device_interop.cc @@ -99,6 +99,8 @@ RTCAudioDevice_RecordingDeviceName( } ZERO_MEMORY(pOutName, cchOutName); ZERO_MEMORY(pOutGuid, cchOutGuid); + cchOutName--; + cchOutGuid--; char szName[RTCAudioDevice::kAdmMaxDeviceNameSize] = {0}; char szGuid[RTCAudioDevice::kAdmMaxGuidSize] = {0}; diff --git a/src/interop/rtc_data_channel_interop.cc b/src/interop/rtc_data_channel_interop.cc index f8d83cd9c2..ad9cd3b251 100644 --- a/src/interop/rtc_data_channel_interop.cc +++ b/src/interop/rtc_data_channel_interop.cc @@ -88,12 +88,15 @@ RTCDataChannel_GetLabel( scoped_refptr pDataChannel = static_cast(dataChannel); string sLabel = pDataChannel->label(); if (sLabel.size() > 0) { - size_t dstSize = static_cast(label_size); + size_t dstSize = static_cast(label_size - 1); size_t len = std::min(dstSize, sLabel.size()); if (sLabel.size() > len) { result = rtcResultU4::kBufferTooSmall; } - strncpy(label, sLabel.c_string(), len); + if (len > 0) { + strncpy(label, sLabel.c_string(), len); + label[len] = '\0'; + } } return result; diff --git a/src/interop/rtc_desktop_media_list_interop.cc b/src/interop/rtc_desktop_media_list_interop.cc index 4eefce08e5..1cfe339218 100644 --- a/src/interop/rtc_desktop_media_list_interop.cc +++ b/src/interop/rtc_desktop_media_list_interop.cc @@ -131,9 +131,12 @@ MediaSource_GetInfo( ) noexcept { CHECK_NATIVE_HANDLE(mediaSource); - RESET_OUT_POINTER_EX(pOutId, '\0'); - RESET_OUT_POINTER_EX(pOutName, '\0'); + ZERO_MEMORY(pOutId, cchOutId); + ZERO_MEMORY(pOutName, cchOutName); RESET_OUT_POINTER_EX(pOutType, static_cast(-1)); + + cchOutId--; + cchOutName--; rtcResultU4 result = rtcResultU4::kSuccess; size_t cchLen; @@ -148,6 +151,7 @@ MediaSource_GetInfo( } cchLen = std::min(szTmp.size(), (size_t)cchOutId); strncpy(pOutId, szTmp.c_string(), cchLen); + pOutId[cchLen] = '\0'; } if (pOutName && cchOutName > 0) { @@ -158,6 +162,7 @@ MediaSource_GetInfo( } cchLen = std::min(szTmp.size(), (size_t)cchOutName); strncpy(pOutName, szTmp.c_string(), cchLen); + pOutName[cchLen] = '\0'; } if (pOutType) { diff --git a/src/interop/rtc_media_track_interop.cc b/src/interop/rtc_media_track_interop.cc index 073853dc65..64cdaa1c93 100644 --- a/src/interop/rtc_media_track_interop.cc +++ b/src/interop/rtc_media_track_interop.cc @@ -21,10 +21,11 @@ RTCMediaTrack_GetKind( ) noexcept { CHECK_NATIVE_HANDLE(mediaTrack); - if (cchOutKind <= 0) { + if (cchOutKind < 1) { return rtcResultU4::kBufferTooSmall; } ZERO_MEMORY(pOutKind, cchOutKind); + cchOutKind--; rtcResultU4 result = rtcResultU4::kSuccess; scoped_refptr pMediaTrack = static_cast(mediaTrack); @@ -38,6 +39,7 @@ RTCMediaTrack_GetKind( size_t len = std::min(dstSize, srcSize); if (len > 0) { strncpy(pOutKind, kind.c_string(), len); + pOutKind[len] = '\0'; } return result; @@ -51,10 +53,11 @@ RTCMediaTrack_GetId( ) noexcept { CHECK_NATIVE_HANDLE(mediaTrack); - if (cchOutId <= 0) { + if (cchOutId < 1) { return rtcResultU4::kBufferTooSmall; } ZERO_MEMORY(pOutId, cchOutId); + cchOutId--; rtcResultU4 result = rtcResultU4::kSuccess; scoped_refptr pMediaTrack = static_cast(mediaTrack); diff --git a/src/interop/rtc_sdp_parse_error_interop.cc b/src/interop/rtc_sdp_parse_error_interop.cc new file mode 100644 index 0000000000..ef43149f22 --- /dev/null +++ b/src/interop/rtc_sdp_parse_error_interop.cc @@ -0,0 +1,105 @@ +#include "rtc_sdp_parse_error.h" +#include "src/rtc_sdp_parse_error_impl.h" +#include "interop_api.h" + +using namespace libwebrtc; + +rtcResultU4 LIB_WEBRTC_CALL +RTCSdpParseError_Create( + rtcSdpParseErrorHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + + scoped_refptr pSdpParseError = RTCSdpParseError::Create(); + *pOutRetVal = static_cast(pSdpParseError.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCSdpParseError_GetLine( + rtcSdpParseErrorHandle sdpParseError, + char* value, + int sz_value +) noexcept +{ + CHECK_NATIVE_HANDLE(sdpParseError); + CHECK_POINTER_EX(value, rtcResultU4::kInvalidParameter); + if (sz_value < 1) { + return rtcResultU4::kBufferTooSmall; + } + ZERO_MEMORY(value, sz_value); + + rtcResultU4 result = rtcResultU4::kSuccess; + scoped_refptr pSdpParseError = static_cast(sdpParseError); + string sValue = pSdpParseError->line(); + if (sValue.size() > 0) { + size_t dstLen = static_cast(sz_value) - 1; + size_t len = std::min(dstLen, sValue.size()); + if (sValue.size() > len) { + result = rtcResultU4::kBufferTooSmall; + } + if (len > 0) { + strncpy(value, sValue.c_string(), len); + value[len] = '\0'; + } + } + return result; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCSdpParseError_SetLine( + rtcSdpParseErrorHandle sdpParseError, + const char* value +) noexcept +{ + CHECK_NATIVE_HANDLE(sdpParseError); + + scoped_refptr pSdpParseError = static_cast(sdpParseError); + pSdpParseError->set_line(string(value)); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCSdpParseError_GetDescription( + rtcSdpParseErrorHandle sdpParseError, + char* value, + int sz_value +) noexcept +{ + CHECK_NATIVE_HANDLE(sdpParseError); + CHECK_POINTER_EX(value, rtcResultU4::kInvalidParameter); + if (sz_value < 1) { + return rtcResultU4::kBufferTooSmall; + } + ZERO_MEMORY(value, sz_value); + + rtcResultU4 result = rtcResultU4::kSuccess; + scoped_refptr pSdpParseError = static_cast(sdpParseError); + string sValue = pSdpParseError->description(); + if (sValue.size() > 0) { + size_t dstLen = static_cast(sz_value) - 1; + size_t len = std::min(dstLen, sValue.size()); + if (sValue.size() > len) { + result = rtcResultU4::kBufferTooSmall; + } + if (len > 0) { + strncpy(value, sValue.c_string(), len); + value[len] = '\0'; + } + } + return result; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCSdpParseError_SetDescription( + rtcSdpParseErrorHandle sdpParseError, + const char* value +) noexcept +{ + CHECK_NATIVE_HANDLE(sdpParseError); + + scoped_refptr pSdpParseError = static_cast(sdpParseError); + pSdpParseError->set_description(string(value)); + return rtcResultU4::kSuccess; +} From 836d61af3c8565a03c02cd7d6ac73ae570504444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Sun, 22 Dec 2024 19:08:58 +0300 Subject: [PATCH 36/69] Added rtc_ice_candidate_interop.cc --- BUILD.gn | 1 + include/interop_api.h | 49 ++++++++++- src/interop/rtc_ice_candidate_interop.cc | 105 +++++++++++++++++++++++ 3 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 src/interop/rtc_ice_candidate_interop.cc diff --git a/BUILD.gn b/BUILD.gn index 8927ccd8f0..b02aaf70a0 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -172,6 +172,7 @@ rtc_shared_library("libwebrtc") { "src/interop/rtc_video_frame_interop.cc", "src/interop/rtc_video_renderer_interop.cc", "src/interop/rtc_data_channel_interop.cc", + "src/interop/rtc_ice_candidate_interop.cc", ] if (libwebrtc_desktop_capture) { diff --git a/include/interop_api.h b/include/interop_api.h index fd9b93f6ff..c90e1cf982 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -30,8 +30,8 @@ #define CHECK_NATIVE_HANDLE(h) \ CHECK_POINTER_EX(h, rtcResultU4::kInvalidNativeHandle) #define ZERO_MEMORY(p, sz) \ - if ((sz) > 0) { \ - memset((void*)(p), 0, (size_t)(sz)); \ + if (static_cast(sz) > 0) { \ + memset((void*)(p), 0, static_cast(sz)); \ } extern "C" { @@ -1516,6 +1516,51 @@ RTCSdpParseError_SetDescription( const char* value ) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCIceCandidate interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Creates a new instance of the RTCIceCandidate. + * + * @param sdp - sdp string + * @param sdp_mid - sdp media id + * @param sdp_mline_index - sdp media line index + * @param pOutSdpParseError - sdp parse error handle (optional) + * @param pOutRetVal - Handle of RTCIceCandidate + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCIceCandidate_Create( + const char* sdp, + const char* sdp_mid, + int sdp_mline_index, + rtcSdpParseErrorHandle* pOutSdpParseError, + rtcIceCandidateHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCIceCandidate_GetCandidate( + rtcIceCandidateHandle iceCandidate, + char* value, + int sz_value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCIceCandidate_GetSdpMid( + rtcIceCandidateHandle iceCandidate, + char* value, + int sz_value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCIceCandidate_GetSdpMlineIndex( + rtcIceCandidateHandle iceCandidate, + int* pOutRetVal +) noexcept; + } // extern "C" #endif // LIB_WEBRTC_INTROP_API_HXX \ No newline at end of file diff --git a/src/interop/rtc_ice_candidate_interop.cc b/src/interop/rtc_ice_candidate_interop.cc new file mode 100644 index 0000000000..fbd9205d15 --- /dev/null +++ b/src/interop/rtc_ice_candidate_interop.cc @@ -0,0 +1,105 @@ +#include "rtc_ice_candidate.h" +#include "rtc_sdp_parse_error.h" +#include "interop_api.h" + +using namespace libwebrtc; + +rtcResultU4 LIB_WEBRTC_CALL +RTCIceCandidate_Create( + const char* sdp, + const char* sdp_mid, + int sdp_mline_index, + rtcSdpParseErrorHandle* pOutSdpParseError, + rtcIceCandidateHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + RESET_OUT_POINTER(pOutSdpParseError); + + scoped_refptr pSdpParseError = RTCSdpParseError::Create(); + scoped_refptr pIceCandidate = RTCIceCandidate::Create( + string(sdp), + string(sdp_mid), + sdp_mline_index, + pSdpParseError.get() + ); + + if (pOutSdpParseError && (pIceCandidate == nullptr)) { + *pOutSdpParseError = static_cast(pSdpParseError.release()); + } + *pOutRetVal = static_cast(pIceCandidate.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCIceCandidate_GetCandidate( + rtcIceCandidateHandle iceCandidate, + char* value, + int sz_value +) noexcept +{ + CHECK_NATIVE_HANDLE(iceCandidate); + ZERO_MEMORY(value, sz_value); + if (sz_value < 1) { + return rtcResultU4::kBufferTooSmall; + } + sz_value--; + + rtcResultU4 result = rtcResultU4::kSuccess; + scoped_refptr pIceCandidate = static_cast(iceCandidate); + size_t dstLen = static_cast(sz_value); + string src_value = pIceCandidate->candidate(); + size_t len = std::min(dstLen, src_value.size()); + if (src_value.size() > len) { + result = rtcResultU4::kBufferTooSmall; + } + if (len > 0) { + strncpy(value, src_value.c_string(), len); + value[len] = '\0'; + } + return result; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCIceCandidate_GetSdpMid( + rtcIceCandidateHandle iceCandidate, + char* value, + int sz_value +) noexcept +{ + CHECK_NATIVE_HANDLE(iceCandidate); + ZERO_MEMORY(value, sz_value); + if (sz_value < 1) { + return rtcResultU4::kBufferTooSmall; + } + sz_value--; + + rtcResultU4 result = rtcResultU4::kSuccess; + scoped_refptr pIceCandidate = static_cast(iceCandidate); + size_t dstLen = static_cast(sz_value); + string src_value = pIceCandidate->sdp_mid(); + size_t len = std::min(dstLen, src_value.size()); + if (src_value.size() > len) { + result = rtcResultU4::kBufferTooSmall; + } + if (len > 0) { + strncpy(value, src_value.c_string(), len); + value[len] = '\0'; + } + return result; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCIceCandidate_GetSdpMlineIndex( + rtcIceCandidateHandle iceCandidate, + int* pOutRetVal +) noexcept +{ + CHECK_NATIVE_HANDLE(iceCandidate); + CHECK_POINTER(pOutRetVal); + *pOutRetVal = -1; + + scoped_refptr pIceCandidate = static_cast(iceCandidate); + *pOutRetVal = pIceCandidate->sdp_mline_index(); + return rtcResultU4::kSuccess; +} \ No newline at end of file From 6f18ac9c5a76a306ddd60c815b7c8c64ca700601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Tue, 24 Dec 2024 17:29:29 +0300 Subject: [PATCH 37/69] Added rtc_media_stream_interop.cc --- BUILD.gn | 1 + include/interop_api.h | 170 +++++++++++++++++ src/interop/rtc_media_stream_interop.cc | 234 ++++++++++++++++++++++++ 3 files changed, 405 insertions(+) create mode 100644 src/interop/rtc_media_stream_interop.cc diff --git a/BUILD.gn b/BUILD.gn index b02aaf70a0..522d2b2b37 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -173,6 +173,7 @@ rtc_shared_library("libwebrtc") { "src/interop/rtc_video_renderer_interop.cc", "src/interop/rtc_data_channel_interop.cc", "src/interop/rtc_ice_candidate_interop.cc", + "src/interop/rtc_media_stream_interop.cc", ] if (libwebrtc_desktop_capture) { diff --git a/include/interop_api.h b/include/interop_api.h index c90e1cf982..937e8d0be4 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -1561,6 +1561,176 @@ RTCIceCandidate_GetSdpMlineIndex( int* pOutRetVal ) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCMediaStream interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Adds an audio track to the media stream. + * + * @param mediaStream - Media stream handle + * @param audioTrack - Audio track handle + * @return rtcBool32 - kTrue if successful, otherwise kFalse. + */ +LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL +RTCMediaStream_AddAudioTrack( + rtcMediaStreamHandle mediaStream, + rtcAudioTrackHandle audioTrack +) noexcept; + +/** + * Adds a video track to the media stream. + * + * @param mediaStream - Media stream handle + * @param videoTrack - Video track handle + * @return rtcBool32 - kTrue if successful, otherwise kFalse. + */ +LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL +RTCMediaStream_AddVideoTrack( + rtcMediaStreamHandle mediaStream, + rtcVideoTrackHandle videoTrack +) noexcept; + +/** + * Removes an audio track from the media stream. + * + * @param mediaStream - Media stream handle + * @param audioTrack - Audio track handle + * @return rtcBool32 - kTrue if successful, otherwise kFalse. + */ +LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL +RTCMediaStream_RemoveAudioTrack( + rtcMediaStreamHandle mediaStream, + rtcAudioTrackHandle audioTrack +) noexcept; + +/** + * Removes a video track from the media stream. + * + * @param mediaStream - Media stream handle + * @param videoTrack - Video track handle + * @return rtcBool32 - kTrue if successful, otherwise kFalse. + */ +LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL +RTCMediaStream_RemoveVideoTrack( + rtcMediaStreamHandle mediaStream, + rtcVideoTrackHandle videoTrack +) noexcept; + +/** + * Returns the number of audio tracks in the media stream. + * + * @param mediaStream - Media stream handle + * @return int - Number of audio tracks (if successful), otherwise 0. + */ +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RTCMediaStream_NumberOfAudioTracks( + rtcMediaStreamHandle mediaStream +) noexcept; + +/** + * Returns the number of video tracks in the media stream. + * + * @param mediaStream - Media stream handle + * @return int - Number of video tracks (if successful), otherwise 0. + */ +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RTCMediaStream_NumberOfVideoTracks( + rtcMediaStreamHandle mediaStream +) noexcept; + +/** + * Returns the audio track with the specified index. + * + * @param mediaStream - Media stream handle + * @param index - 0-based index value. + * @param pOutRetVal - The audio track handle value to return. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCMediaStream_GetAudioTrack ( + rtcMediaStreamHandle mediaStream, + int index, + rtcAudioTrackHandle* pOutRetVal +) noexcept; + +/** + * Returns the video track with the specified index. + * + * @param mediaStream - Media stream handle + * @param index - 0-based index value. + * @param pOutRetVal - The video track handle value to return. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCMediaStream_GetVideoTrack ( + rtcMediaStreamHandle mediaStream, + int index, + rtcVideoTrackHandle* pOutRetVal +) noexcept; + +/** + * Returns the audio track with the specified id. + * + * @param mediaStream - Media stream handle + * @param track_id - Track identifier + * @param pOutRetVal - The audio track handle value to return. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCMediaStream_FindAudioTrack ( + rtcMediaStreamHandle mediaStream, + const char* track_id, + rtcAudioTrackHandle* pOutRetVal +) noexcept; + +/** + * Returns the video track with the specified id. + * + * @param mediaStream - Media stream handle + * @param track_id - Track identifier + * @param pOutRetVal - The video track handle value to return. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCMediaStream_FindVideoTrack ( + rtcMediaStreamHandle mediaStream, + const char* track_id, + rtcVideoTrackHandle* pOutRetVal +) noexcept; + +/** + * Returns the label value for the media stream. + * + * @param mediaStream - Media stream handle + * @param value - Value to be returned + * @param sz_value - Size of value + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCMediaStream_GetLabel ( + rtcMediaStreamHandle mediaStream, + char* value, + int sz_value +) noexcept; + +/** + * Returns the id value for the media stream. + * + * @param mediaStream - Media stream handle + * @param value - Value to be returned + * @param sz_value - Size of value + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCMediaStream_GetId ( + rtcMediaStreamHandle mediaStream, + char* value, + int sz_value +) noexcept; + } // extern "C" #endif // LIB_WEBRTC_INTROP_API_HXX \ No newline at end of file diff --git a/src/interop/rtc_media_stream_interop.cc b/src/interop/rtc_media_stream_interop.cc new file mode 100644 index 0000000000..a8c85f0bc7 --- /dev/null +++ b/src/interop/rtc_media_stream_interop.cc @@ -0,0 +1,234 @@ +#include "rtc_media_stream.h" +#include "interop_api.h" + +using namespace libwebrtc; + +rtcBool32 LIB_WEBRTC_CALL +RTCMediaStream_AddAudioTrack( + rtcMediaStreamHandle mediaStream, + rtcAudioTrackHandle audioTrack +) noexcept +{ + CHECK_POINTER_EX(mediaStream, rtcBool32::kFalse); + CHECK_POINTER_EX(audioTrack, rtcBool32::kFalse); + + scoped_refptr pMediaStream = static_cast(mediaStream); + scoped_refptr pAudioTrack = static_cast(audioTrack); + return pMediaStream->AddTrack(pAudioTrack) + ? rtcBool32::kTrue + : rtcBool32::kFalse; +} + +rtcBool32 LIB_WEBRTC_CALL +RTCMediaStream_AddVideoTrack( + rtcMediaStreamHandle mediaStream, + rtcVideoTrackHandle videoTrack +) noexcept +{ + CHECK_POINTER_EX(mediaStream, rtcBool32::kFalse); + CHECK_POINTER_EX(videoTrack, rtcBool32::kFalse); + + scoped_refptr pMediaStream = static_cast(mediaStream); + scoped_refptr pVideoTrack = static_cast(videoTrack); + return pMediaStream->AddTrack(pVideoTrack) + ? rtcBool32::kTrue + : rtcBool32::kFalse; +} + +rtcBool32 LIB_WEBRTC_CALL +RTCMediaStream_RemoveAudioTrack( + rtcMediaStreamHandle mediaStream, + rtcAudioTrackHandle audioTrack +) noexcept +{ + CHECK_POINTER_EX(mediaStream, rtcBool32::kFalse); + CHECK_POINTER_EX(audioTrack, rtcBool32::kFalse); + + scoped_refptr pMediaStream = static_cast(mediaStream); + scoped_refptr pAudioTrack = static_cast(audioTrack); + return pMediaStream->RemoveTrack(pAudioTrack) + ? rtcBool32::kTrue + : rtcBool32::kFalse; +} + +rtcBool32 LIB_WEBRTC_CALL +RTCMediaStream_RemoveVideoTrack( + rtcMediaStreamHandle mediaStream, + rtcVideoTrackHandle videoTrack +) noexcept +{ + CHECK_POINTER_EX(mediaStream, rtcBool32::kFalse); + CHECK_POINTER_EX(videoTrack, rtcBool32::kFalse); + + scoped_refptr pMediaStream = static_cast(mediaStream); + scoped_refptr pVideoTrack = static_cast(videoTrack); + return pMediaStream->RemoveTrack(pVideoTrack) + ? rtcBool32::kTrue + : rtcBool32::kFalse; +} + +int LIB_WEBRTC_CALL +RTCMediaStream_NumberOfAudioTracks( + rtcMediaStreamHandle mediaStream +) noexcept +{ + CHECK_POINTER_EX(mediaStream, 0); + scoped_refptr pMediaStream = static_cast(mediaStream); + vector> audio_tracks = pMediaStream->audio_tracks(); + return static_cast(audio_tracks.size()); +} + +int LIB_WEBRTC_CALL +RTCMediaStream_NumberOfVideoTracks( + rtcMediaStreamHandle mediaStream +) noexcept +{ + CHECK_POINTER_EX(mediaStream, 0); + scoped_refptr pMediaStream = static_cast(mediaStream); + vector> video_tracks = pMediaStream->video_tracks(); + return static_cast(video_tracks.size()); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCMediaStream_GetAudioTrack ( + rtcMediaStreamHandle mediaStream, + int index, + rtcAudioTrackHandle* pOutRetVal +) noexcept +{ + CHECK_NATIVE_HANDLE(mediaStream); + CHECK_OUT_POINTER(pOutRetVal); + if (index < 0) { + return rtcResultU4::kOutOfRange; + } + + scoped_refptr pMediaStream = static_cast(mediaStream); + vector> audio_tracks = pMediaStream->audio_tracks(); + size_t ndx = static_cast(index); + if (ndx >= audio_tracks.size()) { + return rtcResultU4::kOutOfRange; + } + scoped_refptr audio_track = audio_tracks[index]; + *pOutRetVal = static_cast(audio_track.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCMediaStream_GetVideoTrack ( + rtcMediaStreamHandle mediaStream, + int index, + rtcVideoTrackHandle* pOutRetVal +) noexcept +{ + CHECK_NATIVE_HANDLE(mediaStream); + CHECK_OUT_POINTER(pOutRetVal); + if (index < 0) { + return rtcResultU4::kOutOfRange; + } + + scoped_refptr pMediaStream = static_cast(mediaStream); + vector> video_tracks = pMediaStream->video_tracks(); + size_t ndx = static_cast(index); + if (ndx >= video_tracks.size()) { + return rtcResultU4::kOutOfRange; + } + scoped_refptr video_track = video_tracks[index]; + *pOutRetVal = static_cast(video_track.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCMediaStream_FindAudioTrack ( + rtcMediaStreamHandle mediaStream, + const char* track_id, + rtcAudioTrackHandle* pOutRetVal +) noexcept +{ + CHECK_NATIVE_HANDLE(mediaStream); + CHECK_OUT_POINTER(pOutRetVal); + CHECK_POINTER_EX(track_id, rtcResultU4::kInvalidParameter); + + scoped_refptr pMediaStream = static_cast(mediaStream); + scoped_refptr audio_track = pMediaStream->FindAudioTrack(string(track_id)); + *pOutRetVal = static_cast(audio_track.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCMediaStream_FindVideoTrack ( + rtcMediaStreamHandle mediaStream, + const char* track_id, + rtcVideoTrackHandle* pOutRetVal +) noexcept +{ + CHECK_NATIVE_HANDLE(mediaStream); + CHECK_OUT_POINTER(pOutRetVal); + CHECK_POINTER_EX(track_id, rtcResultU4::kInvalidParameter); + + scoped_refptr pMediaStream = static_cast(mediaStream); + scoped_refptr video_track = pMediaStream->FindVideoTrack(string(track_id)); + *pOutRetVal = static_cast(video_track.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCMediaStream_GetLabel ( + rtcMediaStreamHandle mediaStream, + char* value, + int sz_value +) noexcept +{ + CHECK_NATIVE_HANDLE(mediaStream); + CHECK_POINTER(value); + ZERO_MEMORY(value, sz_value); + if (sz_value < 1) { + return rtcResultU4::kBufferTooSmall; + } + sz_value--; + + rtcResultU4 result = rtcResultU4::kSuccess; + scoped_refptr pMediaStream = static_cast(mediaStream); + string srcValue = pMediaStream->label(); + size_t srcLen = srcValue.size(); + size_t dstSize = static_cast(sz_value); + size_t len = std::min(srcLen, dstSize); + if (srcLen > len) { + result = rtcResultU4::kBufferTooSmall; + } + if (len > 0) { + strncpy(value, srcValue.c_string(), len); + value[len] = '\0'; + } + return result; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCMediaStream_GetId ( + rtcMediaStreamHandle mediaStream, + char* value, + int sz_value +) noexcept +{ + CHECK_NATIVE_HANDLE(mediaStream); + CHECK_POINTER(value); + ZERO_MEMORY(value, sz_value); + if (sz_value < 1) { + return rtcResultU4::kBufferTooSmall; + } + sz_value--; + + rtcResultU4 result = rtcResultU4::kSuccess; + scoped_refptr pMediaStream = static_cast(mediaStream); + string srcValue = pMediaStream->id(); + size_t srcLen = srcValue.size(); + size_t dstSize = static_cast(sz_value); + size_t len = std::min(srcLen, dstSize); + if (srcLen > len) { + result = rtcResultU4::kBufferTooSmall; + } + if (len > 0) { + strncpy(value, srcValue.c_string(), len); + value[len] = '\0'; + } + return result; +} From 21e46908c259814b03f035e7fe8d448c314bf832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Tue, 24 Dec 2024 22:02:34 +0300 Subject: [PATCH 38/69] Added empty rtc_peerconnection_interop.cc --- BUILD.gn | 1 + include/interop_api.h | 12 ++++-------- src/interop/rtc_peerconnection_interop.cc | 4 ++++ src/rtc_data_channel_impl.cc | 8 ++++---- src/rtc_desktop_media_list_impl.cc | 8 ++++---- 5 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 src/interop/rtc_peerconnection_interop.cc diff --git a/BUILD.gn b/BUILD.gn index 522d2b2b37..17b8d33b53 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -174,6 +174,7 @@ rtc_shared_library("libwebrtc") { "src/interop/rtc_data_channel_interop.cc", "src/interop/rtc_ice_candidate_interop.cc", "src/interop/rtc_media_stream_interop.cc", + "src/interop/rtc_peerconnection_interop.cc", ] if (libwebrtc_desktop_capture) { diff --git a/include/interop_api.h b/include/interop_api.h index 937e8d0be4..49db5b6180 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -526,14 +526,11 @@ using rtcMediaListObserverDelegate = void(LIB_WEBRTC_CALL*)( * Callback delegate structure for MediaListObserver. */ struct rtcMediaListObserverCallbacks { + rtcObjectHandle UserData{}; rtcMediaListObserverDelegate MediaSourceAdded{}; - rtcObjectHandle user_data_added{}; rtcMediaListObserverDelegate MediaSourceRemoved{}; - rtcObjectHandle user_data_removed{}; rtcMediaListObserverDelegate MediaSourceNameChanged{}; - rtcObjectHandle user_data_name_changed{}; rtcMediaListObserverDelegate MediaSourceThumbnailChanged{}; - rtcObjectHandle user_data_thumbnail_changed{}; }; /** @@ -558,10 +555,9 @@ using rtcDataChannelObserverMessageDelegate = void(LIB_WEBRTC_CALL*)( * Callback delegate structure for RTCDataChannelObserver. */ struct rtcDataChannelObserverCallbacks { - rtcDataChannelObserverStateChangeDelegate StateChange{}; - rtcObjectHandle user_data_state_change{}; - rtcDataChannelObserverMessageDelegate Message{}; - rtcObjectHandle user_data_message{}; + rtcObjectHandle UserData{}; + rtcDataChannelObserverStateChangeDelegate StateChanged{}; + rtcDataChannelObserverMessageDelegate MessageReceived{}; }; /* diff --git a/src/interop/rtc_peerconnection_interop.cc b/src/interop/rtc_peerconnection_interop.cc new file mode 100644 index 0000000000..036f6c362b --- /dev/null +++ b/src/interop/rtc_peerconnection_interop.cc @@ -0,0 +1,4 @@ +#include "rtc_peerconnection.h" +#include "interop_api.h" + +using namespace libwebrtc; diff --git a/src/rtc_data_channel_impl.cc b/src/rtc_data_channel_impl.cc index 4a71277d07..e994c5f891 100644 --- a/src/rtc_data_channel_impl.cc +++ b/src/rtc_data_channel_impl.cc @@ -29,8 +29,8 @@ void RTCDataChannelObserverImpl::OnStateChange(RTCDataChannelState state) { if (callbacks_) { rtcDataChannelObserverCallbacks* pCallbacks = static_cast(callbacks_); - pCallbacks->StateChange( - pCallbacks->user_data_state_change, + pCallbacks->StateChanged( + pCallbacks->UserData, static_cast(state)); } } @@ -39,8 +39,8 @@ void RTCDataChannelObserverImpl::OnMessage(const char* buffer, int length, bool { if (callbacks_) { rtcDataChannelObserverCallbacks* pCallbacks = static_cast(callbacks_); - pCallbacks->Message( - pCallbacks->user_data_message, + pCallbacks->MessageReceived( + pCallbacks->UserData, buffer, length, binary ? rtcBool32::kTrue : rtcBool32::kFalse); diff --git a/src/rtc_desktop_media_list_impl.cc b/src/rtc_desktop_media_list_impl.cc index b8d96637eb..41a3068b0f 100644 --- a/src/rtc_desktop_media_list_impl.cc +++ b/src/rtc_desktop_media_list_impl.cc @@ -278,7 +278,7 @@ void MediaListObserverImpl::OnMediaSourceAdded(scoped_refptr source if (callbacks_) { rtcMediaListObserverCallbacks* pCallbacks = static_cast(callbacks_); rtcDesktopMediaSourceHandle pSource = static_cast(source.release()); - pCallbacks->MediaSourceAdded(pCallbacks->user_data_added, pSource); + pCallbacks->MediaSourceAdded(pCallbacks->UserData, pSource); } } @@ -287,7 +287,7 @@ void MediaListObserverImpl::OnMediaSourceRemoved(scoped_refptr sour if (callbacks_) { rtcMediaListObserverCallbacks* pCallbacks = static_cast(callbacks_); rtcDesktopMediaSourceHandle pSource = static_cast(source.release()); - pCallbacks->MediaSourceRemoved(pCallbacks->user_data_removed, pSource); + pCallbacks->MediaSourceRemoved(pCallbacks->UserData, pSource); } } @@ -296,7 +296,7 @@ void MediaListObserverImpl::OnMediaSourceNameChanged(scoped_refptr if (callbacks_) { rtcMediaListObserverCallbacks* pCallbacks = static_cast(callbacks_); rtcDesktopMediaSourceHandle pSource = static_cast(source.release()); - pCallbacks->MediaSourceNameChanged(pCallbacks->user_data_name_changed, pSource); + pCallbacks->MediaSourceNameChanged(pCallbacks->UserData, pSource); } } @@ -305,7 +305,7 @@ void MediaListObserverImpl::OnMediaSourceThumbnailChanged(scoped_refptr(callbacks_); rtcDesktopMediaSourceHandle pSource = static_cast(source.release()); - pCallbacks->MediaSourceThumbnailChanged(pCallbacks->user_data_thumbnail_changed, pSource); + pCallbacks->MediaSourceThumbnailChanged(pCallbacks->UserData, pSource); } } From 6ddd25be0c5cb844a1e1df696674174a4de8fed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Wed, 25 Dec 2024 12:35:11 +0300 Subject: [PATCH 39/69] optimization --- include/base/portable.h | 18 +++++ include/interop_api.h | 4 +- src/interop/libwebrtc_interop.cc | 21 +++-- src/interop/rtc_audio_device_interop.cc | 76 +++++++------------ src/interop/rtc_data_channel_interop.cc | 22 ++---- src/interop/rtc_desktop_media_list_interop.cc | 25 ++---- src/interop/rtc_ice_candidate_interop.cc | 38 +++------- src/interop/rtc_media_stream_interop.cc | 42 +++------- src/interop/rtc_media_track_interop.cc | 47 ++++-------- .../rtc_peerconnection_factory_interop.cc | 14 +--- src/interop/rtc_sdp_parse_error_interop.cc | 38 +++------- src/interop/rtc_video_device_interop.cc | 21 +++-- 12 files changed, 132 insertions(+), 234 deletions(-) diff --git a/include/base/portable.h b/include/base/portable.h index 66f7356a52..b3a68f4c11 100644 --- a/include/base/portable.h +++ b/include/base/portable.h @@ -84,6 +84,24 @@ class string { inline std::string std_string() const { return std::string(m_dynamic == 0 ? m_buf : m_dynamic, m_length); } + + /** + * Makes safe copies up to the size of the output buffer. + * + * @param dest - Output buffer + * @param sz_dest - Size of the output buffer + * @return size_t - Number of characters copied. (excluding the ending character '\0') + */ + inline size_t copy_to(char* dest, size_t sz_dest) const { + if (dest == 0) { return 0; } + *dest = '\0'; + if (sz_dest == 0 || m_length == 0) { return 0; } + size_t cch_len = sz_dest - 1; + // safe copy + strncpy(dest, c_string(), cch_len); + dest[cch_len] = '\0'; + return cch_len; + } }; inline std::string to_std_string(const string& str) { return str.std_string(); } diff --git a/include/interop_api.h b/include/interop_api.h index 49db5b6180..076a4e5327 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -30,8 +30,8 @@ #define CHECK_NATIVE_HANDLE(h) \ CHECK_POINTER_EX(h, rtcResultU4::kInvalidNativeHandle) #define ZERO_MEMORY(p, sz) \ - if (static_cast(sz) > 0) { \ - memset((void*)(p), 0, static_cast(sz)); \ + if (static_cast(p) && static_cast(sz) > 0) { \ + memset(static_cast(p), 0, static_cast(sz)); \ } extern "C" { diff --git a/src/interop/libwebrtc_interop.cc b/src/interop/libwebrtc_interop.cc index f0c9d18fa0..556794e117 100644 --- a/src/interop/libwebrtc_interop.cc +++ b/src/interop/libwebrtc_interop.cc @@ -26,16 +26,16 @@ rtcResultU4 LIB_WEBRTC_CALL LibWebRTC_GetErrorMessage( rtcResultU4 code, char* pBuffer, - unsigned int cchBuffer + unsigned int sizeOfBuffer ) noexcept { CHECK_POINTER(pBuffer); - if (cchBuffer == 0) { + if (sizeOfBuffer == 0) { return rtcResultU4::kBufferTooSmall; } - ZERO_MEMORY(pBuffer, cchBuffer); + ZERO_MEMORY(pBuffer, sizeOfBuffer); - char szBuffer[256] = {0}; + char szTemp[256] = {0}; const char* message = ""; switch (code) { @@ -91,18 +91,15 @@ LibWebRTC_GetErrorMessage( message = "A null or invalid pointer."; break; default: - snprintf(szBuffer, sizeof(szBuffer), "Undefined error: 0x%X", static_cast(code)); - message = (const char*)szBuffer; + snprintf(szTemp, sizeof(szTemp), "Undefined error: 0x%X", static_cast(code)); + message = szTemp; break; } - unsigned int cchMessage = (unsigned int)strlen(message); - unsigned int cchLen = std::min(cchMessage, cchBuffer - 1); - if (cchLen > 0) { - strncpy(pBuffer, message, (size_t)cchLen); - } + string strMessage(message); + size_t len = strMessage.copy_to(pBuffer, static_cast(sizeOfBuffer)); - return cchMessage > cchLen + return strMessage.size() > len ? rtcResultU4::kBufferTooSmall : rtcResultU4::kSuccess; } diff --git a/src/interop/rtc_audio_device_interop.cc b/src/interop/rtc_audio_device_interop.cc index 2b5c1bffd5..84716a5493 100644 --- a/src/interop/rtc_audio_device_interop.cc +++ b/src/interop/rtc_audio_device_interop.cc @@ -16,7 +16,7 @@ RTCAudioDevice_PlayoutDevices( { CHECK_POINTER_EX(audiDevice, 0); scoped_refptr pAudioDevice = static_cast(audiDevice); - return (int)pAudioDevice->PlayoutDevices(); + return static_cast(pAudioDevice->PlayoutDevices()); } // end RTCAudioDevice_PlayoutDevices int LIB_WEBRTC_CALL @@ -26,7 +26,7 @@ RTCAudioDevice_RecordingDevices( { CHECK_POINTER_EX(audiDevice, 0); scoped_refptr pAudioDevice = static_cast(audiDevice); - return (int)pAudioDevice->RecordingDevices(); + return static_cast(pAudioDevice->RecordingDevices()); } // end RTCAudioDevice_RecordingDevices rtcResultU4 LIB_WEBRTC_CALL @@ -57,25 +57,18 @@ RTCAudioDevice_PlayoutDeviceName( return result; } - int nSrcNameLen = ((int)strlen(szName)); - if (nSrcNameLen > cchOutName) { - result = rtcResultU4::kBufferTooSmall; - } - int nSrcGuidLen = ((int)strlen(szGuid)); - if (nSrcGuidLen > cchOutGuid) { + size_t len; + string strName(szName); + string strGuid(szGuid); + + len = strName.copy_to(pOutName, static_cast(cchOutName)); + if (strName.size() > len) { result = rtcResultU4::kBufferTooSmall; } - int nNameLen = std::min(cchOutName, nSrcNameLen); - if (nNameLen > 0) { - strncpy(pOutName, (const char*)szName, nNameLen); - pOutName[nNameLen] = '\0'; - } - - int nGuidLen = std::min(cchOutGuid, nSrcGuidLen); - if (nGuidLen > 0) { - strncpy(pOutGuid, (const char*)szGuid, nGuidLen); - pOutGuid[nGuidLen] = '\0'; + len = strGuid.copy_to(pOutGuid, static_cast(cchOutGuid)); + if (strGuid.size() > len) { + result = rtcResultU4::kBufferTooSmall; } return result; @@ -99,8 +92,6 @@ RTCAudioDevice_RecordingDeviceName( } ZERO_MEMORY(pOutName, cchOutName); ZERO_MEMORY(pOutGuid, cchOutGuid); - cchOutName--; - cchOutGuid--; char szName[RTCAudioDevice::kAdmMaxDeviceNameSize] = {0}; char szGuid[RTCAudioDevice::kAdmMaxGuidSize] = {0}; @@ -111,25 +102,18 @@ RTCAudioDevice_RecordingDeviceName( return result; } - int nSrcNameLen = ((int)strlen(szName)); - if (nSrcNameLen > cchOutName) { - result = rtcResultU4::kBufferTooSmall; - } - int nSrcGuidLen = ((int)strlen(szGuid)); - if (nSrcGuidLen > cchOutGuid) { + size_t len; + string strName(szName); + string strGuid(szGuid); + + len = strName.copy_to(pOutName, static_cast(cchOutName)); + if (strName.size() > len) { result = rtcResultU4::kBufferTooSmall; } - int nNameLen = std::min(cchOutName, nSrcNameLen); - if (nNameLen > 0) { - strncpy(pOutName, (const char*)szName, nNameLen); - pOutName[nNameLen] = '\0'; - } - - int nGuidLen = std::min(cchOutGuid, nSrcGuidLen); - if (nGuidLen > 0) { - strncpy(pOutGuid, (const char*)szGuid, nGuidLen); - pOutGuid[nGuidLen] = '\0'; + len = strGuid.copy_to(pOutGuid, static_cast(cchOutGuid)); + if (strGuid.size() > len) { + result = rtcResultU4::kBufferTooSmall; } return result; @@ -148,7 +132,7 @@ RTCAudioDevice_SetPlayoutDevice( if (index < 0 || index >= nCount) { return rtcResultU4::kOutOfRange; } - return (rtcResultU4)pAudioDevice->SetPlayoutDevice((uint16_t)index); + return static_cast(pAudioDevice->SetPlayoutDevice((uint16_t)index)); } // end RTCAudioDevice_SetPlayoutDevice rtcResultU4 LIB_WEBRTC_CALL @@ -164,7 +148,7 @@ RTCAudioDevice_SetRecordingDevice( if (index < 0 || index >= nCount) { return rtcResultU4::kOutOfRange; } - return (rtcResultU4)pAudioDevice->SetRecordingDevice((uint16_t)index); + return static_cast(pAudioDevice->SetRecordingDevice((uint16_t)index)); } // end RTCAudioDevice_SetRecordingDevice rtcResultU4 LIB_WEBRTC_CALL @@ -187,8 +171,8 @@ RTCAudioDevice_RegisterDeviceChangeCallback( } }; } - rtcResultU4 result = (rtcResultU4)pAudioDevice->OnDeviceChange(cb); - return result; + + return static_cast(pAudioDevice->OnDeviceChange(cb)); } // end RTCAudioDevice_RegisterDeviceChangeCallback rtcResultU4 LIB_WEBRTC_CALL @@ -199,8 +183,7 @@ RTCAudioDevice_SetMicrophoneVolume( { CHECK_NATIVE_HANDLE(audiDevice); scoped_refptr pAudioDevice = static_cast(audiDevice); - rtcResultU4 result = (rtcResultU4)pAudioDevice->SetMicrophoneVolume(volume); - return result; + return static_cast(pAudioDevice->SetMicrophoneVolume(volume)); } // end RTCAudioDevice_SetMicrophoneVolume rtcResultU4 LIB_WEBRTC_CALL @@ -211,8 +194,7 @@ RTCAudioDevice_GetMicrophoneVolume( { CHECK_NATIVE_HANDLE(audiDevice); scoped_refptr pAudioDevice = static_cast(audiDevice); - rtcResultU4 result = (rtcResultU4)pAudioDevice->MicrophoneVolume(*volume); - return result; + return static_cast(pAudioDevice->MicrophoneVolume(*volume)); } // end RTCAudioDevice_GetMicrophoneVolume rtcResultU4 LIB_WEBRTC_CALL @@ -223,8 +205,7 @@ RTCAudioDevice_SetSpeakerVolume( { CHECK_NATIVE_HANDLE(audiDevice); scoped_refptr pAudioDevice = static_cast(audiDevice); - rtcResultU4 result = (rtcResultU4)pAudioDevice->SetSpeakerVolume(volume); - return result; + return static_cast(pAudioDevice->SetSpeakerVolume(volume)); } // end RTCAudioDevice_SetSpeakerVolume rtcResultU4 LIB_WEBRTC_CALL @@ -235,6 +216,5 @@ RTCAudioDevice_GetSpeakerVolume( { CHECK_NATIVE_HANDLE(audiDevice); scoped_refptr pAudioDevice = static_cast(audiDevice); - rtcResultU4 result = (rtcResultU4)pAudioDevice->SpeakerVolume(*volume); - return result; + return static_cast(pAudioDevice->SpeakerVolume(*volume)); } // end RTCAudioDevice_GetSpeakerVolume diff --git a/src/interop/rtc_data_channel_interop.cc b/src/interop/rtc_data_channel_interop.cc index ad9cd3b251..39a772dd43 100644 --- a/src/interop/rtc_data_channel_interop.cc +++ b/src/interop/rtc_data_channel_interop.cc @@ -79,27 +79,17 @@ RTCDataChannel_GetLabel( { CHECK_NATIVE_HANDLE(dataChannel); CHECK_POINTER(label); + ZERO_MEMORY(label, label_size); if (label_size < 1) { return rtcResultU4::kInvalidParameter; } - ZERO_MEMORY(label, label_size); - rtcResultU4 result = rtcResultU4::kSuccess; scoped_refptr pDataChannel = static_cast(dataChannel); - string sLabel = pDataChannel->label(); - if (sLabel.size() > 0) { - size_t dstSize = static_cast(label_size - 1); - size_t len = std::min(dstSize, sLabel.size()); - if (sLabel.size() > len) { - result = rtcResultU4::kBufferTooSmall; - } - if (len > 0) { - strncpy(label, sLabel.c_string(), len); - label[len] = '\0'; - } - } - - return result; + string strLabel = pDataChannel->label(); + size_t len = strLabel.copy_to(label, static_cast(label_size)); + return strLabel.size() > len + ? rtcResultU4::kBufferTooSmall + : rtcResultU4::kSuccess; } rtcResultU4 LIB_WEBRTC_CALL diff --git a/src/interop/rtc_desktop_media_list_interop.cc b/src/interop/rtc_desktop_media_list_interop.cc index 1cfe339218..1305778e83 100644 --- a/src/interop/rtc_desktop_media_list_interop.cc +++ b/src/interop/rtc_desktop_media_list_interop.cc @@ -134,9 +134,6 @@ MediaSource_GetInfo( ZERO_MEMORY(pOutId, cchOutId); ZERO_MEMORY(pOutName, cchOutName); RESET_OUT_POINTER_EX(pOutType, static_cast(-1)); - - cchOutId--; - cchOutName--; rtcResultU4 result = rtcResultU4::kSuccess; size_t cchLen; @@ -144,25 +141,19 @@ MediaSource_GetInfo( scoped_refptr pMediaSource = static_cast(mediaSource); if (pOutId && cchOutId > 0) { - ZERO_MEMORY(pOutId, cchOutId); szTmp = pMediaSource->id(); - if (szTmp.size() > (size_t)cchOutId) { + cchLen = szTmp.copy_to(pOutId, static_cast(cchOutId)); + if (szTmp.size() > cchLen) { result = rtcResultU4::kBufferTooSmall; } - cchLen = std::min(szTmp.size(), (size_t)cchOutId); - strncpy(pOutId, szTmp.c_string(), cchLen); - pOutId[cchLen] = '\0'; } if (pOutName && cchOutName > 0) { - ZERO_MEMORY(pOutName, cchOutName); szTmp = pMediaSource->name(); - if (szTmp.size() > (size_t)cchOutName) { + cchLen = szTmp.copy_to(pOutName, static_cast(cchOutName)); + if (szTmp.size() > cchLen) { result = rtcResultU4::kBufferTooSmall; } - cchLen = std::min(szTmp.size(), (size_t)cchOutName); - strncpy(pOutName, szTmp.c_string(), cchLen); - pOutName[cchLen] = '\0'; } if (pOutType) { @@ -192,7 +183,8 @@ MediaSource_GetThumbnail( ) noexcept { CHECK_NATIVE_HANDLE(mediaSource); - size_t szDstBuffer = static_cast(*refSizeOfBuffer); + CHECK_POINTER(refSizeOfBuffer); + size_t sizeOfBuffer = static_cast(*refSizeOfBuffer); RESET_OUT_POINTER_EX(refSizeOfBuffer, 0); scoped_refptr pMediaSource = static_cast(mediaSource); @@ -200,13 +192,12 @@ MediaSource_GetThumbnail( size_t szSrcSize = buffer.size(); *refSizeOfBuffer = static_cast(szSrcSize); - if (pBuffer) { - if (szSrcSize > szDstBuffer) { + if (pBuffer && szSrcSize > 0) { + if (szSrcSize > sizeOfBuffer) { return rtcResultU4::kBufferTooSmall; } memcpy((void*)pBuffer, (const void*)buffer.data(), szSrcSize); } - return rtcResultU4::kSuccess; } diff --git a/src/interop/rtc_ice_candidate_interop.cc b/src/interop/rtc_ice_candidate_interop.cc index fbd9205d15..3f118d20b5 100644 --- a/src/interop/rtc_ice_candidate_interop.cc +++ b/src/interop/rtc_ice_candidate_interop.cc @@ -43,21 +43,13 @@ RTCIceCandidate_GetCandidate( if (sz_value < 1) { return rtcResultU4::kBufferTooSmall; } - sz_value--; - rtcResultU4 result = rtcResultU4::kSuccess; scoped_refptr pIceCandidate = static_cast(iceCandidate); - size_t dstLen = static_cast(sz_value); - string src_value = pIceCandidate->candidate(); - size_t len = std::min(dstLen, src_value.size()); - if (src_value.size() > len) { - result = rtcResultU4::kBufferTooSmall; - } - if (len > 0) { - strncpy(value, src_value.c_string(), len); - value[len] = '\0'; - } - return result; + string strValue = pIceCandidate->candidate(); + size_t len = strValue.copy_to(value, static_cast(sz_value)); + return strValue.size() > len + ? rtcResultU4::kBufferTooSmall + : rtcResultU4::kSuccess; } rtcResultU4 LIB_WEBRTC_CALL @@ -72,21 +64,13 @@ RTCIceCandidate_GetSdpMid( if (sz_value < 1) { return rtcResultU4::kBufferTooSmall; } - sz_value--; - rtcResultU4 result = rtcResultU4::kSuccess; scoped_refptr pIceCandidate = static_cast(iceCandidate); - size_t dstLen = static_cast(sz_value); - string src_value = pIceCandidate->sdp_mid(); - size_t len = std::min(dstLen, src_value.size()); - if (src_value.size() > len) { - result = rtcResultU4::kBufferTooSmall; - } - if (len > 0) { - strncpy(value, src_value.c_string(), len); - value[len] = '\0'; - } - return result; + string strValue = pIceCandidate->sdp_mid(); + size_t len = strValue.copy_to(value, static_cast(sz_value)); + return strValue.size() > len + ? rtcResultU4::kBufferTooSmall + : rtcResultU4::kSuccess; } rtcResultU4 LIB_WEBRTC_CALL @@ -102,4 +86,4 @@ RTCIceCandidate_GetSdpMlineIndex( scoped_refptr pIceCandidate = static_cast(iceCandidate); *pOutRetVal = pIceCandidate->sdp_mline_index(); return rtcResultU4::kSuccess; -} \ No newline at end of file +} diff --git a/src/interop/rtc_media_stream_interop.cc b/src/interop/rtc_media_stream_interop.cc index a8c85f0bc7..42bec056c8 100644 --- a/src/interop/rtc_media_stream_interop.cc +++ b/src/interop/rtc_media_stream_interop.cc @@ -179,27 +179,18 @@ RTCMediaStream_GetLabel ( ) noexcept { CHECK_NATIVE_HANDLE(mediaStream); - CHECK_POINTER(value); ZERO_MEMORY(value, sz_value); + CHECK_POINTER(value); if (sz_value < 1) { return rtcResultU4::kBufferTooSmall; } - sz_value--; - rtcResultU4 result = rtcResultU4::kSuccess; scoped_refptr pMediaStream = static_cast(mediaStream); - string srcValue = pMediaStream->label(); - size_t srcLen = srcValue.size(); - size_t dstSize = static_cast(sz_value); - size_t len = std::min(srcLen, dstSize); - if (srcLen > len) { - result = rtcResultU4::kBufferTooSmall; - } - if (len > 0) { - strncpy(value, srcValue.c_string(), len); - value[len] = '\0'; - } - return result; + string strValue = pMediaStream->label(); + size_t len = strValue.copy_to(value, static_cast(sz_value)); + return strValue.size() > len + ? rtcResultU4::kBufferTooSmall + : rtcResultU4::kSuccess; } rtcResultU4 LIB_WEBRTC_CALL @@ -210,25 +201,16 @@ RTCMediaStream_GetId ( ) noexcept { CHECK_NATIVE_HANDLE(mediaStream); - CHECK_POINTER(value); ZERO_MEMORY(value, sz_value); + CHECK_POINTER(value); if (sz_value < 1) { return rtcResultU4::kBufferTooSmall; } - sz_value--; - rtcResultU4 result = rtcResultU4::kSuccess; scoped_refptr pMediaStream = static_cast(mediaStream); - string srcValue = pMediaStream->id(); - size_t srcLen = srcValue.size(); - size_t dstSize = static_cast(sz_value); - size_t len = std::min(srcLen, dstSize); - if (srcLen > len) { - result = rtcResultU4::kBufferTooSmall; - } - if (len > 0) { - strncpy(value, srcValue.c_string(), len); - value[len] = '\0'; - } - return result; + string strValue = pMediaStream->id(); + size_t len = strValue.copy_to(value, static_cast(sz_value)); + return strValue.size() > len + ? rtcResultU4::kBufferTooSmall + : rtcResultU4::kSuccess; } diff --git a/src/interop/rtc_media_track_interop.cc b/src/interop/rtc_media_track_interop.cc index 64cdaa1c93..be0bc7f7f5 100644 --- a/src/interop/rtc_media_track_interop.cc +++ b/src/interop/rtc_media_track_interop.cc @@ -21,28 +21,18 @@ RTCMediaTrack_GetKind( ) noexcept { CHECK_NATIVE_HANDLE(mediaTrack); + ZERO_MEMORY(pOutKind, cchOutKind); + CHECK_POINTER(pOutKind); if (cchOutKind < 1) { return rtcResultU4::kBufferTooSmall; } - ZERO_MEMORY(pOutKind, cchOutKind); - cchOutKind--; - rtcResultU4 result = rtcResultU4::kSuccess; scoped_refptr pMediaTrack = static_cast(mediaTrack); - string kind = pMediaTrack->kind(); - size_t dstSize = static_cast(cchOutKind); - size_t srcSize = kind.size(); - if (srcSize > dstSize) { - result = rtcResultU4::kBufferTooSmall; - } - - size_t len = std::min(dstSize, srcSize); - if (len > 0) { - strncpy(pOutKind, kind.c_string(), len); - pOutKind[len] = '\0'; - } - - return result; + string strValue = pMediaTrack->kind(); + size_t len = strValue.copy_to(pOutKind, static_cast(cchOutKind)); + return strValue.size() > len + ? rtcResultU4::kBufferTooSmall + : rtcResultU4::kSuccess; } rtcResultU4 LIB_WEBRTC_CALL @@ -53,27 +43,18 @@ RTCMediaTrack_GetId( ) noexcept { CHECK_NATIVE_HANDLE(mediaTrack); + ZERO_MEMORY(pOutId, cchOutId); + CHECK_POINTER(pOutId); if (cchOutId < 1) { return rtcResultU4::kBufferTooSmall; } - ZERO_MEMORY(pOutId, cchOutId); - cchOutId--; - rtcResultU4 result = rtcResultU4::kSuccess; scoped_refptr pMediaTrack = static_cast(mediaTrack); - string id = pMediaTrack->id(); - size_t dstSize = static_cast(cchOutId); - size_t srcSize = id.size(); - if (srcSize > dstSize) { - result = rtcResultU4::kBufferTooSmall; - } - - size_t len = std::min(dstSize, srcSize); - if (len > 0) { - strncpy(pOutId, id.c_string(), len); - } - - return result; + string strValue = pMediaTrack->id(); + size_t len = strValue.copy_to(pOutId, static_cast(cchOutId)); + return strValue.size() > len + ? rtcResultU4::kBufferTooSmall + : rtcResultU4::kSuccess; } rtcBool32 LIB_WEBRTC_CALL diff --git a/src/interop/rtc_peerconnection_factory_interop.cc b/src/interop/rtc_peerconnection_factory_interop.cc index b2979ed336..62570b3848 100644 --- a/src/interop/rtc_peerconnection_factory_interop.cc +++ b/src/interop/rtc_peerconnection_factory_interop.cc @@ -7,10 +7,8 @@ using namespace libwebrtc; RTCConfiguration CreateRtcConfiguration(const rtcPeerConnectionConfiguration* configuration) { - RTCConfiguration result; - if (configuration == nullptr) { - return result; - } + RTCConfiguration result{}; + CHECK_POINTER_EX(configuration, result); for (int i = 0; i < kMaxIceServerSize; i++) { result.ice_servers[i].uri = string(configuration->ice_servers[i].uri); @@ -53,9 +51,7 @@ RTCPeerConnectionFactory_Initialize( rtcPeerConnectionFactoryHandle factory ) noexcept { - if (factory == nullptr) { - return rtcBool32::kFalse; - } + CHECK_POINTER_EX(factory, rtcBool32::kFalse); scoped_refptr pFactory = static_cast(factory); return pFactory->Initialize() @@ -68,9 +64,7 @@ RTCPeerConnectionFactory_Terminate( rtcPeerConnectionFactoryHandle factory ) noexcept { - if (factory == nullptr) { - return rtcBool32::kFalse; - } + CHECK_POINTER_EX(factory, rtcBool32::kFalse); scoped_refptr pFactory = static_cast(factory); return pFactory->Terminate() diff --git a/src/interop/rtc_sdp_parse_error_interop.cc b/src/interop/rtc_sdp_parse_error_interop.cc index ef43149f22..1afd4e56f2 100644 --- a/src/interop/rtc_sdp_parse_error_interop.cc +++ b/src/interop/rtc_sdp_parse_error_interop.cc @@ -30,21 +30,12 @@ RTCSdpParseError_GetLine( } ZERO_MEMORY(value, sz_value); - rtcResultU4 result = rtcResultU4::kSuccess; scoped_refptr pSdpParseError = static_cast(sdpParseError); - string sValue = pSdpParseError->line(); - if (sValue.size() > 0) { - size_t dstLen = static_cast(sz_value) - 1; - size_t len = std::min(dstLen, sValue.size()); - if (sValue.size() > len) { - result = rtcResultU4::kBufferTooSmall; - } - if (len > 0) { - strncpy(value, sValue.c_string(), len); - value[len] = '\0'; - } - } - return result; + string strValue = pSdpParseError->line(); + size_t len = strValue.copy_to(value, static_cast(sz_value)); + return strValue.size() > len + ? rtcResultU4::kBufferTooSmall + : rtcResultU4::kSuccess; } rtcResultU4 LIB_WEBRTC_CALL @@ -74,21 +65,12 @@ RTCSdpParseError_GetDescription( } ZERO_MEMORY(value, sz_value); - rtcResultU4 result = rtcResultU4::kSuccess; scoped_refptr pSdpParseError = static_cast(sdpParseError); - string sValue = pSdpParseError->description(); - if (sValue.size() > 0) { - size_t dstLen = static_cast(sz_value) - 1; - size_t len = std::min(dstLen, sValue.size()); - if (sValue.size() > len) { - result = rtcResultU4::kBufferTooSmall; - } - if (len > 0) { - strncpy(value, sValue.c_string(), len); - value[len] = '\0'; - } - } - return result; + string strValue = pSdpParseError->description(); + size_t len = strValue.copy_to(value, static_cast(sz_value)); + return strValue.size() > len + ? rtcResultU4::kBufferTooSmall + : rtcResultU4::kSuccess; } rtcResultU4 LIB_WEBRTC_CALL diff --git a/src/interop/rtc_video_device_interop.cc b/src/interop/rtc_video_device_interop.cc index 14ec2ea499..4ece7b5637 100644 --- a/src/interop/rtc_video_device_interop.cc +++ b/src/interop/rtc_video_device_interop.cc @@ -37,13 +37,12 @@ RTCVideoDevice_GetDeviceName( ZERO_MEMORY(pOutProductUniqueIdUTF8, cchOutProductUniqueIdUTF8); scoped_refptr pVideoDevice = static_cast(videoDevice); - rtcResultU4 result = (rtcResultU4)pVideoDevice->GetDeviceName( - (uint32_t)index, - pOutDeviceNameUTF8, (uint32_t)cchOutDeviceNameUTF8, - pOutDeviceUniqueIdUTF8, (uint32_t)cchOutDeviceUniqueIdUTF8, - pOutProductUniqueIdUTF8, (uint32_t)cchOutProductUniqueIdUTF8 - ); - + rtcResultU4 result = static_cast(pVideoDevice->GetDeviceName( + static_cast(index), + pOutDeviceNameUTF8, static_cast(cchOutDeviceNameUTF8), + pOutDeviceUniqueIdUTF8, static_cast(cchOutDeviceUniqueIdUTF8), + pOutProductUniqueIdUTF8, static_cast(cchOutProductUniqueIdUTF8) + )); return result; } @@ -62,10 +61,10 @@ RTCVideoDevice_CreateVideoCapturer( scoped_refptr pVideoDevice = static_cast(videoDevice); scoped_refptr pVideoCapturer = pVideoDevice->Create( name, - (uint32_t)index, - (size_t)width, - (size_t)height, - (size_t)target_fps + static_cast(index), + static_cast(width), + static_cast(height), + static_cast(target_fps) ); if (pVideoCapturer == nullptr) { return rtcResultU4::kUnknownError; From 85b63605fe8c60a782215b866c2448f6a69b5deb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Wed, 25 Dec 2024 20:56:47 +0300 Subject: [PATCH 40/69] Added rtc_base_list.h --- BUILD.gn | 1 + include/rtc_base_list.h | 57 ++++++++++++++++++++++++++++++++++ include/rtc_peerconnection.h | 2 ++ src/rtc_peerconnection_impl.cc | 22 ++++++++++++- src/rtc_peerconnection_impl.h | 3 ++ 5 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 include/rtc_base_list.h diff --git a/BUILD.gn b/BUILD.gn index 17b8d33b53..0ed57b3488 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -69,6 +69,7 @@ rtc_shared_library("libwebrtc") { "include/base/refcountedobject.h", "include/base/scoped_ref_ptr.h", "include/libwebrtc.h", + "include/rtc_base_list.h", "include/rtc_audio_device.h", "include/rtc_audio_source.h", "include/rtc_audio_track.h", diff --git a/include/rtc_base_list.h b/include/rtc_base_list.h new file mode 100644 index 0000000000..138288e63f --- /dev/null +++ b/include/rtc_base_list.h @@ -0,0 +1,57 @@ +#ifndef LIB_WEBRTC_RTC_BASE_LIST_HXX +#define LIB_WEBRTC_RTC_BASE_LIST_HXX + +#include "rtc_types.h" + +namespace libwebrtc { + +template +class RTCBaseList : public RefCountInterface { + protected: + using raw_type = typename std::aligned_storage::type; + + private: + T* m_items; + size_t m_count; + + public: + RTCBaseList() : m_items(0), m_count(0) {} + + RTCBaseList(const vector& o) : m_items(0), m_count(0) { + m_count = o.size(); + if (m_count != 0) { + m_items = new T[m_count]; + for (size_t i = 0; i < m_count; ++i) { + m_items[i] = o[i]; + } + } + } + + vector to_vector() const { return vector(m_items, m_count); } + + ~RTCBaseList() { destroy_all(); } + + public: + size_t count() const { return m_count; } + + T& item(size_t index) { return m_items[index]; } + + const T& item(size_t index) const { return m_items[index]; } + + void clear() { destroy_all(); } + + protected: + void destroy(T* rt) { reinterpret_cast(rt)->~T(); } + + void destroy_all() { + for (size_t i = 0; i < m_count; ++i) { + destroy(&m_items[i]); + } + m_items = 0; + m_count = 0; + } +}; // end class RTCBaseList + +} // namespace libwebrtc + +#endif // LIB_WEBRTC_RTC_BASE_LIST_HXX diff --git a/include/rtc_peerconnection.h b/include/rtc_peerconnection.h index 39811a9a61..3d3b266959 100644 --- a/include/rtc_peerconnection.h +++ b/include/rtc_peerconnection.h @@ -172,6 +172,8 @@ class RTCPeerConnectionObserver { class RTCPeerConnection : public RefCountInterface { public: + virtual bool IsInitialized() const = 0; + virtual int AddStream(scoped_refptr stream) = 0; virtual int RemoveStream(scoped_refptr stream) = 0; diff --git a/src/rtc_peerconnection_impl.cc b/src/rtc_peerconnection_impl.cc index 6ff2241ee9..a1a5a722e8 100644 --- a/src/rtc_peerconnection_impl.cc +++ b/src/rtc_peerconnection_impl.cc @@ -191,7 +191,9 @@ RTCPeerConnectionImpl::RTCPeerConnectionImpl( : rtc_peerconnection_factory_(peer_connection_factory), configuration_(configuration), constraints_(constraints), - callback_crt_sec_(new webrtc::Mutex()) { + callback_crt_sec_(new webrtc::Mutex()), + initialize_crt_sec_(new webrtc::Mutex()) +{ RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor"; Initialize(); } @@ -361,6 +363,12 @@ void RTCPeerConnectionImpl::DeRegisterRTCPeerConnectionObserver() { } bool RTCPeerConnectionImpl::Initialize() { + webrtc::MutexLock cs(initialize_crt_sec_.get()); + if (initialized_) { + return true; + } + initialized_ = true; + RTC_DCHECK(rtc_peerconnection_factory_.get() != nullptr); RTC_DCHECK(rtc_peerconnection_.get() == nullptr); @@ -434,6 +442,12 @@ bool RTCPeerConnectionImpl::Initialize() { return true; } +bool RTCPeerConnectionImpl::IsInitialized() const +{ + webrtc::MutexLock cs(initialize_crt_sec_.get()); + return initialized_; +} + scoped_refptr RTCPeerConnectionImpl::CreateDataChannel( const string label, RTCDataChannelInit* dataChannelDict) { webrtc::DataChannelInit init; @@ -606,6 +620,12 @@ void RTCPeerConnectionImpl::RestartIce() { } void RTCPeerConnectionImpl::Close() { + webrtc::MutexLock cs(initialize_crt_sec_.get()); + if (!initialized_) { + return; + } + initialized_ = false; + RTC_LOG(LS_INFO) << __FUNCTION__; if (rtc_peerconnection_.get()) { rtc_peerconnection_ = nullptr; diff --git a/src/rtc_peerconnection_impl.h b/src/rtc_peerconnection_impl.h index 7920bd5fc3..c781a275b6 100644 --- a/src/rtc_peerconnection_impl.h +++ b/src/rtc_peerconnection_impl.h @@ -35,6 +35,7 @@ class RTCPeerConnectionImpl : public RTCPeerConnection, public webrtc::PeerConnectionObserver { public: virtual bool Initialize(); + virtual bool IsInitialized() const override; virtual void CreateOffer( OnSdpCreateSuccess success, OnSdpCreateFailure failure, @@ -191,7 +192,9 @@ class RTCPeerConnectionImpl : public RTCPeerConnection, webrtc::PeerConnectionInterface::RTCOfferAnswerOptions offer_answer_options_; RTCPeerConnectionObserver* observer_ = nullptr; std::unique_ptr callback_crt_sec_; + std::unique_ptr initialize_crt_sec_; bool initialize_offer_sent = false; + bool initialized_ = false; std::vector> local_streams_; std::vector> remote_streams_; scoped_refptr data_channel_; From 9c19044eb4377bdf8bbad9b31b36596d5c1ec28d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Thu, 26 Dec 2024 18:24:56 +0300 Subject: [PATCH 41/69] Added rtc_media_stream_list_impl --- BUILD.gn | 4 +++ include/interop_api.h | 34 ++++++++++++++++++ include/rtc_media_stream_list.h | 25 +++++++++++++ src/interop/rtc_media_stream_list_interop.cc | 38 ++++++++++++++++++++ src/rtc_media_stream_list_impl.cc | 24 +++++++++++++ src/rtc_media_stream_list_impl.h | 17 +++++++++ 6 files changed, 142 insertions(+) create mode 100644 include/rtc_media_stream_list.h create mode 100644 src/interop/rtc_media_stream_list_interop.cc create mode 100644 src/rtc_media_stream_list_impl.cc create mode 100644 src/rtc_media_stream_list_impl.h diff --git a/BUILD.gn b/BUILD.gn index 0ed57b3488..4336058f47 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -80,6 +80,7 @@ rtc_shared_library("libwebrtc") { "include/rtc_sdp_parse_error.h", "include/rtc_ice_candidate.h", "include/rtc_media_stream.h", + "include/rtc_media_stream_list.h", "include/rtc_media_track.h", "include/rtc_mediaconstraints.h", "include/rtc_peerconnection.h", @@ -124,6 +125,8 @@ rtc_shared_library("libwebrtc") { "src/rtc_ice_candidate_impl.h", "src/rtc_media_stream_impl.cc", "src/rtc_media_stream_impl.h", + "src/rtc_media_stream_list_impl.cc", + "src/rtc_media_stream_list_impl.h", "src/rtc_mediaconstraints_impl.cc", "src/rtc_mediaconstraints_impl.h", "src/rtc_peerconnection_factory_impl.cc", @@ -175,6 +178,7 @@ rtc_shared_library("libwebrtc") { "src/interop/rtc_data_channel_interop.cc", "src/interop/rtc_ice_candidate_interop.cc", "src/interop/rtc_media_stream_interop.cc", + "src/interop/rtc_media_stream_list_interop.cc", "src/interop/rtc_peerconnection_interop.cc", ] diff --git a/include/interop_api.h b/include/interop_api.h index 076a4e5327..17783860f5 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -413,6 +413,9 @@ using rtcDesktopMediaListHandle = rtcRefCountedObjectHandle; /// Opaque handle to a native RTCMediaStream interop object. using rtcMediaStreamHandle = rtcRefCountedObjectHandle; +/// Opaque handle to a native RTCMediaStreamList interop object. +using rtcMediaStreamListHandle = rtcRefCountedObjectHandle; + /// Opaque handle to a native RTCMediaTrack interop object. using rtcMediaTrackHandle = rtcRefCountedObjectHandle; @@ -1727,6 +1730,37 @@ RTCMediaStream_GetId ( int sz_value ) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCMediaStreamList interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Returns the number of MediaStreams. + * + * @param mediaStreamList - Media stream list handle + * @return int - The number of streams + */ +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RTCMediaStreamList_GetCount ( + rtcMediaStreamListHandle mediaStreamList +) noexcept; + +/** + * Returns the media stream whose index is specified. + * + * @param mediaStreamList - Media stream list handle + * @param index - Media stream index + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCMediaStreamList_GetItem ( + rtcMediaStreamListHandle mediaStreamList, + int index, + rtcMediaStreamHandle* pOutRetVal +) noexcept; + } // extern "C" #endif // LIB_WEBRTC_INTROP_API_HXX \ No newline at end of file diff --git a/include/rtc_media_stream_list.h b/include/rtc_media_stream_list.h new file mode 100644 index 0000000000..1c9a18848e --- /dev/null +++ b/include/rtc_media_stream_list.h @@ -0,0 +1,25 @@ +#ifndef LIB_WEBRTC_RTC_MEDIA_STREAM_LIST_HXX +#define LIB_WEBRTC_RTC_MEDIA_STREAM_LIST_HXX + +#include "rtc_types.h" +#include "rtc_base_list.h" +#include "rtc_media_stream.h" + +namespace libwebrtc { + +class RTCMediaStreamList : public RTCBaseList> { + public: + static LIB_WEBRTC_API scoped_refptr Create( + const vector>& source); + + protected: + RTCMediaStreamList(const vector>& source) + : RTCBaseList>(source) + {} + + ~RTCMediaStreamList() {} +}; + +} // namespace libwebrtc + +#endif // LIB_WEBRTC_RTC_MEDIA_STREAM_LIST_HXX diff --git a/src/interop/rtc_media_stream_list_interop.cc b/src/interop/rtc_media_stream_list_interop.cc new file mode 100644 index 0000000000..bc76fa8ebd --- /dev/null +++ b/src/interop/rtc_media_stream_list_interop.cc @@ -0,0 +1,38 @@ +#include "rtc_media_stream_list.h" +#include "interop_api.h" + +using namespace libwebrtc; + +int LIB_WEBRTC_CALL +RTCMediaStreamList_GetCount ( + rtcMediaStreamListHandle mediaStreamList +) noexcept +{ + CHECK_POINTER_EX(mediaStreamList, 0); + + scoped_refptr pMediaStreamList = static_cast(mediaStreamList); + return static_cast(pMediaStreamList->count()); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCMediaStreamList_GetItem ( + rtcMediaStreamListHandle mediaStreamList, + int index, + rtcMediaStreamHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + RESET_OUT_POINTER(pOutRetVal); + CHECK_NATIVE_HANDLE(mediaStreamList); + if (index < 0) { + return rtcResultU4::kOutOfRange; + } + + scoped_refptr pMediaStreamList = static_cast(mediaStreamList); + scoped_refptr pMediaStream = pMediaStreamList->item(static_cast(index)); + if (pMediaStream == nullptr) { + return rtcResultU4::kUnknownError; + } + *pOutRetVal = static_cast(pMediaStream.release()); + return rtcResultU4::kSuccess; +} diff --git a/src/rtc_media_stream_list_impl.cc b/src/rtc_media_stream_list_impl.cc new file mode 100644 index 0000000000..73d5840ffc --- /dev/null +++ b/src/rtc_media_stream_list_impl.cc @@ -0,0 +1,24 @@ +#include "rtc_media_stream_list_impl.h" + +#include "rtc_base/logging.h" +#include "rtc_media_stream.h" +#include "rtc_types.h" + +namespace libwebrtc { + +scoped_refptr RTCMediaStreamList::Create( + const vector>& source) { + return new RefCountedObject(source); +} + +RTCMediaStreamListImpl::RTCMediaStreamListImpl( + const vector>& source) + : RTCMediaStreamList(source) { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor "; +} + +RTCMediaStreamListImpl::~RTCMediaStreamListImpl() { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; +} + +} // namespace libwebrtc diff --git a/src/rtc_media_stream_list_impl.h b/src/rtc_media_stream_list_impl.h new file mode 100644 index 0000000000..f2ec78e9f2 --- /dev/null +++ b/src/rtc_media_stream_list_impl.h @@ -0,0 +1,17 @@ +#ifndef LIB_WEBRTC_MEDIA_STREAM_LIST_IMPL_HXX +#define LIB_WEBRTC_MEDIA_STREAM_LIST_IMPL_HXX + +#include "rtc_media_stream_list.h" +#include "rtc_media_stream.h" + +namespace libwebrtc { + +class RTCMediaStreamListImpl : public RTCMediaStreamList { + public: + RTCMediaStreamListImpl(const vector>& source); + ~RTCMediaStreamListImpl(); +}; + +} // namespace libwebrtc + +#endif //! LIB_WEBRTC_MEDIA_STREAM_LIST_IMPL_HXX \ No newline at end of file From 55a872422117dd5554a65145126aa91daaf10237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Fri, 27 Dec 2024 23:34:12 +0300 Subject: [PATCH 42/69] Added rtc_rtp_capabilities_interop.cc --- BUILD.gn | 5 + include/interop_api.h | 211 +++++++++++ include/rtc_base_list.h | 13 +- include/rtc_ice_candidate.h | 2 +- include/rtc_media_stream_list.h | 4 +- include/rtc_rtp_capabilities_lists.h | 44 +++ include/rtc_sdp_parse_error.h | 2 +- include/rtc_session_description.h | 2 +- src/interop/rtc_rtp_capabilities_interop.cc | 398 ++++++++++++++++++++ src/interop/rtc_rtp_transceiver_interop.cc | 5 + src/rtc_rtp_capabilities_lists_impl.cc | 40 ++ src/rtc_rtp_capabilities_lists_impl.h | 29 ++ 12 files changed, 749 insertions(+), 6 deletions(-) create mode 100644 include/rtc_rtp_capabilities_lists.h create mode 100644 src/interop/rtc_rtp_capabilities_interop.cc create mode 100644 src/interop/rtc_rtp_transceiver_interop.cc create mode 100644 src/rtc_rtp_capabilities_lists_impl.cc create mode 100644 src/rtc_rtp_capabilities_lists_impl.h diff --git a/BUILD.gn b/BUILD.gn index 4336058f47..1c57fd41e7 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -86,6 +86,7 @@ rtc_shared_library("libwebrtc") { "include/rtc_peerconnection.h", "include/rtc_peerconnection_factory.h", "include/rtc_rtp_capabilities.h", + "include/rtc_rtp_capabilities_lists.h", "include/rtc_rtp_parameters.h", "include/rtc_rtp_receiver.h", "include/rtc_rtp_sender.h", @@ -135,6 +136,8 @@ rtc_shared_library("libwebrtc") { "src/rtc_peerconnection_impl.h", "src/rtc_rtp_capabilities_impl.cc", "src/rtc_rtp_capabilities_impl.h", + "src/rtc_rtp_capabilities_lists_impl.cc", + "src/rtc_rtp_capabilities_lists_impl.h", "src/rtc_rtp_parameters_impl.cc", "src/rtc_rtp_parameters_impl.h", "src/rtc_rtp_receiver_impl.cc", @@ -179,6 +182,8 @@ rtc_shared_library("libwebrtc") { "src/interop/rtc_ice_candidate_interop.cc", "src/interop/rtc_media_stream_interop.cc", "src/interop/rtc_media_stream_list_interop.cc", + "src/interop/rtc_rtp_capabilities_interop.cc", + "src/interop/rtc_rtp_transceiver_interop.cc", "src/interop/rtc_peerconnection_interop.cc", ] diff --git a/include/interop_api.h b/include/interop_api.h index 17783860f5..700cecbbf3 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -473,6 +473,12 @@ using rtcRtpCodecCapabilityHandle = rtcRefCountedObjectHandle; /// Opaque handle to a native RTCRtpHeaderExtensionCapability interop object. using rtcRtpHeaderExtensionCapabilityHandle = rtcRefCountedObjectHandle; +/// Opaque handle to a native RTCRtpCodecCapabilityList interop object. +using rtcRtpCodecCapabilityListHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCRtpHeaderExtensionListCapability interop object. +using rtcRtpHeaderExtensionCapabilityListHandle = rtcRefCountedObjectHandle; + /// Opaque handle to a native RTCRtpCapabilities interop object. using rtcRtpCapabilitiesHandle = rtcRefCountedObjectHandle; @@ -1752,6 +1758,7 @@ RTCMediaStreamList_GetCount ( * * @param mediaStreamList - Media stream list handle * @param index - Media stream index + * @param pOutRetVal - Media stream handle * @return rtcResultU4 - 0 if successful, otherwise an error code. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL @@ -1761,6 +1768,210 @@ RTCMediaStreamList_GetItem ( rtcMediaStreamHandle* pOutRetVal ) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCRtpCodecCapability interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Creates a new instance of RTCRtpCodecCapability. + * + * @param pOutRetVal - Handle of RTCRtpCodecCapability + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_Create( + rtcRtpCodecCapabilityHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_GetMimeType( + rtcRtpCodecCapabilityHandle handle, + char* value, + int sz_value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_SetMimeType( + rtcRtpCodecCapabilityHandle handle, + const char* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_GetClockRate( + rtcRtpCodecCapabilityHandle handle, + int* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_SetClockRate( + rtcRtpCodecCapabilityHandle handle, + int value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_GetChannels( + rtcRtpCodecCapabilityHandle handle, + int* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_SetChannels( + rtcRtpCodecCapabilityHandle handle, + int value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_GetSdpFmtpLine( + rtcRtpCodecCapabilityHandle handle, + char* value, + int sz_value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_SetSdpFmtpLine( + rtcRtpCodecCapabilityHandle handle, + const char* value +) noexcept; + +/* + * ---------------------------------------------------------------------- + * RTCRtpCodecCapabilityList interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Returns the number of RtpCodecCapabilityList. + * + * @param handle - List handle + * @return int - The number of items + */ +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RTCRtpCodecCapabilityList_GetCount ( + rtcRtpCodecCapabilityListHandle handle +) noexcept; + +/** + * Returns the rtp codec capability whose index is specified. + * + * @param handle - List handle + * @param index - Item index + * @param pOutRetVal - Item handle + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapabilityList_GetItem ( + rtcRtpCodecCapabilityListHandle handle, + int index, + rtcRtpCodecCapabilityHandle* pOutRetVal +) noexcept; + +/* + * ---------------------------------------------------------------------- + * RTCRtpHeaderExtensionCapability interop methods + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapability_GetUri( + rtcRtpHeaderExtensionCapabilityHandle handle, + char* value, + int sz_value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapability_SetUri( + rtcRtpHeaderExtensionCapabilityHandle handle, + const char* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapability_GetPreferredId( + rtcRtpHeaderExtensionCapabilityHandle handle, + int* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapability_SetPreferredId( + rtcRtpHeaderExtensionCapabilityHandle handle, + int value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapability_GetPreferredEncrypt( + rtcRtpHeaderExtensionCapabilityHandle handle, + rtcBool32* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapability_SetPreferredEncrypt( + rtcRtpHeaderExtensionCapabilityHandle handle, + rtcBool32 value +) noexcept; + +/* + * ---------------------------------------------------------------------- + * RTCRtpHeaderExtensionCapabilityList interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Returns the number of RtpHeaderExtensionCapabilityList. + * + * @param handle - List handle + * @return int - The number of items + */ +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapabilityList_GetCount ( + rtcRtpHeaderExtensionCapabilityListHandle handle +) noexcept; + +/** + * Returns the rtp header extension capability whose index is specified. + * + * @param handle - List handle + * @param index - Item index + * @param pOutRetVal - Item handle + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapabilityList_GetItem ( + rtcRtpHeaderExtensionCapabilityListHandle handle, + int index, + rtcRtpHeaderExtensionCapabilityHandle* pOutRetVal +) noexcept; + +/* + * ---------------------------------------------------------------------- + * RTCRtpCapabilities interop methods + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCapabilities_GetCodecs( + rtcRtpCapabilitiesHandle handle, + rtcRtpCodecCapabilityListHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCapabilities_SetCodecs( + rtcRtpCapabilitiesHandle handle, + rtcRtpCodecCapabilityListHandle hCodecs +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCapabilities_GetHeaderExtensions( + rtcRtpCapabilitiesHandle handle, + rtcRtpHeaderExtensionCapabilityListHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCapabilities_SetHeaderExtensions( + rtcRtpCapabilitiesHandle handle, + rtcRtpHeaderExtensionCapabilityListHandle hHeaderExtensions +) noexcept; + } // extern "C" #endif // LIB_WEBRTC_INTROP_API_HXX \ No newline at end of file diff --git a/include/rtc_base_list.h b/include/rtc_base_list.h index 138288e63f..c4f6ad8e72 100644 --- a/include/rtc_base_list.h +++ b/include/rtc_base_list.h @@ -27,7 +27,18 @@ class RTCBaseList : public RefCountInterface { } } - vector to_vector() const { return vector(m_items, m_count); } + vector to_vector() const { + if (m_count == 0) { + return vector(); + } + else { + T* items = new T[m_count]; + for (size_t i = 0; i < m_count; ++i) { + items[i] = m_items[i]; + } + return vector(items, m_count); + } + } ~RTCBaseList() { destroy_all(); } diff --git a/include/rtc_ice_candidate.h b/include/rtc_ice_candidate.h index 0bbbc9423d..57e5aa5171 100644 --- a/include/rtc_ice_candidate.h +++ b/include/rtc_ice_candidate.h @@ -8,7 +8,7 @@ namespace libwebrtc { class RTCIceCandidate : public RefCountInterface { public: - static LIB_WEBRTC_API scoped_refptr Create( + LIB_WEBRTC_API static scoped_refptr Create( const string sdp, const string sdp_mid, int sdp_mline_index, RTCSdpParseError* error); diff --git a/include/rtc_media_stream_list.h b/include/rtc_media_stream_list.h index 1c9a18848e..105e66afd6 100644 --- a/include/rtc_media_stream_list.h +++ b/include/rtc_media_stream_list.h @@ -9,14 +9,14 @@ namespace libwebrtc { class RTCMediaStreamList : public RTCBaseList> { public: - static LIB_WEBRTC_API scoped_refptr Create( + LIB_WEBRTC_API static scoped_refptr Create( const vector>& source); protected: RTCMediaStreamList(const vector>& source) : RTCBaseList>(source) {} - + ~RTCMediaStreamList() {} }; diff --git a/include/rtc_rtp_capabilities_lists.h b/include/rtc_rtp_capabilities_lists.h new file mode 100644 index 0000000000..ae4448451f --- /dev/null +++ b/include/rtc_rtp_capabilities_lists.h @@ -0,0 +1,44 @@ +#ifndef LIB_WBBRTC_RTC_RTP_CAPABILITIES_LISTS_HXX +#define LIB_WBBRTC_RTC_RTP_CAPABILITIES_LISTS_HXX + +#include "rtc_types.h" +#include "rtc_base_list.h" +#include "rtc_rtp_capabilities.h" + +namespace libwebrtc { + +/** + * class RTCRtpCodecCapabilityList + */ +class RTCRtpCodecCapabilityList : public RTCBaseList> { + public: + LIB_WEBRTC_API static scoped_refptr Create( + const vector>& source); + + protected: + RTCRtpCodecCapabilityList(const vector>& source) + : RTCBaseList>(source) + {} + + ~RTCRtpCodecCapabilityList() {} +}; + +/** + * class RTCRtpHeaderExtensionCapabilityList + */ +class RTCRtpHeaderExtensionCapabilityList : public RTCBaseList> { + public: + LIB_WEBRTC_API static scoped_refptr Create( + const vector>& source); + + protected: + RTCRtpHeaderExtensionCapabilityList(const vector>& source) + : RTCBaseList>(source) + {} + + ~RTCRtpHeaderExtensionCapabilityList() {} +}; + +} // namespace libwebrtc + +#endif // LIB_WBBRTC_RTC_RTP_CAPABILITIES_LISTS_HXX diff --git a/include/rtc_sdp_parse_error.h b/include/rtc_sdp_parse_error.h index 8cda63fd6a..af8e43099f 100644 --- a/include/rtc_sdp_parse_error.h +++ b/include/rtc_sdp_parse_error.h @@ -7,7 +7,7 @@ namespace libwebrtc { class RTCSdpParseError : public RefCountInterface { public: - static LIB_WEBRTC_API scoped_refptr Create(); + LIB_WEBRTC_API static scoped_refptr Create(); public: // The sdp line that causes the error. diff --git a/include/rtc_session_description.h b/include/rtc_session_description.h index bd4ad743f4..ae8ec3a9e5 100644 --- a/include/rtc_session_description.h +++ b/include/rtc_session_description.h @@ -10,7 +10,7 @@ class RTCSessionDescription : public RefCountInterface { public: enum SdpType { kOffer = 0, kPrAnswer, kAnswer }; - static LIB_WEBRTC_API scoped_refptr Create( + LIB_WEBRTC_API static scoped_refptr Create( const string type, const string sdp, RTCSdpParseError* error); public: diff --git a/src/interop/rtc_rtp_capabilities_interop.cc b/src/interop/rtc_rtp_capabilities_interop.cc new file mode 100644 index 0000000000..22fe3df9d9 --- /dev/null +++ b/src/interop/rtc_rtp_capabilities_interop.cc @@ -0,0 +1,398 @@ +#include "rtc_rtp_capabilities.h" +#include "rtc_rtp_capabilities_lists.h" +#include "interop_api.h" + +using namespace libwebrtc; + +/* + * ---------------------------------------------------------------------- + * RTCRtpCodecCapability interop methods + * ---------------------------------------------------------------------- + */ + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_Create( + rtcRtpCodecCapabilityHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + + scoped_refptr pCodec = RTCRtpCodecCapability::Create(); + if (pCodec == nullptr) { + return rtcResultU4::kUnknownError; + } + *pOutRetVal = static_cast(pCodec.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_GetMimeType( + rtcRtpCodecCapabilityHandle handle, + char* value, + int sz_value +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + ZERO_MEMORY(value, sz_value); + CHECK_POINTER(value); + if (sz_value < 1) { + return rtcResultU4::kBufferTooSmall; + } + + scoped_refptr pCodec = static_cast(handle); + string strValue = pCodec->mime_type(); + size_t len = strValue.copy_to(value, static_cast(sz_value)); + return strValue.size() > len + ? rtcResultU4::kBufferTooSmall + : rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_SetMimeType( + rtcRtpCodecCapabilityHandle handle, + const char* value +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr pCodec = static_cast(handle); + pCodec->set_mime_type(string(value)); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_GetClockRate( + rtcRtpCodecCapabilityHandle handle, + int* pOutRetVal +) noexcept +{ + CHECK_POINTER(pOutRetVal); + RESET_OUT_POINTER_EX(pOutRetVal, 0); + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr pCodec = static_cast(handle); + *pOutRetVal = pCodec->clock_rate(); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_SetClockRate( + rtcRtpCodecCapabilityHandle handle, + int value +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr pCodec = static_cast(handle); + pCodec->set_clock_rate(value); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_GetChannels( + rtcRtpCodecCapabilityHandle handle, + int* pOutRetVal +) noexcept +{ + CHECK_POINTER(pOutRetVal); + RESET_OUT_POINTER_EX(pOutRetVal, 0); + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr pCodec = static_cast(handle); + *pOutRetVal = pCodec->channels(); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_SetChannels( + rtcRtpCodecCapabilityHandle handle, + int value +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr pCodec = static_cast(handle); + pCodec->set_channels(value); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_GetSdpFmtpLine( + rtcRtpCodecCapabilityHandle handle, + char* value, + int sz_value +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + ZERO_MEMORY(value, sz_value); + CHECK_POINTER(value); + if (sz_value < 1) { + return rtcResultU4::kBufferTooSmall; + } + + scoped_refptr pCodec = static_cast(handle); + string strValue = pCodec->sdp_fmtp_line(); + size_t len = strValue.copy_to(value, static_cast(sz_value)); + return strValue.size() > len + ? rtcResultU4::kBufferTooSmall + : rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_SetSdpFmtpLine( + rtcRtpCodecCapabilityHandle handle, + const char* value +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr pCodec = static_cast(handle); + pCodec->set_sdp_fmtp_line(string(value)); + return rtcResultU4::kSuccess; +} + +/* + * ---------------------------------------------------------------------- + * RTCRtpCodecCapabilityList interop methods + * ---------------------------------------------------------------------- + */ + +int LIB_WEBRTC_CALL +RTCRtpCodecCapabilityList_GetCount ( + rtcRtpCodecCapabilityListHandle handle +) noexcept +{ + CHECK_POINTER_EX(handle, 0); + scoped_refptr pList = static_cast(handle); + return static_cast(pList->count()); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapabilityList_GetItem ( + rtcRtpCodecCapabilityListHandle handle, + int index, + rtcRtpCodecCapabilityHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr pList = static_cast(handle); + if (index < 0 || static_cast(index) >= pList->count()) { + return rtcResultU4::kOutOfRange; + } + scoped_refptr pItem = pList->item(static_cast(index)); + *pOutRetVal = static_cast(pItem.release()); + return rtcResultU4::kSuccess; +} + +/* + * ---------------------------------------------------------------------- + * RTCRtpHeaderExtensionCapability interop methods + * ---------------------------------------------------------------------- + */ + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapability_GetUri( + rtcRtpHeaderExtensionCapabilityHandle handle, + char* value, + int sz_value +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + ZERO_MEMORY(value, sz_value); + CHECK_POINTER(value); + if (sz_value < 1) { + return rtcResultU4::kBufferTooSmall; + } + + scoped_refptr pHeaderExtension = static_cast(handle); + string strValue = pHeaderExtension->uri(); + size_t len = strValue.copy_to(value, static_cast(sz_value)); + return strValue.size() > len + ? rtcResultU4::kBufferTooSmall + : rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapability_SetUri( + rtcRtpHeaderExtensionCapabilityHandle handle, + const char* value +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr pHeaderExtension = static_cast(handle); + pHeaderExtension->set_uri(string(value)); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapability_GetPreferredId( + rtcRtpHeaderExtensionCapabilityHandle handle, + int* pOutRetVal +) noexcept +{ + CHECK_POINTER(pOutRetVal); + RESET_OUT_POINTER_EX(pOutRetVal, 0); + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr pHeaderExtension = static_cast(handle); + *pOutRetVal = pHeaderExtension->preferred_id(); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapability_SetPreferredId( + rtcRtpHeaderExtensionCapabilityHandle handle, + int value +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr pHeaderExtension = static_cast(handle); + pHeaderExtension->set_preferred_id(value); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapability_GetPreferredEncrypt( + rtcRtpHeaderExtensionCapabilityHandle handle, + rtcBool32* pOutRetVal +) noexcept +{ + CHECK_POINTER(pOutRetVal); + RESET_OUT_POINTER_EX(pOutRetVal, rtcBool32::kFalse); + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr pHeaderExtension = static_cast(handle); + *pOutRetVal = pHeaderExtension->preferred_encrypt() ? rtcBool32::kTrue : rtcBool32::kFalse; + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapability_SetPreferredEncrypt( + rtcRtpHeaderExtensionCapabilityHandle handle, + rtcBool32 value +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr pHeaderExtension = static_cast(handle); + pHeaderExtension->set_preferred_encrypt(value != rtcBool32::kFalse); + return rtcResultU4::kSuccess; +} + +/* + * ---------------------------------------------------------------------- + * RTCRtpHeaderExtensionCapabilityList interop methods + * ---------------------------------------------------------------------- + */ + +int LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapabilityList_GetCount ( + rtcRtpHeaderExtensionCapabilityListHandle handle +) noexcept +{ + CHECK_POINTER_EX(handle, 0); + scoped_refptr pList = + static_cast(handle); + return static_cast(pList->count()); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapabilityList_GetItem ( + rtcRtpHeaderExtensionCapabilityListHandle handle, + int index, + rtcRtpHeaderExtensionCapabilityHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr pList = + static_cast(handle); + if (index < 0 || static_cast(index) >= pList->count()) { + return rtcResultU4::kOutOfRange; + } + scoped_refptr pItem = pList->item(static_cast(index)); + *pOutRetVal = static_cast(pItem.release()); + return rtcResultU4::kSuccess; +} + +/* + * ---------------------------------------------------------------------- + * RTCRtpCapabilities interop methods + * ---------------------------------------------------------------------- + */ + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCapabilities_GetCodecs( + rtcRtpCapabilitiesHandle handle, + rtcRtpCodecCapabilityListHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr pRtpCapabilities = static_cast(handle); + scoped_refptr codecs = RTCRtpCodecCapabilityList::Create( + pRtpCapabilities->codecs() + ); + if (codecs == nullptr) { + return rtcResultU4::kUnknownError; + } + *pOutRetVal = static_cast(codecs.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCapabilities_SetCodecs( + rtcRtpCapabilitiesHandle handle, + rtcRtpCodecCapabilityListHandle hCodecs +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(hCodecs, rtcResultU4::kInvalidParameter); + + scoped_refptr pRtpCapabilities = static_cast(handle); + scoped_refptr codecs = static_cast(hCodecs); + pRtpCapabilities->set_codecs(codecs->to_vector()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCapabilities_GetHeaderExtensions( + rtcRtpCapabilitiesHandle handle, + rtcRtpHeaderExtensionCapabilityListHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr pRtpCapabilities = static_cast(handle); + scoped_refptr header_extensions = RTCRtpHeaderExtensionCapabilityList::Create( + pRtpCapabilities->header_extensions() + ); + if (header_extensions == nullptr) { + return rtcResultU4::kUnknownError; + } + *pOutRetVal = static_cast(header_extensions.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCapabilities_SetHeaderExtensions( + rtcRtpCapabilitiesHandle handle, + rtcRtpHeaderExtensionCapabilityListHandle hHeaderExtensions +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(hHeaderExtensions, rtcResultU4::kInvalidParameter); + + scoped_refptr pRtpCapabilities = static_cast(handle); + scoped_refptr header_extensions = + static_cast(hHeaderExtensions); + pRtpCapabilities->set_header_extensions(header_extensions->to_vector()); + return rtcResultU4::kSuccess; +} diff --git a/src/interop/rtc_rtp_transceiver_interop.cc b/src/interop/rtc_rtp_transceiver_interop.cc new file mode 100644 index 0000000000..a33cacaf4a --- /dev/null +++ b/src/interop/rtc_rtp_transceiver_interop.cc @@ -0,0 +1,5 @@ +#include "rtc_rtp_transceiver.h" +#include "interop_api.h" + +using namespace libwebrtc; + diff --git a/src/rtc_rtp_capabilities_lists_impl.cc b/src/rtc_rtp_capabilities_lists_impl.cc new file mode 100644 index 0000000000..76ba1198dc --- /dev/null +++ b/src/rtc_rtp_capabilities_lists_impl.cc @@ -0,0 +1,40 @@ +#include "rtc_rtp_capabilities_lists_impl.h" + +#include "rtc_base/logging.h" +#include "rtc_rtp_capabilities.h" +#include "rtc_types.h" + +namespace libwebrtc { + +scoped_refptr RTCRtpCodecCapabilityList::Create( + const vector>& source) { + return new RefCountedObject(source); +} + +RTCRtpCodecCapabilityListImpl::RTCRtpCodecCapabilityListImpl( + const vector>& source) + : RTCRtpCodecCapabilityList(source) { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor "; +} + +RTCRtpCodecCapabilityListImpl::~RTCRtpCodecCapabilityListImpl() { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; +} + + +scoped_refptr RTCRtpHeaderExtensionCapabilityList::Create( + const vector>& source) { + return new RefCountedObject(source); +} + +RTCRtpHeaderExtensionCapabilityListImpl::RTCRtpHeaderExtensionCapabilityListImpl( + const vector>& source) + : RTCRtpHeaderExtensionCapabilityList(source) { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor "; +} + +RTCRtpHeaderExtensionCapabilityListImpl::~RTCRtpHeaderExtensionCapabilityListImpl() { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; +} + +} // namespace libwebrtc diff --git a/src/rtc_rtp_capabilities_lists_impl.h b/src/rtc_rtp_capabilities_lists_impl.h new file mode 100644 index 0000000000..21952fc2a2 --- /dev/null +++ b/src/rtc_rtp_capabilities_lists_impl.h @@ -0,0 +1,29 @@ +#ifndef LIB_WBBRTC_RTC_RTP_CAPABILITIES_LISTS_IMPL_HXX +#define LIB_WBBRTC_RTC_RTP_CAPABILITIES_LISTS_IMPL_HXX + +#include "rtc_rtp_capabilities.h" +#include "rtc_rtp_capabilities_lists.h" + +namespace libwebrtc { + +/** + * class RTCRtpCodecCapabilityListImpl + */ +class RTCRtpCodecCapabilityListImpl : public RTCRtpCodecCapabilityList { + public: + RTCRtpCodecCapabilityListImpl(const vector>& source); + ~RTCRtpCodecCapabilityListImpl(); +}; + +/** + * class RTCRtpHeaderExtensionCapabilityListImpl + */ +class RTCRtpHeaderExtensionCapabilityListImpl : public RTCRtpHeaderExtensionCapabilityList { + public: + RTCRtpHeaderExtensionCapabilityListImpl(const vector>& source); + ~RTCRtpHeaderExtensionCapabilityListImpl(); +}; + +} // namespace libwebrtc + +#endif //! LIB_WBBRTC_RTC_RTP_CAPABILITIES_LISTS_IMPL_HXX \ No newline at end of file From a795fce356dbea31562db68411063bd383959a68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Sat, 28 Dec 2024 18:49:19 +0300 Subject: [PATCH 43/69] Deleted _list_. List codes have been moved. --- BUILD.gn | 7 ---- include/interop_api.h | 22 ++++++++++ include/rtc_media_stream.h | 17 ++++++++ include/rtc_media_stream_list.h | 25 ----------- include/rtc_rtp_capabilities.h | 33 +++++++++++++++ include/rtc_rtp_capabilities_lists.h | 44 -------------------- src/interop/rtc_media_stream_interop.cc | 34 +++++++++++++++ src/interop/rtc_media_stream_list_interop.cc | 38 ----------------- src/interop/rtc_rtp_capabilities_interop.cc | 11 +++-- src/rtc_media_stream_impl.cc | 15 +++++++ src/rtc_media_stream_impl.h | 6 +++ src/rtc_media_stream_list_impl.cc | 24 ----------- src/rtc_media_stream_list_impl.h | 17 -------- src/rtc_rtp_capabilities_impl.cc | 31 ++++++++++++++ src/rtc_rtp_capabilities_impl.h | 18 ++++++++ src/rtc_rtp_capabilities_lists_impl.cc | 40 ------------------ src/rtc_rtp_capabilities_lists_impl.h | 29 ------------- 17 files changed, 184 insertions(+), 227 deletions(-) delete mode 100644 include/rtc_media_stream_list.h delete mode 100644 include/rtc_rtp_capabilities_lists.h delete mode 100644 src/interop/rtc_media_stream_list_interop.cc delete mode 100644 src/rtc_media_stream_list_impl.cc delete mode 100644 src/rtc_media_stream_list_impl.h delete mode 100644 src/rtc_rtp_capabilities_lists_impl.cc delete mode 100644 src/rtc_rtp_capabilities_lists_impl.h diff --git a/BUILD.gn b/BUILD.gn index 1c57fd41e7..1bf71c4048 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -80,13 +80,11 @@ rtc_shared_library("libwebrtc") { "include/rtc_sdp_parse_error.h", "include/rtc_ice_candidate.h", "include/rtc_media_stream.h", - "include/rtc_media_stream_list.h", "include/rtc_media_track.h", "include/rtc_mediaconstraints.h", "include/rtc_peerconnection.h", "include/rtc_peerconnection_factory.h", "include/rtc_rtp_capabilities.h", - "include/rtc_rtp_capabilities_lists.h", "include/rtc_rtp_parameters.h", "include/rtc_rtp_receiver.h", "include/rtc_rtp_sender.h", @@ -126,8 +124,6 @@ rtc_shared_library("libwebrtc") { "src/rtc_ice_candidate_impl.h", "src/rtc_media_stream_impl.cc", "src/rtc_media_stream_impl.h", - "src/rtc_media_stream_list_impl.cc", - "src/rtc_media_stream_list_impl.h", "src/rtc_mediaconstraints_impl.cc", "src/rtc_mediaconstraints_impl.h", "src/rtc_peerconnection_factory_impl.cc", @@ -136,8 +132,6 @@ rtc_shared_library("libwebrtc") { "src/rtc_peerconnection_impl.h", "src/rtc_rtp_capabilities_impl.cc", "src/rtc_rtp_capabilities_impl.h", - "src/rtc_rtp_capabilities_lists_impl.cc", - "src/rtc_rtp_capabilities_lists_impl.h", "src/rtc_rtp_parameters_impl.cc", "src/rtc_rtp_parameters_impl.h", "src/rtc_rtp_receiver_impl.cc", @@ -181,7 +175,6 @@ rtc_shared_library("libwebrtc") { "src/interop/rtc_data_channel_interop.cc", "src/interop/rtc_ice_candidate_interop.cc", "src/interop/rtc_media_stream_interop.cc", - "src/interop/rtc_media_stream_list_interop.cc", "src/interop/rtc_rtp_capabilities_interop.cc", "src/interop/rtc_rtp_transceiver_interop.cc", "src/interop/rtc_peerconnection_interop.cc", diff --git a/include/interop_api.h b/include/interop_api.h index 700cecbbf3..b8e0c401bf 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -1972,6 +1972,28 @@ RTCRtpCapabilities_SetHeaderExtensions( rtcRtpHeaderExtensionCapabilityListHandle hHeaderExtensions ) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCRtpTransceiverInit interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Creates a new instance of the RTCRtpTransceiverInit object. + * + * @param pOutRetVal - Object handle + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +/* +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiverInit_Create( + rtcRtpTransceiverDirection direction, + const char** stream_ids, + rtcRtpEncodingParametersHandle hEncodings, + rtcRtpTransceiverInitHandle* pOutRetVal +) noexcept; +*/ + } // extern "C" #endif // LIB_WEBRTC_INTROP_API_HXX \ No newline at end of file diff --git a/include/rtc_media_stream.h b/include/rtc_media_stream.h index 17c04d1ba4..68661d9fcb 100644 --- a/include/rtc_media_stream.h +++ b/include/rtc_media_stream.h @@ -4,6 +4,7 @@ #include "rtc_audio_track.h" #include "rtc_types.h" #include "rtc_video_track.h" +#include "rtc_base_list.h" namespace libwebrtc { @@ -37,6 +38,22 @@ class RTCMediaStream : public RefCountInterface { ~RTCMediaStream() {} }; +/** + * class RTCMediaStreamList + */ +class RTCMediaStreamList : public RTCBaseList> { + public: + LIB_WEBRTC_API static scoped_refptr Create( + const vector>& source); + + protected: + RTCMediaStreamList(const vector>& source) + : RTCBaseList>(source) + {} + + ~RTCMediaStreamList() {} +}; + } // namespace libwebrtc #endif // LIB_WEBRTC_RTC_MEDIA_STREAM_HXX diff --git a/include/rtc_media_stream_list.h b/include/rtc_media_stream_list.h deleted file mode 100644 index 105e66afd6..0000000000 --- a/include/rtc_media_stream_list.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef LIB_WEBRTC_RTC_MEDIA_STREAM_LIST_HXX -#define LIB_WEBRTC_RTC_MEDIA_STREAM_LIST_HXX - -#include "rtc_types.h" -#include "rtc_base_list.h" -#include "rtc_media_stream.h" - -namespace libwebrtc { - -class RTCMediaStreamList : public RTCBaseList> { - public: - LIB_WEBRTC_API static scoped_refptr Create( - const vector>& source); - - protected: - RTCMediaStreamList(const vector>& source) - : RTCBaseList>(source) - {} - - ~RTCMediaStreamList() {} -}; - -} // namespace libwebrtc - -#endif // LIB_WEBRTC_RTC_MEDIA_STREAM_LIST_HXX diff --git a/include/rtc_rtp_capabilities.h b/include/rtc_rtp_capabilities.h index 39b49765fc..62ffbff86a 100644 --- a/include/rtc_rtp_capabilities.h +++ b/include/rtc_rtp_capabilities.h @@ -4,6 +4,7 @@ #include "base/refcount.h" #include "base/scoped_ref_ptr.h" #include "rtc_rtp_parameters.h" +#include "rtc_base_list.h" #include "rtc_types.h" namespace libwebrtc { @@ -26,6 +27,22 @@ class RTCRtpCodecCapability : public RefCountInterface { virtual ~RTCRtpCodecCapability() {} }; +/** + * class RTCRtpCodecCapabilityList + */ +class RTCRtpCodecCapabilityList : public RTCBaseList> { + public: + LIB_WEBRTC_API static scoped_refptr Create( + const vector>& source); + + protected: + RTCRtpCodecCapabilityList(const vector>& source) + : RTCBaseList>(source) + {} + + ~RTCRtpCodecCapabilityList() {} +}; + class RTCRtpHeaderExtensionCapability : public RefCountInterface { public: virtual const string uri() = 0; @@ -38,6 +55,22 @@ class RTCRtpHeaderExtensionCapability : public RefCountInterface { virtual void set_preferred_encrypt(bool value) = 0; }; +/** + * class RTCRtpHeaderExtensionCapabilityList + */ +class RTCRtpHeaderExtensionCapabilityList : public RTCBaseList> { + public: + LIB_WEBRTC_API static scoped_refptr Create( + const vector>& source); + + protected: + RTCRtpHeaderExtensionCapabilityList(const vector>& source) + : RTCBaseList>(source) + {} + + ~RTCRtpHeaderExtensionCapabilityList() {} +}; + class RTCRtpCapabilities : public RefCountInterface { public: virtual const vector> codecs() = 0; diff --git a/include/rtc_rtp_capabilities_lists.h b/include/rtc_rtp_capabilities_lists.h deleted file mode 100644 index ae4448451f..0000000000 --- a/include/rtc_rtp_capabilities_lists.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef LIB_WBBRTC_RTC_RTP_CAPABILITIES_LISTS_HXX -#define LIB_WBBRTC_RTC_RTP_CAPABILITIES_LISTS_HXX - -#include "rtc_types.h" -#include "rtc_base_list.h" -#include "rtc_rtp_capabilities.h" - -namespace libwebrtc { - -/** - * class RTCRtpCodecCapabilityList - */ -class RTCRtpCodecCapabilityList : public RTCBaseList> { - public: - LIB_WEBRTC_API static scoped_refptr Create( - const vector>& source); - - protected: - RTCRtpCodecCapabilityList(const vector>& source) - : RTCBaseList>(source) - {} - - ~RTCRtpCodecCapabilityList() {} -}; - -/** - * class RTCRtpHeaderExtensionCapabilityList - */ -class RTCRtpHeaderExtensionCapabilityList : public RTCBaseList> { - public: - LIB_WEBRTC_API static scoped_refptr Create( - const vector>& source); - - protected: - RTCRtpHeaderExtensionCapabilityList(const vector>& source) - : RTCBaseList>(source) - {} - - ~RTCRtpHeaderExtensionCapabilityList() {} -}; - -} // namespace libwebrtc - -#endif // LIB_WBBRTC_RTC_RTP_CAPABILITIES_LISTS_HXX diff --git a/src/interop/rtc_media_stream_interop.cc b/src/interop/rtc_media_stream_interop.cc index 42bec056c8..1cbfb8b68b 100644 --- a/src/interop/rtc_media_stream_interop.cc +++ b/src/interop/rtc_media_stream_interop.cc @@ -214,3 +214,37 @@ RTCMediaStream_GetId ( ? rtcResultU4::kBufferTooSmall : rtcResultU4::kSuccess; } + +int LIB_WEBRTC_CALL +RTCMediaStreamList_GetCount ( + rtcMediaStreamListHandle mediaStreamList +) noexcept +{ + CHECK_POINTER_EX(mediaStreamList, 0); + + scoped_refptr pMediaStreamList = static_cast(mediaStreamList); + return static_cast(pMediaStreamList->count()); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCMediaStreamList_GetItem ( + rtcMediaStreamListHandle mediaStreamList, + int index, + rtcMediaStreamHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + RESET_OUT_POINTER(pOutRetVal); + CHECK_NATIVE_HANDLE(mediaStreamList); + if (index < 0) { + return rtcResultU4::kOutOfRange; + } + + scoped_refptr pMediaStreamList = static_cast(mediaStreamList); + scoped_refptr pMediaStream = pMediaStreamList->item(static_cast(index)); + if (pMediaStream == nullptr) { + return rtcResultU4::kUnknownError; + } + *pOutRetVal = static_cast(pMediaStream.release()); + return rtcResultU4::kSuccess; +} diff --git a/src/interop/rtc_media_stream_list_interop.cc b/src/interop/rtc_media_stream_list_interop.cc deleted file mode 100644 index bc76fa8ebd..0000000000 --- a/src/interop/rtc_media_stream_list_interop.cc +++ /dev/null @@ -1,38 +0,0 @@ -#include "rtc_media_stream_list.h" -#include "interop_api.h" - -using namespace libwebrtc; - -int LIB_WEBRTC_CALL -RTCMediaStreamList_GetCount ( - rtcMediaStreamListHandle mediaStreamList -) noexcept -{ - CHECK_POINTER_EX(mediaStreamList, 0); - - scoped_refptr pMediaStreamList = static_cast(mediaStreamList); - return static_cast(pMediaStreamList->count()); -} - -rtcResultU4 LIB_WEBRTC_CALL -RTCMediaStreamList_GetItem ( - rtcMediaStreamListHandle mediaStreamList, - int index, - rtcMediaStreamHandle* pOutRetVal -) noexcept -{ - CHECK_OUT_POINTER(pOutRetVal); - RESET_OUT_POINTER(pOutRetVal); - CHECK_NATIVE_HANDLE(mediaStreamList); - if (index < 0) { - return rtcResultU4::kOutOfRange; - } - - scoped_refptr pMediaStreamList = static_cast(mediaStreamList); - scoped_refptr pMediaStream = pMediaStreamList->item(static_cast(index)); - if (pMediaStream == nullptr) { - return rtcResultU4::kUnknownError; - } - *pOutRetVal = static_cast(pMediaStream.release()); - return rtcResultU4::kSuccess; -} diff --git a/src/interop/rtc_rtp_capabilities_interop.cc b/src/interop/rtc_rtp_capabilities_interop.cc index 22fe3df9d9..934ecd9164 100644 --- a/src/interop/rtc_rtp_capabilities_interop.cc +++ b/src/interop/rtc_rtp_capabilities_interop.cc @@ -1,5 +1,4 @@ #include "rtc_rtp_capabilities.h" -#include "rtc_rtp_capabilities_lists.h" #include "interop_api.h" using namespace libwebrtc; @@ -176,9 +175,12 @@ RTCRtpCodecCapabilityList_GetItem ( { CHECK_OUT_POINTER(pOutRetVal); CHECK_NATIVE_HANDLE(handle); + if (index < 0) { + return rtcResultU4::kOutOfRange; + } scoped_refptr pList = static_cast(handle); - if (index < 0 || static_cast(index) >= pList->count()) { + if (static_cast(index) >= pList->count()) { return rtcResultU4::kOutOfRange; } scoped_refptr pItem = pList->item(static_cast(index)); @@ -309,10 +311,13 @@ RTCRtpHeaderExtensionCapabilityList_GetItem ( { CHECK_OUT_POINTER(pOutRetVal); CHECK_NATIVE_HANDLE(handle); + if (index < 0) { + return rtcResultU4::kOutOfRange; + } scoped_refptr pList = static_cast(handle); - if (index < 0 || static_cast(index) >= pList->count()) { + if (static_cast(index) >= pList->count()) { return rtcResultU4::kOutOfRange; } scoped_refptr pItem = pList->item(static_cast(index)); diff --git a/src/rtc_media_stream_impl.cc b/src/rtc_media_stream_impl.cc index f5d6072a4b..7464262113 100644 --- a/src/rtc_media_stream_impl.cc +++ b/src/rtc_media_stream_impl.cc @@ -159,4 +159,19 @@ void MediaStreamImpl::OnChanged() { video_tracks_ = video_tracks; } +scoped_refptr RTCMediaStreamList::Create( + const vector>& source) { + return new RefCountedObject(source); +} + +RTCMediaStreamListImpl::RTCMediaStreamListImpl( + const vector>& source) + : RTCMediaStreamList(source) { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor "; +} + +RTCMediaStreamListImpl::~RTCMediaStreamListImpl() { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; +} + } // namespace libwebrtc diff --git a/src/rtc_media_stream_impl.h b/src/rtc_media_stream_impl.h index 011efc90af..e66b10e7b0 100644 --- a/src/rtc_media_stream_impl.h +++ b/src/rtc_media_stream_impl.h @@ -234,5 +234,11 @@ class MediaStreamImpl : public RTCMediaStream, string label_, id_; }; +class RTCMediaStreamListImpl : public RTCMediaStreamList { + public: + RTCMediaStreamListImpl(const vector>& source); + ~RTCMediaStreamListImpl(); +}; + } // namespace libwebrtc #endif //! LIB_WEBRTC_MEDIA_STREAM_IMPL_HXX \ No newline at end of file diff --git a/src/rtc_media_stream_list_impl.cc b/src/rtc_media_stream_list_impl.cc deleted file mode 100644 index 73d5840ffc..0000000000 --- a/src/rtc_media_stream_list_impl.cc +++ /dev/null @@ -1,24 +0,0 @@ -#include "rtc_media_stream_list_impl.h" - -#include "rtc_base/logging.h" -#include "rtc_media_stream.h" -#include "rtc_types.h" - -namespace libwebrtc { - -scoped_refptr RTCMediaStreamList::Create( - const vector>& source) { - return new RefCountedObject(source); -} - -RTCMediaStreamListImpl::RTCMediaStreamListImpl( - const vector>& source) - : RTCMediaStreamList(source) { - RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor "; -} - -RTCMediaStreamListImpl::~RTCMediaStreamListImpl() { - RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; -} - -} // namespace libwebrtc diff --git a/src/rtc_media_stream_list_impl.h b/src/rtc_media_stream_list_impl.h deleted file mode 100644 index f2ec78e9f2..0000000000 --- a/src/rtc_media_stream_list_impl.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef LIB_WEBRTC_MEDIA_STREAM_LIST_IMPL_HXX -#define LIB_WEBRTC_MEDIA_STREAM_LIST_IMPL_HXX - -#include "rtc_media_stream_list.h" -#include "rtc_media_stream.h" - -namespace libwebrtc { - -class RTCMediaStreamListImpl : public RTCMediaStreamList { - public: - RTCMediaStreamListImpl(const vector>& source); - ~RTCMediaStreamListImpl(); -}; - -} // namespace libwebrtc - -#endif //! LIB_WEBRTC_MEDIA_STREAM_LIST_IMPL_HXX \ No newline at end of file diff --git a/src/rtc_rtp_capabilities_impl.cc b/src/rtc_rtp_capabilities_impl.cc index ce502f609d..bf4e0b0282 100644 --- a/src/rtc_rtp_capabilities_impl.cc +++ b/src/rtc_rtp_capabilities_impl.cc @@ -1,4 +1,5 @@ #include "rtc_rtp_capabilities_impl.h" +#include "rtc_base/logging.h" namespace libwebrtc { @@ -149,6 +150,21 @@ webrtc::RtpCodecCapability RTCRtpCodecCapabilityImpl::rtp_codec_capability() { return rtp_codec_capability_; } +scoped_refptr RTCRtpCodecCapabilityList::Create( + const vector>& source) { + return new RefCountedObject(source); +} + +RTCRtpCodecCapabilityListImpl::RTCRtpCodecCapabilityListImpl( + const vector>& source) + : RTCRtpCodecCapabilityList(source) { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor "; +} + +RTCRtpCodecCapabilityListImpl::~RTCRtpCodecCapabilityListImpl() { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; +} + RTCRtpHeaderExtensionCapabilityImpl::RTCRtpHeaderExtensionCapabilityImpl( webrtc::RtpHeaderExtensionCapability rtp_header_extension_capability) : rtp_header_extension_capability_(rtp_header_extension_capability) {} @@ -181,4 +197,19 @@ void RTCRtpHeaderExtensionCapabilityImpl::set_preferred_encrypt(bool value) { rtp_header_extension_capability_.preferred_encrypt = value; } +scoped_refptr RTCRtpHeaderExtensionCapabilityList::Create( + const vector>& source) { + return new RefCountedObject(source); +} + +RTCRtpHeaderExtensionCapabilityListImpl::RTCRtpHeaderExtensionCapabilityListImpl( + const vector>& source) + : RTCRtpHeaderExtensionCapabilityList(source) { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor "; +} + +RTCRtpHeaderExtensionCapabilityListImpl::~RTCRtpHeaderExtensionCapabilityListImpl() { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; +} + } // namespace libwebrtc diff --git a/src/rtc_rtp_capabilities_impl.h b/src/rtc_rtp_capabilities_impl.h index 52c54ffbeb..4b2d4b103b 100644 --- a/src/rtc_rtp_capabilities_impl.h +++ b/src/rtc_rtp_capabilities_impl.h @@ -44,6 +44,15 @@ class RTCRtpCodecCapabilityImpl : public RTCRtpCodecCapability { webrtc::RtpCodecCapability rtp_codec_capability_; }; +/** + * class RTCRtpCodecCapabilityListImpl + */ +class RTCRtpCodecCapabilityListImpl : public RTCRtpCodecCapabilityList { + public: + RTCRtpCodecCapabilityListImpl(const vector>& source); + ~RTCRtpCodecCapabilityListImpl(); +}; + class RTCRtpHeaderExtensionCapabilityImpl : public RTCRtpHeaderExtensionCapability { public: @@ -64,6 +73,15 @@ class RTCRtpHeaderExtensionCapabilityImpl webrtc::RtpHeaderExtensionCapability rtp_header_extension_capability_; }; +/** + * class RTCRtpHeaderExtensionCapabilityListImpl + */ +class RTCRtpHeaderExtensionCapabilityListImpl : public RTCRtpHeaderExtensionCapabilityList { + public: + RTCRtpHeaderExtensionCapabilityListImpl(const vector>& source); + ~RTCRtpHeaderExtensionCapabilityListImpl(); +}; + } // namespace libwebrtc #endif // LIB_WBBRTC_RTC_RTP_CAPABILITIES_IMPL_HXX diff --git a/src/rtc_rtp_capabilities_lists_impl.cc b/src/rtc_rtp_capabilities_lists_impl.cc deleted file mode 100644 index 76ba1198dc..0000000000 --- a/src/rtc_rtp_capabilities_lists_impl.cc +++ /dev/null @@ -1,40 +0,0 @@ -#include "rtc_rtp_capabilities_lists_impl.h" - -#include "rtc_base/logging.h" -#include "rtc_rtp_capabilities.h" -#include "rtc_types.h" - -namespace libwebrtc { - -scoped_refptr RTCRtpCodecCapabilityList::Create( - const vector>& source) { - return new RefCountedObject(source); -} - -RTCRtpCodecCapabilityListImpl::RTCRtpCodecCapabilityListImpl( - const vector>& source) - : RTCRtpCodecCapabilityList(source) { - RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor "; -} - -RTCRtpCodecCapabilityListImpl::~RTCRtpCodecCapabilityListImpl() { - RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; -} - - -scoped_refptr RTCRtpHeaderExtensionCapabilityList::Create( - const vector>& source) { - return new RefCountedObject(source); -} - -RTCRtpHeaderExtensionCapabilityListImpl::RTCRtpHeaderExtensionCapabilityListImpl( - const vector>& source) - : RTCRtpHeaderExtensionCapabilityList(source) { - RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor "; -} - -RTCRtpHeaderExtensionCapabilityListImpl::~RTCRtpHeaderExtensionCapabilityListImpl() { - RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; -} - -} // namespace libwebrtc diff --git a/src/rtc_rtp_capabilities_lists_impl.h b/src/rtc_rtp_capabilities_lists_impl.h deleted file mode 100644 index 21952fc2a2..0000000000 --- a/src/rtc_rtp_capabilities_lists_impl.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef LIB_WBBRTC_RTC_RTP_CAPABILITIES_LISTS_IMPL_HXX -#define LIB_WBBRTC_RTC_RTP_CAPABILITIES_LISTS_IMPL_HXX - -#include "rtc_rtp_capabilities.h" -#include "rtc_rtp_capabilities_lists.h" - -namespace libwebrtc { - -/** - * class RTCRtpCodecCapabilityListImpl - */ -class RTCRtpCodecCapabilityListImpl : public RTCRtpCodecCapabilityList { - public: - RTCRtpCodecCapabilityListImpl(const vector>& source); - ~RTCRtpCodecCapabilityListImpl(); -}; - -/** - * class RTCRtpHeaderExtensionCapabilityListImpl - */ -class RTCRtpHeaderExtensionCapabilityListImpl : public RTCRtpHeaderExtensionCapabilityList { - public: - RTCRtpHeaderExtensionCapabilityListImpl(const vector>& source); - ~RTCRtpHeaderExtensionCapabilityListImpl(); -}; - -} // namespace libwebrtc - -#endif //! LIB_WBBRTC_RTC_RTP_CAPABILITIES_LISTS_IMPL_HXX \ No newline at end of file From c194998e9623722112c3c863ae32d45e448b5ca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Sun, 29 Dec 2024 03:34:41 +0300 Subject: [PATCH 44/69] Added rtc_rtp_parameters_interop.cc --- BUILD.gn | 2 + include/interop_api.h | 753 ++++++++++++++++- include/interop_macros.h | 108 +++ include/rtc_rtp_parameters.h | 82 ++ src/interop/rtc_audio_device_interop.cc | 10 +- src/interop/rtc_data_channel_interop.cc | 30 +- src/interop/rtc_ice_candidate_interop.cc | 34 +- src/interop/rtc_media_stream_interop.cc | 50 +- src/interop/rtc_media_track_interop.cc | 28 +- src/interop/rtc_rtp_capabilities_interop.cc | 197 +---- src/interop/rtc_rtp_parameters_interop.cc | 853 ++++++++++++++++++++ src/interop/rtc_sdp_parse_error_interop.cc | 40 +- src/interop/rtc_video_frame_interop.cc | 14 +- src/rtc_rtp_parameters_impl.cc | 77 ++ src/rtc_rtp_parameters_impl.h | 45 ++ 15 files changed, 1945 insertions(+), 378 deletions(-) create mode 100644 include/interop_macros.h create mode 100644 src/interop/rtc_rtp_parameters_interop.cc diff --git a/BUILD.gn b/BUILD.gn index 1bf71c4048..233b875bca 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -159,6 +159,7 @@ rtc_shared_library("libwebrtc") { # for interop methods if (is_win && libwebrtc_interop) { sources += [ + "include/interop_macros.h", "include/interop_api.h", "src/interop/ref_counted_object_interop.cc", "src/interop/libwebrtc_interop.cc", @@ -176,6 +177,7 @@ rtc_shared_library("libwebrtc") { "src/interop/rtc_ice_candidate_interop.cc", "src/interop/rtc_media_stream_interop.cc", "src/interop/rtc_rtp_capabilities_interop.cc", + "src/interop/rtc_rtp_parameters_interop.cc", "src/interop/rtc_rtp_transceiver_interop.cc", "src/interop/rtc_peerconnection_interop.cc", ] diff --git a/include/interop_api.h b/include/interop_api.h index b8e0c401bf..8f0ff0fced 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -10,29 +10,7 @@ #endif #include "rtc_types.h" - -#define CHECK_POINTER_EX(p, r) \ - if ((p) == nullptr) { \ - return (r); \ - } -#define CHECK_POINTER(p) CHECK_POINTER_EX(p, rtcResultU4::kInvalidPointer) -#define RESET_OUT_POINTER_EX(p, v) \ - if ((p) != nullptr) { \ - *(p) = (v); \ - } -#define RESET_OUT_POINTER(p) RESET_OUT_POINTER_EX(p, nullptr) -#define CHECK_OUT_POINTER(p) \ - if ((p) != nullptr) { \ - *(p) = nullptr; \ - } else { \ - return rtcResultU4::kInvalidPointer; \ - } -#define CHECK_NATIVE_HANDLE(h) \ - CHECK_POINTER_EX(h, rtcResultU4::kInvalidNativeHandle) -#define ZERO_MEMORY(p, sz) \ - if (static_cast(p) && static_cast(sz) > 0) { \ - memset(static_cast(p), 0, static_cast(sz)); \ - } +#include "interop_macros.h" extern "C" { @@ -51,7 +29,7 @@ using rtcDesktopType = libwebrtc::DesktopType; using rtcTimestamp = long long; /// 32-bit boolean for interop API. -enum class rtcBool32 : int { kTrue = -1, kFalse = 0 }; +enum class rtcBool32 : int { kFalse = 0, kTrue = 1 }; enum class rtcKeyRingSize : int { kMin = 1, kDefault = 16, kMax = 256 }; @@ -485,21 +463,36 @@ using rtcRtpCapabilitiesHandle = rtcRefCountedObjectHandle; /// Opaque handle to a native RTCRtcpFeedback interop object. using rtcRtcpFeedbackHandle = rtcRefCountedObjectHandle; +/// Opaque handle to a native RTCRtcpFeedbackList interop object. +using rtcRtcpFeedbackListHandle = rtcRefCountedObjectHandle; + /// Opaque handle to a native RTCRtpExtension interop object. using rtcRtpExtensionHandle = rtcRefCountedObjectHandle; +/// Opaque handle to a native RTCRtpExtensionList interop object. +using rtcRtpExtensionListHandle = rtcRefCountedObjectHandle; + /// Opaque handle to a native RtpFecParameters interop object. using rtcRtpFecParametersHandle = rtcRefCountedObjectHandle; /// Opaque handle to a native RTCRtpCodecParameters interop object. using rtcRtpCodecParametersHandle = rtcRefCountedObjectHandle; +/// Opaque handle to a native RTCRtpCodecParametersList interop object. +using rtcRtpCodecParametersListHandle = rtcRefCountedObjectHandle; + /// Opaque handle to a native RTCRtcpParameters interop object. using rtcRtcpParametersHandle = rtcRefCountedObjectHandle; +/// Opaque handle to a native RTCRtcpParametersList interop object. +using rtcRtcpParametersListHandle = rtcRefCountedObjectHandle; + /// Opaque handle to a native RTCRtpEncodingParameters interop object. using rtcRtpEncodingParametersHandle = rtcRefCountedObjectHandle; +/// Opaque handle to a native RTCRtpEncodingParametersList interop object. +using rtcRtpEncodingParametersListHandle = rtcRefCountedObjectHandle; + /// Opaque handle to a native RTCRtpParameters interop object. using rtcRtpParametersHandle = rtcRefCountedObjectHandle; @@ -1972,6 +1965,718 @@ RTCRtpCapabilities_SetHeaderExtensions( rtcRtpHeaderExtensionCapabilityListHandle hHeaderExtensions ) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCRtcpFeedback interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Returns the RtcpFeedback type. + * + * @param handle - Object handle + * @param pOutRetVal - The value to return. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpFeedback_GetType( + rtcRtcpFeedbackHandle handle, + rtcRtcpFeedbackType* pOutRetVal +) noexcept; + +/** + * Sets the RtcpFeedback type. + * + * @param handle - Object handle + * @param value - The new value to set. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpFeedback_SetType( + rtcRtcpFeedbackHandle handle, + rtcRtcpFeedbackType value +) noexcept; + +/** + * Returns the RtcpFeedback message type. + * + * @param handle - Object handle + * @param pOutRetVal - The value to return. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpFeedback_GetMessageType( + rtcRtcpFeedbackHandle handle, + rtcRtcpFeedbackMessageType* pOutRetVal +) noexcept; + +/** + * Sets the RtcpFeedback message type. + * + * @param handle - Object handle + * @param value - The new value to set. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpFeedback_SetMessageType( + rtcRtcpFeedbackHandle handle, + rtcRtcpFeedbackMessageType value +) noexcept; + +/* + * ---------------------------------------------------------------------- + * RTCRtcpFeedbackList interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Returns the number of RTCRtcpFeedbackList. + * + * @param handle - List handle + * @return int - The number of items + */ +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RTCRtcpFeedbackList_GetCount ( + rtcRtcpFeedbackListHandle handle +) noexcept; + +/** + * Returns the Rtcp Feedback capability whose index is specified. + * + * @param handle - List handle + * @param index - Item index + * @param pOutRetVal - Item handle + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpFeedbackList_GetItem ( + rtcRtcpFeedbackListHandle handle, + int index, + rtcRtcpFeedbackHandle* pOutRetVal +) noexcept; + +/* + * ---------------------------------------------------------------------- + * RTCRtpExtension interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Returns the text value for RtpExtension. + * + * @param handle - Object handle + * @param value - Return string buffer address + * @param sz_value - Size of value + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpExtension_ToString ( + rtcRtpExtensionHandle handle, + char* value, + int sz_value +) noexcept; + +/** + * Returns the uri for RtpExtension. + * + * @param handle - Object handle + * @param value - Return string buffer address + * @param sz_value - Size of value + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpExtension_GetUri ( + rtcRtpExtensionHandle handle, + char* value, + int sz_value +) noexcept; + +/** + * Sets the RtpExtension uri value. + * + * @param handle - Object handle + * @param value - The new value to set. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpExtension_SetUri ( + rtcRtpExtensionHandle handle, + const char* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpExtension_GetId ( + rtcRtpExtensionHandle handle, + int* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpExtension_SetId ( + rtcRtpExtensionHandle handle, + int value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpExtension_GetEncrypt ( + rtcRtpExtensionHandle handle, + rtcBool32* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpExtension_SetEncrypt ( + rtcRtpExtensionHandle handle, + rtcBool32 value +) noexcept; + +/* + * ---------------------------------------------------------------------- + * RTCRtpExtensionList interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Returns the number of RTCRtpExtensionList. + * + * @param handle - List handle + * @return int - The number of items + */ +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RTCRtpExtensionList_GetCount ( + rtcRtpExtensionListHandle handle +) noexcept; + +/** + * Returns the rtp extension whose index is specified. + * + * @param handle - List handle + * @param index - Item index + * @param pOutRetVal - Item handle + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpExtensionList_GetItem ( + rtcRtpExtensionListHandle handle, + int index, + rtcRtpExtensionHandle* pOutRetVal +) noexcept; + +/* + * ---------------------------------------------------------------------- + * RTCRtpCodecParameters interop methods + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_GetMimeType ( + rtcRtpCodecParametersHandle handle, + char* value, + int sz_value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_GetName ( + rtcRtpCodecParametersHandle handle, + char* value, + int sz_value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_SetName ( + rtcRtpCodecParametersHandle handle, + const char* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_GetKind ( + rtcRtpCodecParametersHandle handle, + rtcMediaType* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_SetKind ( + rtcRtpCodecParametersHandle handle, + rtcMediaType value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_GetPayloadType ( + rtcRtpCodecParametersHandle handle, + int* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_SetPayloadType ( + rtcRtpCodecParametersHandle handle, + int value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_GetClockRate ( + rtcRtpCodecParametersHandle handle, + int* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_SetClockRate ( + rtcRtpCodecParametersHandle handle, + int value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_GetNumChannels ( + rtcRtpCodecParametersHandle handle, + int* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_SetNumChannels ( + rtcRtpCodecParametersHandle handle, + int value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_GetMaxPTime ( + rtcRtpCodecParametersHandle handle, + int* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_SetMaxPTime ( + rtcRtpCodecParametersHandle handle, + int value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_GetPTime ( + rtcRtpCodecParametersHandle handle, + int* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_SetPTime ( + rtcRtpCodecParametersHandle handle, + int value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_GetRtcpFeedBacks ( + rtcRtpCodecParametersHandle handle, + rtcRtcpFeedbackListHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_SetRtcpFeedBacks ( + rtcRtpCodecParametersHandle handle, + rtcRtcpFeedbackListHandle value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_GetParameters ( + rtcRtpCodecParametersHandle handle, + rtcObjectHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_SetParameters ( + rtcRtpCodecParametersHandle handle, + rtcObjectHandle value +) noexcept; + +/* + * ---------------------------------------------------------------------- + * RTCRtpCodecParametersList interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Returns the number of RTCRtpCodecParametersList. + * + * @param handle - List handle + * @return int - The number of items + */ +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RTCRtpCodecParametersList_GetCount ( + rtcRtpCodecParametersListHandle handle +) noexcept; + +/** + * Returns the rtp codec parameters index is specified. + * + * @param handle - List handle + * @param index - Item index + * @param pOutRetVal - Item handle + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParametersList_GetItem ( + rtcRtpCodecParametersListHandle handle, + int index, + rtcRtpCodecParametersHandle* pOutRetVal +) noexcept; + +/* + * ---------------------------------------------------------------------- + * RTCRtcpParameters interop methods + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpParameters_GetSSRC ( + rtcRtcpParametersHandle handle, + unsigned int* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpParameters_SetSSRC ( + rtcRtcpParametersHandle handle, + unsigned int value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpParameters_GetCName ( + rtcRtcpParametersHandle handle, + char* value, + int sz_value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpParameters_SetCName ( + rtcRtcpParametersHandle handle, + const char* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpParameters_GetReducedSize ( + rtcRtcpParametersHandle handle, + rtcBool32* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpParameters_SetReducedSize ( + rtcRtcpParametersHandle handle, + rtcBool32 value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpParameters_GetMux ( + rtcRtcpParametersHandle handle, + rtcBool32* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpParameters_SetMux ( + rtcRtcpParametersHandle handle, + rtcBool32 value +) noexcept; + +/* + * ---------------------------------------------------------------------- + * RTCRtcpParametersList interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Returns the number of RTCRtcpParametersList. + * + * @param handle - List handle + * @return int - The number of items + */ +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RTCRtcpParametersList_GetCount ( + rtcRtcpParametersListHandle handle +) noexcept; + +/** + * Returns the rtcp parameters index is specified. + * + * @param handle - List handle + * @param index - Item index + * @param pOutRetVal - Item handle + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpParametersList_GetItem ( + rtcRtcpParametersListHandle handle, + int index, + rtcRtcpParametersHandle* pOutRetVal +) noexcept; + +/* + * ---------------------------------------------------------------------- + * RTCRtpEncodingParameters interop methods + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetSSRC ( + rtcRtpEncodingParametersHandle handle, + unsigned int* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetSSRC ( + rtcRtpEncodingParametersHandle handle, + unsigned int value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetBitratePriority ( + rtcRtpEncodingParametersHandle handle, + double* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetBitratePriority ( + rtcRtpEncodingParametersHandle handle, + double value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetNetworkPriority ( + rtcRtpEncodingParametersHandle handle, + rtcNetworkPriority* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetNetworkPriority ( + rtcRtpEncodingParametersHandle handle, + rtcNetworkPriority value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetMaxBitrateBps ( + rtcRtpEncodingParametersHandle handle, + int* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetMaxBitrateBps ( + rtcRtpEncodingParametersHandle handle, + int value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetMinBitrateBps ( + rtcRtpEncodingParametersHandle handle, + int* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetMinBitrateBps ( + rtcRtpEncodingParametersHandle handle, + int value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetMaxFramerate ( + rtcRtpEncodingParametersHandle handle, + double* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetMaxFramerate ( + rtcRtpEncodingParametersHandle handle, + double value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetNumTemporalLayers ( + rtcRtpEncodingParametersHandle handle, + int* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetNumTemporalLayers ( + rtcRtpEncodingParametersHandle handle, + int value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetScaleResolutionDownBy ( + rtcRtpEncodingParametersHandle handle, + double* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetScaleResolutionDownBy ( + rtcRtpEncodingParametersHandle handle, + double value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetScalabilityMode ( + rtcRtpEncodingParametersHandle handle, + char* value, + int sz_value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetScalabilityMode ( + rtcRtpEncodingParametersHandle handle, + const char* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetActive ( + rtcRtpEncodingParametersHandle handle, + rtcBool32* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetActive ( + rtcRtpEncodingParametersHandle handle, + rtcBool32 value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetRid ( + rtcRtpEncodingParametersHandle handle, + char* value, + int sz_value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetRid ( + rtcRtpEncodingParametersHandle handle, + const char* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetAdaptivePTime( + rtcRtpEncodingParametersHandle handle, + rtcBool32* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetAdaptivePTime ( + rtcRtpEncodingParametersHandle handle, + rtcBool32 value +) noexcept; + +/* + * ---------------------------------------------------------------------- + * RTCRtpEncodingParametersList interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Returns the number of RTCRtpEncodingParametersList. + * + * @param handle - List handle + * @return int - The number of items + */ +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RTCRtpEncodingParametersList_GetCount ( + rtcRtpEncodingParametersListHandle handle +) noexcept; + +/** + * Returns the rtp encoding parameters index is specified. + * + * @param handle - List handle + * @param index - Item index + * @param pOutRetVal - Item handle + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParametersList_GetItem ( + rtcRtpEncodingParametersListHandle handle, + int index, + rtcRtpEncodingParametersHandle* pOutRetVal +) noexcept; + +/* + * ---------------------------------------------------------------------- + * RTCRtpParameters interop methods + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_GetTransactionId ( + rtcRtpParametersHandle handle, + char* value, + int sz_value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_SetTransactionId ( + rtcRtpParametersHandle handle, + const char* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_GetMid ( + rtcRtpParametersHandle handle, + char* value, + int sz_value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_SetMid ( + rtcRtpParametersHandle handle, + const char* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_GetCodecs ( + rtcRtpParametersHandle handle, + rtcRtpCodecParametersListHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_SetCodecs ( + rtcRtpParametersHandle handle, + rtcRtpCodecParametersListHandle value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_GetHeaderExtensions ( + rtcRtpParametersHandle handle, + rtcRtpExtensionListHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_SetHeaderExtensions ( + rtcRtpParametersHandle handle, + rtcRtpExtensionListHandle value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_GetEncodings ( + rtcRtpParametersHandle handle, + rtcRtpEncodingParametersListHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_SetEncodings ( + rtcRtpParametersHandle handle, + rtcRtpEncodingParametersListHandle value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_GetRtcpParameters ( + rtcRtpParametersHandle handle, + rtcRtcpParametersHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_SetRtcpParameters ( + rtcRtpParametersHandle handle, + rtcRtcpParametersHandle value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_GetDegradationPreference ( + rtcRtpParametersHandle handle, + rtcDegradationPreference* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_SetDegradationPreference ( + rtcRtpParametersHandle handle, + rtcDegradationPreference value +) noexcept; + /* * ---------------------------------------------------------------------- * RTCRtpTransceiverInit interop methods diff --git a/include/interop_macros.h b/include/interop_macros.h new file mode 100644 index 0000000000..7ab1989807 --- /dev/null +++ b/include/interop_macros.h @@ -0,0 +1,108 @@ +#ifndef LIB_WEBRTC_INTROP_MACROS_HXX +#define LIB_WEBRTC_INTROP_MACROS_HXX + +#define CHECK_POINTER_EX(p, r) \ + if ((p) == nullptr) { \ + return (r); \ + } + +#define CHECK_POINTER(p) CHECK_POINTER_EX(p, rtcResultU4::kInvalidPointer) + +#define RESET_OUT_POINTER_EX(p, v) \ + if ((p) != nullptr) { \ + *(p) = (v); \ + } + +#define RESET_OUT_POINTER(p) RESET_OUT_POINTER_EX(p, nullptr) + +#define CHECK_OUT_POINTER(p) \ + if ((p) != nullptr) { \ + *(p) = nullptr; \ + } else { \ + return rtcResultU4::kInvalidPointer; \ + } + +#define CHECK_NATIVE_HANDLE(h) \ + CHECK_POINTER_EX(h, rtcResultU4::kInvalidNativeHandle) + +#define ZERO_MEMORY(p, sz) \ + if (static_cast(p) && static_cast(sz) > 0) { \ + memset(static_cast(p), 0, static_cast(sz)); \ + } + +#define CHECK_AND_ZERO_MEMORY(p, sz) \ + CHECK_POINTER(p); \ + if (static_cast(sz) < 1) { \ + return rtcResultU4::kBufferTooSmall; \ + } \ + ZERO_MEMORY(p, sz) + +#define DECLARE_GET_STRING(handle, value, sz_value, class_name, fun_name) \ + CHECK_NATIVE_HANDLE(handle); \ + CHECK_AND_ZERO_MEMORY(value, sz_value); \ + scoped_refptr p = static_cast(handle); \ + string strValue = p->fun_name(); \ + size_t len = strValue.copy_to(value, static_cast(sz_value)); \ + return strValue.size() > len ? rtcResultU4::kBufferTooSmall \ + : rtcResultU4::kSuccess; + +#define DECLARE_GET_VALUE(handle, value, value_type_name, class_name, \ + fun_name) \ + CHECK_POINTER(value); \ + *(value) = static_cast(0); \ + CHECK_NATIVE_HANDLE(handle); \ + scoped_refptr p = static_cast(handle); \ + *(value) = static_cast(p->fun_name()); \ + return rtcResultU4::kSuccess; + +#define DECLARE_SET_VALUE(handle, value, value_type_name, class_name, \ + fun_name) \ + CHECK_NATIVE_HANDLE(handle); \ + scoped_refptr p = static_cast(handle); \ + p->fun_name(static_cast(value)); \ + return rtcResultU4::kSuccess; + +#define DECLARE_GET_LIST_HANDLE(handle, value, value_type_name, \ + owner_class_name, list_class_name, fun_name) \ + CHECK_OUT_POINTER(value); \ + CHECK_NATIVE_HANDLE(handle); \ + scoped_refptr p = static_cast(handle); \ + scoped_refptr pList = \ + list_class_name::Create(p->fun_name()); \ + if (pList == nullptr) { \ + return rtcResultU4::kUnknownError; \ + } \ + *pOutRetVal = static_cast(pList.release()); \ + return rtcResultU4::kSuccess; + +#define DECLARE_SET_LIST_HANDLE(handle, value, owner_class_name, \ + list_class_name, fun_name) \ + CHECK_NATIVE_HANDLE(handle); \ + scoped_refptr pOwner = \ + static_cast(handle); \ + scoped_refptr pList = static_cast(value); \ + pOwner->fun_name(pList->to_vector()); \ + return rtcResultU4::kSuccess; + +#define DECLARE_LIST_GET_COUNT(handle, list_type_name) \ + CHECK_POINTER_EX(handle, 0); \ + scoped_refptr pList = static_cast(handle); \ + return static_cast(pList->count()); + +#define DECLARE_LIST_GET_ITEM(handle, index, out_val, out_val_type_name, \ + list_type_name, item_type_name) \ + CHECK_OUT_POINTER(out_val); \ + CHECK_NATIVE_HANDLE(handle); \ + if (static_cast(index) < 1) { \ + return rtcResultU4::kOutOfRange; \ + } \ + scoped_refptr pList = static_cast(handle); \ + if (static_cast(index) >= pList->count()) { \ + return rtcResultU4::kOutOfRange; \ + } \ + scoped_refptr pItem = \ + pList->item(static_cast(index)); \ + *(out_val) = static_cast(pItem.release()); \ + return rtcResultU4::kSuccess; + +#endif // LIB_WEBRTC_INTROP_MACROS_HXX diff --git a/include/rtc_rtp_parameters.h b/include/rtc_rtp_parameters.h index 3ef87155d5..37171609a3 100644 --- a/include/rtc_rtp_parameters.h +++ b/include/rtc_rtp_parameters.h @@ -4,6 +4,7 @@ #include "base/refcount.h" #include "base/scoped_ref_ptr.h" #include "rtc_types.h" +#include "rtc_base_list.h" namespace libwebrtc { @@ -48,6 +49,7 @@ enum class RTCDegradationPreference { }; class RTCRtcpFeedback : public RefCountInterface { + public: virtual RTCRtcpFeedbackType type() = 0; virtual void set_type(RTCRtcpFeedbackType value) = 0; @@ -58,6 +60,22 @@ class RTCRtcpFeedback : public RefCountInterface { virtual bool operator!=(scoped_refptr o) = 0; }; +/** + * class RTCRtcpFeedbackList + */ +class RTCRtcpFeedbackList : public RTCBaseList> { + public: + LIB_WEBRTC_API static scoped_refptr Create( + const vector>& source); + + protected: + RTCRtcpFeedbackList(const vector>& source) + : RTCBaseList>(source) + {} + + ~RTCRtcpFeedbackList() {} +}; + class RTCRtpExtension : public RefCountInterface { public: enum RTCFilter { @@ -79,6 +97,22 @@ class RTCRtpExtension : public RefCountInterface { virtual void set_encrypt(bool value) = 0; }; +/** + * class RTCRtpExtensionList + */ +class RTCRtpExtensionList : public RTCBaseList> { + public: + LIB_WEBRTC_API static scoped_refptr Create( + const vector>& source); + + protected: + RTCRtpExtensionList(const vector>& source) + : RTCBaseList>(source) + {} + + ~RTCRtpExtensionList() {} +}; + class RtpFecParameters : public RefCountInterface { virtual uint32_t ssrc() = 0; virtual void set_ssrc(uint32_t value) = 0; @@ -138,6 +172,22 @@ class RTCRtpCodecParameters : public RefCountInterface { virtual ~RTCRtpCodecParameters() {} }; +/** + * class RTCRtpCodecParametersList + */ +class RTCRtpCodecParametersList : public RTCBaseList> { + public: + LIB_WEBRTC_API static scoped_refptr Create( + const vector>& source); + + protected: + RTCRtpCodecParametersList(const vector>& source) + : RTCBaseList>(source) + {} + + ~RTCRtpCodecParametersList() {} +}; + class RTCRtcpParameters : public RefCountInterface { public: virtual uint32_t ssrc() = 0; @@ -156,6 +206,22 @@ class RTCRtcpParameters : public RefCountInterface { virtual bool operator!=(scoped_refptr o) const = 0; }; +/** + * class RTCRtcpParametersList + */ +class RTCRtcpParametersList : public RTCBaseList> { + public: + LIB_WEBRTC_API static scoped_refptr Create( + const vector>& source); + + protected: + RTCRtcpParametersList(const vector>& source) + : RTCBaseList>(source) + {} + + ~RTCRtcpParametersList() {} +}; + enum class RTCPriority { kVeryLow, kLow, @@ -207,6 +273,22 @@ class RTCRtpEncodingParameters : public RefCountInterface { virtual bool operator!=(scoped_refptr o) const = 0; }; +/** + * class RTCRtpEncodingParametersList + */ +class RTCRtpEncodingParametersList : public RTCBaseList> { + public: + LIB_WEBRTC_API static scoped_refptr Create( + const vector>& source); + + protected: + RTCRtpEncodingParametersList(const vector>& source) + : RTCBaseList>(source) + {} + + ~RTCRtpEncodingParametersList() {} +}; + struct RTCRtpParameters : public RefCountInterface { public: // static scoped_refptr Create(); diff --git a/src/interop/rtc_audio_device_interop.cc b/src/interop/rtc_audio_device_interop.cc index 84716a5493..049eda3c32 100644 --- a/src/interop/rtc_audio_device_interop.cc +++ b/src/interop/rtc_audio_device_interop.cc @@ -126,10 +126,13 @@ RTCAudioDevice_SetPlayoutDevice( ) noexcept { CHECK_NATIVE_HANDLE(audiDevice); + if (index < 1) { + return rtcResultU4::kOutOfRange; + } scoped_refptr pAudioDevice = static_cast(audiDevice); int nCount = (int)pAudioDevice->PlayoutDevices(); - if (index < 0 || index >= nCount) { + if (index >= nCount) { return rtcResultU4::kOutOfRange; } return static_cast(pAudioDevice->SetPlayoutDevice((uint16_t)index)); @@ -142,10 +145,13 @@ RTCAudioDevice_SetRecordingDevice( ) noexcept { CHECK_NATIVE_HANDLE(audiDevice); + if (index < 1) { + return rtcResultU4::kOutOfRange; + } scoped_refptr pAudioDevice = static_cast(audiDevice); int nCount = (int)pAudioDevice->RecordingDevices(); - if (index < 0 || index >= nCount) { + if (index >= nCount) { return rtcResultU4::kOutOfRange; } return static_cast(pAudioDevice->SetRecordingDevice((uint16_t)index)); diff --git a/src/interop/rtc_data_channel_interop.cc b/src/interop/rtc_data_channel_interop.cc index 39a772dd43..f3cb752a8a 100644 --- a/src/interop/rtc_data_channel_interop.cc +++ b/src/interop/rtc_data_channel_interop.cc @@ -77,19 +77,7 @@ RTCDataChannel_GetLabel( int label_size ) noexcept { - CHECK_NATIVE_HANDLE(dataChannel); - CHECK_POINTER(label); - ZERO_MEMORY(label, label_size); - if (label_size < 1) { - return rtcResultU4::kInvalidParameter; - } - - scoped_refptr pDataChannel = static_cast(dataChannel); - string strLabel = pDataChannel->label(); - size_t len = strLabel.copy_to(label, static_cast(label_size)); - return strLabel.size() > len - ? rtcResultU4::kBufferTooSmall - : rtcResultU4::kSuccess; + DECLARE_GET_STRING(dataChannel, label, label_size, RTCDataChannel, label); } rtcResultU4 LIB_WEBRTC_CALL @@ -98,13 +86,7 @@ RTCDataChannel_GetId( int* id ) noexcept { - CHECK_NATIVE_HANDLE(dataChannel); - CHECK_POINTER(id); - RESET_OUT_POINTER_EX(id, 0); - - scoped_refptr pDataChannel = static_cast(dataChannel); - *id = pDataChannel->id(); - return rtcResultU4::kSuccess; + DECLARE_GET_VALUE(dataChannel, id, int, RTCDataChannel, id); } rtcResultU4 LIB_WEBRTC_CALL @@ -113,11 +95,5 @@ RTCDataChannel_GetState( rtcDataChannelState* state ) noexcept { - CHECK_NATIVE_HANDLE(dataChannel); - CHECK_POINTER(state); - RESET_OUT_POINTER_EX(state, static_cast(-1)); - - scoped_refptr pDataChannel = static_cast(dataChannel); - *state = static_cast(pDataChannel->state()); - return rtcResultU4::kSuccess; + DECLARE_GET_VALUE(dataChannel, state, rtcDataChannelState, RTCDataChannel, state); } \ No newline at end of file diff --git a/src/interop/rtc_ice_candidate_interop.cc b/src/interop/rtc_ice_candidate_interop.cc index 3f118d20b5..70711e232c 100644 --- a/src/interop/rtc_ice_candidate_interop.cc +++ b/src/interop/rtc_ice_candidate_interop.cc @@ -38,18 +38,7 @@ RTCIceCandidate_GetCandidate( int sz_value ) noexcept { - CHECK_NATIVE_HANDLE(iceCandidate); - ZERO_MEMORY(value, sz_value); - if (sz_value < 1) { - return rtcResultU4::kBufferTooSmall; - } - - scoped_refptr pIceCandidate = static_cast(iceCandidate); - string strValue = pIceCandidate->candidate(); - size_t len = strValue.copy_to(value, static_cast(sz_value)); - return strValue.size() > len - ? rtcResultU4::kBufferTooSmall - : rtcResultU4::kSuccess; + DECLARE_GET_STRING(iceCandidate, value, sz_value, RTCIceCandidate, candidate); } rtcResultU4 LIB_WEBRTC_CALL @@ -59,18 +48,7 @@ RTCIceCandidate_GetSdpMid( int sz_value ) noexcept { - CHECK_NATIVE_HANDLE(iceCandidate); - ZERO_MEMORY(value, sz_value); - if (sz_value < 1) { - return rtcResultU4::kBufferTooSmall; - } - - scoped_refptr pIceCandidate = static_cast(iceCandidate); - string strValue = pIceCandidate->sdp_mid(); - size_t len = strValue.copy_to(value, static_cast(sz_value)); - return strValue.size() > len - ? rtcResultU4::kBufferTooSmall - : rtcResultU4::kSuccess; + DECLARE_GET_STRING(iceCandidate, value, sz_value, RTCIceCandidate, sdp_mid); } rtcResultU4 LIB_WEBRTC_CALL @@ -79,11 +57,5 @@ RTCIceCandidate_GetSdpMlineIndex( int* pOutRetVal ) noexcept { - CHECK_NATIVE_HANDLE(iceCandidate); - CHECK_POINTER(pOutRetVal); - *pOutRetVal = -1; - - scoped_refptr pIceCandidate = static_cast(iceCandidate); - *pOutRetVal = pIceCandidate->sdp_mline_index(); - return rtcResultU4::kSuccess; + DECLARE_GET_VALUE(iceCandidate, pOutRetVal, int, RTCIceCandidate, sdp_mline_index); } diff --git a/src/interop/rtc_media_stream_interop.cc b/src/interop/rtc_media_stream_interop.cc index 1cbfb8b68b..692173ad49 100644 --- a/src/interop/rtc_media_stream_interop.cc +++ b/src/interop/rtc_media_stream_interop.cc @@ -178,19 +178,7 @@ RTCMediaStream_GetLabel ( int sz_value ) noexcept { - CHECK_NATIVE_HANDLE(mediaStream); - ZERO_MEMORY(value, sz_value); - CHECK_POINTER(value); - if (sz_value < 1) { - return rtcResultU4::kBufferTooSmall; - } - - scoped_refptr pMediaStream = static_cast(mediaStream); - string strValue = pMediaStream->label(); - size_t len = strValue.copy_to(value, static_cast(sz_value)); - return strValue.size() > len - ? rtcResultU4::kBufferTooSmall - : rtcResultU4::kSuccess; + DECLARE_GET_STRING(mediaStream, value, sz_value, RTCMediaStream, label); } rtcResultU4 LIB_WEBRTC_CALL @@ -200,30 +188,15 @@ RTCMediaStream_GetId ( int sz_value ) noexcept { - CHECK_NATIVE_HANDLE(mediaStream); - ZERO_MEMORY(value, sz_value); - CHECK_POINTER(value); - if (sz_value < 1) { - return rtcResultU4::kBufferTooSmall; - } - - scoped_refptr pMediaStream = static_cast(mediaStream); - string strValue = pMediaStream->id(); - size_t len = strValue.copy_to(value, static_cast(sz_value)); - return strValue.size() > len - ? rtcResultU4::kBufferTooSmall - : rtcResultU4::kSuccess; + DECLARE_GET_STRING(mediaStream, value, sz_value, RTCMediaStream, id); } int LIB_WEBRTC_CALL RTCMediaStreamList_GetCount ( - rtcMediaStreamListHandle mediaStreamList + rtcMediaStreamListHandle handle ) noexcept { - CHECK_POINTER_EX(mediaStreamList, 0); - - scoped_refptr pMediaStreamList = static_cast(mediaStreamList); - return static_cast(pMediaStreamList->count()); + DECLARE_LIST_GET_COUNT(handle, RTCMediaStreamList); } rtcResultU4 LIB_WEBRTC_CALL @@ -233,18 +206,5 @@ RTCMediaStreamList_GetItem ( rtcMediaStreamHandle* pOutRetVal ) noexcept { - CHECK_OUT_POINTER(pOutRetVal); - RESET_OUT_POINTER(pOutRetVal); - CHECK_NATIVE_HANDLE(mediaStreamList); - if (index < 0) { - return rtcResultU4::kOutOfRange; - } - - scoped_refptr pMediaStreamList = static_cast(mediaStreamList); - scoped_refptr pMediaStream = pMediaStreamList->item(static_cast(index)); - if (pMediaStream == nullptr) { - return rtcResultU4::kUnknownError; - } - *pOutRetVal = static_cast(pMediaStream.release()); - return rtcResultU4::kSuccess; + DECLARE_LIST_GET_ITEM(mediaStreamList, index, pOutRetVal, rtcMediaStreamHandle, RTCMediaStreamList, RTCMediaStream); } diff --git a/src/interop/rtc_media_track_interop.cc b/src/interop/rtc_media_track_interop.cc index be0bc7f7f5..c60af0cefe 100644 --- a/src/interop/rtc_media_track_interop.cc +++ b/src/interop/rtc_media_track_interop.cc @@ -20,19 +20,7 @@ RTCMediaTrack_GetKind( int cchOutKind ) noexcept { - CHECK_NATIVE_HANDLE(mediaTrack); - ZERO_MEMORY(pOutKind, cchOutKind); - CHECK_POINTER(pOutKind); - if (cchOutKind < 1) { - return rtcResultU4::kBufferTooSmall; - } - - scoped_refptr pMediaTrack = static_cast(mediaTrack); - string strValue = pMediaTrack->kind(); - size_t len = strValue.copy_to(pOutKind, static_cast(cchOutKind)); - return strValue.size() > len - ? rtcResultU4::kBufferTooSmall - : rtcResultU4::kSuccess; + DECLARE_GET_STRING(mediaTrack, pOutKind, cchOutKind, RTCMediaTrack, kind); } rtcResultU4 LIB_WEBRTC_CALL @@ -42,19 +30,7 @@ RTCMediaTrack_GetId( int cchOutId ) noexcept { - CHECK_NATIVE_HANDLE(mediaTrack); - ZERO_MEMORY(pOutId, cchOutId); - CHECK_POINTER(pOutId); - if (cchOutId < 1) { - return rtcResultU4::kBufferTooSmall; - } - - scoped_refptr pMediaTrack = static_cast(mediaTrack); - string strValue = pMediaTrack->id(); - size_t len = strValue.copy_to(pOutId, static_cast(cchOutId)); - return strValue.size() > len - ? rtcResultU4::kBufferTooSmall - : rtcResultU4::kSuccess; + DECLARE_GET_STRING(mediaTrack, pOutId, cchOutId, RTCMediaTrack, id); } rtcBool32 LIB_WEBRTC_CALL diff --git a/src/interop/rtc_rtp_capabilities_interop.cc b/src/interop/rtc_rtp_capabilities_interop.cc index 934ecd9164..b65a30dad6 100644 --- a/src/interop/rtc_rtp_capabilities_interop.cc +++ b/src/interop/rtc_rtp_capabilities_interop.cc @@ -31,19 +31,7 @@ RTCRtpCodecCapability_GetMimeType( int sz_value ) noexcept { - CHECK_NATIVE_HANDLE(handle); - ZERO_MEMORY(value, sz_value); - CHECK_POINTER(value); - if (sz_value < 1) { - return rtcResultU4::kBufferTooSmall; - } - - scoped_refptr pCodec = static_cast(handle); - string strValue = pCodec->mime_type(); - size_t len = strValue.copy_to(value, static_cast(sz_value)); - return strValue.size() > len - ? rtcResultU4::kBufferTooSmall - : rtcResultU4::kSuccess; + DECLARE_GET_STRING(handle, value, sz_value, RTCRtpCodecCapability, mime_type); } rtcResultU4 LIB_WEBRTC_CALL @@ -52,11 +40,7 @@ RTCRtpCodecCapability_SetMimeType( const char* value ) noexcept { - CHECK_NATIVE_HANDLE(handle); - - scoped_refptr pCodec = static_cast(handle); - pCodec->set_mime_type(string(value)); - return rtcResultU4::kSuccess; + DECLARE_SET_VALUE(handle, value, string, RTCRtpCodecCapability, set_mime_type); } rtcResultU4 LIB_WEBRTC_CALL @@ -65,13 +49,7 @@ RTCRtpCodecCapability_GetClockRate( int* pOutRetVal ) noexcept { - CHECK_POINTER(pOutRetVal); - RESET_OUT_POINTER_EX(pOutRetVal, 0); - CHECK_NATIVE_HANDLE(handle); - - scoped_refptr pCodec = static_cast(handle); - *pOutRetVal = pCodec->clock_rate(); - return rtcResultU4::kSuccess; + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCRtpCodecCapability, clock_rate); } rtcResultU4 LIB_WEBRTC_CALL @@ -80,11 +58,7 @@ RTCRtpCodecCapability_SetClockRate( int value ) noexcept { - CHECK_NATIVE_HANDLE(handle); - - scoped_refptr pCodec = static_cast(handle); - pCodec->set_clock_rate(value); - return rtcResultU4::kSuccess; + DECLARE_SET_VALUE(handle, value, int, RTCRtpCodecCapability, set_clock_rate); } rtcResultU4 LIB_WEBRTC_CALL @@ -93,13 +67,7 @@ RTCRtpCodecCapability_GetChannels( int* pOutRetVal ) noexcept { - CHECK_POINTER(pOutRetVal); - RESET_OUT_POINTER_EX(pOutRetVal, 0); - CHECK_NATIVE_HANDLE(handle); - - scoped_refptr pCodec = static_cast(handle); - *pOutRetVal = pCodec->channels(); - return rtcResultU4::kSuccess; + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCRtpCodecCapability, channels); } rtcResultU4 LIB_WEBRTC_CALL @@ -108,11 +76,7 @@ RTCRtpCodecCapability_SetChannels( int value ) noexcept { - CHECK_NATIVE_HANDLE(handle); - - scoped_refptr pCodec = static_cast(handle); - pCodec->set_channels(value); - return rtcResultU4::kSuccess; + DECLARE_SET_VALUE(handle, value, int, RTCRtpCodecCapability, set_channels); } rtcResultU4 LIB_WEBRTC_CALL @@ -122,19 +86,7 @@ RTCRtpCodecCapability_GetSdpFmtpLine( int sz_value ) noexcept { - CHECK_NATIVE_HANDLE(handle); - ZERO_MEMORY(value, sz_value); - CHECK_POINTER(value); - if (sz_value < 1) { - return rtcResultU4::kBufferTooSmall; - } - - scoped_refptr pCodec = static_cast(handle); - string strValue = pCodec->sdp_fmtp_line(); - size_t len = strValue.copy_to(value, static_cast(sz_value)); - return strValue.size() > len - ? rtcResultU4::kBufferTooSmall - : rtcResultU4::kSuccess; + DECLARE_GET_STRING(handle, value, sz_value, RTCRtpCodecCapability, sdp_fmtp_line); } rtcResultU4 LIB_WEBRTC_CALL @@ -143,11 +95,7 @@ RTCRtpCodecCapability_SetSdpFmtpLine( const char* value ) noexcept { - CHECK_NATIVE_HANDLE(handle); - - scoped_refptr pCodec = static_cast(handle); - pCodec->set_sdp_fmtp_line(string(value)); - return rtcResultU4::kSuccess; + DECLARE_SET_VALUE(handle, value, string, RTCRtpCodecCapability, set_sdp_fmtp_line); } /* @@ -161,9 +109,7 @@ RTCRtpCodecCapabilityList_GetCount ( rtcRtpCodecCapabilityListHandle handle ) noexcept { - CHECK_POINTER_EX(handle, 0); - scoped_refptr pList = static_cast(handle); - return static_cast(pList->count()); + DECLARE_LIST_GET_COUNT(handle, RTCRtpCodecCapabilityList); } rtcResultU4 LIB_WEBRTC_CALL @@ -173,19 +119,7 @@ RTCRtpCodecCapabilityList_GetItem ( rtcRtpCodecCapabilityHandle* pOutRetVal ) noexcept { - CHECK_OUT_POINTER(pOutRetVal); - CHECK_NATIVE_HANDLE(handle); - if (index < 0) { - return rtcResultU4::kOutOfRange; - } - - scoped_refptr pList = static_cast(handle); - if (static_cast(index) >= pList->count()) { - return rtcResultU4::kOutOfRange; - } - scoped_refptr pItem = pList->item(static_cast(index)); - *pOutRetVal = static_cast(pItem.release()); - return rtcResultU4::kSuccess; + DECLARE_LIST_GET_ITEM(handle, index, pOutRetVal, rtcRtpCodecCapabilityHandle, RTCRtpCodecCapabilityList, RTCRtpCodecCapability); } /* @@ -201,19 +135,7 @@ RTCRtpHeaderExtensionCapability_GetUri( int sz_value ) noexcept { - CHECK_NATIVE_HANDLE(handle); - ZERO_MEMORY(value, sz_value); - CHECK_POINTER(value); - if (sz_value < 1) { - return rtcResultU4::kBufferTooSmall; - } - - scoped_refptr pHeaderExtension = static_cast(handle); - string strValue = pHeaderExtension->uri(); - size_t len = strValue.copy_to(value, static_cast(sz_value)); - return strValue.size() > len - ? rtcResultU4::kBufferTooSmall - : rtcResultU4::kSuccess; + DECLARE_GET_STRING(handle, value, sz_value, RTCRtpHeaderExtensionCapability, uri); } rtcResultU4 LIB_WEBRTC_CALL @@ -222,11 +144,7 @@ RTCRtpHeaderExtensionCapability_SetUri( const char* value ) noexcept { - CHECK_NATIVE_HANDLE(handle); - - scoped_refptr pHeaderExtension = static_cast(handle); - pHeaderExtension->set_uri(string(value)); - return rtcResultU4::kSuccess; + DECLARE_SET_VALUE(handle, value, string, RTCRtpHeaderExtensionCapability, set_uri); } rtcResultU4 LIB_WEBRTC_CALL @@ -235,13 +153,7 @@ RTCRtpHeaderExtensionCapability_GetPreferredId( int* pOutRetVal ) noexcept { - CHECK_POINTER(pOutRetVal); - RESET_OUT_POINTER_EX(pOutRetVal, 0); - CHECK_NATIVE_HANDLE(handle); - - scoped_refptr pHeaderExtension = static_cast(handle); - *pOutRetVal = pHeaderExtension->preferred_id(); - return rtcResultU4::kSuccess; + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCRtpHeaderExtensionCapability, preferred_id); } rtcResultU4 LIB_WEBRTC_CALL @@ -250,11 +162,7 @@ RTCRtpHeaderExtensionCapability_SetPreferredId( int value ) noexcept { - CHECK_NATIVE_HANDLE(handle); - - scoped_refptr pHeaderExtension = static_cast(handle); - pHeaderExtension->set_preferred_id(value); - return rtcResultU4::kSuccess; + DECLARE_SET_VALUE(handle, value, int, RTCRtpHeaderExtensionCapability, set_preferred_id); } rtcResultU4 LIB_WEBRTC_CALL @@ -263,13 +171,7 @@ RTCRtpHeaderExtensionCapability_GetPreferredEncrypt( rtcBool32* pOutRetVal ) noexcept { - CHECK_POINTER(pOutRetVal); - RESET_OUT_POINTER_EX(pOutRetVal, rtcBool32::kFalse); - CHECK_NATIVE_HANDLE(handle); - - scoped_refptr pHeaderExtension = static_cast(handle); - *pOutRetVal = pHeaderExtension->preferred_encrypt() ? rtcBool32::kTrue : rtcBool32::kFalse; - return rtcResultU4::kSuccess; + DECLARE_GET_VALUE(handle, pOutRetVal, rtcBool32, RTCRtpHeaderExtensionCapability, preferred_encrypt); } rtcResultU4 LIB_WEBRTC_CALL @@ -278,11 +180,7 @@ RTCRtpHeaderExtensionCapability_SetPreferredEncrypt( rtcBool32 value ) noexcept { - CHECK_NATIVE_HANDLE(handle); - - scoped_refptr pHeaderExtension = static_cast(handle); - pHeaderExtension->set_preferred_encrypt(value != rtcBool32::kFalse); - return rtcResultU4::kSuccess; + DECLARE_SET_VALUE(handle, value, bool, RTCRtpHeaderExtensionCapability, set_preferred_encrypt); } /* @@ -296,10 +194,7 @@ RTCRtpHeaderExtensionCapabilityList_GetCount ( rtcRtpHeaderExtensionCapabilityListHandle handle ) noexcept { - CHECK_POINTER_EX(handle, 0); - scoped_refptr pList = - static_cast(handle); - return static_cast(pList->count()); + DECLARE_LIST_GET_COUNT(handle, RTCRtpHeaderExtensionCapabilityList); } rtcResultU4 LIB_WEBRTC_CALL @@ -309,20 +204,7 @@ RTCRtpHeaderExtensionCapabilityList_GetItem ( rtcRtpHeaderExtensionCapabilityHandle* pOutRetVal ) noexcept { - CHECK_OUT_POINTER(pOutRetVal); - CHECK_NATIVE_HANDLE(handle); - if (index < 0) { - return rtcResultU4::kOutOfRange; - } - - scoped_refptr pList = - static_cast(handle); - if (static_cast(index) >= pList->count()) { - return rtcResultU4::kOutOfRange; - } - scoped_refptr pItem = pList->item(static_cast(index)); - *pOutRetVal = static_cast(pItem.release()); - return rtcResultU4::kSuccess; + DECLARE_LIST_GET_ITEM(handle, index, pOutRetVal, rtcRtpHeaderExtensionCapabilityHandle, RTCRtpHeaderExtensionCapabilityList, RTCRtpHeaderExtensionCapability); } /* @@ -337,18 +219,7 @@ RTCRtpCapabilities_GetCodecs( rtcRtpCodecCapabilityListHandle* pOutRetVal ) noexcept { - CHECK_OUT_POINTER(pOutRetVal); - CHECK_NATIVE_HANDLE(handle); - - scoped_refptr pRtpCapabilities = static_cast(handle); - scoped_refptr codecs = RTCRtpCodecCapabilityList::Create( - pRtpCapabilities->codecs() - ); - if (codecs == nullptr) { - return rtcResultU4::kUnknownError; - } - *pOutRetVal = static_cast(codecs.release()); - return rtcResultU4::kSuccess; + DECLARE_GET_LIST_HANDLE(handle, pOutRetVal, rtcRtpCodecCapabilityListHandle, RTCRtpCapabilities, RTCRtpCodecCapabilityList, codecs); } rtcResultU4 LIB_WEBRTC_CALL @@ -357,13 +228,7 @@ RTCRtpCapabilities_SetCodecs( rtcRtpCodecCapabilityListHandle hCodecs ) noexcept { - CHECK_NATIVE_HANDLE(handle); - CHECK_POINTER_EX(hCodecs, rtcResultU4::kInvalidParameter); - - scoped_refptr pRtpCapabilities = static_cast(handle); - scoped_refptr codecs = static_cast(hCodecs); - pRtpCapabilities->set_codecs(codecs->to_vector()); - return rtcResultU4::kSuccess; + DECLARE_SET_LIST_HANDLE(handle, hCodecs, RTCRtpCapabilities, RTCRtpCodecCapabilityList, set_codecs); } rtcResultU4 LIB_WEBRTC_CALL @@ -372,18 +237,7 @@ RTCRtpCapabilities_GetHeaderExtensions( rtcRtpHeaderExtensionCapabilityListHandle* pOutRetVal ) noexcept { - CHECK_OUT_POINTER(pOutRetVal); - CHECK_NATIVE_HANDLE(handle); - - scoped_refptr pRtpCapabilities = static_cast(handle); - scoped_refptr header_extensions = RTCRtpHeaderExtensionCapabilityList::Create( - pRtpCapabilities->header_extensions() - ); - if (header_extensions == nullptr) { - return rtcResultU4::kUnknownError; - } - *pOutRetVal = static_cast(header_extensions.release()); - return rtcResultU4::kSuccess; + DECLARE_GET_LIST_HANDLE(handle, pOutRetVal, rtcRtpHeaderExtensionCapabilityListHandle, RTCRtpCapabilities, RTCRtpHeaderExtensionCapabilityList, header_extensions); } rtcResultU4 LIB_WEBRTC_CALL @@ -392,12 +246,5 @@ RTCRtpCapabilities_SetHeaderExtensions( rtcRtpHeaderExtensionCapabilityListHandle hHeaderExtensions ) noexcept { - CHECK_NATIVE_HANDLE(handle); - CHECK_POINTER_EX(hHeaderExtensions, rtcResultU4::kInvalidParameter); - - scoped_refptr pRtpCapabilities = static_cast(handle); - scoped_refptr header_extensions = - static_cast(hHeaderExtensions); - pRtpCapabilities->set_header_extensions(header_extensions->to_vector()); - return rtcResultU4::kSuccess; + DECLARE_SET_LIST_HANDLE(handle, hHeaderExtensions, RTCRtpCapabilities, RTCRtpHeaderExtensionCapabilityList, set_header_extensions); } diff --git a/src/interop/rtc_rtp_parameters_interop.cc b/src/interop/rtc_rtp_parameters_interop.cc new file mode 100644 index 0000000000..1e7b09f133 --- /dev/null +++ b/src/interop/rtc_rtp_parameters_interop.cc @@ -0,0 +1,853 @@ +#include "rtc_rtp_parameters.h" +#include "interop_api.h" + +using namespace libwebrtc; + +/* + * ---------------------------------------------------------------------- + * RTCRtcpFeedback interop methods + * ---------------------------------------------------------------------- + */ + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpFeedback_GetType( + rtcRtcpFeedbackHandle handle, + rtcRtcpFeedbackType* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcRtcpFeedbackType, RTCRtcpFeedback, type); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpFeedback_SetType( + rtcRtcpFeedbackHandle handle, + rtcRtcpFeedbackType value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, RTCRtcpFeedbackType, RTCRtcpFeedback, set_type); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpFeedback_GetMessageType( + rtcRtcpFeedbackHandle handle, + rtcRtcpFeedbackMessageType* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcRtcpFeedbackMessageType, RTCRtcpFeedback, message_type); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpFeedback_SetMessageType( + rtcRtcpFeedbackHandle handle, + rtcRtcpFeedbackMessageType value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, RTCRtcpFeedbackMessageType, RTCRtcpFeedback, set_message_type); +} + +/* + * ---------------------------------------------------------------------- + * RTCRtcpFeedbackList interop methods + * ---------------------------------------------------------------------- + */ + +int LIB_WEBRTC_CALL +RTCRtcpFeedbackList_GetCount ( + rtcRtcpFeedbackListHandle handle +) noexcept +{ + DECLARE_LIST_GET_COUNT(handle, RTCRtcpFeedbackList); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpFeedbackList_GetItem ( + rtcRtcpFeedbackListHandle handle, + int index, + rtcRtcpFeedbackHandle* pOutRetVal +) noexcept +{ + DECLARE_LIST_GET_ITEM(handle, index, pOutRetVal, rtcRtcpFeedbackHandle, RTCRtcpFeedbackList, RTCRtcpFeedback); +} + +/* + * ---------------------------------------------------------------------- + * RTCRtpExtension interop methods + * ---------------------------------------------------------------------- + */ + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpExtension_ToString ( + rtcRtpExtensionHandle handle, + char* value, + int sz_value +) noexcept +{ + DECLARE_GET_STRING(handle, value, sz_value, RTCRtpExtension, ToString); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpExtension_GetUri ( + rtcRtpExtensionHandle handle, + char* value, + int sz_value +) noexcept +{ + DECLARE_GET_STRING(handle, value, sz_value, RTCRtpExtension, uri); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpExtension_SetUri ( + rtcRtpExtensionHandle handle, + const char* value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, string, RTCRtpExtension, set_uri); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpExtension_GetId ( + rtcRtpExtensionHandle handle, + int* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCRtpExtension, id); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpExtension_SetId ( + rtcRtpExtensionHandle handle, + int value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, int, RTCRtpExtension, set_id); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpExtension_GetEncrypt ( + rtcRtpExtensionHandle handle, + rtcBool32* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcBool32, RTCRtpExtension, encrypt); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpExtension_SetEncrypt ( + rtcRtpExtensionHandle handle, + rtcBool32 value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, bool, RTCRtpExtension, set_encrypt); +} + +/* + * ---------------------------------------------------------------------- + * RTCRtpExtensionList interop methods + * ---------------------------------------------------------------------- + */ + +int LIB_WEBRTC_CALL +RTCRtpExtensionList_GetCount ( + rtcRtpExtensionListHandle handle +) noexcept +{ + DECLARE_LIST_GET_COUNT(handle, RTCRtpExtensionList); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpExtensionList_GetItem ( + rtcRtpExtensionListHandle handle, + int index, + rtcRtpExtensionHandle* pOutRetVal +) noexcept +{ + DECLARE_LIST_GET_ITEM(handle, index, pOutRetVal, rtcRtpExtensionHandle, RTCRtpExtensionList, RTCRtpExtension); +} + +/* + * ---------------------------------------------------------------------- + * RTCRtpCodecParameters interop methods + * ---------------------------------------------------------------------- + */ + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_GetMimeType ( + rtcRtpCodecParametersHandle handle, + char* value, + int sz_value +) noexcept +{ + DECLARE_GET_STRING(handle, value, sz_value, RTCRtpCodecParameters, mime_type); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_GetName ( + rtcRtpCodecParametersHandle handle, + char* value, + int sz_value +) noexcept +{ + DECLARE_GET_STRING(handle, value, sz_value, RTCRtpCodecParameters, name); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_SetName ( + rtcRtpCodecParametersHandle handle, + const char* value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, string, RTCRtpCodecParameters, set_name); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_GetKind ( + rtcRtpCodecParametersHandle handle, + rtcMediaType* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcMediaType, RTCRtpCodecParameters, kind); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_SetKind ( + rtcRtpCodecParametersHandle handle, + rtcMediaType value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, RTCMediaType, RTCRtpCodecParameters, set_kind); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_GetPayloadType ( + rtcRtpCodecParametersHandle handle, + int* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCRtpCodecParameters, payload_type); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_SetPayloadType ( + rtcRtpCodecParametersHandle handle, + int value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, int, RTCRtpCodecParameters, set_payload_type); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_GetClockRate ( + rtcRtpCodecParametersHandle handle, + int* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCRtpCodecParameters, clock_rate); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_SetClockRate ( + rtcRtpCodecParametersHandle handle, + int value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, int, RTCRtpCodecParameters, set_clock_rate); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_GetNumChannels ( + rtcRtpCodecParametersHandle handle, + int* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCRtpCodecParameters, num_channels); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_SetNumChannels ( + rtcRtpCodecParametersHandle handle, + int value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, int, RTCRtpCodecParameters, set_num_channels); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_GetMaxPTime ( + rtcRtpCodecParametersHandle handle, + int* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCRtpCodecParameters, max_ptime); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_SetMaxPTime ( + rtcRtpCodecParametersHandle handle, + int value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, int, RTCRtpCodecParameters, set_max_ptime); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_GetPTime ( + rtcRtpCodecParametersHandle handle, + int* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCRtpCodecParameters, ptime); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_SetPTime ( + rtcRtpCodecParametersHandle handle, + int value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, int, RTCRtpCodecParameters, set_ptime); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_GetRtcpFeedBacks ( + rtcRtpCodecParametersHandle handle, + rtcRtcpFeedbackListHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_LIST_HANDLE(handle, pOutRetVal, rtcRtcpFeedbackListHandle, RTCRtpCodecParameters, RTCRtcpFeedbackList, rtcp_feedback); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_SetRtcpFeedBacks ( + rtcRtpCodecParametersHandle handle, + rtcRtcpFeedbackListHandle value +) noexcept +{ + DECLARE_SET_LIST_HANDLE(handle, value, RTCRtpCodecParameters, RTCRtcpFeedbackList, set_rtcp_feedback); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_GetParameters ( + rtcRtpCodecParametersHandle handle, + rtcObjectHandle* pOutRetVal +) noexcept +{ + return rtcResultU4::kInvalidOperation; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_SetParameters ( + rtcRtpCodecParametersHandle handle, + rtcObjectHandle value +) noexcept +{ + return rtcResultU4::kInvalidOperation; +} + +/* + * ---------------------------------------------------------------------- + * RTCRtpCodecParametersList interop methods + * ---------------------------------------------------------------------- + */ + +int LIB_WEBRTC_CALL +RTCRtpCodecParametersList_GetCount ( + rtcRtpCodecParametersListHandle handle +) noexcept +{ + DECLARE_LIST_GET_COUNT(handle, RTCRtpCodecParametersList); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParametersList_GetItem ( + rtcRtpCodecParametersListHandle handle, + int index, + rtcRtpCodecParametersHandle* pOutRetVal +) noexcept +{ + DECLARE_LIST_GET_ITEM(handle, index, pOutRetVal, rtcRtpCodecParametersHandle, RTCRtpCodecParametersList, RTCRtpCodecParameters); +} + +/* + * ---------------------------------------------------------------------- + * RTCRtcpParameters interop methods + * ---------------------------------------------------------------------- + */ + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpParameters_GetSSRC ( + rtcRtcpParametersHandle handle, + unsigned int* value +) noexcept +{ + DECLARE_GET_VALUE(handle, value, unsigned int, RTCRtcpParameters, ssrc); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpParameters_SetSSRC ( + rtcRtcpParametersHandle handle, + unsigned int value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, uint32_t, RTCRtcpParameters, set_ssrc); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpParameters_GetCName ( + rtcRtcpParametersHandle handle, + char* value, + int sz_value +) noexcept +{ + DECLARE_GET_STRING(handle, value, sz_value, RTCRtcpParameters, cname); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpParameters_SetCName ( + rtcRtcpParametersHandle handle, + const char* value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, string, RTCRtcpParameters, set_cname); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpParameters_GetReducedSize ( + rtcRtcpParametersHandle handle, + rtcBool32* value +) noexcept +{ + DECLARE_GET_VALUE(handle, value, rtcBool32, RTCRtcpParameters, reduced_size); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpParameters_SetReducedSize ( + rtcRtcpParametersHandle handle, + rtcBool32 value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, bool, RTCRtcpParameters, set_reduced_size); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpParameters_GetMux ( + rtcRtcpParametersHandle handle, + rtcBool32* value +) noexcept +{ + DECLARE_GET_VALUE(handle, value, rtcBool32, RTCRtcpParameters, mux); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpParameters_SetMux ( + rtcRtcpParametersHandle handle, + rtcBool32 value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, bool, RTCRtcpParameters, set_mux); +} + +/* + * ---------------------------------------------------------------------- + * RTCRtcpParametersList interop methods + * ---------------------------------------------------------------------- + */ + +int LIB_WEBRTC_CALL +RTCRtcpParametersList_GetCount ( + rtcRtcpParametersListHandle handle +) noexcept +{ + DECLARE_LIST_GET_COUNT(handle, RTCRtcpParametersList); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtcpParametersList_GetItem ( + rtcRtcpParametersListHandle handle, + int index, + rtcRtcpParametersHandle* pOutRetVal +) noexcept +{ + DECLARE_LIST_GET_ITEM(handle, index, pOutRetVal, rtcRtcpParametersHandle, RTCRtcpParametersList, RTCRtcpParameters); +} + +/* + * ---------------------------------------------------------------------- + * RTCRtpEncodingParameters interop methods + * ---------------------------------------------------------------------- + */ + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetSSRC ( + rtcRtpEncodingParametersHandle handle, + unsigned int* value +) noexcept +{ + DECLARE_GET_VALUE(handle, value, unsigned int, RTCRtpEncodingParameters, ssrc); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetSSRC ( + rtcRtpEncodingParametersHandle handle, + unsigned int value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, uint32_t, RTCRtpEncodingParameters, set_ssrc); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetBitratePriority ( + rtcRtpEncodingParametersHandle handle, + double* value +) noexcept +{ + DECLARE_GET_VALUE(handle, value, double, RTCRtpEncodingParameters, bitrate_priority); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetBitratePriority ( + rtcRtpEncodingParametersHandle handle, + double value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, double, RTCRtpEncodingParameters, set_bitrate_priority); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetNetworkPriority ( + rtcRtpEncodingParametersHandle handle, + rtcNetworkPriority* value +) noexcept +{ + DECLARE_GET_VALUE(handle, value, rtcNetworkPriority, RTCRtpEncodingParameters, network_priority); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetNetworkPriority ( + rtcRtpEncodingParametersHandle handle, + rtcNetworkPriority value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, RTCPriority, RTCRtpEncodingParameters, set_network_priority); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetMaxBitrateBps ( + rtcRtpEncodingParametersHandle handle, + int* value +) noexcept +{ + DECLARE_GET_VALUE(handle, value, int, RTCRtpEncodingParameters, max_bitrate_bps); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetMaxBitrateBps ( + rtcRtpEncodingParametersHandle handle, + int value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, int, RTCRtpEncodingParameters, set_max_bitrate_bps); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetMinBitrateBps ( + rtcRtpEncodingParametersHandle handle, + int* value +) noexcept +{ + DECLARE_GET_VALUE(handle, value, int, RTCRtpEncodingParameters, min_bitrate_bps); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetMinBitrateBps ( + rtcRtpEncodingParametersHandle handle, + int value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, int, RTCRtpEncodingParameters, set_min_bitrate_bps); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetMaxFramerate ( + rtcRtpEncodingParametersHandle handle, + double* value +) noexcept +{ + DECLARE_GET_VALUE(handle, value, double, RTCRtpEncodingParameters, max_framerate); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetMaxFramerate ( + rtcRtpEncodingParametersHandle handle, + double value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, double, RTCRtpEncodingParameters, set_max_framerate); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetNumTemporalLayers ( + rtcRtpEncodingParametersHandle handle, + int* value +) noexcept +{ + DECLARE_GET_VALUE(handle, value, int, RTCRtpEncodingParameters, num_temporal_layers); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetNumTemporalLayers ( + rtcRtpEncodingParametersHandle handle, + int value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, int, RTCRtpEncodingParameters, set_num_temporal_layers); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetScaleResolutionDownBy ( + rtcRtpEncodingParametersHandle handle, + double* value +) noexcept +{ + DECLARE_GET_VALUE(handle, value, double, RTCRtpEncodingParameters, scale_resolution_down_by); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetScaleResolutionDownBy ( + rtcRtpEncodingParametersHandle handle, + double value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, double, RTCRtpEncodingParameters, set_scale_resolution_down_by); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetScalabilityMode ( + rtcRtpEncodingParametersHandle handle, + char* value, + int sz_value +) noexcept +{ + DECLARE_GET_STRING(handle, value, sz_value, RTCRtpEncodingParameters, scalability_mode); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetScalabilityMode ( + rtcRtpEncodingParametersHandle handle, + const char* value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, string, RTCRtpEncodingParameters, set_scalability_mode); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetActive ( + rtcRtpEncodingParametersHandle handle, + rtcBool32* value +) noexcept +{ + DECLARE_GET_VALUE(handle, value, rtcBool32, RTCRtpEncodingParameters, active); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetActive ( + rtcRtpEncodingParametersHandle handle, + rtcBool32 value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, bool, RTCRtpEncodingParameters, set_active); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetRid ( + rtcRtpEncodingParametersHandle handle, + char* value, + int sz_value +) noexcept +{ + DECLARE_GET_STRING(handle, value, sz_value, RTCRtpEncodingParameters, rid); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetRid ( + rtcRtpEncodingParametersHandle handle, + const char* value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, string, RTCRtpEncodingParameters, set_rid); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_GetAdaptivePTime( + rtcRtpEncodingParametersHandle handle, + rtcBool32* value +) noexcept +{ + DECLARE_GET_VALUE(handle, value, rtcBool32, RTCRtpEncodingParameters, adaptive_ptime); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_SetAdaptivePTime ( + rtcRtpEncodingParametersHandle handle, + rtcBool32 value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, bool, RTCRtpEncodingParameters, set_adaptive_ptime); +} + +/* + * ---------------------------------------------------------------------- + * RTCRtpEncodingParametersList interop methods + * ---------------------------------------------------------------------- + */ + +int LIB_WEBRTC_CALL +RTCRtpEncodingParametersList_GetCount ( + rtcRtpEncodingParametersListHandle handle +) noexcept +{ + DECLARE_LIST_GET_COUNT(handle, RTCRtpEncodingParametersList); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParametersList_GetItem ( + rtcRtpEncodingParametersListHandle handle, + int index, + rtcRtpEncodingParametersHandle* pOutRetVal +) noexcept +{ + DECLARE_LIST_GET_ITEM(handle, index, pOutRetVal, rtcRtpEncodingParametersHandle, RTCRtpEncodingParametersList, RTCRtpEncodingParameters); +} + +/* + * ---------------------------------------------------------------------- + * RTCRtpParameters interop methods + * ---------------------------------------------------------------------- + */ + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_GetTransactionId ( + rtcRtpParametersHandle handle, + char* value, + int sz_value +) noexcept +{ + DECLARE_GET_STRING(handle, value, sz_value, RTCRtpParameters, transaction_id); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_SetTransactionId ( + rtcRtpParametersHandle handle, + const char* value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, string, RTCRtpParameters, set_transaction_id); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_GetMid ( + rtcRtpParametersHandle handle, + char* value, + int sz_value +) noexcept +{ + DECLARE_GET_STRING(handle, value, sz_value, RTCRtpParameters, mid); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_SetMid ( + rtcRtpParametersHandle handle, + const char* value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, string, RTCRtpParameters, set_mid); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_GetCodecs ( + rtcRtpParametersHandle handle, + rtcRtpCodecParametersListHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_LIST_HANDLE(handle, pOutRetVal, rtcRtpCodecParametersListHandle, RTCRtpParameters, RTCRtpCodecParametersList, codecs); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_SetCodecs ( + rtcRtpParametersHandle handle, + rtcRtpCodecParametersListHandle value +) noexcept +{ + DECLARE_SET_LIST_HANDLE(handle, value, RTCRtpParameters, RTCRtpCodecParametersList, set_codecs); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_GetHeaderExtensions ( + rtcRtpParametersHandle handle, + rtcRtpExtensionListHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_LIST_HANDLE(handle, pOutRetVal, rtcRtpExtensionListHandle, RTCRtpParameters, RTCRtpExtensionList, header_extensions); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_SetHeaderExtensions ( + rtcRtpParametersHandle handle, + rtcRtpExtensionListHandle value +) noexcept +{ + DECLARE_SET_LIST_HANDLE(handle, value, RTCRtpParameters, RTCRtpExtensionList, set_header_extensions); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_GetEncodings ( + rtcRtpParametersHandle handle, + rtcRtpEncodingParametersListHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_LIST_HANDLE(handle, pOutRetVal, rtcRtpEncodingParametersListHandle, RTCRtpParameters, RTCRtpEncodingParametersList, encodings); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_SetEncodings ( + rtcRtpParametersHandle handle, + rtcRtpEncodingParametersListHandle value +) noexcept +{ + DECLARE_SET_LIST_HANDLE(handle, value, RTCRtpParameters, RTCRtpEncodingParametersList, set_encodings); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_GetRtcpParameters ( + rtcRtpParametersHandle handle, + rtcRtcpParametersHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcRtcpParametersHandle, RTCRtpParameters, rtcp_parameters().release); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_SetRtcpParameters ( + rtcRtpParametersHandle handle, + rtcRtcpParametersHandle value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, RTCRtcpParameters*, RTCRtpParameters, set_rtcp_parameters); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_GetDegradationPreference ( + rtcRtpParametersHandle handle, + rtcDegradationPreference* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcDegradationPreference, RTCRtpParameters, GetDegradationPreference); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpParameters_SetDegradationPreference ( + rtcRtpParametersHandle handle, + rtcDegradationPreference value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, RTCDegradationPreference, RTCRtpParameters, SetDegradationPreference); +} diff --git a/src/interop/rtc_sdp_parse_error_interop.cc b/src/interop/rtc_sdp_parse_error_interop.cc index 1afd4e56f2..33608f40ba 100644 --- a/src/interop/rtc_sdp_parse_error_interop.cc +++ b/src/interop/rtc_sdp_parse_error_interop.cc @@ -23,19 +23,7 @@ RTCSdpParseError_GetLine( int sz_value ) noexcept { - CHECK_NATIVE_HANDLE(sdpParseError); - CHECK_POINTER_EX(value, rtcResultU4::kInvalidParameter); - if (sz_value < 1) { - return rtcResultU4::kBufferTooSmall; - } - ZERO_MEMORY(value, sz_value); - - scoped_refptr pSdpParseError = static_cast(sdpParseError); - string strValue = pSdpParseError->line(); - size_t len = strValue.copy_to(value, static_cast(sz_value)); - return strValue.size() > len - ? rtcResultU4::kBufferTooSmall - : rtcResultU4::kSuccess; + DECLARE_GET_STRING(sdpParseError, value, sz_value, RTCSdpParseError, line); } rtcResultU4 LIB_WEBRTC_CALL @@ -44,11 +32,7 @@ RTCSdpParseError_SetLine( const char* value ) noexcept { - CHECK_NATIVE_HANDLE(sdpParseError); - - scoped_refptr pSdpParseError = static_cast(sdpParseError); - pSdpParseError->set_line(string(value)); - return rtcResultU4::kSuccess; + DECLARE_SET_VALUE(sdpParseError, value, string, RTCSdpParseError, set_line); } rtcResultU4 LIB_WEBRTC_CALL @@ -58,19 +42,7 @@ RTCSdpParseError_GetDescription( int sz_value ) noexcept { - CHECK_NATIVE_HANDLE(sdpParseError); - CHECK_POINTER_EX(value, rtcResultU4::kInvalidParameter); - if (sz_value < 1) { - return rtcResultU4::kBufferTooSmall; - } - ZERO_MEMORY(value, sz_value); - - scoped_refptr pSdpParseError = static_cast(sdpParseError); - string strValue = pSdpParseError->description(); - size_t len = strValue.copy_to(value, static_cast(sz_value)); - return strValue.size() > len - ? rtcResultU4::kBufferTooSmall - : rtcResultU4::kSuccess; + DECLARE_GET_STRING(sdpParseError, value, sz_value, RTCSdpParseError, description); } rtcResultU4 LIB_WEBRTC_CALL @@ -79,9 +51,5 @@ RTCSdpParseError_SetDescription( const char* value ) noexcept { - CHECK_NATIVE_HANDLE(sdpParseError); - - scoped_refptr pSdpParseError = static_cast(sdpParseError); - pSdpParseError->set_description(string(value)); - return rtcResultU4::kSuccess; + DECLARE_SET_VALUE(sdpParseError, value, string, RTCSdpParseError, set_description); } diff --git a/src/interop/rtc_video_frame_interop.cc b/src/interop/rtc_video_frame_interop.cc index aadbf24de9..ea78f430c2 100644 --- a/src/interop/rtc_video_frame_interop.cc +++ b/src/interop/rtc_video_frame_interop.cc @@ -140,13 +140,7 @@ RTCVideoFrame_GetRotation( rtcVideoRotation* pOutRetVal ) noexcept { - CHECK_POINTER(pOutRetVal); - *pOutRetVal = rtcVideoRotation::kVideoRotation_0; - CHECK_NATIVE_HANDLE(videoFrame); - - scoped_refptr pvf = static_cast(videoFrame); - *pOutRetVal = static_cast(pvf->rotation()); - return rtcResultU4::kSuccess; + DECLARE_GET_VALUE(videoFrame, pOutRetVal, rtcVideoRotation, RTCVideoFrame, rotation); } rtcTimestamp LIB_WEBRTC_CALL @@ -167,11 +161,7 @@ RTCVideoFrame_SetTimestampInMicroseconds( rtcTimestamp timestampInMicroseconds ) noexcept { - CHECK_NATIVE_HANDLE(videoFrame); - - scoped_refptr pvf = static_cast(videoFrame); - pvf->set_timestamp_us(static_cast(timestampInMicroseconds)); - return rtcResultU4::kSuccess; + DECLARE_SET_VALUE(videoFrame, timestampInMicroseconds, int64_t, RTCVideoFrame, set_timestamp_us); } int LIB_WEBRTC_CALL diff --git a/src/rtc_rtp_parameters_impl.cc b/src/rtc_rtp_parameters_impl.cc index ac4aec8a25..76e0e00432 100644 --- a/src/rtc_rtp_parameters_impl.cc +++ b/src/rtc_rtp_parameters_impl.cc @@ -1,5 +1,6 @@ #include "rtc_rtp_parameters_impl.h" +#include "rtc_base/logging.h" #include "base/refcountedobject.h" namespace libwebrtc { @@ -129,6 +130,22 @@ bool RTCRtpEncodingParametersImpl::operator!=( webrtc::RtpEncodingParameters RTCRtpEncodingParametersImpl::rtp_parameters() { return rtp_encoding_parameters_; } + +scoped_refptr RTCRtpEncodingParametersList::Create( + const vector>& source) { + return new RefCountedObject(source); +} + +RTCRtpEncodingParametersListImpl::RTCRtpEncodingParametersListImpl( + const vector>& source) + : RTCRtpEncodingParametersList(source) { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor "; +} + +RTCRtpEncodingParametersListImpl::~RTCRtpEncodingParametersListImpl() { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; +} + RTCRtpParametersImpl::RTCRtpParametersImpl(webrtc::RtpParameters rtp_parameters) : rtp_parameters_(rtp_parameters) {} webrtc::RtpParameters RTCRtpParametersImpl::rtp_parameters() { @@ -303,6 +320,21 @@ webrtc::RtcpParameters RTCRtcpParametersImpl::rtcp_parameters() { return rtcp_parameters_; } +scoped_refptr RTCRtcpParametersList::Create( + const vector>& source) { + return new RefCountedObject(source); +} + +RTCRtcpParametersListImpl::RTCRtcpParametersListImpl( + const vector>& source) + : RTCRtcpParametersList(source) { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor "; +} + +RTCRtcpParametersListImpl::~RTCRtcpParametersListImpl() { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; +} + RTCRtpExtensionImpl::RTCRtpExtensionImpl(webrtc::RtpExtension rtp_extension) : rtp_extension_(rtp_extension) {} @@ -335,6 +367,21 @@ const string RTCRtpExtensionImpl::ToString() const { return rtp_extension_.ToString(); } +scoped_refptr RTCRtpExtensionList::Create( + const vector>& source) { + return new RefCountedObject(source); +} + +RTCRtpExtensionListImpl::RTCRtpExtensionListImpl( + const vector>& source) + : RTCRtpExtensionList(source) { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor "; +} + +RTCRtpExtensionListImpl::~RTCRtpExtensionListImpl() { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; +} + RTCRtpCodecParametersImpl::RTCRtpCodecParametersImpl( webrtc::RtpCodecParameters rtp_codec_parameters) : rtp_codec_parameters_(rtp_codec_parameters) {} @@ -457,6 +504,21 @@ webrtc::RtpCodecParameters RTCRtpCodecParametersImpl::rtp_codec_parameters() { return rtp_codec_parameters_; } +scoped_refptr RTCRtpCodecParametersList::Create( + const vector>& source) { + return new RefCountedObject(source); +} + +RTCRtpCodecParametersListImpl::RTCRtpCodecParametersListImpl( + const vector>& source) + : RTCRtpCodecParametersList(source) { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor "; +} + +RTCRtpCodecParametersListImpl::~RTCRtpCodecParametersListImpl() { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; +} + RTCRtcpFeedbackImpl::RTCRtcpFeedbackImpl(webrtc::RtcpFeedback rtcp_feedback) : rtcp_feedback_(rtcp_feedback) {} @@ -492,4 +554,19 @@ bool RTCRtcpFeedbackImpl::operator!=(scoped_refptr o) { static_cast(o.get())->rtcp_feedback(); } +scoped_refptr RTCRtcpFeedbackList::Create( + const vector>& source) { + return new RefCountedObject(source); +} + +RTCRtcpFeedbackListImpl::RTCRtcpFeedbackListImpl( + const vector>& source) + : RTCRtcpFeedbackList(source) { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor "; +} + +RTCRtcpFeedbackListImpl::~RTCRtcpFeedbackListImpl() { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; +} + } // namespace libwebrtc diff --git a/src/rtc_rtp_parameters_impl.h b/src/rtc_rtp_parameters_impl.h index 8325e18090..985acea769 100644 --- a/src/rtc_rtp_parameters_impl.h +++ b/src/rtc_rtp_parameters_impl.h @@ -23,6 +23,15 @@ class RTCRtcpFeedbackImpl : public RTCRtcpFeedback { webrtc::RtcpFeedback rtcp_feedback_; }; +/** + * class RTCRtcpFeedbackListImpl + */ +class RTCRtcpFeedbackListImpl : public RTCRtcpFeedbackList { + public: + RTCRtcpFeedbackListImpl(const vector>& source); + ~RTCRtcpFeedbackListImpl(); +}; + class RTCRtpCodecParametersImpl : public RTCRtpCodecParameters { public: RTCRtpCodecParametersImpl(webrtc::RtpCodecParameters rtp_codec_parameters); @@ -55,6 +64,15 @@ class RTCRtpCodecParametersImpl : public RTCRtpCodecParameters { webrtc::RtpCodecParameters rtp_codec_parameters_; }; +/** + * class RTCRtpCodecParametersListImpl + */ +class RTCRtpCodecParametersListImpl : public RTCRtpCodecParametersList { + public: + RTCRtpCodecParametersListImpl(const vector>& source); + ~RTCRtpCodecParametersListImpl(); +}; + class RTCRtpExtensionImpl : public RTCRtpExtension { public: RTCRtpExtensionImpl(webrtc::RtpExtension rtp_extension); @@ -73,6 +91,15 @@ class RTCRtpExtensionImpl : public RTCRtpExtension { webrtc::RtpExtension rtp_extension_; }; +/** + * class RTCRtpExtensionListImpl + */ +class RTCRtpExtensionListImpl : public RTCRtpExtensionList { + public: + RTCRtpExtensionListImpl(const vector>& source); + ~RTCRtpExtensionListImpl(); +}; + class RTCRtcpParametersImpl : public RTCRtcpParameters { public: RTCRtcpParametersImpl(webrtc::RtcpParameters rtcp_parameters); @@ -94,6 +121,15 @@ class RTCRtcpParametersImpl : public RTCRtcpParameters { webrtc::RtcpParameters rtcp_parameters_; }; +/** + * class RTCRtcpParametersListImpl + */ +class RTCRtcpParametersListImpl : public RTCRtcpParametersList { + public: + RTCRtcpParametersListImpl(const vector>& source); + ~RTCRtcpParametersListImpl(); +}; + class RTCRtpParametersImpl : public RTCRtpParameters { public: RTCRtpParametersImpl(webrtc::RtpParameters rtp_parameters); @@ -184,5 +220,14 @@ class RTCRtpEncodingParametersImpl : public RTCRtpEncodingParameters { webrtc::RtpEncodingParameters rtp_encoding_parameters_; }; +/** + * class RTCRtpEncodingParametersListImpl + */ +class RTCRtpEncodingParametersListImpl : public RTCRtpEncodingParametersList { + public: + RTCRtpEncodingParametersListImpl(const vector>& source); + ~RTCRtpEncodingParametersListImpl(); +}; + } // namespace libwebrtc #endif // WINDOWS_RTP_PARAMETERS_H \ No newline at end of file From 01f4b58f87b7f07cd33360990447ac21ffa3a488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Sun, 29 Dec 2024 22:47:30 +0300 Subject: [PATCH 45/69] Added RTCRtpCodecParametersPair and RTCRtpCodecParametersMap --- include/interop_api.h | 91 +++++++++++++++++++ include/interop_macros.h | 2 +- include/rtc_base_list.h | 25 +++++- include/rtc_rtp_parameters.h | 48 ++++++++++ src/interop/rtc_rtp_parameters_interop.cc | 104 +++++++++++++++++++++- src/rtc_rtp_parameters_impl.cc | 68 ++++++++++++++ src/rtc_rtp_parameters_impl.h | 25 +++++- 7 files changed, 358 insertions(+), 5 deletions(-) diff --git a/include/interop_api.h b/include/interop_api.h index 8f0ff0fced..ae0f25f662 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -272,6 +272,11 @@ enum class rtcResultU4 : unsigned int { kInvalidPointer = 0x80004003, }; // end enum class rtcResultU4 +struct rtcStringPair { + const char* key = nullptr; + const char* value = nullptr; +}; // end struct rtcStringPair + struct rtcIceServer { const char* uri = nullptr; const char* username = nullptr; @@ -478,6 +483,12 @@ using rtcRtpFecParametersHandle = rtcRefCountedObjectHandle; /// Opaque handle to a native RTCRtpCodecParameters interop object. using rtcRtpCodecParametersHandle = rtcRefCountedObjectHandle; +/// Opaque handle to a native RTCRtpCodecParametersPair interop object. +using rtcRtpCodecParametersPairHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCRtpCodecParametersMap interop object. +using rtcRtpCodecParametersMapHandle = rtcRefCountedObjectHandle; + /// Opaque handle to a native RTCRtpCodecParametersList interop object. using rtcRtpCodecParametersListHandle = rtcRefCountedObjectHandle; @@ -2160,6 +2171,86 @@ RTCRtpExtensionList_GetItem ( rtcRtpExtensionHandle* pOutRetVal ) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCRtpCodecParametersPair interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Creates a new pair instance. + * + * @param pair - Single pair item + * @param pOutRetVal - The handle of the object to be returned. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParametersPair_Create( + const rtcStringPair* pair, + rtcRtpCodecParametersPairHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParametersPair_GetKey( + rtcRtpCodecParametersPairHandle handle, + char* value, + int sz_value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParametersPair_GetValue( + rtcRtpCodecParametersPairHandle handle, + char* value, + int sz_value +) noexcept; + +/* + * ---------------------------------------------------------------------- + * RTCRtpCodecParametersMap interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Creates a new pair map. + * + * @param pairs - Array + * @param length - Count of array + * @param pOutRetVal - The handle of the object to be returned. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParametersMap_Create( + const rtcStringPair* pairs, + int length, + rtcRtpCodecParametersPairHandle* pOutRetVal +) noexcept; + +/** + * Returns the number of pairs. + * + * @param handle - Map handle + * @return int - The number of pairs + */ +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RTCRtpCodecParametersMap_GetCount ( + rtcRtpCodecParametersMapHandle handle +) noexcept; + +/** + * Returns the pair whose index is specified. + * + * @param handle - Map handle + * @param index - Pair index + * @param pOutRetVal - Pair handle + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParametersMap_GetItem ( + rtcRtpCodecParametersMapHandle handle, + int index, + rtcRtpCodecParametersPairHandle* pOutRetVal +) noexcept; + /* * ---------------------------------------------------------------------- * RTCRtpCodecParameters interop methods diff --git a/include/interop_macros.h b/include/interop_macros.h index 7ab1989807..b4a9d5af94 100644 --- a/include/interop_macros.h +++ b/include/interop_macros.h @@ -93,7 +93,7 @@ list_type_name, item_type_name) \ CHECK_OUT_POINTER(out_val); \ CHECK_NATIVE_HANDLE(handle); \ - if (static_cast(index) < 1) { \ + if (static_cast(index) < 0) { \ return rtcResultU4::kOutOfRange; \ } \ scoped_refptr pList = static_cast(handle); \ diff --git a/include/rtc_base_list.h b/include/rtc_base_list.h index c4f6ad8e72..81a2b3ce03 100644 --- a/include/rtc_base_list.h +++ b/include/rtc_base_list.h @@ -5,7 +5,30 @@ namespace libwebrtc { -template +template +class RTCBasePair : public RefCountInterface { + private: + TKey key_; + TVal value_; + + public: + RTCBasePair() : key_{}, value_{} {} + + RTCBasePair(const TKey key, const TVal value) : key_(key), value_(value) {} + + RTCBasePair(const std::pair pair) + : key_(pair.first), value_(pair.second) {} + + ~RTCBasePair() {} + + TKey& key() { return key_; } + const TKey& key() const { return key_; } + + TVal& value() { return value_; } + const TVal& value() const { return value_; } +}; // end class RTCBasePair + +template class RTCBaseList : public RefCountInterface { protected: using raw_type = typename std::aligned_storage::type; diff --git a/include/rtc_rtp_parameters.h b/include/rtc_rtp_parameters.h index 37171609a3..d6393aa086 100644 --- a/include/rtc_rtp_parameters.h +++ b/include/rtc_rtp_parameters.h @@ -133,6 +133,53 @@ class RTCRtpRtxParameters : public RefCountInterface { virtual bool operator!=(scoped_refptr o) const = 0; }; +/** + * class RTCRtpCodecParametersPair + */ +class RTCRtpCodecParametersPair : public RTCBasePair { + public: + LIB_WEBRTC_API static scoped_refptr Create( + const std::pair& source); + + LIB_WEBRTC_API static scoped_refptr Create(); + + protected: + RTCRtpCodecParametersPair() + : RTCBasePair() + {} + + RTCRtpCodecParametersPair(const std::pair& source) + : RTCBasePair(source) + {} + + ~RTCRtpCodecParametersPair() {} +}; + +/** + * class RTCRtpCodecParametersMap + */ +class RTCRtpCodecParametersMap : public RTCBaseList> { + public: + LIB_WEBRTC_API static scoped_refptr Create( + const vector>& source); + + LIB_WEBRTC_API static scoped_refptr Create(); + + protected: + RTCRtpCodecParametersMap() + : RTCBaseList>() + {} + + RTCRtpCodecParametersMap(const vector>& source) + : RTCBaseList>(source) + {} + + ~RTCRtpCodecParametersMap() {} + + public: + virtual vector> to_parameters() = 0; +}; + class RTCRtpCodecParameters : public RefCountInterface { public: virtual const string mime_type() const = 0; @@ -164,6 +211,7 @@ class RTCRtpCodecParameters : public RefCountInterface { virtual const vector> parameters() = 0; virtual void set_parameters(const map parameters) = 0; + virtual void set_parameters(const vector> parameters) = 0; virtual bool operator==(scoped_refptr o) = 0; virtual bool operator!=(scoped_refptr o) = 0; diff --git a/src/interop/rtc_rtp_parameters_interop.cc b/src/interop/rtc_rtp_parameters_interop.cc index 1e7b09f133..851ff933c8 100644 --- a/src/interop/rtc_rtp_parameters_interop.cc +++ b/src/interop/rtc_rtp_parameters_interop.cc @@ -164,6 +164,106 @@ RTCRtpExtensionList_GetItem ( DECLARE_LIST_GET_ITEM(handle, index, pOutRetVal, rtcRtpExtensionHandle, RTCRtpExtensionList, RTCRtpExtension); } +/* + * ---------------------------------------------------------------------- + * RTCRtpCodecParametersPair interop methods + * ---------------------------------------------------------------------- + */ + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParametersPair_Create( + const rtcStringPair* pair, + rtcRtpCodecParametersPairHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + + scoped_refptr p; + if (pair) { + p = RTCRtpCodecParametersPair::Create( + std::pair(string(pair->key), string(pair->value)) + ); + } + else { + p = RTCRtpCodecParametersPair::Create(); + } + *pOutRetVal = static_cast(p.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParametersPair_GetKey( + rtcRtpCodecParametersPairHandle handle, + char* value, + int sz_value +) noexcept +{ + DECLARE_GET_STRING(handle, value, sz_value, RTCRtpCodecParametersPair, key); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParametersPair_GetValue( + rtcRtpCodecParametersPairHandle handle, + char* value, + int sz_value +) noexcept +{ + DECLARE_GET_STRING(handle, value, sz_value, RTCRtpCodecParametersPair, value); +} + +/* + * ---------------------------------------------------------------------- + * RTCRtpCodecParametersMap interop methods + * ---------------------------------------------------------------------- + */ + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParametersMap_Create( + const rtcStringPair* pairs, + int length, + rtcRtpCodecParametersPairHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + if (length > 0) { + CHECK_POINTER_EX(pairs, rtcResultU4::kInvalidParameter); + } + + scoped_refptr pMap; + std::vector> items; + if (length > 0) { + for (int i = 0; i < length; i++) { + items.push_back( + RTCRtpCodecParametersPair::Create(std::pair( + string(pairs[i].key), + string(pairs[i].value) + )) + ); + } + } + pMap = RTCRtpCodecParametersMap::Create(items); + *pOutRetVal = static_cast(pMap.release()); + return rtcResultU4::kSuccess; +} + +int LIB_WEBRTC_CALL +RTCRtpCodecParametersMap_GetCount ( + rtcRtpCodecParametersMapHandle handle +) noexcept +{ + DECLARE_LIST_GET_COUNT(handle, RTCRtpCodecParametersMap); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParametersMap_GetItem ( + rtcRtpCodecParametersMapHandle handle, + int index, + rtcRtpCodecParametersPairHandle* pOutRetVal +) noexcept +{ + DECLARE_LIST_GET_ITEM(handle, index, pOutRetVal, rtcRtpCodecParametersPairHandle, RTCRtpCodecParametersMap, RTCRtpCodecParametersPair); +} + /* * ---------------------------------------------------------------------- * RTCRtpCodecParameters interop methods @@ -328,7 +428,7 @@ RTCRtpCodecParameters_SetRtcpFeedBacks ( rtcResultU4 LIB_WEBRTC_CALL RTCRtpCodecParameters_GetParameters ( rtcRtpCodecParametersHandle handle, - rtcObjectHandle* pOutRetVal + rtcRtpCodecParametersMapHandle* pOutRetVal ) noexcept { return rtcResultU4::kInvalidOperation; @@ -337,7 +437,7 @@ RTCRtpCodecParameters_GetParameters ( rtcResultU4 LIB_WEBRTC_CALL RTCRtpCodecParameters_SetParameters ( rtcRtpCodecParametersHandle handle, - rtcObjectHandle value + rtcRtpCodecParametersMapHandle value ) noexcept { return rtcResultU4::kInvalidOperation; diff --git a/src/rtc_rtp_parameters_impl.cc b/src/rtc_rtp_parameters_impl.cc index 76e0e00432..c8184a35bc 100644 --- a/src/rtc_rtp_parameters_impl.cc +++ b/src/rtc_rtp_parameters_impl.cc @@ -382,6 +382,65 @@ RTCRtpExtensionListImpl::~RTCRtpExtensionListImpl() { RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; } +scoped_refptr RTCRtpCodecParametersPair::Create( + const std::pair& source) { + return new RefCountedObject(source); +} + +scoped_refptr RTCRtpCodecParametersPair::Create() { + return new RefCountedObject(); +} + +RTCRtpCodecParametersPairImpl::RTCRtpCodecParametersPairImpl() + : RTCRtpCodecParametersPair() { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor "; +} + +RTCRtpCodecParametersPairImpl::RTCRtpCodecParametersPairImpl( + const std::pair& source) + : RTCRtpCodecParametersPair(source) { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor "; +} + +RTCRtpCodecParametersPairImpl::~RTCRtpCodecParametersPairImpl() { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; +} + +scoped_refptr RTCRtpCodecParametersMap::Create( + const vector>& source) { + return new RefCountedObject(source); +} + +scoped_refptr RTCRtpCodecParametersMap::Create() { + return new RefCountedObject(); +} + +RTCRtpCodecParametersMapImpl::RTCRtpCodecParametersMapImpl() + : RTCRtpCodecParametersMap() { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor "; +} + +RTCRtpCodecParametersMapImpl::RTCRtpCodecParametersMapImpl( + const vector>& source) + : RTCRtpCodecParametersMap(source) { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor "; +} + +RTCRtpCodecParametersMapImpl::~RTCRtpCodecParametersMapImpl() { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; +} + +vector> RTCRtpCodecParametersMapImpl::to_parameters() { + std::vector> parameters; + size_t nCount = count(); + parameters.reserve(nCount); + for (size_t i = 0; i < nCount; i++) { + scoped_refptr ipPair = item(i); + parameters.push_back(std::pair(ipPair->key(), ipPair->value())); + } + return parameters; +} + RTCRtpCodecParametersImpl::RTCRtpCodecParametersImpl( webrtc::RtpCodecParameters rtp_codec_parameters) : rtp_codec_parameters_(rtp_codec_parameters) {} @@ -486,6 +545,15 @@ void RTCRtpCodecParametersImpl::set_parameters( rtp_codec_parameters_.parameters = parameters; } +void RTCRtpCodecParametersImpl::set_parameters( + const vector> parameters_in) { + std::map parameters; + for (auto item : parameters_in.std_vector()) { + parameters[to_std_string(item.first)] = to_std_string(item.second); + } + rtp_codec_parameters_.parameters = parameters; +} + bool RTCRtpCodecParametersImpl::operator==( scoped_refptr o) { RTCRtpCodecParametersImpl* impl = diff --git a/src/rtc_rtp_parameters_impl.h b/src/rtc_rtp_parameters_impl.h index 985acea769..968071c0bb 100644 --- a/src/rtc_rtp_parameters_impl.h +++ b/src/rtc_rtp_parameters_impl.h @@ -32,6 +32,28 @@ class RTCRtcpFeedbackListImpl : public RTCRtcpFeedbackList { ~RTCRtcpFeedbackListImpl(); }; +/** + * class RTCRtpCodecParametersPairImpl + */ +class RTCRtpCodecParametersPairImpl : public RTCRtpCodecParametersPair { + public: + RTCRtpCodecParametersPairImpl(); + RTCRtpCodecParametersPairImpl(const std::pair& source); + ~RTCRtpCodecParametersPairImpl(); +}; + +/** + * class RTCRtpCodecParametersMapImpl + */ +class RTCRtpCodecParametersMapImpl : public RTCRtpCodecParametersMap { + public: + RTCRtpCodecParametersMapImpl(); + RTCRtpCodecParametersMapImpl(const vector>& source); + ~RTCRtpCodecParametersMapImpl(); + + virtual vector> to_parameters() override; +}; + class RTCRtpCodecParametersImpl : public RTCRtpCodecParameters { public: RTCRtpCodecParametersImpl(webrtc::RtpCodecParameters rtp_codec_parameters); @@ -54,7 +76,8 @@ class RTCRtpCodecParametersImpl : public RTCRtpCodecParameters { virtual void set_rtcp_feedback( vector> rtcp_feedbacks) override; virtual const vector> parameters() override; - virtual void set_parameters(map parameters) override; + virtual void set_parameters(const map parameters) override; + virtual void set_parameters(const vector> parameters) override; virtual bool operator==(scoped_refptr o) override; virtual bool operator!=(scoped_refptr o) override; From 3e42afcce955231e037acb24841b8f4408890e12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Mon, 30 Dec 2024 00:06:24 +0300 Subject: [PATCH 46/69] Added RTCRtpCodecParameters_GetParameters and RTCRtpCodecParameters_SetParameters methods --- include/interop_api.h | 4 ++-- src/interop/rtc_rtp_parameters_interop.cc | 27 +++++++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/include/interop_api.h b/include/interop_api.h index ae0f25f662..2a82029788 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -2364,13 +2364,13 @@ RTCRtpCodecParameters_SetRtcpFeedBacks ( LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCRtpCodecParameters_GetParameters ( rtcRtpCodecParametersHandle handle, - rtcObjectHandle* pOutRetVal + rtcRtpCodecParametersMapHandle* pOutRetVal ) noexcept; LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCRtpCodecParameters_SetParameters ( rtcRtpCodecParametersHandle handle, - rtcObjectHandle value + rtcRtpCodecParametersMapHandle value ) noexcept; /* diff --git a/src/interop/rtc_rtp_parameters_interop.cc b/src/interop/rtc_rtp_parameters_interop.cc index 851ff933c8..74b18e6052 100644 --- a/src/interop/rtc_rtp_parameters_interop.cc +++ b/src/interop/rtc_rtp_parameters_interop.cc @@ -431,7 +431,21 @@ RTCRtpCodecParameters_GetParameters ( rtcRtpCodecParametersMapHandle* pOutRetVal ) noexcept { - return rtcResultU4::kInvalidOperation; + CHECK_OUT_POINTER(pOutRetVal); + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr p = static_cast(handle); + std::vector> parameters = p->parameters().std_vector(); + std::vector> pParameters; + for (auto item : parameters) { + pParameters.push_back(RTCRtpCodecParametersPair::Create(item)); + } + scoped_refptr pMap = RTCRtpCodecParametersMap::Create(pParameters); + if (pMap == nullptr) { + return rtcResultU4::kUnknownError; + } + *pOutRetVal = static_cast(pMap.release()); + return rtcResultU4::kSuccess; } rtcResultU4 LIB_WEBRTC_CALL @@ -440,7 +454,16 @@ RTCRtpCodecParameters_SetParameters ( rtcRtpCodecParametersMapHandle value ) noexcept { - return rtcResultU4::kInvalidOperation; + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr p = static_cast(handle); + vector> parameters; + if (value) { + scoped_refptr pMap = static_cast(value); + parameters = pMap->to_parameters(); + } + p->set_parameters(parameters); + return rtcResultU4::kSuccess; } /* From b366a68ab6b908a0e95f2b7a465759d045416b73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Tue, 31 Dec 2024 17:10:44 +0300 Subject: [PATCH 47/69] Added rtc_rtp_receiver_interop.cc --- BUILD.gn | 2 + include/interop_api.h | 87 ++++++++++ include/rtc_rtp_receiver.h | 2 + src/interop/rtc_data_channel_interop.cc | 3 + src/interop/rtc_desktop_media_list_interop.cc | 3 + src/interop/rtc_rtp_receiver_interop.cc | 148 ++++++++++++++++++ src/interop/rtc_rtp_sender_interop.cc | 5 + src/rtc_rtp_receiver_impl.cc | 39 +++++ src/rtc_rtp_receiver_impl.h | 17 ++ 9 files changed, 306 insertions(+) create mode 100644 src/interop/rtc_rtp_receiver_interop.cc create mode 100644 src/interop/rtc_rtp_sender_interop.cc diff --git a/BUILD.gn b/BUILD.gn index 233b875bca..a25b376cba 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -178,6 +178,8 @@ rtc_shared_library("libwebrtc") { "src/interop/rtc_media_stream_interop.cc", "src/interop/rtc_rtp_capabilities_interop.cc", "src/interop/rtc_rtp_parameters_interop.cc", + "src/interop/rtc_rtp_receiver_interop.cc", + "src/interop/rtc_rtp_sender_interop.cc", "src/interop/rtc_rtp_transceiver_interop.cc", "src/interop/rtc_peerconnection_interop.cc", ] diff --git a/include/interop_api.h b/include/interop_api.h index 2a82029788..58d30e2732 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -573,6 +573,20 @@ struct rtcDataChannelObserverCallbacks { rtcDataChannelObserverMessageDelegate MessageReceived{}; }; +/** + * RTCRtpReceiver: first packet received callback delegate + */ +using rtcRtpReceiverFirstPacketReceivedDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, rtcMediaType media_type); + +/** + * Callback delegate structure for RTCRtpReceiverObserver. + */ +struct rtcRtpReceiverObserverCallbacks { + rtcObjectHandle UserData{}; + rtcRtpReceiverFirstPacketReceivedDelegate FirstPacketReceived{}; +}; + /* * ---------------------------------------------------------------------- * LibWebRTC interop methods @@ -2768,6 +2782,79 @@ RTCRtpParameters_SetDegradationPreference ( rtcDegradationPreference value ) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCRtpReceiver interop methods + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiver_GetTrack ( + rtcRtpReceiverHandle handle, + rtcMediaTrackHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiver_GetDtlsTransport ( + rtcRtpReceiverHandle handle, + rtcDtlsTransportHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiver_GetStreamIds ( + rtcRtpReceiverHandle handle, + char* value, + int sz_value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiver_GetStreams ( + rtcRtpReceiverHandle handle, + rtcMediaStreamListHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiver_GetMediaType ( + rtcRtpReceiverHandle handle, + rtcMediaType* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiver_GetId ( + rtcRtpReceiverHandle handle, + char* value, + int sz_value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiver_GetParameters ( + rtcRtpReceiverHandle handle, + rtcRtpParametersHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiver_SetParameters ( + rtcRtpReceiverHandle handle, + rtcRtpParametersHandle value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiver_RegisterObserver ( + rtcRtpReceiverHandle handle, + rtcRtpReceiverObserverCallbacks* callbacks +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiver_UnregisterObserver( + rtcRtpReceiverHandle handle +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiver_SetJitterBufferMinimumDelay ( + rtcRtpReceiverHandle handle, + double value +) noexcept; + /* * ---------------------------------------------------------------------- * RTCRtpTransceiverInit interop methods diff --git a/include/rtc_rtp_receiver.h b/include/rtc_rtp_receiver.h index a72f2b8a06..5bfcda53c1 100644 --- a/include/rtc_rtp_receiver.h +++ b/include/rtc_rtp_receiver.h @@ -45,6 +45,8 @@ class RTCRtpReceiver : public RefCountInterface { virtual void SetJitterBufferMinimumDelay(double delay_seconds) = 0; + virtual RTCRtpReceiverObserver* GetObserver() = 0; + // virtual Vector GetSources() const = 0; // virtual void SetFrameDecryptor( diff --git a/src/interop/rtc_data_channel_interop.cc b/src/interop/rtc_data_channel_interop.cc index f3cb752a8a..9b923ce775 100644 --- a/src/interop/rtc_data_channel_interop.cc +++ b/src/interop/rtc_data_channel_interop.cc @@ -48,6 +48,9 @@ RTCDataChannel_RegisterObserver( CHECK_NATIVE_HANDLE(dataChannel); CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); + // unregistered + RTCDataChannel_UnregisterObserver(dataChannel); + RTCDataChannelObserver* pObserver = static_cast(new RTCDataChannelObserverImpl(callbacks)); scoped_refptr pDataChannel = static_cast(dataChannel); pDataChannel->RegisterObserver(pObserver); diff --git a/src/interop/rtc_desktop_media_list_interop.cc b/src/interop/rtc_desktop_media_list_interop.cc index 1305778e83..0a60c9d11b 100644 --- a/src/interop/rtc_desktop_media_list_interop.cc +++ b/src/interop/rtc_desktop_media_list_interop.cc @@ -20,6 +20,9 @@ RTCDesktopMediaList_RegisterMediaListObserver( { CHECK_NATIVE_HANDLE(hMediaList); CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); + + // unregistered + RTCDesktopMediaList_DeRegisterMediaListObserver(hMediaList); MediaListObserver* pObserver = static_cast(new MediaListObserverImpl(callbacks)); scoped_refptr pMediaList = static_cast(hMediaList); diff --git a/src/interop/rtc_rtp_receiver_interop.cc b/src/interop/rtc_rtp_receiver_interop.cc new file mode 100644 index 0000000000..bfcb23b139 --- /dev/null +++ b/src/interop/rtc_rtp_receiver_interop.cc @@ -0,0 +1,148 @@ +#include "rtc_rtp_receiver.h" +#include "interop_api.h" +#include "rtc_media_stream.h" +#include "src/rtc_rtp_receiver_impl.h" + +using namespace libwebrtc; + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiver_GetTrack ( + rtcRtpReceiverHandle handle, + rtcMediaTrackHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcMediaTrackHandle, RTCRtpReceiver, track().release); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiver_GetDtlsTransport ( + rtcRtpReceiverHandle handle, + rtcDtlsTransportHandle* pOutRetVal +) noexcept +{ + //DECLARE_GET_VALUE(handle, pOutRetVal, rtcDtlsTransportHandle, RTCRtpReceiver, dtls_transport().release); + return rtcResultU4::kInvalidOperation; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiver_GetStreamIds ( + rtcRtpReceiverHandle handle, + char* value, + int sz_value +) noexcept +{ + CHECK_POINTER(value); + if (sz_value < 1) { + return rtcResultU4::kBufferTooSmall; + } + ZERO_MEMORY(value, sz_value); + CHECK_NATIVE_HANDLE(handle); + sz_value--; + + scoped_refptr p = static_cast(handle); + std::vector streamIds = p->stream_ids().std_vector(); + std::string strValue; + for (auto stream_id : streamIds) { + strValue += stream_id.std_string() + "\n"; + } + size_t len = std::min(strValue.size(), static_cast(sz_value)); + if (strValue.size() > 0 && len > 0) { + strncpy(value, strValue.c_str(), len); + value[len] = '\0'; + } + return strValue.size() > len + ? rtcResultU4::kBufferTooSmall + : rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiver_GetStreams ( + rtcRtpReceiverHandle handle, + rtcMediaStreamListHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_LIST_HANDLE(handle, pOutRetVal, rtcMediaStreamListHandle, RTCRtpReceiver, RTCMediaStreamList, streams); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiver_GetMediaType ( + rtcRtpReceiverHandle handle, + rtcMediaType* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcMediaType, RTCRtpReceiver, media_type); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiver_GetId ( + rtcRtpReceiverHandle handle, + char* value, + int sz_value +) noexcept +{ + DECLARE_GET_STRING(handle, value, sz_value, RTCRtpReceiver, id); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiver_GetParameters ( + rtcRtpReceiverHandle handle, + rtcRtpParametersHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcRtpParametersHandle, RTCRtpReceiver, parameters().release); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiver_SetParameters ( + rtcRtpReceiverHandle handle, + rtcRtpParametersHandle value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, RTCRtpParameters*, RTCRtpReceiver, set_parameters); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiver_RegisterObserver ( + rtcRtpReceiverHandle handle, + rtcRtpReceiverObserverCallbacks* callbacks +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); + + // unregistered + RTCRtpReceiver_UnregisterObserver(handle); + + scoped_refptr p = static_cast(handle); + RTCRtpReceiverObserver* pObserver = static_cast + ( + new RTCRtpReceiverObserverImpl(static_cast(callbacks)) + ); + p->SetObserver(pObserver); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiver_UnregisterObserver( + rtcRtpReceiverHandle handle +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr p = static_cast(handle); + RTCRtpReceiverObserverImpl* pObserverImpl = static_cast(p->GetObserver()); + p->SetObserver(nullptr); + if (pObserverImpl) { + delete pObserverImpl; + } + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiver_SetJitterBufferMinimumDelay ( + rtcRtpReceiverHandle handle, + double value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, double, RTCRtpReceiver, SetJitterBufferMinimumDelay); +} diff --git a/src/interop/rtc_rtp_sender_interop.cc b/src/interop/rtc_rtp_sender_interop.cc new file mode 100644 index 0000000000..b0319c0821 --- /dev/null +++ b/src/interop/rtc_rtp_sender_interop.cc @@ -0,0 +1,5 @@ +#include "rtc_rtp_sender.h" +#include "interop_api.h" + +using namespace libwebrtc; + diff --git a/src/rtc_rtp_receiver_impl.cc b/src/rtc_rtp_receiver_impl.cc index 615d96509f..ce11037bf9 100644 --- a/src/rtc_rtp_receiver_impl.cc +++ b/src/rtc_rtp_receiver_impl.cc @@ -1,4 +1,5 @@ #include "rtc_rtp_receiver_impl.h" +#include "interop_api.h" #include "base/refcountedobject.h" #include "rtc_audio_track_impl.h" @@ -8,6 +9,44 @@ #include "rtc_video_track_impl.h" namespace libwebrtc { + +/** + * class RTCDataChannelObserverImpl + */ + +RTCRtpReceiverObserverImpl::RTCRtpReceiverObserverImpl( + void* callbacks /* rtcRtpReceiverObserverCallbacks* */) + : callbacks_(nullptr) +{ + if (callbacks) { + size_t nSize = sizeof(rtcRtpReceiverObserverCallbacks); + callbacks_ = malloc(nSize); + memcpy(callbacks_, (const void*)callbacks, nSize); + } +} + +RTCRtpReceiverObserverImpl::~RTCRtpReceiverObserverImpl() +{ + if (callbacks_) { + free(callbacks_); + } + callbacks_ = nullptr; +} + +void RTCRtpReceiverObserverImpl::OnFirstPacketReceived(RTCMediaType media_type) +{ + if (callbacks_) { + rtcRtpReceiverObserverCallbacks* pCallbacks = static_cast(callbacks_); + pCallbacks->FirstPacketReceived( + pCallbacks->UserData, + static_cast(media_type)); + } +} + +/** + * class RTCRtpReceiverImpl + */ + RTCRtpReceiverImpl::RTCRtpReceiverImpl( rtc::scoped_refptr rtp_receiver) : rtp_receiver_(rtp_receiver), observer_(nullptr) {} diff --git a/src/rtc_rtp_receiver_impl.h b/src/rtc_rtp_receiver_impl.h index 986956ce14..c0edc949e6 100644 --- a/src/rtc_rtp_receiver_impl.h +++ b/src/rtc_rtp_receiver_impl.h @@ -5,6 +5,22 @@ #include "rtc_rtp_receiver.h" namespace libwebrtc { + +/** + * class RTCRtpReceiverObserverImpl + */ +class RTCRtpReceiverObserverImpl : public RTCRtpReceiverObserver +{ + public: + RTCRtpReceiverObserverImpl(void* callbacks /* rtcRtpReceiverObserverCallbacks* */); + ~RTCRtpReceiverObserverImpl(); + + void OnFirstPacketReceived(RTCMediaType media_type) override; + + private: + void* callbacks_ /* rtcRtpReceiverObserverCallbacks* */; +}; // end class RTCRtpReceiverObserverImpl + class RTCRtpReceiverImpl : public RTCRtpReceiver, webrtc::RtpReceiverObserverInterface { public: @@ -23,6 +39,7 @@ class RTCRtpReceiverImpl : public RTCRtpReceiver, virtual void SetObserver(RTCRtpReceiverObserver* observer) override; virtual void SetJitterBufferMinimumDelay(double delay_seconds) override; rtc::scoped_refptr rtp_receiver(); + virtual RTCRtpReceiverObserver* GetObserver() override { return observer_; } private: rtc::scoped_refptr rtp_receiver_; From 5e61952c0636ac21f00f0b78410593896cb147f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Wed, 1 Jan 2025 13:53:15 +0300 Subject: [PATCH 48/69] Added rtc_rtp_sender_interop.cc --- include/interop_api.h | 80 +++++++++++++ src/interop/rtc_rtp_receiver_interop.cc | 4 +- src/interop/rtc_rtp_sender_interop.cc | 148 ++++++++++++++++++++++++ 3 files changed, 230 insertions(+), 2 deletions(-) diff --git a/include/interop_api.h b/include/interop_api.h index 58d30e2732..121e9dc9db 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -2855,6 +2855,86 @@ RTCRtpReceiver_SetJitterBufferMinimumDelay ( double value ) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCRtpSender interop methods + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_GetTrack ( + rtcRtpSenderHandle handle, + rtcMediaTrackHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_SetTrack ( + rtcRtpSenderHandle handle, + rtcMediaTrackHandle value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_GetDtlsTransport ( + rtcRtpSenderHandle handle, + rtcDtlsTransportHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_GetSSRC ( + rtcRtpSenderHandle handle, + unsigned int* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_GetMediaType ( + rtcRtpSenderHandle handle, + rtcMediaType* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_GetId ( + rtcRtpSenderHandle handle, + char* value, + int sz_value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_GetStreamIds ( + rtcRtpSenderHandle handle, + char* value, + int sz_value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_SetStreamIds ( + rtcRtpSenderHandle handle, + const char* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_SetEncodings ( + rtcRtpSenderHandle handle, + rtcRtpEncodingParametersListHandle value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_GetParameters ( + rtcRtpSenderHandle handle, + rtcRtpParametersHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_SetParameters ( + rtcRtpSenderHandle handle, + rtcRtpParametersHandle value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_GetDtmfSender ( + rtcRtpSenderHandle handle, + rtcDtmfSenderHandle* pOutRetVal +) noexcept; + /* * ---------------------------------------------------------------------- * RTCRtpTransceiverInit interop methods diff --git a/src/interop/rtc_rtp_receiver_interop.cc b/src/interop/rtc_rtp_receiver_interop.cc index bfcb23b139..563ada0d9d 100644 --- a/src/interop/rtc_rtp_receiver_interop.cc +++ b/src/interop/rtc_rtp_receiver_interop.cc @@ -1,6 +1,7 @@ #include "rtc_rtp_receiver.h" #include "interop_api.h" #include "rtc_media_stream.h" +#include "rtc_dtls_transport.h" #include "src/rtc_rtp_receiver_impl.h" using namespace libwebrtc; @@ -20,8 +21,7 @@ RTCRtpReceiver_GetDtlsTransport ( rtcDtlsTransportHandle* pOutRetVal ) noexcept { - //DECLARE_GET_VALUE(handle, pOutRetVal, rtcDtlsTransportHandle, RTCRtpReceiver, dtls_transport().release); - return rtcResultU4::kInvalidOperation; + DECLARE_GET_VALUE(handle, pOutRetVal, rtcDtlsTransportHandle, RTCRtpReceiver, dtls_transport().release); } rtcResultU4 LIB_WEBRTC_CALL diff --git a/src/interop/rtc_rtp_sender_interop.cc b/src/interop/rtc_rtp_sender_interop.cc index b0319c0821..7ce8d174e8 100644 --- a/src/interop/rtc_rtp_sender_interop.cc +++ b/src/interop/rtc_rtp_sender_interop.cc @@ -1,5 +1,153 @@ #include "rtc_rtp_sender.h" #include "interop_api.h" +#include "rtc_media_track.h" +#include "rtc_dtmf_sender.h" +#include "rtc_dtls_transport.h" + +#include using namespace libwebrtc; +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_GetTrack ( + rtcRtpSenderHandle handle, + rtcMediaTrackHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcMediaTrackHandle, RTCRtpSender, track().release); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_SetTrack ( + rtcRtpSenderHandle handle, + rtcMediaTrackHandle value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, RTCMediaTrack*, RTCRtpSender, set_track); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_GetDtlsTransport ( + rtcRtpSenderHandle handle, + rtcDtlsTransportHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcDtlsTransportHandle, RTCRtpSender, dtls_transport().release); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_GetSSRC ( + rtcRtpSenderHandle handle, + unsigned int* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, unsigned int, RTCRtpSender, ssrc); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_GetMediaType ( + rtcRtpSenderHandle handle, + rtcMediaType* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcMediaType, RTCRtpSender, media_type); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_GetId ( + rtcRtpSenderHandle handle, + char* value, + int sz_value +) noexcept +{ + DECLARE_GET_STRING(handle, value, sz_value, RTCRtpSender, id); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_GetStreamIds ( + rtcRtpSenderHandle handle, + char* value, + int sz_value +) noexcept +{ + CHECK_POINTER(value); + if (sz_value < 1) { + return rtcResultU4::kBufferTooSmall; + } + ZERO_MEMORY(value, sz_value); + CHECK_NATIVE_HANDLE(handle); + sz_value--; + + scoped_refptr p = static_cast(handle); + std::vector streamIds = p->stream_ids().std_vector(); + std::string strValue; + for (auto stream_id : streamIds) { + strValue += stream_id.std_string() + "\n"; + } + size_t len = std::min(strValue.size(), static_cast(sz_value)); + if (strValue.size() > 0 && len > 0) { + strncpy(value, strValue.c_str(), len); + value[len] = '\0'; + } + return strValue.size() > len + ? rtcResultU4::kBufferTooSmall + : rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_SetStreamIds ( + rtcRtpSenderHandle handle, + const char* value +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + + std::string input(value ? value : '\0'); + std::vector streamIds; + std::stringstream ss(input); + std::string line; + + while (std::getline(ss, line)) { + streamIds.push_back(line); + } + + scoped_refptr p = static_cast(handle); + p->set_stream_ids(streamIds); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_GetInitEncodings ( + rtcRtpSenderHandle handle, + rtcRtpEncodingParametersListHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_LIST_HANDLE(handle, pOutRetVal, rtcRtpEncodingParametersListHandle, RTCRtpSender, RTCRtpEncodingParametersList, init_send_encodings); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_GetParameters ( + rtcRtpSenderHandle handle, + rtcRtpParametersHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcRtpParametersHandle, RTCRtpSender, parameters().release); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_SetParameters ( + rtcRtpSenderHandle handle, + rtcRtpParametersHandle value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, RTCRtpParameters*, RTCRtpSender, set_parameters); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSender_GetDtmfSender ( + rtcRtpSenderHandle handle, + rtcDtmfSenderHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcDtmfSenderHandle, RTCRtpSender, dtmf_sender().release); +} From c56ab2623360a70a5e2600d3cc95098060325b99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Thu, 2 Jan 2025 19:36:58 +0300 Subject: [PATCH 49/69] Added rtc_dtls_transport_interop.cc and rtc_dtmf_sender_interop.cc --- BUILD.gn | 2 + include/interop_api.h | 143 +++++++++++++++++++++- include/rtc_dtls_transport.h | 4 +- include/rtc_dtmf_sender.h | 2 + src/interop/rtc_dtls_transport_interop.cc | 90 ++++++++++++++ src/interop/rtc_dtmf_sender_interop.cc | 109 +++++++++++++++++ src/rtc_data_channel_impl.cc | 4 +- src/rtc_desktop_media_list_impl.cc | 8 +- src/rtc_dtls_transport_impl.cc | 63 +++++++++- src/rtc_dtls_transport_impl.h | 18 +++ src/rtc_dtmf_sender_impl.cc | 54 ++++++++ src/rtc_dtmf_sender_impl.h | 18 +++ src/rtc_rtp_receiver_impl.cc | 4 +- 13 files changed, 507 insertions(+), 12 deletions(-) create mode 100644 src/interop/rtc_dtls_transport_interop.cc create mode 100644 src/interop/rtc_dtmf_sender_interop.cc diff --git a/BUILD.gn b/BUILD.gn index a25b376cba..d89f558082 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -176,6 +176,8 @@ rtc_shared_library("libwebrtc") { "src/interop/rtc_data_channel_interop.cc", "src/interop/rtc_ice_candidate_interop.cc", "src/interop/rtc_media_stream_interop.cc", + "src/interop/rtc_dtmf_sender_interop.cc", + "src/interop/rtc_dtls_transport_interop.cc", "src/interop/rtc_rtp_capabilities_interop.cc", "src/interop/rtc_rtp_parameters_interop.cc", "src/interop/rtc_rtp_receiver_interop.cc", diff --git a/include/interop_api.h b/include/interop_api.h index 121e9dc9db..596dbae93c 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -587,6 +587,41 @@ struct rtcRtpReceiverObserverCallbacks { rtcRtpReceiverFirstPacketReceivedDelegate FirstPacketReceived{}; }; +/** + * RTCDtmfSender: Tone changed callback delegate + */ +using rtcDtmfSenderToneChangedDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, const char* tone, int tone_len, const char* tone_buffer, int tone_buffer_len); + +/** + * Callback delegate structure for RTCDtmfSenderObserver. + */ +struct rtcDtmfSenderObserverCallbacks { + rtcObjectHandle UserData{}; + rtcDtmfSenderToneChangedDelegate ToneChanged{}; +}; + +/** + * RTCDtlsTransport: State changed callback delegate + */ +using rtcDtlsTransportStateChangedDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, rtcDtlsTransportInformationHandle info); + +/** + * RTCDtlsTransport: Error callback delegate + */ +using rtcDtlsTransportErrorDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, const int type, const char* message, int message_len); + +/** + * Callback delegate structure for RTCDtlsTransportObserver. + */ +struct rtcDtlsTransportObserverCallbacks { + rtcObjectHandle UserData{}; + rtcDtlsTransportStateChangedDelegate StateChanged{}; + rtcDtlsTransportErrorDelegate Error{}; +}; + /* * ---------------------------------------------------------------------- * LibWebRTC interop methods @@ -2855,6 +2890,63 @@ RTCRtpReceiver_SetJitterBufferMinimumDelay ( double value ) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCDtmfSender interop methods + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDtmfSender_RegisterObserver ( + rtcDtmfSenderHandle handle, + rtcDtmfSenderObserverCallbacks* callbacks +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDtmfSender_UnregisterObserver ( + rtcDtmfSenderHandle handle +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDtmfSender_InsertDtmf ( + rtcDtmfSenderHandle handle, + const char* tones, + int duration, + int inter_tone_gap, + const int* comma_delay = nullptr +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDtmfSender_CanInsertDtmf ( + rtcDtmfSenderHandle handle, + rtcBool32* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDtmfSender_GetTones ( + rtcDtmfSenderHandle handle, + char* value, + int sz_value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDtmfSender_GetDuration ( + rtcDtmfSenderHandle handle, + int* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDtmfSender_GetInterToneGap ( + rtcDtmfSenderHandle handle, + int* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDtmfSender_GetCommaDelay ( + rtcDtmfSenderHandle handle, + int* pOutRetVal +) noexcept; + /* * ---------------------------------------------------------------------- * RTCRtpSender interop methods @@ -2912,9 +3004,9 @@ RTCRtpSender_SetStreamIds ( ) noexcept; LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCRtpSender_SetEncodings ( +RTCRtpSender_GetInitEncodings ( rtcRtpSenderHandle handle, - rtcRtpEncodingParametersListHandle value + rtcRtpEncodingParametersListHandle* pOutRetVal ) noexcept; LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL @@ -2935,6 +3027,53 @@ RTCRtpSender_GetDtmfSender ( rtcDtmfSenderHandle* pOutRetVal ) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCDtlsTransportInformation interop methods + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDtlsTransportInformation_GetState ( + rtcDtlsTransportInformationHandle handle, + rtcDtlsTransportState* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDtlsTransportInformation_GetSslCipherSuite ( + rtcDtlsTransportInformationHandle handle, + int* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDtlsTransportInformation_GetSrtpCipherSuite ( + rtcDtlsTransportInformationHandle handle, + int* pOutRetVal +) noexcept; + +/* + * ---------------------------------------------------------------------- + * RTCDtlsTransport interop methods + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDtlsTransport_GetInformation ( + rtcDtlsTransportHandle handle, + rtcDtlsTransportInformationHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDtlsTransport_RegisterObserver ( + rtcDtlsTransportHandle handle, + rtcDtlsTransportObserverCallbacks* callbacks +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDtlsTransport_UnregisterObserver ( + rtcDtlsTransportHandle handle +) noexcept; + /* * ---------------------------------------------------------------------- * RTCRtpTransceiverInit interop methods diff --git a/include/rtc_dtls_transport.h b/include/rtc_dtls_transport.h index fe7adad7f0..fe2169a5c9 100644 --- a/include/rtc_dtls_transport.h +++ b/include/rtc_dtls_transport.h @@ -27,7 +27,7 @@ class RTCDtlsTransportInformation : public RefCountInterface { class RTCDtlsTransportObserver { public: - virtual void OnStateChange(RTCDtlsTransportInformation info) = 0; + virtual void OnStateChange(scoped_refptr info) = 0; virtual void OnError(const int type, const char* message) = 0; @@ -44,6 +44,8 @@ class RTCDtlsTransport : public RefCountInterface { virtual void RegisterObserver(RTCDtlsTransportObserver* observer) = 0; virtual void UnregisterObserver() = 0; + + virtual RTCDtlsTransportObserver* GetObserver() const = 0; }; } // namespace libwebrtc diff --git a/include/rtc_dtmf_sender.h b/include/rtc_dtmf_sender.h index 7f42cc56b5..d9c20d51fd 100644 --- a/include/rtc_dtmf_sender.h +++ b/include/rtc_dtmf_sender.h @@ -40,6 +40,8 @@ class RTCDtmfSender : public RefCountInterface { virtual int inter_tone_gap() const = 0; virtual int comma_delay() const = 0; + + virtual RTCDtmfSenderObserver* GetObserver() const = 0; }; } // namespace libwebrtc diff --git a/src/interop/rtc_dtls_transport_interop.cc b/src/interop/rtc_dtls_transport_interop.cc new file mode 100644 index 0000000000..362ed2ce06 --- /dev/null +++ b/src/interop/rtc_dtls_transport_interop.cc @@ -0,0 +1,90 @@ +#include "rtc_dtls_transport.h" +#include "src/rtc_dtls_transport_impl.h" +#include "interop_api.h" + +using namespace libwebrtc; + +/* + * ---------------------------------------------------------------------- + * RTCDtlsTransportInformation interop methods + * ---------------------------------------------------------------------- + */ + +rtcResultU4 LIB_WEBRTC_CALL +RTCDtlsTransportInformation_GetState ( + rtcDtlsTransportInformationHandle handle, + rtcDtlsTransportState* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcDtlsTransportState, RTCDtlsTransportInformation, state); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDtlsTransportInformation_GetSslCipherSuite ( + rtcDtlsTransportInformationHandle handle, + int* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCDtlsTransportInformation, ssl_cipher_suite); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDtlsTransportInformation_GetSrtpCipherSuite ( + rtcDtlsTransportInformationHandle handle, + int* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCDtlsTransportInformation, srtp_cipher_suite); +} + +/* + * ---------------------------------------------------------------------- + * RTCDtlsTransport interop methods + * ---------------------------------------------------------------------- + */ + +rtcResultU4 LIB_WEBRTC_CALL +RTCDtlsTransport_GetInformation ( + rtcDtlsTransportHandle handle, + rtcDtlsTransportInformationHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcDtlsTransportInformationHandle, RTCDtlsTransport, GetInformation().release); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDtlsTransport_RegisterObserver ( + rtcDtlsTransportHandle handle, + rtcDtlsTransportObserverCallbacks* callbacks +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); + + // unregistered + RTCDtlsTransport_UnregisterObserver(handle); + + scoped_refptr p = static_cast(handle); + RTCDtlsTransportObserver* pObserver = static_cast + ( + new RTCDtlsTransportObserverImpl(static_cast(callbacks)) + ); + p->RegisterObserver(pObserver); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDtlsTransport_UnregisterObserver ( + rtcDtlsTransportHandle handle +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr p = static_cast(handle); + RTCDtlsTransportObserverImpl* pObserverImpl = static_cast(p->GetObserver()); + p->UnregisterObserver(); + if (pObserverImpl) { + delete pObserverImpl; + } + return rtcResultU4::kSuccess; +} diff --git a/src/interop/rtc_dtmf_sender_interop.cc b/src/interop/rtc_dtmf_sender_interop.cc new file mode 100644 index 0000000000..df4943bd4d --- /dev/null +++ b/src/interop/rtc_dtmf_sender_interop.cc @@ -0,0 +1,109 @@ +#include "rtc_dtmf_sender.h" +#include "src/rtc_dtmf_sender_impl.h" +#include "interop_api.h" + +using namespace libwebrtc; + +rtcResultU4 LIB_WEBRTC_CALL +RTCDtmfSender_RegisterObserver ( + rtcDtmfSenderHandle handle, + rtcDtmfSenderObserverCallbacks* callbacks +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); + + // unregistered + RTCDtmfSender_UnregisterObserver(handle); + + scoped_refptr p = static_cast(handle); + RTCDtmfSenderObserver* pObserver = static_cast + ( + new RTCDtmfSenderObserverImpl(static_cast(callbacks)) + ); + p->RegisterObserver(pObserver); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDtmfSender_UnregisterObserver ( + rtcDtmfSenderHandle handle +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr p = static_cast(handle); + RTCDtmfSenderObserverImpl* pObserverImpl = static_cast(p->GetObserver()); + p->UnregisterObserver(); + if (pObserverImpl) { + delete pObserverImpl; + } + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDtmfSender_InsertDtmf ( + rtcDtmfSenderHandle handle, + const char* tones, + int duration, + int inter_tone_gap, + const int* comma_delay /*= nullptr*/ +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr p = static_cast(handle); + if (comma_delay) { + p->InsertDtmf(string(tones), duration, inter_tone_gap, *comma_delay); + } + else { + p->InsertDtmf(string(tones), duration, inter_tone_gap); + } + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDtmfSender_CanInsertDtmf ( + rtcDtmfSenderHandle handle, + rtcBool32* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcBool32, RTCDtmfSender, CanInsertDtmf); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDtmfSender_GetTones ( + rtcDtmfSenderHandle handle, + char* value, + int sz_value +) noexcept +{ + DECLARE_GET_STRING(handle, value, sz_value, RTCDtmfSender, tones); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDtmfSender_GetDuration ( + rtcDtmfSenderHandle handle, + int* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCDtmfSender, duration); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDtmfSender_GetInterToneGap ( + rtcDtmfSenderHandle handle, + int* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCDtmfSender, inter_tone_gap); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDtmfSender_GetCommaDelay ( + rtcDtmfSenderHandle handle, + int* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCDtmfSender, comma_delay); +} diff --git a/src/rtc_data_channel_impl.cc b/src/rtc_data_channel_impl.cc index e994c5f891..9bd181bc04 100644 --- a/src/rtc_data_channel_impl.cc +++ b/src/rtc_data_channel_impl.cc @@ -28,7 +28,7 @@ RTCDataChannelObserverImpl::~RTCDataChannelObserverImpl() void RTCDataChannelObserverImpl::OnStateChange(RTCDataChannelState state) { if (callbacks_) { - rtcDataChannelObserverCallbacks* pCallbacks = static_cast(callbacks_); + rtcDataChannelObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); pCallbacks->StateChanged( pCallbacks->UserData, static_cast(state)); @@ -38,7 +38,7 @@ void RTCDataChannelObserverImpl::OnStateChange(RTCDataChannelState state) void RTCDataChannelObserverImpl::OnMessage(const char* buffer, int length, bool binary) { if (callbacks_) { - rtcDataChannelObserverCallbacks* pCallbacks = static_cast(callbacks_); + rtcDataChannelObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); pCallbacks->MessageReceived( pCallbacks->UserData, buffer, diff --git a/src/rtc_desktop_media_list_impl.cc b/src/rtc_desktop_media_list_impl.cc index 41a3068b0f..3d0c8bc5b7 100644 --- a/src/rtc_desktop_media_list_impl.cc +++ b/src/rtc_desktop_media_list_impl.cc @@ -276,7 +276,7 @@ MediaListObserverImpl::~MediaListObserverImpl() void MediaListObserverImpl::OnMediaSourceAdded(scoped_refptr source) { if (callbacks_) { - rtcMediaListObserverCallbacks* pCallbacks = static_cast(callbacks_); + rtcMediaListObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); rtcDesktopMediaSourceHandle pSource = static_cast(source.release()); pCallbacks->MediaSourceAdded(pCallbacks->UserData, pSource); } @@ -285,7 +285,7 @@ void MediaListObserverImpl::OnMediaSourceAdded(scoped_refptr source void MediaListObserverImpl::OnMediaSourceRemoved(scoped_refptr source) { if (callbacks_) { - rtcMediaListObserverCallbacks* pCallbacks = static_cast(callbacks_); + rtcMediaListObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); rtcDesktopMediaSourceHandle pSource = static_cast(source.release()); pCallbacks->MediaSourceRemoved(pCallbacks->UserData, pSource); } @@ -294,7 +294,7 @@ void MediaListObserverImpl::OnMediaSourceRemoved(scoped_refptr sour void MediaListObserverImpl::OnMediaSourceNameChanged(scoped_refptr source) { if (callbacks_) { - rtcMediaListObserverCallbacks* pCallbacks = static_cast(callbacks_); + rtcMediaListObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); rtcDesktopMediaSourceHandle pSource = static_cast(source.release()); pCallbacks->MediaSourceNameChanged(pCallbacks->UserData, pSource); } @@ -303,7 +303,7 @@ void MediaListObserverImpl::OnMediaSourceNameChanged(scoped_refptr void MediaListObserverImpl::OnMediaSourceThumbnailChanged(scoped_refptr source) { if (callbacks_) { - rtcMediaListObserverCallbacks* pCallbacks = static_cast(callbacks_); + rtcMediaListObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); rtcDesktopMediaSourceHandle pSource = static_cast(source.release()); pCallbacks->MediaSourceThumbnailChanged(pCallbacks->UserData, pSource); } diff --git a/src/rtc_dtls_transport_impl.cc b/src/rtc_dtls_transport_impl.cc index 0d29e9c64f..7e1fd4406b 100644 --- a/src/rtc_dtls_transport_impl.cc +++ b/src/rtc_dtls_transport_impl.cc @@ -1,11 +1,15 @@ #include "rtc_dtls_transport_impl.h" #include "base/refcountedobject.h" +#include "interop_api.h" // #include "rtc_ice_transport_impl.h" namespace libwebrtc { +/** + * class RTCDtlsTransportInformationImpl + */ RTCDtlsTransportInformationImpl::RTCDtlsTransportInformationImpl( webrtc::DtlsTransportInformation dtls_transport_information) : dtls_transport_information_(dtls_transport_information) {} @@ -37,6 +41,56 @@ RTCDtlsTransportInformationImpl::dtls_transport_information() { return dtls_transport_information_; } +/** + * class RTCDtlsTransportObserverImpl + */ + +RTCDtlsTransportObserverImpl::RTCDtlsTransportObserverImpl( + void* callbacks /* rtcDtlsTransportObserverCallbacks* */) + : callbacks_(nullptr) +{ + if (callbacks) { + size_t nSize = sizeof(rtcDtlsTransportObserverCallbacks); + callbacks_ = malloc(nSize); + memcpy(callbacks_, (const void*)callbacks, nSize); + } +} + +RTCDtlsTransportObserverImpl::~RTCDtlsTransportObserverImpl() +{ + if (callbacks_) { + free(callbacks_); + } + callbacks_ = nullptr; +} + +void RTCDtlsTransportObserverImpl::OnStateChange(scoped_refptr info) +{ + if (callbacks_) { + rtcDtlsTransportObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + pCallbacks->StateChanged( + pCallbacks->UserData, + static_cast(info.release()) + ); + } +} + +void RTCDtlsTransportObserverImpl::OnError(const int type, const char* message) +{ + if (callbacks_) { + rtcDtlsTransportObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + pCallbacks->Error( + pCallbacks->UserData, + type, + message, + message ? strlen(message) : 0 + ); + } +} + +/** + * class RTCDtlsTransportImpl + */ RTCDtlsTransportImpl::RTCDtlsTransportImpl( rtc::scoped_refptr dtls_transport) : dtls_transport_(dtls_transport), observer_(nullptr) {} @@ -59,7 +113,14 @@ void RTCDtlsTransportImpl::UnregisterObserver() { } void RTCDtlsTransportImpl::OnStateChange( - webrtc::DtlsTransportInformation info) {} + webrtc::DtlsTransportInformation info) +{ + if (observer_) { + scoped_refptr pInfo = + new RefCountedObject(info); + observer_->OnStateChange(pInfo); + } +} void RTCDtlsTransportImpl::OnError(webrtc::RTCError error) { if (observer_) { diff --git a/src/rtc_dtls_transport_impl.h b/src/rtc_dtls_transport_impl.h index ea2f3ae148..e8c3a444ce 100644 --- a/src/rtc_dtls_transport_impl.h +++ b/src/rtc_dtls_transport_impl.h @@ -28,6 +28,22 @@ class RTCDtlsTransportInformationImpl : public RTCDtlsTransportInformation { webrtc::DtlsTransportInformation dtls_transport_information_; }; +/** + * class RTCDtlsTransportObserverImpl + */ +class RTCDtlsTransportObserverImpl : public RTCDtlsTransportObserver +{ + public: + RTCDtlsTransportObserverImpl(void* callbacks /* rtcDtlsTransportObserverCallbacks* */); + ~RTCDtlsTransportObserverImpl(); + + void OnStateChange(scoped_refptr info) override; + void OnError(const int type, const char* message) override; + + private: + void* callbacks_ /* rtcDtlsTransportObserverCallbacks* */; +}; // end class RTCDtlsTransportObserverImpl + class RTCDtlsTransportImpl : public RTCDtlsTransport, public webrtc::DtlsTransportObserverInterface { public: @@ -40,6 +56,8 @@ class RTCDtlsTransportImpl : public RTCDtlsTransport, virtual void UnregisterObserver() override; + virtual RTCDtlsTransportObserver* GetObserver() const override { return observer_; } + public: virtual void OnStateChange(webrtc::DtlsTransportInformation info) override; diff --git a/src/rtc_dtmf_sender_impl.cc b/src/rtc_dtmf_sender_impl.cc index f603157a10..a8bb2e39bc 100644 --- a/src/rtc_dtmf_sender_impl.cc +++ b/src/rtc_dtmf_sender_impl.cc @@ -1,7 +1,61 @@ #include "rtc_dtmf_sender_impl.h" +#include "interop_api.h" namespace libwebrtc { +/** + * class RTCDtmfSenderObserverImpl + */ + +RTCDtmfSenderObserverImpl::RTCDtmfSenderObserverImpl( + void* callbacks /* rtcDtmfSenderObserverCallbacks* */) + : callbacks_(nullptr) +{ + if (callbacks) { + size_t nSize = sizeof(rtcDtmfSenderObserverCallbacks); + callbacks_ = malloc(nSize); + memcpy(callbacks_, (const void*)callbacks, nSize); + } +} + +RTCDtmfSenderObserverImpl::~RTCDtmfSenderObserverImpl() +{ + if (callbacks_) { + free(callbacks_); + } + callbacks_ = nullptr; +} + +void RTCDtmfSenderObserverImpl::OnToneChange(const string tone, const string tone_buffer) +{ + if (callbacks_) { + rtcDtmfSenderObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + pCallbacks->ToneChanged( + pCallbacks->UserData, + tone.c_string(), + static_cast(((string*)&tone)->size()), + tone_buffer.c_string(), + static_cast(((string*)&tone_buffer)->size())); + } +} + +void RTCDtmfSenderObserverImpl::OnToneChange(const string tone) +{ + if (callbacks_) { + rtcDtmfSenderObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + pCallbacks->ToneChanged( + pCallbacks->UserData, + tone.c_string(), + static_cast(((string*)&tone)->size()), + nullptr, + 0); + } +} + +/** + * class RTCDtmfSenderImpl + */ + RTCDtmfSenderImpl::RTCDtmfSenderImpl( rtc::scoped_refptr dtmf_sender) : dtmf_sender_(dtmf_sender), observer_(nullptr) {} diff --git a/src/rtc_dtmf_sender_impl.h b/src/rtc_dtmf_sender_impl.h index 9f762e5ed8..1fbf27309f 100644 --- a/src/rtc_dtmf_sender_impl.h +++ b/src/rtc_dtmf_sender_impl.h @@ -10,6 +10,22 @@ namespace libwebrtc { +/** + * class RTCDtmfSenderObserverImpl + */ +class RTCDtmfSenderObserverImpl : public RTCDtmfSenderObserver +{ + public: + RTCDtmfSenderObserverImpl(void* callbacks /* rtcDtmfSenderObserverCallbacks* */); + ~RTCDtmfSenderObserverImpl(); + + void OnToneChange(const string tone, const string tone_buffer) override; + void OnToneChange(const string tone) override; + + private: + void* callbacks_ /* rtcDtmfSenderObserverCallbacks* */; +}; // end class RTCDtmfSenderObserverImpl + class RTCDtmfSenderImpl : public RTCDtmfSender, public webrtc::DtmfSenderObserverInterface { public: @@ -35,6 +51,8 @@ class RTCDtmfSenderImpl : public RTCDtmfSender, rtc::scoped_refptr dtmf_sender(); + virtual RTCDtmfSenderObserver* GetObserver() const override { return observer_; } + private: rtc::scoped_refptr dtmf_sender_; RTCDtmfSenderObserver* observer_; diff --git a/src/rtc_rtp_receiver_impl.cc b/src/rtc_rtp_receiver_impl.cc index ce11037bf9..f3691f7757 100644 --- a/src/rtc_rtp_receiver_impl.cc +++ b/src/rtc_rtp_receiver_impl.cc @@ -11,7 +11,7 @@ namespace libwebrtc { /** - * class RTCDataChannelObserverImpl + * class RTCRtpReceiverObserverImpl */ RTCRtpReceiverObserverImpl::RTCRtpReceiverObserverImpl( @@ -36,7 +36,7 @@ RTCRtpReceiverObserverImpl::~RTCRtpReceiverObserverImpl() void RTCRtpReceiverObserverImpl::OnFirstPacketReceived(RTCMediaType media_type) { if (callbacks_) { - rtcRtpReceiverObserverCallbacks* pCallbacks = static_cast(callbacks_); + rtcRtpReceiverObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); pCallbacks->FirstPacketReceived( pCallbacks->UserData, static_cast(media_type)); From 9751bd760e6e1eb5d3f7a2a316b5c0d5adb32853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Fri, 3 Jan 2025 00:23:39 +0300 Subject: [PATCH 50/69] Added rtc_rtp_transceiver_interop.cc --- include/base/portable.h | 48 ++++ include/interop_api.h | 140 +++++++++++- include/rtc_base_list.h | 11 + src/interop/rtc_rtp_receiver_interop.cc | 13 +- src/interop/rtc_rtp_sender_interop.cc | 25 +-- src/interop/rtc_rtp_transceiver_interop.cc | 243 +++++++++++++++++++++ 6 files changed, 436 insertions(+), 44 deletions(-) diff --git a/include/base/portable.h b/include/base/portable.h index b3a68f4c11..3d71e9dcd0 100644 --- a/include/base/portable.h +++ b/include/base/portable.h @@ -16,6 +16,7 @@ #include #include #include +#include /** * This file defines structures that can be passed across shared library/DLL @@ -38,6 +39,9 @@ namespace portable { #define PORTABLE_STRING_BUF_SIZE 48 +template +class vector; + class string { private: char m_buf[PORTABLE_STRING_BUF_SIZE]; @@ -102,6 +106,34 @@ class string { dest[cch_len] = '\0'; return cch_len; } + + inline std::vector split(string delimiter, bool removeEmptyEntries = true) + { + std::string input = std_string(); + std::string item; + std::vector tokens; + size_t start = 0; + size_t end = input.find(delimiter.c_string()); + + while (end != std::string::npos) { + item = input.substr(start, end - start); + if (!removeEmptyEntries || item.size() > 0) { + tokens.push_back(item); + } + start = end + delimiter.size(); + end = input.find(delimiter.c_string(), start); + } + + item = input.substr(start); + if (removeEmptyEntries && item.size() == 0) { + return tokens; + } + + tokens.push_back(input.substr(start)); + return tokens; + } + + static std::string join(string separator, const vector& values); }; inline std::string to_std_string(const string& str) { return str.std_string(); } @@ -235,6 +267,22 @@ class vector { } }; +inline std::string string::join(string separator, const vector& values) +{ + size_t count = values.size(); + if (count == 0) { + return std::string(); + } + std::string retVal; + for (size_t i = 0; i < count; i++) { + retVal += values[i].std_string(); + if ((i + 1) < count) { + retVal += separator.std_string(); + } + } + return retVal; +} + template class pair { public: diff --git a/include/interop_api.h b/include/interop_api.h index 596dbae93c..7ddb7bbb74 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -3080,21 +3080,139 @@ RTCDtlsTransport_UnregisterObserver ( * ---------------------------------------------------------------------- */ -/** - * Creates a new instance of the RTCRtpTransceiverInit object. - * - * @param pOutRetVal - Object handle - * @return rtcResultU4 - 0 if successful, otherwise an error code. - */ -/* LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCRtpTransceiverInit_Create( +RTCRtpTransceiverInit_Create ( rtcRtpTransceiverDirection direction, - const char** stream_ids, - rtcRtpEncodingParametersHandle hEncodings, + const char* stream_ids, + /* [optional, in] */ rtcRtpEncodingParametersListHandle encodings, rtcRtpTransceiverInitHandle* pOutRetVal ) noexcept; -*/ + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiverInit_GetDirection ( + rtcRtpTransceiverInitHandle handle, + rtcRtpTransceiverDirection* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiverInit_SetDirection ( + rtcRtpTransceiverInitHandle handle, + rtcRtpTransceiverDirection value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiverInit_GetStreamIds ( + rtcRtpTransceiverInitHandle handle, + char* value, + int sz_value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiverInit_SetStreamIds ( + rtcRtpTransceiverInitHandle handle, + const char* value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiverInit_GetEncodings ( + rtcRtpTransceiverInitHandle handle, + rtcRtpEncodingParametersListHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiverInit_SetEncodings ( + rtcRtpTransceiverInitHandle handle, + rtcRtpEncodingParametersListHandle value +) noexcept; + +/* + * ---------------------------------------------------------------------- + * RTCRtpTransceiver interop methods + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_GetMediaType ( + rtcRtpTransceiverHandle handle, + rtcMediaType* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_GetMid ( + rtcRtpTransceiverHandle handle, + char* value, + int sz_value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_GetSender ( + rtcRtpTransceiverHandle handle, + rtcRtpSenderHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_GetReceiver ( + rtcRtpTransceiverHandle handle, + rtcRtpReceiverHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_Stopped ( + rtcRtpTransceiverHandle handle, + rtcBool32* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_Stopping ( + rtcRtpTransceiverHandle handle, + rtcBool32* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_GetDirection ( + rtcRtpTransceiverHandle handle, + rtcRtpTransceiverDirection* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_SetDirectionWithError ( + rtcRtpTransceiverHandle handle, + rtcRtpTransceiverDirection value, + char* retVal, + int sz_retVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_GetCurrentDirection ( + rtcRtpTransceiverHandle handle, + rtcRtpTransceiverDirection* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_GetFiredDirection ( + rtcRtpTransceiverHandle handle, + rtcRtpTransceiverDirection* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_StopStandard ( + rtcRtpTransceiverHandle handle, + char* value, + int sz_value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_SetCodecPreferences ( + rtcRtpTransceiverHandle handle, + rtcRtpCodecCapabilityListHandle value +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_GetTransceiverId ( + rtcRtpTransceiverHandle handle, + char* value, + int sz_value +) noexcept; } // extern "C" diff --git a/include/rtc_base_list.h b/include/rtc_base_list.h index 81a2b3ce03..3dc86b7450 100644 --- a/include/rtc_base_list.h +++ b/include/rtc_base_list.h @@ -74,6 +74,17 @@ class RTCBaseList : public RefCountInterface { void clear() { destroy_all(); } + bool removeAt(size_t index) { + if (index >= m_count) { + return false; + } + destroy(&m_items[index]); + m_count--; + for (size_t i = index; i < m_count; i++) { + m_items[i] = m_items[i + 1]; + } + } + protected: void destroy(T* rt) { reinterpret_cast(rt)->~T(); } diff --git a/src/interop/rtc_rtp_receiver_interop.cc b/src/interop/rtc_rtp_receiver_interop.cc index 563ada0d9d..1a63662c21 100644 --- a/src/interop/rtc_rtp_receiver_interop.cc +++ b/src/interop/rtc_rtp_receiver_interop.cc @@ -37,19 +37,10 @@ RTCRtpReceiver_GetStreamIds ( } ZERO_MEMORY(value, sz_value); CHECK_NATIVE_HANDLE(handle); - sz_value--; scoped_refptr p = static_cast(handle); - std::vector streamIds = p->stream_ids().std_vector(); - std::string strValue; - for (auto stream_id : streamIds) { - strValue += stream_id.std_string() + "\n"; - } - size_t len = std::min(strValue.size(), static_cast(sz_value)); - if (strValue.size() > 0 && len > 0) { - strncpy(value, strValue.c_str(), len); - value[len] = '\0'; - } + string strValue = string::join("\n", p->stream_ids()); + size_t len = strValue.copy_to(value, sz_value); return strValue.size() > len ? rtcResultU4::kBufferTooSmall : rtcResultU4::kSuccess; diff --git a/src/interop/rtc_rtp_sender_interop.cc b/src/interop/rtc_rtp_sender_interop.cc index 7ce8d174e8..88a4d68db6 100644 --- a/src/interop/rtc_rtp_sender_interop.cc +++ b/src/interop/rtc_rtp_sender_interop.cc @@ -4,8 +4,6 @@ #include "rtc_dtmf_sender.h" #include "rtc_dtls_transport.h" -#include - using namespace libwebrtc; rtcResultU4 LIB_WEBRTC_CALL @@ -76,19 +74,10 @@ RTCRtpSender_GetStreamIds ( } ZERO_MEMORY(value, sz_value); CHECK_NATIVE_HANDLE(handle); - sz_value--; scoped_refptr p = static_cast(handle); - std::vector streamIds = p->stream_ids().std_vector(); - std::string strValue; - for (auto stream_id : streamIds) { - strValue += stream_id.std_string() + "\n"; - } - size_t len = std::min(strValue.size(), static_cast(sz_value)); - if (strValue.size() > 0 && len > 0) { - strncpy(value, strValue.c_str(), len); - value[len] = '\0'; - } + string strValue = string::join("\n", p->stream_ids()); + size_t len = strValue.copy_to(value, sz_value); return strValue.size() > len ? rtcResultU4::kBufferTooSmall : rtcResultU4::kSuccess; @@ -102,16 +91,8 @@ RTCRtpSender_SetStreamIds ( { CHECK_NATIVE_HANDLE(handle); - std::string input(value ? value : '\0'); - std::vector streamIds; - std::stringstream ss(input); - std::string line; - - while (std::getline(ss, line)) { - streamIds.push_back(line); - } - scoped_refptr p = static_cast(handle); + vector streamIds = string(value).split("\n"); p->set_stream_ids(streamIds); return rtcResultU4::kSuccess; } diff --git a/src/interop/rtc_rtp_transceiver_interop.cc b/src/interop/rtc_rtp_transceiver_interop.cc index a33cacaf4a..561a3701d4 100644 --- a/src/interop/rtc_rtp_transceiver_interop.cc +++ b/src/interop/rtc_rtp_transceiver_interop.cc @@ -1,5 +1,248 @@ #include "rtc_rtp_transceiver.h" #include "interop_api.h" +#include + using namespace libwebrtc; +/* + * ---------------------------------------------------------------------- + * RTCRtpTransceiverInit interop methods + * ---------------------------------------------------------------------- + */ + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiverInit_Create ( + rtcRtpTransceiverDirection direction, + const char* stream_ids, + /* [optional, in] */ rtcRtpEncodingParametersListHandle encodings, + rtcRtpTransceiverInitHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + + vector streamIds = string(stream_ids).split("\n"); + vector> vecEncoding; + scoped_refptr pList = static_cast(encodings); + if (pList) { + vecEncoding = pList->to_vector(); + } + scoped_refptr p = RTCRtpTransceiverInit::Create( + static_cast(direction), + streamIds, + vecEncoding + ); + *pOutRetVal = static_cast(p.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiverInit_GetDirection ( + rtcRtpTransceiverInitHandle handle, + rtcRtpTransceiverDirection* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcRtpTransceiverDirection, RTCRtpTransceiverInit, direction); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiverInit_SetDirection ( + rtcRtpTransceiverInitHandle handle, + rtcRtpTransceiverDirection value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, RTCRtpTransceiverDirection, RTCRtpTransceiverInit, set_direction); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiverInit_GetStreamIds ( + rtcRtpTransceiverInitHandle handle, + char* value, + int sz_value +) noexcept +{ + CHECK_POINTER(value); + if (sz_value < 1) { + return rtcResultU4::kBufferTooSmall; + } + ZERO_MEMORY(value, sz_value); + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr p = static_cast(handle); + string strValue = string::join("\n", p->stream_ids()); + size_t len = strValue.copy_to(value, sz_value); + return strValue.size() > len + ? rtcResultU4::kBufferTooSmall + : rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiverInit_SetStreamIds ( + rtcRtpTransceiverInitHandle handle, + const char* value +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr p = static_cast(handle); + vector streamIds = string(value).split("\n"); + p->set_stream_ids(streamIds); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiverInit_GetEncodings ( + rtcRtpTransceiverInitHandle handle, + rtcRtpEncodingParametersListHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_LIST_HANDLE(handle, pOutRetVal, rtcRtpEncodingParametersListHandle, RTCRtpTransceiverInit, RTCRtpEncodingParametersList, send_encodings); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiverInit_SetEncodings ( + rtcRtpTransceiverInitHandle handle, + rtcRtpEncodingParametersListHandle value +) noexcept +{ + DECLARE_SET_LIST_HANDLE(handle, value, RTCRtpTransceiverInit, RTCRtpEncodingParametersList, set_send_encodings); +} + +/* + * ---------------------------------------------------------------------- + * RTCRtpTransceiver interop methods + * ---------------------------------------------------------------------- + */ + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_GetMediaType ( + rtcRtpTransceiverHandle handle, + rtcMediaType* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcMediaType, RTCRtpTransceiver, media_type); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_GetMid ( + rtcRtpTransceiverHandle handle, + char* value, + int sz_value +) noexcept +{ + DECLARE_GET_STRING(handle, value, sz_value, RTCRtpTransceiver, mid); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_GetSender ( + rtcRtpTransceiverHandle handle, + rtcRtpSenderHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcRtpSenderHandle, RTCRtpTransceiver, sender().release); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_GetReceiver ( + rtcRtpTransceiverHandle handle, + rtcRtpReceiverHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcRtpReceiverHandle, RTCRtpTransceiver, receiver().release); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_Stopped ( + rtcRtpTransceiverHandle handle, + rtcBool32* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcBool32, RTCRtpTransceiver, Stopped); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_Stopping ( + rtcRtpTransceiverHandle handle, + rtcBool32* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcBool32, RTCRtpTransceiver, Stopping); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_GetDirection ( + rtcRtpTransceiverHandle handle, + rtcRtpTransceiverDirection* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcRtpTransceiverDirection, RTCRtpTransceiver, direction); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_SetDirectionWithError ( + rtcRtpTransceiverHandle handle, + rtcRtpTransceiverDirection value, + char* retVal, + int sz_retVal +) noexcept +{ + CHECK_POINTER(retVal); + if (sz_retVal < 1) { + return rtcResultU4::kBufferTooSmall; + } + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr p = static_cast(handle); + string strValue = p->SetDirectionWithError(static_cast(value)); + size_t len = strValue.copy_to(retVal, sz_retVal); + return strValue.size() > len + ? rtcResultU4::kBufferTooSmall + : rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_GetCurrentDirection ( + rtcRtpTransceiverHandle handle, + rtcRtpTransceiverDirection* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcRtpTransceiverDirection, RTCRtpTransceiver, current_direction); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_GetFiredDirection ( + rtcRtpTransceiverHandle handle, + rtcRtpTransceiverDirection* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcRtpTransceiverDirection, RTCRtpTransceiver, fired_direction); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_StopStandard ( + rtcRtpTransceiverHandle handle, + char* value, + int sz_value +) noexcept +{ + DECLARE_GET_STRING(handle, value, sz_value, RTCRtpTransceiver, StopStandard); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_SetCodecPreferences ( + rtcRtpTransceiverHandle handle, + rtcRtpCodecCapabilityListHandle value +) noexcept +{ + DECLARE_SET_LIST_HANDLE(handle, value, RTCRtpTransceiver, RTCRtpCodecCapabilityList, SetCodecPreferences); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiver_GetTransceiverId ( + rtcRtpTransceiverHandle handle, + char* value, + int sz_value +) noexcept +{ + DECLARE_GET_STRING(handle, value, sz_value, RTCRtpTransceiver, transceiver_id); +} From 504cf64045764ceea7ae32f18b1e138c213e3b44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Fri, 3 Jan 2025 07:00:25 +0300 Subject: [PATCH 51/69] Added rtc_peerconnection_impl.cc codes --- include/base/portable.h | 2 +- include/interop_api.h | 335 +++++++++++ include/rtc_base_list.h | 11 - include/rtc_peerconnection.h | 35 ++ include/rtc_rtp_receiver.h | 16 + include/rtc_rtp_sender.h | 17 + include/rtc_rtp_transceiver.h | 16 + src/interop/rtc_peerconnection_interop.cc | 686 ++++++++++++++++++++++ src/rtc_peerconnection_impl.cc | 169 ++++++ src/rtc_peerconnection_impl.h | 61 ++ src/rtc_rtp_receiver_impl.cc | 15 + src/rtc_rtp_receiver_impl.h | 9 + src/rtc_rtp_sender_impl.cc | 15 + src/rtc_rtp_sender_impl.h | 10 + src/rtc_rtp_transceiver_impl.cc | 15 + src/rtc_rtp_transceiver_impl.h | 9 + 16 files changed, 1409 insertions(+), 12 deletions(-) diff --git a/include/base/portable.h b/include/base/portable.h index 3d71e9dcd0..7e4bc0a558 100644 --- a/include/base/portable.h +++ b/include/base/portable.h @@ -79,7 +79,7 @@ class string { return *this; } - inline size_t size() { return m_length; } + inline size_t size() const { return m_length; } inline const char* c_string() const { return m_dynamic == 0 ? m_buf : m_dynamic; diff --git a/include/interop_api.h b/include/interop_api.h index 7ddb7bbb74..b93d2ee284 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -360,6 +360,12 @@ using rtcRefCountedObjectHandle = rtcObjectHandle; /// Opaque handle to a native RTCPeerConnectionFactory interop object. using rtcPeerConnectionFactoryHandle = rtcRefCountedObjectHandle; +/// Opaque handle to a native RTCStatsMemberList interop object. +using rtcStatsMemberListHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native MediaRTCStatsList interop object. +using rtcMediaRTCStatsListHandle = rtcRefCountedObjectHandle; + /// Opaque handle to a native RTCPeerConnection interop object. using rtcPeerConnectionHandle = rtcRefCountedObjectHandle; @@ -510,15 +516,24 @@ using rtcRtpParametersHandle = rtcRefCountedObjectHandle; /// Opaque handle to a native RTCRtpReceiver interop object. using rtcRtpReceiverHandle = rtcRefCountedObjectHandle; +/// Opaque handle to a native RTCRtpReceiverList interop object. +using rtcRtpReceiverListHandle = rtcRefCountedObjectHandle; + /// Opaque handle to a native RTCRtpSender interop object. using rtcRtpSenderHandle = rtcRefCountedObjectHandle; +/// Opaque handle to a native RTCRtpSenderList interop object. +using rtcRtpSenderListHandle = rtcRefCountedObjectHandle; + /// Opaque handle to a native RTCRtpTransceiverInit interop object. using rtcRtpTransceiverInitHandle = rtcRefCountedObjectHandle; /// Opaque handle to a native RTCRtpTransceiver interop object. using rtcRtpTransceiverHandle = rtcRefCountedObjectHandle; +/// Opaque handle to a native RTCRtpTransceiverList interop object. +using rtcRtpTransceiverListHandle = rtcRefCountedObjectHandle; + /// Opaque handle to a native RTCSessionDescription interop object. using rtcSessionDescriptionHandle = rtcRefCountedObjectHandle; @@ -622,6 +637,86 @@ struct rtcDtlsTransportObserverCallbacks { rtcDtlsTransportErrorDelegate Error{}; }; +/** + * RTCPeerConnectionObserverCallbacks + */ +using rtcSignalingStateChangedDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, rtcSignalingState state); + +using rtcConnectionStateChangedDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, rtcPeerConnectionState state); + +using rtcIceGatheringStateChangedDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, rtcIceGatheringState state); + +using rtcIceConnectionStateChangedDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, rtcIceConnectionState state); + +using rtcIceCandidateReadytoSendDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, rtcIceCandidateHandle iceCandidate); + +using rtcStreamAddedRemovedDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, rtcMediaStreamHandle mediaStream); + +using rtcDataChannelAddedDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, rtcDataChannelHandle dataChannel); + +using rtcRenegotiationNeededDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data); + +using rtcTransceiverAddedDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, rtcRtpTransceiverHandle rtpTransceiver); + +using rtcTrackAddedDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, rtcMediaStreamListHandle mediaStreamList, rtcRtpReceiverHandle rtpReceiver); + +using rtcTrackRemovedDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, rtcRtpReceiverHandle rtpReceiver); + +/** + * Callback delegate structure for RTCPeerConnectionObserver. + */ +struct rtcPeerConnectionObserverCallbacks { + rtcObjectHandle UserData{}; + rtcSignalingStateChangedDelegate SignalingStateChanged{}; + rtcConnectionStateChangedDelegate ConnectionStateChanged{}; + rtcIceGatheringStateChangedDelegate IceGatheringStateChanged{}; + rtcIceConnectionStateChangedDelegate IceConnectionStateChanged{}; + rtcIceCandidateReadytoSendDelegate IceCandidateReadytoSend{}; + rtcStreamAddedRemovedDelegate StreamAdded{}; + rtcStreamAddedRemovedDelegate StreamRemoved{}; + rtcDataChannelAddedDelegate DataChannelAdded{}; + rtcRenegotiationNeededDelegate RenegotiationNeeded{}; + rtcTransceiverAddedDelegate TransceiverAdded{}; + rtcTrackAddedDelegate TrackAdded{}; + rtcTrackRemovedDelegate TrackRemoved{}; +}; // end struct rtcPeerConnectionObserverCallbacks + +/*-----------------------------------------------------------------*/ + +using rtcOnStatsCollectorSuccessDelegate = void(LIB_WEBRTC_CALL*)( + rtcMediaRTCStatsListHandle reports); + +using rtcOnStatsCollectorFailureDelegate = void(LIB_WEBRTC_CALL*)( + const char* error, int error_len); + +using rtcOnSdpCreateSuccessDelegate = void(LIB_WEBRTC_CALL*)( + const char* sdp, int sdp_len, const char* type, int type_len); + +using rtcOnSdpCreateFailureDelegate = void(LIB_WEBRTC_CALL*)( + const char* error, int error_len); + +using rtcOnSetSdpSuccessDelegate = void(LIB_WEBRTC_CALL*)(); + +using rtcOnSetSdpFailureDelegate = void(LIB_WEBRTC_CALL*)( + const char* error, int error_len); + +using rtcOnGetSdpSuccessDelegate = void(LIB_WEBRTC_CALL*)( + const char* sdp, int sdp_len, const char* type, int type_len); + +using rtcOnGetSdpFailureDelegate = void(LIB_WEBRTC_CALL*)( + const char* error, int error_len); + /* * ---------------------------------------------------------------------- * LibWebRTC interop methods @@ -3214,6 +3309,246 @@ RTCRtpTransceiver_GetTransceiverId ( int sz_value ) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCPeerConnection interop methods + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_IsInitialized ( + rtcPeerConnectionHandle handle, + rtcBool32* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_AddStream ( + rtcPeerConnectionHandle handle, + rtcMediaStreamHandle stream, + int* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_RemoveStream ( + rtcPeerConnectionHandle handle, + rtcMediaStreamHandle stream, + int* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_CreateLocalMediaStream ( + rtcPeerConnectionHandle handle, + const char* stream_id, + rtcMediaStreamHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_CreateDataChannel ( + rtcPeerConnectionHandle handle, + const char* label, + /* [optional, in] */ rtcDataChannelInit* dataChannelDict, + rtcDataChannelHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_CreateOffer ( + rtcPeerConnectionHandle handle, + rtcOnSdpCreateSuccessDelegate success, + rtcOnSdpCreateFailureDelegate failure, + rtcMediaConstraintsHandle constraints +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_CreateAnswer ( + rtcPeerConnectionHandle handle, + rtcOnSdpCreateSuccessDelegate success, + rtcOnSdpCreateFailureDelegate failure, + rtcMediaConstraintsHandle constraints +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_RestartIce ( + rtcPeerConnectionHandle handle +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_Close ( + rtcPeerConnectionHandle handle +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_SetLocalDescription ( + rtcPeerConnectionHandle handle, + const char* sdp, + const char* type, + rtcOnSetSdpSuccessDelegate success, + rtcOnSetSdpFailureDelegate failure +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_SetRemoteDescription ( + rtcPeerConnectionHandle handle, + const char* sdp, + const char* type, + rtcOnSetSdpSuccessDelegate success, + rtcOnSetSdpFailureDelegate failure +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetLocalDescription ( + rtcPeerConnectionHandle handle, + rtcOnGetSdpSuccessDelegate success, + rtcOnGetSdpFailureDelegate failure +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetRemoteDescription ( + rtcPeerConnectionHandle handle, + rtcOnGetSdpSuccessDelegate success, + rtcOnGetSdpFailureDelegate failure +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_AddCandidate ( + rtcPeerConnectionHandle handle, + const char* mid, + int mid_mline_index, + const char* candiate +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_RegisterObserver ( + rtcPeerConnectionHandle handle, + rtcPeerConnectionObserverCallbacks* callbacks +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_UnregisterObserver ( + rtcPeerConnectionHandle handle +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetLocalStreams ( + rtcPeerConnectionHandle handle, + rtcMediaStreamListHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetRemoteStreams ( + rtcPeerConnectionHandle handle, + rtcMediaStreamListHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetSenderStats ( + rtcPeerConnectionHandle handle, + rtcRtpSenderHandle sender, + rtcOnStatsCollectorSuccessDelegate success, + rtcOnStatsCollectorFailureDelegate failure, + rtcBool32* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetReceiverStats ( + rtcPeerConnectionHandle handle, + rtcRtpReceiverHandle receiver, + rtcOnStatsCollectorSuccessDelegate success, + rtcOnStatsCollectorFailureDelegate failure, + rtcBool32* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetStats ( + rtcPeerConnectionHandle handle, + rtcOnStatsCollectorSuccessDelegate success, + rtcOnStatsCollectorFailureDelegate failure +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_AddTransceiver1 ( + rtcPeerConnectionHandle handle, + rtcMediaType media_type, + rtcRtpTransceiverHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_AddTransceiver2 ( + rtcPeerConnectionHandle handle, + rtcMediaTrackHandle track, + rtcRtpTransceiverHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_AddTransceiver3 ( + rtcPeerConnectionHandle handle, + rtcMediaTrackHandle track, + rtcRtpTransceiverInitHandle init, + rtcRtpTransceiverHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_AddTrack ( + rtcPeerConnectionHandle handle, + rtcMediaTrackHandle track, + const char* stream_ids, + rtcRtpSenderHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_RemoveTrack ( + rtcPeerConnectionHandle handle, + rtcRtpSenderHandle sender, + rtcBool32* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetSenders ( + rtcPeerConnectionHandle handle, + rtcRtpSenderListHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetTransceivers ( + rtcPeerConnectionHandle handle, + rtcRtpTransceiverListHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetReceivers ( + rtcPeerConnectionHandle handle, + rtcRtpReceiverListHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetSignalingState ( + rtcPeerConnectionHandle handle, + rtcSignalingState* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetIceConnectionState ( + rtcPeerConnectionHandle handle, + rtcIceConnectionState* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetStandardizedIceConnectionState ( + rtcPeerConnectionHandle handle, + rtcIceConnectionState* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetPeerConnectionState ( + rtcPeerConnectionHandle handle, + rtcPeerConnectionState* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetIceGatheringState ( + rtcPeerConnectionHandle handle, + rtcIceGatheringState* pOutRetVal +) noexcept; + } // extern "C" #endif // LIB_WEBRTC_INTROP_API_HXX \ No newline at end of file diff --git a/include/rtc_base_list.h b/include/rtc_base_list.h index 3dc86b7450..81a2b3ce03 100644 --- a/include/rtc_base_list.h +++ b/include/rtc_base_list.h @@ -74,17 +74,6 @@ class RTCBaseList : public RefCountInterface { void clear() { destroy_all(); } - bool removeAt(size_t index) { - if (index >= m_count) { - return false; - } - destroy(&m_items[index]); - m_count--; - for (size_t i = index; i < m_count; i++) { - m_items[i] = m_items[i + 1]; - } - } - protected: void destroy(T* rt) { reinterpret_cast(rt)->~T(); } diff --git a/include/rtc_peerconnection.h b/include/rtc_peerconnection.h index 3d3b266959..0354c74a3e 100644 --- a/include/rtc_peerconnection.h +++ b/include/rtc_peerconnection.h @@ -1,6 +1,7 @@ #ifndef LIB_WEBRTC_RTC_PEERCONNECTION_HXX #define LIB_WEBRTC_RTC_PEERCONNECTION_HXX +#include "rtc_base_list.h" #include "rtc_audio_track.h" #include "rtc_data_channel.h" #include "rtc_sdp_parse_error.h" @@ -106,6 +107,22 @@ class RTCStatsMember : public RefCountInterface { virtual ~RTCStatsMember() {} }; +/** + * class RTCStatsMemberList + */ +class RTCStatsMemberList : public RTCBaseList> { + public: + LIB_WEBRTC_API static scoped_refptr Create( + const vector>& source); + + protected: + RTCStatsMemberList(const vector>& source) + : RTCBaseList>(source) + {} + + ~RTCStatsMemberList() {} +}; // end class RTCStatsMemberList + class MediaRTCStats : public RefCountInterface { public: virtual const string id() = 0; @@ -119,6 +136,22 @@ class MediaRTCStats : public RefCountInterface { virtual const vector> Members() = 0; }; +/** + * class MediaRTCStatsList + */ +class MediaRTCStatsList : public RTCBaseList> { + public: + LIB_WEBRTC_API static scoped_refptr Create( + const vector>& source); + + protected: + MediaRTCStatsList(const vector>& source) + : RTCBaseList>(source) + {} + + ~MediaRTCStatsList() {} +}; // end class MediaRTCStatsList + typedef fixed_size_function> reports)> OnStatsCollectorSuccess; @@ -267,6 +300,8 @@ class RTCPeerConnection : public RefCountInterface { virtual RTCIceGatheringState ice_gathering_state() = 0; + virtual RTCPeerConnectionObserver* GetObserver() = 0; + protected: virtual ~RTCPeerConnection() {} }; diff --git a/include/rtc_rtp_receiver.h b/include/rtc_rtp_receiver.h index 5bfcda53c1..9ebde332f6 100644 --- a/include/rtc_rtp_receiver.h +++ b/include/rtc_rtp_receiver.h @@ -58,6 +58,22 @@ class RTCRtpReceiver : public RefCountInterface { // scoped_refptr frame_transformer) = 0; }; +/** + * class RTCRtpReceiverList + */ +class RTCRtpReceiverList : public RTCBaseList> { + public: + LIB_WEBRTC_API static scoped_refptr Create( + const vector>& source); + + protected: + RTCRtpReceiverList(const vector>& source) + : RTCBaseList>(source) + {} + + ~RTCRtpReceiverList() {} +}; // end class RTCRtpReceiverList + } // namespace libwebrtc #endif // !LIB_WEBRTC_RTP_RECEIVER_H_ \ No newline at end of file diff --git a/include/rtc_rtp_sender.h b/include/rtc_rtp_sender.h index 9c2f73249b..aa3d21bf1c 100644 --- a/include/rtc_rtp_sender.h +++ b/include/rtc_rtp_sender.h @@ -5,6 +5,7 @@ #include "base/scoped_ref_ptr.h" #include "rtc_rtp_parameters.h" #include "rtc_types.h" +#include "rtc_base_list.h" namespace libwebrtc { @@ -41,6 +42,22 @@ class RTCRtpSender : public RefCountInterface { virtual scoped_refptr dtmf_sender() const = 0; }; +/** + * class RTCRtpSenderList + */ +class RTCRtpSenderList : public RTCBaseList> { + public: + LIB_WEBRTC_API static scoped_refptr Create( + const vector>& source); + + protected: + RTCRtpSenderList(const vector>& source) + : RTCBaseList>(source) + {} + + ~RTCRtpSenderList() {} +}; // end class RTCRtpSenderList + } // namespace libwebrtc #endif // LIB_WEBRTC_RTC_TYPES_HXX \ No newline at end of file diff --git a/include/rtc_rtp_transceiver.h b/include/rtc_rtp_transceiver.h index ecf24f45b6..6af69c4957 100644 --- a/include/rtc_rtp_transceiver.h +++ b/include/rtc_rtp_transceiver.h @@ -61,6 +61,22 @@ class RTCRtpTransceiver : public RefCountInterface { virtual const string transceiver_id() const = 0; }; +/** + * class RTCRtpTransceiverList + */ +class RTCRtpTransceiverList : public RTCBaseList> { + public: + LIB_WEBRTC_API static scoped_refptr Create( + const vector>& source); + + protected: + RTCRtpTransceiverList(const vector>& source) + : RTCBaseList>(source) + {} + + ~RTCRtpTransceiverList() {} +}; // end class RTCRtpTransceiverList + } // namespace libwebrtc #endif // LIB_WEBRTC_RTC_TYPES_HXX diff --git a/src/interop/rtc_peerconnection_interop.cc b/src/interop/rtc_peerconnection_interop.cc index 036f6c362b..f53fb0eb4e 100644 --- a/src/interop/rtc_peerconnection_interop.cc +++ b/src/interop/rtc_peerconnection_interop.cc @@ -1,4 +1,690 @@ #include "rtc_peerconnection.h" +#include "src/rtc_peerconnection_impl.h" #include "interop_api.h" using namespace libwebrtc; + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_IsInitialized ( + rtcPeerConnectionHandle handle, + rtcBool32* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcBool32, RTCPeerConnection, IsInitialized); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_AddStream ( + rtcPeerConnectionHandle handle, + rtcMediaStreamHandle stream, + int* pOutRetVal +) noexcept +{ + if (pOutRetVal) { + *pOutRetVal = -1; + } + CHECK_POINTER_EX(stream, rtcResultU4::kInvalidParameter); + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr p = static_cast(handle); + scoped_refptr pStream = static_cast(stream); + int retVal = p->AddStream(pStream); + if (pOutRetVal) { + *pOutRetVal = retVal; + } + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_RemoveStream ( + rtcPeerConnectionHandle handle, + rtcMediaStreamHandle stream, + int* pOutRetVal +) noexcept +{ + if (pOutRetVal) { + *pOutRetVal = -1; + } + CHECK_POINTER_EX(stream, rtcResultU4::kInvalidParameter); + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr p = static_cast(handle); + scoped_refptr pStream = static_cast(stream); + int retVal = p->RemoveStream(pStream); + if (pOutRetVal) { + *pOutRetVal = retVal; + } + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_CreateLocalMediaStream ( + rtcPeerConnectionHandle handle, + const char* stream_id, + rtcMediaStreamHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr p = static_cast(handle); + scoped_refptr pStream = p->CreateLocalMediaStream(string(stream_id)); + *pOutRetVal = static_cast(pStream.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_CreateDataChannel ( + rtcPeerConnectionHandle handle, + const char* label, + /* [optional, in] */ rtcDataChannelInit* dataChannelDict, + rtcDataChannelHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + CHECK_NATIVE_HANDLE(handle); + + RTCDataChannelInit initDict{}; + if (dataChannelDict) { + initDict.ordered = static_cast(dataChannelDict->ordered); + initDict.reliable = static_cast(dataChannelDict->reliable); + initDict.maxRetransmitTime = dataChannelDict->maxRetransmitTime; + initDict.maxRetransmits = dataChannelDict->maxRetransmits; + initDict.protocol = string(dataChannelDict->protocol != rtcDataChannelProtocol::kSCTP ? "quic" : "sctp"); + initDict.negotiated = static_cast(dataChannelDict->negotiated); + initDict.id = dataChannelDict->id; + } + + scoped_refptr p = static_cast(handle); + scoped_refptr pDataChannel = p->CreateDataChannel(string(label), &initDict); + *pOutRetVal = static_cast(pDataChannel.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_CreateOffer ( + rtcPeerConnectionHandle handle, + rtcOnSdpCreateSuccessDelegate success, + rtcOnSdpCreateFailureDelegate failure, + rtcMediaConstraintsHandle constraints +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(constraints, rtcResultU4::kInvalidParameter); + + scoped_refptr p = static_cast(handle); + OnSdpCreateSuccess fn_success = [success](const string sdp, const string type) { + if (success) { + success( + sdp.c_string(), + static_cast(sdp.size()), + type.c_string(), + static_cast(type.size()) + ); + } + }; + OnSdpCreateFailure fn_failure = [failure](const char* erro) { + if (failure) { + failure( + erro, + strlen(erro ? erro : "") + ); + } + }; + scoped_refptr pConstraints= static_cast(constraints); + p->CreateOffer(fn_success, fn_failure, pConstraints); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_CreateAnswer ( + rtcPeerConnectionHandle handle, + rtcOnSdpCreateSuccessDelegate success, + rtcOnSdpCreateFailureDelegate failure, + rtcMediaConstraintsHandle constraints +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(constraints, rtcResultU4::kInvalidParameter); + + scoped_refptr p = static_cast(handle); + OnSdpCreateSuccess fn_success = [success](const string sdp, const string type) { + if (success) { + success( + sdp.c_string(), + static_cast(sdp.size()), + type.c_string(), + static_cast(type.size()) + ); + } + }; + OnSdpCreateFailure fn_failure = [failure](const char* erro) { + if (failure) { + failure( + erro, + strlen(erro ? erro : "") + ); + } + }; + scoped_refptr pConstraints= static_cast(constraints); + p->CreateAnswer(fn_success, fn_failure, pConstraints); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_RestartIce ( + rtcPeerConnectionHandle handle +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + scoped_refptr p = static_cast(handle); + p->RestartIce(); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_Close ( + rtcPeerConnectionHandle handle +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + + // unregistered + RTCPeerConnection_UnregisterObserver(handle); + + scoped_refptr p = static_cast(handle); + p->Close(); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_SetLocalDescription ( + rtcPeerConnectionHandle handle, + const char* sdp, + const char* type, + rtcOnSetSdpSuccessDelegate success, + rtcOnSetSdpFailureDelegate failure +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); + + OnSetSdpSuccess fn_success = [success]() { + if (success) { + success(); + } + }; + OnSetSdpFailure fn_failure = [failure](const char* error) { + if (failure) { + failure( + error, + strlen(error ? error : "") + ); + } + }; + scoped_refptr p = static_cast(handle); + p->SetLocalDescription(string(sdp), string(type), fn_success, fn_failure); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_SetRemoteDescription ( + rtcPeerConnectionHandle handle, + const char* sdp, + const char* type, + rtcOnSetSdpSuccessDelegate success, + rtcOnSetSdpFailureDelegate failure +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); + + OnSetSdpSuccess fn_success = [success]() { + if (success) { + success(); + } + }; + OnSetSdpFailure fn_failure = [failure](const char* error) { + if (failure) { + failure( + error, + strlen(error ? error : "") + ); + } + }; + scoped_refptr p = static_cast(handle); + p->SetRemoteDescription(string(sdp), string(type), fn_success, fn_failure); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetLocalDescription ( + rtcPeerConnectionHandle handle, + rtcOnGetSdpSuccessDelegate success, + rtcOnGetSdpFailureDelegate failure +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); + + OnGetSdpSuccess fn_success = [success](const char* sdp, const char* type) { + if (success) { + success( + sdp, + strlen(sdp ? sdp : ""), + type, + strlen(type ? type : "") + ); + } + }; + OnGetSdpFailure fn_failure = [failure](const char* error) { + if (failure) { + failure( + error, + strlen(error ? error : "") + ); + } + }; + scoped_refptr p = static_cast(handle); + p->GetLocalDescription(fn_success, fn_failure); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetRemoteDescription ( + rtcPeerConnectionHandle handle, + rtcOnGetSdpSuccessDelegate success, + rtcOnGetSdpFailureDelegate failure +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); + + OnGetSdpSuccess fn_success = [success](const char* sdp, const char* type) { + if (success) { + success( + sdp, + strlen(sdp ? sdp : ""), + type, + strlen(type ? type : "") + ); + } + }; + OnGetSdpFailure fn_failure = [failure](const char* error) { + if (failure) { + failure( + error, + strlen(error ? error : "") + ); + } + }; + scoped_refptr p = static_cast(handle); + p->GetRemoteDescription(fn_success, fn_failure); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_AddCandidate ( + rtcPeerConnectionHandle handle, + const char* mid, + int mid_mline_index, + const char* candiate +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr p = static_cast(handle); + p->AddCandidate( + string(mid), + mid_mline_index, + string(candiate) + ); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_RegisterObserver ( + rtcPeerConnectionHandle handle, + rtcPeerConnectionObserverCallbacks* callbacks +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); + + // unregistered + RTCPeerConnection_UnregisterObserver(handle); + + scoped_refptr p = static_cast(handle); + RTCPeerConnectionObserver* pObserver = static_cast( + new RTCPeerConnectionObserverImpl(static_cast(callbacks)) + ); + p->RegisterRTCPeerConnectionObserver(pObserver); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_UnregisterObserver ( + rtcPeerConnectionHandle handle +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr p = static_cast(handle); + RTCPeerConnectionObserverImpl* pObserverImpl = static_cast(p->GetObserver()); + p->DeRegisterRTCPeerConnectionObserver(); + if (pObserverImpl) { + delete pObserverImpl; + } + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetLocalStreams ( + rtcPeerConnectionHandle handle, + rtcMediaStreamListHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_LIST_HANDLE(handle, pOutRetVal, rtcMediaStreamListHandle, RTCPeerConnection, RTCMediaStreamList, local_streams); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetRemoteStreams ( + rtcPeerConnectionHandle handle, + rtcMediaStreamListHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_LIST_HANDLE(handle, pOutRetVal, rtcMediaStreamListHandle, RTCPeerConnection, RTCMediaStreamList, remote_streams); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetSenderStats ( + rtcPeerConnectionHandle handle, + rtcRtpSenderHandle sender, + rtcOnStatsCollectorSuccessDelegate success, + rtcOnStatsCollectorFailureDelegate failure, + rtcBool32* pOutRetVal +) noexcept +{ + if (pOutRetVal) { + *pOutRetVal = rtcBool32::kFalse; + } + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(sender, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); + + OnStatsCollectorSuccess fn_success = [success](const vector> reports) { + if (success) { + scoped_refptr pList = MediaRTCStatsList::Create(reports); + success( + static_cast(pList.release()) + ); + } + }; + OnStatsCollectorFailure fn_failure = [failure](const char* error) { + if (failure) { + failure( + error, + strlen(error ? error : "") + ); + } + }; + scoped_refptr p = static_cast(handle); + scoped_refptr pSender = static_cast(sender); + bool retVal = p->GetStats(pSender, fn_success, fn_failure); + if (pOutRetVal) { + *pOutRetVal = static_cast(retVal); + } + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetReceiverStats ( + rtcPeerConnectionHandle handle, + rtcRtpReceiverHandle receiver, + rtcOnStatsCollectorSuccessDelegate success, + rtcOnStatsCollectorFailureDelegate failure, + rtcBool32* pOutRetVal +) noexcept +{ + if (pOutRetVal) { + *pOutRetVal = rtcBool32::kFalse; + } + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(receiver, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); + + OnStatsCollectorSuccess fn_success = [success](const vector> reports) { + if (success) { + scoped_refptr pList = MediaRTCStatsList::Create(reports); + success( + static_cast(pList.release()) + ); + } + }; + OnStatsCollectorFailure fn_failure = [failure](const char* error) { + if (failure) { + failure( + error, + strlen(error ? error : "") + ); + } + }; + scoped_refptr p = static_cast(handle); + scoped_refptr pReceiver = static_cast(receiver); + bool retVal = p->GetStats(pReceiver, fn_success, fn_failure); + if (pOutRetVal) { + *pOutRetVal = static_cast(retVal); + } + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetStats ( + rtcPeerConnectionHandle handle, + rtcOnStatsCollectorSuccessDelegate success, + rtcOnStatsCollectorFailureDelegate failure +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); + + OnStatsCollectorSuccess fn_success = [success](const vector> reports) { + if (success) { + scoped_refptr pList = MediaRTCStatsList::Create(reports); + success( + static_cast(pList.release()) + ); + } + }; + OnStatsCollectorFailure fn_failure = [failure](const char* error) { + if (failure) { + failure( + error, + strlen(error ? error : "") + ); + } + }; + scoped_refptr p = static_cast(handle); + p->GetStats(fn_success, fn_failure); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_AddTransceiver1 ( + rtcPeerConnectionHandle handle, + rtcMediaType media_type, + rtcRtpTransceiverHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr p = static_cast(handle); + scoped_refptr pTransceiver = p->AddTransceiver(static_cast(media_type)); + *pOutRetVal = static_cast(pTransceiver.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_AddTransceiver2 ( + rtcPeerConnectionHandle handle, + rtcMediaTrackHandle track, + rtcRtpTransceiverHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(track, rtcResultU4::kInvalidParameter); + + scoped_refptr p = static_cast(handle); + scoped_refptr pTrack = static_cast(track); + scoped_refptr pTransceiver = p->AddTransceiver(pTrack); + *pOutRetVal = static_cast(pTransceiver.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_AddTransceiver3 ( + rtcPeerConnectionHandle handle, + rtcMediaTrackHandle track, + rtcRtpTransceiverInitHandle init, + rtcRtpTransceiverHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(track, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(init, rtcResultU4::kInvalidParameter); + + scoped_refptr p = static_cast(handle); + scoped_refptr pTrack = static_cast(track); + scoped_refptr pInit = static_cast(init); + scoped_refptr pTransceiver = p->AddTransceiver(pTrack, pInit); + *pOutRetVal = static_cast(pTransceiver.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_AddTrack ( + rtcPeerConnectionHandle handle, + rtcMediaTrackHandle track, + const char* stream_ids, + rtcRtpSenderHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(track, rtcResultU4::kInvalidParameter); + + vector streamIds = string(stream_ids).split("\n"); + scoped_refptr p = static_cast(handle); + scoped_refptr pTrack = static_cast(track); + scoped_refptr pSender = p->AddTrack(pTrack, streamIds); + *pOutRetVal = static_cast(pSender.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_RemoveTrack ( + rtcPeerConnectionHandle handle, + rtcRtpSenderHandle sender, + rtcBool32* pOutRetVal +) noexcept +{ + if (pOutRetVal) { + *pOutRetVal = rtcBool32::kFalse; + } + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(sender, rtcResultU4::kInvalidParameter); + + scoped_refptr p = static_cast(handle); + scoped_refptr pSender = static_cast(sender); + bool retVal = p->RemoveTrack(pSender); + if (pOutRetVal) { + *pOutRetVal = static_cast(retVal); + } + return rtcResultU4::kInvalidOperation; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetSenders ( + rtcPeerConnectionHandle handle, + rtcRtpSenderListHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_LIST_HANDLE(handle, pOutRetVal, rtcRtpSenderListHandle, RTCPeerConnection, RTCRtpSenderList, senders); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetTransceivers ( + rtcPeerConnectionHandle handle, + rtcRtpTransceiverListHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_LIST_HANDLE(handle, pOutRetVal, rtcRtpTransceiverListHandle, RTCPeerConnection, RTCRtpTransceiverList, transceivers); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetReceivers ( + rtcPeerConnectionHandle handle, + rtcRtpReceiverListHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_LIST_HANDLE(handle, pOutRetVal, rtcRtpReceiverListHandle, RTCPeerConnection, RTCRtpReceiverList, receivers); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetSignalingState ( + rtcPeerConnectionHandle handle, + rtcSignalingState* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcSignalingState, RTCPeerConnection, signaling_state); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetIceConnectionState ( + rtcPeerConnectionHandle handle, + rtcIceConnectionState* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcIceConnectionState, RTCPeerConnection, ice_connection_state); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetStandardizedIceConnectionState ( + rtcPeerConnectionHandle handle, + rtcIceConnectionState* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcIceConnectionState, RTCPeerConnection, standardized_ice_connection_state); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetPeerConnectionState ( + rtcPeerConnectionHandle handle, + rtcPeerConnectionState* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcPeerConnectionState, RTCPeerConnection, peer_connection_state); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetIceGatheringState ( + rtcPeerConnectionHandle handle, + rtcIceGatheringState* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcIceGatheringState, RTCPeerConnection, ice_gathering_state); +} diff --git a/src/rtc_peerconnection_impl.cc b/src/rtc_peerconnection_impl.cc index a1a5a722e8..7b202e25fe 100644 --- a/src/rtc_peerconnection_impl.cc +++ b/src/rtc_peerconnection_impl.cc @@ -16,6 +16,8 @@ #include "rtc_rtp_sender_impl.h" #include "rtc_rtp_transceiver_impl.h" +#include "interop_api.h" + using rtc::Thread; static std::map RTCStatsMemberList::Create( + const vector>& source) { + return new RefCountedObject(source); +} + +RTCStatsMemberListImpl::RTCStatsMemberListImpl( + const vector>& source) + : RTCStatsMemberList(source) { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor "; +} + +RTCStatsMemberListImpl::~RTCStatsMemberListImpl() { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; +} + +scoped_refptr MediaRTCStatsList::Create( + const vector>& source) { + return new RefCountedObject(source); +} + +MediaRTCStatsListImpl::MediaRTCStatsListImpl( + const vector>& source) + : MediaRTCStatsList(source) { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor "; +} + +MediaRTCStatsListImpl::~MediaRTCStatsListImpl() { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; +} + +/** + * class RTCPeerConnectionObserverImpl + */ + +RTCPeerConnectionObserverImpl::RTCPeerConnectionObserverImpl( + void* callbacks /* rtcPeerConnectionObserverCallbacks* */) + : callbacks_(nullptr) +{ + if (callbacks) { + size_t nSize = sizeof(rtcPeerConnectionObserverCallbacks); + callbacks_ = malloc(nSize); + memcpy(callbacks_, (const void*)callbacks, nSize); + } +} + +RTCPeerConnectionObserverImpl::~RTCPeerConnectionObserverImpl() +{ + if (callbacks_) { + free(callbacks_); + } + callbacks_ = nullptr; +} + +void RTCPeerConnectionObserverImpl::OnSignalingState(RTCSignalingState state) { + if (callbacks_) { + rtcPeerConnectionObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + pCallbacks->SignalingStateChanged( + pCallbacks->UserData, + static_cast(state)); + } +} + +void RTCPeerConnectionObserverImpl::OnPeerConnectionState(RTCPeerConnectionState state) { + if (callbacks_) { + rtcPeerConnectionObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + pCallbacks->ConnectionStateChanged( + pCallbacks->UserData, + static_cast(state)); + } +} + +void RTCPeerConnectionObserverImpl::OnIceGatheringState(RTCIceGatheringState state) { + if (callbacks_) { + rtcPeerConnectionObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + pCallbacks->IceGatheringStateChanged( + pCallbacks->UserData, + static_cast(state)); + } +} + +void RTCPeerConnectionObserverImpl::OnIceConnectionState(RTCIceConnectionState state) { + if (callbacks_) { + rtcPeerConnectionObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + pCallbacks->IceConnectionStateChanged( + pCallbacks->UserData, + static_cast(state)); + } +} + +void RTCPeerConnectionObserverImpl::OnIceCandidate(scoped_refptr candidate) { + if (callbacks_) { + rtcPeerConnectionObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + pCallbacks->IceCandidateReadytoSend( + pCallbacks->UserData, + static_cast(candidate.release())); + } +} + +void RTCPeerConnectionObserverImpl::OnAddStream(scoped_refptr stream) { + if (callbacks_) { + rtcPeerConnectionObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + pCallbacks->StreamAdded( + pCallbacks->UserData, + static_cast(stream.release())); + } +} + +void RTCPeerConnectionObserverImpl::OnRemoveStream(scoped_refptr stream) { + if (callbacks_) { + rtcPeerConnectionObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + pCallbacks->StreamRemoved( + pCallbacks->UserData, + static_cast(stream.release())); + } +} + +void RTCPeerConnectionObserverImpl::OnDataChannel(scoped_refptr data_channel) { + if (callbacks_) { + rtcPeerConnectionObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + pCallbacks->DataChannelAdded( + pCallbacks->UserData, + static_cast(data_channel.release())); + } +} + +void RTCPeerConnectionObserverImpl::OnRenegotiationNeeded() { + if (callbacks_) { + rtcPeerConnectionObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + pCallbacks->RenegotiationNeeded(pCallbacks->UserData); + } +} + +void RTCPeerConnectionObserverImpl::OnTrack(scoped_refptr transceiver) { + if (callbacks_) { + rtcPeerConnectionObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + pCallbacks->TransceiverAdded( + pCallbacks->UserData, + static_cast(transceiver.release())); + } +} + +void RTCPeerConnectionObserverImpl::OnAddTrack(vector> streams, + scoped_refptr receiver) { + if (callbacks_) { + rtcPeerConnectionObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + pCallbacks->TrackAdded( + pCallbacks->UserData, + static_cast(RTCMediaStreamList::Create(streams).release()), + static_cast(receiver.release()) + ); + } +} + +void RTCPeerConnectionObserverImpl::OnRemoveTrack(scoped_refptr receiver) { + if (callbacks_) { + rtcPeerConnectionObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + pCallbacks->TrackRemoved( + pCallbacks->UserData, + static_cast(receiver.release()) + ); + } +} + +/** + * class RTCPeerConnectionImpl + */ + RTCPeerConnectionImpl::RTCPeerConnectionImpl( const RTCConfiguration& configuration, scoped_refptr constraints, diff --git a/src/rtc_peerconnection_impl.h b/src/rtc_peerconnection_impl.h index c781a275b6..a407ce7ed7 100644 --- a/src/rtc_peerconnection_impl.h +++ b/src/rtc_peerconnection_impl.h @@ -31,6 +31,65 @@ class VideoRenderer; namespace libwebrtc { +/** + * class RTCStatsMemberListImpl + */ +class RTCStatsMemberListImpl : public RTCStatsMemberList { + public: + RTCStatsMemberListImpl(const vector>& source); + ~RTCStatsMemberListImpl(); +}; // end class RTCStatsMemberListImpl + +/** + * class MediaRTCStatsListImpl + */ +class MediaRTCStatsListImpl : public MediaRTCStatsList { + public: + MediaRTCStatsListImpl(const vector>& source); + ~MediaRTCStatsListImpl(); +}; // end class MediaRTCStatsListImpl + +/** + * class RTCPeerConnectionObserverImpl + */ +class RTCPeerConnectionObserverImpl : public RTCPeerConnectionObserver +{ + public: + RTCPeerConnectionObserverImpl(void* callbacks /* rtcPeerConnectionObserverCallbacks* */); + ~RTCPeerConnectionObserverImpl(); + + void OnSignalingState(RTCSignalingState state) override; + + void OnPeerConnectionState(RTCPeerConnectionState state) override; + + void OnIceGatheringState(RTCIceGatheringState state) override; + + void OnIceConnectionState(RTCIceConnectionState state) override; + + void OnIceCandidate(scoped_refptr candidate) override; + + void OnAddStream(scoped_refptr stream) override; + + void OnRemoveStream(scoped_refptr stream) override; + + void OnDataChannel(scoped_refptr data_channel) override; + + void OnRenegotiationNeeded() override; + + void OnTrack(scoped_refptr transceiver) override; + + void OnAddTrack(vector> streams, + scoped_refptr receiver) override; + + void OnRemoveTrack(scoped_refptr receiver) override; + + private: + void* callbacks_ /* rtcPeerConnectionObserverCallbacks* */; +}; // end class RTCPeerConnectionObserverImpl + +/** + * class RTCPeerConnectionImpl + */ class RTCPeerConnectionImpl : public RTCPeerConnection, public webrtc::PeerConnectionObserver { public: @@ -183,6 +242,8 @@ class RTCPeerConnectionImpl : public RTCPeerConnection, virtual void OnSignalingChange( webrtc::PeerConnectionInterface::SignalingState new_state) override; + virtual RTCPeerConnectionObserver* GetObserver() override { return observer_; } + protected: rtc::scoped_refptr rtc_peerconnection_factory_; diff --git a/src/rtc_rtp_receiver_impl.cc b/src/rtc_rtp_receiver_impl.cc index f3691f7757..e81a7c2e71 100644 --- a/src/rtc_rtp_receiver_impl.cc +++ b/src/rtc_rtp_receiver_impl.cc @@ -131,4 +131,19 @@ void RTCRtpReceiverImpl::SetJitterBufferMinimumDelay(double delay_seconds) { rtp_receiver_->SetJitterBufferMinimumDelay(delay_seconds); } +scoped_refptr RTCRtpReceiverList::Create( + const vector>& source) { + return new RefCountedObject(source); +} + +RTCRtpReceiverListImpl::RTCRtpReceiverListImpl( + const vector>& source) + : RTCRtpReceiverList(source) { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor "; +} + +RTCRtpReceiverListImpl::~RTCRtpReceiverListImpl() { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; +} + } // namespace libwebrtc diff --git a/src/rtc_rtp_receiver_impl.h b/src/rtc_rtp_receiver_impl.h index c0edc949e6..610fe29ea5 100644 --- a/src/rtc_rtp_receiver_impl.h +++ b/src/rtc_rtp_receiver_impl.h @@ -49,6 +49,15 @@ class RTCRtpReceiverImpl : public RTCRtpReceiver, }; // namespace libwebrtc +/** + * class RTCRtpReceiverListImpl + */ +class RTCRtpReceiverListImpl : public RTCRtpReceiverList { + public: + RTCRtpReceiverListImpl(const vector>& source); + ~RTCRtpReceiverListImpl(); +}; // end class RTCRtpReceiverListImpl + } // namespace libwebrtc #endif // !LIB_WEBRTC_RTP_RECEIV \ No newline at end of file diff --git a/src/rtc_rtp_sender_impl.cc b/src/rtc_rtp_sender_impl.cc index 5785b9c370..073fd1893e 100644 --- a/src/rtc_rtp_sender_impl.cc +++ b/src/rtc_rtp_sender_impl.cc @@ -109,4 +109,19 @@ scoped_refptr RTCRtpSenderImpl::dtmf_sender() const { return new RefCountedObject(rtp_sender_->GetDtmfSender()); } +scoped_refptr RTCRtpSenderList::Create( + const vector>& source) { + return new RefCountedObject(source); +} + +RTCRtpSenderListImpl::RTCRtpSenderListImpl( + const vector>& source) + : RTCRtpSenderList(source) { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor "; +} + +RTCRtpSenderListImpl::~RTCRtpSenderListImpl() { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; +} + } // namespace libwebrtc diff --git a/src/rtc_rtp_sender_impl.h b/src/rtc_rtp_sender_impl.h index a8660a3af3..50562c3e68 100644 --- a/src/rtc_rtp_sender_impl.h +++ b/src/rtc_rtp_sender_impl.h @@ -33,6 +33,16 @@ class RTCRtpSenderImpl : public RTCRtpSender { private: rtc::scoped_refptr rtp_sender_; }; + +/** + * class RTCRtpSenderListImpl + */ +class RTCRtpSenderListImpl : public RTCRtpSenderList { + public: + RTCRtpSenderListImpl(const vector>& source); + ~RTCRtpSenderListImpl(); +}; // end class RTCRtpSenderListImpl + } // namespace libwebrtc #endif // LIB_WEBRTC_RTC_RTP_SENDER_IMPL_HXX \ No newline at end of file diff --git a/src/rtc_rtp_transceiver_impl.cc b/src/rtc_rtp_transceiver_impl.cc index 301d78691f..7014f2730d 100644 --- a/src/rtc_rtp_transceiver_impl.cc +++ b/src/rtc_rtp_transceiver_impl.cc @@ -166,4 +166,19 @@ const string RTCRtpTransceiverImpl::transceiver_id() const { return ss.str(); } +scoped_refptr RTCRtpTransceiverList::Create( + const vector>& source) { + return new RefCountedObject(source); +} + +RTCRtpTransceiverListImpl::RTCRtpTransceiverListImpl( + const vector>& source) + : RTCRtpTransceiverList(source) { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor "; +} + +RTCRtpTransceiverListImpl::~RTCRtpTransceiverListImpl() { + RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; +} + } // namespace libwebrtc diff --git a/src/rtc_rtp_transceiver_impl.h b/src/rtc_rtp_transceiver_impl.h index d04297d011..3508d03f8d 100644 --- a/src/rtc_rtp_transceiver_impl.h +++ b/src/rtc_rtp_transceiver_impl.h @@ -55,6 +55,15 @@ class RTCRtpTransceiverImpl : public RTCRtpTransceiver { rtc::scoped_refptr rtp_transceiver_; }; +/** + * class RTCRtpTransceiverListImpl + */ +class RTCRtpTransceiverListImpl : public RTCRtpTransceiverList { + public: + RTCRtpTransceiverListImpl(const vector>& source); + ~RTCRtpTransceiverListImpl(); +}; // end class RTCRtpTransceiverListImpl + } // namespace libwebrtc #endif // LIB_WEBRTC_RTC_TYPES_HXX From 90d5a2e60cfe3ae5eaacc50732991101c92c2962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Sat, 4 Jan 2025 02:37:21 +0300 Subject: [PATCH 52/69] Interop callbacks optimization --- include/interop_api.h | 167 +++++++++++---- src/interop/rtc_audio_device_interop.cc | 23 +- src/interop/rtc_peerconnection_interop.cc | 235 +++++++++------------ src/interop/rtc_rtp_receiver_interop.cc | 18 ++ src/interop/rtc_rtp_sender_interop.cc | 18 ++ src/interop/rtc_rtp_transceiver_interop.cc | 18 ++ src/rtc_dtls_transport_impl.cc | 3 +- src/rtc_dtmf_sender_impl.cc | 10 +- 8 files changed, 303 insertions(+), 189 deletions(-) diff --git a/include/interop_api.h b/include/interop_api.h index b93d2ee284..e9203ff533 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -542,7 +542,16 @@ using rtcSessionDescriptionHandle = rtcRefCountedObjectHandle; /** * Audio device change callback delegate */ -using rtcAudioDeviceChangeDelegate = void(LIB_WEBRTC_CALL*)(); +using rtcAudioDeviceChangeDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data); + +/** + * Callback delegate structure for RTCAudioDevice. + */ +struct rtcAudioDeviceCallbacks { + rtcObjectHandle UserData{}; + rtcAudioDeviceChangeDelegate DeviceChanged{}; +}; /** * Callback delegate for MediaListObserver. @@ -606,7 +615,7 @@ struct rtcRtpReceiverObserverCallbacks { * RTCDtmfSender: Tone changed callback delegate */ using rtcDtmfSenderToneChangedDelegate = void(LIB_WEBRTC_CALL*)( - rtcObjectHandle user_data, const char* tone, int tone_len, const char* tone_buffer, int tone_buffer_len); + rtcObjectHandle user_data, const char* tone, const char* tone_buffer); /** * Callback delegate structure for RTCDtmfSenderObserver. @@ -626,7 +635,7 @@ using rtcDtlsTransportStateChangedDelegate = void(LIB_WEBRTC_CALL*)( * RTCDtlsTransport: Error callback delegate */ using rtcDtlsTransportErrorDelegate = void(LIB_WEBRTC_CALL*)( - rtcObjectHandle user_data, const int type, const char* message, int message_len); + rtcObjectHandle user_data, const int type, const char* message); /** * Callback delegate structure for RTCDtlsTransportObserver. @@ -695,27 +704,42 @@ struct rtcPeerConnectionObserverCallbacks { /*-----------------------------------------------------------------*/ using rtcOnStatsCollectorSuccessDelegate = void(LIB_WEBRTC_CALL*)( - rtcMediaRTCStatsListHandle reports); - -using rtcOnStatsCollectorFailureDelegate = void(LIB_WEBRTC_CALL*)( - const char* error, int error_len); + rtcObjectHandle user_data, rtcMediaRTCStatsListHandle reports); -using rtcOnSdpCreateSuccessDelegate = void(LIB_WEBRTC_CALL*)( - const char* sdp, int sdp_len, const char* type, int type_len); +using rtcOnFailureDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, const char* error); -using rtcOnSdpCreateFailureDelegate = void(LIB_WEBRTC_CALL*)( - const char* error, int error_len); +using rtcOnGetSdpSuccessDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, const char* sdp, const char* type); -using rtcOnSetSdpSuccessDelegate = void(LIB_WEBRTC_CALL*)(); +using rtcOnSetSdpSuccessDelegate = void(LIB_WEBRTC_CALL*)(rtcObjectHandle user_data); -using rtcOnSetSdpFailureDelegate = void(LIB_WEBRTC_CALL*)( - const char* error, int error_len); +/** + * Callback delegate structure for RTCPeerConnection. + */ +struct rtcOnStatsCallbacks { + rtcObjectHandle UserData{}; + rtcOnStatsCollectorSuccessDelegate Success{}; + rtcOnFailureDelegate Failure{}; +}; // end struct rtcOnStatsCallbacks -using rtcOnGetSdpSuccessDelegate = void(LIB_WEBRTC_CALL*)( - const char* sdp, int sdp_len, const char* type, int type_len); +/** + * Callback delegate structure for RTCPeerConnection. + */ +struct rtcOnGetSdpCallbacks { + rtcObjectHandle UserData{}; + rtcOnGetSdpSuccessDelegate Success{}; + rtcOnFailureDelegate Failure{}; +}; // end struct rtcOnGetSdpCallbacks -using rtcOnGetSdpFailureDelegate = void(LIB_WEBRTC_CALL*)( - const char* error, int error_len); +/** + * Callback delegate structure for RTCPeerConnection. + */ +struct rtcOnSetSdpCallbacks { + rtcObjectHandle UserData{}; + rtcOnSetSdpSuccessDelegate Success{}; + rtcOnFailureDelegate Failure{}; +}; // end struct rtcOnSetSdpCallbacks /* * ---------------------------------------------------------------------- @@ -1023,7 +1047,13 @@ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCAudioDevice_SetRecordingDevice( LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCAudioDevice_RegisterDeviceChangeCallback( rtcAudioDeviceHandle audiDevice, - rtcAudioDeviceChangeDelegate deviceChangeCallback) noexcept; + rtcAudioDeviceCallbacks* callbacks +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_UnregisterDeviceChangeCallback( + rtcAudioDeviceHandle audiDevice +) noexcept; /** * Sets the microphone volume level. @@ -2985,6 +3015,24 @@ RTCRtpReceiver_SetJitterBufferMinimumDelay ( double value ) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCRtpReceiverList interop methods + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RTCRtpReceiverList_GetCount ( + rtcRtpReceiverListHandle handle +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiverList_GetItem ( + rtcRtpReceiverListHandle handle, + int index, + rtcRtpReceiverHandle* pOutRetVal +) noexcept; + /* * ---------------------------------------------------------------------- * RTCDtmfSender interop methods @@ -3122,6 +3170,24 @@ RTCRtpSender_GetDtmfSender ( rtcDtmfSenderHandle* pOutRetVal ) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCRtpSenderList interop methods + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RTCRtpSenderList_GetCount ( + rtcRtpSenderListHandle handle +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSenderList_GetItem ( + rtcRtpSenderListHandle handle, + int index, + rtcRtpSenderHandle* pOutRetVal +) noexcept; + /* * ---------------------------------------------------------------------- * RTCDtlsTransportInformation interop methods @@ -3309,6 +3375,42 @@ RTCRtpTransceiver_GetTransceiverId ( int sz_value ) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCRtpTransceiverList interop methods + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RTCRtpTransceiverList_GetCount ( + rtcRtpTransceiverListHandle handle +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiverList_GetItem ( + rtcRtpTransceiverListHandle handle, + int index, + rtcRtpTransceiverHandle* pOutRetVal +) noexcept; + +/* + * ---------------------------------------------------------------------- + * MediaRTCStatsList interop methods + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RTCMediaRTCStatsList_GetCount ( + rtcMediaRTCStatsListHandle handle +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCMediaRTCStatsList_GetItem ( + rtcMediaRTCStatsListHandle handle, + int index, + rtcMediaRTCStatsHandle* pOutRetVal +) noexcept; + /* * ---------------------------------------------------------------------- * RTCPeerConnection interop methods @@ -3353,16 +3455,14 @@ RTCPeerConnection_CreateDataChannel ( LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_CreateOffer ( rtcPeerConnectionHandle handle, - rtcOnSdpCreateSuccessDelegate success, - rtcOnSdpCreateFailureDelegate failure, + rtcOnGetSdpCallbacks* callbacks, rtcMediaConstraintsHandle constraints ) noexcept; LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_CreateAnswer ( rtcPeerConnectionHandle handle, - rtcOnSdpCreateSuccessDelegate success, - rtcOnSdpCreateFailureDelegate failure, + rtcOnGetSdpCallbacks* callbacks, rtcMediaConstraintsHandle constraints ) noexcept; @@ -3381,8 +3481,7 @@ RTCPeerConnection_SetLocalDescription ( rtcPeerConnectionHandle handle, const char* sdp, const char* type, - rtcOnSetSdpSuccessDelegate success, - rtcOnSetSdpFailureDelegate failure + rtcOnSetSdpCallbacks* callbacks ) noexcept; LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL @@ -3390,22 +3489,19 @@ RTCPeerConnection_SetRemoteDescription ( rtcPeerConnectionHandle handle, const char* sdp, const char* type, - rtcOnSetSdpSuccessDelegate success, - rtcOnSetSdpFailureDelegate failure + rtcOnSetSdpCallbacks* callbacks ) noexcept; LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_GetLocalDescription ( rtcPeerConnectionHandle handle, - rtcOnGetSdpSuccessDelegate success, - rtcOnGetSdpFailureDelegate failure + rtcOnGetSdpCallbacks* callbacks ) noexcept; LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_GetRemoteDescription ( rtcPeerConnectionHandle handle, - rtcOnGetSdpSuccessDelegate success, - rtcOnGetSdpFailureDelegate failure + rtcOnGetSdpCallbacks* callbacks ) noexcept; LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL @@ -3443,8 +3539,7 @@ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_GetSenderStats ( rtcPeerConnectionHandle handle, rtcRtpSenderHandle sender, - rtcOnStatsCollectorSuccessDelegate success, - rtcOnStatsCollectorFailureDelegate failure, + rtcOnStatsCallbacks* callbacks, rtcBool32* pOutRetVal ) noexcept; @@ -3452,16 +3547,14 @@ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_GetReceiverStats ( rtcPeerConnectionHandle handle, rtcRtpReceiverHandle receiver, - rtcOnStatsCollectorSuccessDelegate success, - rtcOnStatsCollectorFailureDelegate failure, + rtcOnStatsCallbacks* callbacks, rtcBool32* pOutRetVal ) noexcept; LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_GetStats ( rtcPeerConnectionHandle handle, - rtcOnStatsCollectorSuccessDelegate success, - rtcOnStatsCollectorFailureDelegate failure + rtcOnStatsCallbacks* callbacks ) noexcept; LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL diff --git a/src/interop/rtc_audio_device_interop.cc b/src/interop/rtc_audio_device_interop.cc index 049eda3c32..02b645dbe9 100644 --- a/src/interop/rtc_audio_device_interop.cc +++ b/src/interop/rtc_audio_device_interop.cc @@ -160,20 +160,21 @@ RTCAudioDevice_SetRecordingDevice( rtcResultU4 LIB_WEBRTC_CALL RTCAudioDevice_RegisterDeviceChangeCallback( rtcAudioDeviceHandle audiDevice, - rtcAudioDeviceChangeDelegate deviceChangeCallback + rtcAudioDeviceCallbacks* callbacks ) noexcept { CHECK_NATIVE_HANDLE(audiDevice); scoped_refptr pAudioDevice = static_cast(audiDevice); RTCAudioDevice::OnDeviceChangeCallback cb; - if (deviceChangeCallback == nullptr) { + if (callbacks == nullptr || callbacks->DeviceChanged == nullptr) { cb = nullptr; } else { - cb = [deviceChangeCallback](void) { - if (deviceChangeCallback) { - deviceChangeCallback(); + rtcAudioDeviceCallbacks cb2 = *callbacks; + cb = [cb2](void) { + if (cb2.DeviceChanged) { + cb2.DeviceChanged(cb2.UserData); } }; } @@ -181,6 +182,18 @@ RTCAudioDevice_RegisterDeviceChangeCallback( return static_cast(pAudioDevice->OnDeviceChange(cb)); } // end RTCAudioDevice_RegisterDeviceChangeCallback +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_UnregisterDeviceChangeCallback( + rtcAudioDeviceHandle audiDevice +) noexcept +{ + CHECK_NATIVE_HANDLE(audiDevice); + + scoped_refptr pAudioDevice = static_cast(audiDevice); + RTCAudioDevice::OnDeviceChangeCallback cb = nullptr; + return static_cast(pAudioDevice->OnDeviceChange(cb)); +} // end RTCAudioDevice_UnregisterDeviceChangeCallback + rtcResultU4 LIB_WEBRTC_CALL RTCAudioDevice_SetMicrophoneVolume( rtcAudioDeviceHandle audiDevice, diff --git a/src/interop/rtc_peerconnection_interop.cc b/src/interop/rtc_peerconnection_interop.cc index f53fb0eb4e..d99ec56a32 100644 --- a/src/interop/rtc_peerconnection_interop.cc +++ b/src/interop/rtc_peerconnection_interop.cc @@ -4,6 +4,25 @@ using namespace libwebrtc; +int LIB_WEBRTC_CALL +RTCMediaRTCStatsList_GetCount ( + rtcMediaRTCStatsListHandle handle +) noexcept +{ + DECLARE_LIST_GET_COUNT(handle, MediaRTCStatsList); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCMediaRTCStatsList_GetItem ( + rtcMediaRTCStatsListHandle handle, + int index, + rtcMediaRTCStatsHandle* pOutRetVal +) noexcept +{ + DECLARE_LIST_GET_ITEM(handle, index, pOutRetVal, rtcMediaRTCStatsHandle, MediaRTCStatsList, MediaRTCStats); +} + + rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_IsInitialized ( rtcPeerConnectionHandle handle, @@ -104,33 +123,23 @@ RTCPeerConnection_CreateDataChannel ( rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_CreateOffer ( rtcPeerConnectionHandle handle, - rtcOnSdpCreateSuccessDelegate success, - rtcOnSdpCreateFailureDelegate failure, + rtcOnGetSdpCallbacks* callbacks, rtcMediaConstraintsHandle constraints ) noexcept { CHECK_NATIVE_HANDLE(handle); - CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); - CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); CHECK_POINTER_EX(constraints, rtcResultU4::kInvalidParameter); scoped_refptr p = static_cast(handle); - OnSdpCreateSuccess fn_success = [success](const string sdp, const string type) { - if (success) { - success( - sdp.c_string(), - static_cast(sdp.size()), - type.c_string(), - static_cast(type.size()) - ); + OnSdpCreateSuccess fn_success = [callbacks](const string sdp, const string type) { + if (callbacks && callbacks->Success) { + callbacks->Success(callbacks->UserData, sdp.c_string(), type.c_string()); } }; - OnSdpCreateFailure fn_failure = [failure](const char* erro) { - if (failure) { - failure( - erro, - strlen(erro ? erro : "") - ); + OnSdpCreateFailure fn_failure = [callbacks](const char* error) { + if (callbacks && callbacks->Failure) { + callbacks->Failure(callbacks->UserData, error); } }; scoped_refptr pConstraints= static_cast(constraints); @@ -141,33 +150,23 @@ RTCPeerConnection_CreateOffer ( rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_CreateAnswer ( rtcPeerConnectionHandle handle, - rtcOnSdpCreateSuccessDelegate success, - rtcOnSdpCreateFailureDelegate failure, + rtcOnGetSdpCallbacks* callbacks, rtcMediaConstraintsHandle constraints ) noexcept { CHECK_NATIVE_HANDLE(handle); - CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); - CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); CHECK_POINTER_EX(constraints, rtcResultU4::kInvalidParameter); scoped_refptr p = static_cast(handle); - OnSdpCreateSuccess fn_success = [success](const string sdp, const string type) { - if (success) { - success( - sdp.c_string(), - static_cast(sdp.size()), - type.c_string(), - static_cast(type.size()) - ); + OnSdpCreateSuccess fn_success = [callbacks](const string sdp, const string type) { + if (callbacks && callbacks->Success) { + callbacks->Success(callbacks->UserData, sdp.c_string(), type.c_string()); } }; - OnSdpCreateFailure fn_failure = [failure](const char* erro) { - if (failure) { - failure( - erro, - strlen(erro ? erro : "") - ); + OnSdpCreateFailure fn_failure = [callbacks](const char* error) { + if (callbacks && callbacks->Failure) { + callbacks->Failure(callbacks->UserData, error); } }; scoped_refptr pConstraints= static_cast(constraints); @@ -206,25 +205,20 @@ RTCPeerConnection_SetLocalDescription ( rtcPeerConnectionHandle handle, const char* sdp, const char* type, - rtcOnSetSdpSuccessDelegate success, - rtcOnSetSdpFailureDelegate failure + rtcOnSetSdpCallbacks* callbacks ) noexcept { CHECK_NATIVE_HANDLE(handle); - CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); - CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); - OnSetSdpSuccess fn_success = [success]() { - if (success) { - success(); + OnSetSdpSuccess fn_success = [callbacks]() { + if (callbacks && callbacks->Success) { + callbacks->Success(callbacks->UserData); } }; - OnSetSdpFailure fn_failure = [failure](const char* error) { - if (failure) { - failure( - error, - strlen(error ? error : "") - ); + OnSetSdpFailure fn_failure = [callbacks](const char* error) { + if (callbacks && callbacks->Failure) { + callbacks->Failure(callbacks->UserData, error); } }; scoped_refptr p = static_cast(handle); @@ -237,25 +231,20 @@ RTCPeerConnection_SetRemoteDescription ( rtcPeerConnectionHandle handle, const char* sdp, const char* type, - rtcOnSetSdpSuccessDelegate success, - rtcOnSetSdpFailureDelegate failure + rtcOnSetSdpCallbacks* callbacks ) noexcept { CHECK_NATIVE_HANDLE(handle); - CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); - CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); - OnSetSdpSuccess fn_success = [success]() { - if (success) { - success(); + OnSetSdpSuccess fn_success = [callbacks]() { + if (callbacks && callbacks->Success) { + callbacks->Success(callbacks->UserData); } }; - OnSetSdpFailure fn_failure = [failure](const char* error) { - if (failure) { - failure( - error, - strlen(error ? error : "") - ); + OnSetSdpFailure fn_failure = [callbacks](const char* error) { + if (callbacks && callbacks->Failure) { + callbacks->Failure(callbacks->UserData, error); } }; scoped_refptr p = static_cast(handle); @@ -266,30 +255,20 @@ RTCPeerConnection_SetRemoteDescription ( rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_GetLocalDescription ( rtcPeerConnectionHandle handle, - rtcOnGetSdpSuccessDelegate success, - rtcOnGetSdpFailureDelegate failure + rtcOnGetSdpCallbacks* callbacks ) noexcept { CHECK_NATIVE_HANDLE(handle); - CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); - CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); - - OnGetSdpSuccess fn_success = [success](const char* sdp, const char* type) { - if (success) { - success( - sdp, - strlen(sdp ? sdp : ""), - type, - strlen(type ? type : "") - ); + CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); + + OnGetSdpSuccess fn_success = [callbacks](const char* sdp, const char* type) { + if (callbacks && callbacks->Success) { + callbacks->Success(callbacks->UserData, sdp, type); } }; - OnGetSdpFailure fn_failure = [failure](const char* error) { - if (failure) { - failure( - error, - strlen(error ? error : "") - ); + OnGetSdpFailure fn_failure = [callbacks](const char* error) { + if (callbacks && callbacks->Failure) { + callbacks->Failure(callbacks->UserData, error); } }; scoped_refptr p = static_cast(handle); @@ -300,30 +279,20 @@ RTCPeerConnection_GetLocalDescription ( rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_GetRemoteDescription ( rtcPeerConnectionHandle handle, - rtcOnGetSdpSuccessDelegate success, - rtcOnGetSdpFailureDelegate failure + rtcOnGetSdpCallbacks* callbacks ) noexcept { CHECK_NATIVE_HANDLE(handle); - CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); - CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); - - OnGetSdpSuccess fn_success = [success](const char* sdp, const char* type) { - if (success) { - success( - sdp, - strlen(sdp ? sdp : ""), - type, - strlen(type ? type : "") - ); + CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); + + OnGetSdpSuccess fn_success = [callbacks](const char* sdp, const char* type) { + if (callbacks && callbacks->Success) { + callbacks->Success(callbacks->UserData, sdp, type); } }; - OnGetSdpFailure fn_failure = [failure](const char* error) { - if (failure) { - failure( - error, - strlen(error ? error : "") - ); + OnGetSdpFailure fn_failure = [callbacks](const char* error) { + if (callbacks && callbacks->Failure) { + callbacks->Failure(callbacks->UserData, error); } }; scoped_refptr p = static_cast(handle); @@ -408,8 +377,7 @@ rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_GetSenderStats ( rtcPeerConnectionHandle handle, rtcRtpSenderHandle sender, - rtcOnStatsCollectorSuccessDelegate success, - rtcOnStatsCollectorFailureDelegate failure, + rtcOnStatsCallbacks* callbacks, rtcBool32* pOutRetVal ) noexcept { @@ -418,23 +386,20 @@ RTCPeerConnection_GetSenderStats ( } CHECK_NATIVE_HANDLE(handle); CHECK_POINTER_EX(sender, rtcResultU4::kInvalidParameter); - CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); - CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); - OnStatsCollectorSuccess fn_success = [success](const vector> reports) { - if (success) { + OnStatsCollectorSuccess fn_success = [callbacks](const vector> reports) { + if (callbacks && callbacks->Success) { scoped_refptr pList = MediaRTCStatsList::Create(reports); - success( + callbacks->Success( + callbacks->UserData, static_cast(pList.release()) ); } }; - OnStatsCollectorFailure fn_failure = [failure](const char* error) { - if (failure) { - failure( - error, - strlen(error ? error : "") - ); + OnStatsCollectorFailure fn_failure = [callbacks](const char* error) { + if (callbacks && callbacks->Failure) { + callbacks->Failure(callbacks->UserData, error); } }; scoped_refptr p = static_cast(handle); @@ -450,8 +415,7 @@ rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_GetReceiverStats ( rtcPeerConnectionHandle handle, rtcRtpReceiverHandle receiver, - rtcOnStatsCollectorSuccessDelegate success, - rtcOnStatsCollectorFailureDelegate failure, + rtcOnStatsCallbacks* callbacks, rtcBool32* pOutRetVal ) noexcept { @@ -460,23 +424,20 @@ RTCPeerConnection_GetReceiverStats ( } CHECK_NATIVE_HANDLE(handle); CHECK_POINTER_EX(receiver, rtcResultU4::kInvalidParameter); - CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); - CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); - OnStatsCollectorSuccess fn_success = [success](const vector> reports) { - if (success) { + OnStatsCollectorSuccess fn_success = [callbacks](const vector> reports) { + if (callbacks && callbacks->Success) { scoped_refptr pList = MediaRTCStatsList::Create(reports); - success( + callbacks->Success( + callbacks->UserData, static_cast(pList.release()) ); } }; - OnStatsCollectorFailure fn_failure = [failure](const char* error) { - if (failure) { - failure( - error, - strlen(error ? error : "") - ); + OnStatsCollectorFailure fn_failure = [callbacks](const char* error) { + if (callbacks && callbacks->Failure) { + callbacks->Failure(callbacks->UserData, error); } }; scoped_refptr p = static_cast(handle); @@ -491,28 +452,24 @@ RTCPeerConnection_GetReceiverStats ( rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_GetStats ( rtcPeerConnectionHandle handle, - rtcOnStatsCollectorSuccessDelegate success, - rtcOnStatsCollectorFailureDelegate failure + rtcOnStatsCallbacks* callbacks ) noexcept { CHECK_NATIVE_HANDLE(handle); - CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); - CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); - OnStatsCollectorSuccess fn_success = [success](const vector> reports) { - if (success) { + OnStatsCollectorSuccess fn_success = [callbacks](const vector> reports) { + if (callbacks && callbacks->Success) { scoped_refptr pList = MediaRTCStatsList::Create(reports); - success( + callbacks->Success( + callbacks->UserData, static_cast(pList.release()) ); } }; - OnStatsCollectorFailure fn_failure = [failure](const char* error) { - if (failure) { - failure( - error, - strlen(error ? error : "") - ); + OnStatsCollectorFailure fn_failure = [callbacks](const char* error) { + if (callbacks && callbacks->Failure) { + callbacks->Failure(callbacks->UserData, error); } }; scoped_refptr p = static_cast(handle); diff --git a/src/interop/rtc_rtp_receiver_interop.cc b/src/interop/rtc_rtp_receiver_interop.cc index 1a63662c21..4bb87782f8 100644 --- a/src/interop/rtc_rtp_receiver_interop.cc +++ b/src/interop/rtc_rtp_receiver_interop.cc @@ -137,3 +137,21 @@ RTCRtpReceiver_SetJitterBufferMinimumDelay ( { DECLARE_SET_VALUE(handle, value, double, RTCRtpReceiver, SetJitterBufferMinimumDelay); } + +int LIB_WEBRTC_CALL +RTCRtpReceiverList_GetCount ( + rtcRtpReceiverListHandle handle +) noexcept +{ + DECLARE_LIST_GET_COUNT(handle, RTCRtpReceiverList); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpReceiverList_GetItem ( + rtcRtpReceiverListHandle handle, + int index, + rtcRtpReceiverHandle* pOutRetVal +) noexcept +{ + DECLARE_LIST_GET_ITEM(handle, index, pOutRetVal, rtcRtpReceiverHandle, RTCRtpReceiverList, RTCRtpReceiver); +} diff --git a/src/interop/rtc_rtp_sender_interop.cc b/src/interop/rtc_rtp_sender_interop.cc index 88a4d68db6..c69b840f5d 100644 --- a/src/interop/rtc_rtp_sender_interop.cc +++ b/src/interop/rtc_rtp_sender_interop.cc @@ -132,3 +132,21 @@ RTCRtpSender_GetDtmfSender ( { DECLARE_GET_VALUE(handle, pOutRetVal, rtcDtmfSenderHandle, RTCRtpSender, dtmf_sender().release); } + +int LIB_WEBRTC_CALL +RTCRtpSenderList_GetCount ( + rtcRtpSenderListHandle handle +) noexcept +{ + DECLARE_LIST_GET_COUNT(handle, RTCRtpSenderList); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpSenderList_GetItem ( + rtcRtpSenderListHandle handle, + int index, + rtcRtpSenderHandle* pOutRetVal +) noexcept +{ + DECLARE_LIST_GET_ITEM(handle, index, pOutRetVal, rtcRtpSenderHandle, RTCRtpSenderList, RTCRtpSender); +} diff --git a/src/interop/rtc_rtp_transceiver_interop.cc b/src/interop/rtc_rtp_transceiver_interop.cc index 561a3701d4..56bf24e4c8 100644 --- a/src/interop/rtc_rtp_transceiver_interop.cc +++ b/src/interop/rtc_rtp_transceiver_interop.cc @@ -246,3 +246,21 @@ RTCRtpTransceiver_GetTransceiverId ( { DECLARE_GET_STRING(handle, value, sz_value, RTCRtpTransceiver, transceiver_id); } + +int LIB_WEBRTC_CALL +RTCRtpTransceiverList_GetCount ( + rtcRtpTransceiverListHandle handle +) noexcept +{ + DECLARE_LIST_GET_COUNT(handle, RTCRtpTransceiverList); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiverList_GetItem ( + rtcRtpTransceiverListHandle handle, + int index, + rtcRtpTransceiverHandle* pOutRetVal +) noexcept +{ + DECLARE_LIST_GET_ITEM(handle, index, pOutRetVal, rtcRtpTransceiverHandle, RTCRtpTransceiverList, RTCRtpTransceiver); +} diff --git a/src/rtc_dtls_transport_impl.cc b/src/rtc_dtls_transport_impl.cc index 7e1fd4406b..033a25a428 100644 --- a/src/rtc_dtls_transport_impl.cc +++ b/src/rtc_dtls_transport_impl.cc @@ -82,8 +82,7 @@ void RTCDtlsTransportObserverImpl::OnError(const int type, const char* message) pCallbacks->Error( pCallbacks->UserData, type, - message, - message ? strlen(message) : 0 + message ); } } diff --git a/src/rtc_dtmf_sender_impl.cc b/src/rtc_dtmf_sender_impl.cc index a8bb2e39bc..5910e32522 100644 --- a/src/rtc_dtmf_sender_impl.cc +++ b/src/rtc_dtmf_sender_impl.cc @@ -33,9 +33,8 @@ void RTCDtmfSenderObserverImpl::OnToneChange(const string tone, const string ton pCallbacks->ToneChanged( pCallbacks->UserData, tone.c_string(), - static_cast(((string*)&tone)->size()), - tone_buffer.c_string(), - static_cast(((string*)&tone_buffer)->size())); + tone_buffer.c_string() + ); } } @@ -46,9 +45,8 @@ void RTCDtmfSenderObserverImpl::OnToneChange(const string tone) pCallbacks->ToneChanged( pCallbacks->UserData, tone.c_string(), - static_cast(((string*)&tone)->size()), - nullptr, - 0); + nullptr + ); } } From db9bf9c32829b966a9b1c5c6e1e3e7612883f95e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Sun, 5 Jan 2025 04:22:23 +0300 Subject: [PATCH 53/69] interop callback optimization --- include/interop_api.h | 74 ++++---- src/interop/rtc_audio_device_interop.cc | 12 +- src/interop/rtc_peerconnection_interop.cc | 201 +++++++++++----------- 3 files changed, 131 insertions(+), 156 deletions(-) diff --git a/include/interop_api.h b/include/interop_api.h index e9203ff533..36ad781492 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -545,14 +545,6 @@ using rtcSessionDescriptionHandle = rtcRefCountedObjectHandle; using rtcAudioDeviceChangeDelegate = void(LIB_WEBRTC_CALL*)( rtcObjectHandle user_data); -/** - * Callback delegate structure for RTCAudioDevice. - */ -struct rtcAudioDeviceCallbacks { - rtcObjectHandle UserData{}; - rtcAudioDeviceChangeDelegate DeviceChanged{}; -}; - /** * Callback delegate for MediaListObserver. */ @@ -714,33 +706,6 @@ using rtcOnGetSdpSuccessDelegate = void(LIB_WEBRTC_CALL*)( using rtcOnSetSdpSuccessDelegate = void(LIB_WEBRTC_CALL*)(rtcObjectHandle user_data); -/** - * Callback delegate structure for RTCPeerConnection. - */ -struct rtcOnStatsCallbacks { - rtcObjectHandle UserData{}; - rtcOnStatsCollectorSuccessDelegate Success{}; - rtcOnFailureDelegate Failure{}; -}; // end struct rtcOnStatsCallbacks - -/** - * Callback delegate structure for RTCPeerConnection. - */ -struct rtcOnGetSdpCallbacks { - rtcObjectHandle UserData{}; - rtcOnGetSdpSuccessDelegate Success{}; - rtcOnFailureDelegate Failure{}; -}; // end struct rtcOnGetSdpCallbacks - -/** - * Callback delegate structure for RTCPeerConnection. - */ -struct rtcOnSetSdpCallbacks { - rtcObjectHandle UserData{}; - rtcOnSetSdpSuccessDelegate Success{}; - rtcOnFailureDelegate Failure{}; -}; // end struct rtcOnSetSdpCallbacks - /* * ---------------------------------------------------------------------- * LibWebRTC interop methods @@ -1047,7 +1012,8 @@ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCAudioDevice_SetRecordingDevice( LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCAudioDevice_RegisterDeviceChangeCallback( rtcAudioDeviceHandle audiDevice, - rtcAudioDeviceCallbacks* callbacks + rtcObjectHandle userData, + rtcAudioDeviceChangeDelegate callback ) noexcept; LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL @@ -3455,14 +3421,18 @@ RTCPeerConnection_CreateDataChannel ( LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_CreateOffer ( rtcPeerConnectionHandle handle, - rtcOnGetSdpCallbacks* callbacks, + rtcObjectHandle user_data, + rtcOnGetSdpSuccessDelegate success, + rtcOnFailureDelegate failure, rtcMediaConstraintsHandle constraints ) noexcept; LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_CreateAnswer ( rtcPeerConnectionHandle handle, - rtcOnGetSdpCallbacks* callbacks, + rtcObjectHandle user_data, + rtcOnGetSdpSuccessDelegate success, + rtcOnFailureDelegate failure, rtcMediaConstraintsHandle constraints ) noexcept; @@ -3481,7 +3451,9 @@ RTCPeerConnection_SetLocalDescription ( rtcPeerConnectionHandle handle, const char* sdp, const char* type, - rtcOnSetSdpCallbacks* callbacks + rtcObjectHandle user_data, + rtcOnSetSdpSuccessDelegate success, + rtcOnFailureDelegate failure ) noexcept; LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL @@ -3489,19 +3461,25 @@ RTCPeerConnection_SetRemoteDescription ( rtcPeerConnectionHandle handle, const char* sdp, const char* type, - rtcOnSetSdpCallbacks* callbacks + rtcObjectHandle user_data, + rtcOnSetSdpSuccessDelegate success, + rtcOnFailureDelegate failure ) noexcept; LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_GetLocalDescription ( rtcPeerConnectionHandle handle, - rtcOnGetSdpCallbacks* callbacks + rtcObjectHandle user_data, + rtcOnGetSdpSuccessDelegate success, + rtcOnFailureDelegate failure ) noexcept; LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_GetRemoteDescription ( rtcPeerConnectionHandle handle, - rtcOnGetSdpCallbacks* callbacks + rtcObjectHandle user_data, + rtcOnGetSdpSuccessDelegate success, + rtcOnFailureDelegate failure ) noexcept; LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL @@ -3539,7 +3517,9 @@ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_GetSenderStats ( rtcPeerConnectionHandle handle, rtcRtpSenderHandle sender, - rtcOnStatsCallbacks* callbacks, + rtcObjectHandle user_data, + rtcOnStatsCollectorSuccessDelegate success, + rtcOnFailureDelegate failure, rtcBool32* pOutRetVal ) noexcept; @@ -3547,14 +3527,18 @@ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_GetReceiverStats ( rtcPeerConnectionHandle handle, rtcRtpReceiverHandle receiver, - rtcOnStatsCallbacks* callbacks, + rtcObjectHandle user_data, + rtcOnStatsCollectorSuccessDelegate success, + rtcOnFailureDelegate failure, rtcBool32* pOutRetVal ) noexcept; LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_GetStats ( rtcPeerConnectionHandle handle, - rtcOnStatsCallbacks* callbacks + rtcObjectHandle user_data, + rtcOnStatsCollectorSuccessDelegate success, + rtcOnFailureDelegate failure ) noexcept; LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL diff --git a/src/interop/rtc_audio_device_interop.cc b/src/interop/rtc_audio_device_interop.cc index 02b645dbe9..e01e2982b8 100644 --- a/src/interop/rtc_audio_device_interop.cc +++ b/src/interop/rtc_audio_device_interop.cc @@ -160,21 +160,21 @@ RTCAudioDevice_SetRecordingDevice( rtcResultU4 LIB_WEBRTC_CALL RTCAudioDevice_RegisterDeviceChangeCallback( rtcAudioDeviceHandle audiDevice, - rtcAudioDeviceCallbacks* callbacks + rtcObjectHandle userData, + rtcAudioDeviceChangeDelegate callback ) noexcept { CHECK_NATIVE_HANDLE(audiDevice); scoped_refptr pAudioDevice = static_cast(audiDevice); RTCAudioDevice::OnDeviceChangeCallback cb; - if (callbacks == nullptr || callbacks->DeviceChanged == nullptr) { + if (callback == nullptr) { cb = nullptr; } else { - rtcAudioDeviceCallbacks cb2 = *callbacks; - cb = [cb2](void) { - if (cb2.DeviceChanged) { - cb2.DeviceChanged(cb2.UserData); + cb = [callback, userData](void) { + if (callback) { + callback(userData); } }; } diff --git a/src/interop/rtc_peerconnection_interop.cc b/src/interop/rtc_peerconnection_interop.cc index d99ec56a32..08d6c11356 100644 --- a/src/interop/rtc_peerconnection_interop.cc +++ b/src/interop/rtc_peerconnection_interop.cc @@ -123,24 +123,23 @@ RTCPeerConnection_CreateDataChannel ( rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_CreateOffer ( rtcPeerConnectionHandle handle, - rtcOnGetSdpCallbacks* callbacks, + rtcObjectHandle user_data, + rtcOnGetSdpSuccessDelegate success, + rtcOnFailureDelegate failure, rtcMediaConstraintsHandle constraints ) noexcept { CHECK_NATIVE_HANDLE(handle); - CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); CHECK_POINTER_EX(constraints, rtcResultU4::kInvalidParameter); scoped_refptr p = static_cast(handle); - OnSdpCreateSuccess fn_success = [callbacks](const string sdp, const string type) { - if (callbacks && callbacks->Success) { - callbacks->Success(callbacks->UserData, sdp.c_string(), type.c_string()); - } + OnSdpCreateSuccess fn_success = [success, user_data](const string sdp, const string type) { + success(user_data, sdp.c_string(), type.c_string()); }; - OnSdpCreateFailure fn_failure = [callbacks](const char* error) { - if (callbacks && callbacks->Failure) { - callbacks->Failure(callbacks->UserData, error); - } + OnSdpCreateFailure fn_failure = [failure, user_data](const char* error) { + failure(user_data, error); }; scoped_refptr pConstraints= static_cast(constraints); p->CreateOffer(fn_success, fn_failure, pConstraints); @@ -150,24 +149,23 @@ RTCPeerConnection_CreateOffer ( rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_CreateAnswer ( rtcPeerConnectionHandle handle, - rtcOnGetSdpCallbacks* callbacks, + rtcObjectHandle user_data, + rtcOnGetSdpSuccessDelegate success, + rtcOnFailureDelegate failure, rtcMediaConstraintsHandle constraints ) noexcept { CHECK_NATIVE_HANDLE(handle); - CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); CHECK_POINTER_EX(constraints, rtcResultU4::kInvalidParameter); scoped_refptr p = static_cast(handle); - OnSdpCreateSuccess fn_success = [callbacks](const string sdp, const string type) { - if (callbacks && callbacks->Success) { - callbacks->Success(callbacks->UserData, sdp.c_string(), type.c_string()); - } + OnSdpCreateSuccess fn_success = [success, user_data](const string sdp, const string type) { + success(user_data, sdp.c_string(), type.c_string()); }; - OnSdpCreateFailure fn_failure = [callbacks](const char* error) { - if (callbacks && callbacks->Failure) { - callbacks->Failure(callbacks->UserData, error); - } + OnSdpCreateFailure fn_failure = [failure, user_data](const char* error) { + failure(user_data, error); }; scoped_refptr pConstraints= static_cast(constraints); p->CreateAnswer(fn_success, fn_failure, pConstraints); @@ -205,21 +203,20 @@ RTCPeerConnection_SetLocalDescription ( rtcPeerConnectionHandle handle, const char* sdp, const char* type, - rtcOnSetSdpCallbacks* callbacks + rtcObjectHandle user_data, + rtcOnSetSdpSuccessDelegate success, + rtcOnFailureDelegate failure ) noexcept { CHECK_NATIVE_HANDLE(handle); - CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); - OnSetSdpSuccess fn_success = [callbacks]() { - if (callbacks && callbacks->Success) { - callbacks->Success(callbacks->UserData); - } + OnSetSdpSuccess fn_success = [success, user_data]() { + success(user_data); }; - OnSetSdpFailure fn_failure = [callbacks](const char* error) { - if (callbacks && callbacks->Failure) { - callbacks->Failure(callbacks->UserData, error); - } + OnSetSdpFailure fn_failure = [failure, user_data](const char* error) { + failure(user_data, error); }; scoped_refptr p = static_cast(handle); p->SetLocalDescription(string(sdp), string(type), fn_success, fn_failure); @@ -231,21 +228,20 @@ RTCPeerConnection_SetRemoteDescription ( rtcPeerConnectionHandle handle, const char* sdp, const char* type, - rtcOnSetSdpCallbacks* callbacks + rtcObjectHandle user_data, + rtcOnSetSdpSuccessDelegate success, + rtcOnFailureDelegate failure ) noexcept { CHECK_NATIVE_HANDLE(handle); - CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); - OnSetSdpSuccess fn_success = [callbacks]() { - if (callbacks && callbacks->Success) { - callbacks->Success(callbacks->UserData); - } + OnSetSdpSuccess fn_success = [success, user_data]() { + success(user_data); }; - OnSetSdpFailure fn_failure = [callbacks](const char* error) { - if (callbacks && callbacks->Failure) { - callbacks->Failure(callbacks->UserData, error); - } + OnSetSdpFailure fn_failure = [failure, user_data](const char* error) { + failure(user_data, error); }; scoped_refptr p = static_cast(handle); p->SetRemoteDescription(string(sdp), string(type), fn_success, fn_failure); @@ -255,21 +251,20 @@ RTCPeerConnection_SetRemoteDescription ( rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_GetLocalDescription ( rtcPeerConnectionHandle handle, - rtcOnGetSdpCallbacks* callbacks + rtcObjectHandle user_data, + rtcOnGetSdpSuccessDelegate success, + rtcOnFailureDelegate failure ) noexcept { CHECK_NATIVE_HANDLE(handle); - CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); - OnGetSdpSuccess fn_success = [callbacks](const char* sdp, const char* type) { - if (callbacks && callbacks->Success) { - callbacks->Success(callbacks->UserData, sdp, type); - } + OnGetSdpSuccess fn_success = [success, user_data](const char* sdp, const char* type) { + success(user_data, sdp, type); }; - OnGetSdpFailure fn_failure = [callbacks](const char* error) { - if (callbacks && callbacks->Failure) { - callbacks->Failure(callbacks->UserData, error); - } + OnGetSdpFailure fn_failure = [failure, user_data](const char* error) { + failure(user_data, error); }; scoped_refptr p = static_cast(handle); p->GetLocalDescription(fn_success, fn_failure); @@ -279,21 +274,20 @@ RTCPeerConnection_GetLocalDescription ( rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_GetRemoteDescription ( rtcPeerConnectionHandle handle, - rtcOnGetSdpCallbacks* callbacks + rtcObjectHandle user_data, + rtcOnGetSdpSuccessDelegate success, + rtcOnFailureDelegate failure ) noexcept { CHECK_NATIVE_HANDLE(handle); - CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); - OnGetSdpSuccess fn_success = [callbacks](const char* sdp, const char* type) { - if (callbacks && callbacks->Success) { - callbacks->Success(callbacks->UserData, sdp, type); - } + OnGetSdpSuccess fn_success = [success, user_data](const char* sdp, const char* type) { + success(user_data, sdp, type); }; - OnGetSdpFailure fn_failure = [callbacks](const char* error) { - if (callbacks && callbacks->Failure) { - callbacks->Failure(callbacks->UserData, error); - } + OnGetSdpFailure fn_failure = [failure, user_data](const char* error) { + failure(user_data, error); }; scoped_refptr p = static_cast(handle); p->GetRemoteDescription(fn_success, fn_failure); @@ -377,7 +371,9 @@ rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_GetSenderStats ( rtcPeerConnectionHandle handle, rtcRtpSenderHandle sender, - rtcOnStatsCallbacks* callbacks, + rtcObjectHandle user_data, + rtcOnStatsCollectorSuccessDelegate success, + rtcOnFailureDelegate failure, rtcBool32* pOutRetVal ) noexcept { @@ -386,21 +382,18 @@ RTCPeerConnection_GetSenderStats ( } CHECK_NATIVE_HANDLE(handle); CHECK_POINTER_EX(sender, rtcResultU4::kInvalidParameter); - CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); - - OnStatsCollectorSuccess fn_success = [callbacks](const vector> reports) { - if (callbacks && callbacks->Success) { - scoped_refptr pList = MediaRTCStatsList::Create(reports); - callbacks->Success( - callbacks->UserData, - static_cast(pList.release()) - ); - } + CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); + + OnStatsCollectorSuccess fn_success = [success, user_data](const vector> reports) { + scoped_refptr pList = MediaRTCStatsList::Create(reports); + success( + user_data, + static_cast(pList.release()) + ); }; - OnStatsCollectorFailure fn_failure = [callbacks](const char* error) { - if (callbacks && callbacks->Failure) { - callbacks->Failure(callbacks->UserData, error); - } + OnStatsCollectorFailure fn_failure = [failure, user_data](const char* error) { + failure(user_data, error); }; scoped_refptr p = static_cast(handle); scoped_refptr pSender = static_cast(sender); @@ -415,7 +408,9 @@ rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_GetReceiverStats ( rtcPeerConnectionHandle handle, rtcRtpReceiverHandle receiver, - rtcOnStatsCallbacks* callbacks, + rtcObjectHandle user_data, + rtcOnStatsCollectorSuccessDelegate success, + rtcOnFailureDelegate failure, rtcBool32* pOutRetVal ) noexcept { @@ -424,21 +419,18 @@ RTCPeerConnection_GetReceiverStats ( } CHECK_NATIVE_HANDLE(handle); CHECK_POINTER_EX(receiver, rtcResultU4::kInvalidParameter); - CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); - - OnStatsCollectorSuccess fn_success = [callbacks](const vector> reports) { - if (callbacks && callbacks->Success) { - scoped_refptr pList = MediaRTCStatsList::Create(reports); - callbacks->Success( - callbacks->UserData, - static_cast(pList.release()) - ); - } + CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); + + OnStatsCollectorSuccess fn_success = [success, user_data](const vector> reports) { + scoped_refptr pList = MediaRTCStatsList::Create(reports); + success( + user_data, + static_cast(pList.release()) + ); }; - OnStatsCollectorFailure fn_failure = [callbacks](const char* error) { - if (callbacks && callbacks->Failure) { - callbacks->Failure(callbacks->UserData, error); - } + OnStatsCollectorFailure fn_failure = [failure, user_data](const char* error) { + failure(user_data, error); }; scoped_refptr p = static_cast(handle); scoped_refptr pReceiver = static_cast(receiver); @@ -452,25 +444,24 @@ RTCPeerConnection_GetReceiverStats ( rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnection_GetStats ( rtcPeerConnectionHandle handle, - rtcOnStatsCallbacks* callbacks + rtcObjectHandle user_data, + rtcOnStatsCollectorSuccessDelegate success, + rtcOnFailureDelegate failure ) noexcept { CHECK_NATIVE_HANDLE(handle); - CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); - - OnStatsCollectorSuccess fn_success = [callbacks](const vector> reports) { - if (callbacks && callbacks->Success) { - scoped_refptr pList = MediaRTCStatsList::Create(reports); - callbacks->Success( - callbacks->UserData, - static_cast(pList.release()) - ); - } + CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); + + OnStatsCollectorSuccess fn_success = [success, user_data](const vector> reports) { + scoped_refptr pList = MediaRTCStatsList::Create(reports); + success( + user_data, + static_cast(pList.release()) + ); }; - OnStatsCollectorFailure fn_failure = [callbacks](const char* error) { - if (callbacks && callbacks->Failure) { - callbacks->Failure(callbacks->UserData, error); - } + OnStatsCollectorFailure fn_failure = [failure, user_data](const char* error) { + failure(user_data, error); }; scoped_refptr p = static_cast(handle); p->GetStats(fn_success, fn_failure); From f6e21f005e2592a635f7e4b9a51a1e468aa5be50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Sun, 5 Jan 2025 21:34:24 +0300 Subject: [PATCH 54/69] BugFix --- src/interop/rtc_audio_device_interop.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interop/rtc_audio_device_interop.cc b/src/interop/rtc_audio_device_interop.cc index e01e2982b8..3ad59afc85 100644 --- a/src/interop/rtc_audio_device_interop.cc +++ b/src/interop/rtc_audio_device_interop.cc @@ -145,7 +145,7 @@ RTCAudioDevice_SetRecordingDevice( ) noexcept { CHECK_NATIVE_HANDLE(audiDevice); - if (index < 1) { + if (index < 0) { return rtcResultU4::kOutOfRange; } From 141cd493346222481be70c982dbc65c5dec9304f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Thu, 9 Jan 2025 15:45:18 +0300 Subject: [PATCH 55/69] Added rtc_desktop_capturer_interop.cc --- BUILD.gn | 1 + include/interop_api.h | 75 +++++++++++++ include/rtc_desktop_capturer.h | 4 +- src/interop/rtc_desktop_capturer_interop.cc | 114 ++++++++++++++++++++ src/rtc_desktop_capturer_impl.cc | 60 +++++++++++ src/rtc_desktop_capturer_impl.h | 20 ++++ 6 files changed, 273 insertions(+), 1 deletion(-) create mode 100644 src/interop/rtc_desktop_capturer_interop.cc diff --git a/BUILD.gn b/BUILD.gn index d89f558082..47f43f8d35 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -189,6 +189,7 @@ rtc_shared_library("libwebrtc") { if (libwebrtc_desktop_capture) { sources += [ "src/interop/rtc_desktop_media_list_interop.cc", + "src/interop/rtc_desktop_capturer_interop.cc", "src/interop/rtc_desktop_device_interop.cc", ] } diff --git a/include/interop_api.h b/include/interop_api.h index 36ad781492..449c669d4a 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -187,6 +187,12 @@ enum class rtcNetworkPriority : int { kHigh = 3 }; +enum class rtcDesktopCaptureState : int { + CS_RUNNING = 0, + CS_STOPPED = 1, + CS_FAILED = 2 +}; + /// 32-bit result enumerator enum class rtcResultU4 : unsigned int { /// The operation was successful. @@ -562,6 +568,23 @@ struct rtcMediaListObserverCallbacks { rtcMediaListObserverDelegate MediaSourceThumbnailChanged{}; }; +/** + * Desktop capturer callback delegate + */ +using rtcDesktopCapturerCommonDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data); + +/** + * Callback delegate structure for DesktopCapturerObserver. + */ +struct rtcDesktopCapturerObserverCallbacks { + rtcObjectHandle UserData{}; + rtcDesktopCapturerCommonDelegate Started{}; + rtcDesktopCapturerCommonDelegate Paused{}; + rtcDesktopCapturerCommonDelegate Stopped{}; + rtcDesktopCapturerCommonDelegate Failed{}; +}; + /** * Callback OnFrame delegate for RTCVideoRenderer. */ @@ -1540,6 +1563,58 @@ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL MediaSource_GetThumbnail(rtcDesktopMediaSourceHandle mediaSource, unsigned char* pBuffer, int* refSizeOfBuffer) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCDesktopCapturer interop methods + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopCapturer_RegisterObserver( + rtcDesktopCapturerHandle handle, + rtcDesktopCapturerObserverCallbacks* callbacks +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopCapturer_UnregisterObserver( + rtcDesktopCapturerHandle handle +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopCapturer_Start1( + rtcDesktopCapturerHandle handle, + unsigned int fps, + rtcDesktopCaptureState* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopCapturer_Start2( + rtcDesktopCapturerHandle handle, + unsigned int fps, + unsigned int x, + unsigned int y, + unsigned int width, + unsigned int height, + rtcDesktopCaptureState* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopCapturer_Stop( + rtcDesktopCapturerHandle handle +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopCapturer_IsRunning( + rtcDesktopCapturerHandle handle, + rtcBool32* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopCapturer_GetSource( + rtcDesktopCapturerHandle handle, + rtcDesktopMediaSourceHandle* pOutRetVal +) noexcept; + /* * ---------------------------------------------------------------------- * RTCDesktopDevice interop methods diff --git a/include/rtc_desktop_capturer.h b/include/rtc_desktop_capturer.h index 9d2e955ab3..ddfebea157 100644 --- a/include/rtc_desktop_capturer.h +++ b/include/rtc_desktop_capturer.h @@ -86,6 +86,8 @@ class RTCDesktopCapturer : public RefCountInterface { */ virtual scoped_refptr source() = 0; + virtual DesktopCapturerObserver* GetObserver() = 0; + /** * @brief Destroys the RTCDesktopCapturer object. */ @@ -130,7 +132,7 @@ class DesktopCapturerObserver { virtual void OnError(scoped_refptr capturer) = 0; protected: - ~DesktopCapturerObserver() {} + virtual ~DesktopCapturerObserver() {} }; } // namespace libwebrtc diff --git a/src/interop/rtc_desktop_capturer_interop.cc b/src/interop/rtc_desktop_capturer_interop.cc new file mode 100644 index 0000000000..dfeee0d985 --- /dev/null +++ b/src/interop/rtc_desktop_capturer_interop.cc @@ -0,0 +1,114 @@ +#include "rtc_desktop_capturer.h" +#include "src/rtc_desktop_capturer_impl.h" +#include "interop_api.h" + +using namespace libwebrtc; + +#ifdef RTC_DESKTOP_DEVICE + +rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopCapturer_RegisterObserver( + rtcDesktopCapturerHandle handle, + rtcDesktopCapturerObserverCallbacks* callbacks +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); + + // unregistered + RTCDesktopCapturer_UnregisterObserver(handle); + + DesktopCapturerObserver* pObserver = static_cast(new DesktopCapturerObserverImpl(callbacks)); + scoped_refptr p = static_cast(handle); + p->RegisterDesktopCapturerObserver(pObserver); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopCapturer_UnregisterObserver( + rtcDesktopCapturerHandle handle +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr p = static_cast(handle); + DesktopCapturerObserverImpl* pObserverImpl = static_cast(p->GetObserver()); + p->DeRegisterDesktopCapturerObserver(); + if (pObserverImpl) { + delete pObserverImpl; + } + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopCapturer_Start1( + rtcDesktopCapturerHandle handle, + unsigned int fps, + rtcDesktopCaptureState* pOutRetVal +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER(pOutRetVal); + *pOutRetVal = rtcDesktopCaptureState::CS_FAILED; + + scoped_refptr p = static_cast(handle); + *pOutRetVal = static_cast(p->Start(static_cast(fps))); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopCapturer_Start2( + rtcDesktopCapturerHandle handle, + unsigned int fps, + unsigned int x, + unsigned int y, + unsigned int width, + unsigned int height, + rtcDesktopCaptureState* pOutRetVal +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER(pOutRetVal); + *pOutRetVal = rtcDesktopCaptureState::CS_FAILED; + + scoped_refptr p = static_cast(handle); + *pOutRetVal = static_cast(p->Start( + static_cast(fps), + static_cast(x), + static_cast(y), + static_cast(width), + static_cast(height) + )); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopCapturer_Stop( + rtcDesktopCapturerHandle handle +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + scoped_refptr p = static_cast(handle); + p->Stop(); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopCapturer_IsRunning( + rtcDesktopCapturerHandle handle, + rtcBool32* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcBool32, RTCDesktopCapturer, IsRunning); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopCapturer_GetSource( + rtcDesktopCapturerHandle handle, + rtcDesktopMediaSourceHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcDesktopMediaSourceHandle, RTCDesktopCapturer, source().release); +} + +#endif // RTC_DESKTOP_DEVICE diff --git a/src/rtc_desktop_capturer_impl.cc b/src/rtc_desktop_capturer_impl.cc index 93dec6d38d..18d3957aff 100644 --- a/src/rtc_desktop_capturer_impl.cc +++ b/src/rtc_desktop_capturer_impl.cc @@ -23,10 +23,70 @@ #include "modules/desktop_capture/win/window_capture_utils.h" #endif +#include "interop_api.h" + namespace libwebrtc { enum { kCaptureDelay = 33, kCaptureMessageId = 1000 }; +/** + * DesktopCapturerObserverImpl + */ + +DesktopCapturerObserverImpl::DesktopCapturerObserverImpl(void* callbacks /* rtcDesktopCapturerObserverCallbacks* */) + : callbacks_(nullptr) +{ + if (callbacks) { + size_t nSize = sizeof(rtcDesktopCapturerObserverCallbacks); + callbacks_ = malloc(nSize); + memcpy(callbacks_, (const void*)callbacks, nSize); + } +} + +DesktopCapturerObserverImpl::~DesktopCapturerObserverImpl() +{ + if (callbacks_) { + free(callbacks_); + } + callbacks_ = nullptr; +} + +void DesktopCapturerObserverImpl::OnStart(scoped_refptr capturer) +{ + if (callbacks_) { + rtcDesktopCapturerObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + pCallbacks->Started(pCallbacks->UserData); + } +} + +void DesktopCapturerObserverImpl::OnPaused(scoped_refptr capturer) +{ + if (callbacks_) { + rtcDesktopCapturerObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + pCallbacks->Paused(pCallbacks->UserData); + } +} + +void DesktopCapturerObserverImpl::OnStop(scoped_refptr capturer) +{ + if (callbacks_) { + rtcDesktopCapturerObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + pCallbacks->Stopped(pCallbacks->UserData); + } +} + +void DesktopCapturerObserverImpl::OnError(scoped_refptr capturer) +{ + if (callbacks_) { + rtcDesktopCapturerObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + pCallbacks->Failed(pCallbacks->UserData); + } +} + +/** + * class RTCDesktopCapturerImpl + */ + RTCDesktopCapturerImpl::RTCDesktopCapturerImpl( DesktopType type, webrtc::DesktopCapturer::SourceId source_id, rtc::Thread* signaling_thread, scoped_refptr source) diff --git a/src/rtc_desktop_capturer_impl.h b/src/rtc_desktop_capturer_impl.h index 7ae63f546b..f29fb0970c 100644 --- a/src/rtc_desktop_capturer_impl.h +++ b/src/rtc_desktop_capturer_impl.h @@ -31,6 +31,24 @@ namespace libwebrtc { +/** + * class DesktopCapturerObserverImpl + */ +class DesktopCapturerObserverImpl : public DesktopCapturerObserver +{ + public: + DesktopCapturerObserverImpl(void* callbacks /* rtcDesktopCapturerObserverCallbacks* */); + ~DesktopCapturerObserverImpl(); + + void OnStart(scoped_refptr capturer) override; + void OnPaused(scoped_refptr capturer) override; + void OnStop(scoped_refptr capturer) override; + void OnError(scoped_refptr capturer) override; + + private: + void* callbacks_ /* rtcDesktopCapturerObserverCallbacks* */; +}; // end class DesktopCapturerObserverImpl + class RTCDesktopCapturerImpl : public RTCDesktopCapturer, public webrtc::DesktopCapturer::Callback, public webrtc::internal::VideoCapturer { @@ -58,6 +76,8 @@ class RTCDesktopCapturerImpl : public RTCDesktopCapturer, scoped_refptr source() override { return source_; } + DesktopCapturerObserver* GetObserver() override { return observer_; } + protected: virtual void OnCaptureResult( webrtc::DesktopCapturer::Result result, From 199c9da3b43467c441c73b1bf2e53bd2ce82ca18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Sun, 12 Jan 2025 00:13:59 +0300 Subject: [PATCH 56/69] Optimization --- src/rtc_desktop_capturer_impl.cc | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/rtc_desktop_capturer_impl.cc b/src/rtc_desktop_capturer_impl.cc index 18d3957aff..1f3d6ad7e1 100644 --- a/src/rtc_desktop_capturer_impl.cc +++ b/src/rtc_desktop_capturer_impl.cc @@ -170,7 +170,9 @@ RTCDesktopCapturerImpl::CaptureState RTCDesktopCapturerImpl::Start( capture_state_ = CS_RUNNING; thread_->PostTask([this] { CaptureFrame(); }); if (observer_) { - signaling_thread_->BlockingCall([&, this]() { observer_->OnStart(this); }); + signaling_thread_->BlockingCall([&, this]() { + if (observer_) { observer_->OnStart(this); } + }); } return capture_state_; } @@ -178,7 +180,9 @@ RTCDesktopCapturerImpl::CaptureState RTCDesktopCapturerImpl::Start( void RTCDesktopCapturerImpl::Stop() { if (observer_) { if (!signaling_thread_->IsCurrent()) { - signaling_thread_->BlockingCall([&, this]() { observer_->OnStop(this); }); + signaling_thread_->BlockingCall([&, this]() { + if (observer_) { observer_->OnStop(this); } + }); } else { observer_->OnStop(this); } @@ -202,8 +206,9 @@ void RTCDesktopCapturerImpl::OnCaptureResult( if (result != result_) { if (result == webrtc::DesktopCapturer::Result::ERROR_PERMANENT) { if (observer_) { - signaling_thread_->BlockingCall( - [&, this]() { observer_->OnError(this); }); + signaling_thread_->BlockingCall([&, this]() { + if (observer_) { observer_->OnError(this); } + }); } capture_state_ = CS_FAILED; return; @@ -212,8 +217,9 @@ void RTCDesktopCapturerImpl::OnCaptureResult( if (result == webrtc::DesktopCapturer::Result::ERROR_TEMPORARY) { result_ = result; if (observer_) { - signaling_thread_->BlockingCall( - [&, this]() { observer_->OnPaused(this); }); + signaling_thread_->BlockingCall([&, this]() { + if (observer_) { observer_->OnPaused(this); } + }); } return; } @@ -221,8 +227,9 @@ void RTCDesktopCapturerImpl::OnCaptureResult( if (result == webrtc::DesktopCapturer::Result::SUCCESS) { result_ = result; if (observer_) { - signaling_thread_->BlockingCall( - [&, this]() { observer_->OnStart(this); }); + signaling_thread_->BlockingCall([&, this]() { + if (observer_) { observer_->OnStart(this); } + }); } } } From ddcb34f70f18e2de7501317c428a03db520f2df7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Mon, 13 Jan 2025 04:47:21 +0300 Subject: [PATCH 57/69] Created rtc_dummy_video_capturer --- BUILD.gn | 6 + include/interop_api.h | 115 +++++++++- include/rtc_desktop_capturer.h | 10 +- include/rtc_dummy_video_capturer.h | 59 +++++ include/rtc_peerconnection_factory.h | 6 + include/rtc_types.h | 2 + include/rtc_video_renderer.h | 4 + src/internal/dummy_capturer.cc | 3 + src/internal/dummy_capturer.h | 47 ++++ src/interop/rtc_desktop_capturer_interop.cc | 12 +- .../rtc_dummy_video_capturer_interop.cc | 124 +++++++++++ .../rtc_peerconnection_factory_interop.cc | 43 ++++ src/rtc_desktop_capturer_impl.cc | 22 +- src/rtc_desktop_capturer_impl.h | 6 +- src/rtc_dummy_video_capturer_impl.cc | 203 ++++++++++++++++++ src/rtc_dummy_video_capturer_impl.h | 87 ++++++++ src/rtc_peerconnection_factory_impl.cc | 43 ++++ src/rtc_peerconnection_factory_impl.h | 10 + src/rtc_video_renderer_impl.cc | 15 ++ src/rtc_video_renderer_impl.h | 2 + 20 files changed, 783 insertions(+), 36 deletions(-) create mode 100644 include/rtc_dummy_video_capturer.h create mode 100644 src/internal/dummy_capturer.cc create mode 100644 src/internal/dummy_capturer.h create mode 100644 src/interop/rtc_dummy_video_capturer_interop.cc create mode 100644 src/rtc_dummy_video_capturer_impl.cc create mode 100644 src/rtc_dummy_video_capturer_impl.h diff --git a/BUILD.gn b/BUILD.gn index 47f43f8d35..300fd0d9d0 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -96,6 +96,7 @@ rtc_shared_library("libwebrtc") { "include/rtc_video_renderer.h", "include/rtc_video_source.h", "include/rtc_video_track.h", + "include/rtc_dummy_video_capturer.h", "include/helper.h", "src/helper.cc", "src/base/portable.cc", @@ -103,6 +104,8 @@ rtc_shared_library("libwebrtc") { "src/internal/vcm_capturer.h", "src/internal/video_capturer.cc", "src/internal/video_capturer.h", + "src/internal/dummy_capturer.cc", + "src/internal/dummy_capturer.h", "src/libwebrtc.cc", "src/rtc_audio_device_impl.cc", "src/rtc_audio_device_impl.h", @@ -154,6 +157,8 @@ rtc_shared_library("libwebrtc") { "src/rtc_video_source_impl.h", "src/rtc_video_track_impl.cc", "src/rtc_video_track_impl.h", + "src/rtc_dummy_video_capturer_impl.cc", + "src/rtc_dummy_video_capturer_impl.h", ] # for interop methods @@ -173,6 +178,7 @@ rtc_shared_library("libwebrtc") { "src/interop/rtc_video_track_interop.cc", "src/interop/rtc_video_frame_interop.cc", "src/interop/rtc_video_renderer_interop.cc", + "src/interop/rtc_dummy_video_capturer_interop.cc", "src/interop/rtc_data_channel_interop.cc", "src/interop/rtc_ice_candidate_interop.cc", "src/interop/rtc_media_stream_interop.cc", diff --git a/include/interop_api.h b/include/interop_api.h index 449c669d4a..d735bcef0f 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -24,6 +24,7 @@ using rtcMediaSecurityType = libwebrtc::MediaSecurityType; using rtcSdpSemantics = libwebrtc::SdpSemantics; using rtcMediaType = libwebrtc::RTCMediaType; using rtcDesktopType = libwebrtc::DesktopType; +using rtcCaptureState = libwebrtc::RTCCaptureState; /// 64-bit timestamp for interop API. using rtcTimestamp = long long; @@ -187,12 +188,6 @@ enum class rtcNetworkPriority : int { kHigh = 3 }; -enum class rtcDesktopCaptureState : int { - CS_RUNNING = 0, - CS_STOPPED = 1, - CS_FAILED = 2 -}; - /// 32-bit result enumerator enum class rtcResultU4 : unsigned int { /// The operation was successful. @@ -405,6 +400,9 @@ using rtcDesktopMediaSourceHandle = rtcRefCountedObjectHandle; /// Opaque handle to a native RTCDesktopMediaList interop object. using rtcDesktopMediaListHandle = rtcRefCountedObjectHandle; +/// Opaque handle to a native RTCDummyVideoCapturer interop object. +using rtcDummyVideoCapturerHandle = rtcRefCountedObjectHandle; + /// Opaque handle to a native RTCMediaStream interop object. using rtcMediaStreamHandle = rtcRefCountedObjectHandle; @@ -585,6 +583,30 @@ struct rtcDesktopCapturerObserverCallbacks { rtcDesktopCapturerCommonDelegate Failed{}; }; +/** + * Dummy video capturer callback delegate + */ +using rtcDummyVideoCapturerCommonDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data); + +/** + * Dummy video capturer fill buffer callback delegate + */ +using rtcDummyVideoCapturerFillBufferDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, rtcVideoFrameHandle frame); + +/** + * Callback delegate structure for DummyVideoCapturerObserver. + */ +struct rtcDummyVideoCapturerObserverCallbacks { + rtcObjectHandle UserData{}; + rtcDummyVideoCapturerCommonDelegate Started{}; + rtcDummyVideoCapturerCommonDelegate Paused{}; + rtcDummyVideoCapturerCommonDelegate Stopped{}; + rtcDummyVideoCapturerCommonDelegate Failed{}; + rtcDummyVideoCapturerFillBufferDelegate FillBuffer{}; +}; + /** * Callback OnFrame delegate for RTCVideoRenderer. */ @@ -909,6 +931,27 @@ RTCPeerConnectionFactory_CreateDesktopSource( rtcVideoSourceHandle* pRetVal) noexcept; #endif // RTC_DESKTOP_DEVICE +/** + * @brief Creates a new instance of the RTCDummyVideoCapturer object. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_CreateDummyVideoCapturer( + rtcPeerConnectionFactoryHandle factory, + unsigned int fps, + unsigned int width, + unsigned int height, + rtcDummyVideoCapturerHandle* pRetVal) noexcept; + +/** + * @brief Creates a new instance of the RTCVideoSource object. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_CreateDummyVideoSource( + rtcPeerConnectionFactoryHandle factory, + rtcDummyVideoCapturerHandle capturer, + const char* video_source_label, + rtcVideoSourceHandle* pRetVal) noexcept; + /** * @brief Creates a new instance of the RTCAudioTrack object. */ @@ -1584,7 +1627,7 @@ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCDesktopCapturer_Start1( rtcDesktopCapturerHandle handle, unsigned int fps, - rtcDesktopCaptureState* pOutRetVal + rtcCaptureState* pOutRetVal ) noexcept; LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL @@ -1595,7 +1638,7 @@ RTCDesktopCapturer_Start2( unsigned int y, unsigned int width, unsigned int height, - rtcDesktopCaptureState* pOutRetVal + rtcCaptureState* pOutRetVal ) noexcept; LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL @@ -1648,6 +1691,62 @@ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCDesktopDevice_GetDesktopMediaList( #endif // RTC_DESKTOP_DEVICE +/* + * ---------------------------------------------------------------------- + * RTCDummyVideoCapturer interop methods + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDummyVideoCapturer_RegisterObserver( + rtcDummyVideoCapturerHandle handle, + rtcDummyVideoCapturerObserverCallbacks* callbacks +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDummyVideoCapturer_UnregisterObserver( + rtcDummyVideoCapturerHandle handle +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDummyVideoCapturer_Start1( + rtcDummyVideoCapturerHandle handle, + rtcCaptureState* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDummyVideoCapturer_Start2( + rtcDummyVideoCapturerHandle handle, + unsigned int fps, + rtcCaptureState* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDummyVideoCapturer_Start3( + rtcDummyVideoCapturerHandle handle, + unsigned int fps, + unsigned int width, + unsigned int height, + rtcCaptureState* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDummyVideoCapturer_Stop( + rtcDummyVideoCapturerHandle handle +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDummyVideoCapturer_IsRunning( + rtcDummyVideoCapturerHandle handle, + rtcBool32* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDummyVideoCapturer_GetState( + rtcDummyVideoCapturerHandle handle, + rtcCaptureState* pOutRetVal +) noexcept; + /* * ---------------------------------------------------------------------- * RTCDataChannel interop methods diff --git a/include/rtc_desktop_capturer.h b/include/rtc_desktop_capturer.h index ddfebea157..7fcd6c4ee9 100644 --- a/include/rtc_desktop_capturer.h +++ b/include/rtc_desktop_capturer.h @@ -22,12 +22,6 @@ class DesktopCapturerObserver; * retrieving the current capture state and media source. */ class RTCDesktopCapturer : public RefCountInterface { - public: - /** - * @brief Enumeration for the possible states of desktop capture. - */ - enum CaptureState { CS_RUNNING, CS_STOPPED, CS_FAILED }; - public: /** * @brief Registers the given observer for desktop capture events. @@ -49,7 +43,7 @@ class RTCDesktopCapturer : public RefCountInterface { * * @return The current capture state after attempting to start capture. */ - virtual CaptureState Start(uint32_t fps) = 0; + virtual RTCCaptureState Start(uint32_t fps) = 0; /** * @brief Starts desktop capture with the given frame rate and capture @@ -63,7 +57,7 @@ class RTCDesktopCapturer : public RefCountInterface { * * @return The current capture state after attempting to start capture. */ - virtual CaptureState Start(uint32_t fps, uint32_t x, uint32_t y, uint32_t w, + virtual RTCCaptureState Start(uint32_t fps, uint32_t x, uint32_t y, uint32_t w, uint32_t h) = 0; /** diff --git a/include/rtc_dummy_video_capturer.h b/include/rtc_dummy_video_capturer.h new file mode 100644 index 0000000000..8e9c9d48ef --- /dev/null +++ b/include/rtc_dummy_video_capturer.h @@ -0,0 +1,59 @@ +#ifndef LIB_WEBRTC_RTC_DUMMY_VIDEO_CAPTURER_HXX +#define LIB_WEBRTC_RTC_DUMMY_VIDEO_CAPTURER_HXX + +#include "rtc_types.h" +#include "rtc_video_device.h" +#include "rtc_video_frame.h" + +namespace libwebrtc { + +/** + * class DummyVideoCapturerObserver + */ +class DummyVideoCapturerObserver { + public: + virtual void OnStart() = 0; + + virtual void OnPaused() = 0; + + virtual void OnStop() = 0; + + virtual void OnError() = 0; + + virtual void OnFillBuffer(scoped_refptr frame) = 0; + + protected: + virtual ~DummyVideoCapturerObserver() {} +}; // class DummyVideoCapturerObserver + +/** + * class RTCDummyVideoCapturer + */ +class RTCDummyVideoCapturer : public RefCountInterface { + public: + virtual void RegisterObserver( + DummyVideoCapturerObserver* observer) = 0; + + virtual void DeRegisterObserver() = 0; + + virtual RTCCaptureState Start() = 0; + + virtual RTCCaptureState Start(uint32_t fps) = 0; + + virtual RTCCaptureState Start(uint32_t fps, + uint32_t width, + uint32_t height) = 0; + virtual void Stop() = 0; + + virtual bool IsRunning() const = 0; + + virtual RTCCaptureState state() const = 0; + + virtual DummyVideoCapturerObserver* GetObserver() = 0; + + virtual ~RTCDummyVideoCapturer() {} +}; // class RTCDummyVideoCapturer + +} // namespace libwebrtc + +#endif // LIB_WEBRTC_RTC_DUMMY_VIDEO_CAPTURER_HXX diff --git a/include/rtc_peerconnection_factory.h b/include/rtc_peerconnection_factory.h index cb024672c2..6dfa70fc5d 100644 --- a/include/rtc_peerconnection_factory.h +++ b/include/rtc_peerconnection_factory.h @@ -11,6 +11,7 @@ #include "rtc_mediaconstraints.h" #include "rtc_video_device.h" #include "rtc_video_source.h" +#include "rtc_dummy_video_capturer.h" namespace libwebrtc { @@ -49,6 +50,11 @@ class RTCPeerConnectionFactory : public RefCountInterface { const string video_source_label, scoped_refptr constraints) = 0; #endif + virtual scoped_refptr CreateDummyVideoCapturer( + uint32_t fps, uint32_t width, uint32_t height) = 0; + virtual scoped_refptr CreateDummyVideoSource( + scoped_refptr capturer, const string video_source_label) = 0; + virtual scoped_refptr CreateAudioTrack( scoped_refptr source, const string track_id) = 0; diff --git a/include/rtc_types.h b/include/rtc_types.h index d98a2f4e51..994243711b 100644 --- a/include/rtc_types.h +++ b/include/rtc_types.h @@ -30,6 +30,8 @@ enum class MediaSecurityType { kSRTP_None = 0, kSDES_SRTP, kDTLS_SRTP }; enum class RTCMediaType { AUDIO, VIDEO, DATA, UNSUPPORTED }; +enum class RTCCaptureState { CS_RUNNING = 0, CS_STOPPED, CS_FAILED }; + using string = portable::string; // template diff --git a/include/rtc_video_renderer.h b/include/rtc_video_renderer.h index a7089cb941..0ff08a7637 100644 --- a/include/rtc_video_renderer.h +++ b/include/rtc_video_renderer.h @@ -7,12 +7,16 @@ namespace libwebrtc { template class RTCVideoRenderer : public RefCountInterface { + public: + typedef fixed_size_function OnFrameCallbackSafe; + public: virtual ~RTCVideoRenderer() {} virtual void OnFrame(VideoFrameT frame) = 0; virtual void RegisterFrameCallback(void* user_data /* rtcObjectHandle */, void* callback /* rtcVideoRendererFrameDelegate */) = 0; + virtual void RegisterFrameCallback(OnFrameCallbackSafe callback) = 0; virtual void UnRegisterFrameCallback() = 0; public: diff --git a/src/internal/dummy_capturer.cc b/src/internal/dummy_capturer.cc new file mode 100644 index 0000000000..ac4aa19c9d --- /dev/null +++ b/src/internal/dummy_capturer.cc @@ -0,0 +1,3 @@ +#include "dummy_capturer.h" + +namespace libwebrtc {} // namespace libwebrtc \ No newline at end of file diff --git a/src/internal/dummy_capturer.h b/src/internal/dummy_capturer.h new file mode 100644 index 0000000000..da170b30e9 --- /dev/null +++ b/src/internal/dummy_capturer.h @@ -0,0 +1,47 @@ +#ifndef LIB_WEBRTC_DUMMY_CAPTURER_IMPL_HXX +#define LIB_WEBRTC_DUMMY_CAPTURER_IMPL_HXX + +#include "api/scoped_refptr.h" +#include "api/video/i420_buffer.h" +#include "api/video/video_frame.h" +#include "api/video/video_source_interface.h" +#include "include/base/refcount.h" +#include "media/base/video_adapter.h" +#include "media/base/video_broadcaster.h" +#include "modules/video_capture/video_capture.h" +#include "modules/video_capture/video_capture_factory.h" +#include "pc/video_track_source.h" +#include "rtc_base/thread.h" +#include "rtc_types.h" +#include "src/internal/video_capturer.h" +#include "src/rtc_dummy_video_capturer_impl.h" +#include "third_party/libyuv/include/libyuv.h" + +namespace libwebrtc { + +class DummyCapturerTrackSource : public webrtc::VideoTrackSource { + public: + static rtc::scoped_refptr Create( + scoped_refptr capturer) { + if (capturer) { + return rtc::make_ref_counted(capturer); + } + return nullptr; + } + + public: + explicit DummyCapturerTrackSource(scoped_refptr capturer) + : VideoTrackSource(/*remote=*/false), capturer_(std::move(capturer)) {} + virtual ~DummyCapturerTrackSource() { capturer_->Stop(); } + + private: + rtc::VideoSourceInterface* source() override { + return static_cast(capturer_.get()); + } + + scoped_refptr capturer_; +}; + +} // namespace libwebrtc + +#endif // LIB_WEBRTC_DUMMY_CAPTURER_IMPL_HXX diff --git a/src/interop/rtc_desktop_capturer_interop.cc b/src/interop/rtc_desktop_capturer_interop.cc index dfeee0d985..e685b28381 100644 --- a/src/interop/rtc_desktop_capturer_interop.cc +++ b/src/interop/rtc_desktop_capturer_interop.cc @@ -44,15 +44,15 @@ rtcResultU4 LIB_WEBRTC_CALL RTCDesktopCapturer_Start1( rtcDesktopCapturerHandle handle, unsigned int fps, - rtcDesktopCaptureState* pOutRetVal + rtcCaptureState* pOutRetVal ) noexcept { CHECK_NATIVE_HANDLE(handle); CHECK_POINTER(pOutRetVal); - *pOutRetVal = rtcDesktopCaptureState::CS_FAILED; + *pOutRetVal = rtcCaptureState::CS_FAILED; scoped_refptr p = static_cast(handle); - *pOutRetVal = static_cast(p->Start(static_cast(fps))); + *pOutRetVal = static_cast(p->Start(static_cast(fps))); return rtcResultU4::kSuccess; } @@ -64,15 +64,15 @@ RTCDesktopCapturer_Start2( unsigned int y, unsigned int width, unsigned int height, - rtcDesktopCaptureState* pOutRetVal + rtcCaptureState* pOutRetVal ) noexcept { CHECK_NATIVE_HANDLE(handle); CHECK_POINTER(pOutRetVal); - *pOutRetVal = rtcDesktopCaptureState::CS_FAILED; + *pOutRetVal = rtcCaptureState::CS_FAILED; scoped_refptr p = static_cast(handle); - *pOutRetVal = static_cast(p->Start( + *pOutRetVal = static_cast(p->Start( static_cast(fps), static_cast(x), static_cast(y), diff --git a/src/interop/rtc_dummy_video_capturer_interop.cc b/src/interop/rtc_dummy_video_capturer_interop.cc new file mode 100644 index 0000000000..1d83101edb --- /dev/null +++ b/src/interop/rtc_dummy_video_capturer_interop.cc @@ -0,0 +1,124 @@ +#include "src/rtc_dummy_video_capturer_impl.h" +#include "interop_api.h" + +using namespace libwebrtc; + +rtcResultU4 LIB_WEBRTC_CALL +RTCDummyVideoCapturer_RegisterObserver( + rtcDummyVideoCapturerHandle handle, + rtcDummyVideoCapturerObserverCallbacks* callbacks +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); + + // unregistered + RTCDummyVideoCapturer_UnregisterObserver(handle); + + scoped_refptr p = static_cast(handle); + DummyVideoCapturerObserver* pObserver = static_cast( + new DummyVideoCapturerObserverImpl(static_cast(callbacks)) + ); + p->RegisterObserver(pObserver); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDummyVideoCapturer_UnregisterObserver( + rtcDummyVideoCapturerHandle handle +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr p = static_cast(handle); + DummyVideoCapturerObserverImpl* pObserverImpl = static_cast(p->GetObserver()); + p->DeRegisterObserver(); + if (pObserverImpl) { + delete pObserverImpl; + } + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDummyVideoCapturer_Start1( + rtcDummyVideoCapturerHandle handle, + rtcCaptureState* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcCaptureState, RTCDummyVideoCapturer, Start); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDummyVideoCapturer_Start2( + rtcDummyVideoCapturerHandle handle, + unsigned int fps, + rtcCaptureState* pOutRetVal +) noexcept +{ + CHECK_POINTER(pOutRetVal); + *pOutRetVal = rtcCaptureState::CS_FAILED; + CHECK_NATIVE_HANDLE(handle); + if (fps == 0) { + return rtcResultU4::kInvalidParameter; + } + + scoped_refptr p = static_cast(handle); + *pOutRetVal = static_cast(p->Start( + static_cast(fps) + )); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDummyVideoCapturer_Start3( + rtcDummyVideoCapturerHandle handle, + unsigned int fps, + unsigned int width, + unsigned int height, + rtcCaptureState* pOutRetVal +) noexcept +{ + CHECK_POINTER(pOutRetVal); + *pOutRetVal = rtcCaptureState::CS_FAILED; + CHECK_NATIVE_HANDLE(handle); + if (fps == 0 || width == 0 || height == 0) { + return rtcResultU4::kInvalidParameter; + } + + scoped_refptr p = static_cast(handle); + *pOutRetVal = static_cast(p->Start( + static_cast(fps), + static_cast(width), + static_cast(height) + )); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDummyVideoCapturer_Stop( + rtcDummyVideoCapturerHandle handle +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + scoped_refptr p = static_cast(handle); + p->Stop(); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDummyVideoCapturer_IsRunning( + rtcDummyVideoCapturerHandle handle, + rtcBool32* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcBool32, RTCDummyVideoCapturer, IsRunning); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDummyVideoCapturer_GetState( + rtcDummyVideoCapturerHandle handle, + rtcCaptureState* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcCaptureState, RTCDummyVideoCapturer, state); +} diff --git a/src/interop/rtc_peerconnection_factory_interop.cc b/src/interop/rtc_peerconnection_factory_interop.cc index 62570b3848..78e6a14029 100644 --- a/src/interop/rtc_peerconnection_factory_interop.cc +++ b/src/interop/rtc_peerconnection_factory_interop.cc @@ -226,6 +226,49 @@ RTCPeerConnectionFactory_CreateDesktopSource( } // end RTCPeerConnectionFactory_CreateDesktopSource #endif // RTC_DESKTOP_DEVICE +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_CreateDummyVideoCapturer( + rtcPeerConnectionFactoryHandle factory, + unsigned int fps, + unsigned int width, + unsigned int height, + rtcDummyVideoCapturerHandle* pRetVal) noexcept +{ + CHECK_OUT_POINTER(pRetVal); + CHECK_NATIVE_HANDLE(factory); + if (fps == 0 || width == 0 || height == 0) { + return rtcResultU4::kInvalidParameter; + } + + scoped_refptr pFactory = static_cast(factory); + scoped_refptr pDummyVideoCapturer = pFactory->CreateDummyVideoCapturer( + fps, width, height + ); + *pRetVal = static_cast(pDummyVideoCapturer.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_CreateDummyVideoSource( + rtcPeerConnectionFactoryHandle factory, + rtcDummyVideoCapturerHandle capturer, + const char* video_source_label, + rtcVideoSourceHandle* pRetVal) noexcept +{ + CHECK_OUT_POINTER(pRetVal); + CHECK_NATIVE_HANDLE(factory); + CHECK_POINTER_EX(capturer, rtcResultU4::kInvalidParameter); + + scoped_refptr pFactory = static_cast(factory); + scoped_refptr pDummyVideoCapturer = static_cast(capturer); + scoped_refptr pVideoSource = pFactory->CreateDummyVideoSource( + pDummyVideoCapturer, + string(video_source_label) + ); + *pRetVal = static_cast(pVideoSource.release()); + return rtcResultU4::kSuccess; +} + rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_CreateAudioTrack( rtcPeerConnectionFactoryHandle factory, diff --git a/src/rtc_desktop_capturer_impl.cc b/src/rtc_desktop_capturer_impl.cc index 1f3d6ad7e1..b752645537 100644 --- a/src/rtc_desktop_capturer_impl.cc +++ b/src/rtc_desktop_capturer_impl.cc @@ -123,7 +123,7 @@ RTCDesktopCapturerImpl::~RTCDesktopCapturerImpl() { capturer_.reset(); } -RTCDesktopCapturerImpl::CaptureState RTCDesktopCapturerImpl::Start( +RTCCaptureState RTCDesktopCapturerImpl::Start( uint32_t fps, uint32_t x, uint32_t y, uint32_t w, uint32_t h) { x_ = x; y_ = y; @@ -136,14 +136,14 @@ RTCDesktopCapturerImpl::CaptureState RTCDesktopCapturerImpl::Start( return Start(fps); } -RTCDesktopCapturerImpl::CaptureState RTCDesktopCapturerImpl::Start( +RTCCaptureState RTCDesktopCapturerImpl::Start( uint32_t fps) { - if (capture_state_ == CS_RUNNING) { + if (capture_state_ == RTCCaptureState::CS_RUNNING) { return capture_state_; } if (fps == 0) { - capture_state_ = CS_FAILED; + capture_state_ = RTCCaptureState::CS_FAILED; return capture_state_; } @@ -155,19 +155,19 @@ RTCDesktopCapturerImpl::CaptureState RTCDesktopCapturerImpl::Start( if (source_id_ != -1) { if (!capturer_->SelectSource(source_id_)) { - capture_state_ = CS_FAILED; + capture_state_ = RTCCaptureState::CS_FAILED; return capture_state_; } if (type_ == kWindow) { if (!capturer_->FocusOnSelectedSource()) { - capture_state_ = CS_FAILED; + capture_state_ = RTCCaptureState::CS_FAILED; return capture_state_; } } } thread_->BlockingCall([this] { capturer_->Start(this); }); - capture_state_ = CS_RUNNING; + capture_state_ = RTCCaptureState::CS_RUNNING; thread_->PostTask([this] { CaptureFrame(); }); if (observer_) { signaling_thread_->BlockingCall([&, this]() { @@ -187,11 +187,11 @@ void RTCDesktopCapturerImpl::Stop() { observer_->OnStop(this); } } - capture_state_ = CS_STOPPED; + capture_state_ = RTCCaptureState::CS_STOPPED; } bool RTCDesktopCapturerImpl::IsRunning() { - return capture_state_ == CS_RUNNING; + return capture_state_ == RTCCaptureState::CS_RUNNING; } #ifdef WEBRTC_WIN @@ -210,7 +210,7 @@ void RTCDesktopCapturerImpl::OnCaptureResult( if (observer_) { observer_->OnError(this); } }); } - capture_state_ = CS_FAILED; + capture_state_ = RTCCaptureState::CS_FAILED; return; } @@ -279,7 +279,7 @@ void RTCDesktopCapturerImpl::OnCaptureResult( void RTCDesktopCapturerImpl::CaptureFrame() { RTC_DCHECK_RUN_ON(thread_.get()); - if (capture_state_ == CS_RUNNING) { + if (capture_state_ == RTCCaptureState::CS_RUNNING) { capturer_->CaptureFrame(); thread_->PostDelayedHighPrecisionTask( [this]() { CaptureFrame(); }, diff --git a/src/rtc_desktop_capturer_impl.h b/src/rtc_desktop_capturer_impl.h index f29fb0970c..c14912057a 100644 --- a/src/rtc_desktop_capturer_impl.h +++ b/src/rtc_desktop_capturer_impl.h @@ -65,9 +65,9 @@ class RTCDesktopCapturerImpl : public RTCDesktopCapturer, } void DeRegisterDesktopCapturerObserver() override { observer_ = nullptr; } - CaptureState Start(uint32_t fps) override; + RTCCaptureState Start(uint32_t fps) override; - CaptureState Start(uint32_t fps, uint32_t x, uint32_t y, uint32_t w, + RTCCaptureState Start(uint32_t fps, uint32_t x, uint32_t y, uint32_t w, uint32_t h) override; void Stop() override; @@ -89,7 +89,7 @@ class RTCDesktopCapturerImpl : public RTCDesktopCapturer, std::unique_ptr capturer_; std::unique_ptr thread_; rtc::scoped_refptr i420_buffer_; - CaptureState capture_state_ = CS_STOPPED; + RTCCaptureState capture_state_ = RTCCaptureState::CS_STOPPED; DesktopType type_; webrtc::DesktopCapturer::SourceId source_id_; DesktopCapturerObserver* observer_ = nullptr; diff --git a/src/rtc_dummy_video_capturer_impl.cc b/src/rtc_dummy_video_capturer_impl.cc new file mode 100644 index 0000000000..753723b173 --- /dev/null +++ b/src/rtc_dummy_video_capturer_impl.cc @@ -0,0 +1,203 @@ +#include "src/rtc_dummy_video_capturer_impl.h" +#include "rtc_video_frame.h" +#include "third_party/libyuv/include/libyuv.h" + +#include "interop_api.h" + +namespace libwebrtc { + +/** + * DummyVideoCapturerObserverImpl + */ + +DummyVideoCapturerObserverImpl::DummyVideoCapturerObserverImpl( + void* callbacks /* rtcDummyVideoCapturerObserverCallbacks* */) + : callbacks_(nullptr) { + if (callbacks) { + size_t nSize = sizeof(rtcDummyVideoCapturerObserverCallbacks); + callbacks_ = malloc(nSize); + memcpy(callbacks_, (const void*)callbacks, nSize); + } +} + +DummyVideoCapturerObserverImpl::~DummyVideoCapturerObserverImpl() { + if (callbacks_) { + free(callbacks_); + } + callbacks_ = nullptr; +} + +void DummyVideoCapturerObserverImpl::OnStart() { + if (callbacks_) { + rtcDummyVideoCapturerObserverCallbacks* pCallbacks = + reinterpret_cast(callbacks_); + pCallbacks->Started(pCallbacks->UserData); + } +} + +void DummyVideoCapturerObserverImpl::OnPaused() { + if (callbacks_) { + rtcDummyVideoCapturerObserverCallbacks* pCallbacks = + reinterpret_cast(callbacks_); + pCallbacks->Paused(pCallbacks->UserData); + } +} + +void DummyVideoCapturerObserverImpl::OnStop() { + if (callbacks_) { + rtcDummyVideoCapturerObserverCallbacks* pCallbacks = + reinterpret_cast(callbacks_); + pCallbacks->Stopped(pCallbacks->UserData); + } +} + +void DummyVideoCapturerObserverImpl::OnError() { + if (callbacks_) { + rtcDummyVideoCapturerObserverCallbacks* pCallbacks = + reinterpret_cast(callbacks_); + pCallbacks->Failed(pCallbacks->UserData); + } +} + +void DummyVideoCapturerObserverImpl::OnFillBuffer( + scoped_refptr frame) { + if (callbacks_) { + rtcDummyVideoCapturerObserverCallbacks* pCallbacks = + reinterpret_cast(callbacks_); + rtcVideoFrameHandle hFrame = + static_cast(frame.release()); + pCallbacks->FillBuffer(pCallbacks->UserData, hFrame); + } +} + +/** + * class RTCDummyVideoCapturerImpl + */ + +RTCDummyVideoCapturerImpl::RTCDummyVideoCapturerImpl( + rtc::Thread* signaling_thread, uint32_t fps, uint32_t width, + uint32_t height) + : thread_(rtc::Thread::Create()), + signaling_thread_(signaling_thread), + fps_(fps), + width_(width), + height_(height) { + thread_->Start(); +} + +RTCDummyVideoCapturerImpl::~RTCDummyVideoCapturerImpl() { + observer_ = nullptr; + thread_->Stop(); +} + +RTCCaptureState RTCDummyVideoCapturerImpl::Start() { + return Start(fps_, width_, height_); +} + +RTCCaptureState RTCDummyVideoCapturerImpl::Start(uint32_t fps) { + return Start(fps, width_, height_); +} + +RTCCaptureState RTCDummyVideoCapturerImpl::Start(uint32_t fps, uint32_t width, + uint32_t height) { + if (capture_state_ == RTCCaptureState::CS_RUNNING) { + return capture_state_; + } + + if (fps == 0 || width == 0 || height == 0) { + capture_state_ = RTCCaptureState::CS_FAILED; + } + + if (fps >= 60) { + capture_delay_ = uint32_t(1000.0 / 60.0); + } + else { + capture_delay_ = uint32_t(1000.0 / fps); + } + + capture_state_ = RTCCaptureState::CS_RUNNING; + fps_ = fps; + width_ = width; + height_ = height; + thread_->PostTask([this] { CaptureFrame(); }); + if (observer_) { + if (!signaling_thread_->IsCurrent()) { + signaling_thread_->BlockingCall([&, this]() { + if (observer_) { observer_->OnStart(); } + }); + } + else { + observer_->OnStart(); + } + } + return capture_state_; +} + +void RTCDummyVideoCapturerImpl::Stop() { + if (observer_) { + if (!signaling_thread_->IsCurrent()) { + signaling_thread_->BlockingCall([&, this]() { + if (observer_) { observer_->OnStop(); } + }); + } else { + observer_->OnStop(); + } + } + capture_state_ = RTCCaptureState::CS_STOPPED; +} + +bool RTCDummyVideoCapturerImpl::IsRunning() const { + return capture_state_ == RTCCaptureState::CS_RUNNING; +} + +void RTCDummyVideoCapturerImpl::OnFrameReady(const scoped_refptr& frame) { + int width = frame->width(); + int height = frame->height(); + + width = width_ > 0 ? width_ : width; + height = height_ > 0 ? height_ : height; + if (!i420_buffer_ || !i420_buffer_.get() || + i420_buffer_->width() * i420_buffer_->height() != width * height) { + i420_buffer_ = webrtc::I420Buffer::Create(width, height); + } + + libyuv::I420Copy( + frame->DataY(), + frame->StrideY(), + frame->DataU(), + frame->StrideU(), + frame->DataV(), + frame->StrideV(), + i420_buffer_->MutableDataY(), + i420_buffer_->StrideY(), + i420_buffer_->MutableDataU(), + i420_buffer_->StrideU(), + i420_buffer_->MutableDataV(), + i420_buffer_->StrideV(), + width, + height + ); + + webrtc::VideoRotation rotation = static_cast(frame->rotation()); + OnFrame(webrtc::VideoFrame(i420_buffer_, 0, rtc::TimeMillis(), rotation)); +} + +void RTCDummyVideoCapturerImpl::FillBuffer() { + scoped_refptr frame = RTCVideoFrame::Create(width_, height_); + if (observer_ != nullptr) { + observer_->OnFillBuffer(frame); + } + OnFrameReady(frame); +} + +void RTCDummyVideoCapturerImpl::CaptureFrame() { + RTC_DCHECK_RUN_ON(thread_.get()); + if (capture_state_ == RTCCaptureState::CS_RUNNING) { + FillBuffer(); + thread_->PostDelayedHighPrecisionTask( + [this]() { CaptureFrame(); }, + webrtc::TimeDelta::Millis(capture_delay_)); + } +} + +} // namespace libwebrtc diff --git a/src/rtc_dummy_video_capturer_impl.h b/src/rtc_dummy_video_capturer_impl.h new file mode 100644 index 0000000000..b3dbbf86dc --- /dev/null +++ b/src/rtc_dummy_video_capturer_impl.h @@ -0,0 +1,87 @@ +#ifndef LIB_WEBRTC_RTC_DUMMY_VIDEO_CAPTURER_IMPL_HXX +#define LIB_WEBRTC_RTC_DUMMY_VIDEO_CAPTURER_IMPL_HXX + +#include "rtc_types.h" +#include "rtc_video_frame.h" +#include "rtc_dummy_video_capturer.h" +#include "rtc_base/thread.h" +#include "api/video/i420_buffer.h" +#include "src/internal/video_capturer.h" + +namespace libwebrtc { + +/** + * class DummyVideoCapturerObserverImpl + */ +class DummyVideoCapturerObserverImpl : public DummyVideoCapturerObserver +{ + public: + DummyVideoCapturerObserverImpl(void* callbacks /* rtcDesktopCapturerObserverCallbacks* */); + ~DummyVideoCapturerObserverImpl(); + + void OnStart() override; + void OnPaused() override; + void OnStop() override; + void OnError() override; + void OnFillBuffer(scoped_refptr frame) override; + + private: + void* callbacks_ /* rtcDesktopCapturerObserverCallbacks* */; +}; // end class DummyVideoCapturerObserverImpl + +/** + * class RTCDummyVideoCapturerImpl + */ +class RTCDummyVideoCapturerImpl : public RTCDummyVideoCapturer, + public webrtc::internal::VideoCapturer { +public: + RTCDummyVideoCapturerImpl(rtc::Thread* signaling_thread, + uint32_t fps, + uint32_t width, + uint32_t height); + ~RTCDummyVideoCapturerImpl(); + + void RegisterObserver( + DummyVideoCapturerObserver* observer) override { + observer_ = observer; + } + + void DeRegisterObserver() override { + observer_ = nullptr; + } + + DummyVideoCapturerObserver* GetObserver() override { return observer_; } + + RTCCaptureState Start() override; + + RTCCaptureState Start(uint32_t fps) override; + + RTCCaptureState Start(uint32_t fps, + uint32_t width, + uint32_t height) override; + void Stop() override; + + bool IsRunning() const override; + + RTCCaptureState state() const override { return capture_state_; } + +private: + void OnFrameReady(const scoped_refptr& frame); + void FillBuffer(); + void CaptureFrame(); + +private: + DummyVideoCapturerObserver* observer_ = nullptr; + std::unique_ptr thread_; + rtc::Thread* signaling_thread_ = nullptr; + rtc::scoped_refptr i420_buffer_; + RTCCaptureState capture_state_ = RTCCaptureState::CS_STOPPED; + uint32_t capture_delay_ = 1000; // 1s + uint32_t fps_ = 25; + uint32_t width_ = 960; + uint32_t height_ = 540; +}; // end class RTCDummyVideoCapturerImpl + +} // namespace libwebrtc + +#endif // LIB_WEBRTC_RTC_DUMMY_VIDEO_CAPTURER_IMPL_HXX diff --git a/src/rtc_peerconnection_factory_impl.cc b/src/rtc_peerconnection_factory_impl.cc index 7c7fe2d452..75e4d43645 100644 --- a/src/rtc_peerconnection_factory_impl.cc +++ b/src/rtc_peerconnection_factory_impl.cc @@ -14,6 +14,7 @@ #include "rtc_rtp_capabilities_impl.h" #include "rtc_video_device_impl.h" #include "rtc_video_source_impl.h" +#include "rtc_dummy_video_capturer_impl.h" #if defined(USE_INTEL_MEDIA_SDK) #include "src/win/mediacapabilities.h" #include "src/win/msdkvideodecoderfactory.h" @@ -205,6 +206,19 @@ scoped_refptr RTCPeerConnectionFactoryImpl::CreateVideoSource_s( return source; } +scoped_refptr RTCPeerConnectionFactoryImpl::CreateDummyVideoSource_s( + scoped_refptr capturer, const char* video_source_label) +{ + rtc::scoped_refptr rtc_source_track = + rtc::scoped_refptr( + new rtc::RefCountedObject(capturer)); + + scoped_refptr source = scoped_refptr( + new RefCountedObject(rtc_source_track)); + + return source; +} + #ifdef RTC_DESKTOP_DEVICE scoped_refptr RTCPeerConnectionFactoryImpl::CreateDesktopSource( scoped_refptr capturer, const string video_source_label, @@ -272,6 +286,35 @@ scoped_refptr RTCPeerConnectionFactoryImpl::CreateVideoTrack( return video_track; } +scoped_refptr RTCPeerConnectionFactoryImpl::CreateDummyVideoCapturer( + uint32_t fps, uint32_t width, uint32_t height) +{ + return scoped_refptr( + new RefCountedObject( + signaling_thread_.get(), + fps, + width, + height + ) + ); +} + +scoped_refptr RTCPeerConnectionFactoryImpl::CreateDummyVideoSource( + scoped_refptr capturer, const string video_source_label) +{ + if (rtc::Thread::Current() != signaling_thread_.get()) { + scoped_refptr source = signaling_thread_->BlockingCall( + [this, capturer, video_source_label] { + return CreateDummyVideoSource_s( + capturer, to_std_string(video_source_label).c_str()); + }); + return source; + } + + return CreateDummyVideoSource_s( + capturer, to_std_string(video_source_label).c_str()); +} + scoped_refptr RTCPeerConnectionFactoryImpl::CreateAudioTrack( scoped_refptr source, const string track_id) { RTCAudioSourceImpl* source_impl = diff --git a/src/rtc_peerconnection_factory_impl.h b/src/rtc_peerconnection_factory_impl.h index f87bba67ff..1eb3210f95 100644 --- a/src/rtc_peerconnection_factory_impl.h +++ b/src/rtc_peerconnection_factory_impl.h @@ -11,6 +11,7 @@ #include "rtc_peerconnection.h" #include "rtc_peerconnection_factory.h" #include "rtc_video_device_impl.h" +#include "src/internal/dummy_capturer.h" #ifdef RTC_DESKTOP_DEVICE #include "rtc_desktop_capturer_impl.h" @@ -53,6 +54,11 @@ class RTCPeerConnectionFactoryImpl : public RTCPeerConnectionFactory { const string video_source_label, scoped_refptr constraints) override; #endif + virtual scoped_refptr CreateDummyVideoCapturer( + uint32_t fps, uint32_t width, uint32_t height) override; + virtual scoped_refptr CreateDummyVideoSource( + scoped_refptr capturer, const string video_source_label) override; + virtual scoped_refptr CreateAudioTrack( scoped_refptr source, const string track_id) override; @@ -83,6 +89,10 @@ class RTCPeerConnectionFactoryImpl : public RTCPeerConnectionFactory { scoped_refptr CreateVideoSource_s( scoped_refptr capturer, const char* video_source_label, scoped_refptr constraints); + + scoped_refptr CreateDummyVideoSource_s( + scoped_refptr capturer, const char* video_source_label); + #ifdef RTC_DESKTOP_DEVICE scoped_refptr CreateDesktopSource_d( scoped_refptr capturer, diff --git a/src/rtc_video_renderer_impl.cc b/src/rtc_video_renderer_impl.cc index 0ad2af413e..9206dff58e 100644 --- a/src/rtc_video_renderer_impl.cc +++ b/src/rtc_video_renderer_impl.cc @@ -8,6 +8,7 @@ namespace libwebrtc { RTCVideoRendererImpl::RTCVideoRendererImpl() : user_data_(nullptr) , callback_(nullptr) + , callback_safe_(nullptr) { RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor " << (void*)this; } @@ -16,6 +17,7 @@ RTCVideoRendererImpl::~RTCVideoRendererImpl() { user_data_ = nullptr; callback_ = nullptr; + callback_safe_ = nullptr; RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; } @@ -25,6 +27,9 @@ void RTCVideoRendererImpl::OnFrame(scoped_refptr frame) void* pFrame = static_cast(frame.release()); callback_(user_data_, pFrame); } + else if (callback_safe_) { + callback_safe_(frame); + } } void RTCVideoRendererImpl::RegisterFrameCallback(void* user_data /* rtcObjectHandle */, void* callback /* rtcVideoRendererFrameDelegate */) @@ -32,6 +37,15 @@ void RTCVideoRendererImpl::RegisterFrameCallback(void* user_data /* rtcObjectHan RTC_LOG(LS_INFO) << __FUNCTION__ << ": RegisterFrameCallback " << callback; user_data_ = user_data; callback_ = reinterpret_cast(callback); + callback_safe_ = nullptr; +} + +void RTCVideoRendererImpl::RegisterFrameCallback(OnFrameCallbackSafe callback) +{ + RTC_LOG(LS_INFO) << __FUNCTION__ << ": RegisterFrameCallback (Safe)"; + user_data_ = nullptr; + callback_ = nullptr; + callback_safe_ = callback; } void RTCVideoRendererImpl::UnRegisterFrameCallback() @@ -39,6 +53,7 @@ void RTCVideoRendererImpl::UnRegisterFrameCallback() RTC_LOG(LS_INFO) << __FUNCTION__; user_data_ = nullptr; callback_ = nullptr; + callback_safe_ = nullptr; } template <> diff --git a/src/rtc_video_renderer_impl.h b/src/rtc_video_renderer_impl.h index 516f25d5ed..ab252c3ce1 100644 --- a/src/rtc_video_renderer_impl.h +++ b/src/rtc_video_renderer_impl.h @@ -17,11 +17,13 @@ class RTCVideoRendererImpl : public RTCVideoRenderer frame) override; void RegisterFrameCallback(void* user_data /* rtcObjectHandle */, void* callback /* rtcVideoRendererFrameDelegate */) override; + void RegisterFrameCallback(OnFrameCallbackSafe callback) override; void UnRegisterFrameCallback() override; private: void* user_data_ = nullptr; OnFrameCallback callback_ = nullptr; + OnFrameCallbackSafe callback_safe_ = nullptr; }; // end class RTCVideoRendererImpl } // end namespace libwebrtc From 2840c802628e588fc20d82aeff08685830d224ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Mon, 13 Jan 2025 20:33:57 +0300 Subject: [PATCH 58/69] Added ScaleFrom method for RTCVideoFrame. --- include/interop_api.h | 14 ++++++++++++++ include/rtc_video_frame.h | 2 ++ src/interop/rtc_video_frame_interop.cc | 15 +++++++++++++++ src/rtc_video_frame_impl.cc | 23 +++++++++++++++++++++++ src/rtc_video_frame_impl.h | 2 ++ 5 files changed, 56 insertions(+) diff --git a/include/interop_api.h b/include/interop_api.h index d735bcef0f..b7da5b4442 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -1395,6 +1395,20 @@ LIB_WEBRTC_API int LIB_WEBRTC_CALL RTCVideoFrame_ConvertToARGB( unsigned char* dst_argb, int dst_stride_argb, int dest_width, int dest_height) noexcept; +/** + * Copies the source frame and scales it to the dimensions + * of the destination frame. + * + * @param handle - Destination video frame handle + * @param source - Source video frame handle + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_ScaleFrom( + rtcVideoFrameHandle dest, + rtcVideoFrameHandle source +) noexcept; + /* * ---------------------------------------------------------------------- * RTCVideoRenderer interop methods diff --git a/include/rtc_video_frame.h b/include/rtc_video_frame.h index 3be8013deb..2d7f00c315 100644 --- a/include/rtc_video_frame.h +++ b/include/rtc_video_frame.h @@ -54,6 +54,8 @@ class RTCVideoFrame : public RefCountInterface { virtual int ConvertToARGB(Type type, uint8_t* dst_argb, int dst_stride_argb, int dest_width, int dest_height) = 0; + virtual void ScaleFrom(scoped_refptr source) = 0; + protected: virtual ~RTCVideoFrame() {} }; diff --git a/src/interop/rtc_video_frame_interop.cc b/src/interop/rtc_video_frame_interop.cc index ea78f430c2..cb21e71863 100644 --- a/src/interop/rtc_video_frame_interop.cc +++ b/src/interop/rtc_video_frame_interop.cc @@ -192,3 +192,18 @@ RTCVideoFrame_ConvertToARGB( dest_height ); } + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_ScaleFrom( + rtcVideoFrameHandle dest, + rtcVideoFrameHandle source +) noexcept +{ + CHECK_NATIVE_HANDLE(dest); + CHECK_NATIVE_HANDLE(source); + + scoped_refptr pDst = static_cast(dest); + scoped_refptr pSrc = static_cast(source); + pDst->ScaleFrom(pSrc); + return rtcResultU4::kSuccess; +} diff --git a/src/rtc_video_frame_impl.cc b/src/rtc_video_frame_impl.cc index ca26c290c1..68ab15800e 100644 --- a/src/rtc_video_frame_impl.cc +++ b/src/rtc_video_frame_impl.cc @@ -95,6 +95,29 @@ int VideoFrameBufferImpl::ConvertToARGB(Type type, uint8_t* dst_buffer, return buf_size; } +void VideoFrameBufferImpl::ScaleFrom(scoped_refptr source) +{ + if (nullptr == source || this == source.get()) { + return; + } + scoped_refptr source_impl = + scoped_refptr( + static_cast(source.get()) + ); + if (nullptr == source_impl->buffer_) { + return; + } + rtc::scoped_refptr i420 = + webrtc::I420Buffer::Rotate(*buffer_.get(), rotation_); + rtc::scoped_refptr i420_source = + webrtc::I420Buffer::Rotate( + *source_impl->buffer_.get(), + static_cast(source_impl->rotation()) + ); + i420->ScaleFrom(*i420_source.get()); + buffer_ = i420; +} + libwebrtc::RTCVideoFrame::VideoRotation VideoFrameBufferImpl::rotation() { switch (rotation_) { case webrtc::kVideoRotation_0: diff --git a/src/rtc_video_frame_impl.h b/src/rtc_video_frame_impl.h index 9b341f667b..c9580a96fa 100644 --- a/src/rtc_video_frame_impl.h +++ b/src/rtc_video_frame_impl.h @@ -39,6 +39,8 @@ class VideoFrameBufferImpl : public RTCVideoFrame { int ConvertToARGB(Type type, uint8_t* dst_argb, int dst_stride_argb, int dest_width, int dest_height) override; + void ScaleFrom(scoped_refptr source) override; + rtc::scoped_refptr buffer() { return buffer_; } // System monotonic clock, same timebase as rtc::TimeMicros(). From 20051cf3d1279747577aa97874f4aa848b8d6342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Thu, 16 Jan 2025 21:02:19 +0300 Subject: [PATCH 59/69] Added ScaleFrom(ARGB) to RTCVideoFrame. --- include/interop_api.h | 26 ++++++++++- include/rtc_video_frame.h | 10 +++- src/interop/rtc_video_frame_interop.cc | 62 ++++++++++++++++++++++++- src/rtc_video_frame_impl.cc | 64 ++++++++++++++++++++++++-- src/rtc_video_frame_impl.h | 10 +++- 5 files changed, 164 insertions(+), 8 deletions(-) diff --git a/include/interop_api.h b/include/interop_api.h index b7da5b4442..8efbf31c0e 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -1406,7 +1406,31 @@ LIB_WEBRTC_API int LIB_WEBRTC_CALL RTCVideoFrame_ConvertToARGB( LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCVideoFrame_ScaleFrom( rtcVideoFrameHandle dest, - rtcVideoFrameHandle source + rtcVideoFrameHandle source, + int* pOutRetVal +) noexcept; + +/** + * Copies the source frame and scales it to the dimensions + * of the destination frame. + * + * @param handle - Destination video frame handle + * @param frameType - RGBA frame type + * @param src_argb - Source frame buffer address + * @param src_stride_argb - Source stride + * @param src_width - Source frame width + * @param src_height - Source frame height + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_ScaleFrom2( + rtcVideoFrameHandle dest, + rtcVideoFrameType frameType, + const unsigned char* src_argb, + int src_stride_argb, + int src_width, + int src_height, + int* pOutRetVal ) noexcept; /* diff --git a/include/rtc_video_frame.h b/include/rtc_video_frame.h index 2d7f00c315..217ccc563b 100644 --- a/include/rtc_video_frame.h +++ b/include/rtc_video_frame.h @@ -54,7 +54,15 @@ class RTCVideoFrame : public RefCountInterface { virtual int ConvertToARGB(Type type, uint8_t* dst_argb, int dst_stride_argb, int dest_width, int dest_height) = 0; - virtual void ScaleFrom(scoped_refptr source) = 0; + virtual int ScaleFrom(scoped_refptr source) = 0; + + virtual int ScaleFrom( + Type type, + const uint8_t* src_argb, + int src_stride_argb, + int src_width, + int src_height + ) = 0; protected: virtual ~RTCVideoFrame() {} diff --git a/src/interop/rtc_video_frame_interop.cc b/src/interop/rtc_video_frame_interop.cc index cb21e71863..ecd45a75bd 100644 --- a/src/interop/rtc_video_frame_interop.cc +++ b/src/interop/rtc_video_frame_interop.cc @@ -196,7 +196,8 @@ RTCVideoFrame_ConvertToARGB( rtcResultU4 LIB_WEBRTC_CALL RTCVideoFrame_ScaleFrom( rtcVideoFrameHandle dest, - rtcVideoFrameHandle source + rtcVideoFrameHandle source, + int* pOutRetVal ) noexcept { CHECK_NATIVE_HANDLE(dest); @@ -204,6 +205,63 @@ RTCVideoFrame_ScaleFrom( scoped_refptr pDst = static_cast(dest); scoped_refptr pSrc = static_cast(source); - pDst->ScaleFrom(pSrc); + int buffer_size = pDst->ScaleFrom(pSrc); + if (pOutRetVal) { + *pOutRetVal = buffer_size; + } + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_ScaleFrom2( + rtcVideoFrameHandle dest, + rtcVideoFrameType frameType, + const unsigned char* src_argb, + int src_stride_argb, + int src_width, + int src_height, + int* pOutRetVal +) noexcept +{ + CHECK_NATIVE_HANDLE(dest); + CHECK_POINTER_EX(src_argb, rtcResultU4::kInvalidParameter); + if (src_width < 16 || + src_height < 16 || + src_stride_argb < 64 || + (src_width * 4) > src_stride_argb) + { + return rtcResultU4::kInvalidParameter; + } + + RTCVideoFrame::Type type; + switch (frameType) + { + case rtcVideoFrameType::kARGB: + type = RTCVideoFrame::Type::kARGB; + break; + case rtcVideoFrameType::kBGRA: + type = RTCVideoFrame::Type::kBGRA; + break; + case rtcVideoFrameType::kABGR: + type = RTCVideoFrame::Type::kABGR; + break; + case rtcVideoFrameType::kRGBA: + type = RTCVideoFrame::Type::kRGBA; + break; + default: + return rtcResultU4::kInvalidParameter; + } + + scoped_refptr pDst = static_cast(dest); + int buffer_size = pDst->ScaleFrom( + type, + static_cast(src_argb), + src_stride_argb, + src_width, + src_height + ); + if (pOutRetVal) { + *pOutRetVal = buffer_size; + } return rtcResultU4::kSuccess; } diff --git a/src/rtc_video_frame_impl.cc b/src/rtc_video_frame_impl.cc index 68ab15800e..79a7aee806 100644 --- a/src/rtc_video_frame_impl.cc +++ b/src/rtc_video_frame_impl.cc @@ -1,8 +1,10 @@ #include "rtc_video_frame_impl.h" #include "api/video/i420_buffer.h" +#include "libyuv/convert.h" #include "libyuv/convert_argb.h" #include "libyuv/convert_from.h" +#include "libyuv/convert_from_argb.h" #include "rtc_base/checks.h" #include "rtc_base/logging.h" @@ -95,17 +97,17 @@ int VideoFrameBufferImpl::ConvertToARGB(Type type, uint8_t* dst_buffer, return buf_size; } -void VideoFrameBufferImpl::ScaleFrom(scoped_refptr source) +int VideoFrameBufferImpl::ScaleFrom(scoped_refptr source) { if (nullptr == source || this == source.get()) { - return; + return 0; } scoped_refptr source_impl = scoped_refptr( static_cast(source.get()) ); if (nullptr == source_impl->buffer_) { - return; + return 0; } rtc::scoped_refptr i420 = webrtc::I420Buffer::Rotate(*buffer_.get(), rotation_); @@ -116,6 +118,62 @@ void VideoFrameBufferImpl::ScaleFrom(scoped_refptr source) ); i420->ScaleFrom(*i420_source.get()); buffer_ = i420; + + int buffer_size = (StrideY() * height()) + (StrideU() * (height() / 2)) + (StrideV() * (height() / 2)); + return buffer_size; +} + +int VideoFrameBufferImpl::ScaleFrom( + Type type, + const uint8_t* src_argb, + int src_stride_argb, + int src_width, + int src_height + ) +{ + rtc::scoped_refptr i420_src = + webrtc::I420Buffer::Create(src_width, src_height); + rtc::scoped_refptr i420_dst = + webrtc::I420Buffer::Create(width(), height()); + + switch (type) { + case libwebrtc::RTCVideoFrame::Type::kARGB: + libyuv::ARGBToI420(src_argb, src_stride_argb, + i420_src->MutableDataY(), i420_src->StrideY(), + i420_src->MutableDataU(), i420_src->StrideU(), + i420_src->MutableDataV(), i420_src->StrideV(), + src_width, src_height); + break; + case libwebrtc::RTCVideoFrame::Type::kBGRA: + libyuv::BGRAToI420(src_argb, src_stride_argb, + i420_src->MutableDataY(), i420_src->StrideY(), + i420_src->MutableDataU(), i420_src->StrideU(), + i420_src->MutableDataV(), i420_src->StrideV(), + src_width, src_height); + break; + case libwebrtc::RTCVideoFrame::Type::kABGR: + libyuv::ABGRToI420(src_argb, src_stride_argb, + i420_src->MutableDataY(), i420_src->StrideY(), + i420_src->MutableDataU(), i420_src->StrideU(), + i420_src->MutableDataV(), i420_src->StrideV(), + src_width, src_height); + break; + case libwebrtc::RTCVideoFrame::Type::kRGBA: + libyuv::RGBAToI420(src_argb, src_stride_argb, + i420_src->MutableDataY(), i420_src->StrideY(), + i420_src->MutableDataU(), i420_src->StrideU(), + i420_src->MutableDataV(), i420_src->StrideV(), + src_width, src_height); + break; + default: + break; + } + + i420_dst->ScaleFrom(*i420_src.get()); + buffer_ = i420_dst; + + int buffer_size = (StrideY() * height()) + (StrideU() * (height() / 2)) + (StrideV() * (height() / 2)); + return buffer_size; } libwebrtc::RTCVideoFrame::VideoRotation VideoFrameBufferImpl::rotation() { diff --git a/src/rtc_video_frame_impl.h b/src/rtc_video_frame_impl.h index c9580a96fa..2b19fd2557 100644 --- a/src/rtc_video_frame_impl.h +++ b/src/rtc_video_frame_impl.h @@ -39,7 +39,15 @@ class VideoFrameBufferImpl : public RTCVideoFrame { int ConvertToARGB(Type type, uint8_t* dst_argb, int dst_stride_argb, int dest_width, int dest_height) override; - void ScaleFrom(scoped_refptr source) override; + int ScaleFrom(scoped_refptr source) override; + + int ScaleFrom( + Type type, + const uint8_t* src_argb, + int src_stride_argb, + int src_width, + int src_height + ) override; rtc::scoped_refptr buffer() { return buffer_; } From 84f2e4480665f871ee30eaba3830cea1eb02a610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Thu, 16 Jan 2025 22:42:43 +0300 Subject: [PATCH 60/69] Updated rtc_video_frame_interop.cc --- include/interop_api.h | 84 +++++++++++----- src/interop/rtc_video_frame_interop.cc | 132 +++++++++++++++++++------ 2 files changed, 159 insertions(+), 57 deletions(-) diff --git a/include/interop_api.h b/include/interop_api.h index 8efbf31c0e..856015496d 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -313,21 +313,6 @@ struct rtcPeerConnectionConfiguration { uint32_t local_video_bandwidth = 512; }; // end struct rtcPeerConnectionConfiguration -struct rtcVideoFrameDatas { - // frame width in pixel - int width = 0; - // frame height in pixel - int height = 0; - // The YUV starting address of the frame buffer. - const unsigned char* data_y = nullptr; - const unsigned char* data_u = nullptr; - const unsigned char* data_v = nullptr; - // The stride of the YUV - int stride_y = 0; - int stride_u = 0; - int stride_v = 0; -}; // end struct rtcVideoFrameDatas - struct rtcDataChannelInit { rtcBool32 ordered = rtcBool32::kTrue; rtcBool32 reliable = rtcBool32::kTrue; @@ -1324,8 +1309,17 @@ RTCVideoFrame_Create1(int width, int height, const unsigned char* buffer, * @return rtcResultU4 - 0 if successful, otherwise an error code. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCVideoFrame_Create2(const rtcVideoFrameDatas* frameDatas, - rtcVideoFrameHandle* pOutRetVal) noexcept; +RTCVideoFrame_Create2( + int width, + int height, + const unsigned char* data_y, + const unsigned char* data_u, + const unsigned char* data_v, + int stride_y, + int stride_u, + int stride_v, + rtcVideoFrameHandle* pOutRetVal +) noexcept; /** * Creates a copy of the video frame. @@ -1337,15 +1331,53 @@ RTCVideoFrame_Create2(const rtcVideoFrameDatas* frameDatas, LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCVideoFrame_Copy( rtcVideoFrameHandle videoFrame, rtcVideoFrameHandle* pOutRetVal) noexcept; -/** - * Returns the datas of the video frame. - * - * @param videoFrame - Source video frame handle - * @param refFrameDatas - The frame datas. - * @return rtcResultU4 - 0 if successful, otherwise an error code. - */ -LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCVideoFrame_GetFrameDatas( - rtcVideoFrameHandle videoFrame, rtcVideoFrameDatas* refFrameDatas) noexcept; +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_GetWidth( + rtcVideoFrameHandle handle, + int* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_GetHeight( + rtcVideoFrameHandle handle, + int* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_GetDataY( + rtcVideoFrameHandle handle, + const unsigned char** pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_GetDataU( + rtcVideoFrameHandle handle, + const unsigned char** pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_GetDataV( + rtcVideoFrameHandle handle, + const unsigned char** pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_GetStrideY( + rtcVideoFrameHandle handle, + int* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_GetStrideU( + rtcVideoFrameHandle handle, + int* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_GetStrideV( + rtcVideoFrameHandle handle, + int* pOutRetVal +) noexcept; /** * Returns the rotation of the video frame. (See: rtcVideoRotation) diff --git a/src/interop/rtc_video_frame_interop.cc b/src/interop/rtc_video_frame_interop.cc index ecd45a75bd..665987a2d5 100644 --- a/src/interop/rtc_video_frame_interop.cc +++ b/src/interop/rtc_video_frame_interop.cc @@ -66,29 +66,35 @@ RTCVideoFrame_Create1( rtcResultU4 LIB_WEBRTC_CALL RTCVideoFrame_Create2( - const rtcVideoFrameDatas* frameDatas, + int width, + int height, + const unsigned char* data_y, + const unsigned char* data_u, + const unsigned char* data_v, + int stride_y, + int stride_u, + int stride_v, rtcVideoFrameHandle* pOutRetVal ) noexcept { - if (frameDatas == nullptr - || frameDatas->width < 2 - || (frameDatas->width % 4) != 0 - || frameDatas->height < 2 - || frameDatas->data_y == nullptr - || frameDatas->data_u == nullptr - || frameDatas->data_v == nullptr - || frameDatas->stride_y < 1 - || frameDatas->stride_y < 1 - || frameDatas->stride_v < 1) + if (width < 2 + || (width % 4) != 0 + || height < 2 + || data_y == nullptr + || data_u == nullptr + || data_v == nullptr + || stride_y < 1 + || stride_y < 1 + || stride_v < 1) { return rtcResultU4::kInvalidParameter; } scoped_refptr pvf = RTCVideoFrame::Create( - frameDatas->width, frameDatas->height, - frameDatas->data_y, frameDatas->stride_y, - frameDatas->data_u, frameDatas->stride_u, - frameDatas->data_v, frameDatas->stride_v + width, height, + data_y, stride_y, + data_u, stride_u, + data_v, stride_v ); CHECK_POINTER_EX(pvf, rtcResultU4::kUnknownError); *pOutRetVal = static_cast(pvf.release()); @@ -111,29 +117,93 @@ RTCVideoFrame_Copy( return rtcResultU4::kSuccess; } -rtcResultU4 LIB_WEBRTC_CALL -RTCVideoFrame_GetFrameDatas( - rtcVideoFrameHandle videoFrame, - rtcVideoFrameDatas* refFrameDatas +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_GetWidth( + rtcVideoFrameHandle handle, + int* pOutRetVal ) noexcept { - CHECK_POINTER(refFrameDatas); - ZERO_MEMORY(refFrameDatas, sizeof(rtcVideoFrameDatas)); + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCVideoFrame, width); +} - scoped_refptr pvf = static_cast(videoFrame); - - refFrameDatas->width = pvf->width(); - refFrameDatas->height = pvf->height(); - refFrameDatas->data_y = static_cast(pvf->DataY()); - refFrameDatas->data_u = static_cast(pvf->DataU()); - refFrameDatas->data_v = static_cast(pvf->DataV()); - refFrameDatas->stride_y = pvf->StrideY(); - refFrameDatas->stride_u = pvf->StrideU(); - refFrameDatas->stride_v = pvf->StrideV(); +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_GetHeight( + rtcVideoFrameHandle handle, + int* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCVideoFrame, height); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_GetDataY( + rtcVideoFrameHandle handle, + const unsigned char** pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr p = static_cast(handle); + *pOutRetVal = static_cast(p->DataY()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_GetDataU( + rtcVideoFrameHandle handle, + const unsigned char** pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr p = static_cast(handle); + *pOutRetVal = static_cast(p->DataU()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_GetDataV( + rtcVideoFrameHandle handle, + const unsigned char** pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + CHECK_NATIVE_HANDLE(handle); + scoped_refptr p = static_cast(handle); + *pOutRetVal = static_cast(p->DataV()); return rtcResultU4::kSuccess; } +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_GetStrideY( + rtcVideoFrameHandle handle, + int* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCVideoFrame, StrideY); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_GetStrideU( + rtcVideoFrameHandle handle, + int* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCVideoFrame, StrideU); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_GetStrideV( + rtcVideoFrameHandle handle, + int* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCVideoFrame, StrideV); +} + rtcResultU4 LIB_WEBRTC_CALL RTCVideoFrame_GetRotation( rtcVideoFrameHandle videoFrame, From 2046578f3264b6db34812ab10fee62e4bed007fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Mon, 27 Jan 2025 08:06:29 +0300 Subject: [PATCH 61/69] Added Dummy Audio Source --- BUILD.gn | 10 ++ include/interop_api.h | 35 +++- include/libwebrtc.h | 2 +- include/rtc_audio_data.h | 46 +++++ include/rtc_dummy_audio_source.h | 51 ++++++ include/rtc_peerconnection_factory.h | 12 +- src/internal/audio_util.cc | 90 ++++++++++ src/internal/audio_util.h | 23 +++ src/internal/desktop_capturer.cc | 2 +- src/internal/dummy_audio_capturer.cc | 163 +++++++++++++++++ src/internal/dummy_audio_capturer.h | 106 +++++++++++ src/internal/dummy_capturer.cc | 2 +- src/interop/libwebrtc_interop.cc | 7 +- .../rtc_peerconnection_factory_interop.cc | 5 +- src/libwebrtc.cc | 4 +- src/rtc_audio_data_impl.cc | 167 ++++++++++++++++++ src/rtc_audio_data_impl.h | 46 +++++ src/rtc_dummy_audio_source_impl.cc | 132 ++++++++++++++ src/rtc_dummy_audio_source_impl.h | 69 ++++++++ src/rtc_dummy_video_capturer_impl.h | 4 +- src/rtc_peerconnection_factory_impl.cc | 46 ++++- src/rtc_peerconnection_factory_impl.h | 13 +- 22 files changed, 1017 insertions(+), 18 deletions(-) create mode 100644 include/rtc_audio_data.h create mode 100644 include/rtc_dummy_audio_source.h create mode 100644 src/internal/audio_util.cc create mode 100644 src/internal/audio_util.h create mode 100644 src/internal/dummy_audio_capturer.cc create mode 100644 src/internal/dummy_audio_capturer.h create mode 100644 src/rtc_audio_data_impl.cc create mode 100644 src/rtc_audio_data_impl.h create mode 100644 src/rtc_dummy_audio_source_impl.cc create mode 100644 src/rtc_dummy_audio_source_impl.h diff --git a/BUILD.gn b/BUILD.gn index 300fd0d9d0..cf0350ce0b 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -97,15 +97,21 @@ rtc_shared_library("libwebrtc") { "include/rtc_video_source.h", "include/rtc_video_track.h", "include/rtc_dummy_video_capturer.h", + "include/rtc_audio_data.h", + "include/rtc_dummy_audio_source.h", "include/helper.h", "src/helper.cc", "src/base/portable.cc", + "src/internal/audio_util.cc", + "src/internal/audio_util.h", "src/internal/vcm_capturer.cc", "src/internal/vcm_capturer.h", "src/internal/video_capturer.cc", "src/internal/video_capturer.h", "src/internal/dummy_capturer.cc", "src/internal/dummy_capturer.h", + "src/internal/dummy_audio_capturer.cc", + "src/internal/dummy_audio_capturer.h", "src/libwebrtc.cc", "src/rtc_audio_device_impl.cc", "src/rtc_audio_device_impl.h", @@ -159,6 +165,10 @@ rtc_shared_library("libwebrtc") { "src/rtc_video_track_impl.h", "src/rtc_dummy_video_capturer_impl.cc", "src/rtc_dummy_video_capturer_impl.h", + "src/rtc_audio_data_impl.cc", + "src/rtc_audio_data_impl.h", + "src/rtc_dummy_audio_source_impl.cc", + "src/rtc_dummy_audio_source_impl.h", ] # for interop methods diff --git a/include/interop_api.h b/include/interop_api.h index 856015496d..2bdff8b649 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -406,6 +406,9 @@ using rtcVideoTrackHandle = rtcMediaTrackHandle; /// Opaque handle to a native RTCVideoFrame interop object. using rtcVideoFrameHandle = rtcRefCountedObjectHandle; +/// Opaque handle to a native RTCAudioData interop object. +using rtcAudioDataHandle = rtcRefCountedObjectHandle; + /// Opaque handle to a native RTCVideoRenderer interop object. using rtcVideoRendererHandle = rtcRefCountedObjectHandle; // ??? @@ -592,6 +595,30 @@ struct rtcDummyVideoCapturerObserverCallbacks { rtcDummyVideoCapturerFillBufferDelegate FillBuffer{}; }; +/** + * Dummy audio source callback delegate + */ +using rtcDummyAudioSourceCommonDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data); + +/** + * Dummy audio source fill buffer callback delegate + */ +using rtcDummyAudioSourceFillBufferDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, rtcAudioDataHandle frame); + +/** + * Callback delegate structure for DummyAudioSourceObserver. + */ +struct rtcDummyAudioSourceObserverCallbacks { + rtcObjectHandle UserData{}; + rtcDummyAudioSourceCommonDelegate Started{}; + rtcDummyAudioSourceCommonDelegate Paused{}; + rtcDummyAudioSourceCommonDelegate Stopped{}; + rtcDummyAudioSourceCommonDelegate Failed{}; + rtcDummyAudioSourceFillBufferDelegate FillBuffer{}; +}; + /** * Callback OnFrame delegate for RTCVideoRenderer. */ @@ -764,7 +791,9 @@ LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL LibWebRTC_Initialize() noexcept; * RTCPeerConnectionFactory. */ LIB_WEBRTC_API rtcPeerConnectionFactoryHandle LIB_WEBRTC_CALL -LibWebRTC_CreateRTCPeerConnectionFactory() noexcept; +LibWebRTC_CreateRTCPeerConnectionFactory( + rtcBool32 use_dummy_audio = rtcBool32::kFalse +) noexcept; /** * @brief Terminates the WebRTC PeerConnectionFactory and threads. @@ -841,7 +870,9 @@ RTCPeerConnectionFactory_Create() noexcept; * do not use this method. */ LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL RTCPeerConnectionFactory_Initialize( - rtcPeerConnectionFactoryHandle factory) noexcept; + rtcPeerConnectionFactoryHandle factory, + rtcBool32 use_dummy_audio = rtcBool32::kFalse +) noexcept; /** * @brief Terminates the RTCPeerConnectionFactor object. diff --git a/include/libwebrtc.h b/include/libwebrtc.h index f17af394c0..110c756df9 100644 --- a/include/libwebrtc.h +++ b/include/libwebrtc.h @@ -41,7 +41,7 @@ class LibWebRTC { * RTCPeerConnectionFactory. */ LIB_WEBRTC_API static scoped_refptr - CreateRTCPeerConnectionFactory(); + CreateRTCPeerConnectionFactory(bool use_dummy_audio = false); /** * @brief Terminates the WebRTC PeerConnectionFactory and threads. diff --git a/include/rtc_audio_data.h b/include/rtc_audio_data.h new file mode 100644 index 0000000000..96b0525263 --- /dev/null +++ b/include/rtc_audio_data.h @@ -0,0 +1,46 @@ +#ifndef LIB_WEBRTC_RTC_AUDIO_DATA_HXX +#define LIB_WEBRTC_RTC_AUDIO_DATA_HXX + +#include "rtc_types.h" + +namespace libwebrtc { + +class RTCAudioData : public RefCountInterface { +public: + LIB_WEBRTC_API static scoped_refptr Create( + const uint8_t* data, + uint32_t bits_per_sample, + int sample_rate_hz, // the sample rate in Hz. + uint32_t num_channels = 1 + ); + + LIB_WEBRTC_API static scoped_refptr Create(); + +public: + virtual const uint8_t* data() const = 0; + virtual size_t data_size() const = 0; + virtual uint32_t bits_per_sample() const = 0; + virtual uint32_t samples_per_channel() const = 0; + virtual int sample_rate_hz() const = 0; + virtual uint32_t num_channels() const = 0; + + /** + * @brief Scales the contents of another RTCAudioData. + */ + virtual int ScaleFrom(scoped_refptr src) = 0; + + /** + * Empty the buffer space. Or fill it with 1khz tone signal. + */ + virtual int Clear(bool fill_1khz_tone = false) = 0; + +protected: + /** + * The destructor for the RTCAudioData class. + */ + virtual ~RTCAudioData() {} +}; // end class RTCAudioData + +} // namespace libwebrtc + +#endif // LIB_WEBRTC_RTC_AUDIO_DATA_HXX diff --git a/include/rtc_dummy_audio_source.h b/include/rtc_dummy_audio_source.h new file mode 100644 index 0000000000..606dadd6df --- /dev/null +++ b/include/rtc_dummy_audio_source.h @@ -0,0 +1,51 @@ +#ifndef LIB_WEBRTC_RTC_DUMMY_AUDIO_SOURCE_HXX +#define LIB_WEBRTC_RTC_DUMMY_AUDIO_SOURCE_HXX + +#include "rtc_types.h" +#include "rtc_audio_data.h" + +namespace libwebrtc { + +/** + * class DummyAudioSourceObserver + */ +class DummyAudioSourceObserver { + public: + virtual void OnStart() = 0; + + virtual void OnPaused() = 0; + + virtual void OnStop() = 0; + + virtual void OnError() = 0; + + virtual void OnFillBuffer(scoped_refptr data) = 0; + + protected: + virtual ~DummyAudioSourceObserver() {} +}; // class DummyAudioSourceObserver + +class RTCDummyAudioSource : public RefCountInterface { + public: + virtual void RegisterAudioDataObserver(DummyAudioSourceObserver* observer) = 0; + virtual void DeRegisterAudioDataObserver() = 0; + + virtual int bits_per_sample() const = 0; + virtual int sample_rate_hz() const = 0; + virtual size_t number_of_channels() = 0; + virtual size_t number_of_frames() = 0; + + virtual RTCCaptureState Start() = 0; + virtual void Stop() = 0; + virtual RTCCaptureState CaptureState() = 0; + virtual bool IsRunning() const = 0; + + virtual DummyAudioSourceObserver* GetObserver() = 0; + + protected: + virtual ~RTCDummyAudioSource() {} +}; + +} // namespace libwebrtc + +#endif // LIB_WEBRTC_RTC_DUMMY_AUDIO_SOURCE_HXX diff --git a/include/rtc_peerconnection_factory.h b/include/rtc_peerconnection_factory.h index 6dfa70fc5d..eddc41ef12 100644 --- a/include/rtc_peerconnection_factory.h +++ b/include/rtc_peerconnection_factory.h @@ -12,6 +12,7 @@ #include "rtc_video_device.h" #include "rtc_video_source.h" #include "rtc_dummy_video_capturer.h" +#include "rtc_dummy_audio_source.h" namespace libwebrtc { @@ -22,7 +23,7 @@ class RTCRtpCapabilities; class RTCPeerConnectionFactory : public RefCountInterface { public: - virtual bool Initialize() = 0; + virtual bool Initialize(bool use_dummy_audio = false) = 0; virtual bool Terminate() = 0; @@ -41,6 +42,12 @@ class RTCPeerConnectionFactory : public RefCountInterface { virtual scoped_refptr CreateAudioSource( const string audio_source_label) = 0; + virtual scoped_refptr CreateDummyAudioSource( + const string audio_source_label, + int sample_rate_hz = 16000, + uint32_t num_channels = 2 + ) = 0; + virtual scoped_refptr CreateVideoSource( scoped_refptr capturer, const string video_source_label, scoped_refptr constraints) = 0; @@ -58,6 +65,9 @@ class RTCPeerConnectionFactory : public RefCountInterface { virtual scoped_refptr CreateAudioTrack( scoped_refptr source, const string track_id) = 0; + virtual scoped_refptr CreateAudioTrack( + scoped_refptr source, const string track_id) = 0; + virtual scoped_refptr CreateVideoTrack( scoped_refptr source, const string track_id) = 0; diff --git a/src/internal/audio_util.cc b/src/internal/audio_util.cc new file mode 100644 index 0000000000..0acdaf866a --- /dev/null +++ b/src/internal/audio_util.cc @@ -0,0 +1,90 @@ +#include "audio_util.h" + +#include "rtc_types.h" + +namespace libwebrtc { + +uint32_t AudioScale( + uint8_t* dst_data, + uint32_t dst_bits_per_sample, + uint32_t dst_samples_per_channel, + int dst_sample_rate, + uint32_t dst_num_channels, + const uint8_t* src_data, + uint32_t src_bits_per_sample, + uint32_t src_samples_per_channel, + int src_sample_rate, + uint32_t src_num_channels) +{ + if (!dst_data || + !src_data || + (dst_bits_per_sample % 8 != 0) || + (dst_bits_per_sample < 8) || + (dst_bits_per_sample > 32) || + (src_bits_per_sample % 8 != 0) || + (src_bits_per_sample < 8) || + (src_bits_per_sample > 32) || + (dst_samples_per_channel < 160) || + (src_samples_per_channel < 160) || + (dst_sample_rate < 16) || + (src_sample_rate < 16) || + (dst_num_channels < 1) || + (src_num_channels < 1) + ) + { + return 0; + } + + uint32_t result = 0; + + uint32_t src_bytes_per_sample = src_bits_per_sample / 8; + uint32_t dst_bytes_per_sample = dst_bits_per_sample / 8; + + float sample_rate_scale = static_cast(dst_sample_rate) / src_sample_rate; + float channel_scale = static_cast(dst_num_channels) / src_num_channels; + + for (uint32_t dst_sample = 0; dst_sample < dst_samples_per_channel; ++dst_sample) { + uint32_t src_sample = static_cast(dst_sample / sample_rate_scale); + + if (src_sample >= src_samples_per_channel) { + break; + } + + for (uint32_t dst_channel = 0; dst_channel < dst_num_channels; ++dst_channel) { + uint32_t src_channel = static_cast(dst_channel / channel_scale); + if (src_channel >= src_num_channels) { + break; + } + + const uint8_t* src_sample_ptr = src_data + + (src_sample * src_num_channels + src_channel) * src_bytes_per_sample; + + uint8_t* dst_sample_ptr = dst_data + + (dst_sample * dst_num_channels + dst_channel) * dst_bytes_per_sample; + + if (src_bits_per_sample == dst_bits_per_sample) { + memcpy(dst_sample_ptr, src_sample_ptr, dst_bytes_per_sample); + } else if (src_bits_per_sample < dst_bits_per_sample) { + int32_t sample = 0; + memcpy(&sample, src_sample_ptr, src_bytes_per_sample); + sample = static_cast( + sample * (1 << (dst_bits_per_sample - src_bits_per_sample)) + ); + memcpy(dst_sample_ptr, &sample, dst_bytes_per_sample); + } else { + int32_t sample = 0; + memcpy(&sample, src_sample_ptr, src_bytes_per_sample); + sample = static_cast( + sample / (1 << (src_bits_per_sample - dst_bits_per_sample)) + ); + memcpy(dst_sample_ptr, &sample, dst_bytes_per_sample); + } + + result += dst_bytes_per_sample; + } + } + + return result; +} + +} // namespace libwebrtc diff --git a/src/internal/audio_util.h b/src/internal/audio_util.h new file mode 100644 index 0000000000..39bbcf6a0e --- /dev/null +++ b/src/internal/audio_util.h @@ -0,0 +1,23 @@ +#ifndef INTERNAL_AUDIO_UTIL_HXX +#define INTERNAL_AUDIO_UTIL_HXX + +#include + +namespace libwebrtc { + +uint32_t AudioScale( + uint8_t* dst_data, + uint32_t dst_bits_per_sample, + uint32_t dst_samples_per_channel, + int dst_sample_rate, + uint32_t dst_num_channels, + const uint8_t* src_data, + uint32_t src_bits_per_sample, + uint32_t src_samples_per_channel, + int src_sample_rate, + uint32_t src_num_channels +); + +} // namespace libwebrtc + +#endif // INTERNAL_AUDIO_UTIL_HXX \ No newline at end of file diff --git a/src/internal/desktop_capturer.cc b/src/internal/desktop_capturer.cc index 34d39243a7..5b78a8b958 100644 --- a/src/internal/desktop_capturer.cc +++ b/src/internal/desktop_capturer.cc @@ -1,3 +1,3 @@ -#include "desktop_capturer.h" +#include "src/internal/desktop_capturer.h" namespace libwebrtc {} // namespace libwebrtc diff --git a/src/internal/dummy_audio_capturer.cc b/src/internal/dummy_audio_capturer.cc new file mode 100644 index 0000000000..fdb4a8c68f --- /dev/null +++ b/src/internal/dummy_audio_capturer.cc @@ -0,0 +1,163 @@ +#include "src/internal/dummy_audio_capturer.h" + +#include "rtc_base/logging.h" +#include "rtc_base/time_utils.h" + +namespace webrtc { +namespace internal { + +DummyAudioCapturer::DummyAudioCapturer( + TaskQueueFactory* task_queue_factory, + rtc::Thread* signaling_thread, + int bits_per_sample, + int sample_rate_hz, + size_t number_of_channels +) : task_queue_(task_queue_factory->CreateTaskQueue("DummyAudioCapturer", TaskQueueFactory::Priority::HIGH)) + , signaling_thread_(signaling_thread) + , bits_per_sample_(bits_per_sample) + , sample_rate_hz_(sample_rate_hz) + , number_of_channels_(number_of_channels) + , number_of_frames_(sample_rate_hz / 100) // for 10 msec chunk + , sinks_() +{ + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor " << (void*)this; +} + +DummyAudioCapturer::~DummyAudioCapturer() +{ + Stop(); + RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; +} + +RTCCaptureState DummyAudioCapturer::Start() +{ + if (capture_state_ == RTCCaptureState::CS_RUNNING) { + return capture_state_; + } + + capture_delay_ = number_of_frames_ * 1000 / sample_rate_hz_; + capture_state_ = RTCCaptureState::CS_RUNNING; + task_queue_->PostTask([this] { CaptureFrame(); }); + if (observer_) { + if (!signaling_thread_->IsCurrent()) { + signaling_thread_->BlockingCall([&, this]() { + if (observer_) { observer_->OnStart(); } + }); + } + else { + observer_->OnStart(); + } + } + return capture_state_; +} + +void DummyAudioCapturer::Stop() +{ + if (!IsRunning()) { + return; + } + + if (observer_) { + if (!signaling_thread_->IsCurrent()) { + signaling_thread_->BlockingCall([&, this]() { + if (observer_) { observer_->OnStop(); } + }); + } else { + observer_->OnStop(); + } + } + capture_state_ = RTCCaptureState::CS_STOPPED; +} + +RTCCaptureState DummyAudioCapturer::CaptureState() { + return capture_state_; +} + +bool DummyAudioCapturer::IsRunning() const { + return capture_state_ == RTCCaptureState::CS_RUNNING; +} + +void DummyAudioCapturer::AddSink(AudioTrackSinkInterface* sink) { + if (sinks_.end() == std::find(sinks_.begin(), sinks_.end(), sink)) { + sinks_.push_back(sink); + } +} + +void DummyAudioCapturer::RemoveSink(AudioTrackSinkInterface* sink) { + sinks_.erase( + std::remove_if( + sinks_.begin(), sinks_.end(), + [sink](AudioTrackSinkInterface* sink_) { + return sink_ == sink; + }), + sinks_.end()); +} + +void DummyAudioCapturer::OnData(const void* audio_data, + int bits_per_sample, + int sample_rate, + size_t number_of_channels, + size_t number_of_frames) +{ + for (auto* sink_ : sinks_) { + sink_->OnData( + audio_data, + bits_per_sample, + sample_rate, + number_of_channels, + number_of_frames + ); + } +} + +void DummyAudioCapturer::OnFrameReady(const RTCAudioDataPtr& audio_data) { + OnData( + static_cast(audio_data->data()), + static_cast(audio_data->bits_per_sample()), + audio_data->sample_rate_hz(), + static_cast(audio_data->num_channels()), + static_cast(audio_data->samples_per_channel()) + ); +} + +void DummyAudioCapturer::FillBuffer() +{ + RTCAudioDataPtr audio_data = RTCAudioData::Create + ( + nullptr, + static_cast(bits_per_sample_), + sample_rate_hz_, + static_cast(number_of_channels_) + ); + + datas_.push_back(audio_data); + while (datas_.size() > 15) { + datas_.pop_front(); + } + +#if defined(DEBUG) || defined(_DEBUG) + audio_data->Clear(true); // fill 1Khz tone signal +#endif // DEBUG + + if (observer_ != nullptr) { + observer_->OnFillBuffer(audio_data); + } + OnFrameReady(audio_data); +} + +void DummyAudioCapturer::CaptureFrame() { + if (capture_state_ != RTCCaptureState::CS_RUNNING) { + return; + } + int64_t timeFirst = rtc::TimeMillis(); + FillBuffer(); + int64_t timeLast = rtc::TimeMillis(); + int64_t waitTime = capture_delay_ - (timeLast - timeFirst); + if (waitTime < 1) { waitTime = 1; } + task_queue_->PostDelayedHighPrecisionTask([this]() { + CaptureFrame(); + }, webrtc::TimeDelta::Millis(waitTime)); +} + +} // namespace internal +} // namespace webrtc diff --git a/src/internal/dummy_audio_capturer.h b/src/internal/dummy_audio_capturer.h new file mode 100644 index 0000000000..54699d9d3e --- /dev/null +++ b/src/internal/dummy_audio_capturer.h @@ -0,0 +1,106 @@ +#ifndef INTERNAL_DUMMY_AUDIO_CAPTURER_H_ +#define INTERNAL_DUMMY_AUDIO_CAPTURER_H_ + +#include + +#include "api/media_stream_interface.h" +#include "api/task_queue/task_queue_factory.h" +#include "rtc_base/thread.h" +#include "rtc_types.h" +#include "rtc_audio_data.h" +#include "rtc_dummy_audio_source.h" + +namespace webrtc { +namespace internal { + +using DummyAudioSourceObserver = libwebrtc::DummyAudioSourceObserver; +using RTCCaptureState = libwebrtc::RTCCaptureState; +using RTCAudioData = libwebrtc::RTCAudioData; +using RTCAudioDataPtr = libwebrtc::scoped_refptr; + +/** + * class DummyAudioCapturer + */ +class DummyAudioCapturer : public AudioSourceInterface { + public: + DummyAudioCapturer( + TaskQueueFactory* task_queue_factory, + rtc::Thread* signaling_thread, + int bits_per_sample, + int sample_rate_hz, + size_t number_of_channels + ); + + virtual ~DummyAudioCapturer(); + + virtual void SetVolume(double volume) override {} + + virtual void RegisterAudioObserver(AudioObserver* observer) override {} + virtual void UnregisterAudioObserver(AudioObserver* observer) override {} + + virtual void RegisterObserver(ObserverInterface* observer) override {} + virtual void UnregisterObserver(ObserverInterface* observer) override {} + + virtual const cricket::AudioOptions options() const override { + return {}; + } + + virtual MediaSourceInterface::SourceState state() const override { + return MediaSourceInterface::SourceState::kLive; + } + + virtual bool remote() const override { return false; } + + void RegisterAudioDataObserver(DummyAudioSourceObserver* observer) { + observer_ = observer; + } + + void DeRegisterAudioDataObserver() { + observer_ = nullptr; + } + + int bits_per_sample() const { return bits_per_sample_; } + int sample_rate_hz() const { return sample_rate_hz_; } + size_t number_of_channels() { return number_of_channels_; } + size_t number_of_frames() { return number_of_frames_; } + + RTCCaptureState Start(); + void Stop(); + RTCCaptureState CaptureState(); + bool IsRunning() const; + + DummyAudioSourceObserver* GetObserver() { return observer_; } + + void AddSink(AudioTrackSinkInterface* sink) override; + void RemoveSink(AudioTrackSinkInterface* sink) override; + + protected: + void OnData(const void* audio_data, + int bits_per_sample, + int sample_rate, + size_t number_of_channels, + size_t number_of_frames); + + private: + void OnFrameReady(const RTCAudioDataPtr& audio_data); + void FillBuffer(); + void CaptureFrame(); + + private: + std::unique_ptr task_queue_; + rtc::Thread* signaling_thread_ = nullptr; + int bits_per_sample_ = 16; + int sample_rate_hz_ = 44100; + size_t number_of_channels_ = 2; + size_t number_of_frames_ = 441; + RTCCaptureState capture_state_ = RTCCaptureState::CS_STOPPED; + uint32_t capture_delay_ = 1000; // 1s + std::list sinks_; + std::list datas_; + DummyAudioSourceObserver* observer_ = nullptr; +}; // end class DummyAudioCapturer + +} // namespace internal +} // namespace webrtc + +#endif // INTERNAL_DUMMY_AUDIO_CAPTURER_H_ diff --git a/src/internal/dummy_capturer.cc b/src/internal/dummy_capturer.cc index ac4aa19c9d..7344ac5617 100644 --- a/src/internal/dummy_capturer.cc +++ b/src/internal/dummy_capturer.cc @@ -1,3 +1,3 @@ -#include "dummy_capturer.h" +#include "src/internal/dummy_capturer.h" namespace libwebrtc {} // namespace libwebrtc \ No newline at end of file diff --git a/src/interop/libwebrtc_interop.cc b/src/interop/libwebrtc_interop.cc index 556794e117..e0f9879611 100644 --- a/src/interop/libwebrtc_interop.cc +++ b/src/interop/libwebrtc_interop.cc @@ -11,9 +11,12 @@ rtcBool32 LIB_WEBRTC_CALL LibWebRTC_Initialize() noexcept : rtcBool32::kFalse; } -rtcPeerConnectionFactoryHandle LIB_WEBRTC_CALL LibWebRTC_CreateRTCPeerConnectionFactory() noexcept +rtcPeerConnectionFactoryHandle LIB_WEBRTC_CALL LibWebRTC_CreateRTCPeerConnectionFactory( + rtcBool32 use_dummy_audio /*= rtcBool32::kFalse*/ +) noexcept { - scoped_refptr p = LibWebRTC::CreateRTCPeerConnectionFactory(); + scoped_refptr p = + LibWebRTC::CreateRTCPeerConnectionFactory(use_dummy_audio != rtcBool32::kFalse); return static_cast(p.release()); } diff --git a/src/interop/rtc_peerconnection_factory_interop.cc b/src/interop/rtc_peerconnection_factory_interop.cc index 78e6a14029..e74f1a69c8 100644 --- a/src/interop/rtc_peerconnection_factory_interop.cc +++ b/src/interop/rtc_peerconnection_factory_interop.cc @@ -48,13 +48,14 @@ RTCPeerConnectionFactory_Create() noexcept rtcBool32 LIB_WEBRTC_CALL RTCPeerConnectionFactory_Initialize( - rtcPeerConnectionFactoryHandle factory + rtcPeerConnectionFactoryHandle factory, + rtcBool32 use_dummy_audio /*= rtcBool32::kFalse*/ ) noexcept { CHECK_POINTER_EX(factory, rtcBool32::kFalse); scoped_refptr pFactory = static_cast(factory); - return pFactory->Initialize() + return pFactory->Initialize(use_dummy_audio != rtcBool32::kFalse) ? rtcBool32::kTrue : rtcBool32::kFalse; } // end RTCPeerConnectionFactory_Initialize diff --git a/src/libwebrtc.cc b/src/libwebrtc.cc index a2e03243dc..538bc3186c 100644 --- a/src/libwebrtc.cc +++ b/src/libwebrtc.cc @@ -30,11 +30,11 @@ void LibWebRTC::Terminate() { // Creates and returns an instance of RTCPeerConnectionFactory. scoped_refptr -LibWebRTC::CreateRTCPeerConnectionFactory() { +LibWebRTC::CreateRTCPeerConnectionFactory(bool use_dummy_audio /*= false*/) { scoped_refptr rtc_peerconnection_factory = scoped_refptr( new RefCountedObject()); - rtc_peerconnection_factory->Initialize(); + rtc_peerconnection_factory->Initialize(use_dummy_audio); return rtc_peerconnection_factory; } diff --git a/src/rtc_audio_data_impl.cc b/src/rtc_audio_data_impl.cc new file mode 100644 index 0000000000..b59c392965 --- /dev/null +++ b/src/rtc_audio_data_impl.cc @@ -0,0 +1,167 @@ +#include "rtc_audio_data_impl.h" +#include "rtc_base/checks.h" +#include "src/internal/audio_util.h" + +namespace libwebrtc { + +double RTC_FREQUENCY = 1000.0; // Hertz +double RTC_PI = 3.14159265358979323846; + +/** + * class RTCAudioData + */ + +scoped_refptr RTCAudioData::Create( + const uint8_t* data, + uint32_t bits_per_sample, + int sample_rate_hz, + uint32_t num_channels /* = 1 */ +) { + scoped_refptr audio_data = + scoped_refptr( + new RefCountedObject( + data, + bits_per_sample, + sample_rate_hz, + num_channels + ) + ); + return audio_data; +} + +scoped_refptr RTCAudioData::Create() { + return RTCAudioData::Create( + nullptr, // data + 16, // 16 bits + 44100, // sample_rate in Hz + 2 // num_channels + ); +} + +/** + * class RTCAudioDataImpl + */ + +RTCAudioDataImpl::RTCAudioDataImpl( + const uint8_t* data, + uint32_t bits_per_sample, + int sample_rate_hz, + uint32_t num_channels +) : bits_per_sample_(bits_per_sample) + , samples_per_channel_(sample_rate_hz / 100) // for 10 ms chunk + , sample_rate_hz_(sample_rate_hz) + , num_channels_(num_channels) + , total_data_size_(0) + , data_size_(0) + , data_(nullptr) +{ + RTC_DCHECK_GE(bits_per_sample_, 16); + RTC_DCHECK_LE(bits_per_sample_, 32); + RTC_DCHECK_EQ(bits_per_sample_ % 8, 0); + RTC_DCHECK_GE(sample_rate_hz_, 16000); + RTC_DCHECK_GT(num_channels_, 0); + + total_data_size_ = data_size_ = samples_per_channel_ * num_channels_ * bits_per_sample_ / 8; + if (data_size_ > 0) { + data_ = std::unique_ptr( + static_cast(webrtc::AlignedMalloc(data_size_, 64)) + ); + if (data) { + memcpy(data_.get(), data, data_size_); + } + else { + memset(data_.get(), 0, data_size_); + } + } +} + +RTCAudioDataImpl::~RTCAudioDataImpl() { + data_ = nullptr; +} + +int RTCAudioDataImpl::ScaleFrom(scoped_refptr src) { + if (src == nullptr) { + return 0; + } + + uint32_t result = 0; + if (src->data_size() == data_size_ && + src->bits_per_sample() == bits_per_sample_ && + src->samples_per_channel() == samples_per_channel_ && + src->sample_rate_hz() == sample_rate_hz_ && + src->num_channels() == num_channels_) + { + // direct copy + memcpy(data_.get(), src->data(), data_size_); + result = static_cast(data_size_); + } + else + { + // scale + result = AudioScale( + data_.get(), + bits_per_sample(), + samples_per_channel(), + sample_rate_hz(), + num_channels(), + src->data(), + src->bits_per_sample(), + src->samples_per_channel(), + src->sample_rate_hz(), + src->num_channels() + ); + } + return static_cast(result); +} + +int RTCAudioDataImpl::Clear(bool fill_1khz_tone /* = false */) { + if (data_size_ == 0) { + return 0; + } + + if (fill_1khz_tone) { + if (16 == bits_per_sample_) { + int16_t* pDest = reinterpret_cast(data_.get()); + for (size_t i = 0; i < samples_per_channel_; ++i) { + double time = static_cast(i) / sample_rate_hz_; + int16_t sample = static_cast(32767 * sin(2 * RTC_PI * RTC_FREQUENCY * time)); + for (size_t ch = 0; ch < num_channels_; ++ch) { + pDest[i * num_channels_ + ch] = sample; + } + } + } + else if (24 == bits_per_sample_) { + int32_t* pDest = reinterpret_cast(data_.get()); + for (size_t i = 0; i < samples_per_channel_; ++i) { + double time = static_cast(i) / sample_rate_hz_; + int32_t sample = static_cast(8388607 * sin(2 * RTC_PI * RTC_FREQUENCY * time)); + for (size_t ch = 0; ch < num_channels_; ++ch) { + uint8_t* pByteDest = reinterpret_cast(pDest) + (i * num_channels_ + ch) * 3; + pByteDest[2] = static_cast((sample >> 16) & 0xFF); + pByteDest[1] = static_cast((sample >> 8) & 0xFF); + pByteDest[0] = static_cast(sample & 0xFF); + } + } + } + else if (32 == bits_per_sample_) { + int32_t* pDest = reinterpret_cast(data_.get()); + for (size_t i = 0; i < samples_per_channel_; ++i) { + double time = static_cast(i) / sample_rate_hz_; + int32_t sample = static_cast(2147483647 * sin(2 * RTC_PI * RTC_FREQUENCY * time)); + for (size_t ch = 0; ch < num_channels_; ++ch) { + pDest[i * num_channels_ + ch] = sample; + } + } + } + else { + return 0; + } + } + else { + memset(data_.get(), 0, data_size_); + } + + return static_cast(data_size_); +} + +} // namespace libwebrtc diff --git a/src/rtc_audio_data_impl.h b/src/rtc_audio_data_impl.h new file mode 100644 index 0000000000..8328054be8 --- /dev/null +++ b/src/rtc_audio_data_impl.h @@ -0,0 +1,46 @@ +#ifndef LIB_WEBRTC_RTC_AUDIO_DATA_IMPL_HXX +#define LIB_WEBRTC_RTC_AUDIO_DATA_IMPL_HXX + +#include +#include + +#include "rtc_base/memory/aligned_malloc.h" +#include "rtc_audio_data.h" + +namespace libwebrtc { + +class RTCAudioDataImpl : public RTCAudioData { + public: + RTCAudioDataImpl( + const uint8_t* data, + uint32_t bits_per_sample, + int sample_rate_hz, + uint32_t num_channels + ); + virtual ~RTCAudioDataImpl(); + + public: + const uint8_t* data() const override { return data_.get(); } + size_t data_size() const override { return data_size_; } + uint32_t bits_per_sample() const override { return bits_per_sample_; } + uint32_t samples_per_channel() const override { return samples_per_channel_; } + int sample_rate_hz() const override { return sample_rate_hz_; } + uint32_t num_channels() const override { return num_channels_; } + + int ScaleFrom(scoped_refptr src) override; + + int Clear(bool fill_1khz_tone = false) override; + + private: + uint32_t bits_per_sample_; + uint32_t samples_per_channel_; + int sample_rate_hz_; + uint32_t num_channels_; + size_t total_data_size_; + size_t data_size_; + std::unique_ptr data_; +}; // end class RTCAudioDataImpl + +} // namespace libwebrtc + +#endif // LIB_WEBRTC_RTC_AUDIO_DATA_IMPL_HXX diff --git a/src/rtc_dummy_audio_source_impl.cc b/src/rtc_dummy_audio_source_impl.cc new file mode 100644 index 0000000000..df4060d299 --- /dev/null +++ b/src/rtc_dummy_audio_source_impl.cc @@ -0,0 +1,132 @@ +#include "rtc_dummy_audio_source_impl.h" +#include "rtc_base/logging.h" + +#include "interop_api.h" + +namespace libwebrtc { + +/** + * DummyAudioSourceObserverImpl + */ + +DummyAudioSourceObserverImpl::DummyAudioSourceObserverImpl( + void* callbacks /* rtcDummyAudioSourceObserverCallbacks* */) + : callbacks_(nullptr) { + if (callbacks) { + size_t nSize = sizeof(rtcDummyAudioSourceObserverCallbacks); + callbacks_ = malloc(nSize); + memcpy(callbacks_, (const void*)callbacks, nSize); + } +} + +DummyAudioSourceObserverImpl::~DummyAudioSourceObserverImpl() { + if (callbacks_) { + free(callbacks_); + } + callbacks_ = nullptr; +} + +void DummyAudioSourceObserverImpl::OnStart() { + if (callbacks_) { + rtcDummyAudioSourceObserverCallbacks* pCallbacks = + reinterpret_cast(callbacks_); + pCallbacks->Started(pCallbacks->UserData); + } +} + +void DummyAudioSourceObserverImpl::OnPaused() { + if (callbacks_) { + rtcDummyAudioSourceObserverCallbacks* pCallbacks = + reinterpret_cast(callbacks_); + pCallbacks->Paused(pCallbacks->UserData); + } +} + +void DummyAudioSourceObserverImpl::OnStop() { + if (callbacks_) { + rtcDummyAudioSourceObserverCallbacks* pCallbacks = + reinterpret_cast(callbacks_); + pCallbacks->Stopped(pCallbacks->UserData); + } +} + +void DummyAudioSourceObserverImpl::OnError() { + if (callbacks_) { + rtcDummyAudioSourceObserverCallbacks* pCallbacks = + reinterpret_cast(callbacks_); + pCallbacks->Failed(pCallbacks->UserData); + } +} + +void DummyAudioSourceObserverImpl::OnFillBuffer( + scoped_refptr audio_data) { + if (callbacks_) { + rtcDummyAudioSourceObserverCallbacks* pCallbacks = + reinterpret_cast(callbacks_); + rtcAudioDataHandle hData = + static_cast(audio_data.release()); + pCallbacks->FillBuffer(pCallbacks->UserData, hData); + } +} + +/** + * class RTCDummyAudioSourceImpl + */ + +RTCDummyAudioSourceImpl::RTCDummyAudioSourceImpl( + rtc::scoped_refptr rtc_audio_source +) : rtc_audio_source_(rtc_audio_source) +{ + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor " << (void*)this; +} + +RTCDummyAudioSourceImpl::~RTCDummyAudioSourceImpl() { + Stop(); + RTC_LOG(LS_INFO) << __FUNCTION__ << ": dtor "; +} + +void RTCDummyAudioSourceImpl::RegisterAudioDataObserver(DummyAudioSourceObserver* observer) { + rtc_audio_source_->RegisterAudioDataObserver(observer); +} + +void RTCDummyAudioSourceImpl::DeRegisterAudioDataObserver() { + rtc_audio_source_->DeRegisterAudioDataObserver(); +} + +int RTCDummyAudioSourceImpl::bits_per_sample() const { + return rtc_audio_source_->bits_per_sample(); +} + +int RTCDummyAudioSourceImpl::sample_rate_hz() const { + return rtc_audio_source_->sample_rate_hz(); +} + +size_t RTCDummyAudioSourceImpl::number_of_channels() { + return rtc_audio_source_->number_of_channels(); +} + +size_t RTCDummyAudioSourceImpl::number_of_frames() { + return rtc_audio_source_->number_of_frames(); +} + +RTCCaptureState RTCDummyAudioSourceImpl::Start() { + return rtc_audio_source_->Start(); +} + +void RTCDummyAudioSourceImpl::Stop() { + rtc_audio_source_->Stop(); +} + +RTCCaptureState RTCDummyAudioSourceImpl::CaptureState() { + return rtc_audio_source_->CaptureState(); +} + +bool RTCDummyAudioSourceImpl::IsRunning() const { + return rtc_audio_source_->IsRunning(); +} + +DummyAudioSourceObserver* RTCDummyAudioSourceImpl::GetObserver() { + return rtc_audio_source_->GetObserver(); +} + +} // namespace libwebrtc diff --git a/src/rtc_dummy_audio_source_impl.h b/src/rtc_dummy_audio_source_impl.h new file mode 100644 index 0000000000..bb7de9203b --- /dev/null +++ b/src/rtc_dummy_audio_source_impl.h @@ -0,0 +1,69 @@ +#ifndef LIB_WEBRTC_DUMMY_AUDIO_SOURCE_IMPL_HXX +#define LIB_WEBRTC_DUMMY_AUDIO_SOURCE_IMPL_HXX + +#include + +#include "rtc_types.h" +#include "rtc_dummy_audio_source.h" +#include "src/internal/dummy_audio_capturer.h" + +namespace libwebrtc { + +/** + * class DummyAudioSourceObserverImpl + */ +class DummyAudioSourceObserverImpl : public DummyAudioSourceObserver +{ + public: + DummyAudioSourceObserverImpl(void* callbacks /* rtcAudioSourceObserverCallbacks* */); + ~DummyAudioSourceObserverImpl(); + + void OnStart() override; + void OnPaused() override; + void OnStop() override; + void OnError() override; + void OnFillBuffer(scoped_refptr audio_data) override; + + private: + void* callbacks_ /* rtcAudioSourceObserverCallbacks* */; +}; // end class DummyAudioSourceObserverImpl + +/** + * class RTCDummyAudioSourceImpl + */ +class RTCDummyAudioSourceImpl : public RTCDummyAudioSource { + public: + RTCDummyAudioSourceImpl( + rtc::scoped_refptr rtc_audio_source + ); + + virtual ~RTCDummyAudioSourceImpl(); + + void RegisterAudioDataObserver(DummyAudioSourceObserver* observer) override; + void DeRegisterAudioDataObserver() override; + + int bits_per_sample() const override; + int sample_rate_hz() const override; + size_t number_of_channels() override; + size_t number_of_frames() override; + + RTCCaptureState Start() override; + void Stop() override; + RTCCaptureState CaptureState() override; + bool IsRunning() const override; + + DummyAudioSourceObserver* GetObserver() override; + + rtc::scoped_refptr rtc_audio_source() { + return rtc::scoped_refptr( + static_cast(rtc_audio_source_.get()) + ); + } + + private: + rtc::scoped_refptr rtc_audio_source_; +}; + +} // namespace libwebrtc + +#endif // LIB_WEBRTC_DUMMY_AUDIO_SOURCE_IMPL_HXX diff --git a/src/rtc_dummy_video_capturer_impl.h b/src/rtc_dummy_video_capturer_impl.h index b3dbbf86dc..ed1ee75f33 100644 --- a/src/rtc_dummy_video_capturer_impl.h +++ b/src/rtc_dummy_video_capturer_impl.h @@ -16,7 +16,7 @@ namespace libwebrtc { class DummyVideoCapturerObserverImpl : public DummyVideoCapturerObserver { public: - DummyVideoCapturerObserverImpl(void* callbacks /* rtcDesktopCapturerObserverCallbacks* */); + DummyVideoCapturerObserverImpl(void* callbacks /* rtcVideoCapturerObserverCallbacks* */); ~DummyVideoCapturerObserverImpl(); void OnStart() override; @@ -26,7 +26,7 @@ class DummyVideoCapturerObserverImpl : public DummyVideoCapturerObserver void OnFillBuffer(scoped_refptr frame) override; private: - void* callbacks_ /* rtcDesktopCapturerObserverCallbacks* */; + void* callbacks_ /* rtcVideoCapturerObserverCallbacks* */; }; // end class DummyVideoCapturerObserverImpl /** diff --git a/src/rtc_peerconnection_factory_impl.cc b/src/rtc_peerconnection_factory_impl.cc index 75e4d43645..956c0c358c 100644 --- a/src/rtc_peerconnection_factory_impl.cc +++ b/src/rtc_peerconnection_factory_impl.cc @@ -15,6 +15,9 @@ #include "rtc_video_device_impl.h" #include "rtc_video_source_impl.h" #include "rtc_dummy_video_capturer_impl.h" +#include "rtc_dummy_audio_source_impl.h" +#include "src/internal/dummy_capturer.h" +#include "src/internal/dummy_audio_capturer.h" #if defined(USE_INTEL_MEDIA_SDK) #include "src/win/mediacapabilities.h" #include "src/win/msdkvideodecoderfactory.h" @@ -47,7 +50,8 @@ RTCPeerConnectionFactoryImpl::RTCPeerConnectionFactoryImpl() {} RTCPeerConnectionFactoryImpl::~RTCPeerConnectionFactoryImpl() {} -bool RTCPeerConnectionFactoryImpl::Initialize() { +bool RTCPeerConnectionFactoryImpl::Initialize(bool use_dummy_audio /*= false*/) { + use_dummy_audio_ = use_dummy_audio; worker_thread_ = rtc::Thread::Create(); worker_thread_->SetName("worker_thread", nullptr); RTC_CHECK(worker_thread_->Start()) << "Failed to start thread"; @@ -102,7 +106,9 @@ bool RTCPeerConnectionFactoryImpl::Terminate() { void RTCPeerConnectionFactoryImpl::CreateAudioDeviceModule_w() { if (!audio_device_module_) audio_device_module_ = webrtc::AudioDeviceModule::Create( - webrtc::AudioDeviceModule::kPlatformDefaultAudio, + use_dummy_audio_ + ? webrtc::AudioDeviceModule::kDummyAudio + : webrtc::AudioDeviceModule::kPlatformDefaultAudio, task_queue_factory_.get()); } @@ -163,6 +169,28 @@ scoped_refptr RTCPeerConnectionFactoryImpl::CreateAudioSource( return source; } +scoped_refptr RTCPeerConnectionFactoryImpl::CreateDummyAudioSource( + const string audio_source_label, + int sample_rate_hz /*= 16000 */, + uint32_t num_channels /*= 2*/ +) { + + rtc::scoped_refptr rtc_source_track = + rtc::scoped_refptr( + new rtc::RefCountedObject( + task_queue_factory_.get(), + signaling_thread_.get(), + 16, /* bits_per_sample */ + sample_rate_hz, + num_channels + ) + ); + + scoped_refptr source = scoped_refptr( + new RefCountedObject(rtc_source_track)); + return source; +} + #ifdef RTC_DESKTOP_DEVICE scoped_refptr RTCPeerConnectionFactoryImpl::GetDesktopDevice() { @@ -329,6 +357,20 @@ scoped_refptr RTCPeerConnectionFactoryImpl::CreateAudioTrack( return track; } +scoped_refptr RTCPeerConnectionFactoryImpl::CreateAudioTrack( + scoped_refptr source, const string track_id) { + RTCDummyAudioSourceImpl* source_impl = + static_cast(source.get()); + + rtc::scoped_refptr audio_track( + rtc_peerconnection_factory_->CreateAudioTrack( + to_std_string(track_id), source_impl->rtc_audio_source().get())); + + scoped_refptr track = scoped_refptr( + new RefCountedObject(audio_track)); + return track; +} + scoped_refptr RTCPeerConnectionFactoryImpl::GetRtpSenderCapabilities( RTCMediaType media_type) { diff --git a/src/rtc_peerconnection_factory_impl.h b/src/rtc_peerconnection_factory_impl.h index 1eb3210f95..d185019bcf 100644 --- a/src/rtc_peerconnection_factory_impl.h +++ b/src/rtc_peerconnection_factory_impl.h @@ -11,7 +11,6 @@ #include "rtc_peerconnection.h" #include "rtc_peerconnection_factory.h" #include "rtc_video_device_impl.h" -#include "src/internal/dummy_capturer.h" #ifdef RTC_DESKTOP_DEVICE #include "rtc_desktop_capturer_impl.h" @@ -27,7 +26,7 @@ class RTCPeerConnectionFactoryImpl : public RTCPeerConnectionFactory { virtual ~RTCPeerConnectionFactoryImpl(); - bool Initialize() override; + bool Initialize(bool use_dummy_audio = false) override; bool Terminate() override; @@ -44,6 +43,12 @@ class RTCPeerConnectionFactoryImpl : public RTCPeerConnectionFactory { virtual scoped_refptr CreateAudioSource( const string audio_source_label) override; + virtual scoped_refptr CreateDummyAudioSource( + const string audio_source_label, + int sample_rate_hz = 16000, + uint32_t num_channels = 2 + ) override; + virtual scoped_refptr CreateVideoSource( scoped_refptr capturer, const string video_source_label, scoped_refptr constraints) override; @@ -62,6 +67,9 @@ class RTCPeerConnectionFactoryImpl : public RTCPeerConnectionFactory { virtual scoped_refptr CreateAudioTrack( scoped_refptr source, const string track_id) override; + virtual scoped_refptr CreateAudioTrack( + scoped_refptr source, const string track_id) override; + virtual scoped_refptr CreateVideoTrack( scoped_refptr source, const string track_id) override; @@ -113,6 +121,7 @@ class RTCPeerConnectionFactoryImpl : public RTCPeerConnectionFactory { #endif std::list> peerconnections_; std::unique_ptr task_queue_factory_; + bool use_dummy_audio_ = false; }; } // namespace libwebrtc From 5234f6763864ab9dd10dc080db09f05f6e81f816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Tue, 28 Jan 2025 06:28:23 +0300 Subject: [PATCH 62/69] Optimization and added interop methods --- BUILD.gn | 2 + include/interop_api.h | 189 +++++++++++++++++- include/rtc_audio_data.h | 6 +- include/rtc_peerconnection_factory.h | 2 + include/rtc_types.h | 9 + src/internal/audio_util.h | 6 +- src/internal/dummy_audio_capturer.cc | 8 +- src/internal/dummy_audio_capturer.h | 7 +- src/internal/jpeg_util.h | 6 +- src/interop/libwebrtc_interop.cc | 3 + src/interop/rtc_audio_data_interop.cc | 127 ++++++++++++ src/interop/rtc_dummy_audio_source_interop.cc | 114 +++++++++++ .../rtc_peerconnection_factory_interop.cc | 58 ++++++ src/rtc_audio_data_impl.cc | 26 ++- src/rtc_audio_data_impl.h | 5 +- src/rtc_peerconnection_factory_impl.cc | 12 +- src/rtc_peerconnection_factory_impl.h | 2 + 17 files changed, 557 insertions(+), 25 deletions(-) create mode 100644 src/interop/rtc_audio_data_interop.cc create mode 100644 src/interop/rtc_dummy_audio_source_interop.cc diff --git a/BUILD.gn b/BUILD.gn index cf0350ce0b..52b25cab98 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -181,9 +181,11 @@ rtc_shared_library("libwebrtc") { "src/interop/rtc_sdp_parse_error_interop.cc", "src/interop/rtc_mediaconstraints_interop.cc", "src/interop/rtc_peerconnection_factory_interop.cc", + "src/interop/rtc_audio_data_interop.cc", "src/interop/rtc_media_track_interop.cc", "src/interop/rtc_audio_device_interop.cc", "src/interop/rtc_audio_track_interop.cc", + "src/interop/rtc_dummy_audio_source_interop.cc", "src/interop/rtc_video_device_interop.cc", "src/interop/rtc_video_track_interop.cc", "src/interop/rtc_video_frame_interop.cc", diff --git a/include/interop_api.h b/include/interop_api.h index 2bdff8b649..45b84ece3e 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -25,6 +25,7 @@ using rtcSdpSemantics = libwebrtc::SdpSemantics; using rtcMediaType = libwebrtc::RTCMediaType; using rtcDesktopType = libwebrtc::DesktopType; using rtcCaptureState = libwebrtc::RTCCaptureState; +using rtcAudioDataToneFrequency = libwebrtc::RTCAudioDataToneFrequency; /// 64-bit timestamp for interop API. using rtcTimestamp = long long; @@ -268,6 +269,10 @@ enum class rtcResultU4 : unsigned int { /// support the specified input/output frequency ratio. Use a different output /// frequency for the current audio source to solve the issue. kAudioResamplingNotSupported = 0x80000402, + + /// Dummy audio source does not support. To resolve the issue, + /// use the PeerConnectionFactory initialize method with 'use_dummy_audio'. + kDummyAudioSourceNotSupported = 0x80000501, /// Error rtcResultU4 for a null or invalid pointer. kInvalidPointer = 0x80004003, @@ -364,6 +369,9 @@ using rtcVideoDeviceHandle = rtcRefCountedObjectHandle; /// Opaque handle to a native RTCAudioSource interop object. using rtcAudioSourceHandle = rtcRefCountedObjectHandle; +/// Opaque handle to a native RTCDummyAudioSource interop object. +using rtcDummyAudioSourceHandle = rtcRefCountedObjectHandle; + /// Opaque handle to a native RTCVideoSource interop object. using rtcVideoSourceHandle = rtcRefCountedObjectHandle; @@ -924,8 +932,22 @@ RTCPeerConnectionFactory_GetDesktopDevice( */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_CreateAudioSource( - rtcPeerConnectionFactoryHandle factory, const char* audio_source_label, - rtcAudioSourceHandle* pRetVal) noexcept; + rtcPeerConnectionFactoryHandle factory, + const char* audio_source_label, + rtcAudioSourceHandle* pRetVal +) noexcept; + +/** + * @brief Creates a new instance of the RTCDummyAudioSource object. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_CreateDummyAudioSource( + rtcPeerConnectionFactoryHandle factory, + const char* audio_source_label, + int sample_rate_hz, + unsigned int num_channels, + rtcAudioSourceHandle* pRetVal +) noexcept; /** * @brief Creates a new instance of the RTCVideoSource object. @@ -976,6 +998,14 @@ RTCPeerConnectionFactory_CreateAudioTrack( rtcPeerConnectionFactoryHandle factory, rtcAudioSourceHandle source, const char* track_id, rtcAudioTrackHandle* pRetVal) noexcept; +/** + * @brief Creates a new instance of the RTCAudioTrack object. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_CreateDummyAudioTrack( + rtcPeerConnectionFactoryHandle factory, rtcDummyAudioSourceHandle source, + const char* track_id, rtcAudioTrackHandle* pRetVal) noexcept; + /** * @brief Creates a new instance of the RTCVideoTrack object. */ @@ -1010,6 +1040,97 @@ RTCPeerConnectionFactory_GetRtpReceiverCapabilities( rtcPeerConnectionFactoryHandle factory, rtcMediaType media_type, rtcRtpCapabilitiesHandle* pRetVal) noexcept; +/** + * Returns whether an dummy audio device is used. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_GetUseDummyAudio( + rtcPeerConnectionFactoryHandle factory, + rtcBool32* pRetVal) noexcept; + +/* + * ---------------------------------------------------------------------- + * RTCAudioData interop methods + * ---------------------------------------------------------------------- + */ + +/** + * Creates a new instance of RTCAudioData. + * + * @param index - Sample index + * @param data - Sample data. (optional) + * @param bits_per_sample - Bits per sample. (16, 24, 32) + * @param sample_rate_hz - Sample rate in hertz. (16000, 44100, 480000) + * @param num_channels - Number of audio channels. [1 ... 8] + * @param pOutRetVal - Handle of object. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCAudioData_Create( + unsigned int index, + const unsigned char* data, + unsigned int bits_per_sample, + int sample_rate_hz, + unsigned int num_channels, + rtcAudioDataHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCAudioData_GetIndex( + rtcAudioDataHandle handle, + unsigned int* pRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCAudioData_GetData( + rtcAudioDataHandle handle, + const unsigned char** ppRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCAudioData_GetDataSize( + rtcAudioDataHandle handle, + int* pRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCAudioData_GetBitsPerSample( + rtcAudioDataHandle handle, + int* pRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCAudioData_GetSamplesPerChannel( + rtcAudioDataHandle handle, + int* pRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCAudioData_GetSampleRateHz( + rtcAudioDataHandle handle, + int* pRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCAudioData_GetNumChannels( + rtcAudioDataHandle handle, + int* pRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCAudioData_ScaleFrom( + rtcAudioDataHandle handle, + rtcAudioDataHandle source_data, + int* pRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCAudioData_Clear( + rtcAudioDataHandle handle, + rtcAudioDataToneFrequency frequency, + int* pRetVal +) noexcept; + /* * ---------------------------------------------------------------------- * RTCAudioDevice interop methods @@ -1143,6 +1264,70 @@ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCAudioDevice_SetSpeakerVolume( LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCAudioDevice_GetSpeakerVolume( rtcAudioDeviceHandle audiDevice, unsigned int* volume) noexcept; +/* + * ---------------------------------------------------------------------- + * RTCDummyAudioSource interop methods + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDummyAudioSource_RegisterAudioDataObserver( + rtcDummyAudioSourceHandle handle, + rtcDummyAudioSourceObserverCallbacks* callbacks +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDummyAudioSource_DeRegisterAudioDataObserver( + rtcDummyAudioSourceHandle handle +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDummyAudioSource_GetBitsPerSample( + rtcDummyAudioSourceHandle handle, + int* pRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDummyAudioSource_GetSampleRateHz( + rtcDummyAudioSourceHandle handle, + int* pRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDummyAudioSource_GetNumChannels( + rtcDummyAudioSourceHandle handle, + int* pRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDummyAudioSource_GetSamplesPerChannel( + rtcDummyAudioSourceHandle handle, + int* pRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDummyAudioSource_Start( + rtcDummyAudioSourceHandle handle, + rtcCaptureState* pRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDummyAudioSource_Stop( + rtcDummyAudioSourceHandle handle +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDummyAudioSource_GetCaptureState( + rtcDummyAudioSourceHandle handle, + rtcCaptureState* pRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCDummyAudioSource_IsRunning( + rtcDummyAudioSourceHandle handle, + rtcBool32* pRetVal +) noexcept; + /* * ---------------------------------------------------------------------- * RTCMediaTrack interop methods diff --git a/include/rtc_audio_data.h b/include/rtc_audio_data.h index 96b0525263..24958aa604 100644 --- a/include/rtc_audio_data.h +++ b/include/rtc_audio_data.h @@ -6,8 +6,9 @@ namespace libwebrtc { class RTCAudioData : public RefCountInterface { -public: +public: LIB_WEBRTC_API static scoped_refptr Create( + uint32_t index, const uint8_t* data, uint32_t bits_per_sample, int sample_rate_hz, // the sample rate in Hz. @@ -17,6 +18,7 @@ class RTCAudioData : public RefCountInterface { LIB_WEBRTC_API static scoped_refptr Create(); public: + virtual uint32_t index() const = 0; virtual const uint8_t* data() const = 0; virtual size_t data_size() const = 0; virtual uint32_t bits_per_sample() const = 0; @@ -32,7 +34,7 @@ class RTCAudioData : public RefCountInterface { /** * Empty the buffer space. Or fill it with 1khz tone signal. */ - virtual int Clear(bool fill_1khz_tone = false) = 0; + virtual int Clear(RTCAudioDataToneFrequency frequency = RTCAudioDataToneFrequency::kNone) = 0; protected: /** diff --git a/include/rtc_peerconnection_factory.h b/include/rtc_peerconnection_factory.h index eddc41ef12..4a6c64a24c 100644 --- a/include/rtc_peerconnection_factory.h +++ b/include/rtc_peerconnection_factory.h @@ -79,6 +79,8 @@ class RTCPeerConnectionFactory : public RefCountInterface { virtual scoped_refptr GetRtpReceiverCapabilities( RTCMediaType media_type) = 0; + + virtual bool GetUseDummyAudio() = 0; }; } // namespace libwebrtc diff --git a/include/rtc_types.h b/include/rtc_types.h index 994243711b..a1e882ba91 100644 --- a/include/rtc_types.h +++ b/include/rtc_types.h @@ -32,6 +32,15 @@ enum class RTCMediaType { AUDIO, VIDEO, DATA, UNSUPPORTED }; enum class RTCCaptureState { CS_RUNNING = 0, CS_STOPPED, CS_FAILED }; +enum class RTCAudioDataToneFrequency { + kNone = 0, // Clear audio buffer + kTone60Hz = 60, + kTone440Hz = 440, + kTone1kHz = 1000, + kTone2kHz = 2000, + kTone5kHz = 5000 +}; + using string = portable::string; // template diff --git a/src/internal/audio_util.h b/src/internal/audio_util.h index 39bbcf6a0e..799fe2e527 100644 --- a/src/internal/audio_util.h +++ b/src/internal/audio_util.h @@ -1,5 +1,5 @@ -#ifndef INTERNAL_AUDIO_UTIL_HXX -#define INTERNAL_AUDIO_UTIL_HXX +#ifndef LIB_WEBRTC_AUDIO_UTIL_HXX +#define LIB_WEBRTC_AUDIO_UTIL_HXX #include @@ -20,4 +20,4 @@ uint32_t AudioScale( } // namespace libwebrtc -#endif // INTERNAL_AUDIO_UTIL_HXX \ No newline at end of file +#endif // LIB_WEBRTC_AUDIO_UTIL_HXX \ No newline at end of file diff --git a/src/internal/dummy_audio_capturer.cc b/src/internal/dummy_audio_capturer.cc index fdb4a8c68f..dec7335886 100644 --- a/src/internal/dummy_audio_capturer.cc +++ b/src/internal/dummy_audio_capturer.cc @@ -11,9 +11,11 @@ DummyAudioCapturer::DummyAudioCapturer( rtc::Thread* signaling_thread, int bits_per_sample, int sample_rate_hz, - size_t number_of_channels + size_t number_of_channels, + const std::string name ) : task_queue_(task_queue_factory->CreateTaskQueue("DummyAudioCapturer", TaskQueueFactory::Priority::HIGH)) , signaling_thread_(signaling_thread) + , name_(name) , bits_per_sample_(bits_per_sample) , sample_rate_hz_(sample_rate_hz) , number_of_channels_(number_of_channels) @@ -35,6 +37,7 @@ RTCCaptureState DummyAudioCapturer::Start() return capture_state_; } + sample_index_ = 0; capture_delay_ = number_of_frames_ * 1000 / sample_rate_hz_; capture_state_ = RTCCaptureState::CS_RUNNING; task_queue_->PostTask([this] { CaptureFrame(); }); @@ -124,6 +127,7 @@ void DummyAudioCapturer::FillBuffer() { RTCAudioDataPtr audio_data = RTCAudioData::Create ( + sample_index_++, nullptr, static_cast(bits_per_sample_), sample_rate_hz_, @@ -136,7 +140,7 @@ void DummyAudioCapturer::FillBuffer() } #if defined(DEBUG) || defined(_DEBUG) - audio_data->Clear(true); // fill 1Khz tone signal + audio_data->Clear(libwebrtc::RTCAudioDataToneFrequency::kTone1kHz); // fill 1Khz tone signal #endif // DEBUG if (observer_ != nullptr) { diff --git a/src/internal/dummy_audio_capturer.h b/src/internal/dummy_audio_capturer.h index 54699d9d3e..3455157963 100644 --- a/src/internal/dummy_audio_capturer.h +++ b/src/internal/dummy_audio_capturer.h @@ -28,7 +28,8 @@ class DummyAudioCapturer : public AudioSourceInterface { rtc::Thread* signaling_thread, int bits_per_sample, int sample_rate_hz, - size_t number_of_channels + size_t number_of_channels, + const std::string name ); virtual ~DummyAudioCapturer(); @@ -64,6 +65,8 @@ class DummyAudioCapturer : public AudioSourceInterface { size_t number_of_channels() { return number_of_channels_; } size_t number_of_frames() { return number_of_frames_; } + const char* name() const { return name_.c_str(); } + RTCCaptureState Start(); void Stop(); RTCCaptureState CaptureState(); @@ -89,6 +92,8 @@ class DummyAudioCapturer : public AudioSourceInterface { private: std::unique_ptr task_queue_; rtc::Thread* signaling_thread_ = nullptr; + std::string name_; + uint32_t sample_index_ = 0; int bits_per_sample_ = 16; int sample_rate_hz_ = 44100; size_t number_of_channels_ = 2; diff --git a/src/internal/jpeg_util.h b/src/internal/jpeg_util.h index 1ae3c07c3d..4e61ae3f47 100644 --- a/src/internal/jpeg_util.h +++ b/src/internal/jpeg_util.h @@ -1,5 +1,5 @@ -#ifndef INTERNAL_JPEG_UTIL_HXX -#define INTERNAL_JPEG_UTIL_HXX +#ifndef LIB_WEBRTC_JPEG_UTIL_HXX +#define LIB_WEBRTC_JPEG_UTIL_HXX #include @@ -12,4 +12,4 @@ std::vector EncodeRGBToJpeg(const unsigned char* data, int width, int quality); } // namespace libwebrtc -#endif // INTERNAL_JPEG_UTIL_HXX +#endif // LIB_WEBRTC_JPEG_UTIL_HXX diff --git a/src/interop/libwebrtc_interop.cc b/src/interop/libwebrtc_interop.cc index e0f9879611..e329b42eeb 100644 --- a/src/interop/libwebrtc_interop.cc +++ b/src/interop/libwebrtc_interop.cc @@ -90,6 +90,9 @@ LibWebRTC_GetErrorMessage( case rtcResultU4::kAudioResamplingNotSupported: message= "The internal audio resampler used in the audio track read buffer doesn't support the specified input/output frequency ratio. Use a different output frequency for the current audio source to solve the issue."; break; + case rtcResultU4::kDummyAudioSourceNotSupported: + message = "Dummy audio source does not support. To resolve the issue, use the PeerConnectionFactory initialize method with 'use_dummy_audio'."; + break; case rtcResultU4::kInvalidPointer: message = "A null or invalid pointer."; break; diff --git a/src/interop/rtc_audio_data_interop.cc b/src/interop/rtc_audio_data_interop.cc new file mode 100644 index 0000000000..8e919f1e3d --- /dev/null +++ b/src/interop/rtc_audio_data_interop.cc @@ -0,0 +1,127 @@ +#include "rtc_audio_data.h" +#include "interop_api.h" + +using namespace libwebrtc; + +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioData_Create( + unsigned int index, + const unsigned char* data, + unsigned int bits_per_sample, + int sample_rate_hz, + unsigned int num_channels, + rtcAudioDataHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + + scoped_refptr p = RTCAudioData::Create( + static_cast(index), + static_cast(data), + static_cast(bits_per_sample), + sample_rate_hz, + static_cast(num_channels) + ); + *pOutRetVal = static_cast(p.release()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioData_GetIndex( + rtcAudioDataHandle handle, + unsigned int* pRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pRetVal, unsigned int, RTCAudioData, index); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioData_GetData( + rtcAudioDataHandle handle, + const unsigned char** ppRetVal +) noexcept +{ + CHECK_POINTER(ppRetVal); + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr p = static_cast(handle); + *ppRetVal = static_cast(p->data()); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioData_GetDataSize( + rtcAudioDataHandle handle, + int* pRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pRetVal, int, RTCAudioData, data_size); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioData_GetBitsPerSample( + rtcAudioDataHandle handle, + int* pRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pRetVal, int, RTCAudioData, bits_per_sample); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioData_GetSamplesPerChannel( + rtcAudioDataHandle handle, + int* pRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pRetVal, int, RTCAudioData, samples_per_channel); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioData_GetSampleRateHz( + rtcAudioDataHandle handle, + int* pRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pRetVal, int, RTCAudioData, sample_rate_hz); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioData_GetNumChannels( + rtcAudioDataHandle handle, + int* pRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pRetVal, int, RTCAudioData, num_channels); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioData_ScaleFrom( + rtcAudioDataHandle handle, + rtcAudioDataHandle source_data, + int* pRetVal +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(source_data, rtcResultU4::kInvalidParameter); + + scoped_refptr p = static_cast(handle); + scoped_refptr pSourceData = static_cast(source_data); + int retVal = p->ScaleFrom(pSourceData); + if (pRetVal) { *pRetVal = retVal; } + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioData_Clear( + rtcAudioDataHandle handle, + rtcAudioDataToneFrequency frequency, + int* pRetVal +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr p = static_cast(handle); + int retVal = p->Clear(static_cast(frequency)); + if (pRetVal) { *pRetVal = retVal; } + return rtcResultU4::kSuccess; +} diff --git a/src/interop/rtc_dummy_audio_source_interop.cc b/src/interop/rtc_dummy_audio_source_interop.cc new file mode 100644 index 0000000000..db76f2abc7 --- /dev/null +++ b/src/interop/rtc_dummy_audio_source_interop.cc @@ -0,0 +1,114 @@ +#include "src/rtc_dummy_audio_source_impl.h" +#include "interop_api.h" + +using namespace libwebrtc; + +rtcResultU4 LIB_WEBRTC_CALL +RTCDummyAudioSource_RegisterAudioDataObserver( + rtcDummyAudioSourceHandle handle, + rtcDummyAudioSourceObserverCallbacks* callbacks +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(callbacks, rtcResultU4::kInvalidParameter); + + // unregistered + RTCDummyAudioSource_DeRegisterAudioDataObserver(handle); + + scoped_refptr p = static_cast(handle); + DummyAudioSourceObserver* pObserver = static_cast( + new DummyAudioSourceObserverImpl(static_cast(callbacks)) + ); + p->RegisterAudioDataObserver(pObserver); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDummyAudioSource_DeRegisterAudioDataObserver( + rtcDummyAudioSourceHandle handle +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr p = static_cast(handle); + DummyAudioSourceObserverImpl* pObserverImpl = static_cast(p->GetObserver()); + p->DeRegisterAudioDataObserver(); + if (pObserverImpl) { + delete pObserverImpl; + } + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDummyAudioSource_GetBitsPerSample( + rtcDummyAudioSourceHandle handle, + int* pRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pRetVal, int, RTCDummyAudioSource, bits_per_sample); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDummyAudioSource_GetSampleRateHz( + rtcDummyAudioSourceHandle handle, + int* pRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pRetVal, int, RTCDummyAudioSource, sample_rate_hz); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDummyAudioSource_GetNumChannels( + rtcDummyAudioSourceHandle handle, + int* pRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pRetVal, int, RTCDummyAudioSource, number_of_channels); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDummyAudioSource_GetSamplesPerChannel( + rtcDummyAudioSourceHandle handle, + int* pRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pRetVal, int, RTCDummyAudioSource, number_of_frames); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDummyAudioSource_Start( + rtcDummyAudioSourceHandle handle, + rtcCaptureState* pRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pRetVal, rtcCaptureState, RTCDummyAudioSource, Start); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDummyAudioSource_Stop( + rtcDummyAudioSourceHandle handle +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + scoped_refptr p = static_cast(handle); + p->Stop(); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDummyAudioSource_GetCaptureState( + rtcDummyAudioSourceHandle handle, + rtcCaptureState* pRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pRetVal, rtcCaptureState, RTCDummyAudioSource, CaptureState); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDummyAudioSource_IsRunning( + rtcDummyAudioSourceHandle handle, + rtcBool32* pRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pRetVal, rtcBool32, RTCDummyAudioSource, IsRunning); +} \ No newline at end of file diff --git a/src/interop/rtc_peerconnection_factory_interop.cc b/src/interop/rtc_peerconnection_factory_interop.cc index e74f1a69c8..8c06349bc5 100644 --- a/src/interop/rtc_peerconnection_factory_interop.cc +++ b/src/interop/rtc_peerconnection_factory_interop.cc @@ -179,6 +179,32 @@ RTCPeerConnectionFactory_CreateAudioSource( return rtcResultU4::kSuccess; } // end RTCPeerConnectionFactory_CreateAudioSource +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_CreateDummyAudioSource( + rtcPeerConnectionFactoryHandle factory, + const char* audio_source_label, + int sample_rate_hz, + unsigned int num_channels, + rtcDummyAudioSourceHandle* pRetVal +) noexcept +{ + CHECK_OUT_POINTER(pRetVal); + CHECK_NATIVE_HANDLE(factory); + + scoped_refptr pFactory = static_cast(factory); + if (!pFactory->GetUseDummyAudio()) { + return rtcResultU4::kDummyAudioSourceNotSupported; + } + scoped_refptr audio_source = pFactory->CreateDummyAudioSource( + string(audio_source_label), + sample_rate_hz, + static_cast(num_channels) + ); + + *pRetVal = static_cast(audio_source.release()); + return rtcResultU4::kSuccess; +} // end RTCPeerConnectionFactory_CreateDummyAudioSource + rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_CreateVideoSource( rtcPeerConnectionFactoryHandle factory, @@ -290,6 +316,29 @@ RTCPeerConnectionFactory_CreateAudioTrack( return rtcResultU4::kSuccess; } // end RTCPeerConnectionFactory_CreateAudioTrack +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_CreateDummyAudioTrack( + rtcPeerConnectionFactoryHandle factory, + rtcDummyAudioSourceHandle source, + const char* track_id, + rtcAudioTrackHandle* pRetVal +) noexcept +{ + CHECK_OUT_POINTER(pRetVal); + CHECK_NATIVE_HANDLE(factory); + CHECK_POINTER_EX(source, rtcResultU4::kInvalidParameter); + + scoped_refptr pFactory = static_cast(factory); + if (!pFactory->GetUseDummyAudio()) { + return rtcResultU4::kDummyAudioSourceNotSupported; + } + scoped_refptr audio_source = static_cast(source); + scoped_refptr audio_track = pFactory->CreateAudioTrack(audio_source, string(track_id)); + + *pRetVal = static_cast(audio_track.release()); + return rtcResultU4::kSuccess; +} // end RTCPeerConnectionFactory_CreateAudioTrack + rtcResultU4 LIB_WEBRTC_CALL RTCPeerConnectionFactory_CreateVideoTrack( rtcPeerConnectionFactoryHandle factory, @@ -360,3 +409,12 @@ RTCPeerConnectionFactory_GetRtpReceiverCapabilities( *pRetVal = static_cast(rtp_capabilities.release()); return rtcResultU4::kSuccess; } // end RTCPeerConnectionFactory_GetRtpReceiverCapabilities + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_GetUseDummyAudio( + rtcPeerConnectionFactoryHandle factory, + rtcBool32* pRetVal +) noexcept +{ + DECLARE_GET_VALUE(factory, pRetVal, rtcBool32, RTCPeerConnectionFactory, GetUseDummyAudio); +} diff --git a/src/rtc_audio_data_impl.cc b/src/rtc_audio_data_impl.cc index b59c392965..b5db929876 100644 --- a/src/rtc_audio_data_impl.cc +++ b/src/rtc_audio_data_impl.cc @@ -4,7 +4,6 @@ namespace libwebrtc { -double RTC_FREQUENCY = 1000.0; // Hertz double RTC_PI = 3.14159265358979323846; /** @@ -12,6 +11,7 @@ double RTC_PI = 3.14159265358979323846; */ scoped_refptr RTCAudioData::Create( + uint32_t index, const uint8_t* data, uint32_t bits_per_sample, int sample_rate_hz, @@ -20,6 +20,7 @@ scoped_refptr RTCAudioData::Create( scoped_refptr audio_data = scoped_refptr( new RefCountedObject( + index, data, bits_per_sample, sample_rate_hz, @@ -31,6 +32,7 @@ scoped_refptr RTCAudioData::Create( scoped_refptr RTCAudioData::Create() { return RTCAudioData::Create( + 0, // index nullptr, // data 16, // 16 bits 44100, // sample_rate in Hz @@ -43,11 +45,13 @@ scoped_refptr RTCAudioData::Create() { */ RTCAudioDataImpl::RTCAudioDataImpl( + uint32_t index, const uint8_t* data, uint32_t bits_per_sample, int sample_rate_hz, uint32_t num_channels -) : bits_per_sample_(bits_per_sample) +) : index_(index) + , bits_per_sample_(bits_per_sample) , samples_per_channel_(sample_rate_hz / 100) // for 10 ms chunk , sample_rate_hz_(sample_rate_hz) , num_channels_(num_channels) @@ -114,17 +118,19 @@ int RTCAudioDataImpl::ScaleFrom(scoped_refptr src) { return static_cast(result); } -int RTCAudioDataImpl::Clear(bool fill_1khz_tone /* = false */) { +int RTCAudioDataImpl::Clear(RTCAudioDataToneFrequency frequency /*= RTCAudioDataToneFrequency::kNone*/) { if (data_size_ == 0) { return 0; } - if (fill_1khz_tone) { + if (frequency != RTCAudioDataToneFrequency::kNone) { + double freq = static_cast(frequency); + size_t first_time = static_cast(index_) * static_cast(samples_per_channel_); if (16 == bits_per_sample_) { int16_t* pDest = reinterpret_cast(data_.get()); for (size_t i = 0; i < samples_per_channel_; ++i) { - double time = static_cast(i) / sample_rate_hz_; - int16_t sample = static_cast(32767 * sin(2 * RTC_PI * RTC_FREQUENCY * time)); + double time = static_cast(first_time + i) / sample_rate_hz_; + int16_t sample = static_cast(32767 * sin(2 * RTC_PI * freq * time)); for (size_t ch = 0; ch < num_channels_; ++ch) { pDest[i * num_channels_ + ch] = sample; } @@ -133,8 +139,8 @@ int RTCAudioDataImpl::Clear(bool fill_1khz_tone /* = false */) { else if (24 == bits_per_sample_) { int32_t* pDest = reinterpret_cast(data_.get()); for (size_t i = 0; i < samples_per_channel_; ++i) { - double time = static_cast(i) / sample_rate_hz_; - int32_t sample = static_cast(8388607 * sin(2 * RTC_PI * RTC_FREQUENCY * time)); + double time = static_cast(first_time + i) / sample_rate_hz_; + int32_t sample = static_cast(8388607 * sin(2 * RTC_PI * freq * time)); for (size_t ch = 0; ch < num_channels_; ++ch) { uint8_t* pByteDest = reinterpret_cast(pDest) + (i * num_channels_ + ch) * 3; pByteDest[2] = static_cast((sample >> 16) & 0xFF); @@ -146,8 +152,8 @@ int RTCAudioDataImpl::Clear(bool fill_1khz_tone /* = false */) { else if (32 == bits_per_sample_) { int32_t* pDest = reinterpret_cast(data_.get()); for (size_t i = 0; i < samples_per_channel_; ++i) { - double time = static_cast(i) / sample_rate_hz_; - int32_t sample = static_cast(2147483647 * sin(2 * RTC_PI * RTC_FREQUENCY * time)); + double time = static_cast(first_time + i) / sample_rate_hz_; + int32_t sample = static_cast(2147483647 * sin(2 * RTC_PI * freq * time)); for (size_t ch = 0; ch < num_channels_; ++ch) { pDest[i * num_channels_ + ch] = sample; } diff --git a/src/rtc_audio_data_impl.h b/src/rtc_audio_data_impl.h index 8328054be8..0401aca543 100644 --- a/src/rtc_audio_data_impl.h +++ b/src/rtc_audio_data_impl.h @@ -12,6 +12,7 @@ namespace libwebrtc { class RTCAudioDataImpl : public RTCAudioData { public: RTCAudioDataImpl( + uint32_t index, const uint8_t* data, uint32_t bits_per_sample, int sample_rate_hz, @@ -20,6 +21,7 @@ class RTCAudioDataImpl : public RTCAudioData { virtual ~RTCAudioDataImpl(); public: + uint32_t index() const override { return index_; } const uint8_t* data() const override { return data_.get(); } size_t data_size() const override { return data_size_; } uint32_t bits_per_sample() const override { return bits_per_sample_; } @@ -29,9 +31,10 @@ class RTCAudioDataImpl : public RTCAudioData { int ScaleFrom(scoped_refptr src) override; - int Clear(bool fill_1khz_tone = false) override; + int Clear(RTCAudioDataToneFrequency frequency = RTCAudioDataToneFrequency::kNone) override; private: + uint32_t index_; uint32_t bits_per_sample_; uint32_t samples_per_channel_; int sample_rate_hz_; diff --git a/src/rtc_peerconnection_factory_impl.cc b/src/rtc_peerconnection_factory_impl.cc index 956c0c358c..6a4471059b 100644 --- a/src/rtc_peerconnection_factory_impl.cc +++ b/src/rtc_peerconnection_factory_impl.cc @@ -175,6 +175,10 @@ scoped_refptr RTCPeerConnectionFactoryImpl::CreateDummyAudi uint32_t num_channels /*= 2*/ ) { + if (!use_dummy_audio_) { + return nullptr; + } + rtc::scoped_refptr rtc_source_track = rtc::scoped_refptr( new rtc::RefCountedObject( @@ -182,7 +186,8 @@ scoped_refptr RTCPeerConnectionFactoryImpl::CreateDummyAudi signaling_thread_.get(), 16, /* bits_per_sample */ sample_rate_hz, - num_channels + num_channels, + audio_source_label.std_string() ) ); @@ -359,6 +364,11 @@ scoped_refptr RTCPeerConnectionFactoryImpl::CreateAudioTrack( scoped_refptr RTCPeerConnectionFactoryImpl::CreateAudioTrack( scoped_refptr source, const string track_id) { + + if (!use_dummy_audio_) { + return nullptr; + } + RTCDummyAudioSourceImpl* source_impl = static_cast(source.get()); diff --git a/src/rtc_peerconnection_factory_impl.h b/src/rtc_peerconnection_factory_impl.h index d185019bcf..14b8b3a34c 100644 --- a/src/rtc_peerconnection_factory_impl.h +++ b/src/rtc_peerconnection_factory_impl.h @@ -76,6 +76,8 @@ class RTCPeerConnectionFactoryImpl : public RTCPeerConnectionFactory { virtual scoped_refptr CreateStream( const string stream_id) override; + virtual bool GetUseDummyAudio() override { return use_dummy_audio_; } + rtc::scoped_refptr peer_connection_factory() { return rtc_peerconnection_factory_; From c1492a28b166f46cc16b12952a643983349ce23e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Thu, 30 Jan 2025 19:52:06 +0300 Subject: [PATCH 63/69] Added Clear method for RTCVideoFrame --- include/interop_api.h | 14 ++++ include/rtc_types.h | 6 ++ include/rtc_video_frame.h | 3 + src/interop/rtc_video_frame_interop.cc | 29 +++++++++ src/rtc_video_frame_impl.cc | 90 +++++++++++++++++++++++++- src/rtc_video_frame_impl.h | 8 +-- 6 files changed, 142 insertions(+), 8 deletions(-) diff --git a/include/interop_api.h b/include/interop_api.h index 45b84ece3e..afea04634e 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -26,6 +26,7 @@ using rtcMediaType = libwebrtc::RTCMediaType; using rtcDesktopType = libwebrtc::DesktopType; using rtcCaptureState = libwebrtc::RTCCaptureState; using rtcAudioDataToneFrequency = libwebrtc::RTCAudioDataToneFrequency; +using rtcVideoFrameClearType = libwebrtc::RTCVideoFrameClearType; /// 64-bit timestamp for interop API. using rtcTimestamp = long long; @@ -1559,6 +1560,12 @@ RTCVideoFrame_GetHeight( int* pOutRetVal ) noexcept; +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_GetSize( + rtcVideoFrameHandle handle, + int* pOutRetVal +) noexcept; + LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCVideoFrame_GetDataY( rtcVideoFrameHandle handle, @@ -1681,6 +1688,13 @@ RTCVideoFrame_ScaleFrom2( int* pOutRetVal ) noexcept; +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_Clear( + rtcVideoFrameHandle handle, + rtcVideoFrameClearType clearType, + int* pRetVal +) noexcept; + /* * ---------------------------------------------------------------------- * RTCVideoRenderer interop methods diff --git a/include/rtc_types.h b/include/rtc_types.h index a1e882ba91..f7e38a5275 100644 --- a/include/rtc_types.h +++ b/include/rtc_types.h @@ -41,6 +41,12 @@ enum class RTCAudioDataToneFrequency { kTone5kHz = 5000 }; +enum class RTCVideoFrameClearType { + kNone = 0, // Clear video buffer + kNoise, + kColorBar +}; + using string = portable::string; // template diff --git a/include/rtc_video_frame.h b/include/rtc_video_frame.h index 217ccc563b..15202ded38 100644 --- a/include/rtc_video_frame.h +++ b/include/rtc_video_frame.h @@ -33,6 +33,7 @@ class RTCVideoFrame : public RefCountInterface { // subsampled, this is the highest-resolution plane. virtual int width() const = 0; virtual int height() const = 0; + virtual int size() const = 0; virtual VideoRotation rotation() = 0; @@ -64,6 +65,8 @@ class RTCVideoFrame : public RefCountInterface { int src_height ) = 0; + virtual int Clear(RTCVideoFrameClearType clearType) = 0; + protected: virtual ~RTCVideoFrame() {} }; diff --git a/src/interop/rtc_video_frame_interop.cc b/src/interop/rtc_video_frame_interop.cc index 665987a2d5..4db03be385 100644 --- a/src/interop/rtc_video_frame_interop.cc +++ b/src/interop/rtc_video_frame_interop.cc @@ -135,6 +135,15 @@ RTCVideoFrame_GetHeight( DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCVideoFrame, height); } +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_GetSize( + rtcVideoFrameHandle handle, + int* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCVideoFrame, size); +} + rtcResultU4 LIB_WEBRTC_CALL RTCVideoFrame_GetDataY( rtcVideoFrameHandle handle, @@ -335,3 +344,23 @@ RTCVideoFrame_ScaleFrom2( } return rtcResultU4::kSuccess; } + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_Clear( + rtcVideoFrameHandle handle, + rtcVideoFrameClearType clearType, + int* pRetVal +) noexcept +{ + if (pRetVal) { + *pRetVal = 0; + } + CHECK_NATIVE_HANDLE(handle); + + scoped_refptr p = static_cast(handle); + int result = p->Clear(static_cast(clearType)); + if (pRetVal) { + *pRetVal = result; + } + return rtcResultU4::kSuccess; +} diff --git a/src/rtc_video_frame_impl.cc b/src/rtc_video_frame_impl.cc index 79a7aee806..5b65da660a 100644 --- a/src/rtc_video_frame_impl.cc +++ b/src/rtc_video_frame_impl.cc @@ -31,6 +31,11 @@ int VideoFrameBufferImpl::width() const { return buffer_->width(); } int VideoFrameBufferImpl::height() const { return buffer_->height(); } +int VideoFrameBufferImpl::size() const { + int buffer_size = (StrideY() * height()) + (StrideU() * (height() / 2)) + (StrideV() * (height() / 2)); + return buffer_size; +} + const uint8_t* VideoFrameBufferImpl::DataY() const { return buffer_->GetI420()->DataY(); } @@ -65,6 +70,7 @@ int VideoFrameBufferImpl::ConvertToARGB(Type type, uint8_t* dst_buffer, webrtc::I420Buffer::Create(dest_width, dest_height); dest->ScaleFrom(*i420.get()); + // ARGB buffer size int buf_size = dest->width() * dest->height() * (32 >> 3); switch (type) { case libwebrtc::RTCVideoFrame::Type::kARGB: @@ -119,8 +125,7 @@ int VideoFrameBufferImpl::ScaleFrom(scoped_refptr source) i420->ScaleFrom(*i420_source.get()); buffer_ = i420; - int buffer_size = (StrideY() * height()) + (StrideU() * (height() / 2)) + (StrideV() * (height() / 2)); - return buffer_size; + return size(); } int VideoFrameBufferImpl::ScaleFrom( @@ -172,7 +177,86 @@ int VideoFrameBufferImpl::ScaleFrom( i420_dst->ScaleFrom(*i420_src.get()); buffer_ = i420_dst; - int buffer_size = (StrideY() * height()) + (StrideU() * (height() / 2)) + (StrideV() * (height() / 2)); + return size(); +} + +int VideoFrameBufferImpl::Clear(RTCVideoFrameClearType clearType) { + int buffer_size = size(); + if (buffer_size <= 0) { + return 0; + } + + switch (clearType) + { + case RTCVideoFrameClearType::kNoise: + { + const int noiseLevel = 50; + const int height = buffer_->height(); + uint8_t* mutableDataY = const_cast(DataY()); + uint8_t* mutableDataU = const_cast(DataU()); + uint8_t* mutableDataV = const_cast(DataV()); + const int countY = StrideY() * height; + const int countU = StrideU() * height / 2; + const int countV = StrideV() * height / 2; + + for (int i = 0; i < countY; i++) { + mutableDataY[i] = static_cast((rand() % (256 - noiseLevel)) + noiseLevel); + } + memset(mutableDataU, 128, countU); + memset(mutableDataV, 128, countV); + } + break; + case RTCVideoFrameClearType::kColorBar: + { + const int width = buffer_->width(); + const int height = buffer_->height(); + const int blockWidth = width/ 8; + uint8_t* mutableDataY = const_cast(DataY()); + uint8_t* mutableDataU = const_cast(DataU()); + uint8_t* mutableDataV = const_cast(DataV()); + const int strideY = StrideY(); + const int strideU = StrideU(); + const int strideV = StrideV(); + + // Colorbar colors + // Colors: White, Yellow, Cyan, Green, Magenta, Red, Blue, Black + const uint8_t colorBarY[8] = {235, 214, 183, 162, 88, 73, 36, 0}; + const uint8_t colorBarU[8] = {128, 38, 157, 65, 188, 95, 218, 128}; + const uint8_t colorBarV[8] = {128, 142, 39, 54, 203, 226, 114, 128}; + + for (int i = 0; i < 8; ++i) { + for (int y = 0; y < height; ++y) { + for (int x = i * blockWidth; x < (i + 1) * blockWidth; ++x) { + mutableDataY[y * strideY + x] = colorBarY[i]; + } + } + } + + for (int i = 0; i < 8; ++i) { + for (int y = 0; y < height / 2; ++y) { + for (int x = i * blockWidth / 2; x < (i + 1) * blockWidth / 2; ++x) { + mutableDataU[(y * strideU) + x] = colorBarU[i]; + mutableDataV[(y * strideV) + x] = colorBarV[i]; + } + } + } + } + break; + default: // Clear + { + const int height = buffer_->height(); + uint8_t* mutableDataY = const_cast(DataY()); + uint8_t* mutableDataU = const_cast(DataU()); + uint8_t* mutableDataV = const_cast(DataV()); + const int countY = StrideY() * height; + const int countU = StrideU() * height / 2; + const int countV = StrideV() * height / 2; + memset(mutableDataY, 0, countY); + memset(mutableDataU, 128, countU); + memset(mutableDataV, 128, countV); + } + break; + } return buffer_size; } diff --git a/src/rtc_video_frame_impl.h b/src/rtc_video_frame_impl.h index 2b19fd2557..a20b731fa8 100644 --- a/src/rtc_video_frame_impl.h +++ b/src/rtc_video_frame_impl.h @@ -21,19 +21,15 @@ class VideoFrameBufferImpl : public RTCVideoFrame { public: int width() const override; - int height() const override; + int size() const override; const uint8_t* DataY() const override; - const uint8_t* DataU() const override; - const uint8_t* DataV() const override; int StrideY() const override; - int StrideU() const override; - int StrideV() const override; int ConvertToARGB(Type type, uint8_t* dst_argb, int dst_stride_argb, @@ -49,6 +45,8 @@ class VideoFrameBufferImpl : public RTCVideoFrame { int src_height ) override; + int Clear(RTCVideoFrameClearType clearType) override; + rtc::scoped_refptr buffer() { return buffer_; } // System monotonic clock, same timebase as rtc::TimeMicros(). From 3480a48f6c1e2ddd53236482c13402ed6e3f21db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Tue, 4 Feb 2025 13:27:43 +0300 Subject: [PATCH 64/69] Added set_index to RTCAudioData --- include/interop_api.h | 6 ++++++ include/rtc_audio_data.h | 1 + src/interop/rtc_audio_data_interop.cc | 9 +++++++++ src/rtc_audio_data_impl.h | 1 + 4 files changed, 17 insertions(+) diff --git a/include/interop_api.h b/include/interop_api.h index afea04634e..bd491cb683 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -1082,6 +1082,12 @@ RTCAudioData_GetIndex( unsigned int* pRetVal ) noexcept; +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCAudioData_SetIndex( + rtcAudioDataHandle handle, + unsigned int index +) noexcept; + LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCAudioData_GetData( rtcAudioDataHandle handle, diff --git a/include/rtc_audio_data.h b/include/rtc_audio_data.h index 24958aa604..97cd089b2b 100644 --- a/include/rtc_audio_data.h +++ b/include/rtc_audio_data.h @@ -19,6 +19,7 @@ class RTCAudioData : public RefCountInterface { public: virtual uint32_t index() const = 0; + virtual void set_index(uint32_t index) = 0; virtual const uint8_t* data() const = 0; virtual size_t data_size() const = 0; virtual uint32_t bits_per_sample() const = 0; diff --git a/src/interop/rtc_audio_data_interop.cc b/src/interop/rtc_audio_data_interop.cc index 8e919f1e3d..e28b49b3c7 100644 --- a/src/interop/rtc_audio_data_interop.cc +++ b/src/interop/rtc_audio_data_interop.cc @@ -35,6 +35,15 @@ RTCAudioData_GetIndex( DECLARE_GET_VALUE(handle, pRetVal, unsigned int, RTCAudioData, index); } +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioData_SetIndex( + rtcAudioDataHandle handle, + unsigned int index +) noexcept +{ + DECLARE_SET_VALUE(handle, index, uint32_t, RTCAudioData, set_index); +} + rtcResultU4 LIB_WEBRTC_CALL RTCAudioData_GetData( rtcAudioDataHandle handle, diff --git a/src/rtc_audio_data_impl.h b/src/rtc_audio_data_impl.h index 0401aca543..91998a1cc9 100644 --- a/src/rtc_audio_data_impl.h +++ b/src/rtc_audio_data_impl.h @@ -22,6 +22,7 @@ class RTCAudioDataImpl : public RTCAudioData { public: uint32_t index() const override { return index_; } + void set_index(uint32_t index) override { index_ = index; } const uint8_t* data() const override { return data_.get(); } size_t data_size() const override { return data_size_; } uint32_t bits_per_sample() const override { return bits_per_sample_; } From 0e1d96edd444a3b064e9510034a363fc66ff4816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Sat, 8 Feb 2025 13:47:44 +0300 Subject: [PATCH 65/69] Dummy Video Capturer frame buffer optimization --- include/rtc_audio_data.h | 6 ++++++ include/rtc_dummy_audio_source.h | 6 ++++++ include/rtc_dummy_video_capturer.h | 6 ++++++ include/rtc_video_frame.h | 6 ++++++ src/internal/audio_util.cc | 6 ++++++ src/internal/audio_util.h | 6 ++++++ src/internal/dummy_audio_capturer.cc | 6 ++++++ src/internal/dummy_audio_capturer.h | 6 ++++++ src/internal/dummy_capturer.cc | 6 ++++++ src/internal/dummy_capturer.h | 6 ++++++ src/interop/libwebrtc_interop.cc | 6 ++++++ src/interop/ref_counted_object_interop.cc | 6 ++++++ src/interop/rtc_audio_data_interop.cc | 6 ++++++ src/interop/rtc_audio_device_interop.cc | 6 ++++++ src/interop/rtc_audio_track_interop.cc | 6 ++++++ src/interop/rtc_data_channel_interop.cc | 6 ++++++ src/interop/rtc_desktop_capturer_interop.cc | 6 ++++++ src/interop/rtc_desktop_device_interop.cc | 6 ++++++ src/interop/rtc_desktop_media_list_interop.cc | 6 ++++++ src/interop/rtc_dtls_transport_interop.cc | 6 ++++++ src/interop/rtc_dtmf_sender_interop.cc | 6 ++++++ src/interop/rtc_dummy_audio_source_interop.cc | 6 ++++++ src/interop/rtc_dummy_video_capturer_interop.cc | 6 ++++++ src/interop/rtc_ice_candidate_interop.cc | 6 ++++++ src/interop/rtc_media_stream_interop.cc | 6 ++++++ src/interop/rtc_media_track_interop.cc | 6 ++++++ src/interop/rtc_mediaconstraints_interop.cc | 6 ++++++ .../rtc_peerconnection_factory_interop.cc | 6 ++++++ src/interop/rtc_peerconnection_interop.cc | 6 ++++++ src/interop/rtc_rtp_capabilities_interop.cc | 6 ++++++ src/interop/rtc_rtp_parameters_interop.cc | 6 ++++++ src/interop/rtc_rtp_receiver_interop.cc | 6 ++++++ src/interop/rtc_rtp_sender_interop.cc | 6 ++++++ src/interop/rtc_rtp_transceiver_interop.cc | 6 ++++++ src/interop/rtc_sdp_parse_error_interop.cc | 6 ++++++ src/interop/rtc_video_device_interop.cc | 6 ++++++ src/interop/rtc_video_frame_interop.cc | 6 ++++++ src/interop/rtc_video_renderer_interop.cc | 6 ++++++ src/interop/rtc_video_track_interop.cc | 6 ++++++ src/rtc_audio_data_impl.cc | 6 ++++++ src/rtc_audio_data_impl.h | 6 ++++++ src/rtc_dummy_audio_source_impl.cc | 8 +++++++- src/rtc_dummy_audio_source_impl.h | 6 ++++++ src/rtc_dummy_video_capturer_impl.cc | 16 ++++++++++++---- src/rtc_dummy_video_capturer_impl.h | 7 +++++++ src/rtc_peerconnection_factory_impl.h | 2 +- src/rtc_video_frame_impl.cc | 6 ++++++ src/rtc_video_frame_impl.h | 6 ++++++ 48 files changed, 291 insertions(+), 6 deletions(-) diff --git a/include/rtc_audio_data.h b/include/rtc_audio_data.h index 97cd089b2b..fb10c7b8c9 100644 --- a/include/rtc_audio_data.h +++ b/include/rtc_audio_data.h @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #ifndef LIB_WEBRTC_RTC_AUDIO_DATA_HXX #define LIB_WEBRTC_RTC_AUDIO_DATA_HXX diff --git a/include/rtc_dummy_audio_source.h b/include/rtc_dummy_audio_source.h index 606dadd6df..0e3870bbcf 100644 --- a/include/rtc_dummy_audio_source.h +++ b/include/rtc_dummy_audio_source.h @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #ifndef LIB_WEBRTC_RTC_DUMMY_AUDIO_SOURCE_HXX #define LIB_WEBRTC_RTC_DUMMY_AUDIO_SOURCE_HXX diff --git a/include/rtc_dummy_video_capturer.h b/include/rtc_dummy_video_capturer.h index 8e9c9d48ef..ae56268262 100644 --- a/include/rtc_dummy_video_capturer.h +++ b/include/rtc_dummy_video_capturer.h @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #ifndef LIB_WEBRTC_RTC_DUMMY_VIDEO_CAPTURER_HXX #define LIB_WEBRTC_RTC_DUMMY_VIDEO_CAPTURER_HXX diff --git a/include/rtc_video_frame.h b/include/rtc_video_frame.h index 15202ded38..d3b1cca18c 100644 --- a/include/rtc_video_frame.h +++ b/include/rtc_video_frame.h @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #ifndef LIB_WEBRTC_RTC_VIDEO_FRAME_HXX #define LIB_WEBRTC_RTC_VIDEO_FRAME_HXX diff --git a/src/internal/audio_util.cc b/src/internal/audio_util.cc index 0acdaf866a..a931aef876 100644 --- a/src/internal/audio_util.cc +++ b/src/internal/audio_util.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "audio_util.h" #include "rtc_types.h" diff --git a/src/internal/audio_util.h b/src/internal/audio_util.h index 799fe2e527..ec5341997d 100644 --- a/src/internal/audio_util.h +++ b/src/internal/audio_util.h @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #ifndef LIB_WEBRTC_AUDIO_UTIL_HXX #define LIB_WEBRTC_AUDIO_UTIL_HXX diff --git a/src/internal/dummy_audio_capturer.cc b/src/internal/dummy_audio_capturer.cc index dec7335886..19d1e5fcba 100644 --- a/src/internal/dummy_audio_capturer.cc +++ b/src/internal/dummy_audio_capturer.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "src/internal/dummy_audio_capturer.h" #include "rtc_base/logging.h" diff --git a/src/internal/dummy_audio_capturer.h b/src/internal/dummy_audio_capturer.h index 3455157963..b31969041a 100644 --- a/src/internal/dummy_audio_capturer.h +++ b/src/internal/dummy_audio_capturer.h @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #ifndef INTERNAL_DUMMY_AUDIO_CAPTURER_H_ #define INTERNAL_DUMMY_AUDIO_CAPTURER_H_ diff --git a/src/internal/dummy_capturer.cc b/src/internal/dummy_capturer.cc index 7344ac5617..64fd595385 100644 --- a/src/internal/dummy_capturer.cc +++ b/src/internal/dummy_capturer.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "src/internal/dummy_capturer.h" namespace libwebrtc {} // namespace libwebrtc \ No newline at end of file diff --git a/src/internal/dummy_capturer.h b/src/internal/dummy_capturer.h index da170b30e9..ce830c4160 100644 --- a/src/internal/dummy_capturer.h +++ b/src/internal/dummy_capturer.h @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #ifndef LIB_WEBRTC_DUMMY_CAPTURER_IMPL_HXX #define LIB_WEBRTC_DUMMY_CAPTURER_IMPL_HXX diff --git a/src/interop/libwebrtc_interop.cc b/src/interop/libwebrtc_interop.cc index e329b42eeb..413617c230 100644 --- a/src/interop/libwebrtc_interop.cc +++ b/src/interop/libwebrtc_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "interop_api.h" #include "rtc_peerconnection_factory.h" #include "libwebrtc.h" diff --git a/src/interop/ref_counted_object_interop.cc b/src/interop/ref_counted_object_interop.cc index 16a2cc3924..d15b5c20bf 100644 --- a/src/interop/ref_counted_object_interop.cc +++ b/src/interop/ref_counted_object_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "interop_api.h" using namespace libwebrtc; diff --git a/src/interop/rtc_audio_data_interop.cc b/src/interop/rtc_audio_data_interop.cc index e28b49b3c7..f235157cb8 100644 --- a/src/interop/rtc_audio_data_interop.cc +++ b/src/interop/rtc_audio_data_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_audio_data.h" #include "interop_api.h" diff --git a/src/interop/rtc_audio_device_interop.cc b/src/interop/rtc_audio_device_interop.cc index 3ad59afc85..cfe7e31945 100644 --- a/src/interop/rtc_audio_device_interop.cc +++ b/src/interop/rtc_audio_device_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_audio_device.h" #include "interop_api.h" diff --git a/src/interop/rtc_audio_track_interop.cc b/src/interop/rtc_audio_track_interop.cc index b954cf6fab..8776ef68c5 100644 --- a/src/interop/rtc_audio_track_interop.cc +++ b/src/interop/rtc_audio_track_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_audio_track.h" #include "interop_api.h" diff --git a/src/interop/rtc_data_channel_interop.cc b/src/interop/rtc_data_channel_interop.cc index 9b923ce775..69e2ffc304 100644 --- a/src/interop/rtc_data_channel_interop.cc +++ b/src/interop/rtc_data_channel_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_data_channel.h" #include "interop_api.h" #include "src/rtc_data_channel_impl.h" diff --git a/src/interop/rtc_desktop_capturer_interop.cc b/src/interop/rtc_desktop_capturer_interop.cc index e685b28381..c6a5ed2763 100644 --- a/src/interop/rtc_desktop_capturer_interop.cc +++ b/src/interop/rtc_desktop_capturer_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_desktop_capturer.h" #include "src/rtc_desktop_capturer_impl.h" #include "interop_api.h" diff --git a/src/interop/rtc_desktop_device_interop.cc b/src/interop/rtc_desktop_device_interop.cc index 9319a0736e..989caff33c 100644 --- a/src/interop/rtc_desktop_device_interop.cc +++ b/src/interop/rtc_desktop_device_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_desktop_media_list.h" #include "rtc_desktop_capturer.h" #include "rtc_desktop_device.h" diff --git a/src/interop/rtc_desktop_media_list_interop.cc b/src/interop/rtc_desktop_media_list_interop.cc index 0a60c9d11b..0909c1b942 100644 --- a/src/interop/rtc_desktop_media_list_interop.cc +++ b/src/interop/rtc_desktop_media_list_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_desktop_media_list.h" #include "interop_api.h" #include "src/rtc_desktop_media_list_impl.h" diff --git a/src/interop/rtc_dtls_transport_interop.cc b/src/interop/rtc_dtls_transport_interop.cc index 362ed2ce06..6574ea3771 100644 --- a/src/interop/rtc_dtls_transport_interop.cc +++ b/src/interop/rtc_dtls_transport_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_dtls_transport.h" #include "src/rtc_dtls_transport_impl.h" #include "interop_api.h" diff --git a/src/interop/rtc_dtmf_sender_interop.cc b/src/interop/rtc_dtmf_sender_interop.cc index df4943bd4d..e841c050cb 100644 --- a/src/interop/rtc_dtmf_sender_interop.cc +++ b/src/interop/rtc_dtmf_sender_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_dtmf_sender.h" #include "src/rtc_dtmf_sender_impl.h" #include "interop_api.h" diff --git a/src/interop/rtc_dummy_audio_source_interop.cc b/src/interop/rtc_dummy_audio_source_interop.cc index db76f2abc7..ecc10dd3c7 100644 --- a/src/interop/rtc_dummy_audio_source_interop.cc +++ b/src/interop/rtc_dummy_audio_source_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "src/rtc_dummy_audio_source_impl.h" #include "interop_api.h" diff --git a/src/interop/rtc_dummy_video_capturer_interop.cc b/src/interop/rtc_dummy_video_capturer_interop.cc index 1d83101edb..8071c26f6d 100644 --- a/src/interop/rtc_dummy_video_capturer_interop.cc +++ b/src/interop/rtc_dummy_video_capturer_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "src/rtc_dummy_video_capturer_impl.h" #include "interop_api.h" diff --git a/src/interop/rtc_ice_candidate_interop.cc b/src/interop/rtc_ice_candidate_interop.cc index 70711e232c..92417aa303 100644 --- a/src/interop/rtc_ice_candidate_interop.cc +++ b/src/interop/rtc_ice_candidate_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_ice_candidate.h" #include "rtc_sdp_parse_error.h" #include "interop_api.h" diff --git a/src/interop/rtc_media_stream_interop.cc b/src/interop/rtc_media_stream_interop.cc index 692173ad49..6318f4982b 100644 --- a/src/interop/rtc_media_stream_interop.cc +++ b/src/interop/rtc_media_stream_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_media_stream.h" #include "interop_api.h" diff --git a/src/interop/rtc_media_track_interop.cc b/src/interop/rtc_media_track_interop.cc index c60af0cefe..d21571b0e8 100644 --- a/src/interop/rtc_media_track_interop.cc +++ b/src/interop/rtc_media_track_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_media_track.h" #include "interop_api.h" diff --git a/src/interop/rtc_mediaconstraints_interop.cc b/src/interop/rtc_mediaconstraints_interop.cc index 8e6965823a..1ebc81173d 100644 --- a/src/interop/rtc_mediaconstraints_interop.cc +++ b/src/interop/rtc_mediaconstraints_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_mediaconstraints.h" #include "src/rtc_mediaconstraints_impl.h" #include "interop_api.h" diff --git a/src/interop/rtc_peerconnection_factory_interop.cc b/src/interop/rtc_peerconnection_factory_interop.cc index 8c06349bc5..2d3376c343 100644 --- a/src/interop/rtc_peerconnection_factory_interop.cc +++ b/src/interop/rtc_peerconnection_factory_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "src/rtc_mediaconstraints_impl.h" #include "src/rtc_peerconnection_factory_impl.h" diff --git a/src/interop/rtc_peerconnection_interop.cc b/src/interop/rtc_peerconnection_interop.cc index 08d6c11356..2dd3a1bf0c 100644 --- a/src/interop/rtc_peerconnection_interop.cc +++ b/src/interop/rtc_peerconnection_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_peerconnection.h" #include "src/rtc_peerconnection_impl.h" #include "interop_api.h" diff --git a/src/interop/rtc_rtp_capabilities_interop.cc b/src/interop/rtc_rtp_capabilities_interop.cc index b65a30dad6..fd29e1708b 100644 --- a/src/interop/rtc_rtp_capabilities_interop.cc +++ b/src/interop/rtc_rtp_capabilities_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_rtp_capabilities.h" #include "interop_api.h" diff --git a/src/interop/rtc_rtp_parameters_interop.cc b/src/interop/rtc_rtp_parameters_interop.cc index 74b18e6052..db6f1934d7 100644 --- a/src/interop/rtc_rtp_parameters_interop.cc +++ b/src/interop/rtc_rtp_parameters_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_rtp_parameters.h" #include "interop_api.h" diff --git a/src/interop/rtc_rtp_receiver_interop.cc b/src/interop/rtc_rtp_receiver_interop.cc index 4bb87782f8..164ba7e76b 100644 --- a/src/interop/rtc_rtp_receiver_interop.cc +++ b/src/interop/rtc_rtp_receiver_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_rtp_receiver.h" #include "interop_api.h" #include "rtc_media_stream.h" diff --git a/src/interop/rtc_rtp_sender_interop.cc b/src/interop/rtc_rtp_sender_interop.cc index c69b840f5d..71051a87d3 100644 --- a/src/interop/rtc_rtp_sender_interop.cc +++ b/src/interop/rtc_rtp_sender_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_rtp_sender.h" #include "interop_api.h" #include "rtc_media_track.h" diff --git a/src/interop/rtc_rtp_transceiver_interop.cc b/src/interop/rtc_rtp_transceiver_interop.cc index 56bf24e4c8..c4693caa45 100644 --- a/src/interop/rtc_rtp_transceiver_interop.cc +++ b/src/interop/rtc_rtp_transceiver_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_rtp_transceiver.h" #include "interop_api.h" diff --git a/src/interop/rtc_sdp_parse_error_interop.cc b/src/interop/rtc_sdp_parse_error_interop.cc index 33608f40ba..8809939495 100644 --- a/src/interop/rtc_sdp_parse_error_interop.cc +++ b/src/interop/rtc_sdp_parse_error_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_sdp_parse_error.h" #include "src/rtc_sdp_parse_error_impl.h" #include "interop_api.h" diff --git a/src/interop/rtc_video_device_interop.cc b/src/interop/rtc_video_device_interop.cc index 4ece7b5637..5e3be60be1 100644 --- a/src/interop/rtc_video_device_interop.cc +++ b/src/interop/rtc_video_device_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_video_device.h" #include "interop_api.h" diff --git a/src/interop/rtc_video_frame_interop.cc b/src/interop/rtc_video_frame_interop.cc index 4db03be385..8aae380f90 100644 --- a/src/interop/rtc_video_frame_interop.cc +++ b/src/interop/rtc_video_frame_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_video_frame.h" #include "interop_api.h" diff --git a/src/interop/rtc_video_renderer_interop.cc b/src/interop/rtc_video_renderer_interop.cc index 5f40af489b..018ff137dd 100644 --- a/src/interop/rtc_video_renderer_interop.cc +++ b/src/interop/rtc_video_renderer_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_video_renderer.h" #include "rtc_video_frame.h" #include "interop_api.h" diff --git a/src/interop/rtc_video_track_interop.cc b/src/interop/rtc_video_track_interop.cc index c0c45429bf..53caaaf2a9 100644 --- a/src/interop/rtc_video_track_interop.cc +++ b/src/interop/rtc_video_track_interop.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_video_track.h" #include "interop_api.h" #include "rtc_video_frame.h" diff --git a/src/rtc_audio_data_impl.cc b/src/rtc_audio_data_impl.cc index b5db929876..95068b226b 100644 --- a/src/rtc_audio_data_impl.cc +++ b/src/rtc_audio_data_impl.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_audio_data_impl.h" #include "rtc_base/checks.h" #include "src/internal/audio_util.h" diff --git a/src/rtc_audio_data_impl.h b/src/rtc_audio_data_impl.h index 91998a1cc9..9800d776ab 100644 --- a/src/rtc_audio_data_impl.h +++ b/src/rtc_audio_data_impl.h @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #ifndef LIB_WEBRTC_RTC_AUDIO_DATA_IMPL_HXX #define LIB_WEBRTC_RTC_AUDIO_DATA_IMPL_HXX diff --git a/src/rtc_dummy_audio_source_impl.cc b/src/rtc_dummy_audio_source_impl.cc index df4060d299..c951385f58 100644 --- a/src/rtc_dummy_audio_source_impl.cc +++ b/src/rtc_dummy_audio_source_impl.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_dummy_audio_source_impl.h" #include "rtc_base/logging.h" @@ -64,7 +70,7 @@ void DummyAudioSourceObserverImpl::OnFillBuffer( rtcDummyAudioSourceObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); rtcAudioDataHandle hData = - static_cast(audio_data.release()); + static_cast(audio_data.release()); pCallbacks->FillBuffer(pCallbacks->UserData, hData); } } diff --git a/src/rtc_dummy_audio_source_impl.h b/src/rtc_dummy_audio_source_impl.h index bb7de9203b..ab2e7d9528 100644 --- a/src/rtc_dummy_audio_source_impl.h +++ b/src/rtc_dummy_audio_source_impl.h @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #ifndef LIB_WEBRTC_DUMMY_AUDIO_SOURCE_IMPL_HXX #define LIB_WEBRTC_DUMMY_AUDIO_SOURCE_IMPL_HXX diff --git a/src/rtc_dummy_video_capturer_impl.cc b/src/rtc_dummy_video_capturer_impl.cc index 753723b173..80e65bdf70 100644 --- a/src/rtc_dummy_video_capturer_impl.cc +++ b/src/rtc_dummy_video_capturer_impl.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "src/rtc_dummy_video_capturer_impl.h" #include "rtc_video_frame.h" #include "third_party/libyuv/include/libyuv.h" @@ -81,7 +87,9 @@ RTCDummyVideoCapturerImpl::RTCDummyVideoCapturerImpl( signaling_thread_(signaling_thread), fps_(fps), width_(width), - height_(height) { + height_(height), + frame_buffer_(RTCVideoFrame::Create(width, height)) +{ thread_->Start(); } @@ -183,11 +191,11 @@ void RTCDummyVideoCapturerImpl::OnFrameReady(const scoped_refptr& } void RTCDummyVideoCapturerImpl::FillBuffer() { - scoped_refptr frame = RTCVideoFrame::Create(width_, height_); + //scoped_refptr frame = RTCVideoFrame::Create(width_, height_); if (observer_ != nullptr) { - observer_->OnFillBuffer(frame); + observer_->OnFillBuffer(frame_buffer_); } - OnFrameReady(frame); + OnFrameReady(frame_buffer_); } void RTCDummyVideoCapturerImpl::CaptureFrame() { diff --git a/src/rtc_dummy_video_capturer_impl.h b/src/rtc_dummy_video_capturer_impl.h index ed1ee75f33..705e2f27da 100644 --- a/src/rtc_dummy_video_capturer_impl.h +++ b/src/rtc_dummy_video_capturer_impl.h @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #ifndef LIB_WEBRTC_RTC_DUMMY_VIDEO_CAPTURER_IMPL_HXX #define LIB_WEBRTC_RTC_DUMMY_VIDEO_CAPTURER_IMPL_HXX @@ -80,6 +86,7 @@ class RTCDummyVideoCapturerImpl : public RTCDummyVideoCapturer, uint32_t fps_ = 25; uint32_t width_ = 960; uint32_t height_ = 540; + scoped_refptr frame_buffer_; }; // end class RTCDummyVideoCapturerImpl } // namespace libwebrtc diff --git a/src/rtc_peerconnection_factory_impl.h b/src/rtc_peerconnection_factory_impl.h index 14b8b3a34c..bbf1b200b8 100644 --- a/src/rtc_peerconnection_factory_impl.h +++ b/src/rtc_peerconnection_factory_impl.h @@ -42,7 +42,7 @@ class RTCPeerConnectionFactoryImpl : public RTCPeerConnectionFactory { virtual scoped_refptr CreateAudioSource( const string audio_source_label) override; - + virtual scoped_refptr CreateDummyAudioSource( const string audio_source_label, int sample_rate_hz = 16000, diff --git a/src/rtc_video_frame_impl.cc b/src/rtc_video_frame_impl.cc index 5b65da660a..c9950d439e 100644 --- a/src/rtc_video_frame_impl.cc +++ b/src/rtc_video_frame_impl.cc @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #include "rtc_video_frame_impl.h" #include "api/video/i420_buffer.h" diff --git a/src/rtc_video_frame_impl.h b/src/rtc_video_frame_impl.h index a20b731fa8..e9eac68d0c 100644 --- a/src/rtc_video_frame_impl.h +++ b/src/rtc_video_frame_impl.h @@ -1,3 +1,9 @@ +/** + * File provided for Reference Use Only by isoft (c) 2025. + * Copyright (c) isoft. All rights reserved. + * + */ + #ifndef LIB_WEBRTC_VIDEO_FRAME_IMPL_HXX #define LIB_WEBRTC_VIDEO_FRAME_IMPL_HXX From f5fb7dd346b3f3f7e6ffaab90c45c09779c34fe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Sat, 8 Feb 2025 22:47:17 +0300 Subject: [PATCH 66/69] Added Create method for RTCRtpEncodingParameters and RTCRtpEncodingParametersList --- include/interop_api.h | 12 ++++++++ src/interop/rtc_rtp_parameters_interop.cc | 35 +++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/include/interop_api.h b/include/interop_api.h index bd491cb683..2a6dc4485f 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -3118,6 +3118,11 @@ RTCRtcpParametersList_GetItem ( * ---------------------------------------------------------------------- */ + LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL + RTCRtpEncodingParameters_Create ( + rtcRtpEncodingParametersHandle* pOutRetVal + ) noexcept; + LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL RTCRtpEncodingParameters_GetSSRC ( rtcRtpEncodingParametersHandle handle, @@ -3270,6 +3275,13 @@ RTCRtpEncodingParameters_SetAdaptivePTime ( * ---------------------------------------------------------------------- */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParametersList_Create ( + rtcRtpEncodingParametersHandle* items, + int count, + rtcRtpEncodingParametersListHandle* pOutRetVal +) noexcept; + /** * Returns the number of RTCRtpEncodingParametersList. * diff --git a/src/interop/rtc_rtp_parameters_interop.cc b/src/interop/rtc_rtp_parameters_interop.cc index db6f1934d7..dca633708f 100644 --- a/src/interop/rtc_rtp_parameters_interop.cc +++ b/src/interop/rtc_rtp_parameters_interop.cc @@ -605,6 +605,18 @@ RTCRtcpParametersList_GetItem ( * ---------------------------------------------------------------------- */ +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParameters_Create ( + rtcRtpEncodingParametersHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + + scoped_refptr p = RTCRtpEncodingParameters::Create(); + *pOutRetVal = static_cast(p.release()); + return rtcResultU4::kSuccess; +} + rtcResultU4 LIB_WEBRTC_CALL RTCRtpEncodingParameters_GetSSRC ( rtcRtpEncodingParametersHandle handle, @@ -829,6 +841,29 @@ RTCRtpEncodingParameters_SetAdaptivePTime ( * ---------------------------------------------------------------------- */ +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParametersList_Create ( + rtcRtpEncodingParametersHandle* items, + int count, + rtcRtpEncodingParametersListHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + CHECK_POINTER_EX(items, rtcResultU4::kInvalidParameter); + if (count <= 0) { + return rtcResultU4::kInvalidParameter; + } + + std::vector> vecItems; + for (int i = 0; i < count; i++) { + scoped_refptr pItem = static_cast(items[i]); + vecItems.push_back(pItem); + } + scoped_refptr p = RTCRtpEncodingParametersList::Create(vecItems); + *pOutRetVal = static_cast(p.release()); + return rtcResultU4::kSuccess; +} + int LIB_WEBRTC_CALL RTCRtpEncodingParametersList_GetCount ( rtcRtpEncodingParametersListHandle handle From 9bb84c724b17facfa510e357a894cc03ab99787c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Sun, 9 Feb 2025 13:44:31 +0300 Subject: [PATCH 67/69] Added RTCRtpCodecCapabilityList_Create interop method --- include/interop_api.h | 7 +++++++ src/interop/rtc_rtp_capabilities_interop.cc | 23 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/interop_api.h b/include/interop_api.h index 2a6dc4485f..6dd7bd3438 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -2465,6 +2465,13 @@ RTCRtpCodecCapability_SetSdpFmtpLine( * ---------------------------------------------------------------------- */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapabilityList_Create ( + rtcRtpCodecCapabilityHandle* items, + int count, + rtcRtpCodecCapabilityListHandle* pOutRetVal +) noexcept; + /** * Returns the number of RtpCodecCapabilityList. * diff --git a/src/interop/rtc_rtp_capabilities_interop.cc b/src/interop/rtc_rtp_capabilities_interop.cc index fd29e1708b..ec75db18f7 100644 --- a/src/interop/rtc_rtp_capabilities_interop.cc +++ b/src/interop/rtc_rtp_capabilities_interop.cc @@ -110,6 +110,29 @@ RTCRtpCodecCapability_SetSdpFmtpLine( * ---------------------------------------------------------------------- */ +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapabilityList_Create ( + rtcRtpCodecCapabilityHandle* items, + int count, + rtcRtpCodecCapabilityListHandle* pOutRetVal +) noexcept +{ + CHECK_OUT_POINTER(pOutRetVal); + CHECK_POINTER_EX(items, rtcResultU4::kInvalidParameter); + if (count <= 0) { + return rtcResultU4::kInvalidParameter; + } + + std::vector> vecItems; + for (int i = 0; i < count; i++) { + scoped_refptr pItem = static_cast(items[i]); + vecItems.push_back(pItem); + } + scoped_refptr p = RTCRtpCodecCapabilityList::Create(vecItems); + *pOutRetVal = static_cast(p.release()); + return rtcResultU4::kSuccess; +} + int LIB_WEBRTC_CALL RTCRtpCodecCapabilityList_GetCount ( rtcRtpCodecCapabilityListHandle handle From 38cd79cea895219af3856df244d77c694ed2a595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Tue, 11 Feb 2025 03:59:51 +0300 Subject: [PATCH 68/69] Added YUY2 video frame buffer --- include/interop_api.h | 53 ++++--- include/rtc_types.h | 39 ++++++ include/rtc_video_frame.h | 15 +- src/interop/rtc_video_frame_interop.cc | 103 ++++++++------ src/rtc_video_frame_impl.cc | 186 +++++++++++++++++++------ src/rtc_video_frame_impl.h | 13 +- 6 files changed, 272 insertions(+), 137 deletions(-) diff --git a/include/interop_api.h b/include/interop_api.h index 6dd7bd3438..1a2af0be84 100644 --- a/include/interop_api.h +++ b/include/interop_api.h @@ -27,6 +27,10 @@ using rtcDesktopType = libwebrtc::DesktopType; using rtcCaptureState = libwebrtc::RTCCaptureState; using rtcAudioDataToneFrequency = libwebrtc::RTCAudioDataToneFrequency; using rtcVideoFrameClearType = libwebrtc::RTCVideoFrameClearType; +using rtcVideoFrameTypeARGB = libwebrtc::RTCVideoFrameTypeARGB; +using rtcVideoFrameTypeYUV = libwebrtc::RTCVideoFrameTypeYUV; +using rtcVideoFrameARGB = libwebrtc::RTCVideoFrameARGB; +using rtcVideoFrameYUV = libwebrtc::RTCVideoFrameYUV; /// 64-bit timestamp for interop API. using rtcTimestamp = long long; @@ -38,14 +42,6 @@ enum class rtcKeyRingSize : int { kMin = 1, kDefault = 16, kMax = 256 }; enum class rtcTrackState : int { kUnknown = -1, kLive = 0, kEnded = 1 }; -enum class rtcVideoFrameType : int { - kUnknown = -1, - kARGB = 0, - kBGRA = 1, - kABGR = 2, - kRGBA = 3 -}; - enum class rtcVideoRotation : int { kVideoRotation_0 = 0, kVideoRotation_90 = 90, @@ -1644,17 +1640,13 @@ RTCVideoFrame_SetTimestampInMicroseconds( * Converts the video frame to RGB colorspace. * * @param videoFrame - Source video frame handle - * @param type - Type of destination video frame buffer. - * @param dst_argb - Destination video frame buffer. - * @param dst_stride_argb - Stride of destination video frame buffer. - * @param dest_width - Width of destination video frame buffer. - * @param dest_height - Height of destination video frame buffer. + * @param dest - Destination video frame. * @return int - Size of destination */ LIB_WEBRTC_API int LIB_WEBRTC_CALL RTCVideoFrame_ConvertToARGB( - rtcVideoFrameHandle videoFrame, rtcVideoFrameType type, - unsigned char* dst_argb, int dst_stride_argb, int dest_width, - int dest_height) noexcept; + rtcVideoFrameHandle videoFrame, + rtcVideoFrameARGB* dest +) noexcept; /** * Copies the source frame and scales it to the dimensions @@ -1676,21 +1668,28 @@ RTCVideoFrame_ScaleFrom( * of the destination frame. * * @param handle - Destination video frame handle - * @param frameType - RGBA frame type - * @param src_argb - Source frame buffer address - * @param src_stride_argb - Source stride - * @param src_width - Source frame width - * @param src_height - Source frame height + * @param source - Source video frame. + * @return rtcResultU4 - 0 if successful, otherwise an error code. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_ScaleFromARGB( + rtcVideoFrameHandle dest, + rtcVideoFrameARGB* source, + int* pOutRetVal +) noexcept; + +/** + * Copies the source frame and scales it to the dimensions + * of the destination frame. + * + * @param handle - Destination video frame handle + * @param source - Source video frame. * @return rtcResultU4 - 0 if successful, otherwise an error code. */ LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL -RTCVideoFrame_ScaleFrom2( +RTCVideoFrame_ScaleFromYUV( rtcVideoFrameHandle dest, - rtcVideoFrameType frameType, - const unsigned char* src_argb, - int src_stride_argb, - int src_width, - int src_height, + rtcVideoFrameYUV* source, int* pOutRetVal ) noexcept; diff --git a/include/rtc_types.h b/include/rtc_types.h index f7e38a5275..69b8486926 100644 --- a/include/rtc_types.h +++ b/include/rtc_types.h @@ -16,6 +16,12 @@ #include "base/refcount.h" #include "base/scoped_ref_ptr.h" +#ifndef RTC_FOURCC +#define RTC_FOURCC(ch0, ch1, ch2, ch3) \ + ((unsigned int)(unsigned char)(ch0) | ((unsigned int)(unsigned char)(ch1) << 8) | \ + ((unsigned int)(unsigned char)(ch2) << 16) | ((unsigned int)(unsigned char)(ch3) << 24 )) +#endif + namespace libwebrtc { enum { kMaxIceServerSize = 8 }; @@ -32,6 +38,19 @@ enum class RTCMediaType { AUDIO, VIDEO, DATA, UNSUPPORTED }; enum class RTCCaptureState { CS_RUNNING = 0, CS_STOPPED, CS_FAILED }; +enum class RTCVideoFrameTypeARGB { + kARGB = RTC_FOURCC('A', 'R', 'G', 'B'), + kBGRA = RTC_FOURCC('B', 'G', 'R', 'A'), + kABGR = RTC_FOURCC('A', 'B', 'G', 'R'), + kRGBA = RTC_FOURCC('R', 'G', 'B', 'A') +}; + +enum class RTCVideoFrameTypeYUV { + kI420 = RTC_FOURCC('I', '4', '2', '0'), + kYUY2 = RTC_FOURCC('Y', 'U', 'Y', '2'), + kNV12 = RTC_FOURCC('N', 'V', '1', '2') +}; + enum class RTCAudioDataToneFrequency { kNone = 0, // Clear audio buffer kTone60Hz = 60, @@ -125,6 +144,26 @@ struct RTCConfiguration { enum DesktopType { kScreen, kWindow }; +struct RTCVideoFrameARGB { + RTCVideoFrameTypeARGB type = RTCVideoFrameTypeARGB::kARGB; + int width = 0; + int height = 0; + uint8_t* data = nullptr; + int stride = 0; +}; + +struct RTCVideoFrameYUV { + RTCVideoFrameTypeYUV type = RTCVideoFrameTypeYUV::kI420; + int width = 0; + int height = 0; + uint8_t* dataY = nullptr; + uint8_t* dataU = nullptr; + uint8_t* dataV = nullptr; + int strideY = 0; + int strideU = 0; + int strideV = 0; +}; + } // namespace libwebrtc #endif // LIB_WEBRTC_RTC_TYPES_HXX diff --git a/include/rtc_video_frame.h b/include/rtc_video_frame.h index d3b1cca18c..7a43968a28 100644 --- a/include/rtc_video_frame.h +++ b/include/rtc_video_frame.h @@ -13,8 +13,6 @@ namespace libwebrtc { class RTCVideoFrame : public RefCountInterface { public: - enum class Type { kARGB, kBGRA, kABGR, kRGBA }; - enum VideoRotation { kVideoRotation_0 = 0, kVideoRotation_90 = 90, @@ -58,18 +56,13 @@ class RTCVideoFrame : public RefCountInterface { virtual int64_t timestamp_us() const = 0; virtual void set_timestamp_us(int64_t timestamp_us) = 0; - virtual int ConvertToARGB(Type type, uint8_t* dst_argb, int dst_stride_argb, - int dest_width, int dest_height) = 0; + virtual int ConvertToARGB(RTCVideoFrameARGB* pDest) = 0; virtual int ScaleFrom(scoped_refptr source) = 0; - virtual int ScaleFrom( - Type type, - const uint8_t* src_argb, - int src_stride_argb, - int src_width, - int src_height - ) = 0; + virtual int ScaleFrom(RTCVideoFrameARGB* source) = 0; + + virtual int ScaleFrom(RTCVideoFrameYUV* source) = 0; virtual int Clear(RTCVideoFrameClearType clearType) = 0; diff --git a/src/interop/rtc_video_frame_interop.cc b/src/interop/rtc_video_frame_interop.cc index 8aae380f90..eff32adf0b 100644 --- a/src/interop/rtc_video_frame_interop.cc +++ b/src/interop/rtc_video_frame_interop.cc @@ -252,29 +252,22 @@ RTCVideoFrame_SetTimestampInMicroseconds( int LIB_WEBRTC_CALL RTCVideoFrame_ConvertToARGB( rtcVideoFrameHandle videoFrame, - rtcVideoFrameType type, - unsigned char* dst_argb, - int dst_stride_argb, - int dest_width, - int dest_height + rtcVideoFrameARGB* dest ) noexcept { CHECK_POINTER_EX(videoFrame, 0); - if (dst_argb == nullptr - || dest_width < 2 - || dest_height < 2 - || dst_stride_argb < 12) + CHECK_POINTER_EX(dest, 0); + if (dest->data == nullptr + || dest->width < 2 + || dest->height < 2 + || dest->stride < 12) { return 0; } scoped_refptr pvf = static_cast(videoFrame); return pvf->ConvertToARGB( - static_cast(type), - static_cast(dst_argb), - dst_stride_argb, - dest_width, - dest_height + reinterpret_cast(dest) ); } @@ -298,53 +291,75 @@ RTCVideoFrame_ScaleFrom( } rtcResultU4 LIB_WEBRTC_CALL -RTCVideoFrame_ScaleFrom2( +RTCVideoFrame_ScaleFromARGB( rtcVideoFrameHandle dest, - rtcVideoFrameType frameType, - const unsigned char* src_argb, - int src_stride_argb, - int src_width, - int src_height, + rtcVideoFrameARGB* source, int* pOutRetVal ) noexcept { CHECK_NATIVE_HANDLE(dest); - CHECK_POINTER_EX(src_argb, rtcResultU4::kInvalidParameter); - if (src_width < 16 || - src_height < 16 || - src_stride_argb < 64 || - (src_width * 4) > src_stride_argb) + CHECK_POINTER_EX(source, rtcResultU4::kInvalidParameter); + if (source->data == nullptr || + source->width < 16 || + source->height < 16 || + source->stride < 64 || + (source->width * 4) > source->stride) { return rtcResultU4::kInvalidParameter; } - RTCVideoFrame::Type type; - switch (frameType) + switch (source->type) { - case rtcVideoFrameType::kARGB: - type = RTCVideoFrame::Type::kARGB; + case rtcVideoFrameTypeARGB::kARGB: + case rtcVideoFrameTypeARGB::kBGRA: + case rtcVideoFrameTypeARGB::kABGR: + case rtcVideoFrameTypeARGB::kRGBA: break; - case rtcVideoFrameType::kBGRA: - type = RTCVideoFrame::Type::kBGRA; - break; - case rtcVideoFrameType::kABGR: - type = RTCVideoFrame::Type::kABGR; - break; - case rtcVideoFrameType::kRGBA: - type = RTCVideoFrame::Type::kRGBA; + default: + return rtcResultU4::kInvalidParameter; + } + + scoped_refptr pDst = static_cast(dest); + int buffer_size = pDst->ScaleFrom(reinterpret_cast(source)); + if (pOutRetVal) { + *pOutRetVal = buffer_size; + } + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_ScaleFromYUV( + rtcVideoFrameHandle dest, + rtcVideoFrameYUV* source, + int* pOutRetVal +) noexcept +{ + CHECK_NATIVE_HANDLE(dest); + CHECK_POINTER_EX(source, rtcResultU4::kInvalidParameter); + if (source->width < 16 || + source->height < 16 || + source->dataY == nullptr || + source->dataU == nullptr || + source->dataV == nullptr || + source->strideY < 16 || + source->strideU < 8 || + source->strideV < 8) + { + return rtcResultU4::kInvalidParameter; + } + + switch (source->type) + { + case rtcVideoFrameTypeYUV::kI420: + case rtcVideoFrameTypeYUV::kYUY2: + case rtcVideoFrameTypeYUV::kNV12: break; default: return rtcResultU4::kInvalidParameter; } scoped_refptr pDst = static_cast(dest); - int buffer_size = pDst->ScaleFrom( - type, - static_cast(src_argb), - src_stride_argb, - src_width, - src_height - ); + int buffer_size = pDst->ScaleFrom(reinterpret_cast(source)); if (pOutRetVal) { *pOutRetVal = buffer_size; } diff --git a/src/rtc_video_frame_impl.cc b/src/rtc_video_frame_impl.cc index c9950d439e..d05413b2a8 100644 --- a/src/rtc_video_frame_impl.cc +++ b/src/rtc_video_frame_impl.cc @@ -66,42 +66,53 @@ int VideoFrameBufferImpl::StrideV() const { return buffer_->GetI420()->StrideV(); } -int VideoFrameBufferImpl::ConvertToARGB(Type type, uint8_t* dst_buffer, - int dst_stride, int dest_width, - int dest_height) { +int VideoFrameBufferImpl::ConvertToARGB(RTCVideoFrameARGB* pDest) +{ + if (pDest == nullptr) { + return 0; + } + rtc::scoped_refptr i420 = webrtc::I420Buffer::Rotate(*buffer_.get(), rotation_); rtc::scoped_refptr dest = - webrtc::I420Buffer::Create(dest_width, dest_height); + webrtc::I420Buffer::Create(pDest->width, pDest->height); dest->ScaleFrom(*i420.get()); // ARGB buffer size int buf_size = dest->width() * dest->height() * (32 >> 3); - switch (type) { - case libwebrtc::RTCVideoFrame::Type::kARGB: - libyuv::I420ToARGB(dest->DataY(), dest->StrideY(), dest->DataU(), - dest->StrideU(), dest->DataV(), dest->StrideV(), - dst_buffer, dest->width() * 32 / 8, dest->width(), - dest->height()); + switch (pDest->type) { + case RTCVideoFrameTypeARGB::kARGB: + libyuv::I420ToARGB(dest->DataY(), dest->StrideY(), + dest->DataU(), dest->StrideU(), + dest->DataV(), dest->StrideV(), + pDest->data, pDest->stride, + pDest->width, + pDest->height); break; - case libwebrtc::RTCVideoFrame::Type::kBGRA: - libyuv::I420ToBGRA(dest->DataY(), dest->StrideY(), dest->DataU(), - dest->StrideU(), dest->DataV(), dest->StrideV(), - dst_buffer, dest->width() * 32 / 8, dest->width(), - dest->height()); + case RTCVideoFrameTypeARGB::kBGRA: + libyuv::I420ToBGRA(dest->DataY(), dest->StrideY(), + dest->DataU(), dest->StrideU(), + dest->DataV(), dest->StrideV(), + pDest->data, pDest->stride, + pDest->width, + pDest->height); break; - case libwebrtc::RTCVideoFrame::Type::kABGR: - libyuv::I420ToABGR(dest->DataY(), dest->StrideY(), dest->DataU(), - dest->StrideU(), dest->DataV(), dest->StrideV(), - dst_buffer, dest->width() * 32 / 8, dest->width(), - dest->height()); + case RTCVideoFrameTypeARGB::kABGR: + libyuv::I420ToABGR(dest->DataY(), dest->StrideY(), + dest->DataU(), dest->StrideU(), + dest->DataV(), dest->StrideV(), + pDest->data, pDest->stride, + pDest->width, + pDest->height); break; - case libwebrtc::RTCVideoFrame::Type::kRGBA: - libyuv::I420ToRGBA(dest->DataY(), dest->StrideY(), dest->DataU(), - dest->StrideU(), dest->DataV(), dest->StrideV(), - dst_buffer, dest->width() * 32 / 8, dest->width(), - dest->height()); + case RTCVideoFrameTypeARGB::kRGBA: + libyuv::I420ToRGBA(dest->DataY(), dest->StrideY(), + dest->DataU(), dest->StrideU(), + dest->DataV(), dest->StrideV(), + pDest->data, pDest->stride, + pDest->width, + pDest->height); break; default: break; @@ -134,47 +145,61 @@ int VideoFrameBufferImpl::ScaleFrom(scoped_refptr source) return size(); } -int VideoFrameBufferImpl::ScaleFrom( - Type type, - const uint8_t* src_argb, - int src_stride_argb, - int src_width, - int src_height - ) +int VideoFrameBufferImpl::ScaleFrom(RTCVideoFrameARGB* source) { + if (source == nullptr || + source->data == nullptr || + source->width < 16 || + source->height < 16 || + source->stride < 64 || + (source->width * 4) > source->stride) + { + return 0; + } + + switch (source->type) { + case RTCVideoFrameTypeARGB::kARGB: + case RTCVideoFrameTypeARGB::kBGRA: + case RTCVideoFrameTypeARGB::kABGR: + case RTCVideoFrameTypeARGB::kRGBA: + break; + default: + return 0; // Unknown type + } + rtc::scoped_refptr i420_src = - webrtc::I420Buffer::Create(src_width, src_height); + webrtc::I420Buffer::Create(source->width, source->height); rtc::scoped_refptr i420_dst = webrtc::I420Buffer::Create(width(), height()); - switch (type) { - case libwebrtc::RTCVideoFrame::Type::kARGB: - libyuv::ARGBToI420(src_argb, src_stride_argb, + switch (source->type) { + case RTCVideoFrameTypeARGB::kARGB: + libyuv::ARGBToI420(source->data, source->stride, i420_src->MutableDataY(), i420_src->StrideY(), i420_src->MutableDataU(), i420_src->StrideU(), i420_src->MutableDataV(), i420_src->StrideV(), - src_width, src_height); + source->width, source->height); break; - case libwebrtc::RTCVideoFrame::Type::kBGRA: - libyuv::BGRAToI420(src_argb, src_stride_argb, + case RTCVideoFrameTypeARGB::kBGRA: + libyuv::BGRAToI420(source->data, source->stride, i420_src->MutableDataY(), i420_src->StrideY(), i420_src->MutableDataU(), i420_src->StrideU(), i420_src->MutableDataV(), i420_src->StrideV(), - src_width, src_height); + source->width, source->height); break; - case libwebrtc::RTCVideoFrame::Type::kABGR: - libyuv::ABGRToI420(src_argb, src_stride_argb, + case RTCVideoFrameTypeARGB::kABGR: + libyuv::ABGRToI420(source->data, source->stride, i420_src->MutableDataY(), i420_src->StrideY(), i420_src->MutableDataU(), i420_src->StrideU(), i420_src->MutableDataV(), i420_src->StrideV(), - src_width, src_height); + source->width, source->height); break; - case libwebrtc::RTCVideoFrame::Type::kRGBA: - libyuv::RGBAToI420(src_argb, src_stride_argb, + case RTCVideoFrameTypeARGB::kRGBA: + libyuv::RGBAToI420(source->data, source->stride, i420_src->MutableDataY(), i420_src->StrideY(), i420_src->MutableDataU(), i420_src->StrideU(), i420_src->MutableDataV(), i420_src->StrideV(), - src_width, src_height); + source->width, source->height); break; default: break; @@ -186,6 +211,75 @@ int VideoFrameBufferImpl::ScaleFrom( return size(); } +int VideoFrameBufferImpl::ScaleFrom(RTCVideoFrameYUV* source) +{ + if (source == nullptr || + source->width < 16 || + source->height < 16 || + source->dataY == nullptr || + source->dataU == nullptr || + source->dataV == nullptr || + source->strideY < 16 || + source->strideU < 8 || + source->strideV < 8) + { + return 0; + } + + switch (source->type) { + case RTCVideoFrameTypeYUV::kI420: + case RTCVideoFrameTypeYUV::kYUY2: + case RTCVideoFrameTypeYUV::kNV12: + break; + default: + return 0; // Unknown type + } + + if (source->type == RTCVideoFrameTypeYUV::kI420) { + scoped_refptr videoFrame = RTCVideoFrame::Create( + source->width, + source->height, + static_cast(source->dataY), + source->strideY, + static_cast(source->dataU), + source->strideU, + static_cast(source->dataV), + source->strideV + ); + + return ScaleFrom(videoFrame); + } + else if (source->type == RTCVideoFrameTypeYUV::kYUY2) { + rtc::scoped_refptr i420_src = + webrtc::I420Buffer::Create(source->width, source->height); + rtc::scoped_refptr i420_dst = + webrtc::I420Buffer::Create(width(), height()); + + int retVal = libyuv::YUY2ToI420( + static_cast(source->dataY), + source->strideY, + i420_src->MutableDataY(), i420_src->StrideY(), + i420_src->MutableDataU(), i420_src->StrideU(), + i420_src->MutableDataV(), i420_src->StrideV(), + source->width, source->height + ); + + if (retVal != 0) { + return 0; // error + } + + i420_dst->ScaleFrom(*i420_src.get()); + buffer_ = i420_dst; + + return size(); + } + else if (source->type == RTCVideoFrameTypeYUV::kNV12) { + return 0; // Not yet supported !!! + } + + return 0; +} + int VideoFrameBufferImpl::Clear(RTCVideoFrameClearType clearType) { int buffer_size = size(); if (buffer_size <= 0) { diff --git a/src/rtc_video_frame_impl.h b/src/rtc_video_frame_impl.h index e9eac68d0c..d360c55bfa 100644 --- a/src/rtc_video_frame_impl.h +++ b/src/rtc_video_frame_impl.h @@ -38,18 +38,13 @@ class VideoFrameBufferImpl : public RTCVideoFrame { int StrideU() const override; int StrideV() const override; - int ConvertToARGB(Type type, uint8_t* dst_argb, int dst_stride_argb, - int dest_width, int dest_height) override; + int ConvertToARGB(RTCVideoFrameARGB* pDest) override; int ScaleFrom(scoped_refptr source) override; - int ScaleFrom( - Type type, - const uint8_t* src_argb, - int src_stride_argb, - int src_width, - int src_height - ) override; + int ScaleFrom(RTCVideoFrameARGB* source) override; + + int ScaleFrom(RTCVideoFrameYUV* source) override; int Clear(RTCVideoFrameClearType clearType) override; From 227260c2a8aec1d07988786df9510798da6d053c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Erdo=C4=9Fdu?= Date: Sun, 26 Oct 2025 16:59:26 +0300 Subject: [PATCH 69/69] License comments removed. --- include/rtc_audio_data.h | 6 ------ include/rtc_dummy_audio_source.h | 6 ------ include/rtc_dummy_video_capturer.h | 6 ------ include/rtc_video_frame.h | 6 ------ src/internal/audio_util.cc | 6 ------ src/internal/audio_util.h | 6 ------ src/internal/dummy_audio_capturer.cc | 6 ------ src/internal/dummy_audio_capturer.h | 6 ------ src/internal/dummy_capturer.cc | 6 ------ src/internal/dummy_capturer.h | 6 ------ src/interop/libwebrtc_interop.cc | 6 ------ src/interop/ref_counted_object_interop.cc | 6 ------ src/interop/rtc_audio_data_interop.cc | 6 ------ src/interop/rtc_audio_device_interop.cc | 6 ------ src/interop/rtc_audio_track_interop.cc | 6 ------ src/interop/rtc_data_channel_interop.cc | 6 ------ src/interop/rtc_desktop_capturer_interop.cc | 6 ------ src/interop/rtc_desktop_device_interop.cc | 6 ------ src/interop/rtc_desktop_media_list_interop.cc | 6 ------ src/interop/rtc_dtls_transport_interop.cc | 6 ------ src/interop/rtc_dtmf_sender_interop.cc | 6 ------ src/interop/rtc_dummy_audio_source_interop.cc | 6 ------ src/interop/rtc_dummy_video_capturer_interop.cc | 6 ------ src/interop/rtc_ice_candidate_interop.cc | 6 ------ src/interop/rtc_media_stream_interop.cc | 6 ------ src/interop/rtc_media_track_interop.cc | 6 ------ src/interop/rtc_mediaconstraints_interop.cc | 6 ------ src/interop/rtc_peerconnection_factory_interop.cc | 6 ------ src/interop/rtc_peerconnection_interop.cc | 6 ------ src/interop/rtc_rtp_capabilities_interop.cc | 6 ------ src/interop/rtc_rtp_parameters_interop.cc | 6 ------ src/interop/rtc_rtp_receiver_interop.cc | 6 ------ src/interop/rtc_rtp_sender_interop.cc | 6 ------ src/interop/rtc_rtp_transceiver_interop.cc | 6 ------ src/interop/rtc_sdp_parse_error_interop.cc | 6 ------ src/interop/rtc_video_device_interop.cc | 6 ------ src/interop/rtc_video_frame_interop.cc | 6 ------ src/interop/rtc_video_renderer_interop.cc | 6 ------ src/interop/rtc_video_track_interop.cc | 6 ------ src/rtc_audio_data_impl.cc | 6 ------ src/rtc_audio_data_impl.h | 6 ------ src/rtc_dummy_audio_source_impl.cc | 6 ------ src/rtc_dummy_audio_source_impl.h | 6 ------ src/rtc_dummy_video_capturer_impl.cc | 6 ------ src/rtc_dummy_video_capturer_impl.h | 6 ------ src/rtc_video_frame_impl.cc | 6 ------ src/rtc_video_frame_impl.h | 6 ------ 47 files changed, 282 deletions(-) diff --git a/include/rtc_audio_data.h b/include/rtc_audio_data.h index fb10c7b8c9..97cd089b2b 100644 --- a/include/rtc_audio_data.h +++ b/include/rtc_audio_data.h @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #ifndef LIB_WEBRTC_RTC_AUDIO_DATA_HXX #define LIB_WEBRTC_RTC_AUDIO_DATA_HXX diff --git a/include/rtc_dummy_audio_source.h b/include/rtc_dummy_audio_source.h index 0e3870bbcf..606dadd6df 100644 --- a/include/rtc_dummy_audio_source.h +++ b/include/rtc_dummy_audio_source.h @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #ifndef LIB_WEBRTC_RTC_DUMMY_AUDIO_SOURCE_HXX #define LIB_WEBRTC_RTC_DUMMY_AUDIO_SOURCE_HXX diff --git a/include/rtc_dummy_video_capturer.h b/include/rtc_dummy_video_capturer.h index ae56268262..8e9c9d48ef 100644 --- a/include/rtc_dummy_video_capturer.h +++ b/include/rtc_dummy_video_capturer.h @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #ifndef LIB_WEBRTC_RTC_DUMMY_VIDEO_CAPTURER_HXX #define LIB_WEBRTC_RTC_DUMMY_VIDEO_CAPTURER_HXX diff --git a/include/rtc_video_frame.h b/include/rtc_video_frame.h index 7a43968a28..3a5b5fccf3 100644 --- a/include/rtc_video_frame.h +++ b/include/rtc_video_frame.h @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #ifndef LIB_WEBRTC_RTC_VIDEO_FRAME_HXX #define LIB_WEBRTC_RTC_VIDEO_FRAME_HXX diff --git a/src/internal/audio_util.cc b/src/internal/audio_util.cc index a931aef876..0acdaf866a 100644 --- a/src/internal/audio_util.cc +++ b/src/internal/audio_util.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "audio_util.h" #include "rtc_types.h" diff --git a/src/internal/audio_util.h b/src/internal/audio_util.h index ec5341997d..799fe2e527 100644 --- a/src/internal/audio_util.h +++ b/src/internal/audio_util.h @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #ifndef LIB_WEBRTC_AUDIO_UTIL_HXX #define LIB_WEBRTC_AUDIO_UTIL_HXX diff --git a/src/internal/dummy_audio_capturer.cc b/src/internal/dummy_audio_capturer.cc index 19d1e5fcba..dec7335886 100644 --- a/src/internal/dummy_audio_capturer.cc +++ b/src/internal/dummy_audio_capturer.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "src/internal/dummy_audio_capturer.h" #include "rtc_base/logging.h" diff --git a/src/internal/dummy_audio_capturer.h b/src/internal/dummy_audio_capturer.h index b31969041a..3455157963 100644 --- a/src/internal/dummy_audio_capturer.h +++ b/src/internal/dummy_audio_capturer.h @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #ifndef INTERNAL_DUMMY_AUDIO_CAPTURER_H_ #define INTERNAL_DUMMY_AUDIO_CAPTURER_H_ diff --git a/src/internal/dummy_capturer.cc b/src/internal/dummy_capturer.cc index 64fd595385..7344ac5617 100644 --- a/src/internal/dummy_capturer.cc +++ b/src/internal/dummy_capturer.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "src/internal/dummy_capturer.h" namespace libwebrtc {} // namespace libwebrtc \ No newline at end of file diff --git a/src/internal/dummy_capturer.h b/src/internal/dummy_capturer.h index ce830c4160..da170b30e9 100644 --- a/src/internal/dummy_capturer.h +++ b/src/internal/dummy_capturer.h @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #ifndef LIB_WEBRTC_DUMMY_CAPTURER_IMPL_HXX #define LIB_WEBRTC_DUMMY_CAPTURER_IMPL_HXX diff --git a/src/interop/libwebrtc_interop.cc b/src/interop/libwebrtc_interop.cc index 413617c230..e329b42eeb 100644 --- a/src/interop/libwebrtc_interop.cc +++ b/src/interop/libwebrtc_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "interop_api.h" #include "rtc_peerconnection_factory.h" #include "libwebrtc.h" diff --git a/src/interop/ref_counted_object_interop.cc b/src/interop/ref_counted_object_interop.cc index d15b5c20bf..16a2cc3924 100644 --- a/src/interop/ref_counted_object_interop.cc +++ b/src/interop/ref_counted_object_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "interop_api.h" using namespace libwebrtc; diff --git a/src/interop/rtc_audio_data_interop.cc b/src/interop/rtc_audio_data_interop.cc index f235157cb8..e28b49b3c7 100644 --- a/src/interop/rtc_audio_data_interop.cc +++ b/src/interop/rtc_audio_data_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_audio_data.h" #include "interop_api.h" diff --git a/src/interop/rtc_audio_device_interop.cc b/src/interop/rtc_audio_device_interop.cc index cfe7e31945..3ad59afc85 100644 --- a/src/interop/rtc_audio_device_interop.cc +++ b/src/interop/rtc_audio_device_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_audio_device.h" #include "interop_api.h" diff --git a/src/interop/rtc_audio_track_interop.cc b/src/interop/rtc_audio_track_interop.cc index 8776ef68c5..b954cf6fab 100644 --- a/src/interop/rtc_audio_track_interop.cc +++ b/src/interop/rtc_audio_track_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_audio_track.h" #include "interop_api.h" diff --git a/src/interop/rtc_data_channel_interop.cc b/src/interop/rtc_data_channel_interop.cc index 69e2ffc304..9b923ce775 100644 --- a/src/interop/rtc_data_channel_interop.cc +++ b/src/interop/rtc_data_channel_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_data_channel.h" #include "interop_api.h" #include "src/rtc_data_channel_impl.h" diff --git a/src/interop/rtc_desktop_capturer_interop.cc b/src/interop/rtc_desktop_capturer_interop.cc index c6a5ed2763..e685b28381 100644 --- a/src/interop/rtc_desktop_capturer_interop.cc +++ b/src/interop/rtc_desktop_capturer_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_desktop_capturer.h" #include "src/rtc_desktop_capturer_impl.h" #include "interop_api.h" diff --git a/src/interop/rtc_desktop_device_interop.cc b/src/interop/rtc_desktop_device_interop.cc index 989caff33c..9319a0736e 100644 --- a/src/interop/rtc_desktop_device_interop.cc +++ b/src/interop/rtc_desktop_device_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_desktop_media_list.h" #include "rtc_desktop_capturer.h" #include "rtc_desktop_device.h" diff --git a/src/interop/rtc_desktop_media_list_interop.cc b/src/interop/rtc_desktop_media_list_interop.cc index 0909c1b942..0a60c9d11b 100644 --- a/src/interop/rtc_desktop_media_list_interop.cc +++ b/src/interop/rtc_desktop_media_list_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_desktop_media_list.h" #include "interop_api.h" #include "src/rtc_desktop_media_list_impl.h" diff --git a/src/interop/rtc_dtls_transport_interop.cc b/src/interop/rtc_dtls_transport_interop.cc index 6574ea3771..362ed2ce06 100644 --- a/src/interop/rtc_dtls_transport_interop.cc +++ b/src/interop/rtc_dtls_transport_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_dtls_transport.h" #include "src/rtc_dtls_transport_impl.h" #include "interop_api.h" diff --git a/src/interop/rtc_dtmf_sender_interop.cc b/src/interop/rtc_dtmf_sender_interop.cc index e841c050cb..df4943bd4d 100644 --- a/src/interop/rtc_dtmf_sender_interop.cc +++ b/src/interop/rtc_dtmf_sender_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_dtmf_sender.h" #include "src/rtc_dtmf_sender_impl.h" #include "interop_api.h" diff --git a/src/interop/rtc_dummy_audio_source_interop.cc b/src/interop/rtc_dummy_audio_source_interop.cc index ecc10dd3c7..db76f2abc7 100644 --- a/src/interop/rtc_dummy_audio_source_interop.cc +++ b/src/interop/rtc_dummy_audio_source_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "src/rtc_dummy_audio_source_impl.h" #include "interop_api.h" diff --git a/src/interop/rtc_dummy_video_capturer_interop.cc b/src/interop/rtc_dummy_video_capturer_interop.cc index 8071c26f6d..1d83101edb 100644 --- a/src/interop/rtc_dummy_video_capturer_interop.cc +++ b/src/interop/rtc_dummy_video_capturer_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "src/rtc_dummy_video_capturer_impl.h" #include "interop_api.h" diff --git a/src/interop/rtc_ice_candidate_interop.cc b/src/interop/rtc_ice_candidate_interop.cc index 92417aa303..70711e232c 100644 --- a/src/interop/rtc_ice_candidate_interop.cc +++ b/src/interop/rtc_ice_candidate_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_ice_candidate.h" #include "rtc_sdp_parse_error.h" #include "interop_api.h" diff --git a/src/interop/rtc_media_stream_interop.cc b/src/interop/rtc_media_stream_interop.cc index 6318f4982b..692173ad49 100644 --- a/src/interop/rtc_media_stream_interop.cc +++ b/src/interop/rtc_media_stream_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_media_stream.h" #include "interop_api.h" diff --git a/src/interop/rtc_media_track_interop.cc b/src/interop/rtc_media_track_interop.cc index d21571b0e8..c60af0cefe 100644 --- a/src/interop/rtc_media_track_interop.cc +++ b/src/interop/rtc_media_track_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_media_track.h" #include "interop_api.h" diff --git a/src/interop/rtc_mediaconstraints_interop.cc b/src/interop/rtc_mediaconstraints_interop.cc index 1ebc81173d..8e6965823a 100644 --- a/src/interop/rtc_mediaconstraints_interop.cc +++ b/src/interop/rtc_mediaconstraints_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_mediaconstraints.h" #include "src/rtc_mediaconstraints_impl.h" #include "interop_api.h" diff --git a/src/interop/rtc_peerconnection_factory_interop.cc b/src/interop/rtc_peerconnection_factory_interop.cc index 2d3376c343..8c06349bc5 100644 --- a/src/interop/rtc_peerconnection_factory_interop.cc +++ b/src/interop/rtc_peerconnection_factory_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "src/rtc_mediaconstraints_impl.h" #include "src/rtc_peerconnection_factory_impl.h" diff --git a/src/interop/rtc_peerconnection_interop.cc b/src/interop/rtc_peerconnection_interop.cc index 2dd3a1bf0c..08d6c11356 100644 --- a/src/interop/rtc_peerconnection_interop.cc +++ b/src/interop/rtc_peerconnection_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_peerconnection.h" #include "src/rtc_peerconnection_impl.h" #include "interop_api.h" diff --git a/src/interop/rtc_rtp_capabilities_interop.cc b/src/interop/rtc_rtp_capabilities_interop.cc index ec75db18f7..58418dde35 100644 --- a/src/interop/rtc_rtp_capabilities_interop.cc +++ b/src/interop/rtc_rtp_capabilities_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_rtp_capabilities.h" #include "interop_api.h" diff --git a/src/interop/rtc_rtp_parameters_interop.cc b/src/interop/rtc_rtp_parameters_interop.cc index dca633708f..87a8735203 100644 --- a/src/interop/rtc_rtp_parameters_interop.cc +++ b/src/interop/rtc_rtp_parameters_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_rtp_parameters.h" #include "interop_api.h" diff --git a/src/interop/rtc_rtp_receiver_interop.cc b/src/interop/rtc_rtp_receiver_interop.cc index 164ba7e76b..4bb87782f8 100644 --- a/src/interop/rtc_rtp_receiver_interop.cc +++ b/src/interop/rtc_rtp_receiver_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_rtp_receiver.h" #include "interop_api.h" #include "rtc_media_stream.h" diff --git a/src/interop/rtc_rtp_sender_interop.cc b/src/interop/rtc_rtp_sender_interop.cc index 71051a87d3..c69b840f5d 100644 --- a/src/interop/rtc_rtp_sender_interop.cc +++ b/src/interop/rtc_rtp_sender_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_rtp_sender.h" #include "interop_api.h" #include "rtc_media_track.h" diff --git a/src/interop/rtc_rtp_transceiver_interop.cc b/src/interop/rtc_rtp_transceiver_interop.cc index c4693caa45..56bf24e4c8 100644 --- a/src/interop/rtc_rtp_transceiver_interop.cc +++ b/src/interop/rtc_rtp_transceiver_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_rtp_transceiver.h" #include "interop_api.h" diff --git a/src/interop/rtc_sdp_parse_error_interop.cc b/src/interop/rtc_sdp_parse_error_interop.cc index 8809939495..33608f40ba 100644 --- a/src/interop/rtc_sdp_parse_error_interop.cc +++ b/src/interop/rtc_sdp_parse_error_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_sdp_parse_error.h" #include "src/rtc_sdp_parse_error_impl.h" #include "interop_api.h" diff --git a/src/interop/rtc_video_device_interop.cc b/src/interop/rtc_video_device_interop.cc index 5e3be60be1..4ece7b5637 100644 --- a/src/interop/rtc_video_device_interop.cc +++ b/src/interop/rtc_video_device_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_video_device.h" #include "interop_api.h" diff --git a/src/interop/rtc_video_frame_interop.cc b/src/interop/rtc_video_frame_interop.cc index eff32adf0b..a38e6e23a6 100644 --- a/src/interop/rtc_video_frame_interop.cc +++ b/src/interop/rtc_video_frame_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_video_frame.h" #include "interop_api.h" diff --git a/src/interop/rtc_video_renderer_interop.cc b/src/interop/rtc_video_renderer_interop.cc index 018ff137dd..5f40af489b 100644 --- a/src/interop/rtc_video_renderer_interop.cc +++ b/src/interop/rtc_video_renderer_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_video_renderer.h" #include "rtc_video_frame.h" #include "interop_api.h" diff --git a/src/interop/rtc_video_track_interop.cc b/src/interop/rtc_video_track_interop.cc index 53caaaf2a9..c0c45429bf 100644 --- a/src/interop/rtc_video_track_interop.cc +++ b/src/interop/rtc_video_track_interop.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_video_track.h" #include "interop_api.h" #include "rtc_video_frame.h" diff --git a/src/rtc_audio_data_impl.cc b/src/rtc_audio_data_impl.cc index 95068b226b..b5db929876 100644 --- a/src/rtc_audio_data_impl.cc +++ b/src/rtc_audio_data_impl.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_audio_data_impl.h" #include "rtc_base/checks.h" #include "src/internal/audio_util.h" diff --git a/src/rtc_audio_data_impl.h b/src/rtc_audio_data_impl.h index 9800d776ab..91998a1cc9 100644 --- a/src/rtc_audio_data_impl.h +++ b/src/rtc_audio_data_impl.h @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #ifndef LIB_WEBRTC_RTC_AUDIO_DATA_IMPL_HXX #define LIB_WEBRTC_RTC_AUDIO_DATA_IMPL_HXX diff --git a/src/rtc_dummy_audio_source_impl.cc b/src/rtc_dummy_audio_source_impl.cc index c951385f58..637d24009b 100644 --- a/src/rtc_dummy_audio_source_impl.cc +++ b/src/rtc_dummy_audio_source_impl.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_dummy_audio_source_impl.h" #include "rtc_base/logging.h" diff --git a/src/rtc_dummy_audio_source_impl.h b/src/rtc_dummy_audio_source_impl.h index ab2e7d9528..bb7de9203b 100644 --- a/src/rtc_dummy_audio_source_impl.h +++ b/src/rtc_dummy_audio_source_impl.h @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #ifndef LIB_WEBRTC_DUMMY_AUDIO_SOURCE_IMPL_HXX #define LIB_WEBRTC_DUMMY_AUDIO_SOURCE_IMPL_HXX diff --git a/src/rtc_dummy_video_capturer_impl.cc b/src/rtc_dummy_video_capturer_impl.cc index 80e65bdf70..9aa2c675e7 100644 --- a/src/rtc_dummy_video_capturer_impl.cc +++ b/src/rtc_dummy_video_capturer_impl.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "src/rtc_dummy_video_capturer_impl.h" #include "rtc_video_frame.h" #include "third_party/libyuv/include/libyuv.h" diff --git a/src/rtc_dummy_video_capturer_impl.h b/src/rtc_dummy_video_capturer_impl.h index 705e2f27da..f146cf9b0e 100644 --- a/src/rtc_dummy_video_capturer_impl.h +++ b/src/rtc_dummy_video_capturer_impl.h @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #ifndef LIB_WEBRTC_RTC_DUMMY_VIDEO_CAPTURER_IMPL_HXX #define LIB_WEBRTC_RTC_DUMMY_VIDEO_CAPTURER_IMPL_HXX diff --git a/src/rtc_video_frame_impl.cc b/src/rtc_video_frame_impl.cc index d05413b2a8..0b3ca5f0c6 100644 --- a/src/rtc_video_frame_impl.cc +++ b/src/rtc_video_frame_impl.cc @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #include "rtc_video_frame_impl.h" #include "api/video/i420_buffer.h" diff --git a/src/rtc_video_frame_impl.h b/src/rtc_video_frame_impl.h index d360c55bfa..282b6f09f5 100644 --- a/src/rtc_video_frame_impl.h +++ b/src/rtc_video_frame_impl.h @@ -1,9 +1,3 @@ -/** - * File provided for Reference Use Only by isoft (c) 2025. - * Copyright (c) isoft. All rights reserved. - * - */ - #ifndef LIB_WEBRTC_VIDEO_FRAME_IMPL_HXX #define LIB_WEBRTC_VIDEO_FRAME_IMPL_HXX