2 * Copyright (c) 2016 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.Collections.Generic;
20 using Native = Interop.StreamRecorder;
22 namespace Tizen.Multimedia
24 public partial class StreamRecorder
26 internal void LoadCapabilities()
28 _videoCodecs = LoadVideoCodecs(this);
29 _audioCodecs = LoadAudioCodecs(this);
30 _fileFormats = LoadFileFormats(this);
31 _videoResolutions = LoadResolutions(this);
34 private static IEnumerable<RecorderVideoCodec> LoadVideoCodecs(StreamRecorder recorder)
36 var result = new List<RecorderVideoCodec>();
37 Native.VideoEncoderCallback callback = (codec, _) =>
39 result.Add(codec.ToRecorderEnum());
43 Native.VideoEncoders(recorder.Handle, callback).ThrowIfError("Failed to get the supported video codecs.");
45 return result.AsReadOnly();
48 private static IEnumerable<RecorderAudioCodec> LoadAudioCodecs(StreamRecorder recorder)
50 var result = new List<RecorderAudioCodec>();
52 Native.AudioEncoders(recorder.Handle, (codec, _) =>
54 result.Add(codec.ToRecorderEnum());
56 }).ThrowIfError("Failed to get the supported audio codecs.");
58 return result.AsReadOnly();
61 private static IEnumerable<RecorderFileFormat> LoadFileFormats(StreamRecorder recorder)
63 var result = new List<RecorderFileFormat>();
65 Native.FileFormats(recorder.Handle, (fileFormat, _) =>
67 result.Add(fileFormat.ToRecorderEnum());
69 }).ThrowIfError("Failed to get the supported file formats.");
71 return result.AsReadOnly();
74 private static IEnumerable<Size> LoadResolutions(StreamRecorder recorder)
76 List<Size> result = new List<Size>();
78 Native.VideoResolutionCallback callback = (width, height, _) =>
80 result.Add(new Size(width, height));
84 Native.VideoResolution(recorder.Handle, callback).
85 ThrowIfError("Failed to get the supported video resolutions.");
87 return result.AsReadOnly();
90 private IEnumerable<RecorderFileFormat> _fileFormats;
93 /// Gets the file formats that the current device supports.
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;
100 private IEnumerable<RecorderAudioCodec> _audioCodecs;
103 /// Gets the audio codecs that the current device supports.
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;
110 private IEnumerable<RecorderVideoCodec> _videoCodecs;
113 /// Gets the video codecs that the current device supports.
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;
120 private IEnumerable<Size> _videoResolutions;
123 /// Gets the video resolutions that the current device supports.
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;
130 internal void ValidateFileFormat(RecorderFileFormat format)
132 if (_fileFormats.Contains(format) == false)
134 throw new NotSupportedException($"{format.ToString()} is not supported.");
138 internal void ValidateAudioCodec(RecorderAudioCodec codec)
140 if (_audioCodecs.Contains(codec) == false)
142 throw new NotSupportedException($"{codec.ToString()} is not supported.");
146 internal void ValidateVideoCodec(RecorderVideoCodec codec)
148 if (_videoCodecs.Contains(codec) == false)
150 throw new NotSupportedException($"{codec.ToString()} is not supported.");
154 internal void ValidateVideoResolution(Size resolution)
156 if (_videoResolutions.Contains(resolution) == false)
158 throw new NotSupportedException($"Resolution({resolution.ToString()}) is not supported.");