[WebRTC] Add new APIs for EncoderBitrate and CameraDeviceId (#4527)
authorHaesu Gwon <haesu.gwon@samsung.com>
Wed, 7 Sep 2022 07:44:14 +0000 (16:44 +0900)
committerGitHub <noreply@github.com>
Wed, 7 Sep 2022 07:44:14 +0000 (16:44 +0900)
* [WebRTC] Add new APIs for EncoderBitrate and CameraDeviceId

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

index 2a7c310..d6301cf 100755 (executable)
@@ -111,6 +111,12 @@ internal static partial class Interop
         [DllImport(Libraries.WebRTC, EntryPoint = "webrtc_remove_media_source")]
         internal static extern WebRTCErrorCode RemoveMediaSource(IntPtr handle, uint sourceId);
 
+        [DllImport(Libraries.WebRTC, EntryPoint = "webrtc_camera_source_set_device_id")]
+        internal static extern WebRTCErrorCode SetCameraDeviceId(IntPtr handle, uint sourceId, uint deviceId);
+
+        [DllImport(Libraries.WebRTC, EntryPoint = "webrtc_camera_source_get_device_id")]
+        internal static extern WebRTCErrorCode GetCameraDeviceId(IntPtr handle, uint sourceId, out uint deviceId);
+
         [DllImport(Libraries.WebRTC, EntryPoint = "webrtc_media_packet_source_set_format")]
         internal static extern WebRTCErrorCode SetMediaPacketSourceInfo(IntPtr handle, uint sourceId, IntPtr packet);
 
@@ -154,6 +160,12 @@ internal static partial class Interop
         [DllImport(Libraries.WebRTC, EntryPoint = "webrtc_media_source_get_mute")]
         internal static extern WebRTCErrorCode GetMute(IntPtr handle, uint sourceId, MediaType type, out bool mute);
 
+        [DllImport(Libraries.WebRTC, EntryPoint = "webrtc_media_source_set_encoder_bitrate")]
+        internal static extern WebRTCErrorCode SetEncoderBitrate(IntPtr handle, uint sourceId, MediaType type, int bitrate);
+
+        [DllImport(Libraries.WebRTC, EntryPoint = "webrtc_media_source_get_encoder_bitrate")]
+        internal static extern WebRTCErrorCode GetEncoderBitrate(IntPtr handle, uint sourceId, MediaType type, out int bitrate);
+
         [DllImport(Libraries.WebRTC, EntryPoint = "webrtc_media_source_set_video_resolution")]
         internal static extern WebRTCErrorCode SetVideoResolution(IntPtr handle, uint sourceId, int width, int height);
 
index 280fbc1..c6829b3 100755 (executable)
@@ -35,6 +35,39 @@ namespace Tizen.Multimedia.Remoting
         /// <since_tizen> 9 </since_tizen>
         public MediaCameraSource() : base(MediaType.Video) {}
 
+        /// <summary>
+        /// Gets or sets the camera device id.
+        /// </summary>
+        /// <value>A value that specifies the camera device id.</value>
+        /// <exception cref="InvalidOperationException">MediaSource is not attached yet.</exception>
+        /// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
+        /// <since_tizen> 10 </since_tizen>
+        public uint CameraDeviceId
+        {
+            get
+            {
+                if (!SourceId.HasValue)
+                {
+                    throw new InvalidOperationException("MediaSource is not attached yet. Call AddSource() first.");
+                }
+
+                NativeWebRTC.GetCameraDeviceId(WebRtc.Handle, SourceId.Value, out uint deviceId).
+                    ThrowIfFailed("Failed to get camera device id");
+
+                return deviceId;
+            }
+            set
+            {
+                if (!SourceId.HasValue)
+                {
+                    throw new InvalidOperationException("MediaSource is not attached yet. Call AddSource() first.");
+                }
+
+                NativeWebRTC.SetCameraDeviceId(WebRtc.Handle, SourceId.Value, value).
+                    ThrowIfFailed("Failed to set camera device id");
+            }
+        }
+
         internal override void OnAttached(WebRTC webRtc)
         {
             Debug.Assert(webRtc != null);
index 4e53ee0..fa133b2 100755 (executable)
@@ -422,6 +422,61 @@ namespace Tizen.Multimedia.Remoting
         }
 
         /// <summary>
+        /// Gets or sets the encoder bitrate of the current media source.
+        /// </summary>
+        /// <remarks>
+        /// This API is not supported in <see cref="MediaFileSource"/>, <see cref="MediaPacketSource"/>.<br/>
+        /// </remarks>
+        /// <value>A value that specifies the encoder bitrate.</value>
+        /// <exception cref="ArgumentException">EncoderBitrate is less than or equal to zero.</exception>
+        /// <exception cref="InvalidOperationException">
+        ///     MediaSource is not attached yet.<br/>
+        /// -or-<br/>
+        ///     This MediaSource is not Video.
+        /// -or-<br/>
+        ///     This MediaSource is not supported type of MediaSource.
+        /// </exception>
+        /// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
+        /// <since_tizen> 10 </since_tizen>
+        public int EncoderBitrate
+        {
+            get
+            {
+                if (!SourceId.HasValue)
+                {
+                    throw new InvalidOperationException("MediaSource is not attached yet. Call AddSource() first.");
+                }
+                if (this is MediaFileSource || this is MediaPacketSource)
+                {
+                    throw new InvalidOperationException($"This property is not supported in {this.GetType()}.");
+                }
+
+                NativeWebRTC.GetEncoderBitrate(WebRtc.Handle, SourceId.Value, MediaType, out int bitrate).
+                    ThrowIfFailed("Failed to get encoder bitrate");
+
+                return bitrate;
+            }
+            set
+            {
+                if (value <= 0)
+                {
+                    throw new ArgumentException($"EncoderBitrate should be greater than zero.");
+                }
+                if (!SourceId.HasValue)
+                {
+                    throw new InvalidOperationException("MediaSource is not attached yet. Call AddSource() first.");
+                }
+                if (this is MediaFileSource || this is MediaPacketSource)
+                {
+                    throw new InvalidOperationException($"This property is not supported in {this.GetType()}.");
+                }
+
+                NativeWebRTC.SetEncoderBitrate(WebRtc.Handle, SourceId.Value, MediaType, value).
+                    ThrowIfFailed("Failed to set encoder bitrate");
+            }
+        }
+
+        /// <summary>
         /// Enables the audio loopback. The local audio will be played with <paramref name="policy"/>.
         /// </summary>
         /// <param name="policy">The <see cref="AudioStreamPolicy"/> to apply.</param>