2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Diagnostics;
19 using Native = Interop.Recorder;
21 namespace Tizen.Multimedia
23 public partial class Recorder
25 private RecorderAudioCodec _audioCodec;
28 /// Gets the audio codec for encoding an audio stream.
30 /// <seealso cref="GetSupportedAudioCodecs"/>
31 /// <since_tizen> 4 </since_tizen>
32 public RecorderAudioCodec AudioCodec
37 Debug.Assert(Enum.IsDefined(typeof(RecorderAudioCodec), value));
39 if (this is AudioRecorder || value != RecorderAudioCodec.None)
41 ValidateAudioCodec(value);
44 Native.SetAudioEncoder(Handle, value).ThrowIfError("Failed to set audio encoder.");
50 private RecorderFileFormat _fileFormat;
53 /// Gets the file format of the recording result.
55 /// <seealso cref="GetSupportedFileFormats"/>
56 /// <since_tizen> 4 </since_tizen>
57 public RecorderFileFormat FileFormat
62 Debug.Assert(Enum.IsDefined(typeof(RecorderFileFormat), value));
64 ValidateFileFormat(value);
66 Native.SetFileFormat(Handle, value).ThrowIfError("Failed to set file format.");
73 /// Gets or sets the number of the audio channel.
76 /// To set, the recorder must be in the <see cref="RecorderState.Idle"/> or the <see cref="RecorderState.Ready"/> state.
79 /// For mono recording, set the channel to 1.
80 /// For stereo recording, set the channel to 2.
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
90 Native.GetAudioChannel(Handle, out var val).ThrowIfError("Failed to get audio channel.");
97 ValidateState(RecorderState.Idle, RecorderState.Ready);
101 throw new ArgumentOutOfRangeException(nameof(value), value,
102 "Audio channels can't be less than or equal to zero.");
105 Native.SetAudioChannel(Handle, value).ThrowIfError("Failed to set audio channel");
110 /// Gets or sets the audio device for recording.
113 /// To set, the recorder must be in the <see cref="RecorderState.Idle"/> or the <see cref="RecorderState.Ready"/> state.
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
124 Native.GetAudioDevice(Handle, out var val).ThrowIfError("Failed to get the audio device.");
131 ValidateState(RecorderState.Idle, RecorderState.Ready);
133 ValidationUtil.ValidateEnum(typeof(RecorderAudioDevice), value, nameof(value));
135 Native.SetAudioDevice(Handle, value).ThrowIfError("Failed to set the audio device.");
140 /// Gets or sets the sampling rate of an audio stream in hertz.
143 /// To set, the recorder must be in the <see cref="RecorderState.Idle"/> or the <see cref="RecorderState.Ready"/> state.
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
153 Native.GetAudioSampleRate(Handle, out var val).
154 ThrowIfError("Failed to get audio sample rate.");
161 ValidateState(RecorderState.Idle, RecorderState.Ready);
165 throw new ArgumentOutOfRangeException(nameof(value), value,
166 "Sample rate can't be less than or equal to zero.");
169 Native.SetAudioSampleRate(Handle, value).
170 ThrowIfError("Failed to set audio sample rate.");
175 /// Gets or sets the bitrate of an audio encoder in bits per second.
178 /// To set, the recorder must be in the <see cref="RecorderState.Idle"/> or the <see cref="RecorderState.Ready"/> state.
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
188 Native.GetAudioEncoderBitrate(Handle, out var val).ThrowIfError("Failed to get audio bitrate.");
195 ValidateState(RecorderState.Idle, RecorderState.Ready);
199 throw new ArgumentOutOfRangeException(nameof(value), value,
200 "Bit rate can't be less than or equal to zero.");
203 Native.SetAudioEncoderBitrate(Handle, value).
204 ThrowIfError("Failed to set audio bitrate");
209 /// Gets or sets the maximum size of a recording file.
212 /// The maximum size of a recording file in kilobytes, or 0 for unlimited size.
215 /// After reaching the limitation, the data which is being recorded will
216 /// be discarded and will not be written to the file.<br/>
218 /// To set, the recorder must be in the <see cref="RecorderState.Idle"/> or the <see cref= "RecorderState.Ready" /> state.
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>
230 Native.GetSizeLimit(Handle, out val).
231 ThrowIfError("Failed to get size limit.");
238 ValidateState(RecorderState.Idle, RecorderState.Ready);
242 throw new ArgumentOutOfRangeException(nameof(value), value,
243 "Size limit can't be less than zero.");
246 Native.SetSizeLimit(Handle, value).ThrowIfError("Failed to set size limit");
251 /// Gets or sets the time limit of recording.
254 /// The time of recording in seconds, or 0 for unlimited time.
257 /// After reaching the limitation, the data which is being recorded will
258 /// be discarded and will not be written to the file.<br/>
260 /// To set, the recorder must be in the <see cref="RecorderState.Idle"/> or the <see cref= "RecorderState.Ready" /> state.
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>
270 Native.GetTimeLimit(Handle, out var val).
271 ThrowIfError("Failed to get time limit.");
278 ValidateState(RecorderState.Idle, RecorderState.Ready);
282 throw new ArgumentOutOfRangeException(nameof(value), value,
283 "Time limit can't be less than zero.");
286 Native.SetTimeLimit(Handle, value).ThrowIfError("Failed to set time limit.");
291 /// Gets or sets the mute state of a recorder.
293 /// <exception cref="ObjectDisposedException">The recorder already has been disposed of.</exception>
294 /// <since_tizen> 4 </since_tizen>
297 get => Native.GetMute(Handle);
299 set => Native.SetMute(Handle, value).ThrowIfError("Failed to set mute");