[WebRTC] Add descrition and payload APIs (#6284)
authorHaesu Gwon <haesu.gwon@samsung.com>
Fri, 13 Sep 2024 03:45:26 +0000 (12:45 +0900)
committerGitHub <noreply@github.com>
Fri, 13 Sep 2024 03:45:26 +0000 (12:45 +0900)
* [WebRTC] Add descrition and payload APIs

src/Tizen.Multimedia.Remoting/Interop/Interop.WebRTC.cs
src/Tizen.Multimedia.Remoting/WebRTC/MediaSource.cs
src/Tizen.Multimedia.Remoting/WebRTC/WebRTC.cs

index 9b6e81607d0b777ca25f8bc62e1d2e52285fa9a1..a682accafa6f7b39e9f9b8c26f93b7c490686cc3 100755 (executable)
@@ -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);
 
index 8798eb2b012715dd352d10bb91968149d4980107..8be7c1f3c1a838bec19e7afcfb8381f83a15bb30 100755 (executable)
@@ -552,6 +552,58 @@ namespace Tizen.Multimedia.Remoting
             }
         }
 
+        /// <summary>
+        /// Sets the RTP payload type of given <paramref name="codec"/>.
+        /// </summary>
+        /// <remarks>
+        /// <paramref name="payloadType"/> should be greater than or equal to 96 and less than or equal to 127.
+        /// </remarks>
+        /// <param name="codec">The transceiver codec.</param>
+        /// <param name="payloadType">The RTP payload type.</param>
+        /// <exception cref="InvalidOperationException">MediaSource is not attached yet.</exception>
+        /// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
+        /// <exception cref="ArgumentOutOfRangeException">
+        ///     <paramref name="payloadType"/> is less than 96 or greater than 127.
+        /// </exception>
+        /// <seealso cref="SupportedTransceiverCodecs"/>
+        /// <since_tizen> 12 </since_tizen>
+        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");
+        }
+
+        /// <summary>
+        /// Gets the RTP payload type of given <paramref name="codec"/>.
+        /// </summary>
+        /// <param name="codec">The transceiver codec.</param>
+        /// <returns>The RTP payload type.</returns>
+        /// <exception cref="InvalidOperationException">MediaSource is not attached yet.</exception>
+        /// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
+        /// <seealso cref="SupportedTransceiverCodecs"/>
+        /// <since_tizen> 12 </since_tizen>
+        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;
+        }
+
         /// <summary>
         /// Enables the audio loopback. The local audio will be played with <paramref name="policy"/>.
         /// </summary>
index df993899ff75fd5e1439bbab60f63bcdba2bfdc9..0590d0f0faa2cddaba275b2b4519cf3fc7b2ad38 100755 (executable)
@@ -318,6 +318,7 @@ namespace Tizen.Multimedia.Remoting
         /// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
         /// <seealso cref="CreateOfferAsync()"/>
         /// <seealso cref="CreateAnswerAsync()"/>
+        /// <seealso cref="GetLocalDescription()"/>
         /// <since_tizen> 9 </since_tizen>
         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.");
+        }
+
+        /// <summary>
+        /// Gets the session description for a local peer.
+        /// </summary>
+        /// <returns>The local session description string</returns>
+        /// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
+        /// <seealso cref="SetLocalDescription()"/>
+        /// <since_tizen> 12 </since_tizen>
+        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);
+            }
         }
 
         /// <summary>
@@ -341,6 +366,7 @@ namespace Tizen.Multimedia.Remoting
         /// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
         /// <seealso cref="CreateOfferAsync()"/>
         /// <seealso cref="CreateAnswerAsync()"/>
+        /// <seealso cref="GetRemoteDescription()"/>
         /// <since_tizen> 9 </since_tizen>
         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.");
+        }
+
+        /// <summary>
+        /// Gets the session description of the remote peer's current offer or answer.
+        /// </summary>
+        /// <value>The remote session description string</value>
+        /// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
+        /// <seealso cref="SetRemoteDescription"/>
+        /// <since_tizen> 12 </since_tizen>
+        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);
+            }
         }
 
         /// <summary>