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;
19 using System.Diagnostics;
21 using Native = Interop.Recorder;
22 using NativeHandle = Interop.RecorderHandle;
24 namespace Tizen.Multimedia
26 /// <since_tizen> 4 </since_tizen>
27 public partial class VideoRecorder
29 private static IEnumerable<Size> _frontResolutions;
30 private static IEnumerable<Size> _rearResolutions;
32 private static IEnumerable<Size> GetVideoResolutions(NativeHandle handle)
34 var result = new List<Size>();
36 var ret = Native.GetVideoResolutions(handle, (w, h, _) => { result.Add(new Size(w, h)); return true; });
38 if (ret == RecorderErrorCode.NotSupported)
40 throw new NotSupportedException("Video recording is not supported.");
43 ret.ThrowIfError("Failed to load the resolutions");
45 return result.AsReadOnly();
48 private static IEnumerable<Size> LoadVideoResolutions(CameraDevice device)
50 if (!Features.IsSupported(RecorderFeatures.VideoRecorder))
52 throw new NotSupportedException("Video Recorder is not supported.");
55 using (var camera = new Camera(device))
57 Native.CreateVideo(camera.Handle, out var handle).ThrowIfError("Failed to get the resolutions");
61 return GetVideoResolutions(handle);
67 /// Gets the video resolutions that the current device supports.
69 /// <feature>http://tizen.org/feature/media.video_recording</feature>
70 /// <param name="device">The camera device to retrieve the supported resolutions.</param>
71 /// <exception cref="NotSupportedException">A required feature is not supported.</exception>
72 /// <exception cref="ArgumentException"><paramref name="device"/> is invalid.</exception>
73 /// <since_tizen> 4 </since_tizen>
74 public static IEnumerable<Size> GetSupportedVideoResolutions(CameraDevice device)
76 ValidationUtil.ValidateEnum(typeof(CameraDevice), device, nameof(device));
78 if (device == CameraDevice.Front)
80 return _frontResolutions ?? (_frontResolutions = LoadVideoResolutions(CameraDevice.Front));
83 if (device == CameraDevice.Rear)
85 return _rearResolutions ?? (_rearResolutions = LoadVideoResolutions(CameraDevice.Rear));
88 Debug.Fail($"No cache for {device}.");
90 return LoadVideoResolutions(device);
94 /// Gets the video encoders that the current device supports.
96 /// <feature>http://tizen.org/feature/media.video_recording</feature>
97 /// <exception cref="NotSupportedException">A required feature is not supported.</exception>
98 /// <since_tizen> 4 </since_tizen>
99 public static IEnumerable<RecorderVideoCodec> GetSupportedVideoCodecs()
100 => Capabilities.Value.SupportedVideoCodecs ?? throw new NotSupportedException("Video recording is not supported.");
102 internal static void ValidateVideoCodec(RecorderVideoCodec codec)
104 if (GetSupportedVideoCodecs().Contains(codec) == false)
106 throw new NotSupportedException($"{codec.ToString()} is not supported.");