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 public class StreamRecorderAudioOptions
30 private const int DefaultSampleRate = 0;
31 private const int DefaultBitRate = 128000;
32 private const int DefaultChannels = 2;
35 /// Initialize a new instance of the <see cref="StreamRecorderAudioOptions"/> class with the specified codec.
37 /// <param name="codec">The <see cref="RecorderAudioCodec"/> for encoding audio stream.</param>
39 /// <see cref="SampleRate"/>, <see cref="BitRate"/> and <see cref="Channels"/> will be set as default.
41 /// <exception cref="ArgumentException"><paramref name="codec"/> is not valid.</exception>
42 public StreamRecorderAudioOptions(RecorderAudioCodec codec) :
43 this(codec, DefaultSampleRate, DefaultBitRate, DefaultChannels)
48 /// Initialize a new instance of the <see cref="StreamRecorderAudioOptions"/> class with the specified
49 /// codec, sample rate, bit rate and channel value.
51 /// <param name="codec">The <see cref="RecorderAudioCodec"/> for encoding audio stream.</param>
52 /// <param name="sampleRate">The sample rate for encoding audio stream.</param>
53 /// <param name="bitRate">The bit rate for encoding audio stream.</param>
54 /// <param name="channels">The number of channels for encoding audio stream.</param>
55 /// <exception cref="ArgumentException"><paramref name="codec"/> is not valid.</exception>
56 /// <exception cref="ArgumentOutOfRangeException">
57 /// <paramref name="sampleRate"/> is less than zero.\n
59 /// <paramref name="bitRate"/> is less than or equal to zero.\n
61 /// <paramref name="channels"/> is less than or equal to zero.
63 public StreamRecorderAudioOptions(RecorderAudioCodec codec, int sampleRate, int bitRate, int channels)
66 SampleRate = sampleRate;
71 private RecorderAudioCodec _codec;
74 /// Gets or sets the audio codec for encoding an audio stream.
76 /// <value>The codec for audio stream recording.</value>
77 /// <exception cref="ArgumentException"><paramref name="value"/> is not valid.</exception>
78 /// <seealso cref="StreamRecorder.GetSupportedAudioCodecs"/>
79 public RecorderAudioCodec Codec
84 ValidationUtil.ValidateEnum(typeof(RecorderAudioCodec), value, nameof(value));
90 private int _sampleRate;
93 /// Gets or sets the sampling rate of the audio stream in hertz.
95 /// <remarks>If the value is zero, the sample rate will be decided based on input buffers.</remarks>
96 /// <value>The sample rate value for stream recorder. The default is zero.</value>
97 /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than zero.</exception>
105 throw new ArgumentOutOfRangeException(nameof(value), value,
106 "Sample rate can't be less than or equal to zero.");
113 private int _bitRate;
116 /// Gets or sets the bit rate of the audio encoder in bits per second.
118 /// <value>The bit rate value for audio stream recording. The default is 128000.</value>
119 /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than or equal to zero.</exception>
127 throw new ArgumentOutOfRangeException(nameof(value), value,
128 "Bit rate can't be less than or equal to zero.");
135 private int _channels;
138 /// Gets or sets the number of audio channels.
140 /// <value>The number of audio channels for audio stream recording. The default is 2.</value>
141 /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> is less than or equal to zero.</exception>
149 throw new ArgumentOutOfRangeException(nameof(value), value,
150 "Channels can't be less than or equal to zero.");
157 internal void Apply(StreamRecorder recorder)
159 recorder.ValidateAudioCodec(Codec);
161 Native.SetAudioEncoder(recorder.Handle, Codec.ToStreamRecorderEnum()).
162 ThrowIfError("Failed to set audio codec.");
164 Native.SetAudioSampleRate(recorder.Handle, SampleRate).
165 ThrowIfError("Failed to set audio sample rate.");
167 Native.SetAudioEncoderBitrate(recorder.Handle, BitRate).
168 ThrowIfError("Failed to set audio bit rate.");
170 Native.SetAudioChannel(recorder.Handle, Channels).
171 ThrowIfError("Failed to set audio channels.");