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 public RecorderAudioCodec AudioCodec
36 Debug.Assert(Enum.IsDefined(typeof(RecorderAudioCodec), value));
38 if (this is AudioRecorder || value != RecorderAudioCodec.None)
40 ValidateAudioCodec(value);
43 Native.SetAudioEncoder(Handle, value).ThrowIfError("Failed to set audio encoder.");
49 private RecorderFileFormat _fileFormat;
52 /// Gets the file format of the recording result.
54 /// <seealso cref="GetSupportedFileFormats"/>
55 public RecorderFileFormat FileFormat
60 Debug.Assert(Enum.IsDefined(typeof(RecorderFileFormat), value));
62 ValidateFileFormat(value);
64 Native.SetFileFormat(Handle, value).ThrowIfError("Failed to set file format.");
71 /// Gets or sets the number of audio channel.
74 /// To set, the recorder must be in the <see cref="RecorderState.Idle"/> or <see cref="RecorderState.Ready"/> state.
77 /// For mono recording, set channel to 1.
78 /// For stereo recording, set channel to 2.
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
87 Native.GetAudioChannel(Handle, out var val).ThrowIfError("Failed to get audio channel.");
94 ValidateState(RecorderState.Idle, RecorderState.Ready);
98 throw new ArgumentOutOfRangeException(nameof(value), value,
99 "Audio channels can't be less than or equal to zero.");
102 Native.SetAudioChannel(Handle, value).ThrowIfError("Failed to set audio channel");
107 /// Gets or sets the audio device for recording.
110 /// To set, the recorder must be in the <see cref="RecorderState.Idle"/> or <see cref="RecorderState.Ready"/> state.
112 /// <value>A <see cref="RecorderAudioDevice"/> that specifies the type of 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
120 Native.GetAudioDevice(Handle, out var val).ThrowIfError("Failed to get the audio device.");
127 ValidateState(RecorderState.Idle, RecorderState.Ready);
129 ValidationUtil.ValidateEnum(typeof(RecorderAudioDevice), value, nameof(value));
131 Native.SetAudioDevice(Handle, value).ThrowIfError("Failed to set the audio device.");
136 /// Gets or sets the sampling rate of an audio stream in hertz.
139 /// To set, the recorder must be in the <see cref="RecorderState.Idle"/> or <see cref="RecorderState.Ready"/> state.
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
148 Native.GetAudioSampleRate(Handle, out var val).
149 ThrowIfError("Failed to get audio sample rate.");
156 ValidateState(RecorderState.Idle, RecorderState.Ready);
160 throw new ArgumentOutOfRangeException(nameof(value), value,
161 "Sample rate can't be less than or equal to zero.");
164 Native.SetAudioSampleRate(Handle, value).
165 ThrowIfError("Failed to set audio sample rate.");
170 /// Gets or sets the bitrate of an audio encoder in bits per second.
173 /// To set, the recorder must be in the <see cref="RecorderState.Idle"/> or <see cref="RecorderState.Ready"/> state.
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
182 Native.GetAudioEncoderBitrate(Handle, out var val).ThrowIfError("Failed to get audio bitrate.");
189 ValidateState(RecorderState.Idle, RecorderState.Ready);
193 throw new ArgumentOutOfRangeException(nameof(value), value,
194 "Bit rate can't be less than or equal to zero.");
197 Native.SetAudioEncoderBitrate(Handle, value).
198 ThrowIfError("Failed to set audio bitrate");
203 /// Gets or sets the maximum size of a recording file.
206 /// The maximum size of a recording file in kilobytes, or 0 for unlimited size.
209 /// After reaching the limitation, the data which is being recorded will
210 /// be discarded and not written to the file.\n
212 /// To set, the recorder must be in the<see cref="RecorderState.Idle"/> or <see cref= "RecorderState.Ready" /> state.
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>
223 Native.GetSizeLimit(Handle, out val).
224 ThrowIfError("Failed to get size limit.");
231 ValidateState(RecorderState.Idle, RecorderState.Ready);
235 throw new ArgumentOutOfRangeException(nameof(value), value,
236 "Size limit can't be less than zero.");
239 Native.SetSizeLimit(Handle, value).ThrowIfError("Failed to set size limit");
244 /// Gets or sets the time limit of recording.
247 /// The time of recording in seconds, or 0 for unlimited time.
250 /// After reaching the limitation, the data which is being recorded will
251 /// be discarded and not written to the file.\n
253 /// To set, the recorder must be in the<see cref="RecorderState.Idle"/> or <see cref= "RecorderState.Ready" /> state.
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>
262 Native.GetTimeLimit(Handle, out var val).
263 ThrowIfError("Failed to get time limit.");
270 ValidateState(RecorderState.Idle, RecorderState.Ready);
274 throw new ArgumentOutOfRangeException(nameof(value), value,
275 "Time limit can't be less than zero.");
278 Native.SetTimeLimit(Handle, value).ThrowIfError("Failed to set time limit.");
283 /// Gets or sets the mute state of a recorder.
285 /// <exception cref="ObjectDisposedException">The recorder already has been disposed of.</exception>
288 get => Native.GetMute(Handle);
290 set => Native.SetMute(Handle, value).ThrowIfError("Failed to set mute");