M4AD_Common.h revision 7c9d8018755adf1857571125ba1b3598c96ea506
161dfca9e892597db79889addb7a3abf54cd50588Logan Chien/*
261dfca9e892597db79889addb7a3abf54cd50588Logan Chien * Copyright (C) 2004-2011 NXP Software
361dfca9e892597db79889addb7a3abf54cd50588Logan Chien * Copyright (C) 2011 The Android Open Source Project
461dfca9e892597db79889addb7a3abf54cd50588Logan Chien *
561dfca9e892597db79889addb7a3abf54cd50588Logan Chien * Licensed under the Apache License, Version 2.0 (the "License");
6541763d9f2395cf4170d6f8fad0b58098f35c70cTDYa * you may not use this file except in compliance with the License.
761dfca9e892597db79889addb7a3abf54cd50588Logan Chien * You may obtain a copy of the License at
861dfca9e892597db79889addb7a3abf54cd50588Logan Chien *
961dfca9e892597db79889addb7a3abf54cd50588Logan Chien *      http://www.apache.org/licenses/LICENSE-2.0
1061dfca9e892597db79889addb7a3abf54cd50588Logan Chien *
1161dfca9e892597db79889addb7a3abf54cd50588Logan Chien * Unless required by applicable law or agreed to in writing, software
1261dfca9e892597db79889addb7a3abf54cd50588Logan Chien * distributed under the License is distributed on an "AS IS" BASIS,
1361dfca9e892597db79889addb7a3abf54cd50588Logan Chien * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1461dfca9e892597db79889addb7a3abf54cd50588Logan Chien * See the License for the specific language governing permissions and
1561dfca9e892597db79889addb7a3abf54cd50588Logan Chien * limitations under the License.
1661dfca9e892597db79889addb7a3abf54cd50588Logan Chien */
1761dfca9e892597db79889addb7a3abf54cd50588Logan Chien/**
1861dfca9e892597db79889addb7a3abf54cd50588Logan Chien ************************************************************************
1961dfca9e892597db79889addb7a3abf54cd50588Logan Chien * @fil        M4AD_Common.h
2061dfca9e892597db79889addb7a3abf54cd50588Logan Chien * @brief    Audio Shell Decoder common interface declaration
2161dfca9e892597db79889addb7a3abf54cd50588Logan Chien * @note    This file declares the common interfaces that audio decoder shells must implement
2261dfca9e892597db79889addb7a3abf54cd50588Logan Chien ************************************************************************
2361dfca9e892597db79889addb7a3abf54cd50588Logan Chien*/
2461dfca9e892597db79889addb7a3abf54cd50588Logan Chien#ifndef __M4AD_COMMON_H__
2561dfca9e892597db79889addb7a3abf54cd50588Logan Chien#define __M4AD_COMMON_H__
2661dfca9e892597db79889addb7a3abf54cd50588Logan Chien
2761dfca9e892597db79889addb7a3abf54cd50588Logan Chien#include "M4OSA_Types.h"
28af521b05a143c96604dbb7488e155c5248e34462Logan Chien#include "M4OSA_Error.h"
29af521b05a143c96604dbb7488e155c5248e34462Logan Chien#include "M4OSA_OptionID.h"
30af521b05a143c96604dbb7488e155c5248e34462Logan Chien#include "M4OSA_CoreID.h"
31af521b05a143c96604dbb7488e155c5248e34462Logan Chien#include "M4DA_Types.h"
32af521b05a143c96604dbb7488e155c5248e34462Logan Chien#include "M4TOOL_VersionInfo.h"
33af521b05a143c96604dbb7488e155c5248e34462Logan Chien
34af521b05a143c96604dbb7488e155c5248e34462Logan Chien#ifdef __cplusplus
35af521b05a143c96604dbb7488e155c5248e34462Logan Chienextern "C" {
36541763d9f2395cf4170d6f8fad0b58098f35c70cTDYa#endif
37541763d9f2395cf4170d6f8fad0b58098f35c70cTDYa
38541763d9f2395cf4170d6f8fad0b58098f35c70cTDYa
3961dfca9e892597db79889addb7a3abf54cd50588Logan Chientypedef M4OSA_Void* M4AD_Context;
4061dfca9e892597db79889addb7a3abf54cd50588Logan Chien
4161dfca9e892597db79889addb7a3abf54cd50588Logan Chien/**
42af521b05a143c96604dbb7488e155c5248e34462Logan Chien ************************************************************************
4361dfca9e892597db79889addb7a3abf54cd50588Logan Chien * enum     M4AD_OptionID
4461dfca9e892597db79889addb7a3abf54cd50588Logan Chien * @brief    This enum defines the Audio decoder options.
4561dfca9e892597db79889addb7a3abf54cd50588Logan Chien * @note    These options can be read from or written to a decoder via
46af521b05a143c96604dbb7488e155c5248e34462Logan Chien *            M4AD_getOption_fct/M4AD_setOption_fct
4761dfca9e892597db79889addb7a3abf54cd50588Logan Chien ************************************************************************
4861dfca9e892597db79889addb7a3abf54cd50588Logan Chien*/
4961dfca9e892597db79889addb7a3abf54cd50588Logan Chientypedef enum
5061dfca9e892597db79889addb7a3abf54cd50588Logan Chien{
5161dfca9e892597db79889addb7a3abf54cd50588Logan Chien    /**
5261dfca9e892597db79889addb7a3abf54cd50588Logan Chien     * Set the flag of presence of protection */
5361dfca9e892597db79889addb7a3abf54cd50588Logan Chien    M4AD_kOptionID_ProtectionAbsent = M4OSA_OPTION_ID_CREATE(M4_WRITE, M4DECODER_AUDIO, 0x01),
5461dfca9e892597db79889addb7a3abf54cd50588Logan Chien
5561dfca9e892597db79889addb7a3abf54cd50588Logan Chien    /**
5661dfca9e892597db79889addb7a3abf54cd50588Logan Chien     * Set the number of frames per bloc */
5761dfca9e892597db79889addb7a3abf54cd50588Logan Chien    M4AD_kOptionID_NbFramePerBloc    = M4OSA_OPTION_ID_CREATE(M4_WRITE, M4DECODER_AUDIO, 0x02),
5861dfca9e892597db79889addb7a3abf54cd50588Logan Chien
5961dfca9e892597db79889addb7a3abf54cd50588Logan Chien    /**
6061dfca9e892597db79889addb7a3abf54cd50588Logan Chien     * Set the AAC decoder user parameters */
6161dfca9e892597db79889addb7a3abf54cd50588Logan Chien    M4AD_kOptionID_UserParam        = M4OSA_OPTION_ID_CREATE(M4_WRITE, M4DECODER_AUDIO, 0x03),
6261dfca9e892597db79889addb7a3abf54cd50588Logan Chien
6361dfca9e892597db79889addb7a3abf54cd50588Logan Chien
6461dfca9e892597db79889addb7a3abf54cd50588Logan Chien    /**
6561dfca9e892597db79889addb7a3abf54cd50588Logan Chien     * Get the AAC steam type */
6661dfca9e892597db79889addb7a3abf54cd50588Logan Chien    M4AD_kOptionID_StreamType        = M4OSA_OPTION_ID_CREATE(M4_READ , M4DECODER_AUDIO, 0x10),
6761dfca9e892597db79889addb7a3abf54cd50588Logan Chien
6861dfca9e892597db79889addb7a3abf54cd50588Logan Chien    /**
6961dfca9e892597db79889addb7a3abf54cd50588Logan Chien     * Get the number of used bytes in the latest decode
7061dfca9e892597db79889addb7a3abf54cd50588Logan Chien     (used only when decoding AAC from ADIF file) */
7161dfca9e892597db79889addb7a3abf54cd50588Logan Chien    M4AD_kOptionID_UsedBytes        = M4OSA_OPTION_ID_CREATE(M4_READ , M4DECODER_AUDIO, 0x11)
7261dfca9e892597db79889addb7a3abf54cd50588Logan Chien
7361dfca9e892597db79889addb7a3abf54cd50588Logan Chien} M4AD_OptionID;
7461dfca9e892597db79889addb7a3abf54cd50588Logan Chien
7561dfca9e892597db79889addb7a3abf54cd50588Logan Chien
7661dfca9e892597db79889addb7a3abf54cd50588Logan Chien
7761dfca9e892597db79889addb7a3abf54cd50588Logan Chientypedef enum
7861dfca9e892597db79889addb7a3abf54cd50588Logan Chien{
7955b5e7c242e599b88f5727352758808461483000Logan Chien    M4_kUnknown = 0,    /* Unknown stream type */
8061dfca9e892597db79889addb7a3abf54cd50588Logan Chien    M4_kAAC,            /* M4_kAAC_MAIN or M4_kAAC_LC or M4_kAAC_SSR or M4_kAAC_LTP    */
8161dfca9e892597db79889addb7a3abf54cd50588Logan Chien    M4_kAACplus,        /* Decoder type is AAC plus */
8261dfca9e892597db79889addb7a3abf54cd50588Logan Chien    M4_keAACplus        /* Decoder type is enhanced AAC plus */
8361dfca9e892597db79889addb7a3abf54cd50588Logan Chien} M4_AACType;
8461dfca9e892597db79889addb7a3abf54cd50588Logan Chien
8561dfca9e892597db79889addb7a3abf54cd50588Logan Chien/**
8661dfca9e892597db79889addb7a3abf54cd50588Logan Chien ************************************************************************
8761dfca9e892597db79889addb7a3abf54cd50588Logan Chien * enum     M4AD_Type
8861dfca9e892597db79889addb7a3abf54cd50588Logan Chien * @brief    This enum defines the audio types used to create decoders
8961dfca9e892597db79889addb7a3abf54cd50588Logan Chien * @note    This enum is used internally by the VPS to identify a currently supported
9061dfca9e892597db79889addb7a3abf54cd50588Logan Chien *            audio decoder interface. Each decoder is registered with one of this type associated.
9161dfca9e892597db79889addb7a3abf54cd50588Logan Chien *            When a decoder instance is needed, this type is used to identify
9261dfca9e892597db79889addb7a3abf54cd50588Logan Chien *            and retrieve its interface.
9361dfca9e892597db79889addb7a3abf54cd50588Logan Chien ************************************************************************
9461dfca9e892597db79889addb7a3abf54cd50588Logan Chien*/
9561dfca9e892597db79889addb7a3abf54cd50588Logan Chientypedef enum
9661dfca9e892597db79889addb7a3abf54cd50588Logan Chien{
9761dfca9e892597db79889addb7a3abf54cd50588Logan Chien    M4AD_kTypeAMRNB = 0,
9861dfca9e892597db79889addb7a3abf54cd50588Logan Chien    M4AD_kTypeAMRWB,
9961dfca9e892597db79889addb7a3abf54cd50588Logan Chien    M4AD_kTypeAAC,
10061dfca9e892597db79889addb7a3abf54cd50588Logan Chien    M4AD_kTypeMP3,
10161dfca9e892597db79889addb7a3abf54cd50588Logan Chien    M4AD_kTypePCM,
10261dfca9e892597db79889addb7a3abf54cd50588Logan Chien    M4AD_kTypeBBMusicEngine,
10361dfca9e892597db79889addb7a3abf54cd50588Logan Chien    M4AD_kTypeWMA,
10461dfca9e892597db79889addb7a3abf54cd50588Logan Chien    M4AD_kTypeRMA,
10561dfca9e892597db79889addb7a3abf54cd50588Logan Chien    M4AD_kTypeADPCM,
10661dfca9e892597db79889addb7a3abf54cd50588Logan Chien    M4AD_kType_NB  /* number of decoders, keep it as last enum entry */
107622e0734f429212e59a04a05b34ea0a5f9e1ef2bLogan Chien
10861dfca9e892597db79889addb7a3abf54cd50588Logan Chien} M4AD_Type ;
10961dfca9e892597db79889addb7a3abf54cd50588Logan Chien
110541763d9f2395cf4170d6f8fad0b58098f35c70cTDYa
111541763d9f2395cf4170d6f8fad0b58098f35c70cTDYa
112541763d9f2395cf4170d6f8fad0b58098f35c70cTDYa/**
113541763d9f2395cf4170d6f8fad0b58098f35c70cTDYa ************************************************************************
114541763d9f2395cf4170d6f8fad0b58098f35c70cTDYa * structure    M4AD_Buffer
115541763d9f2395cf4170d6f8fad0b58098f35c70cTDYa * @brief        Structure to describe a buffer
116541763d9f2395cf4170d6f8fad0b58098f35c70cTDYa ************************************************************************
117541763d9f2395cf4170d6f8fad0b58098f35c70cTDYa*/
118541763d9f2395cf4170d6f8fad0b58098f35c70cTDYatypedef struct
119541763d9f2395cf4170d6f8fad0b58098f35c70cTDYa{
120541763d9f2395cf4170d6f8fad0b58098f35c70cTDYa    M4OSA_MemAddr8    m_dataAddress;
121541763d9f2395cf4170d6f8fad0b58098f35c70cTDYa    M4OSA_UInt32    m_bufferSize;
122541763d9f2395cf4170d6f8fad0b58098f35c70cTDYa} M4AD_Buffer;
123541763d9f2395cf4170d6f8fad0b58098f35c70cTDYa
124541763d9f2395cf4170d6f8fad0b58098f35c70cTDYa/**
125541763d9f2395cf4170d6f8fad0b58098f35c70cTDYa ************************************************************************
126541763d9f2395cf4170d6f8fad0b58098f35c70cTDYa * @brief    Creates an instance of the decoder
127541763d9f2395cf4170d6f8fad0b58098f35c70cTDYa * @note    Allocates the context
128541763d9f2395cf4170d6f8fad0b58098f35c70cTDYa *
129541763d9f2395cf4170d6f8fad0b58098f35c70cTDYa * @param    pContext:        (OUT)    Context of the decoder
13061dfca9e892597db79889addb7a3abf54cd50588Logan Chien * @param    pStreamHandler:    (IN)    Pointer to an audio stream description
131 * @param    pUserData:        (IN)    Pointer to User data
132 *
133 * @return    M4NO_ERROR                 there is no error
134 * @return  M4ERR_STATE             State automaton is not applied
135 * @return    M4ERR_ALLOC                a memory allocation has failed
136 * @return    M4ERR_PARAMETER            at least one parameter is not properly set (in DEBUG only)
137 ************************************************************************
138*/
139
140typedef M4OSA_ERR  (M4AD_create_fct)(M4AD_Context *pContext,
141                                     M4_AudioStreamHandler *pStreamHandler, void* pUserData);
142
143
144/**
145 ************************************************************************
146 * @brief    Destroys the instance of the decoder
147 * @note    After this call the context is invalid
148 *
149 * @param    context:    (IN)    Context of the decoder
150 *
151 * @return    M4NO_ERROR             There is no error
152 * @return  M4ERR_PARAMETER     The context is invalid (in DEBUG only)
153 ************************************************************************
154*/
155typedef M4OSA_ERR  (M4AD_destroy_fct)    (M4AD_Context context);
156
157/**
158 ************************************************************************
159 * @brief   Decodes the given audio data
160 * @note    Parses and decodes the next audio frame, from the given buffer.
161 *            This function changes pInputBufferSize value according to the amount
162 *            of data actually read.
163 *
164 * @param    context:            (IN)    Context of the decoder
165 * @param    inputBuffer:        (IN/OUT)Input Data buffer. It contains at least one audio frame.
166 *                                       The size of the buffer must be updated inside the
167 *                                       function to reflect the size of the actually decoded data.
168 *                                       (e.g. the first frame in pInputBuffer)
169 * @param   decodedPCMBuffer:    (OUT)   Output PCM buffer (decoded data).
170 * @param   jumping:            (IN)    M4OSA_TRUE if a jump was just done, M4OSA_FALSE otherwise.
171 * @return    M4NO_ERROR                 there is no error
172 * @return    M4ERR_PARAMETER            at least one parameter is not properly set
173 ************************************************************************
174*/
175typedef M4OSA_ERR  (M4AD_step_fct)    (M4AD_Context context, M4AD_Buffer *pInputBuffer,
176                                     M4AD_Buffer *pDecodedPCMBuffer, M4OSA_Bool jumping);
177
178/**
179 ************************************************************************
180 * @brief    Gets the decoder version
181 * @note    The version is given in a M4_VersionInfo structure
182 *
183 * @param    pValue:        (OUT)        Pointer to the version structure
184 *
185 * @return    M4NO_ERROR                 there is no error
186 * @return  M4ERR_PARAMETER         The given pointer is null (in DEBUG only)
187 ************************************************************************
188*/
189typedef M4OSA_ERR  (M4AD_getVersion_fct)(M4_VersionInfo* pVersionInfo);
190
191
192/**
193 ************************************************************************
194 * @brief    This function creates the AAC core decoder according to
195 *            the stream properties and to the options that may
196 *            have been set using M4AD_setOption_fct
197 * @note    Creates an instance of the AAC decoder
198 * @note    This function is used especially by the AAC decoder
199 *
200 * @param    pContext:        (IN/OUT)    Context of the decoder
201 * @param    pStreamHandler:    (IN)    Pointer to an audio stream description
202 *
203 * @return    M4NO_ERROR                 there is no error
204 * @return  M4ERR_STATE             State automaton is not applied
205 * @return    M4ERR_ALLOC                a memory allocation has failed
206 * @return    M4ERR_PARAMETER            at least one parameter is not properly set (in DEBUG only)
207 ************************************************************************
208*/
209typedef M4OSA_ERR  (M4AD_start_fct)    (M4AD_Context pContext);
210
211/**
212 ************************************************************************
213 * @brief    Reset the instance of the decoder
214 *
215 * @param    context:    (IN)    Context of the decoder
216 *
217 * @return    M4NO_ERROR             There is no error
218 * @return  M4ERR_PARAMETER     The context is invalid (in DEBUG only)
219 ************************************************************************
220*/
221typedef M4OSA_ERR  (M4AD_reset_fct)    (M4AD_Context context);
222
223
224/**
225 ************************************************************************
226 * @brief   set en option value of the audio decoder
227 *
228 * @param    context:        (IN)    Context of the decoder
229 * @param    optionId:        (IN)    indicates the option to set
230 * @param    pValue:            (IN)    pointer to structure or value (allocated by user)
231 *                                  where option is stored
232 * @return    M4NO_ERROR                 there is no error
233 * @return    M4ERR_BAD_CONTEXT        provided context is not a valid one
234 * @return    M4ERR_PARAMETER            at least one parameter is not properly set
235 * @return    M4ERR_BAD_OPTION_ID        when the option ID is not a valid one
236 ************************************************************************
237*/
238typedef M4OSA_ERR (M4AD_setOption_fct) (M4AD_Context context,
239                                         M4OSA_OptionID optionId, M4OSA_DataOption pValue);
240
241/**
242 ************************************************************************
243 * @brief   Get en option value of the audio decoder
244 *
245 * @param    context:        (IN)    Context of the decoder
246 * @param    optionId:        (IN)    indicates the option to set
247 * @param    pValue:            (OUT)    pointer to structure or value (allocated by user)
248 *                                  where option is stored
249 * @return    M4NO_ERROR                 there is no error
250 * @return    M4ERR_BAD_CONTEXT        provided context is not a valid one
251 * @return    M4ERR_PARAMETER            at least one parameter is not properly set
252 * @return    M4ERR_BAD_OPTION_ID        when the option ID is not a valid one
253 ************************************************************************
254*/
255typedef M4OSA_ERR (M4AD_getOption_fct) (M4AD_Context context, M4OSA_OptionID optionId,
256                                         M4OSA_DataOption pValue);
257/**
258 ************************************************************************
259 * structure    M4AD_Interface
260 * @brief        This structure defines the generic audio decoder interface
261 * @note        This structure stores the pointers to functions of one audio decoder type.
262 *                The decoder type is one of the M4AD_Type
263 ************************************************************************
264*/
265typedef struct _M4AD_Interface
266{
267
268    M4AD_create_fct*        m_pFctCreateAudioDec;
269    M4AD_start_fct*            m_pFctStartAudioDec;
270    M4AD_step_fct*            m_pFctStepAudioDec;
271    M4AD_getVersion_fct*    m_pFctGetVersionAudioDec;
272    M4AD_destroy_fct*        m_pFctDestroyAudioDec;
273    M4AD_reset_fct*            m_pFctResetAudioDec;
274    M4AD_setOption_fct*        m_pFctSetOptionAudioDec;
275    M4AD_getOption_fct*        m_pFctGetOptionAudioDec;
276
277} M4AD_Interface;
278
279#ifdef __cplusplus
280}
281#endif
282
283#endif /*__M4AD_COMMON_H__*/
284
285