[Multimedia] Fix VD SVACE issues (#5445)
[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                 default:
58                     break;
59             }
60         }
61
62         /// <summary>
63         /// Returns supported file formats for a <see cref="RecorderAudioCodec"/>.
64         /// </summary>
65         /// <returns>An IEnumerable of <see cref="RecorderFileFormat"/> representing the supported file formats.</returns>
66         /// <param name="audioCodec">The <see cref="RecorderAudioCodec"/>.</param>
67         /// <exception cref="ArgumentException"><paramref name="audioCodec"/> is invalid.</exception>
68         /// <since_tizen> 4 </since_tizen>
69         public static IEnumerable<RecorderFileFormat> GetSupportedFileFormats(this RecorderAudioCodec audioCodec)
70         {
71             ValidationUtil.ValidateEnum(typeof(RecorderAudioCodec), audioCodec, nameof(audioCodec));
72
73             switch (audioCodec)
74             {
75                 case RecorderAudioCodec.Amr:
76                     yield return RecorderFileFormat.ThreeGp;
77                     yield return RecorderFileFormat.Amr;
78                     break;
79
80                 case RecorderAudioCodec.Mp3:
81                     yield return RecorderFileFormat.Mp4;
82                     yield return RecorderFileFormat.M2ts;
83                     break;
84
85                 case RecorderAudioCodec.Aac:
86                     yield return RecorderFileFormat.ThreeGp;
87                     yield return RecorderFileFormat.Mp4;
88                     yield return RecorderFileFormat.M2ts;
89                     yield return RecorderFileFormat.Adts;
90                     break;
91
92                 case RecorderAudioCodec.Vorbis:
93                     yield return RecorderFileFormat.Ogg;
94                     break;
95
96                 case RecorderAudioCodec.Pcm:
97                     yield return RecorderFileFormat.Wav;
98                     break;
99
100                 default:
101                     break;
102             }
103         }
104
105         internal static void ThrowIfFormatNotSupported(this RecorderAudioCodec audioCodec, RecorderFileFormat fileFormat)
106         {
107             ValidationUtil.ValidateEnum(typeof(RecorderFileFormat), fileFormat, nameof(fileFormat));
108
109             if (audioCodec.GetSupportedFileFormats().Contains(fileFormat) == false)
110             {
111                 throw new NotSupportedException($"{audioCodec} does not support {fileFormat}.");
112             }
113         }
114
115         internal static void ThrowIfFormatNotSupported(this RecorderVideoCodec videoCodec, RecorderFileFormat fileFormat)
116         {
117             ValidationUtil.ValidateEnum(typeof(RecorderFileFormat), fileFormat, nameof(fileFormat));
118
119             if (videoCodec.GetSupportedFileFormats().Contains(fileFormat) == false)
120             {
121                 throw new NotSupportedException($"{videoCodec} does not support {fileFormat}.");
122             }
123         }
124     }
125 }