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 camera source.
26 /// <remarks>The camera privilege(http://tizen.org/privilege/camera) is required.</remarks>
27 /// <seealso cref="WebRTC.AddSource"/>
28 /// <seealso cref="WebRTC.AddSources"/>
29 /// <since_tizen> 9 </since_tizen>
30 public sealed class MediaCameraSource : MediaSource
33 /// Initializes a new instance of the <see cref="MediaCameraSource"/> class.
35 /// <since_tizen> 9 </since_tizen>
36 public MediaCameraSource() : base(MediaType.Video) {}
39 /// Gets or sets the camera device id.
41 /// <value>A value that specifies the camera device id.</value>
42 /// <exception cref="InvalidOperationException">MediaSource is not attached yet.</exception>
43 /// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
44 /// <since_tizen> 10 </since_tizen>
45 public uint CameraDeviceId
49 if (!SourceId.HasValue)
51 throw new InvalidOperationException("MediaSource is not attached yet. Call AddSource() first.");
54 NativeWebRTC.GetCameraDeviceId(WebRtc.Handle, SourceId.Value, out uint deviceId).
55 ThrowIfFailed("Failed to get camera device id");
61 if (!SourceId.HasValue)
63 throw new InvalidOperationException("MediaSource is not attached yet. Call AddSource() first.");
66 NativeWebRTC.SetCameraDeviceId(WebRtc.Handle, SourceId.Value, value).
67 ThrowIfFailed("Failed to set camera device id");
71 internal override void OnAttached(WebRTC webRtc)
73 Debug.Assert(webRtc != null);
77 throw new InvalidOperationException("The source is has already been assigned to another WebRTC.");
80 NativeWebRTC.AddMediaSource(webRtc.Handle, MediaSourceType.Camera, out uint sourceId).
81 ThrowIfFailed("Failed to add MediaCameraSource.");
87 internal override void OnDetached(WebRTC webRtc)
89 NativeWebRTC.RemoveMediaSource(webRtc.Handle, SourceId.Value).
90 ThrowIfFailed("Failed to remove MediaCameraSource.");