Release 4.0.0-preview1-00321
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Recorder / Recorder / Recorder.Settings.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.Diagnostics;
19 using Native = Interop.Recorder;
20
21 namespace Tizen.Multimedia
22 {
23     public partial class Recorder
24     {
25         private RecorderAudioCodec _audioCodec;
26
27         /// <summary>
28         /// Gets the audio codec for encoding an audio stream.
29         /// </summary>
30         /// <seealso cref="GetSupportedAudioCodecs"/>
31         public RecorderAudioCodec AudioCodec
32         {
33             get => _audioCodec;
34             internal set
35             {
36                 Debug.Assert(Enum.IsDefined(typeof(RecorderAudioCodec), value));
37
38                 if (this is AudioRecorder || value != RecorderAudioCodec.None)
39                 {
40                     ValidateAudioCodec(value);
41                 }
42
43                 Native.SetAudioEncoder(Handle, value).ThrowIfError("Failed to set audio encoder.");
44
45                 _audioCodec = value;
46             }
47         }
48
49         private RecorderFileFormat _fileFormat;
50
51         /// <summary>
52         /// Gets the file format of the recording result.
53         /// </summary>
54         /// <seealso cref="GetSupportedFileFormats"/>
55         public RecorderFileFormat FileFormat
56         {
57             get => _fileFormat;
58             internal set
59             {
60                 Debug.Assert(Enum.IsDefined(typeof(RecorderFileFormat), value));
61
62                 ValidateFileFormat(value);
63
64                 Native.SetFileFormat(Handle, value).ThrowIfError("Failed to set file format.");
65
66                 _fileFormat = value;
67             }
68         }
69
70         /// <summary>
71         /// Gets or sets the number of the audio channel.
72         /// </summary>
73         /// <remarks>
74         /// To set, the recorder must be in the <see cref="RecorderState.Idle"/> or the <see cref="RecorderState.Ready"/> state.
75         /// </remarks>
76         /// <value>
77         /// For mono recording, set the channel to 1.
78         /// For stereo recording, set the channel to 2.
79         /// </value>
80         /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than or equal to zero.</exception>
81         /// <exception cref="InvalidOperationException">The recorder is not in the valid state.</exception>
82         /// <exception cref="ObjectDisposedException">The recorder already has been disposed of.</exception>
83         public int AudioChannels
84         {
85             get
86             {
87                 Native.GetAudioChannel(Handle, out var val).ThrowIfError("Failed to get audio channel.");
88
89                 return val;
90             }
91
92             set
93             {
94                 ValidateState(RecorderState.Idle, RecorderState.Ready);
95
96                 if (value <= 0)
97                 {
98                     throw new ArgumentOutOfRangeException(nameof(value), value,
99                         "Audio channels can't be less than or equal to zero.");
100                 }
101
102                 Native.SetAudioChannel(Handle, value).ThrowIfError("Failed to set audio channel");
103             }
104         }
105
106         /// <summary>
107         /// Gets or sets the audio device for recording.
108         /// </summary>
109         /// <remarks>
110         /// To set, the recorder must be in the <see cref="RecorderState.Idle"/> or the <see cref="RecorderState.Ready"/> state.
111         /// </remarks>
112         /// <value>A <see cref="RecorderAudioDevice"/> that specifies the type of the audio device.</value>
113         /// <exception cref="ArgumentException"><paramref name="value"/> is not valid.</exception>
114         /// <exception cref="InvalidOperationException">The recorder is not in the valid state.</exception>
115         /// <exception cref="ObjectDisposedException">The recorder already has been disposed of.</exception>
116         public RecorderAudioDevice AudioDevice
117         {
118             get
119             {
120                 Native.GetAudioDevice(Handle, out var val).ThrowIfError("Failed to get the audio device.");
121
122                 return val;
123             }
124
125             set
126             {
127                 ValidateState(RecorderState.Idle, RecorderState.Ready);
128
129                 ValidationUtil.ValidateEnum(typeof(RecorderAudioDevice), value, nameof(value));
130
131                 Native.SetAudioDevice(Handle, value).ThrowIfError("Failed to set the audio device.");
132             }
133         }
134
135         /// <summary>
136         /// Gets or sets the sampling rate of an audio stream in hertz.
137         /// </summary>
138         /// <remarks>
139         /// To set, the recorder must be in the <see cref="RecorderState.Idle"/> or the <see cref="RecorderState.Ready"/> state.
140         /// </remarks>
141         /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than or equal to zero.</exception>
142         /// <exception cref="InvalidOperationException">The recorder is not in the valid state.</exception>
143         /// <exception cref="ObjectDisposedException">The recorder already has been disposed of.</exception>
144         public int AudioSampleRate
145         {
146             get
147             {
148                 Native.GetAudioSampleRate(Handle, out var val).
149                     ThrowIfError("Failed to get audio sample rate.");
150
151                 return val;
152             }
153
154             set
155             {
156                 ValidateState(RecorderState.Idle, RecorderState.Ready);
157
158                 if (value <= 0)
159                 {
160                     throw new ArgumentOutOfRangeException(nameof(value), value,
161                         "Sample rate can't be less than or equal to zero.");
162                 }
163
164                 Native.SetAudioSampleRate(Handle, value).
165                     ThrowIfError("Failed to set audio sample rate.");
166             }
167         }
168
169         /// <summary>
170         /// Gets or sets the bitrate of an audio encoder in bits per second.
171         /// </summary>
172         /// <remarks>
173         /// To set, the recorder must be in the <see cref="RecorderState.Idle"/> or the <see cref="RecorderState.Ready"/> state.
174         /// </remarks>
175         /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than or equal to zero.</exception>
176         /// <exception cref="InvalidOperationException">The recorder is not in the valid state.</exception>
177         /// <exception cref="ObjectDisposedException">The recorder already has been disposed of.</exception>
178         public int AudioBitRate
179         {
180             get
181             {
182                 Native.GetAudioEncoderBitrate(Handle, out var val).ThrowIfError("Failed to get audio bitrate.");
183
184                 return val;
185             }
186
187             set
188             {
189                 ValidateState(RecorderState.Idle, RecorderState.Ready);
190
191                 if (value <= 0)
192                 {
193                     throw new ArgumentOutOfRangeException(nameof(value), value,
194                         "Bit rate can't be less than or equal to zero.");
195                 }
196
197                 Native.SetAudioEncoderBitrate(Handle, value).
198                     ThrowIfError("Failed to set audio bitrate");
199             }
200         }
201
202         /// <summary>
203         /// Gets or sets the maximum size of a recording file.
204         /// </summary>
205         /// <value>
206         /// The maximum size of a recording file in kilobytes, or 0 for unlimited size.
207         /// </value>
208         /// <remarks>
209         /// After reaching the limitation, the data which is being recorded will
210         /// be discarded and will not be written to the file.<br/>
211         /// <br/>
212         /// To set, the recorder must be in the <see cref="RecorderState.Idle"/> or the <see cref= "RecorderState.Ready" /> state.
213         /// </remarks>
214         /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than zero.</exception>
215         /// <exception cref="InvalidOperationException">The recorder is not in the valid state.</exception>
216         /// <exception cref="ObjectDisposedException">The recorder already has been disposed of.</exception>
217         public int SizeLimit
218         {
219             get
220             {
221                 int val = 0;
222
223                 Native.GetSizeLimit(Handle, out val).
224                     ThrowIfError("Failed to get size limit.");
225
226                 return val;
227             }
228
229             set
230             {
231                 ValidateState(RecorderState.Idle, RecorderState.Ready);
232
233                 if (value < 0)
234                 {
235                     throw new ArgumentOutOfRangeException(nameof(value), value,
236                         "Size limit can't be less than zero.");
237                 }
238
239                 Native.SetSizeLimit(Handle, value).ThrowIfError("Failed to set size limit");
240             }
241         }
242
243         /// <summary>
244         /// Gets or sets the time limit of recording.
245         /// </summary>
246         /// <value>
247         /// The time of recording in seconds, or 0 for unlimited time.
248         /// </value>
249         /// <remarks>
250         /// After reaching the limitation, the data which is being recorded will
251         /// be discarded and will not be written to the file.<br/>
252         /// <br/>
253         /// To set, the recorder must be in the <see cref="RecorderState.Idle"/> or the <see cref= "RecorderState.Ready" /> state.
254         /// </remarks>
255         /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than zero.</exception>
256         /// <exception cref="InvalidOperationException">The recorder is not in the valid state.</exception>
257         /// <exception cref="ObjectDisposedException">The recorder already has been disposed of.</exception>
258         public int TimeLimit
259         {
260             get
261             {
262                 Native.GetTimeLimit(Handle, out var val).
263                     ThrowIfError("Failed to get time limit.");
264
265                 return val;
266             }
267
268             set
269             {
270                 ValidateState(RecorderState.Idle, RecorderState.Ready);
271
272                 if (value < 0)
273                 {
274                     throw new ArgumentOutOfRangeException(nameof(value), value,
275                         "Time limit can't be less than zero.");
276                 }
277
278                 Native.SetTimeLimit(Handle, value).ThrowIfError("Failed to set time limit.");
279             }
280         }
281
282         /// <summary>
283         /// Gets or sets the mute state of a recorder.
284         /// </summary>
285         /// <exception cref="ObjectDisposedException">The recorder already has been disposed of.</exception>
286         public bool Muted
287         {
288             get => Native.GetMute(Handle);
289
290             set => Native.SetMute(Handle, value).ThrowIfError("Failed to set mute");
291         }
292     }
293 }