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 Native = Interop.StreamRecorder;
20 namespace Tizen.Multimedia
23 /// Specifies the options associated with audio recording.
25 /// <seealso cref="StreamRecorder"/>
26 /// <seealso cref="StreamRecorderOptions"/>
27 /// <seealso cref="StreamRecorderVideoOptions"/>
28 /// <since_tizen> 4 </since_tizen>
29 public class StreamRecorderAudioOptions
31 private const int DefaultSampleRate = 0;
32 private const int DefaultBitRate = 128000;
33 private const int DefaultChannels = 2;
36 /// Initialize a new instance of the <see cref="StreamRecorderAudioOptions"/> class with the specified codec.
38 /// <param name="codec">The <see cref="RecorderAudioCodec"/> for encoding audio stream.</param>
40 /// <see cref="SampleRate"/>, <see cref="BitRate"/> and <see cref="Channels"/> will be set as default.
42 /// <exception cref="ArgumentException"><paramref name="codec"/> is not valid.</exception>
43 /// <since_tizen> 4 </since_tizen>
44 public StreamRecorderAudioOptions(RecorderAudioCodec codec) :
45 this(codec, DefaultSampleRate, DefaultBitRate, DefaultChannels)
50 /// Initialize a new instance of the <see cref="StreamRecorderAudioOptions"/> class with the specified
51 /// codec, sample rate, bit rate, and channel value.
53 /// <param name="codec">The <see cref="RecorderAudioCodec"/> for encoding audio stream.</param>
54 /// <param name="sampleRate">The sample rate for encoding audio stream.</param>
55 /// <param name="bitRate">The bit rate for encoding audio stream.</param>
56 /// <param name="channels">The number of channels for encoding audio stream.</param>
57 /// <exception cref="ArgumentException"><paramref name="codec"/> is not valid.</exception>
58 /// <exception cref="ArgumentOutOfRangeException">
59 /// <paramref name="sampleRate"/> is less than zero.<br/>
61 /// <paramref name="bitRate"/> is less than or equal to zero.<br/>
63 /// <paramref name="channels"/> is less than or equal to zero.
65 /// <since_tizen> 4 </since_tizen>
66 public StreamRecorderAudioOptions(RecorderAudioCodec codec, int sampleRate, int bitRate, int channels)
69 SampleRate = sampleRate;
74 private RecorderAudioCodec _codec;
77 /// Gets or sets the audio codec for encoding an audio stream.
79 /// <value>The codec for audio stream recording.</value>
80 /// <exception cref="ArgumentException"><paramref name="value"/> is not valid.</exception>
81 /// <seealso cref="StreamRecorder.GetSupportedAudioCodecs"/>
82 /// <since_tizen> 4 </since_tizen>
83 public RecorderAudioCodec Codec
88 ValidationUtil.ValidateEnum(typeof(RecorderAudioCodec), value, nameof(value));
90 if (value == RecorderAudioCodec.None)
92 throw new ArgumentException("Audio codec can't be None.");
99 private int _sampleRate;
102 /// Gets or sets the sampling rate of the audio stream in hertz.
104 /// <remarks>If the value is zero, the sample rate will be decided based on input buffers.</remarks>
105 /// <value>The sample rate value for stream recorder. The default is zero.</value>
106 /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than zero.</exception>
107 /// <since_tizen> 4 </since_tizen>
108 public int SampleRate
115 throw new ArgumentOutOfRangeException(nameof(value), value,
116 "Sample rate can't be less than or equal to zero.");
123 private int _bitRate;
126 /// Gets or sets the bit rate of the audio encoder in bits per second.
128 /// <value>The bit rate value for audio stream recording. The default is 128000.</value>
129 /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than or equal to zero.</exception>
130 /// <since_tizen> 4 </since_tizen>
138 throw new ArgumentOutOfRangeException(nameof(value), value,
139 "Bit rate can't be less than or equal to zero.");
146 private int _channels;
149 /// Gets or sets the number of audio channels.
151 /// <value>The number of audio channels for audio stream recording. The default is 2.</value>
152 /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than or equal to zero.</exception>
153 /// <since_tizen> 4 </since_tizen>
161 throw new ArgumentOutOfRangeException(nameof(value), value,
162 "Channels can't be less than or equal to zero.");
169 internal void Apply(StreamRecorder recorder)
171 recorder.ValidateAudioCodec(Codec);
173 Native.SetAudioEncoder(recorder.Handle, Codec.ToStreamRecorderEnum()).
174 ThrowIfError("Failed to set audio codec.");
176 Native.SetAudioSampleRate(recorder.Handle, SampleRate).
177 ThrowIfError("Failed to set audio sample rate.");
179 Native.SetAudioEncoderBitrate(recorder.Handle, BitRate).
180 ThrowIfError("Failed to set audio bit rate.");
182 Native.SetAudioChannel(recorder.Handle, Channels).
183 ThrowIfError("Failed to set audio channels.");