/// <summary>
/// Initializes a new instance of the <see cref="MediaFileSource"/> class.
/// </summary>
- /// <param name="type">The <see cref="MediaType"/> of file source.</param>
/// <param name="path">The file path.</param>
/// <exception cref="ArgumentNullException"><paramref name="path"/> is null.</exception>
/// <since_tizen> 10 </since_tizen>
- public MediaFileSource(MediaType type, string path) : base(type)
+ public MediaFileSource(string path) : base()
{
_path = path ?? throw new ArgumentNullException(nameof(path), "path is null");
}
}
}
+ /// <summary>
+ /// Gets the transceiver direction for receiving media stream.
+ /// </summary>
+ /// <param name="type">The media type.</param>
+ /// <returns>The transceiver direction.</returns>
+ /// <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 TransceiverDirection GetTransceiverDirection(MediaType type)
+ {
+ if (!SourceId.HasValue)
+ {
+ throw new InvalidOperationException("MediaSource is not attached yet. Call AddSource() first.");
+ }
+
+ NativeWebRTC.GetTransceiverDirection(WebRtc.Handle, SourceId.Value, type, out TransceiverDirection direction).
+ ThrowIfFailed("Failed to get transceiver direction.");
+
+ return direction;
+ }
+
+ /// <summary>
+ /// 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.
+ /// </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="ObjectDisposedException">The WebRTC has already been disposed.</exception>
+ /// <since_tizen> 10 </since_tizen>
+ public void SetTransceiverDirection(MediaType type, TransceiverDirection direction)
+ {
+ if (!SourceId.HasValue)
+ {
+ throw new InvalidOperationException("MediaSource is not attached yet. Call AddSource() first.");
+ }
+
+ WebRtc.ValidateWebRTCState(WebRTCState.Idle);
+
+ NativeWebRTC.SetTransceiverDirection(WebRtc.Handle, SourceId.Value, type, direction).
+ ThrowIfFailed("Failed to set transceiver direction");
+ }
+
+ /// <summary>
+ /// Gets the pause status of media file source.
+ /// </summary>
+ /// <param name="type">The media type.</param>
+ /// <returns>The pause status.</returns>
+ /// <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 bool GetPause(MediaType type)
+ {
+ if (!SourceId.HasValue)
+ {
+ throw new InvalidOperationException("MediaSource is not attached yet. Call AddSource() first.");
+ }
+
+ WebRtc.ValidateWebRTCState(WebRTCState.Idle);
+
+ NativeWebRTC.GetPause(WebRtc.Handle, SourceId.Value, MediaType, out bool isPaused).
+ ThrowIfFailed("Failed to get pause");
+
+ return isPaused;
+ }
+
+ /// <summary>
+ /// Sets the pause status of media file source.
+ /// </summary>
+ /// <param name="type">The media type.</param>
+ /// <param name="isPaused">The pause status.</param>
+ /// <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 SetPause(MediaType type, bool isPaused)
+ {
+ if (!SourceId.HasValue)
+ {
+ throw new InvalidOperationException("MediaSource is not attached yet. Call AddSource() first.");
+ }
+
+ WebRtc.ValidateWebRTCState(WebRTCState.Idle);
+
+ NativeWebRTC.SetPause(WebRtc.Handle, SourceId.Value, type, isPaused).
+ ThrowIfFailed("Failed to set pause");
+ }
+
internal override void OnAttached(WebRTC webRtc)
{
Debug.Assert(webRtc != null);
WebRtc = null;
}
+
+ internal override MediaSourceType MediaSourceType => MediaSourceType.File;
}
}
--- /dev/null
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Collections.ObjectModel;
+using System.Diagnostics;
+using NativeWebRTC = Interop.NativeWebRTC;
+
+namespace Tizen.Multimedia.Remoting
+{
+ /// <summary>Represents a null source.</summary>
+ /// <remarks>
+ /// If you add this source, WebRTC only receives media stream.<br/>
+ /// <see cref="TransceiverDirection"/> is set <see cref="TransceiverDirection.RecvOnly"/> by default.
+ /// </remarks>
+ /// <seealso cref="WebRTC.AddSource"/>
+ /// <since_tizen> 10 </since_tizen>
+ public sealed class MediaNullSource : MediaSource
+ {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="MediaNullSource"/> class.
+ /// </summary>
+ /// <remarks>TransceiverCodec should be set to receive audio, video stream.</remarks>
+ /// <seealso cref="SetTransceiverCodec"/>
+ /// <since_tizen> 10 </since_tizen>
+ public MediaNullSource() : base() {}
+
+ /// <summary>
+ /// Gets the transceiver codec for receiving media stream.
+ /// </summary>
+ /// <param name="type">The media type.</param>
+ /// <returns>The transceiver codec.</returns>
+ /// <exception cref="InvalidOperationException">MediaSource is not attached yet.</exception>
+ /// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
+ /// <seealso cref="SetTransceiverCodec"/>
+ /// <since_tizen> 10 </since_tizen>
+ public TransceiverCodec GetTransceiverCodec(MediaType type)
+ {
+ if (!SourceId.HasValue)
+ {
+ throw new InvalidOperationException("MediaSource is not attached yet. Call AddSource() first.");
+ }
+
+ NativeWebRTC.GetTransceiverCodec(WebRtc.Handle, SourceId.Value, type, out TransceiverCodec codec).
+ ThrowIfFailed("Failed to get transceiver codec");
+
+ return codec;
+ }
+
+ /// <summary>
+ /// 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/>
+ ///
+ /// </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="ObjectDisposedException">The WebRTC has already been disposed.</exception>
+ /// <seealso cref="GetTransceiverCodec"/>
+ /// <since_tizen> 10 </since_tizen>
+ public void SetTransceiverCodec(MediaType type, TransceiverCodec codec)
+ {
+ if (!SourceId.HasValue)
+ {
+ 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");
+ }
+
+ /// <summary>
+ /// Retrieves the supported transceiver codecs.
+ /// </summary>
+ /// <param name="type">The media type.</param>
+ /// <returns>The supported transceiver codecs.</returns>
+ /// <exception cref="InvalidOperationException">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 ReadOnlyCollection<TransceiverCodec> GetSupportedTransceiverCodecs(MediaType type)
+ {
+ return new ReadOnlyCollection<TransceiverCodec>(ForeachSupportedTransceiverCodecs(type));
+ }
+
+ internal override void OnAttached(WebRTC webRtc)
+ {
+ Debug.Assert(webRtc != null);
+
+ if (WebRtc != null)
+ {
+ throw new InvalidOperationException("The source is has already been assigned to another WebRTC.");
+ }
+
+ NativeWebRTC.AddMediaSource(webRtc.Handle, MediaSourceType.Null, out uint sourceId).
+ ThrowIfFailed("Failed to add MediaNullSource.");
+
+ WebRtc = webRtc;
+ SourceId = sourceId;
+ TransceiverDirection = TransceiverDirection.RecvOnly;
+ }
+
+ internal override void OnDetached(WebRTC webRtc)
+ {
+ NativeWebRTC.RemoveMediaSource(webRtc.Handle, SourceId.Value).
+ ThrowIfFailed("Failed to remove MediaNullSource.");
+
+ WebRtc = null;
+ }
+ }
+}
MediaType = mediaType;
}
+ /// <summary>
+ /// Initializes a new instance of the <see cref="MediaSource"/> class.
+ /// </summary>
+ /// <since_tizen> 10 </since_tizen>
+ protected MediaSource() { }
+
internal void AttachTo(WebRTC webRtc)
{
if (IsDetached)
internal abstract void OnDetached(WebRTC webRtc);
+ internal virtual MediaSourceType MediaSourceType => MediaSourceType.Null;
+
/// <summary>
/// Gets or sets the transceiver direction of current media source.
/// </summary>
+ /// <remarks>
+ /// If user want to set each audio, video direction in <see cref="MediaFileSource"/>,
+ /// please use <see cref="MediaFileSource.SetTransceiverDirection"/>. (Since API level 10)<br/>
+ /// In <see cref="MediaNullSource"/>, only <see cref="TransceiverDirection.SendRecv"/> can be set.(Since API level 10)
+ /// </remarks>
/// <value>A <see cref="TransceiverDirection"/> that specifies the transceiver direction.</value>
- /// <exception cref="InvalidOperationException">MediaSource is not attached yet.</exception>
+ /// <exception cref="InvalidOperationException">
+ /// MediaSource is not attached yet.<br/>
+ /// -or-<br/>
+ /// <see cref="TransceiverDirection.SendOnly"/> or <see cref="TransceiverDirection.SendRecv"/> is set for MediaNullSource. (Since API level 10)
+ /// </exception>
/// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
+ /// <seealso cref="MediaFileSource.GetTransceiverDirection"/>
+ /// <seealso cref="MediaFileSource.SetTransceiverDirection"/>
/// <since_tizen> 9 </since_tizen>
public TransceiverDirection TransceiverDirection
{
{
throw new InvalidOperationException("MediaSource is not attached yet. Call AddSource() first.");
}
+ if (this is MediaNullSource)
+ {
+ return TransceiverDirection.RecvOnly;
+ }
NativeWebRTC.GetTransceiverDirection(WebRtc.Handle, SourceId.Value, MediaType, out TransceiverDirection mode).
ThrowIfFailed("Failed to get transceiver direction.");
{
throw new InvalidOperationException("MediaSource is not attached yet. Call AddSource() first.");
}
+ if (this is MediaNullSource)
+ {
+ if (value != TransceiverDirection.RecvOnly)
+ {
+ throw new InvalidOperationException("Only RecvOnly is allowed for MediaNullSource.");
+ }
- NativeWebRTC.SetTransceiverDirection(WebRtc.Handle, SourceId.Value, MediaType, value).
- ThrowIfFailed("Failed to get transceiver direction.");
+ return;
+ }
+
+ if (this is MediaNullSource || this is MediaFileSource)
+ {
+ NativeWebRTC.SetTransceiverDirection(WebRtc.Handle, SourceId.Value, MediaType.Audio, value).
+ ThrowIfFailed("Failed to set audio transceiver direction.");
+ NativeWebRTC.SetTransceiverDirection(WebRtc.Handle, SourceId.Value, MediaType.Video, value).
+ ThrowIfFailed("Failed to set video transceiver direction.");
+ }
+ else
+ {
+ NativeWebRTC.SetTransceiverDirection(WebRtc.Handle, SourceId.Value, MediaType, value).
+ ThrowIfFailed("Failed to set transceiver direction.");
+ }
}
}
/// </summary>
/// <remarks>
/// This API is not supported in <see cref="MediaFileSource"/>, <see cref="MediaPacketSource"/>.<br/>
+ /// If <see cref="MediaNullSource"/>, please use <see cref="MediaNullSource.GetTransceiverCodec"/>
+ /// or <see cref="MediaNullSource.SetTransceiverCodec"/> instead.<br/>
/// The WebRTC must be in the <see cref="WebRTCState.Idle"/> state when transceiver codec is set.
/// </remarks>
/// <value>The transceiver codec.</value>
/// The WebRTC is not in the valid state.
/// </exception>
/// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
+ /// <seealso cref="MediaNullSource.GetTransceiverCodec"/>
+ /// <seealso cref="MediaNullSource.SetTransceiverCodec"/>
/// <since_tizen> 10 </since_tizen>
public TransceiverCodec TransceiverCodec
{
{
throw new InvalidOperationException("MediaSource is not attached yet. Call AddSource() first.");
}
- if (this is MediaFileSource || this is MediaPacketSource)
+ if (this is MediaFileSource || this is MediaPacketSource || this is MediaNullSource)
{
throw new InvalidOperationException($"This property is not supported in {this.GetType()}.");
}
{
throw new InvalidOperationException("MediaSource is not attached yet. Call AddSource() first.");
}
- if (this is MediaFileSource || this is MediaPacketSource)
+ if (this is MediaFileSource || this is MediaPacketSource || this is MediaNullSource)
{
throw new InvalidOperationException($"This property is not supported in {this.GetType()}.");
}
/// Retrieves the supported transceiver codecs.
/// </summary>
/// <remarks>
- /// This API is not supported in <see cref="MediaFileSource"/>, <see cref="MediaPacketSource"/>.
+ /// This API is not supported in <see cref="MediaFileSource"/>, <see cref="MediaPacketSource"/>.<br/>
+ /// If user want to get supported codecs for each audio or video in <see cref="MediaNullSource"/>,
+ /// please use <see cref="MediaNullSource.GetSupportedTransceiverCodecs"/> instead.
/// </remarks>
/// <returns>The transceiver codecs.</returns>
/// <exception cref="InvalidOperationException">This MediaSource is not supported type of MediaSource.</exception>
/// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
+ /// <seealso cref="MediaNullSource.GetSupportedTransceiverCodecs"/>
/// <since_tizen> 10 </since_tizen>
public ReadOnlyCollection<TransceiverCodec> SupportedTransceiverCodecs
{
{
throw new InvalidOperationException($"This property is not supported in {this.GetType()}.");
}
-
- var codecs = new List<TransceiverCodec>();
- Exception caught = null;
-
- NativeWebRTC.RetrieveTransceiverCodecCallback cb = (codec, _) =>
- {
- try
- {
- codecs.Add(codec);
- }
- catch (Exception e)
- {
- caught = e;
- return false;
- }
-
- return true;
- };
-
- using (var cbKeeper = ObjectKeeper.Get(cb))
+ if (this is MediaNullSource)
{
- NativeWebRTC.ForeachSupportedTransceiverCodec(WebRtc.Handle, GetMediaSourceType(), MediaType, cb).
- ThrowIfFailed("failed to retrieve stats");
+ var codecs = ForeachSupportedTransceiverCodecs(MediaType.Audio);
+ codecs.AddRange(ForeachSupportedTransceiverCodecs(MediaType.Video));
- if (caught != null)
- {
- throw caught;
- }
+ return new ReadOnlyCollection<TransceiverCodec>(codecs);
}
- return new ReadOnlyCollection<TransceiverCodec>(codecs);
+ return new ReadOnlyCollection<TransceiverCodec>(ForeachSupportedTransceiverCodecs(MediaType));
}
}
- private MediaSourceType GetMediaSourceType()
+ internal List<TransceiverCodec> ForeachSupportedTransceiverCodecs(MediaType type)
{
- if (this is MediaTestSource)
+ var codecs = new List<TransceiverCodec>();
+ Exception caught = null;
+
+ NativeWebRTC.RetrieveTransceiverCodecCallback cb = (codec, _) =>
{
- if (MediaType == MediaType.Audio)
+ try
{
- return MediaSourceType.AudioTest;
+ codecs.Add(codec);
}
- else
+ catch (Exception e)
{
- return MediaSourceType.VideoTest;
+ caught = e;
+ return false;
}
- }
- else if (this is MediaMicrophoneSource)
- {
- return MediaSourceType.Microphone;
- }
- else if (this is MediaCameraSource)
- {
- return MediaSourceType.Camera;
- }
- else if (this is MediaScreenSource)
- {
- return MediaSourceType.Screen;
- }
- else if (this is MediaFileSource)
- {
- return MediaSourceType.File;
- }
- else if (this is MediaPacketSource)
+
+ return true;
+ };
+
+ using (var cbKeeper = ObjectKeeper.Get(cb))
{
- return MediaSourceType.MediaPacket;
+ try
+ {
+ NativeWebRTC.ForeachSupportedTransceiverCodec(WebRtc.Handle, MediaSourceType.Null, type, cb).
+ ThrowIfFailed("failed to retrieve stats");
+ }
+ catch
+ {
+ Log.Info(WebRTCLog.Tag, "This is not error in csharp.");
+ }
+
+ if (caught != null)
+ {
+ throw caught;
+ }
}
- return MediaSourceType.Null;
+ return codecs;
}
/// <summary>
/// Gets or sets the pause status of current media source.
/// </summary>
+ /// If <see cref="MediaFileSource"/>, please use <see cref="MediaFileSource.GetPause"/>
+ /// or <see cref="MediaFileSource.SetPause"/> instead.<br/> (Since API level 10)
/// <value>A value that specifies the pause status.</value>
- /// <exception cref="InvalidOperationException">MediaSource is not attached yet.</exception>
+ /// <exception cref="InvalidOperationException">
+ /// MediaSource is not attached yet.<br/>
+ /// -or-<br/>
+ /// This MediaSource is not supported type of MediaSource. (Since API level 10)
+ /// </exception>
/// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
+ /// <seealso cref="MediaFileSource.GetPause"/>
+ /// <seealso cref="MediaFileSource.SetPause"/>
/// <since_tizen> 9 </since_tizen>
public bool Pause
{
{
throw new InvalidOperationException("MediaSource is not attached yet. Call AddSource() first.");
}
+ if (this is MediaFileSource || this is MediaNullSource)
+ {
+ throw new InvalidOperationException($"This property is not supported in {this.GetType()}.");
+ }
NativeWebRTC.GetPause(WebRtc.Handle, SourceId.Value, MediaType, out bool isPaused).
ThrowIfFailed("Failed to get pause");
{
throw new InvalidOperationException("MediaSource is not attached yet. Call AddSource() first.");
}
+ if (this is MediaFileSource || this is MediaNullSource)
+ {
+ throw new InvalidOperationException($"This property is not supported in {this.GetType()}.");
+ }
NativeWebRTC.SetPause(WebRtc.Handle, SourceId.Value, MediaType, value).
ThrowIfFailed("Failed to set pause");
/// <summary>
/// Gets or sets the mute status of the current media source.
/// </summary>
+ /// <remarks>
+ /// This API is not supported in <see cref="MediaFileSource"/>, <see cref="MediaPacketSource"/>, <see cref="MediaNullSource"/>. (Since API level 10)
+ /// </remarks>
/// <value>A value that specifies the mute status.</value>
- /// <exception cref="InvalidOperationException">MediaSource is not attached yet.</exception>
+ /// <exception cref="InvalidOperationException">
+ /// MediaSource is not attached yet.<br/>
+ /// -or-<br/>
+ /// This MediaSource is not supported type of MediaSource. (Since API level 10)
+ /// </exception>
/// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
/// <since_tizen> 9 </since_tizen>
public bool Mute
{
throw new InvalidOperationException("MediaSource is not attached yet. Call AddSource() first.");
}
+ if (this is MediaFileSource || this is MediaPacketSource || this is MediaNullSource)
+ {
+ throw new InvalidOperationException($"This property is not supported in {this.GetType()}.");
+ }
NativeWebRTC.GetMute(WebRtc.Handle, SourceId.Value, MediaType, out bool isMuted).
ThrowIfFailed("Failed to get mute");
{
throw new InvalidOperationException("MediaSource is not attached yet. Call AddSource() first.");
}
+ if (this is MediaFileSource || this is MediaPacketSource || this is MediaNullSource)
+ {
+ throw new InvalidOperationException($"This property is not supported in {this.GetType()}.");
+ }
NativeWebRTC.SetMute(WebRtc.Handle, SourceId.Value, MediaType, value).
ThrowIfFailed("Failed to set mute");
/// 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> 9 </since_tizen>
{
throw new InvalidOperationException("This property is only for video.");
}
+ if (this is MediaFileSource || this is MediaPacketSource)
+ {
+ throw new InvalidOperationException($"This property is not supported in {this.GetType()}.");
+ }
NativeWebRTC.GetVideoResolution(WebRtc.Handle, SourceId.Value, out int width, out int height).
ThrowIfFailed("Failed to get video resolution");
{
throw new InvalidOperationException("This property is only for video.");
}
+ if (this is MediaFileSource || this is MediaPacketSource)
+ {
+ throw new InvalidOperationException($"This property is not supported in {this.GetType()}.");
+ }
NativeWebRTC.SetVideoResolution(WebRtc.Handle, SourceId.Value, value.Width, value.Height).
ThrowIfFailed("Failed to set video resolution");
/// 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/>
+ /// This API is not supported in <see cref="MediaFileSource"/>, <see cref="MediaPacketSource"/>.
/// </remarks>
/// <value>A value that specifies the encoder bitrate.</value>
/// <exception cref="ArgumentException">EncoderBitrate is less than or equal to zero.</exception>