Skip to content

Commit

Permalink
[WebRTC] Add Mute API for audio track (#5440)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsgwon authored Aug 4, 2023
1 parent 3d11880 commit bad2ff3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/Tizen.Multimedia.Remoting/Interop/Interop.WebRTC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ internal static extern WebRTCErrorCode ForeachSupportedTransceiverCodec(IntPtr h
[DllImport(Libraries.WebRTC, EntryPoint = "webrtc_set_sound_stream_info")]
internal static extern WebRTCErrorCode SetAudioStreamPolicy(IntPtr handle, uint trackId, AudioStreamPolicyHandle streamInfo);

[DllImport(Libraries.WebRTC, EntryPoint = "webrtc_set_audio_mute")]
internal static extern WebRTCErrorCode SetAudioMute(IntPtr handle, uint trackId, bool mute);

[DllImport(Libraries.WebRTC, EntryPoint = "webrtc_get_audio_mute")]
internal static extern WebRTCErrorCode GetAudioMute(IntPtr handle, uint trackId, out bool isMuted);

[DllImport(Libraries.WebRTC, EntryPoint = "webrtc_set_display")]
internal static extern WebRTCErrorCode SetDisplay(IntPtr handle, uint trackId, WebRTCDisplayType type, IntPtr display);

Expand Down
45 changes: 39 additions & 6 deletions src/Tizen.Multimedia.Remoting/WebRTC/MediaStreamTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public Display Display
{
if (Type != MediaType.Video)
{
throw new InvalidOperationException("This property is only for video.");
throw new InvalidOperationException("This property is only for video track.");
}

if (value == null)
Expand Down Expand Up @@ -132,7 +132,7 @@ public WebRTCDisplayMode DisplayMode
{
if (Type != MediaType.Video)
{
throw new InvalidOperationException("This property is only for video.");
throw new InvalidOperationException("This property is only for video track.");
}

NativeWebRTC.GetDisplayMode(_webRtc.Handle, _trackId, out var val).
Expand All @@ -144,7 +144,7 @@ public WebRTCDisplayMode DisplayMode
{
if (Type != MediaType.Video)
{
throw new InvalidOperationException("This property is only for video.");
throw new InvalidOperationException("This property is only for video track.");
}

ValidationUtil.ValidateEnum(typeof(WebRTCDisplayMode), value, nameof(value));
Expand All @@ -169,7 +169,7 @@ public bool DisplayVisible
{
if (Type != MediaType.Video)
{
throw new InvalidOperationException("This property is only for video.");
throw new InvalidOperationException("This property is only for video track.");
}

NativeWebRTC.GetDisplayVisible(_webRtc.Handle, _trackId, out bool val).
Expand All @@ -181,14 +181,47 @@ public bool DisplayVisible
{
if (Type != MediaType.Video)
{
throw new InvalidOperationException("This property is only for video.");
throw new InvalidOperationException("This property is only for video track.");
}

NativeWebRTC.SetDisplayVisible(_webRtc.Handle, _trackId, value).
ThrowIfFailed("Failed to set display status.");
}
}

/// <summary>
/// Gets or sets the mute status of the audio track.
/// </summary>
/// <value>true if audio is muted, otherwise false. The default value is false.</value>
/// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
/// <exception cref="InvalidOperationException">This MediaStreamTrack is not Audio.</exception>
/// <since_tizen> 11 </since_tizen>
public bool Mute
{
get
{
if (Type != MediaType.Audio)
{
throw new InvalidOperationException("This property is only for audio track.");
}

NativeWebRTC.GetAudioMute(_webRtc.Handle, _trackId, out bool val).
ThrowIfFailed("Failed to get audio mute status");

return val;
}
set
{
if (Type != MediaType.Audio)
{
throw new InvalidOperationException("This property is only for audio track.");
}

NativeWebRTC.SetAudioMute(_webRtc.Handle, _trackId, value).
ThrowIfFailed("Failed to set audio mute status.");
}
}

/// <summary>
/// Applies the audio stream policy to remote track.
/// </summary>
Expand Down Expand Up @@ -228,7 +261,7 @@ public void ApplyAudioStreamPolicy(AudioStreamPolicy policy)

if (Type != MediaType.Audio)
{
throw new InvalidOperationException("Should be applied in Audio");
throw new InvalidOperationException("This method is only for audio track.");
}

var ret = NativeWebRTC.SetAudioStreamPolicy(_webRtc.Handle, _trackId, policy.Handle);
Expand Down

0 comments on commit bad2ff3

Please sign in to comment.