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