/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using Native = Interop.StreamRecorder;
namespace Tizen.Multimedia
{
///
/// Specifies the options associated with audio recording.
///
///
///
///
/// 4
[Obsolete("Deprecated in API10; Will be removed in API12")]
public class StreamRecorderAudioOptions
{
private const int DefaultSampleRate = 0;
private const int DefaultBitRate = 128000;
private const int DefaultChannels = 2;
///
/// Initialize a new instance of the class with the specified codec.
///
/// The for encoding audio stream.
///
/// , and will be set as default.
///
/// is not valid.
/// 4
[Obsolete("Deprecated in API10; Will be removed in API12")]
public StreamRecorderAudioOptions(RecorderAudioCodec codec) :
this(codec, DefaultSampleRate, DefaultBitRate, DefaultChannels)
{
}
///
/// Initialize a new instance of the class with the specified
/// codec, sample rate, bit rate, and channel value.
///
/// The for encoding audio stream.
/// The sample rate for encoding audio stream.
/// The bit rate for encoding audio stream.
/// The number of channels for encoding audio stream.
/// is not valid.
///
/// is less than zero.
/// -or-
/// is less than or equal to zero.
/// -or-
/// is less than or equal to zero.
///
/// 4
[Obsolete("Deprecated in API10; Will be removed in API12")]
public StreamRecorderAudioOptions(RecorderAudioCodec codec, int sampleRate, int bitRate, int channels)
{
Codec = codec;
SampleRate = sampleRate;
BitRate = bitRate;
Channels = channels;
}
private RecorderAudioCodec _codec;
///
/// Gets or sets the audio codec for encoding an audio stream.
///
/// The codec for audio stream recording.
/// is not valid.
///
/// 4
[Obsolete("Deprecated in API10; Will be removed in API12")]
public RecorderAudioCodec Codec
{
get => _codec;
set
{
ValidationUtil.ValidateEnum(typeof(RecorderAudioCodec), value, nameof(value));
if (value == RecorderAudioCodec.None)
{
throw new ArgumentException("Audio codec can't be None.");
}
_codec = value;
}
}
private int _sampleRate;
///
/// Gets or sets the sampling rate of the audio stream in hertz.
///
/// If the value is zero, the sample rate will be decided based on input buffers.
/// The sample rate value for stream recorder. The default is zero.
/// is less than zero.
/// 4
[Obsolete("Deprecated in API10; Will be removed in API12")]
public int SampleRate
{
get => _sampleRate;
set
{
if (value < 0)
{
throw new ArgumentOutOfRangeException(nameof(value), value,
"Sample rate can't be less than or equal to zero.");
}
_sampleRate = value;
}
}
private int _bitRate;
///
/// Gets or sets the bit rate of the audio encoder in bits per second.
///
/// The bit rate value for audio stream recording. The default is 128000.
/// is less than or equal to zero.
/// 4
[Obsolete("Deprecated in API10; Will be removed in API12")]
public int BitRate
{
get => _bitRate;
set
{
if (value <= 0)
{
throw new ArgumentOutOfRangeException(nameof(value), value,
"Bit rate can't be less than or equal to zero.");
}
_bitRate = value;
}
}
private int _channels;
///
/// Gets or sets the number of audio channels.
///
/// The number of audio channels for audio stream recording. The default is 2.
/// is less than or equal to zero.
/// 4
[Obsolete("Deprecated in API10; Will be removed in API12")]
public int Channels
{
get => _channels;
set
{
if (value <= 0)
{
throw new ArgumentOutOfRangeException(nameof(value), value,
"Channels can't be less than or equal to zero.");
}
_channels = value;
}
}
internal void Apply(StreamRecorder recorder)
{
recorder.ValidateAudioCodec(Codec);
Native.SetAudioEncoder(recorder.Handle, Codec.ToStreamRecorderEnum()).
ThrowIfError("Failed to set audio codec.");
Native.SetAudioSampleRate(recorder.Handle, SampleRate).
ThrowIfError("Failed to set audio sample rate.");
Native.SetAudioEncoderBitrate(recorder.Handle, BitRate).
ThrowIfError("Failed to set audio bit rate.");
Native.SetAudioChannel(recorder.Handle, Channels).
ThrowIfError("Failed to set audio channels.");
}
}
}