diff --git a/BUILD.gn b/BUILD.gn index bcb7ce7ac1..52b25cab98 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 } @@ -68,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", @@ -75,6 +77,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", @@ -93,13 +96,22 @@ 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/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", @@ -115,6 +127,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", @@ -141,13 +155,63 @@ 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", "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", + "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 + 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", + "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", + "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", + "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", + "src/interop/rtc_rtp_sender_interop.cc", + "src/interop/rtc_rtp_transceiver_interop.cc", + "src/interop/rtc_peerconnection_interop.cc", + ] + + 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", + ] + } + } # intel media sdk if (is_win && libwebrtc_intel_media_sdk) { 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"). diff --git a/include/base/portable.h b/include/base/portable.h index b403af9cd3..7e4bc0a558 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]; @@ -49,7 +53,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()); } @@ -71,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; @@ -80,6 +88,52 @@ 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::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(); } @@ -213,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 new file mode 100644 index 0000000000..1a2af0be84 --- /dev/null +++ b/include/interop_api.h @@ -0,0 +1,4129 @@ +#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" +#include "interop_macros.h" + +extern "C" { + +/// Types used from libwebrtc. +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; +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; + +/// 32-bit boolean for interop API. +enum class rtcBool32 : int { kFalse = 0, kTrue = 1 }; + +enum class rtcKeyRingSize : int { kMin = 1, kDefault = 16, kMax = 256 }; + +enum class rtcTrackState : int { kUnknown = -1, kLive = 0, kEnded = 1 }; + +enum class rtcVideoRotation : int { + kVideoRotation_0 = 0, + kVideoRotation_90 = 90, + kVideoRotation_180 = 180, + 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, + + // + // 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, + + /// 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, +}; // 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; + 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 + +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. + rtcKeyRingSize key_ring_size = rtcKeyRingSize::kDefault; + rtcBool32 discard_frame_when_cryptor_not_ready = rtcBool32::kFalse; +}; // end struct rtcKeyProviderOptions + +/// 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; + +/// 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; + +/// 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 RTCDummyAudioSource interop object. +using rtcDummyAudioSourceHandle = 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; + +/// 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; + +/// Opaque handle to a native RTCDummyVideoCapturer interop object. +using rtcDummyVideoCapturerHandle = 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; + +/// Opaque handle to a native RTCAudioTrack interop object. +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 RTCAudioData interop object. +using rtcAudioDataHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCVideoRenderer interop object. +using rtcVideoRendererHandle = rtcRefCountedObjectHandle; // ??? + +/// Opaque handle to a native RTCDataChannel interop object. +using rtcDataChannelHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCDtlsTransportInformation interop object. +using rtcDtlsTransportInformationHandle = rtcRefCountedObjectHandle; + +/// Opaque handle to a native RTCDtlsTransport interop object. +using rtcDtlsTransportHandle = rtcRefCountedObjectHandle; + +/// 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 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; + +/// 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 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; + +/// 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; + +/// 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; + +/* ---------------------------------------------------------------- */ + +/** + * Audio device change callback delegate + */ +using rtcAudioDeviceChangeDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data); + +/** + * Callback delegate for MediaListObserver. + */ +using rtcMediaListObserverDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, rtcDesktopMediaSourceHandle source); + +/** + * Callback delegate structure for MediaListObserver. + */ +struct rtcMediaListObserverCallbacks { + rtcObjectHandle UserData{}; + rtcMediaListObserverDelegate MediaSourceAdded{}; + rtcMediaListObserverDelegate MediaSourceRemoved{}; + rtcMediaListObserverDelegate MediaSourceNameChanged{}; + 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{}; +}; + +/** + * 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{}; +}; + +/** + * 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. + */ +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 { + rtcObjectHandle UserData{}; + rtcDataChannelObserverStateChangeDelegate StateChanged{}; + 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{}; +}; + +/** + * RTCDtmfSender: Tone changed callback delegate + */ +using rtcDtmfSenderToneChangedDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, const char* tone, const char* tone_buffer); + +/** + * 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); + +/** + * Callback delegate structure for RTCDtlsTransportObserver. + */ +struct rtcDtlsTransportObserverCallbacks { + rtcObjectHandle UserData{}; + rtcDtlsTransportStateChangedDelegate StateChanged{}; + 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*)( + rtcObjectHandle user_data, rtcMediaRTCStatsListHandle reports); + +using rtcOnFailureDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, const char* error); + +using rtcOnGetSdpSuccessDelegate = void(LIB_WEBRTC_CALL*)( + rtcObjectHandle user_data, const char* sdp, const char* type); + +using rtcOnSetSdpSuccessDelegate = void(LIB_WEBRTC_CALL*)(rtcObjectHandle user_data); + +/* + * ---------------------------------------------------------------------- + * LibWebRTC interop methods + * ---------------------------------------------------------------------- + */ + +/** + * @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( + rtcBool32 use_dummy_audio = rtcBool32::kFalse +) 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; + +/** + * @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; + +/* + * ---------------------------------------------------------------------- + * RefCountedObject interop methods + * ---------------------------------------------------------------------- + */ + +/** + * @brief Add ref a pointer. + */ +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RefCountedObject_AddRef(rtcRefCountedObjectHandle handle) noexcept; + +/** + * @brief Release a pointer. + */ +LIB_WEBRTC_API int LIB_WEBRTC_CALL +RefCountedObject_Release(rtcRefCountedObjectHandle handle) noexcept; + +/* + * ---------------------------------------------------------------------- + * MediaConstraints interop methods + * ---------------------------------------------------------------------- + */ + +/** + * @brief Creates a new instance of the RTCMediaConstraints object. + */ +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; + +/* + * ---------------------------------------------------------------------- + * RTCPeerConnectionFactory interop methods + * ---------------------------------------------------------------------- + */ + +/** + * @brief Creates a new instance of the RTCPeerConnectionFactor object. + */ +LIB_WEBRTC_API rtcPeerConnectionFactoryHandle LIB_WEBRTC_CALL +RTCPeerConnectionFactory_Create() noexcept; + +/** + * @brief 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, + rtcBool32 use_dummy_audio = rtcBool32::kFalse +) noexcept; + +/** + * @brief Terminates the RTCPeerConnectionFactor object. + */ +LIB_WEBRTC_API rtcBool32 LIB_WEBRTC_CALL RTCPeerConnectionFactory_Terminate( + rtcPeerConnectionFactoryHandle factory) noexcept; + +/** + * @brief Creates a new instance of the RTCPeerConnection object. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_CreatePeerConnection( + rtcPeerConnectionFactoryHandle factory, + const rtcPeerConnectionConfiguration* configuration, + rtcMediaConstraintsHandle constraints, + rtcPeerConnectionHandle* pRetVal) noexcept; + +/** + * @brief Removes the RTCPeerConnection object from the factory. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_DeletePeerConnection( + rtcPeerConnectionFactoryHandle factory, + 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; + +/** + * @brief 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 + +/** + * @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; + +/** + * @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. + */ +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 +/** + * @brief 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 + +/** + * @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. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +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. + */ +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_CreateVideoTrack( + 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; + +/** + * 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; + +/** + * 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_SetIndex( + rtcAudioDataHandle handle, + unsigned int index +) 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 + * ---------------------------------------------------------------------- + */ + +/** + * 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, + rtcObjectHandle userData, + rtcAudioDeviceChangeDelegate callback +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_UnregisterDeviceChangeCallback( + rtcAudioDeviceHandle audiDevice +) 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; + +/* + * ---------------------------------------------------------------------- + * 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 + * ---------------------------------------------------------------------- + */ + +/** + * 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 + * ---------------------------------------------------------------------- + */ + +/** + * 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; + +/* + * ---------------------------------------------------------------------- + * 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; + +/* + * ---------------------------------------------------------------------- + * 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; + +/** + * 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 + * @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 + * 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( + 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. + * + * @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_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_GetSize( + 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) + * + * @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; + +/** + * 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. + * + * @param videoFrame - Source video frame handle + * @param dest - Destination video frame. + * @return int - Size of destination + */ +LIB_WEBRTC_API int LIB_WEBRTC_CALL RTCVideoFrame_ConvertToARGB( + rtcVideoFrameHandle videoFrame, + rtcVideoFrameARGB* dest +) 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, + 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_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_ScaleFromYUV( + rtcVideoFrameHandle dest, + rtcVideoFrameYUV* source, + int* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_Clear( + rtcVideoFrameHandle handle, + rtcVideoFrameClearType clearType, + int* pRetVal +) 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 + +/* + * ---------------------------------------------------------------------- + * 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 + +/* + * ---------------------------------------------------------------------- + * RTCDesktopMediaList interop methods + * ---------------------------------------------------------------------- + */ + +/** + * 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; + +/* + * ---------------------------------------------------------------------- + * 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; + +/* + * ---------------------------------------------------------------------- + * 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, + rtcCaptureState* 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, + rtcCaptureState* 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 + * ---------------------------------------------------------------------- + */ + +/** + * 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, rtcDesktopType type, + rtcDesktopMediaListHandle* pOutRetVal) noexcept; + +#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 + * ---------------------------------------------------------------------- + */ + +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; + +/* + * ---------------------------------------------------------------------- + * 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; + +/* + * ---------------------------------------------------------------------- + * 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; + +/* + * ---------------------------------------------------------------------- + * 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; + +/* + * ---------------------------------------------------------------------- + * 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 + * @param pOutRetVal - Media stream handle + * @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; + +/* + * ---------------------------------------------------------------------- + * 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 + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapabilityList_Create ( + rtcRtpCodecCapabilityHandle* items, + int count, + rtcRtpCodecCapabilityListHandle* pOutRetVal +) noexcept; + +/** + * 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; + +/* + * ---------------------------------------------------------------------- + * 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; + +/* + * ---------------------------------------------------------------------- + * 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 + * ---------------------------------------------------------------------- + */ + +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, + rtcRtpCodecParametersMapHandle* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecParameters_SetParameters ( + rtcRtpCodecParametersHandle handle, + rtcRtpCodecParametersMapHandle 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_Create ( + rtcRtpEncodingParametersHandle* pOutRetVal + ) noexcept; + +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 + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpEncodingParametersList_Create ( + rtcRtpEncodingParametersHandle* items, + int count, + rtcRtpEncodingParametersListHandle* pOutRetVal +) noexcept; + +/** + * 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; + +/* + * ---------------------------------------------------------------------- + * 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; + +/* + * ---------------------------------------------------------------------- + * 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 + * ---------------------------------------------------------------------- + */ + +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 + * ---------------------------------------------------------------------- + */ + +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_GetInitEncodings ( + rtcRtpSenderHandle handle, + rtcRtpEncodingParametersListHandle* pOutRetVal +) 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; + +/* + * ---------------------------------------------------------------------- + * 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 + * ---------------------------------------------------------------------- + */ + +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 + * ---------------------------------------------------------------------- + */ + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCRtpTransceiverInit_Create ( + rtcRtpTransceiverDirection direction, + 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; + +/* + * ---------------------------------------------------------------------- + * 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 + * ---------------------------------------------------------------------- + */ + +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, + rtcObjectHandle user_data, + rtcOnGetSdpSuccessDelegate success, + rtcOnFailureDelegate failure, + rtcMediaConstraintsHandle constraints +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_CreateAnswer ( + rtcPeerConnectionHandle handle, + rtcObjectHandle user_data, + rtcOnGetSdpSuccessDelegate success, + rtcOnFailureDelegate 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, + rtcObjectHandle user_data, + rtcOnSetSdpSuccessDelegate success, + rtcOnFailureDelegate failure +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_SetRemoteDescription ( + rtcPeerConnectionHandle handle, + const char* sdp, + const char* type, + rtcObjectHandle user_data, + rtcOnSetSdpSuccessDelegate success, + rtcOnFailureDelegate failure +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetLocalDescription ( + rtcPeerConnectionHandle handle, + rtcObjectHandle user_data, + rtcOnGetSdpSuccessDelegate success, + rtcOnFailureDelegate failure +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetRemoteDescription ( + rtcPeerConnectionHandle handle, + rtcObjectHandle user_data, + rtcOnGetSdpSuccessDelegate success, + rtcOnFailureDelegate 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, + rtcObjectHandle user_data, + rtcOnStatsCollectorSuccessDelegate success, + rtcOnFailureDelegate failure, + rtcBool32* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetReceiverStats ( + rtcPeerConnectionHandle handle, + rtcRtpReceiverHandle receiver, + rtcObjectHandle user_data, + rtcOnStatsCollectorSuccessDelegate success, + rtcOnFailureDelegate failure, + rtcBool32* pOutRetVal +) noexcept; + +LIB_WEBRTC_API rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetStats ( + rtcPeerConnectionHandle handle, + rtcObjectHandle user_data, + rtcOnStatsCollectorSuccessDelegate success, + rtcOnFailureDelegate 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/interop_macros.h b/include/interop_macros.h new file mode 100644 index 0000000000..b4a9d5af94 --- /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) < 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)); \ + *(out_val) = static_cast(pItem.release()); \ + return rtcResultU4::kSuccess; + +#endif // LIB_WEBRTC_INTROP_MACROS_HXX 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..97cd089b2b --- /dev/null +++ b/include/rtc_audio_data.h @@ -0,0 +1,49 @@ +#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( + uint32_t index, + 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 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; + 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(RTCAudioDataToneFrequency frequency = RTCAudioDataToneFrequency::kNone) = 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_base_list.h b/include/rtc_base_list.h new file mode 100644 index 0000000000..81a2b3ce03 --- /dev/null +++ b/include/rtc_base_list.h @@ -0,0 +1,91 @@ +#ifndef LIB_WEBRTC_RTC_BASE_LIST_HXX +#define LIB_WEBRTC_RTC_BASE_LIST_HXX + +#include "rtc_types.h" + +namespace libwebrtc { + +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; + + 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 { + 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(); } + + 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_desktop_capturer.h b/include/rtc_desktop_capturer.h index 9d2e955ab3..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; /** @@ -86,6 +80,8 @@ class RTCDesktopCapturer : public RefCountInterface { */ virtual scoped_refptr source() = 0; + virtual DesktopCapturerObserver* GetObserver() = 0; + /** * @brief Destroys the RTCDesktopCapturer object. */ @@ -130,7 +126,7 @@ class DesktopCapturerObserver { virtual void OnError(scoped_refptr capturer) = 0; protected: - ~DesktopCapturerObserver() {} + virtual ~DesktopCapturerObserver() {} }; } // namespace libwebrtc 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/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_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_ice_candidate.h b/include/rtc_ice_candidate.h index 82da46edb4..57e5aa5171 100644 --- a/include/rtc_ice_candidate.h +++ b/include/rtc_ice_candidate.h @@ -2,14 +2,15 @@ #define LIB_WEBRTC_RTC_ICE_CANDIDATE_HXX #include "rtc_types.h" +#include "rtc_sdp_parse_error.h" 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, - SdpParseError* error); + RTCSdpParseError* error); public: virtual const string candidate() const = 0; 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_peerconnection.h b/include/rtc_peerconnection.h index 35ea2ad3ea..0354c74a3e 100644 --- a/include/rtc_peerconnection.h +++ b/include/rtc_peerconnection.h @@ -1,8 +1,10 @@ #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" #include "rtc_ice_candidate.h" #include "rtc_media_stream.h" #include "rtc_mediaconstraints.h" @@ -105,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; @@ -118,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; @@ -171,6 +205,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; @@ -264,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_peerconnection_factory.h b/include/rtc_peerconnection_factory.h index cb024672c2..4a6c64a24c 100644 --- a/include/rtc_peerconnection_factory.h +++ b/include/rtc_peerconnection_factory.h @@ -11,6 +11,8 @@ #include "rtc_mediaconstraints.h" #include "rtc_video_device.h" #include "rtc_video_source.h" +#include "rtc_dummy_video_capturer.h" +#include "rtc_dummy_audio_source.h" namespace libwebrtc { @@ -21,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; @@ -40,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; @@ -49,9 +57,17 @@ 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; + virtual scoped_refptr CreateAudioTrack( + scoped_refptr source, const string track_id) = 0; + virtual scoped_refptr CreateVideoTrack( scoped_refptr source, const string track_id) = 0; @@ -63,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_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_parameters.h b/include/rtc_rtp_parameters.h index 3ef87155d5..d6393aa086 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; @@ -99,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; @@ -130,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; @@ -138,6 +220,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 +254,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 +321,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/include/rtc_rtp_receiver.h b/include/rtc_rtp_receiver.h index a72f2b8a06..9ebde332f6 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( @@ -56,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/include/rtc_sdp_parse_error.h b/include/rtc_sdp_parse_error.h new file mode 100644 index 0000000000..af8e43099f --- /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: + LIB_WEBRTC_API static 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..ae8ec3a9e5 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 { @@ -9,8 +10,8 @@ class RTCSessionDescription : public RefCountInterface { public: enum SdpType { kOffer = 0, kPrAnswer, kAnswer }; - static LIB_WEBRTC_API scoped_refptr Create( - const string type, const string sdp, SdpParseError* error); + LIB_WEBRTC_API static scoped_refptr Create( + 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..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 }; @@ -30,6 +36,36 @@ 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 }; + +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, + kTone440Hz = 440, + kTone1kHz = 1000, + kTone2kHz = 2000, + kTone5kHz = 5000 +}; + +enum class RTCVideoFrameClearType { + kNone = 0, // Clear video buffer + kNoise, + kColorBar +}; + using string = portable::string; // template @@ -98,16 +134,36 @@ 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 }; +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 a69023f052..3a5b5fccf3 100644 --- a/include/rtc_video_frame.h +++ b/include/rtc_video_frame.h @@ -7,8 +7,6 @@ namespace libwebrtc { class RTCVideoFrame : public RefCountInterface { public: - enum class Type { kARGB, kBGRA, kABGR, kRGBA }; - enum VideoRotation { kVideoRotation_0 = 0, kVideoRotation_90 = 90, @@ -17,6 +15,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); @@ -30,6 +31,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; @@ -44,8 +46,19 @@ class RTCVideoFrame : public RefCountInterface { virtual int StrideU() const = 0; virtual int StrideV() const = 0; - virtual int ConvertToARGB(Type type, uint8_t* dst_argb, int dst_stride_argb, - int dest_width, int dest_height) = 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(RTCVideoFrameARGB* pDest) = 0; + + virtual int ScaleFrom(scoped_refptr source) = 0; + + virtual int ScaleFrom(RTCVideoFrameARGB* source) = 0; + + virtual int ScaleFrom(RTCVideoFrameYUV* source) = 0; + + virtual int Clear(RTCVideoFrameClearType clearType) = 0; protected: virtual ~RTCVideoFrame() {} diff --git a/include/rtc_video_renderer.h b/include/rtc_video_renderer.h index 7e81d463f6..0ff08a7637 100644 --- a/include/rtc_video_renderer.h +++ b/include/rtc_video_renderer.h @@ -6,11 +6,21 @@ namespace libwebrtc { template -class RTCVideoRenderer { +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: + LIB_WEBRTC_API static scoped_refptr> Create(); }; } // namespace libwebrtc 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..799fe2e527 --- /dev/null +++ b/src/internal/audio_util.h @@ -0,0 +1,23 @@ +#ifndef LIB_WEBRTC_AUDIO_UTIL_HXX +#define LIB_WEBRTC_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 // LIB_WEBRTC_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..dec7335886 --- /dev/null +++ b/src/internal/dummy_audio_capturer.cc @@ -0,0 +1,167 @@ +#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, + 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) + , 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_; + } + + sample_index_ = 0; + 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 + ( + sample_index_++, + 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(libwebrtc::RTCAudioDataToneFrequency::kTone1kHz); // 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..3455157963 --- /dev/null +++ b/src/internal/dummy_audio_capturer.h @@ -0,0 +1,111 @@ +#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, + const std::string name + ); + + 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_; } + + const char* name() const { return name_.c_str(); } + + 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; + std::string name_; + uint32_t sample_index_ = 0; + 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 new file mode 100644 index 0000000000..7344ac5617 --- /dev/null +++ b/src/internal/dummy_capturer.cc @@ -0,0 +1,3 @@ +#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 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/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 new file mode 100644 index 0000000000..e329b42eeb --- /dev/null +++ b/src/interop/libwebrtc_interop.cc @@ -0,0 +1,111 @@ +#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( + rtcBool32 use_dummy_audio /*= rtcBool32::kFalse*/ +) noexcept +{ + scoped_refptr p = + LibWebRTC::CreateRTCPeerConnectionFactory(use_dummy_audio != rtcBool32::kFalse); + return static_cast(p.release()); +} + +void LIB_WEBRTC_CALL LibWebRTC_Terminate() noexcept +{ + LibWebRTC::Terminate(); +} + +rtcResultU4 LIB_WEBRTC_CALL +LibWebRTC_GetErrorMessage( + rtcResultU4 code, + char* pBuffer, + unsigned int sizeOfBuffer +) noexcept +{ + CHECK_POINTER(pBuffer); + if (sizeOfBuffer == 0) { + return rtcResultU4::kBufferTooSmall; + } + ZERO_MEMORY(pBuffer, sizeOfBuffer); + + char szTemp[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::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; + default: + snprintf(szTemp, sizeof(szTemp), "Undefined error: 0x%X", static_cast(code)); + message = szTemp; + break; + } + + string strMessage(message); + size_t len = strMessage.copy_to(pBuffer, static_cast(sizeOfBuffer)); + + return strMessage.size() > len + ? rtcResultU4::kBufferTooSmall + : rtcResultU4::kSuccess; +} diff --git a/src/interop/ref_counted_object_interop.cc b/src/interop/ref_counted_object_interop.cc new file mode 100644 index 0000000000..16a2cc3924 --- /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 == nullptr) { + return -1; + } + RefCountInterface* p = static_cast(handle); + return p->AddRef(); +} + +int LIB_WEBRTC_CALL RefCountedObject_Release(rtcRefCountedObjectHandle handle) noexcept +{ + if (handle == nullptr) { + return -1; + } + RefCountInterface* p = static_cast(handle); + return p->Release(); +} \ No newline at end of file diff --git a/src/interop/rtc_audio_data_interop.cc b/src/interop/rtc_audio_data_interop.cc new file mode 100644 index 0000000000..e28b49b3c7 --- /dev/null +++ b/src/interop/rtc_audio_data_interop.cc @@ -0,0 +1,136 @@ +#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_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, + 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_audio_device_interop.cc b/src/interop/rtc_audio_device_interop.cc new file mode 100644 index 0000000000..3ad59afc85 --- /dev/null +++ b/src/interop/rtc_audio_device_interop.cc @@ -0,0 +1,239 @@ +#include "rtc_audio_device.h" +#include "interop_api.h" + +using namespace libwebrtc; + +/* + * ---------------------------------------------------------------------- + * RTCAudioDevice interop methods + * ---------------------------------------------------------------------- + */ + +int LIB_WEBRTC_CALL +RTCAudioDevice_PlayoutDevices( + rtcAudioDeviceHandle audiDevice +) noexcept +{ + CHECK_POINTER_EX(audiDevice, 0); + scoped_refptr pAudioDevice = static_cast(audiDevice); + return static_cast(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 static_cast(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; + } + + size_t len; + string strName(szName); + string strGuid(szGuid); + + len = strName.copy_to(pOutName, static_cast(cchOutName)); + if (strName.size() > len) { + result = rtcResultU4::kBufferTooSmall; + } + + len = strGuid.copy_to(pOutGuid, static_cast(cchOutGuid)); + if (strGuid.size() > len) { + result = rtcResultU4::kBufferTooSmall; + } + + 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; + } + + size_t len; + string strName(szName); + string strGuid(szGuid); + + len = strName.copy_to(pOutName, static_cast(cchOutName)); + if (strName.size() > len) { + result = rtcResultU4::kBufferTooSmall; + } + + len = strGuid.copy_to(pOutGuid, static_cast(cchOutGuid)); + if (strGuid.size() > len) { + result = rtcResultU4::kBufferTooSmall; + } + + return result; +} // end RTCAudioDevice_RecordingDeviceName + +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_SetPlayoutDevice( + rtcAudioDeviceHandle audiDevice, + int index +) noexcept +{ + CHECK_NATIVE_HANDLE(audiDevice); + if (index < 1) { + return rtcResultU4::kOutOfRange; + } + + scoped_refptr pAudioDevice = static_cast(audiDevice); + int nCount = (int)pAudioDevice->PlayoutDevices(); + if (index >= nCount) { + return rtcResultU4::kOutOfRange; + } + return static_cast(pAudioDevice->SetPlayoutDevice((uint16_t)index)); +} // end RTCAudioDevice_SetPlayoutDevice + +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_SetRecordingDevice( + rtcAudioDeviceHandle audiDevice, + int index +) noexcept +{ + CHECK_NATIVE_HANDLE(audiDevice); + if (index < 0) { + return rtcResultU4::kOutOfRange; + } + + scoped_refptr pAudioDevice = static_cast(audiDevice); + int nCount = (int)pAudioDevice->RecordingDevices(); + if (index >= nCount) { + return rtcResultU4::kOutOfRange; + } + return static_cast(pAudioDevice->SetRecordingDevice((uint16_t)index)); +} // end RTCAudioDevice_SetRecordingDevice + +rtcResultU4 LIB_WEBRTC_CALL +RTCAudioDevice_RegisterDeviceChangeCallback( + rtcAudioDeviceHandle audiDevice, + rtcObjectHandle userData, + rtcAudioDeviceChangeDelegate callback +) noexcept +{ + CHECK_NATIVE_HANDLE(audiDevice); + + scoped_refptr pAudioDevice = static_cast(audiDevice); + RTCAudioDevice::OnDeviceChangeCallback cb; + if (callback == nullptr) { + cb = nullptr; + } + else { + cb = [callback, userData](void) { + if (callback) { + callback(userData); + } + }; + } + + 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, + unsigned int volume +) noexcept +{ + CHECK_NATIVE_HANDLE(audiDevice); + scoped_refptr pAudioDevice = static_cast(audiDevice); + return static_cast(pAudioDevice->SetMicrophoneVolume(volume)); +} // 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); + return static_cast(pAudioDevice->MicrophoneVolume(*volume)); +} // 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); + return static_cast(pAudioDevice->SetSpeakerVolume(volume)); +} // 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); + return static_cast(pAudioDevice->SpeakerVolume(*volume)); +} // end RTCAudioDevice_GetSpeakerVolume 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_data_channel_interop.cc b/src/interop/rtc_data_channel_interop.cc new file mode 100644 index 0000000000..9b923ce775 --- /dev/null +++ b/src/interop/rtc_data_channel_interop.cc @@ -0,0 +1,102 @@ +#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); + + // unregistered + RTCDataChannel_UnregisterObserver(dataChannel); + + 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 +{ + DECLARE_GET_STRING(dataChannel, label, label_size, RTCDataChannel, label); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDataChannel_GetId( + rtcDataChannelHandle dataChannel, + int* id +) noexcept +{ + DECLARE_GET_VALUE(dataChannel, id, int, RTCDataChannel, id); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCDataChannel_GetState( + rtcDataChannelHandle dataChannel, + rtcDataChannelState* state +) noexcept +{ + DECLARE_GET_VALUE(dataChannel, state, rtcDataChannelState, RTCDataChannel, state); +} \ No newline at end of file diff --git a/src/interop/rtc_desktop_capturer_interop.cc b/src/interop/rtc_desktop_capturer_interop.cc new file mode 100644 index 0000000000..e685b28381 --- /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, + rtcCaptureState* pOutRetVal +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER(pOutRetVal); + *pOutRetVal = rtcCaptureState::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, + rtcCaptureState* pOutRetVal +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER(pOutRetVal); + *pOutRetVal = rtcCaptureState::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/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 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..0a60c9d11b --- /dev/null +++ b/src/interop/rtc_desktop_media_list_interop.cc @@ -0,0 +1,207 @@ +#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 + +/* + * ---------------------------------------------------------------------- + * RTCDesktopMediaList interop methods + * ---------------------------------------------------------------------- + */ + +rtcResultU4 LIB_WEBRTC_CALL +RTCDesktopMediaList_RegisterMediaListObserver( + rtcDesktopMediaListHandle hMediaList, + rtcMediaListObserverCallbacks* callbacks +) noexcept +{ + 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); + 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; +} + +/* + * ---------------------------------------------------------------------- + * 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); + ZERO_MEMORY(pOutId, cchOutId); + ZERO_MEMORY(pOutName, cchOutName); + 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) { + szTmp = pMediaSource->id(); + cchLen = szTmp.copy_to(pOutId, static_cast(cchOutId)); + if (szTmp.size() > cchLen) { + result = rtcResultU4::kBufferTooSmall; + } + } + + if (pOutName && cchOutName > 0) { + szTmp = pMediaSource->name(); + cchLen = szTmp.copy_to(pOutName, static_cast(cchOutName)); + if (szTmp.size() > cchLen) { + result = rtcResultU4::kBufferTooSmall; + } + } + + 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); + CHECK_POINTER(refSizeOfBuffer); + size_t sizeOfBuffer = 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 && szSrcSize > 0) { + if (szSrcSize > sizeOfBuffer) { + return rtcResultU4::kBufferTooSmall; + } + memcpy((void*)pBuffer, (const void*)buffer.data(), szSrcSize); + } + return rtcResultU4::kSuccess; +} + +#endif // RTC_DESKTOP_DEVICE 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/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_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_ice_candidate_interop.cc b/src/interop/rtc_ice_candidate_interop.cc new file mode 100644 index 0000000000..70711e232c --- /dev/null +++ b/src/interop/rtc_ice_candidate_interop.cc @@ -0,0 +1,61 @@ +#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 +{ + DECLARE_GET_STRING(iceCandidate, value, sz_value, RTCIceCandidate, candidate); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCIceCandidate_GetSdpMid( + rtcIceCandidateHandle iceCandidate, + char* value, + int sz_value +) noexcept +{ + DECLARE_GET_STRING(iceCandidate, value, sz_value, RTCIceCandidate, sdp_mid); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCIceCandidate_GetSdpMlineIndex( + rtcIceCandidateHandle iceCandidate, + int* pOutRetVal +) noexcept +{ + 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 new file mode 100644 index 0000000000..692173ad49 --- /dev/null +++ b/src/interop/rtc_media_stream_interop.cc @@ -0,0 +1,210 @@ +#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 +{ + DECLARE_GET_STRING(mediaStream, value, sz_value, RTCMediaStream, label); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCMediaStream_GetId ( + rtcMediaStreamHandle mediaStream, + char* value, + int sz_value +) noexcept +{ + DECLARE_GET_STRING(mediaStream, value, sz_value, RTCMediaStream, id); +} + +int LIB_WEBRTC_CALL +RTCMediaStreamList_GetCount ( + rtcMediaStreamListHandle handle +) noexcept +{ + DECLARE_LIST_GET_COUNT(handle, RTCMediaStreamList); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCMediaStreamList_GetItem ( + rtcMediaStreamListHandle mediaStreamList, + int index, + rtcMediaStreamHandle* pOutRetVal +) noexcept +{ + 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 new file mode 100644 index 0000000000..c60af0cefe --- /dev/null +++ b/src/interop/rtc_media_track_interop.cc @@ -0,0 +1,59 @@ +#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 +{ + DECLARE_GET_STRING(mediaTrack, pOutKind, cchOutKind, RTCMediaTrack, kind); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCMediaTrack_GetId( + rtcMediaTrackHandle mediaTrack, + char* pOutId, + int cchOutId +) noexcept +{ + DECLARE_GET_STRING(mediaTrack, pOutId, cchOutId, RTCMediaTrack, id); +} + +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_mediaconstraints_interop.cc b/src/interop/rtc_mediaconstraints_interop.cc new file mode 100644 index 0000000000..8e6965823a --- /dev/null +++ b/src/interop/rtc_mediaconstraints_interop.cc @@ -0,0 +1,44 @@ +#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()); +} + +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 new file mode 100644 index 0000000000..8c06349bc5 --- /dev/null +++ b/src/interop/rtc_peerconnection_factory_interop.cc @@ -0,0 +1,420 @@ +#include "src/rtc_mediaconstraints_impl.h" +#include "src/rtc_peerconnection_factory_impl.h" + +#include "interop_api.h" + +using namespace libwebrtc; + +RTCConfiguration CreateRtcConfiguration(const rtcPeerConnectionConfiguration* configuration) +{ + 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); + 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; + 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; +} + +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, + rtcBool32 use_dummy_audio /*= rtcBool32::kFalse*/ +) noexcept +{ + CHECK_POINTER_EX(factory, rtcBool32::kFalse); + + scoped_refptr pFactory = static_cast(factory); + return pFactory->Initialize(use_dummy_audio != rtcBool32::kFalse) + ? rtcBool32::kTrue + : rtcBool32::kFalse; +} // end RTCPeerConnectionFactory_Initialize + +rtcBool32 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_Terminate( + rtcPeerConnectionFactoryHandle factory +) noexcept +{ + CHECK_POINTER_EX(factory, rtcBool32::kFalse); + + scoped_refptr pFactory = static_cast(factory); + return pFactory->Terminate() + ? rtcBool32::kTrue + : rtcBool32::kFalse; +} // end RTCPeerConnectionFactory_Terminate + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_CreatePeerConnection( + 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_CreatePeerConnection + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_DeletePeerConnection( + 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_DeletePeerConnection + +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(audio_source_label)); + + *pRetVal = static_cast(audio_source.release()); + 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, + 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(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(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_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, + 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(track_id)); + + *pRetVal = static_cast(audio_track.release()); + 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, + 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(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(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 + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnectionFactory_GetUseDummyAudio( + rtcPeerConnectionFactoryHandle factory, + rtcBool32* pRetVal +) noexcept +{ + DECLARE_GET_VALUE(factory, pRetVal, rtcBool32, RTCPeerConnectionFactory, GetUseDummyAudio); +} diff --git a/src/interop/rtc_peerconnection_interop.cc b/src/interop/rtc_peerconnection_interop.cc new file mode 100644 index 0000000000..08d6c11356 --- /dev/null +++ b/src/interop/rtc_peerconnection_interop.cc @@ -0,0 +1,638 @@ +#include "rtc_peerconnection.h" +#include "src/rtc_peerconnection_impl.h" +#include "interop_api.h" + +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, + 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, + rtcObjectHandle user_data, + rtcOnGetSdpSuccessDelegate success, + rtcOnFailureDelegate 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, user_data](const string sdp, const string type) { + success(user_data, sdp.c_string(), type.c_string()); + }; + 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); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_CreateAnswer ( + rtcPeerConnectionHandle handle, + rtcObjectHandle user_data, + rtcOnGetSdpSuccessDelegate success, + rtcOnFailureDelegate 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, user_data](const string sdp, const string type) { + success(user_data, sdp.c_string(), type.c_string()); + }; + 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); + 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, + rtcObjectHandle user_data, + rtcOnSetSdpSuccessDelegate success, + rtcOnFailureDelegate failure +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); + + OnSetSdpSuccess fn_success = [success, user_data]() { + success(user_data); + }; + 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); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_SetRemoteDescription ( + rtcPeerConnectionHandle handle, + const char* sdp, + const char* type, + rtcObjectHandle user_data, + rtcOnSetSdpSuccessDelegate success, + rtcOnFailureDelegate failure +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); + + OnSetSdpSuccess fn_success = [success, user_data]() { + success(user_data); + }; + 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); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetLocalDescription ( + rtcPeerConnectionHandle handle, + rtcObjectHandle user_data, + rtcOnGetSdpSuccessDelegate success, + rtcOnFailureDelegate failure +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); + + OnGetSdpSuccess fn_success = [success, user_data](const char* sdp, const char* type) { + success(user_data, sdp, type); + }; + 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); + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCPeerConnection_GetRemoteDescription ( + rtcPeerConnectionHandle handle, + rtcObjectHandle user_data, + rtcOnGetSdpSuccessDelegate success, + rtcOnFailureDelegate failure +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + CHECK_POINTER_EX(success, rtcResultU4::kInvalidParameter); + CHECK_POINTER_EX(failure, rtcResultU4::kInvalidParameter); + + OnGetSdpSuccess fn_success = [success, user_data](const char* sdp, const char* type) { + success(user_data, sdp, type); + }; + 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); + 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, + rtcObjectHandle user_data, + rtcOnStatsCollectorSuccessDelegate success, + rtcOnFailureDelegate 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, user_data](const vector> reports) { + scoped_refptr pList = MediaRTCStatsList::Create(reports); + success( + user_data, + static_cast(pList.release()) + ); + }; + 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); + 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, + rtcObjectHandle user_data, + rtcOnStatsCollectorSuccessDelegate success, + rtcOnFailureDelegate 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, user_data](const vector> reports) { + scoped_refptr pList = MediaRTCStatsList::Create(reports); + success( + user_data, + static_cast(pList.release()) + ); + }; + 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); + 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, + rtcObjectHandle user_data, + rtcOnStatsCollectorSuccessDelegate success, + rtcOnFailureDelegate failure +) noexcept +{ + CHECK_NATIVE_HANDLE(handle); + 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 = [failure, user_data](const char* error) { + failure(user_data, 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/interop/rtc_rtp_capabilities_interop.cc b/src/interop/rtc_rtp_capabilities_interop.cc new file mode 100644 index 0000000000..58418dde35 --- /dev/null +++ b/src/interop/rtc_rtp_capabilities_interop.cc @@ -0,0 +1,273 @@ +#include "rtc_rtp_capabilities.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 +{ + DECLARE_GET_STRING(handle, value, sz_value, RTCRtpCodecCapability, mime_type); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_SetMimeType( + rtcRtpCodecCapabilityHandle handle, + const char* value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, string, RTCRtpCodecCapability, set_mime_type); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_GetClockRate( + rtcRtpCodecCapabilityHandle handle, + int* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCRtpCodecCapability, clock_rate); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_SetClockRate( + rtcRtpCodecCapabilityHandle handle, + int value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, int, RTCRtpCodecCapability, set_clock_rate); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_GetChannels( + rtcRtpCodecCapabilityHandle handle, + int* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCRtpCodecCapability, channels); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_SetChannels( + rtcRtpCodecCapabilityHandle handle, + int value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, int, RTCRtpCodecCapability, set_channels); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_GetSdpFmtpLine( + rtcRtpCodecCapabilityHandle handle, + char* value, + int sz_value +) noexcept +{ + DECLARE_GET_STRING(handle, value, sz_value, RTCRtpCodecCapability, sdp_fmtp_line); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapability_SetSdpFmtpLine( + rtcRtpCodecCapabilityHandle handle, + const char* value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, string, RTCRtpCodecCapability, set_sdp_fmtp_line); +} + +/* + * ---------------------------------------------------------------------- + * RTCRtpCodecCapabilityList interop methods + * ---------------------------------------------------------------------- + */ + +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 +) noexcept +{ + DECLARE_LIST_GET_COUNT(handle, RTCRtpCodecCapabilityList); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCodecCapabilityList_GetItem ( + rtcRtpCodecCapabilityListHandle handle, + int index, + rtcRtpCodecCapabilityHandle* pOutRetVal +) noexcept +{ + DECLARE_LIST_GET_ITEM(handle, index, pOutRetVal, rtcRtpCodecCapabilityHandle, RTCRtpCodecCapabilityList, RTCRtpCodecCapability); +} + +/* + * ---------------------------------------------------------------------- + * RTCRtpHeaderExtensionCapability interop methods + * ---------------------------------------------------------------------- + */ + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapability_GetUri( + rtcRtpHeaderExtensionCapabilityHandle handle, + char* value, + int sz_value +) noexcept +{ + DECLARE_GET_STRING(handle, value, sz_value, RTCRtpHeaderExtensionCapability, uri); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapability_SetUri( + rtcRtpHeaderExtensionCapabilityHandle handle, + const char* value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, string, RTCRtpHeaderExtensionCapability, set_uri); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapability_GetPreferredId( + rtcRtpHeaderExtensionCapabilityHandle handle, + int* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCRtpHeaderExtensionCapability, preferred_id); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapability_SetPreferredId( + rtcRtpHeaderExtensionCapabilityHandle handle, + int value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, int, RTCRtpHeaderExtensionCapability, set_preferred_id); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapability_GetPreferredEncrypt( + rtcRtpHeaderExtensionCapabilityHandle handle, + rtcBool32* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, rtcBool32, RTCRtpHeaderExtensionCapability, preferred_encrypt); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapability_SetPreferredEncrypt( + rtcRtpHeaderExtensionCapabilityHandle handle, + rtcBool32 value +) noexcept +{ + DECLARE_SET_VALUE(handle, value, bool, RTCRtpHeaderExtensionCapability, set_preferred_encrypt); +} + +/* + * ---------------------------------------------------------------------- + * RTCRtpHeaderExtensionCapabilityList interop methods + * ---------------------------------------------------------------------- + */ + +int LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapabilityList_GetCount ( + rtcRtpHeaderExtensionCapabilityListHandle handle +) noexcept +{ + DECLARE_LIST_GET_COUNT(handle, RTCRtpHeaderExtensionCapabilityList); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpHeaderExtensionCapabilityList_GetItem ( + rtcRtpHeaderExtensionCapabilityListHandle handle, + int index, + rtcRtpHeaderExtensionCapabilityHandle* pOutRetVal +) noexcept +{ + DECLARE_LIST_GET_ITEM(handle, index, pOutRetVal, rtcRtpHeaderExtensionCapabilityHandle, RTCRtpHeaderExtensionCapabilityList, RTCRtpHeaderExtensionCapability); +} + +/* + * ---------------------------------------------------------------------- + * RTCRtpCapabilities interop methods + * ---------------------------------------------------------------------- + */ + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCapabilities_GetCodecs( + rtcRtpCapabilitiesHandle handle, + rtcRtpCodecCapabilityListHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_LIST_HANDLE(handle, pOutRetVal, rtcRtpCodecCapabilityListHandle, RTCRtpCapabilities, RTCRtpCodecCapabilityList, codecs); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCapabilities_SetCodecs( + rtcRtpCapabilitiesHandle handle, + rtcRtpCodecCapabilityListHandle hCodecs +) noexcept +{ + DECLARE_SET_LIST_HANDLE(handle, hCodecs, RTCRtpCapabilities, RTCRtpCodecCapabilityList, set_codecs); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCapabilities_GetHeaderExtensions( + rtcRtpCapabilitiesHandle handle, + rtcRtpHeaderExtensionCapabilityListHandle* pOutRetVal +) noexcept +{ + DECLARE_GET_LIST_HANDLE(handle, pOutRetVal, rtcRtpHeaderExtensionCapabilityListHandle, RTCRtpCapabilities, RTCRtpHeaderExtensionCapabilityList, header_extensions); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCRtpCapabilities_SetHeaderExtensions( + rtcRtpCapabilitiesHandle handle, + rtcRtpHeaderExtensionCapabilityListHandle hHeaderExtensions +) noexcept +{ + 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..87a8735203 --- /dev/null +++ b/src/interop/rtc_rtp_parameters_interop.cc @@ -0,0 +1,1011 @@ +#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); +} + +/* + * ---------------------------------------------------------------------- + * 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 + * ---------------------------------------------------------------------- + */ + +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, + rtcRtpCodecParametersMapHandle* pOutRetVal +) noexcept +{ + 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 +RTCRtpCodecParameters_SetParameters ( + rtcRtpCodecParametersHandle handle, + rtcRtpCodecParametersMapHandle value +) noexcept +{ + 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; +} + +/* + * ---------------------------------------------------------------------- + * 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_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, + 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 + * ---------------------------------------------------------------------- + */ + +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 +) 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_rtp_receiver_interop.cc b/src/interop/rtc_rtp_receiver_interop.cc new file mode 100644 index 0000000000..4bb87782f8 --- /dev/null +++ b/src/interop/rtc_rtp_receiver_interop.cc @@ -0,0 +1,157 @@ +#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; + +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); +} + +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); + + 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 +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); +} + +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 new file mode 100644 index 0000000000..c69b840f5d --- /dev/null +++ b/src/interop/rtc_rtp_sender_interop.cc @@ -0,0 +1,152 @@ +#include "rtc_rtp_sender.h" +#include "interop_api.h" +#include "rtc_media_track.h" +#include "rtc_dtmf_sender.h" +#include "rtc_dtls_transport.h" + +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); + + 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 +RTCRtpSender_SetStreamIds ( + rtcRtpSenderHandle 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 +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); +} + +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 new file mode 100644 index 0000000000..56bf24e4c8 --- /dev/null +++ b/src/interop/rtc_rtp_transceiver_interop.cc @@ -0,0 +1,266 @@ +#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); +} + +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/interop/rtc_sdp_parse_error_interop.cc b/src/interop/rtc_sdp_parse_error_interop.cc new file mode 100644 index 0000000000..33608f40ba --- /dev/null +++ b/src/interop/rtc_sdp_parse_error_interop.cc @@ -0,0 +1,55 @@ +#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 +{ + DECLARE_GET_STRING(sdpParseError, value, sz_value, RTCSdpParseError, line); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCSdpParseError_SetLine( + rtcSdpParseErrorHandle sdpParseError, + const char* value +) noexcept +{ + DECLARE_SET_VALUE(sdpParseError, value, string, RTCSdpParseError, set_line); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCSdpParseError_GetDescription( + rtcSdpParseErrorHandle sdpParseError, + char* value, + int sz_value +) noexcept +{ + DECLARE_GET_STRING(sdpParseError, value, sz_value, RTCSdpParseError, description); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCSdpParseError_SetDescription( + rtcSdpParseErrorHandle sdpParseError, + const char* value +) noexcept +{ + DECLARE_SET_VALUE(sdpParseError, value, string, RTCSdpParseError, set_description); +} diff --git a/src/interop/rtc_video_device_interop.cc b/src/interop/rtc_video_device_interop.cc new file mode 100644 index 0000000000..4ece7b5637 --- /dev/null +++ b/src/interop/rtc_video_device_interop.cc @@ -0,0 +1,115 @@ +#include "rtc_video_device.h" +#include "interop_api.h" + +using namespace libwebrtc; + +/* + * ---------------------------------------------------------------------- + * RTCVideoDevice interop methods + * ---------------------------------------------------------------------- + */ + +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 = static_cast(pVideoDevice->GetDeviceName( + static_cast(index), + pOutDeviceNameUTF8, static_cast(cchOutDeviceNameUTF8), + pOutDeviceUniqueIdUTF8, static_cast(cchOutDeviceUniqueIdUTF8), + pOutProductUniqueIdUTF8, static_cast(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, + static_cast(index), + static_cast(width), + static_cast(height), + static_cast(target_fps) + ); + if (pVideoCapturer == nullptr) { + return rtcResultU4::kUnknownError; + } + *pOutRetVal = static_cast(pVideoCapturer.release()); + return rtcResultU4::kSuccess; +} + +/* + * ---------------------------------------------------------------------- + * RTCVideoCapturer interop methods + * ---------------------------------------------------------------------- + */ + +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; +} diff --git a/src/interop/rtc_video_frame_interop.cc b/src/interop/rtc_video_frame_interop.cc new file mode 100644 index 0000000000..a38e6e23a6 --- /dev/null +++ b/src/interop/rtc_video_frame_interop.cc @@ -0,0 +1,381 @@ +#include "rtc_video_frame.h" +#include "interop_api.h" + +using namespace libwebrtc; + +/* + * ---------------------------------------------------------------------- + * RTCVideoFrame interop methods + * ---------------------------------------------------------------------- + */ + +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, + 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 * 3) / 2; + 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( + 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 (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( + 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()); + 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_GetWidth( + rtcVideoFrameHandle handle, + int* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(handle, pOutRetVal, int, RTCVideoFrame, width); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_GetHeight( + rtcVideoFrameHandle handle, + int* pOutRetVal +) noexcept +{ + 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, + 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, + rtcVideoRotation* pOutRetVal +) noexcept +{ + DECLARE_GET_VALUE(videoFrame, pOutRetVal, rtcVideoRotation, RTCVideoFrame, rotation); +} + +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 +{ + DECLARE_SET_VALUE(videoFrame, timestampInMicroseconds, int64_t, RTCVideoFrame, set_timestamp_us); +} + +int LIB_WEBRTC_CALL +RTCVideoFrame_ConvertToARGB( + rtcVideoFrameHandle videoFrame, + rtcVideoFrameARGB* dest +) noexcept +{ + CHECK_POINTER_EX(videoFrame, 0); + 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( + reinterpret_cast(dest) + ); +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_ScaleFrom( + rtcVideoFrameHandle dest, + rtcVideoFrameHandle source, + int* pOutRetVal +) noexcept +{ + CHECK_NATIVE_HANDLE(dest); + CHECK_NATIVE_HANDLE(source); + + scoped_refptr pDst = static_cast(dest); + scoped_refptr pSrc = static_cast(source); + int buffer_size = pDst->ScaleFrom(pSrc); + if (pOutRetVal) { + *pOutRetVal = buffer_size; + } + return rtcResultU4::kSuccess; +} + +rtcResultU4 LIB_WEBRTC_CALL +RTCVideoFrame_ScaleFromARGB( + rtcVideoFrameHandle dest, + rtcVideoFrameARGB* source, + int* pOutRetVal +) noexcept +{ + CHECK_NATIVE_HANDLE(dest); + 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; + } + + switch (source->type) + { + case rtcVideoFrameTypeARGB::kARGB: + case rtcVideoFrameTypeARGB::kBGRA: + case rtcVideoFrameTypeARGB::kABGR: + case rtcVideoFrameTypeARGB::kRGBA: + break; + 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(reinterpret_cast(source)); + if (pOutRetVal) { + *pOutRetVal = buffer_size; + } + 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/interop/rtc_video_renderer_interop.cc b/src/interop/rtc_video_renderer_interop.cc new file mode 100644 index 0000000000..5f40af489b --- /dev/null +++ b/src/interop/rtc_video_renderer_interop.cc @@ -0,0 +1,67 @@ +#include "rtc_video_renderer.h" +#include "rtc_video_frame.h" +#include "interop_api.h" + +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/interop/rtc_video_track_interop.cc b/src/interop/rtc_video_track_interop.cc new file mode 100644 index 0000000000..c0c45429bf --- /dev/null +++ b/src/interop/rtc_video_track_interop.cc @@ -0,0 +1,38 @@ +#include "rtc_video_track.h" +#include "interop_api.h" +#include "rtc_video_frame.h" +#include "rtc_video_renderer.h" + +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; +} 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..b5db929876 --- /dev/null +++ b/src/rtc_audio_data_impl.cc @@ -0,0 +1,173 @@ +#include "rtc_audio_data_impl.h" +#include "rtc_base/checks.h" +#include "src/internal/audio_util.h" + +namespace libwebrtc { + +double RTC_PI = 3.14159265358979323846; + +/** + * class RTCAudioData + */ + +scoped_refptr RTCAudioData::Create( + uint32_t index, + 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( + index, + data, + bits_per_sample, + sample_rate_hz, + num_channels + ) + ); + return audio_data; +} + +scoped_refptr RTCAudioData::Create() { + return RTCAudioData::Create( + 0, // index + nullptr, // data + 16, // 16 bits + 44100, // sample_rate in Hz + 2 // num_channels + ); +} + +/** + * class RTCAudioDataImpl + */ + +RTCAudioDataImpl::RTCAudioDataImpl( + uint32_t index, + const uint8_t* data, + uint32_t bits_per_sample, + int sample_rate_hz, + uint32_t num_channels +) : 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) + , 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(RTCAudioDataToneFrequency frequency /*= RTCAudioDataToneFrequency::kNone*/) { + if (data_size_ == 0) { + return 0; + } + + 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(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; + } + } + } + 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(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); + 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(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; + } + } + } + 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..91998a1cc9 --- /dev/null +++ b/src/rtc_audio_data_impl.h @@ -0,0 +1,50 @@ +#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( + uint32_t index, + const uint8_t* data, + uint32_t bits_per_sample, + int sample_rate_hz, + uint32_t num_channels + ); + virtual ~RTCAudioDataImpl(); + + 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_; } + 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(RTCAudioDataToneFrequency frequency = RTCAudioDataToneFrequency::kNone) override; + + private: + uint32_t index_; + 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_data_channel_impl.cc b/src/rtc_data_channel_impl.cc index 1d2bedfd5b..9bd181bc04 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 = reinterpret_cast(callbacks_); + pCallbacks->StateChanged( + pCallbacks->UserData, + static_cast(state)); + } +} + +void RTCDataChannelObserverImpl::OnMessage(const char* buffer, int length, bool binary) +{ + if (callbacks_) { + rtcDataChannelObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + pCallbacks->MessageReceived( + pCallbacks->UserData, + 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_capturer_impl.cc b/src/rtc_desktop_capturer_impl.cc index 93dec6d38d..b752645537 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) @@ -63,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; @@ -76,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_; } @@ -95,22 +155,24 @@ 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]() { observer_->OnStart(this); }); + signaling_thread_->BlockingCall([&, this]() { + if (observer_) { observer_->OnStart(this); } + }); } return capture_state_; } @@ -118,16 +180,18 @@ 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); } } - 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 @@ -142,18 +206,20 @@ 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; + capture_state_ = RTCCaptureState::CS_FAILED; return; } 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; } @@ -161,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); } + }); } } } @@ -212,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 7ae63f546b..c14912057a 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 { @@ -47,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; @@ -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, @@ -69,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_desktop_media_list_impl.cc b/src/rtc_desktop_media_list_impl.cc index 68aa783834..3d0c8bc5b7 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_(nullptr) +{ + 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 = reinterpret_cast(callbacks_); + rtcDesktopMediaSourceHandle pSource = static_cast(source.release()); + pCallbacks->MediaSourceAdded(pCallbacks->UserData, pSource); + } +} + +void MediaListObserverImpl::OnMediaSourceRemoved(scoped_refptr source) +{ + if (callbacks_) { + rtcMediaListObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + rtcDesktopMediaSourceHandle pSource = static_cast(source.release()); + pCallbacks->MediaSourceRemoved(pCallbacks->UserData, pSource); + } +} + +void MediaListObserverImpl::OnMediaSourceNameChanged(scoped_refptr source) +{ + if (callbacks_) { + rtcMediaListObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + rtcDesktopMediaSourceHandle pSource = static_cast(source.release()); + pCallbacks->MediaSourceNameChanged(pCallbacks->UserData, pSource); + } +} + +void MediaListObserverImpl::OnMediaSourceThumbnailChanged(scoped_refptr source) +{ + if (callbacks_) { + rtcMediaListObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + rtcDesktopMediaSourceHandle pSource = static_cast(source.release()); + pCallbacks->MediaSourceThumbnailChanged(pCallbacks->UserData, pSource); + } +} + } // namespace libwebrtc diff --git a/src/rtc_desktop_media_list_impl.h b/src/rtc_desktop_media_list_impl.h index bfd6561bc7..7a4d3dc358 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_ /* rtcMediaListObserverCallbacks* */; +}; + 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: diff --git a/src/rtc_dtls_transport_impl.cc b/src/rtc_dtls_transport_impl.cc index 0d29e9c64f..033a25a428 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,55 @@ 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 + ); + } +} + +/** + * class RTCDtlsTransportImpl + */ RTCDtlsTransportImpl::RTCDtlsTransportImpl( rtc::scoped_refptr dtls_transport) : dtls_transport_(dtls_transport), observer_(nullptr) {} @@ -59,7 +112,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..5910e32522 100644 --- a/src/rtc_dtmf_sender_impl.cc +++ b/src/rtc_dtmf_sender_impl.cc @@ -1,7 +1,59 @@ #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(), + tone_buffer.c_string() + ); + } +} + +void RTCDtmfSenderObserverImpl::OnToneChange(const string tone) +{ + if (callbacks_) { + rtcDtmfSenderObserverCallbacks* pCallbacks = reinterpret_cast(callbacks_); + pCallbacks->ToneChanged( + pCallbacks->UserData, + tone.c_string(), + nullptr + ); + } +} + +/** + * 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_dummy_audio_source_impl.cc b/src/rtc_dummy_audio_source_impl.cc new file mode 100644 index 0000000000..637d24009b --- /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.cc b/src/rtc_dummy_video_capturer_impl.cc new file mode 100644 index 0000000000..9aa2c675e7 --- /dev/null +++ b/src/rtc_dummy_video_capturer_impl.cc @@ -0,0 +1,205 @@ +#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), + frame_buffer_(RTCVideoFrame::Create(width, 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_buffer_); + } + OnFrameReady(frame_buffer_); +} + +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..f146cf9b0e --- /dev/null +++ b/src/rtc_dummy_video_capturer_impl.h @@ -0,0 +1,88 @@ +#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 /* rtcVideoCapturerObserverCallbacks* */); + ~DummyVideoCapturerObserverImpl(); + + void OnStart() override; + void OnPaused() override; + void OnStop() override; + void OnError() override; + void OnFillBuffer(scoped_refptr frame) override; + + private: + void* callbacks_ /* rtcVideoCapturerObserverCallbacks* */; +}; // 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; + scoped_refptr frame_buffer_; +}; // end class RTCDummyVideoCapturerImpl + +} // namespace libwebrtc + +#endif // LIB_WEBRTC_RTC_DUMMY_VIDEO_CAPTURER_IMPL_HXX 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_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_peerconnection_factory_impl.cc b/src/rtc_peerconnection_factory_impl.cc index 7c7fe2d452..6a4471059b 100644 --- a/src/rtc_peerconnection_factory_impl.cc +++ b/src/rtc_peerconnection_factory_impl.cc @@ -14,6 +14,10 @@ #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" +#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" @@ -46,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"; @@ -101,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()); } @@ -162,6 +169,33 @@ 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*/ +) { + + if (!use_dummy_audio_) { + return nullptr; + } + + 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, + audio_source_label.std_string() + ) + ); + + scoped_refptr source = scoped_refptr( + new RefCountedObject(rtc_source_track)); + return source; +} + #ifdef RTC_DESKTOP_DEVICE scoped_refptr RTCPeerConnectionFactoryImpl::GetDesktopDevice() { @@ -205,6 +239,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 +319,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 = @@ -286,6 +362,25 @@ scoped_refptr RTCPeerConnectionFactoryImpl::CreateAudioTrack( return track; } +scoped_refptr RTCPeerConnectionFactoryImpl::CreateAudioTrack( + scoped_refptr source, const string track_id) { + + if (!use_dummy_audio_) { + return nullptr; + } + + 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 f87bba67ff..bbf1b200b8 100644 --- a/src/rtc_peerconnection_factory_impl.h +++ b/src/rtc_peerconnection_factory_impl.h @@ -26,7 +26,7 @@ class RTCPeerConnectionFactoryImpl : public RTCPeerConnectionFactory { virtual ~RTCPeerConnectionFactoryImpl(); - bool Initialize() override; + bool Initialize(bool use_dummy_audio = false) override; bool Terminate() override; @@ -42,6 +42,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, @@ -53,15 +59,25 @@ 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; + virtual scoped_refptr CreateAudioTrack( + scoped_refptr source, const string track_id) override; + virtual scoped_refptr CreateVideoTrack( scoped_refptr source, const string track_id) override; 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_; @@ -83,6 +99,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, @@ -103,6 +123,7 @@ class RTCPeerConnectionFactoryImpl : public RTCPeerConnectionFactory { #endif std::list> peerconnections_; std::unique_ptr task_queue_factory_; + bool use_dummy_audio_ = false; }; } // namespace libwebrtc diff --git a/src/rtc_peerconnection_impl.cc b/src/rtc_peerconnection_impl.cc index 609287bdcf..7b202e25fe 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" @@ -15,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, @@ -190,7 +360,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(); } @@ -336,10 +508,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); } @@ -360,6 +532,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); @@ -433,6 +611,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; @@ -605,6 +789,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..a407ce7ed7 100644 --- a/src/rtc_peerconnection_impl.h +++ b/src/rtc_peerconnection_impl.h @@ -31,10 +31,70 @@ 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: virtual bool Initialize(); + virtual bool IsInitialized() const override; virtual void CreateOffer( OnSdpCreateSuccess success, OnSdpCreateFailure failure, @@ -182,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_; @@ -191,7 +253,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_; 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_parameters_impl.cc b/src/rtc_rtp_parameters_impl.cc index ac4aec8a25..c8184a35bc 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,80 @@ 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 "; +} + +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) {} @@ -439,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 = @@ -457,6 +572,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 +622,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..968071c0bb 100644 --- a/src/rtc_rtp_parameters_impl.h +++ b/src/rtc_rtp_parameters_impl.h @@ -23,6 +23,37 @@ class RTCRtcpFeedbackImpl : public RTCRtcpFeedback { webrtc::RtcpFeedback rtcp_feedback_; }; +/** + * class RTCRtcpFeedbackListImpl + */ +class RTCRtcpFeedbackListImpl : public RTCRtcpFeedbackList { + public: + RTCRtcpFeedbackListImpl(const vector>& source); + ~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); @@ -45,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; @@ -55,6 +87,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 +114,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 +144,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 +243,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 diff --git a/src/rtc_rtp_receiver_impl.cc b/src/rtc_rtp_receiver_impl.cc index 615d96509f..e81a7c2e71 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 RTCRtpReceiverObserverImpl + */ + +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 = reinterpret_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) {} @@ -92,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 986956ce14..610fe29ea5 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_; @@ -32,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 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( diff --git a/src/rtc_video_frame_impl.cc b/src/rtc_video_frame_impl.cc index 3c14db17a3..0b3ca5f0c6 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" @@ -29,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(); } @@ -53,41 +60,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; @@ -95,6 +114,246 @@ int VideoFrameBufferImpl::ConvertToARGB(Type type, uint8_t* dst_buffer, return buf_size; } +int VideoFrameBufferImpl::ScaleFrom(scoped_refptr source) +{ + if (nullptr == source || this == source.get()) { + return 0; + } + scoped_refptr source_impl = + scoped_refptr( + static_cast(source.get()) + ); + if (nullptr == source_impl->buffer_) { + return 0; + } + 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; + + return size(); +} + +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(source->width, source->height); + rtc::scoped_refptr i420_dst = + webrtc::I420Buffer::Create(width(), height()); + + 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(), + source->width, source->height); + break; + 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(), + source->width, source->height); + break; + 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(), + source->width, source->height); + break; + 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(), + source->width, source->height); + break; + default: + break; + } + + i420_dst->ScaleFrom(*i420_src.get()); + buffer_ = i420_dst; + + 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) { + 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; +} + libwebrtc::RTCVideoFrame::VideoRotation VideoFrameBufferImpl::rotation() { switch (rotation_) { case webrtc::kVideoRotation_0: @@ -111,6 +370,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..282b6f09f5 100644 --- a/src/rtc_video_frame_impl.h +++ b/src/rtc_video_frame_impl.h @@ -21,29 +21,32 @@ 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, - int dest_width, int dest_height) override; + int ConvertToARGB(RTCVideoFrameARGB* pDest) override; + + int ScaleFrom(scoped_refptr source) override; + + int ScaleFrom(RTCVideoFrameARGB* source) override; + + int ScaleFrom(RTCVideoFrameYUV* source) override; + + int Clear(RTCVideoFrameClearType clearType) override; 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; diff --git a/src/rtc_video_renderer_impl.cc b/src/rtc_video_renderer_impl.cc new file mode 100644 index 0000000000..9206dff58e --- /dev/null +++ b/src/rtc_video_renderer_impl.cc @@ -0,0 +1,69 @@ +#include "rtc_video_renderer_impl.h" + +#include "interop_api.h" +#include "rtc_base/logging.h" + +namespace libwebrtc { + +RTCVideoRendererImpl::RTCVideoRendererImpl() + : user_data_(nullptr) + , callback_(nullptr) + , callback_safe_(nullptr) +{ + RTC_LOG(LS_INFO) << __FUNCTION__ << ": ctor " << (void*)this; +} + +RTCVideoRendererImpl::~RTCVideoRendererImpl() +{ + user_data_ = nullptr; + callback_ = nullptr; + callback_safe_ = 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); + } + else if (callback_safe_) { + callback_safe_(frame); + } +} + +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); + 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() +{ + RTC_LOG(LS_INFO) << __FUNCTION__; + user_data_ = nullptr; + callback_ = nullptr; + callback_safe_ = 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..ab252c3ce1 --- /dev/null +++ b/src/rtc_video_renderer_impl.h @@ -0,0 +1,31 @@ +#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 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 + +#endif // LIB_WEBRTC_VIDEO_RENDERER_IMPL_HXX