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 media source with contents read from a file.
27 /// Depending on where the source file is located either the media storage privilege (http://tizen.org/privilege/mediastorage) is required or<br/>
28 /// the external storage privilege(http://tizen.org/privilege/externalstorage) is required.
30 /// <seealso cref="WebRTC.AddSource"/>
31 /// <seealso cref="WebRTC.AddSources"/>
32 /// <since_tizen> 10 </since_tizen>
33 public sealed class MediaFileSource : MediaSource
38 /// Initializes a new instance of the <see cref="MediaFileSource"/> class.
40 /// <param name="type">The <see cref="MediaType"/> of file source.</param>
41 /// <param name="path">The file path.</param>
42 /// <exception cref="ArgumentNullException"><paramref name="path"/> is null.</exception>
43 /// <since_tizen> 10 </since_tizen>
44 public MediaFileSource(MediaType type, string path) : base(type)
46 _path = path ?? throw new ArgumentNullException(nameof(path), "path is null");
49 internal override void OnAttached(WebRTC webRtc)
51 Debug.Assert(webRtc != null);
55 throw new InvalidOperationException("The source is has already been assigned to another WebRTC.");
58 NativeWebRTC.AddMediaSource(webRtc.Handle, MediaSourceType.File, out uint sourceId).
59 ThrowIfFailed("Failed to add MediaFileSource.");
61 NativeWebRTC.SetFileSourcePath(webRtc.Handle, sourceId, _path).
62 ThrowIfFailed("Failed to set path for MediaFileSource.");
68 internal override void OnDetached(WebRTC webRtc)
70 NativeWebRTC.RemoveMediaSource(webRtc.Handle, SourceId.Value).
71 ThrowIfFailed("Failed to remove MediaFileSource.");