Skip to content

Commit

Permalink
[WebRTC] Change state restriction (Samsung#6181)
Browse files Browse the repository at this point in the history
* [WebRTC] Change state restriction
  • Loading branch information
hsgwon authored and JoogabYun committed Jul 23, 2024
1 parent cb6e861 commit a1db665
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 42 deletions.
8 changes: 2 additions & 6 deletions src/Tizen.Multimedia.Remoting/WebRTC/MediaFileSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,11 @@ public TransceiverDirection GetTransceiverDirection(MediaType type)
/// 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)
Expand Down
7 changes: 2 additions & 5 deletions src/Tizen.Multimedia.Remoting/WebRTC/MediaMicrophoneSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ internal override void OnDetached(WebRTC webRtc)
/// </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"/>.
Expand All @@ -77,7 +76,7 @@ internal override void OnDetached(WebRTC webRtc)
/// -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.
Expand All @@ -91,8 +90,6 @@ public void ApplyAudioStreamPolicy(AudioStreamPolicy policy)
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)
Expand Down
11 changes: 2 additions & 9 deletions src/Tizen.Multimedia.Remoting/WebRTC/MediaNullSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,11 @@ public TransceiverCodec GetTransceiverCodec(MediaType type)
/// 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>
Expand All @@ -84,8 +79,6 @@ public void SetTransceiverCodec(MediaType type, TransceiverCodec codec)
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");
}
Expand Down
50 changes: 28 additions & 22 deletions src/Tizen.Multimedia.Remoting/WebRTC/WebRTC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,17 @@ public void Stop()
/// <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>
/// <seealso cref="CreateAnswerAsync()"/>
/// <since_tizen> 9 </since_tizen>
public async Task<string> CreateOfferAsync()
{
ValidateWebRTCState(WebRTCState.Negotiating);
ValidateWebRTCState(WebRTCState.Negotiating, WebRTCState.Playing);

var tcsSdpCreated = new TaskCompletionSource<string>();

Expand All @@ -259,15 +261,17 @@ public async Task<string> CreateOfferAsync()
/// <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>
/// <seealso cref="CreateOfferAsync()"/>
/// <since_tizen> 9 </since_tizen>
public async Task<string> CreateAnswerAsync()
{
ValidateWebRTCState(WebRTCState.Negotiating);
ValidateWebRTCState(WebRTCState.Negotiating, WebRTCState.Playing);

var tcsSdpCreated = new TaskCompletionSource<string>();

Expand All @@ -292,7 +296,9 @@ public async Task<string> CreateAnswerAsync()
/// <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>
Expand All @@ -303,7 +309,7 @@ public async Task<string> CreateAnswerAsync()
/// <since_tizen> 9 </since_tizen>
public void SetLocalDescription(string description)
{
ValidateWebRTCState(WebRTCState.Negotiating);
ValidateWebRTCState(WebRTCState.Negotiating, WebRTCState.Playing);

ValidationUtil.ValidateIsNullOrEmpty(description, nameof(description));

Expand All @@ -313,7 +319,9 @@ public void SetLocalDescription(string description)
/// <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>
Expand All @@ -324,7 +332,7 @@ public void SetLocalDescription(string description)
/// <since_tizen> 9 </since_tizen>
public void SetRemoteDescription(string description)
{
ValidateWebRTCState(WebRTCState.Negotiating);
ValidateWebRTCState(WebRTCState.Negotiating, WebRTCState.Playing);

ValidationUtil.ValidateIsNullOrEmpty(description, nameof(description));

Expand Down Expand Up @@ -378,7 +386,7 @@ public void AddIceCandidates(IEnumerable<string> iceCandidates)
/// 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/>
Expand All @@ -393,7 +401,7 @@ public void AddIceCandidates(IEnumerable<string> iceCandidates)
/// <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>
Expand All @@ -415,8 +423,6 @@ public void AddSource(MediaSource source)
throw new ArgumentNullException(nameof(source), "source is null");
}

ValidateWebRTCState(WebRTCState.Idle);

source?.AttachTo(this);

_source.Add(source);
Expand All @@ -426,7 +432,7 @@ public void AddSource(MediaSource source)
/// 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/>
Expand All @@ -441,7 +447,7 @@ public void AddSource(MediaSource source)
/// <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>
Expand Down Expand Up @@ -473,12 +479,12 @@ public void AddSources(params MediaSource[] sources)
/// 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"/>
Expand All @@ -495,8 +501,6 @@ public void RemoveSource(MediaSource source)
throw new ArgumentNullException(nameof(source), "source is null");
}

ValidateWebRTCState(WebRTCState.Idle);

source?.DetachFrom(this);

_source.Remove(source);
Expand All @@ -508,12 +512,12 @@ public void RemoveSource(MediaSource source)
/// 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"/>
Expand Down Expand Up @@ -601,15 +605,17 @@ public ReadOnlyCollection<string> GetTurnServer()
/// <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>
/// <exception cref="InvalidOperationException">The WebRTC is not in the valid state.</exception>
/// <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;
Expand Down

0 comments on commit a1db665

Please sign in to comment.