[NUI] Change SetMinAndMaxFrameByMarker behavior + Fix some async cases
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.StreamRecorder / StreamRecorder / StreamRecorder.Capabilities.cs
1 /*
2  * Copyright (c) 2016 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.Collections.Generic;
19 using System.Linq;
20 using Native = Interop.StreamRecorder;
21
22 namespace Tizen.Multimedia
23 {
24     public partial class StreamRecorder
25     {
26         internal void LoadCapabilities()
27         {
28             _videoCodecs = LoadVideoCodecs(this);
29             _audioCodecs = LoadAudioCodecs(this);
30             _fileFormats = LoadFileFormats(this);
31             _videoResolutions = LoadResolutions(this);
32         }
33
34         private static IEnumerable<RecorderVideoCodec> LoadVideoCodecs(StreamRecorder recorder)
35         {
36             var result = new List<RecorderVideoCodec>();
37             Native.VideoEncoderCallback callback = (codec, _) =>
38             {
39                 result.Add(codec.ToRecorderEnum());
40                 return true;
41             };
42
43             Native.VideoEncoders(recorder.Handle, callback).ThrowIfError("Failed to get the supported video codecs.");
44
45             return result.AsReadOnly();
46         }
47
48         private static IEnumerable<RecorderAudioCodec> LoadAudioCodecs(StreamRecorder recorder)
49         {
50             var result = new List<RecorderAudioCodec>();
51
52             Native.AudioEncoders(recorder.Handle, (codec, _) =>
53             {
54                 result.Add(codec.ToRecorderEnum());
55                 return true;
56             }).ThrowIfError("Failed to get the supported audio codecs.");
57
58             return result.AsReadOnly();
59         }
60
61         private static IEnumerable<RecorderFileFormat> LoadFileFormats(StreamRecorder recorder)
62         {
63             var result = new List<RecorderFileFormat>();
64
65             Native.FileFormats(recorder.Handle, (fileFormat, _) =>
66             {
67                 result.Add(fileFormat.ToRecorderEnum());
68                 return true;
69             }).ThrowIfError("Failed to get the supported file formats.");
70
71             return result.AsReadOnly();
72         }
73
74         private static IEnumerable<Size> LoadResolutions(StreamRecorder recorder)
75         {
76             List<Size> result = new List<Size>();
77
78             Native.VideoResolutionCallback callback = (width, height, _) =>
79             {
80                 result.Add(new Size(width, height));
81                 return true;
82             };
83
84             Native.VideoResolution(recorder.Handle, callback).
85                 ThrowIfError("Failed to get the supported video resolutions.");
86
87             return result.AsReadOnly();
88         }
89
90         private IEnumerable<RecorderFileFormat> _fileFormats;
91
92         /// <summary>
93         /// Gets the file formats that the current device supports.
94         /// </summary>
95         /// <returns>An IEnumerable of <see cref="RecorderFileFormat"/> representing the supported file formats.</returns>
96         /// <since_tizen> 4 </since_tizen>
97         [Obsolete("Deprecated in API10; Will be removed in API12")]
98         public IEnumerable<RecorderFileFormat> GetSupportedFileFormats() => _fileFormats;
99
100         private IEnumerable<RecorderAudioCodec> _audioCodecs;
101
102         /// <summary>
103         /// Gets the audio codecs that the current device supports.
104         /// </summary>
105         /// <returns>An IEnumerable of <see cref="RecorderAudioCodec"/> representing the supported audio codecs.</returns>
106         /// <since_tizen> 4 </since_tizen>
107         [Obsolete("Deprecated in API10; Will be removed in API12")]
108         public IEnumerable<RecorderAudioCodec> GetSupportedAudioCodecs() => _audioCodecs;
109
110         private IEnumerable<RecorderVideoCodec> _videoCodecs;
111
112         /// <summary>
113         /// Gets the video codecs that the current device supports.
114         /// </summary>
115         /// <returns>An IEnumerable of <see cref="RecorderVideoCodec"/> representing the supported video codecs.</returns>
116         /// <since_tizen> 4 </since_tizen>
117         [Obsolete("Deprecated in API10; Will be removed in API12")]
118         public IEnumerable<RecorderVideoCodec> GetSupportedVideoCodecs() => _videoCodecs;
119
120         private IEnumerable<Size> _videoResolutions;
121
122         /// <summary>
123         /// Gets the video resolutions that the current device supports.
124         /// </summary>
125         /// <returns>An IEnumerable of <see cref="Size"/> representing the supported resolutions.</returns>
126         /// <since_tizen> 4 </since_tizen>
127         [Obsolete("Deprecated in API10; Will be removed in API12")]
128         public IEnumerable<Size> GetSupportedVideoResolutions() => _videoResolutions;
129
130         internal void ValidateFileFormat(RecorderFileFormat format)
131         {
132             if (_fileFormats.Contains(format) == false)
133             {
134                 throw new NotSupportedException($"{format.ToString()} is not supported.");
135             }
136         }
137
138         internal void ValidateAudioCodec(RecorderAudioCodec codec)
139         {
140             if (_audioCodecs.Contains(codec) == false)
141             {
142                 throw new NotSupportedException($"{codec.ToString()} is not supported.");
143             }
144         }
145
146         internal void ValidateVideoCodec(RecorderVideoCodec codec)
147         {
148             if (_videoCodecs.Contains(codec) == false)
149             {
150                 throw new NotSupportedException($"{codec.ToString()} is not supported.");
151             }
152         }
153
154         internal void ValidateVideoResolution(Size resolution)
155         {
156             if (_videoResolutions.Contains(resolution) == false)
157             {
158                 throw new NotSupportedException($"Resolution({resolution.ToString()}) is not supported.");
159             }
160         }
161     }
162 }