M4AD_Null.c revision 32ed3f4dad00f8a65f7e6b38402c70d5341c57eb
1/* 2 * Copyright (C) 2004-2011 NXP Software 3 * Copyright (C) 2011 The Android Open Source Project 4 * 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 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 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. 16 */ 17/** 18************************************************************************* 19 * @file M4AD_Null.c 20 * @brief Implementation of the MP3 decoder public interface 21 * @note This file implements a "null" audio decoder, that is a decoder 22 * that do nothing except getting AU from the reader 23************************************************************************* 24*/ 25#include "M4OSA_Debug.h" 26#include "M4OSA_Error.h" 27#include "M4OSA_Debug.h" 28#include "M4TOOL_VersionInfo.h" 29#include "M4AD_Common.h" 30#include "M4AD_Null.h" 31 32#define M4AD_FORCE_16BITS 33 34/** 35 ************************************************************************ 36 * NULL Audio Decoder version information 37 ************************************************************************ 38*/ 39/* CHANGE_VERSION_HERE */ 40#define M4AD_NULL_MAJOR 1 41#define M4AD_NULL_MINOR 1 42#define M4AD_NULL_REVISION 4 43 44/** 45 ************************************************************************ 46 * structure M4AD_NullContext 47 * @brief Internal null decoder context 48 ************************************************************************ 49*/ 50typedef struct 51{ 52 /**< Pointer to the stream handler provided by the user */ 53 M4_AudioStreamHandler* m_pAudioStreamhandler; 54} M4AD_NullContext; 55 56 57/** 58 ************************************************************************ 59 * NXP MP3 decoder functions definition 60 ************************************************************************ 61*/ 62 63/** 64 ************************************************************************ 65 * @brief Creates an instance of the null decoder 66 * @note Allocates the context 67 * 68 * @param pContext: (OUT) Context of the decoder 69 * @param pStreamHandler: (IN) Pointer to an audio stream description 70 * @param pUserData: (IN) Pointer to User data 71 * 72 * @return M4NO_ERROR there is no error 73 * @return M4ERR_STATE State automaton is not applied 74 * @return M4ERR_ALLOC a memory allocation has failed 75 * @return M4ERR_PARAMETER at least one parameter is not properly set (in DEBUG only) 76 ************************************************************************ 77*/ 78M4OSA_ERR M4AD_NULL_create( M4AD_Context* pContext, 79 M4_AudioStreamHandler *pStreamHandler, 80 void* pUserData) 81{ 82 M4AD_NullContext* pC; 83 84 M4OSA_DEBUG_IF1((pContext == 0), M4ERR_PARAMETER, 85 "M4AD_NULL_create: invalid context pointer"); 86 M4OSA_DEBUG_IF1((pStreamHandler == 0), M4ERR_PARAMETER, 87 "M4AD_NULL_create: invalid pointer pStreamHandler"); 88 89 pC = (M4AD_NullContext*)M4OSA_malloc(sizeof(M4AD_NullContext), 90 M4DECODER_AUDIO, (M4OSA_Char *)"M4AD_NullContext"); 91 if (pC == (M4AD_NullContext*)0) 92 { 93 M4OSA_TRACE1_0("Can not allocate null decoder context"); 94 return M4ERR_ALLOC; 95 } 96 97 *pContext = pC; 98 99 pC->m_pAudioStreamhandler = pStreamHandler; 100 101 return M4NO_ERROR; 102} 103 104/** 105 ************************************************************************ 106 * @brief Destroys the instance of the null decoder 107 * @note After this call the context is invalid 108 * 109 * @param context: (IN) Context of the decoder 110 * 111 * @return M4NO_ERROR There is no error 112 * @return M4ERR_PARAMETER The context is invalid (in DEBUG only) 113 ************************************************************************ 114*/ 115M4OSA_ERR M4AD_NULL_destroy(M4AD_Context context) 116{ 117 M4AD_NullContext* pC = (M4AD_NullContext*)context; 118 119 M4OSA_DEBUG_IF1((context == M4OSA_NULL), M4ERR_PARAMETER, "M4AD_NULL_destroy: invalid context"); 120 121 M4OSA_free((M4OSA_MemAddr32)pC); 122 123 return M4NO_ERROR; 124} 125 126/** 127 ************************************************************************ 128 * @brief Simply output the given audio data 129 * @note 130 * 131 * @param context: (IN) Context of the decoder 132 * @param pInputBuffer: (IN/OUT)Input Data buffer. It contains at least one audio frame. 133 * The size of the buffer must be updated inside the function 134 * to reflect the size of the actually decoded data. 135 * (e.g. the first frame in pInputBuffer) 136 * @param pDecodedPCMBuffer: (OUT) Output PCM buffer (decoded data). 137 * @param jumping: (IN) M4OSA_TRUE if a jump was just done, M4OSA_FALSE otherwise. 138 * @return M4NO_ERROR there is no error 139 * @return M4ERR_PARAMETER at least one parameter is not properly set 140 ************************************************************************ 141*/ 142M4OSA_ERR M4AD_NULL_step(M4AD_Context context, M4AD_Buffer *pInputBuffer, 143 M4AD_Buffer *pDecodedPCMBuffer, M4OSA_Bool jumping) 144{ 145 M4AD_NullContext* pC = (M4AD_NullContext*)context; 146 147 /*The VPS sends a zero buffer at the end*/ 148 if (0 == pInputBuffer->m_bufferSize) 149 { 150 return M4WAR_NO_MORE_AU; 151 } 152 153 if (pInputBuffer->m_bufferSize > pDecodedPCMBuffer->m_bufferSize) 154 { 155 return M4ERR_PARAMETER; 156 } 157#ifdef M4AD_FORCE_16BITS 158 /*if read samples are 8 bits, complete them to 16 bits*/ 159 if (pC->m_pAudioStreamhandler->m_byteSampleSize == 1) 160 { 161 M4OSA_UInt32 i; 162 M4OSA_Int16 val; 163 164 for (i = 0; i < pInputBuffer->m_bufferSize; i++) 165 { 166 val = (M4OSA_Int16)((M4OSA_UInt8)(pInputBuffer->m_dataAddress[i]) - 128); 167 168 pDecodedPCMBuffer->m_dataAddress[i*2] = (M4OSA_Int8)(val>>8); 169 pDecodedPCMBuffer->m_dataAddress[i*2+1] = (M4OSA_Int8)(val&0x00ff); 170 } 171 } 172 else 173 { 174 memcpy((void *)pDecodedPCMBuffer->m_dataAddress, (void *)pInputBuffer->m_dataAddress, 175 pInputBuffer->m_bufferSize ); 176 } 177#else /*M4AD_FORCE_16BITS*/ 178 memcpy((void *)pDecodedPCMBuffer->m_dataAddress, (void *)pInputBuffer->m_dataAddress, 179 pInputBuffer->m_bufferSize ); 180#endif /*M4AD_FORCE_16BITS*/ 181 182 return M4NO_ERROR; 183} 184 185/** 186 ************************************************************************ 187 * @brief Gets the decoder version 188 * @note The version is given in a M4_VersionInfo structure 189 * 190 * @param pValue: (OUT) Pointer to the version structure 191 * 192 * @return M4NO_ERROR there is no error 193 * @return M4ERR_PARAMETER pVersionInfo pointer is null (in DEBUG only) 194 ************************************************************************ 195*/ 196M4OSA_ERR M4AD_NULL_getVersion(M4_VersionInfo* pVersionInfo) 197{ 198 M4OSA_ERR err = M4NO_ERROR; 199 M4OSA_DEBUG_IF1((pVersionInfo == 0), M4ERR_PARAMETER, 200 "M4AD_NULL_getVersion: invalid pointer pVersionInfo"); 201 202 /* Up until now, the null decoder version is not available */ 203 204 /* CHANGE_VERSION_HERE */ 205 pVersionInfo->m_major = M4AD_NULL_MAJOR; /*major version of the component*/ 206 pVersionInfo->m_minor = M4AD_NULL_MINOR; /*minor version of the component*/ 207 pVersionInfo->m_revision = M4AD_NULL_REVISION; /*revision version of the component*/ 208 pVersionInfo->m_structSize=sizeof(M4_VersionInfo); 209 210 return err; 211} 212 213 214/** 215 ************************************************************************ 216 * getInterface function definitions of NXP MP3 decoder 217 ************************************************************************ 218*/ 219 220/** 221 ************************************************************************ 222 * @brief Retrieves the interface implemented by the decoder 223 * @param pDecoderType : pointer on an M4AD_Type (allocated by the caller) 224 * that will be filled with the decoder type supported by 225 * this decoder 226 * @param pDecoderInterface : address of a pointer that will be set to the interface 227 * implemented by this decoder. The interface is a structure 228 * allocated by the function and must be un-allocated by the 229 * caller. 230 * 231 * @return M4NO_ERROR if OK 232 * @return M4ERR_ALLOC if allocation failed 233 ************************************************************************ 234*/ 235M4OSA_ERR M4AD_NULL_getInterface( M4AD_Type *pDecoderType, M4AD_Interface **pDecoderInterface) 236{ 237 *pDecoderInterface = ( M4AD_Interface*)M4OSA_malloc( sizeof(M4AD_Interface), 238 M4DECODER_AUDIO, (M4OSA_Char *)"M4AD_Interface" ); 239 if (M4OSA_NULL == *pDecoderInterface) 240 { 241 return M4ERR_ALLOC; 242 } 243 244 *pDecoderType = M4AD_kTypePCM; 245 246 (*pDecoderInterface)->m_pFctCreateAudioDec = M4AD_NULL_create; 247 (*pDecoderInterface)->m_pFctDestroyAudioDec = M4AD_NULL_destroy; 248 (*pDecoderInterface)->m_pFctStepAudioDec = M4AD_NULL_step; 249 (*pDecoderInterface)->m_pFctGetVersionAudioDec = M4AD_NULL_getVersion; 250 (*pDecoderInterface)->m_pFctStartAudioDec = M4OSA_NULL; 251 (*pDecoderInterface)->m_pFctResetAudioDec = M4OSA_NULL; 252 (*pDecoderInterface)->m_pFctSetOptionAudioDec = M4OSA_NULL; 253 (*pDecoderInterface)->m_pFctGetOptionAudioDec = M4OSA_NULL; 254 255 return M4NO_ERROR; 256} 257 258