Merge "[NUI] suuport NUIWatchApplication for watchface app"
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Recorder / Recorder / RecorderExtensions.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18 using System.Collections.Generic;
19 using System.Linq;
20
21 namespace Tizen.Multimedia
22 {
23     /// <summary>
24     /// Provides extension methods for <see cref="Recorder"/>.
25     /// </summary>
26     /// <since_tizen> 4 </since_tizen>
27     public static class RecorderExtensions
28     {
29         /// <summary>
30         /// Returns supported file formats for a <see cref="RecorderVideoCodec"/>.
31         /// </summary>
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)
37         {
38             ValidationUtil.ValidateEnum(typeof(RecorderVideoCodec), videoCodec, nameof(videoCodec));
39
40             switch (videoCodec)
41             {
42                 case RecorderVideoCodec.H263:
43                     yield return RecorderFileFormat.ThreeGp;
44                     break;
45
46                 case RecorderVideoCodec.H264:
47                 case RecorderVideoCodec.Mpeg4:
48                     yield return RecorderFileFormat.ThreeGp;
49                     yield return RecorderFileFormat.Mp4;
50                     yield return RecorderFileFormat.M2ts;
51                     break;
52
53                 case RecorderVideoCodec.Theora:
54                     yield return RecorderFileFormat.Ogg;
55                     break;
56             }
57         }
58
59         /// <summary>
60         /// Returns supported file formats for a <see cref="RecorderAudioCodec"/>.
61         /// </summary>
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)
67         {
68             ValidationUtil.ValidateEnum(typeof(RecorderAudioCodec), audioCodec, nameof(audioCodec));
69
70             switch (audioCodec)
71             {
72                 case RecorderAudioCodec.Amr:
73                     yield return RecorderFileFormat.ThreeGp;
74                     yield return RecorderFileFormat.Amr;
75                     break;
76
77                 case RecorderAudioCodec.Mp3:
78                     yield return RecorderFileFormat.Mp4;
79                     yield return RecorderFileFormat.M2ts;
80                     break;
81
82                 case RecorderAudioCodec.Aac:
83                     yield return RecorderFileFormat.ThreeGp;
84                     yield return RecorderFileFormat.Mp4;
85                     yield return RecorderFileFormat.M2ts;
86                     yield return RecorderFileFormat.Adts;
87                     break;
88
89                 case RecorderAudioCodec.Vorbis:
90                     yield return RecorderFileFormat.Ogg;
91                     break;
92
93                 case RecorderAudioCodec.Pcm:
94                     yield return RecorderFileFormat.Wav;
95                     break;
96             }
97         }
98
99         internal static void ThrowIfFormatNotSupported(this RecorderAudioCodec audioCodec, RecorderFileFormat fileFormat)
100         {
101             ValidationUtil.ValidateEnum(typeof(RecorderFileFormat), fileFormat, nameof(fileFormat));
102
103             if (audioCodec.GetSupportedFileFormats().Contains(fileFormat) == false)
104             {
105                 throw new NotSupportedException($"{audioCodec} does not support {fileFormat}.");
106             }
107         }
108
109         internal static void ThrowIfFormatNotSupported(this RecorderVideoCodec videoCodec, RecorderFileFormat fileFormat)
110         {
111             ValidationUtil.ValidateEnum(typeof(RecorderFileFormat), fileFormat, nameof(fileFormat));
112
113             if (videoCodec.GetSupportedFileFormats().Contains(fileFormat) == false)
114             {
115                 throw new NotSupportedException($"{videoCodec} does not support {fileFormat}.");
116             }
117         }
118     }
119 }