From 2a09a5ea88a6717b1ad5fe59eadf3d06526ca837 Mon Sep 17 00:00:00 2001 From: Haesu Gwon Date: Fri, 13 Sep 2024 12:45:26 +0900 Subject: [PATCH] [WebRTC] Add descrition and payload APIs (#6284) * [WebRTC] Add descrition and payload APIs --- .../Interop/Interop.WebRTC.cs | 13 ++++- .../WebRTC/MediaSource.cs | 52 ++++++++++++++++++ .../WebRTC/WebRTC.cs | 54 ++++++++++++++++++- 3 files changed, 116 insertions(+), 3 deletions(-) diff --git a/src/Tizen.Multimedia.Remoting/Interop/Interop.WebRTC.cs b/src/Tizen.Multimedia.Remoting/Interop/Interop.WebRTC.cs index 9b6e81607..a682accaf 100755 --- a/src/Tizen.Multimedia.Remoting/Interop/Interop.WebRTC.cs +++ b/src/Tizen.Multimedia.Remoting/Interop/Interop.WebRTC.cs @@ -148,6 +148,12 @@ internal static partial class Interop [DllImport(Libraries.WebRTC, EntryPoint = "webrtc_media_source_get_transceiver_codec")] internal static extern WebRTCErrorCode GetTransceiverCodec(IntPtr handle, uint sourceId, MediaType type, out TransceiverCodec codec); + [DllImport(Libraries.WebRTC, EntryPoint = "webrtc_media_source_set_payload_type")] + internal static extern WebRTCErrorCode SetPaylodType(IntPtr handle, uint sourceId, TransceiverCodec codec, uint payloadType); + + [DllImport(Libraries.WebRTC, EntryPoint = "webrtc_media_source_get_payload_type")] + internal static extern WebRTCErrorCode GetPaylodType(IntPtr handle, uint sourceId, TransceiverCodec codec, out uint payloadType); + [DllImport(Libraries.WebRTC, EntryPoint = "webrtc_media_source_set_pause")] internal static extern WebRTCErrorCode SetPause(IntPtr handle, uint sourceId, MediaType type, bool pause); @@ -256,9 +262,15 @@ internal static partial class Interop [DllImport(Libraries.WebRTC, EntryPoint = "webrtc_set_local_description")] internal static extern WebRTCErrorCode SetLocalDescription(IntPtr handle, string description); + [DllImport(Libraries.WebRTC, EntryPoint = "webrtc_get_local_description")] + internal static extern WebRTCErrorCode GetLocalDescription(IntPtr handle, out IntPtr description); + [DllImport(Libraries.WebRTC, EntryPoint = "webrtc_set_remote_description")] internal static extern WebRTCErrorCode SetRemoteDescription(IntPtr handle, string description); + [DllImport(Libraries.WebRTC, EntryPoint = "webrtc_get_remote_description")] + internal static extern WebRTCErrorCode GetRemoteDescription(IntPtr handle, out IntPtr description); + [DllImport(Libraries.WebRTC, EntryPoint = "webrtc_add_ice_candidate")] internal static extern WebRTCErrorCode AddIceCandidate(IntPtr handle, string candidate); @@ -268,7 +280,6 @@ internal static partial class Interop [DllImport(Libraries.WebRTC, EntryPoint = "webrtc_foreach_stats")] internal static extern WebRTCErrorCode ForeachStats(IntPtr handle, int typeMask, RetrieveStatsCallback callback, IntPtr userData = default); - [DllImport(Libraries.WebRTC, EntryPoint = "webrtc_set_error_cb")] internal static extern WebRTCErrorCode SetErrorOccurredCb(IntPtr handle, ErrorOccurredCallback callback, IntPtr userData = default); diff --git a/src/Tizen.Multimedia.Remoting/WebRTC/MediaSource.cs b/src/Tizen.Multimedia.Remoting/WebRTC/MediaSource.cs index 8798eb2b0..8be7c1f3c 100755 --- a/src/Tizen.Multimedia.Remoting/WebRTC/MediaSource.cs +++ b/src/Tizen.Multimedia.Remoting/WebRTC/MediaSource.cs @@ -552,6 +552,58 @@ namespace Tizen.Multimedia.Remoting } } + /// + /// Sets the RTP payload type of given . + /// + /// + /// should be greater than or equal to 96 and less than or equal to 127. + /// + /// The transceiver codec. + /// The RTP payload type. + /// MediaSource is not attached yet. + /// The WebRTC has already been disposed. + /// + /// is less than 96 or greater than 127. + /// + /// + /// 12 + public void SetPayloadType(TransceiverCodec codec, uint payloadType) + { + if (!SourceId.HasValue) + { + throw new InvalidOperationException("MediaSource is not attached yet. Call AddSource() first."); + } + if (payloadType < 96 || payloadType > 127) + { + throw new ArgumentOutOfRangeException(nameof(payloadType), payloadType, "Valid range : 96 <= payloadType <= 127"); + } + + NativeWebRTC.SetPaylodType(WebRtc.Handle, SourceId.Value, codec, payloadType). + ThrowIfFailed("Failed to set payload type"); + } + + /// + /// Gets the RTP payload type of given . + /// + /// The transceiver codec. + /// The RTP payload type. + /// MediaSource is not attached yet. + /// The WebRTC has already been disposed. + /// + /// 12 + public uint GetPayloadType(TransceiverCodec codec) + { + if (!SourceId.HasValue) + { + throw new InvalidOperationException("MediaSource is not attached yet. Call AddSource() first."); + } + + NativeWebRTC.GetPaylodType(WebRtc.Handle, SourceId.Value, codec, out uint payloadType). + ThrowIfFailed("Failed to get payload type"); + + return payloadType; + } + /// /// Enables the audio loopback. The local audio will be played with . /// diff --git a/src/Tizen.Multimedia.Remoting/WebRTC/WebRTC.cs b/src/Tizen.Multimedia.Remoting/WebRTC/WebRTC.cs index df993899f..0590d0f0f 100755 --- a/src/Tizen.Multimedia.Remoting/WebRTC/WebRTC.cs +++ b/src/Tizen.Multimedia.Remoting/WebRTC/WebRTC.cs @@ -318,6 +318,7 @@ namespace Tizen.Multimedia.Remoting /// The WebRTC has already been disposed. /// /// + /// /// 9 public void SetLocalDescription(string description) { @@ -325,7 +326,31 @@ namespace Tizen.Multimedia.Remoting ValidationUtil.ValidateIsNullOrEmpty(description, nameof(description)); - NativeWebRTC.SetLocalDescription(Handle, description).ThrowIfFailed("Failed to set description."); + NativeWebRTC.SetLocalDescription(Handle, description).ThrowIfFailed("Failed to set local description."); + } + + /// + /// Gets the session description for a local peer. + /// + /// The local session description string + /// The WebRTC has already been disposed. + /// + /// 12 + public string GetLocalDescription() + { + ValidateNotDisposed(); + + IntPtr description = IntPtr.Zero; + try + { + NativeWebRTC.GetLocalDescription(Handle, out description).ThrowIfFailed("Failed to get local description."); + + return Marshal.PtrToStringAnsi(description); + } + finally + { + Marshal.FreeHGlobal(description); + } } /// @@ -341,6 +366,7 @@ namespace Tizen.Multimedia.Remoting /// The WebRTC has already been disposed. /// /// + /// /// 9 public void SetRemoteDescription(string description) { @@ -348,7 +374,31 @@ namespace Tizen.Multimedia.Remoting ValidationUtil.ValidateIsNullOrEmpty(description, nameof(description)); - NativeWebRTC.SetRemoteDescription(Handle, description).ThrowIfFailed("Failed to set description."); + NativeWebRTC.SetRemoteDescription(Handle, description).ThrowIfFailed("Failed to set remote description."); + } + + /// + /// Gets the session description of the remote peer's current offer or answer. + /// + /// The remote session description string + /// The WebRTC has already been disposed. + /// + /// 12 + public string GetRemoteDescription() + { + ValidateNotDisposed(); + + IntPtr description = IntPtr.Zero; + try + { + NativeWebRTC.GetRemoteDescription(Handle, out description).ThrowIfFailed("Failed to get remote description."); + + return Marshal.PtrToStringAnsi(description); + } + finally + { + Marshal.FreeHGlobal(description); + } } /// -- 2.34.1