2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Diagnostics;
19 using NativeWebRTC = Interop.NativeWebRTC;
21 namespace Tizen.Multimedia.Remoting
24 /// Represents a microphone source.
26 /// <remarks>The recorder privilege(http://tizen.org/privilege/recorder) is required.</remarks>
27 /// <seealso cref="WebRTC.AddSource"/>
28 /// <seealso cref="WebRTC.AddSources"/>
29 /// <since_tizen> 9 </since_tizen>
30 public sealed class MediaMicrophoneSource : MediaSource
33 /// Initializes a new instance of the <see cref="MediaMicrophoneSource"/> class.
35 /// <since_tizen> 9 </since_tizen>
36 public MediaMicrophoneSource() : base(MediaType.Audio) {}
38 internal override void OnAttached(WebRTC webRtc)
40 Debug.Assert(webRtc != null);
43 Log.Error(WebRTCLog.Tag, "The source is has already been assigned to another WebRTC.");
44 throw new InvalidOperationException("The source is has already been assigned to another WebRTC.");
47 NativeWebRTC.AddMediaSource(webRtc.Handle, MediaSourceType.Microphone, out uint sourceId).
48 ThrowIfFailed("Failed to add MediaMicrophoneSource.");
54 internal override void OnDetached(WebRTC webRtc)
56 NativeWebRTC.RemoveMediaSource(webRtc.Handle, SourceId.Value).
57 ThrowIfFailed("Failed to remove MediaMicrophoneSource.");
59 WebRtc = (WebRTC)null;
63 /// Applies the audio stream policy to <see cref="MediaMicrophoneSource"/>.
65 /// <param name="policy">The <see cref="AudioStreamPolicy"/> to apply.</param>
67 /// The WebRTC must be in the <see cref="WebRTCState.Idle"/> state.<br/>
69 /// <see cref="WebRTC"/> does not support all <see cref="AudioStreamType"/>.<br/>
70 /// Supported types are <see cref="AudioStreamType.Media"/>, <see cref="AudioStreamType.VoiceRecognition"/>,
71 /// <see cref="AudioStreamType.Voip"/>, <see cref="AudioStreamType.MediaExternalOnly"/>.
73 /// <exception cref="ObjectDisposedException">
74 /// The WebRTC has already been disposed.<br/>
76 /// <paramref name="policy"/> has already been disposed.
78 /// <exception cref="InvalidOperationException">The WebRTC is not in the valid state.</exception>
79 /// <exception cref="ArgumentNullException"><paramref name="policy"/> is null.</exception>
80 /// <exception cref="NotSupportedException">
81 /// <see cref="AudioStreamType"/> of <paramref name="policy"/> is not supported on the current platform.
83 /// <seealso cref="AudioStreamPolicy"/>
84 /// <since_tizen> 9 </since_tizen>
85 public void ApplyAudioStreamPolicy(AudioStreamPolicy policy)
89 throw new ArgumentNullException(nameof(policy), "policy is null");
92 WebRtc.ValidateWebRTCState(WebRTCState.Idle);
94 var ret = NativeWebRTC.SetAudioStreamPolicyToMicrophoneSource(WebRtc.Handle, SourceId.Value, policy.Handle);
96 if (ret == WebRTCErrorCode.InvalidArgument)
98 throw new NotSupportedException("The specified policy is not supported on the current system.");
101 ret.ThrowIfFailed("Failed to set the audio stream policy to the WebRTC");