[WebRTC] Change state restriction (#6181)
authorHaesu Gwon <haesu.gwon@samsung.com>
Thu, 18 Jul 2024 02:12:19 +0000 (11:12 +0900)
committerGitHub <noreply@github.com>
Thu, 18 Jul 2024 02:12:19 +0000 (11:12 +0900)
* [WebRTC] Change state restriction

src/Tizen.Multimedia.Remoting/WebRTC/MediaFileSource.cs
src/Tizen.Multimedia.Remoting/WebRTC/MediaMicrophoneSource.cs
src/Tizen.Multimedia.Remoting/WebRTC/MediaNullSource.cs
src/Tizen.Multimedia.Remoting/WebRTC/WebRTC.cs

index 4592109..40e6ea3 100755 (executable)
@@ -107,15 +107,11 @@ namespace Tizen.Multimedia.Remoting
         /// Sets the transceiver direction for receiving media stream.
         /// </summary>
         /// <remarks>
-        /// The WebRTC must be in the <see cref="WebRTCState.Idle"/> state when transceiver direction is set.
+        /// This method does not throw state exception anymore(Since API Leve 12). It can be called in any state.<br/>
         /// </remarks>
         /// <param name="type">The media type.</param>
         /// <param name="direction">The transceiver direction.</param>
-        /// <exception cref="InvalidOperationException">
-        ///     MediaSource is not attached yet.<br/>
-        /// -or-<br/>
-        ///     The WebRTC is not in the valid state.
-        /// </exception>
+        /// <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 void SetTransceiverDirection(MediaType type, TransceiverDirection direction)
index d4cd5d0..8823ef8 100755 (executable)
@@ -66,8 +66,7 @@ namespace Tizen.Multimedia.Remoting
         /// </summary>
         /// <param name="policy">The <see cref="AudioStreamPolicy"/> to apply.</param>
         /// <remarks>
-        /// The WebRTC must be in the <see cref="WebRTCState.Idle"/> state.<br/>
-        /// <br/>
+        /// This method does not throw state exception anymore(Since API Level 12). It can be called in any state.<br/>
         /// <see cref="WebRTC"/> does not support all <see cref="AudioStreamType"/>.<br/>
         /// Supported types are <see cref="AudioStreamType.Media"/>, <see cref="AudioStreamType.VoiceRecognition"/>,
         /// <see cref="AudioStreamType.Voip"/>, <see cref="AudioStreamType.MediaExternalOnly"/>.
@@ -77,7 +76,7 @@ namespace Tizen.Multimedia.Remoting
         ///     -or-<br/>
         ///     <paramref name="policy"/> has already been disposed.
         /// </exception>
-        /// <exception cref="InvalidOperationException">The WebRTC is not in the valid state.</exception>
+        /// <exception cref="InvalidOperationException">An internal error occurs.</exception>
         /// <exception cref="ArgumentNullException"><paramref name="policy"/> is null.</exception>
         /// <exception cref="NotSupportedException">
         ///     <see cref="AudioStreamType"/> of <paramref name="policy"/> is not supported on the current platform.
@@ -91,8 +90,6 @@ namespace Tizen.Multimedia.Remoting
                 throw new ArgumentNullException(nameof(policy), "policy is null");
             }
 
-            WebRtc.ValidateWebRTCState(WebRTCState.Idle);
-
             var ret = NativeWebRTC.SetAudioStreamPolicyToMicrophoneSource(WebRtc.Handle, SourceId.Value, policy.Handle);
 
             if (ret == WebRTCErrorCode.InvalidArgument)
index c685439..cdd1d34 100755 (executable)
@@ -64,16 +64,11 @@ namespace Tizen.Multimedia.Remoting
         /// Sets the transceiver codec for receiving media stream.
         /// </summary>
         /// <remarks>
-        /// The WebRTC must be in the <see cref="WebRTCState.Idle"/> state when transceiver codec is set.<br/>
-        ///
+        /// This method does not throw state exception anymore(Since API Level 12). It can be called in any state.<br/>
         /// </remarks>
         /// <param name="type">The media type.</param>
         /// <param name="codec">The transceiver codec.</param>
-        /// <exception cref="InvalidOperationException">
-        ///     MediaSource is not attached yet.<br/>
-        /// -or-<br/>
-        ///     The WebRTC is not in the valid state.
-        /// </exception>
+        /// <exception cref="InvalidOperationException">MediaSource is not attached yet.</exception>
         /// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
         /// <seealso cref="GetTransceiverCodec"/>
         /// <since_tizen> 10 </since_tizen>
@@ -84,8 +79,6 @@ namespace Tizen.Multimedia.Remoting
                 throw new InvalidOperationException("MediaSource is not attached yet. Call AddSource() first.");
             }
 
-            WebRtc.ValidateWebRTCState(WebRTCState.Idle);
-
             NativeWebRTC.SetTransceiverCodec(WebRtc.Handle, SourceId.Value, type, codec).
                 ThrowIfFailed("Failed to set transceiver codec");
         }
index 7564e86..b7dc62b 100755 (executable)
@@ -226,7 +226,9 @@ namespace Tizen.Multimedia.Remoting
         /// <summary>
         /// Creates SDP offer asynchronously to start a new WebRTC connection to a remote peer.
         /// </summary>
-        /// <remarks>The WebRTC must be in the <see cref="WebRTCState.Negotiating"/></remarks>
+        /// <remarks>
+        /// The WebRTC must be in the <see cref="WebRTCState.Negotiating"/> or <see cref="WebRTCState.Playing"/>(Since API Level 12)
+        /// </remarks>
         /// <returns>The SDP offer.</returns>
         /// <exception cref="InvalidOperationException">The WebRTC is not in the valid state.</exception>
         /// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
@@ -234,7 +236,7 @@ namespace Tizen.Multimedia.Remoting
         /// <since_tizen> 9 </since_tizen>
         public async Task<string> CreateOfferAsync()
         {
-            ValidateWebRTCState(WebRTCState.Negotiating);
+            ValidateWebRTCState(WebRTCState.Negotiating, WebRTCState.Playing);
 
             var tcsSdpCreated = new TaskCompletionSource<string>();
 
@@ -259,7 +261,9 @@ namespace Tizen.Multimedia.Remoting
         /// <summary>
         /// Creates SDP answer asynchronously with option to an offer received from a remote peer.
         /// </summary>
-        /// <remarks>The WebRTC must be in the <see cref="WebRTCState.Negotiating"/></remarks>
+        /// <remarks>
+        /// The WebRTC must be in the <see cref="WebRTCState.Negotiating"/> or <see cref="WebRTCState.Playing"/>(Since API Level 12)
+        /// </remarks>
         /// <returns>The SDP answer.</returns>
         /// <exception cref="InvalidOperationException">The WebRTC is not in the valid state.</exception>
         /// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
@@ -267,7 +271,7 @@ namespace Tizen.Multimedia.Remoting
         /// <since_tizen> 9 </since_tizen>
         public async Task<string> CreateAnswerAsync()
         {
-            ValidateWebRTCState(WebRTCState.Negotiating);
+            ValidateWebRTCState(WebRTCState.Negotiating, WebRTCState.Playing);
 
             var tcsSdpCreated = new TaskCompletionSource<string>();
 
@@ -292,7 +296,9 @@ namespace Tizen.Multimedia.Remoting
         /// <summary>
         /// Sets the session description for a local peer.
         /// </summary>
-        /// <remarks>The WebRTC must be in the <see cref="WebRTCState.Negotiating"/>.</remarks>
+        /// <remarks>
+        /// The WebRTC must be in the <see cref="WebRTCState.Negotiating"/> or <see cref="WebRTCState.Playing"/>(Since API Level 12)
+        /// </remarks>
         /// <param name="description">The local session description.</param>
         /// <exception cref="ArgumentException">The description is empty string.</exception>
         /// <exception cref="ArgumentNullException">The description is null.</exception>
@@ -303,7 +309,7 @@ namespace Tizen.Multimedia.Remoting
         /// <since_tizen> 9 </since_tizen>
         public void SetLocalDescription(string description)
         {
-            ValidateWebRTCState(WebRTCState.Negotiating);
+            ValidateWebRTCState(WebRTCState.Negotiating, WebRTCState.Playing);
 
             ValidationUtil.ValidateIsNullOrEmpty(description, nameof(description));
 
@@ -313,7 +319,9 @@ namespace Tizen.Multimedia.Remoting
         /// <summary>
         /// Sets the session description of the remote peer's current offer or answer.
         /// </summary>
-        /// <remarks>The WebRTC must be in the <see cref="WebRTCState.Negotiating"/>.</remarks>
+        /// <remarks>
+        /// The WebRTC must be in the <see cref="WebRTCState.Negotiating"/> or <see cref="WebRTCState.Playing"/>(Since API Level 12)
+        /// </remarks>
         /// <param name="description">The remote session description.</param>
         /// <exception cref="ArgumentException">The description is empty string.</exception>
         /// <exception cref="ArgumentNullException">The description is null.</exception>
@@ -324,7 +332,7 @@ namespace Tizen.Multimedia.Remoting
         /// <since_tizen> 9 </since_tizen>
         public void SetRemoteDescription(string description)
         {
-            ValidateWebRTCState(WebRTCState.Negotiating);
+            ValidateWebRTCState(WebRTCState.Negotiating, WebRTCState.Playing);
 
             ValidationUtil.ValidateIsNullOrEmpty(description, nameof(description));
 
@@ -378,7 +386,7 @@ namespace Tizen.Multimedia.Remoting
         /// Adds media source.
         /// </summary>
         /// <remarks>
-        /// The WebRTC must be in the <see cref="WebRTCState.Idle"/>.<br/>
+        /// This method does not throw state exception anymore(Since API Level 12). It can be called in any state.<br/>
         /// Each MediaSource requires different feature or privilege.<br/>
         /// <see cref="MediaCameraSource"/> needs camera feature and privilege.<br/>
         /// <see cref="MediaMicrophoneSource"/> needs microphone feature and recorder privilege.<br/>
@@ -393,7 +401,7 @@ namespace Tizen.Multimedia.Remoting
         /// <privilege>http://tizen.org/privilege/recorder</privilege>
         /// <exception cref="ArgumentNullException">The media source is null.</exception>
         /// <exception cref="InvalidOperationException">
-        /// The WebRTC is not in the valid state.<br/>
+        /// An internal error occurs.<br/>
         /// - or -<br/>
         /// All or one of <paramref name="source"/> was already detached.
         /// </exception>
@@ -415,8 +423,6 @@ namespace Tizen.Multimedia.Remoting
                 throw new ArgumentNullException(nameof(source), "source is null");
             }
 
-            ValidateWebRTCState(WebRTCState.Idle);
-
             source?.AttachTo(this);
 
             _source.Add(source);
@@ -426,7 +432,7 @@ namespace Tizen.Multimedia.Remoting
         /// Adds media sources.
         /// </summary>
         /// <remarks>
-        /// The WebRTC must be in the <see cref="WebRTCState.Idle"/>.<br/>
+        /// This method does not throw state exception anymore(Since API Level 12). It can be called in any state.<br/>
         /// Each MediaSource requires different feature or privilege.<br/>
         /// <see cref="MediaCameraSource"/> needs camera feature and privilege.<br/>
         /// <see cref="MediaMicrophoneSource"/> needs microphone feature and recorder privilege.<br/>
@@ -441,7 +447,7 @@ namespace Tizen.Multimedia.Remoting
         /// <privilege>http://tizen.org/privilege/recorder</privilege>
         /// <exception cref="ArgumentNullException">The media source is null.</exception>
         /// <exception cref="InvalidOperationException">
-        /// The WebRTC is not in the valid state.<br/>
+        /// An internal error occurs.<br/>
         /// - or -<br/>
         /// All or one of <paramref name="sources"/> was already detached.
         /// </exception>
@@ -473,12 +479,12 @@ namespace Tizen.Multimedia.Remoting
         /// Removes media source.
         /// </summary>
         /// <remarks>
-        /// The WebRTC must be in the <see cref="WebRTCState.Idle"/>.<br/>
+        /// This method does not throw state exception anymore(Since API Level 12). It can be called in any state.<br/>
         /// If user want to use removed MediaSource again, user should create new instance for it.
         /// </remarks>
         /// <param name="source">The media source to remove.</param>
         /// <exception cref="ArgumentNullException">The media source is null.</exception>
-        /// <exception cref="InvalidOperationException">The WebRTC is not in the valid state.</exception>
+        /// <exception cref="InvalidOperationException">An internal error occurs.</exception>
         /// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
         /// <seealso cref="MediaCameraSource"/>
         /// <seealso cref="MediaMicrophoneSource"/>
@@ -495,8 +501,6 @@ namespace Tizen.Multimedia.Remoting
                 throw new ArgumentNullException(nameof(source), "source is null");
             }
 
-            ValidateWebRTCState(WebRTCState.Idle);
-
             source?.DetachFrom(this);
 
             _source.Remove(source);
@@ -508,12 +512,12 @@ namespace Tizen.Multimedia.Remoting
         /// Removes media sources.
         /// </summary>
         /// <remarks>
-        /// The WebRTC must be in the <see cref="WebRTCState.Idle"/>.<br/>
+        /// This method does not throw state exception anymore(Since API Level 12). It can be called in any state.<br/>
         /// If user want to use removed MediaSource again, user should create new instance for it.
         /// </remarks>
         /// <param name="sources">The media source to remove.</param>
         /// <exception cref="ArgumentNullException">The media source is null.</exception>
-        /// <exception cref="InvalidOperationException">The WebRTC is not in the valid state.</exception>
+        /// <exception cref="InvalidOperationException">An internal error occurs.</exception>
         /// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
         /// <seealso cref="MediaCameraSource"/>
         /// <seealso cref="MediaMicrophoneSource"/>
@@ -601,7 +605,9 @@ namespace Tizen.Multimedia.Remoting
         /// <summary>
         /// Retrieves the current statistics information.
         /// </summary>
-        /// <remarks>The WebRTC must be in the <see cref="WebRTCState.Playing"/></remarks>
+        /// <remarks>
+        /// The WebRTC must be in the <see cref="WebRTCState.Negotiating"/>(Since API Level 12) or <see cref="WebRTCState.Playing"/>
+        /// </remarks>
         /// <returns>The WebRTC statistics informations.</returns>
         /// <param name="category">The category of statistics to get.</param>
         /// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
@@ -609,7 +615,7 @@ namespace Tizen.Multimedia.Remoting
         /// <since_tizen> 10 </since_tizen>
         public ReadOnlyCollection<WebRTCStatistics> GetStatistics(WebRTCStatisticsCategory category)
         {
-            ValidateWebRTCState(WebRTCState.Playing);
+            ValidateWebRTCState(WebRTCState.Negotiating, WebRTCState.Playing);
 
             var stats = new List<WebRTCStatistics>();
             Exception caught = null;