2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FMediaAudioEncoder.h
20 * @brief This is the header file for the %AudioEncoder class.
22 * This header file contains the declarations of the %Tizen::Media::AudioEncoder class.
25 #ifndef _FMEDIA_AUDIO_ENCODER_H_
26 #define _FMEDIA_AUDIO_ENCODER_H_
29 #include <FMediaAudioTypes.h>
30 #include <FMediaTypes.h>
32 namespace Tizen { namespace Media
37 * @brief This class encodes raw audio data into compressed audio stream.
41 * The %AudioEncoder class encodes raw audio data into compressed audio stream.
42 * It supports the audio encoding formats such as CODE_AAC and CODEC_AMR_NB. @n
44 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/media/encoding_decoding_audio.htm">Encoding and Decoding Audio</a>. @n
46 * The following example demonstrates how to use the %AudioEncoder class in Advanced Audio Coding (AAC) encoding.
54 * using namespace Tizen::Base;
55 * using namespace Tizen::Base::Collection;
56 * using namespace Tizen::Io;
57 * using namespace Tizen::Media;
59 * #define DST_BUF_SIZE (1024*8)
62 * AudioEncoderSample(void)
66 * ByteBuffer srcBuf, dstBuf;
68 * FileAttributes attr;
69 * int sampleRate = 44100;
70 * AudioChannelType channelType = AUDIO_CHANNEL_TYPE_STEREO;
71 * int bitRate = 128000; // 128Kbps
73 * String filePath = Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/test.wav";
76 * option.Add(*(new Integer(MEDIA_PROPERTY_AUDIO_CHANNEL_TYPE)), *(new Integer(channelType)));
77 * option.Add(*(new Integer(MEDIA_PROPERTY_AUDIO_SAMPLE_RATE)), *(new Integer(sampleRate)));
78 * option.Add(*(new Integer(MEDIA_PROPERTY_AUDIO_BIT_RATE)), *(new Integer(bitRate)));
80 * // Loads src file into buffer
81 * File::GetAttributes(filePath, attr);
82 * srcBuf.Construct(attr.GetFileSize());
83 * srcFile.Construct(filePath, L"rb");
84 * srcFile.Read(srcBuf);
85 * srcBuf.Flip(); // Sets the position of source buffer to zero
87 * // Adds code that skips WAV header in srcBuf
89 * dstBuf.Construct(DST_BUF_SIZE);
91 * enc.Construct(CODEC_AAC, &option);
93 * while (srcBuf.GetRemaining() > 0)
95 * r = enc.Encode(srcBuf, dstBuf);
100 * // Adds code handling encoded data
110 class _OSP_EXPORT_ AudioEncoder
111 : public Tizen::Base::Object
115 * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after calling this constructor.
119 * @remarks After creating an instance of this class, the Construct() method must be called explicitly to initialize this instance.
125 * This destructor overrides Tizen::Base::Object::~Object().
129 virtual ~AudioEncoder(void);
132 * Initializes this instance of %AudioEncoder with the specified parameters.
136 * @return An error code
137 * @param[in] type The codec type
138 * @param[in] pOption The <a href="../org.tizen.native.appprogramming/html/guide/media/encoding_decoding_audio.htm#encoding_audio">optional parameters</a>
139 * @exception E_SUCCESS The method is successful.
140 * @exception E_UNSUPPORTED_CODEC The specified encoder is not supported.
141 * @exception E_OUT_OF_RANGE A specified input parameter has a value that is out of range.
142 * @exception E_OUT_OF_MEMORY The memory is insufficient.
143 * @exception E_SYSTEM A system error has occurred.
144 * @remarks The key type of the specified option is Tizen::Base::Integer, and the value type varies depending on the key type.
146 result Construct(CodecType type, const Tizen::Base::Collection::HashMap* pOption = null);
151 * Encodes the audio data from the source buffer and stores the encoded data into the destination buffer. @n
152 * The %AudioEncoder class reads the audio data from the source buffer
153 * and it writes the encoded audio data into the destination buffer.
154 * The position of the source buffer is moved to the end of the consumed data and the position of the destination buffer is moved to the end of the written data.
155 * If there is no space in the destination buffer, the encoder returns @c E_INVALID_ARG.
159 * @return An error code
160 * @param[in] srcBuf The source buffer that stores the uncompressed audio data
161 * @param[out] dstBuf The destination buffer that stores the encoded audio data
162 * @exception E_SUCCESS The method is successful.
163 * @exception E_INVALID_ARG The specified source or destination buffer is invalid.
164 * @exception E_OUT_OF_MEMORY The specified destination buffer is not sufficient to store the decoded data.
165 * @exception E_SYSTEM A system error has occurred.
167 result Encode(Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& dstBuf);
170 * Resets the internal state of the audio encoder to process a new audio stream.
174 * @return An error code
175 * @exception E_SUCCESS The method is successful.
176 * @exception E_SYSTEM A system error has occurred.
181 * Gets a list of the supported codecs.
185 * @return A list of the codecs supported by the %AudioEncoder class, @n
186 * else @c null if an exception occurs
187 * @exception E_SUCCESS The method is successful.
188 * @exception E_OUT_OF_MEMORY The memory is insufficient.
189 * @remarks The specific error code can be accessed using the GetLastResult() method.
190 * @remarks The return value must be deleted by the caller.
192 static Tizen::Base::Collection::IListT<CodecType>* GetSupportedCodecListN(void);
196 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
201 AudioEncoder(const AudioEncoder& enc);
204 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
209 AudioEncoder& operator =(const AudioEncoder& enc);
211 friend class _AudioEncoderImpl;
212 class _AudioEncoderImpl* __pImpl;