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 public partial class VideoRecorder
28 private static IEnumerable<Size> _frontResolutions;
29 private static IEnumerable<Size> _rearResolutions;
31 private static IEnumerable<Size> GetVideoResolutions(NativeHandle handle)
33 var result = new List<Size>();
35 var ret = Native.GetVideoResolutions(handle, (w, h, _) => { result.Add(new Size(w, h)); return true; });
37 if (ret == RecorderErrorCode.NotSupported)
39 throw new NotSupportedException("Video recording is not supported.");
42 ret.ThrowIfError("Failed to load the resolutions");
44 return result.AsReadOnly();
47 private static IEnumerable<Size> LoadVideoResolutions(CameraDevice device)
49 using (var camera = new Camera(device))
51 Native.CreateVideo(camera.Handle, out var handle).ThrowIfError("Failed to get the resolutions");
55 return GetVideoResolutions(handle);
61 /// Gets the video resolutions that the current device supports.
63 /// <feature>http://tizen.org/feature/camera</feature>
64 /// <param name="device">The camera device to retrieve the supported resolutions.</param>
65 /// <exception cref="NotSupportedException">A required feature is not supported.</exception>
66 /// <exception cref="ArgumentException"><paramref name="device"/> is invalid.</exception>
67 public static IEnumerable<Size> GetSupportedVideoResolutions(CameraDevice device)
69 ValidationUtil.ValidateEnum(typeof(CameraDevice), device, nameof(device));
71 if (device == CameraDevice.Front)
73 return _frontResolutions ?? (_frontResolutions = LoadVideoResolutions(CameraDevice.Front));
76 if (device == CameraDevice.Rear)
78 return _rearResolutions ?? (_rearResolutions = LoadVideoResolutions(CameraDevice.Rear));
81 Debug.Fail($"No cache for {device}.");
83 return LoadVideoResolutions(device);
87 /// Gets the video encoders that the current device supports.
89 /// <feature>http://tizen.org/feature/camera</feature>
90 /// <exception cref="NotSupportedException">A required feature is not supported.</exception>
91 public static IEnumerable<RecorderVideoCodec> GetSupportedVideoCodecs()
92 => Capabilities.Value.SupportedVideoCodecs ?? throw new NotSupportedException("Video recording is not supported.");
94 internal static void ValidateVideoCodec(RecorderVideoCodec codec)
96 if (GetSupportedVideoCodecs().Contains(codec) == false)
98 throw new NotSupportedException($"{codec.ToString()} is not supported.");