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.
123 * This destructor overrides Tizen::Base::Object::~Object().
127 virtual ~AudioEncoder(void);
130 * Initializes this instance of %AudioEncoder with the specified parameters.
134 * @return An error code
135 * @param[in] type The codec type
136 * @param[in] pOption The <a href="../org.tizen.native.appprogramming/html/guide/media/encoding_decoding_audio.htm#encoding_audio">optional parameters</a>
137 * @exception E_SUCCESS The method is successful.
138 * @exception E_UNSUPPORTED_CODEC The specified encoder is not supported.
139 * @exception E_OUT_OF_RANGE A specified input parameter has a value that is out of range.
140 * @exception E_OUT_OF_MEMORY The memory is insufficient.
141 * @exception E_SYSTEM A system error has occurred.
142 * @remarks The key type of the specified option is Tizen::Base::Integer, and the value type varies depending on the key type.
144 result Construct(CodecType type, const Tizen::Base::Collection::HashMap* pOption = null);
149 * Encodes the audio data from the source buffer and stores the encoded data into the destination buffer. @n
150 * The %AudioEncoder class reads the audio data from the source buffer
151 * and it writes the encoded audio data into the destination buffer.
152 * 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.
153 * If there is no space in the destination buffer, the encoder returns @c E_INVALID_ARG.
157 * @return An error code
158 * @param[in] srcBuf The source buffer that stores the uncompressed audio data
159 * @param[out] dstBuf The destination buffer that stores the encoded audio data
160 * @exception E_SUCCESS The method is successful.
161 * @exception E_INVALID_ARG The specified source or destination buffer is invalid.
162 * @exception E_OUT_OF_MEMORY The specified destination buffer is not sufficient to store the decoded data.
163 * @exception E_SYSTEM A system error has occurred.
165 result Encode(Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& dstBuf);
168 * Resets the internal state of the audio encoder to process a new audio stream.
172 * @return An error code
173 * @exception E_SUCCESS The method is successful.
174 * @exception E_SYSTEM A system error has occurred.
179 * Gets a list of the supported codecs.
183 * @return A list of the codecs supported by the %AudioEncoder class, @n
184 * else @c null if an exception occurs
185 * @exception E_SUCCESS The method is successful.
186 * @exception E_OUT_OF_MEMORY The memory is insufficient.
188 * - The specific error code can be accessed using the GetLastResult() method.
189 * - The return value must be deleted by the caller.
191 static Tizen::Base::Collection::IListT<CodecType>* GetSupportedCodecListN(void);
195 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
200 AudioEncoder(const AudioEncoder& enc);
203 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
208 AudioEncoder& operator =(const AudioEncoder& enc);
210 friend class _AudioEncoderImpl;
211 class _AudioEncoderImpl* __pImpl;