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 FMediaAudioDecoder.h
20 * @brief This is the header file for the %AudioDecoder class.
22 * This header file contains the declarations of the %AudioDecoder class.
25 #ifndef _FMEDIA_AUDIO_DECODER_H_
26 #define _FMEDIA_AUDIO_DECODER_H_
29 #include <FMediaAudioTypes.h>
30 #include <FMediaTypes.h>
32 namespace Tizen { namespace Media
37 * @brief This class decodes a compressed audio stream to a raw audio data.
42 * Source data of AAC and AMR decoder must be raw compressed data without header.
44 * The %AudioDecoder class decodes a compressed audio stream to a raw audio data.
45 * The audio decoding formats, such as CODEC_MP3, CODEC_AAC, and CODEC_AMR_NB, are supported.
47 * 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>.
49 * The following example demonstrates how to use the %AudioDecoder class in MP3 decoding.
59 * using namespace Tizen::Base;
60 * using namespace Tizen::Base::Collection;
61 * using namespace Tizen::Io;
62 * using namespace Tizen::Media;
64 * #define DST_BUF_SIZE (1024*16)
67 * AudioDecoderSample(void)
71 * ByteBuffer srcBuf, dstBuf;
73 * FileAttributes attr;
75 * AudioChannelType channelType;
76 * AudioSampleType sampleType;
77 * String filePath = Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/test.mp3";
79 * // Loads src file into buffer
80 * File::GetAttributes(filePath, attr);
81 * srcBuf.Construct(attr.GetFileSize());
82 * srcFile.Construct(filePath, "rb");
83 * srcFile.Read(srcBuf);
84 * srcBuf.Flip(); // Sets the position of source buffer to zero
86 * // Adds code that skips ID3 tag in srcBuf
88 * dstBuf.Construct(DST_BUF_SIZE);
90 * dec.Construct(CODEC_MP3);
91 * r = dec.Probe(srcBuf, sampleType, channelType, sampleRate);
97 * while (srcBuf.GetRemaining() > 0)
99 * r = dec.Decode(srcBuf, dstBuf);
105 * // Adds code handling decoded data
115 class _OSP_EXPORT_ AudioDecoder
116 : public Tizen::Base::Object
120 * 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.
124 * @remarks After creating an instance of this class, the Construct() method must be called explicitly to initialize this instance.
130 * This destructor overrides Tizen::Base::Object::~Object().
134 virtual ~AudioDecoder(void);
137 * Initializes this instance of %AudioDecoder with the specified parameters. @n
138 * The following example demonstrates how to use the %Construct() method as a simple decoder construction with optional parameters.
141 * result OpenAacDecoder(void)
147 * option.Construct();
148 * option.Add(*(new Integer(MEDIA_PROPERTY_AUDIO_CHANNEL_TYPE)), *(new Integer(AUDIO_CHANNEL_TYPE_STEREO)));
149 * option.Add(*(new Integer(MEDIA_PROPERTY_AUDIO_SAMPLE_RATE)), *(new Integer(44100)));
151 * r = dec.Construct(CODEC_AAC, &option);
165 * @return An error code
166 * @param[in] type The codec type
167 * @param[in] pOption The <a href="../org.tizen.native.appprogramming/html/guide/media/encoding_decoding_audio.htm#decoding_audio">optional parameters</a>
168 * @exception E_SUCCESS The method is successful.
169 * @exception E_UNSUPPORTED_CODEC The specified decoder is not supported.
170 * @exception E_OUT_OF_RANGE A specified input parameter has a value that is out of range.
171 * @exception E_OUT_OF_MEMORY The memory is insufficient.
172 * @exception E_SYSTEM A system error has occurred.
173 * @remarks The key type of the specified option is Tizen::Base::Integer, and the value type varies depending on the key type.
175 result Construct(CodecType type, const Tizen::Base::Collection::HashMap* pOption = null);
179 * Probes whether the audio data can be decoded.
183 * @return An error code
184 * @param[in] srcBuf The source buffer that stores the compressed audio data
185 * @param[out] sampleType The sample type of the decoded audio sample
186 * @param[out] channelType The channel type of the decoded audio sample
187 * @param[out] sampleRate The sample rate of the decoded audio sample
188 * @exception E_SUCCESS The method is successful.
189 * @exception E_INVALID_ARG A specified source buffer is invalid.
190 * @exception E_UNSUPPORTED_FORMAT The input data is not in a supported format.
191 * @exception E_OUT_OF_MEMORY The memory is insufficient to decode the sample.
192 * @exception E_SYSTEM A system error has occurred.
193 * @remarks This method resets the internal state of an audio decoder.
195 result Probe(const Tizen::Base::ByteBuffer& srcBuf, AudioSampleType& sampleType, AudioChannelType& channelType, int& sampleRate);
199 * Decodes the audio data from the source buffer and stores the decoded data into a destination buffer. @n
200 * The %AudioDecoder class reads and decodes the audio data from the source buffer
201 * and it also writes the decoded audio data into the destination buffer. @n
202 * 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.
206 * @return An error code
207 * @param[in] srcBuf The source buffer that stores the compressed audio data
208 * @param[out] dstBuf The destination buffer that stores the decoded audio data
209 * @exception E_SUCCESS The method is successful.
210 * @exception E_INVALID_ARG A specified source or destination buffer is invalid.
211 * @exception E_UNSUPPORTED_FORMAT The input data is not in a supported format.
212 * @exception E_OUT_OF_MEMORY The specified destination buffer is insufficient to store the decoded data.
213 * @exception E_SYSTEM A system error has occurred.
215 result Decode(Tizen::Base::ByteBuffer& srcBuf, Tizen::Base::ByteBuffer& dstBuf);
218 * Resets the internal state of the audio decoder to process a new audio stream.
222 * @return An error code
223 * @exception E_SUCCESS The method is successful.
224 * @exception E_SYSTEM A system error has occurred.
229 * Gets the specified property type value of this instance.
233 * @return An error code
234 * @param[in] key The <a href="../org.tizen.native.appprogramming/html/guide/media/encoding_decoding_audio.htm#decoding_audio">key</a> for which the value is obtained
235 * @param[out] value The obtained property value
236 * @exception E_SUCCESS The method is successful.
237 * @exception E_OBJ_NOT_FOUND The specified @c key is not found.
238 * @exception E_INVALID_ARG The specified @c key is not supported.
239 * @exception E_SYSTEM A system error has occurred.
240 * @remarks The property whose value type is enum can be obtained using this method.
242 result GetValue(MediaPropertyType key, int& value) const;
245 * Gets the supported properties of this instance.
249 * @return A list of supported properties, @n
250 * else @c null if no property is supported or if an exception occurs
251 * @exception E_SUCCESS The method is successful.
252 * @exception E_OUT_OF_MEMORY The memory is insufficient.
253 * @exception E_SYSTEM A system error has occurred.
254 * @exception E_OBJ_NOT_FOUND This instance does not support any property.
255 * @remarks The specific error code can be accessed using the GetLastResult() method. @n
256 * The return value must be deleted.
258 Tizen::Base::Collection::IListT<MediaPropertyType>* GetSupportedPropertyListN(void) const;
261 * Checks whether the specified property type is supported.
265 * @return @c true if the property is supported, @n
267 * @param[in] key The <a href="../org.tizen.native.appprogramming/html/guide/media/encoding_decoding_audio.htm#decoding_audio">key</a> for which the value is obtained
268 * @exception E_SUCCESS The method is successful.
269 * @exception E_OBJ_NOT_FOUND The specified @c key is not found.
270 * @exception E_SYSTEM A system error has occurred.
271 * @remarks The specific error code can be accessed using the GetLastResult() method.
273 bool IsPropertySupported(MediaPropertyType key) const;
276 * Gets a list of the supported codecs.
280 * @return A list of the codecs supported by the %AudioDecoder class, @n
281 * else @c null if an exception occurs
282 * @exception E_SUCCESS The method is successful.
283 * @exception E_OUT_OF_MEMORY The memory is insufficient.
284 * @remarks The specific error code can be accessed using the GetLastResult() method.
285 * @remarks The return value must be deleted by the caller.
287 static Tizen::Base::Collection::IListT<CodecType>* GetSupportedCodecListN(void);
291 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
296 AudioDecoder(const AudioDecoder& rhs);
298 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
303 AudioDecoder& operator =(const AudioDecoder& rhs);
305 friend class _AudioDecoderImpl;
306 class _AudioDecoderImpl* __pImpl;
311 #endif // _FMEDIA_AUDIODECODER_H_