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 public IEnumerable<RecorderFileFormat> GetSupportedFileFormats() => _fileFormats;
98 private IEnumerable<RecorderAudioCodec> _audioCodecs;
101 /// Gets the audio codecs that the current device supports.
103 /// <returns>An IEnumerable of <see cref="RecorderAudioCodec"/> representing the supported audio codecs.</returns>
104 public IEnumerable<RecorderAudioCodec> GetSupportedAudioCodecs() => _audioCodecs;
106 private IEnumerable<RecorderVideoCodec> _videoCodecs;
109 /// Gets the video codecs that the current device supports.
111 /// <returns>An IEnumerable of <see cref="RecorderVideoCodec"/> representing the supported video codecs.</returns>
112 public IEnumerable<RecorderVideoCodec> GetSupportedVideoCodecs() => _videoCodecs;
114 private IEnumerable<Size> _videoResolutions;
117 /// Gets the video resolutions that the current device supports.
119 /// <returns>An IEnumerable of <see cref="Size"/> representing the supported resolutions.</returns>
120 public IEnumerable<Size> GetSupportedVideoResolutions() => _videoResolutions;
122 internal void ValidateFileFormat(RecorderFileFormat format)
124 if (_fileFormats.Contains(format) == false)
126 throw new NotSupportedException($"{format.ToString()} is not supported.");
130 internal void ValidateAudioCodec(RecorderAudioCodec codec)
132 if (_audioCodecs.Contains(codec) == false)
134 throw new NotSupportedException($"{codec.ToString()} is not supported.");
138 internal void ValidateVideoCodec(RecorderVideoCodec codec)
140 if (_videoCodecs.Contains(codec) == false)
142 throw new NotSupportedException($"{codec.ToString()} is not supported.");
146 internal void ValidateVideoResolution(Size resolution)
148 if (_videoResolutions.Contains(resolution) == false)
150 throw new NotSupportedException($"Resolution({resolution.ToString()}) is not supported.");