[Multimedia] Deprecate constructors related to ElmSharp (#4540)
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Remoting / WebRTC / MediaTestSource.cs
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18 using System.Diagnostics;
19 using static Interop;
20
21 namespace Tizen.Multimedia.Remoting
22 {
23     /// <summary>
24     /// Represents an audio or a video test source.
25     /// </summary>
26     /// <seealso cref="WebRTC.AddSource"/>
27     /// <seealso cref="WebRTC.AddSources"/>
28     /// <since_tizen> 9 </since_tizen>
29     public sealed class MediaTestSource : MediaSource
30     {
31         /// <summary>
32         /// Initializes a new instance of the <see cref="MediaTestSource"/> class.
33         /// </summary>
34         /// <since_tizen> 9 </since_tizen>
35         public MediaTestSource(MediaType type) : base(type) {}
36         internal override void OnAttached(WebRTC webRtc)
37         {
38             Debug.Assert(webRtc != null);
39
40             if (WebRtc != null)
41             {
42                 throw new InvalidOperationException("The source is has already been assigned to another WebRTC.");
43             }
44
45             var type = MediaType == MediaType.Video ? MediaSourceType.VideoTest : MediaSourceType.AudioTest;
46
47             NativeWebRTC.AddMediaSource(webRtc.Handle, type, out uint sourceId).
48                 ThrowIfFailed($"Failed to add {MediaType.ToString()} MediaTestSource.");
49
50             WebRtc = webRtc;
51             SourceId = sourceId;
52         }
53
54         internal override void OnDetached(WebRTC webRtc)
55         {
56             NativeWebRTC.RemoveMediaSource(webRtc.Handle, SourceId.Value).
57                 ThrowIfFailed($"Failed to remove {MediaType.ToString()} MediaTestSource.");
58
59             WebRtc = null;
60         }
61     }
62 }