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;
21 namespace Tizen.Multimedia
24 /// Provides extension methods for <see cref="Recorder"/>.
26 /// <since_tizen> 4 </since_tizen>
27 public static class RecorderExtensions
30 /// Returns supported file formats for a <see cref="RecorderVideoCodec"/>.
32 /// <returns>An IEnumerable of <see cref="RecorderFileFormat"/> representing the supported file formats.</returns>
33 /// <param name="videoCodec">The <see cref="RecorderVideoCodec"/>.</param>
34 /// <exception cref="ArgumentException"><paramref name="videoCodec"/> is invalid.</exception>
35 /// <since_tizen> 4 </since_tizen>
36 public static IEnumerable<RecorderFileFormat> GetSupportedFileFormats(this RecorderVideoCodec videoCodec)
38 ValidationUtil.ValidateEnum(typeof(RecorderVideoCodec), videoCodec, nameof(videoCodec));
42 case RecorderVideoCodec.H263:
43 yield return RecorderFileFormat.ThreeGp;
46 case RecorderVideoCodec.H264:
47 case RecorderVideoCodec.Mpeg4:
48 yield return RecorderFileFormat.ThreeGp;
49 yield return RecorderFileFormat.Mp4;
50 yield return RecorderFileFormat.M2ts;
53 case RecorderVideoCodec.Theora:
54 yield return RecorderFileFormat.Ogg;
60 /// Returns supported file formats for a <see cref="RecorderAudioCodec"/>.
62 /// <returns>An IEnumerable of <see cref="RecorderFileFormat"/> representing the supported file formats.</returns>
63 /// <param name="audioCodec">The <see cref="RecorderAudioCodec"/>.</param>
64 /// <exception cref="ArgumentException"><paramref name="audioCodec"/> is invalid.</exception>
65 /// <since_tizen> 4 </since_tizen>
66 public static IEnumerable<RecorderFileFormat> GetSupportedFileFormats(this RecorderAudioCodec audioCodec)
68 ValidationUtil.ValidateEnum(typeof(RecorderAudioCodec), audioCodec, nameof(audioCodec));
72 case RecorderAudioCodec.Amr:
73 yield return RecorderFileFormat.ThreeGp;
74 yield return RecorderFileFormat.Amr;
77 case RecorderAudioCodec.Mp3:
78 yield return RecorderFileFormat.Mp4;
79 yield return RecorderFileFormat.M2ts;
82 case RecorderAudioCodec.Aac:
83 yield return RecorderFileFormat.ThreeGp;
84 yield return RecorderFileFormat.Mp4;
85 yield return RecorderFileFormat.M2ts;
86 yield return RecorderFileFormat.Adts;
89 case RecorderAudioCodec.Vorbis:
90 yield return RecorderFileFormat.Ogg;
93 case RecorderAudioCodec.Pcm:
94 yield return RecorderFileFormat.Wav;
99 internal static void ThrowIfFormatNotSupported(this RecorderAudioCodec audioCodec, RecorderFileFormat fileFormat)
101 ValidationUtil.ValidateEnum(typeof(RecorderFileFormat), fileFormat, nameof(fileFormat));
103 if (audioCodec.GetSupportedFileFormats().Contains(fileFormat) == false)
105 throw new NotSupportedException($"{audioCodec} does not support {fileFormat}.");
109 internal static void ThrowIfFormatNotSupported(this RecorderVideoCodec videoCodec, RecorderFileFormat fileFormat)
111 ValidationUtil.ValidateEnum(typeof(RecorderFileFormat), fileFormat, nameof(fileFormat));
113 if (videoCodec.GetSupportedFileFormats().Contains(fileFormat) == false)
115 throw new NotSupportedException($"{videoCodec} does not support {fileFormat}.");