Release 4.0.0-preview1-00321
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Recorder / Recorder / AudioRecorder.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 Native = Interop.Recorder;
19 using NativeHandle = Interop.RecorderHandle;
20
21 namespace Tizen.Multimedia
22 {
23     /// <summary>
24     /// Provides the ability to control audio recording.
25     /// </summary>
26     public class AudioRecorder : Recorder
27     {
28         private static NativeHandle CreateHandle()
29         {
30             Native.Create(out var handle).ThrowIfError("Failed to create Audio recorder");
31
32             return handle;
33         }
34
35         private static void ThrowIfCodecAndFormatNotValid(RecorderAudioCodec audioCodec, RecorderFileFormat fileFormat)
36         {
37             if (audioCodec == RecorderAudioCodec.None)
38             {
39                 throw new ArgumentOutOfRangeException(nameof(audioCodec),
40                     "RecorderAudioCodec.None is only available with VideoRecorder.");
41             }
42
43             audioCodec.ThrowIfFormatNotSupported(fileFormat);
44         }
45
46         /// <summary>
47         /// Initializes a new instance of the <see cref="AudioRecorder"/> class with the specified audio codec and file format.
48         /// </summary>
49         /// <param name="audioCodec">The codec for audio encoding.</param>
50         /// <param name="fileFormat">The format of result file.</param>
51         /// <feature>http://tizen.org/feature/microphone</feature>
52         /// <exception cref="InvalidOperationException">An internal error occurred.</exception>
53         /// <exception cref="NotSupportedException">
54         ///     A required feature is not supported.<br/>
55         ///     -or-<br/>
56         ///     <paramref name="audioCodec"/> is not supported.<br/>
57         ///     -or-<br/>
58         ///     <paramref name="fileFormat"/> is not supported with the specified audio codec.
59         /// </exception>
60         /// <exception cref="ArgumentException">
61         ///     <paramref name="audioCodec"/> is not valid.<br/>
62         ///     -or-<br/>
63         ///     <paramref name="fileFormat"/> is not valid.
64         /// </exception>
65         /// <exception cref="ArgumentOutOfRangeException">
66         ///     <paramref name="audioCodec"/> is <see cref="RecorderAudioCodec.None"/>
67         /// </exception>
68         /// <seealso cref="Recorder.GetSupportedAudioCodecs"/>
69         /// <seealso cref="Recorder.GetSupportedFileFormats"/>
70         /// <seealso cref="RecorderExtensions.GetSupportedFileFormats(RecorderAudioCodec)"/>
71         /// <seealso cref="SetFormatAndCodec(RecorderAudioCodec, RecorderFileFormat)"/>
72         public AudioRecorder(RecorderAudioCodec audioCodec, RecorderFileFormat fileFormat) : base(CreateHandle())
73         {
74             SetFormatAndCodec(audioCodec, fileFormat);
75         }
76
77         /// <summary>
78         /// Sets the audio codec and the file format for recording.
79         /// </summary>
80         /// <param name="audioCodec">The codec for audio encoding.</param>
81         /// <param name="fileFormat">The format of result file.</param>
82         /// <exception cref="NotSupportedException">
83         ///     <paramref name="audioCodec"/> is not supported.<br/>
84         ///     -or-<br/>
85         ///     <paramref name="fileFormat"/> is not supported with the specified audio codec.
86         /// </exception>
87         /// <exception cref="ArgumentException">
88         ///     <paramref name="audioCodec"/> is not valid.<br/>
89         ///     -or-<br/>
90         ///     <paramref name="fileFormat"/> is not valid.
91         /// </exception>
92         /// <exception cref="ArgumentOutOfRangeException">
93         ///     <paramref name="audioCodec"/> is <see cref="RecorderAudioCodec.None"/>
94         /// </exception>
95         /// <seealso cref="Recorder.GetSupportedAudioCodecs"/>
96         /// <seealso cref="Recorder.GetSupportedFileFormats"/>
97         /// <seealso cref="RecorderExtensions.GetSupportedFileFormats(RecorderAudioCodec)"/>
98         /// <seealso cref="Recorder.Start(string)"/>
99         public void SetFormatAndCodec(RecorderAudioCodec audioCodec, RecorderFileFormat fileFormat)
100         {
101             ThrowIfCodecAndFormatNotValid(audioCodec, fileFormat);
102
103             AudioCodec = audioCodec;
104             FileFormat = fileFormat;
105         }
106     }
107 }