M4MCS_Codecs.c revision 7c9d8018755adf1857571125ba1b3598c96ea506
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 M4MCS_Codecs.c 20 * @brief MCS implementation 21 * @note This file contains all functions related to audio/video 22 * codec manipulations. 23 ************************************************************************ 24 */ 25 26/** 27 ******************************************************************** 28 * Includes 29 ******************************************************************** 30 */ 31#include "NXPSW_CompilerSwitches.h" 32#include "M4OSA_Debug.h" /* Include for OSAL debug services */ 33#include "M4MCS_InternalTypes.h" /* Internal types of the MCS */ 34 35 36#ifdef M4MCS_SUPPORT_VIDEC_3GP 37#include "M4_MPEG4VI_VideoHandler.h" /*needed for renderer error codes*/ 38#endif 39 40 41/** 42 ************************************************************************ 43 * M4OSA_ERR M4MCS_clearInterfaceTables() 44 * @brief Clear encoders, decoders, reader and writers interfaces tables 45 * @param pContext (IN/OUT) MCS context. 46 * @return M4NO_ERROR: No error 47 * @return M4ERR_PARAMETER: The context is null 48 ************************************************************************ 49 */ 50M4OSA_ERR M4MCS_clearInterfaceTables(M4MCS_Context pContext) 51{ 52 M4MCS_InternalContext* pC = (M4MCS_InternalContext*)pContext; 53 M4OSA_UInt8 i; 54 55 M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER, "invalid context pointer"); 56 57 /* Initialisation that will allow to check if registering twice */ 58 pC->pWriterGlobalFcts = M4OSA_NULL; 59 pC->pWriterDataFcts = M4OSA_NULL; 60 pC->pVideoEncoderGlobalFcts = M4OSA_NULL; 61 pC->pAudioEncoderGlobalFcts = M4OSA_NULL; 62 63 pC->pCurrentVideoEncoderExternalAPI = M4OSA_NULL; 64 pC->pCurrentVideoEncoderUserData = M4OSA_NULL; 65 66 for (i = 0; i < M4WRITER_kType_NB; i++ ) 67 { 68 pC->WriterInterface[i].pGlobalFcts = M4OSA_NULL; 69 pC->WriterInterface[i].pDataFcts = M4OSA_NULL; 70 } 71 72 for (i = 0; i < M4ENCODER_kVideo_NB; i++ ) 73 { 74 pC->pVideoEncoderInterface[i] = M4OSA_NULL; 75 pC->pVideoEncoderExternalAPITable[i] = M4OSA_NULL; 76 pC->pVideoEncoderUserDataTable[i] = M4OSA_NULL; 77 } 78 79 for (i = 0; i < M4ENCODER_kAudio_NB; i++ ) 80 { 81 pC->pAudioEncoderInterface[i] = M4OSA_NULL; 82 pC->pAudioEncoderFlag[i] = M4OSA_FALSE; 83 pC->pAudioEncoderUserDataTable[i] = M4OSA_NULL; 84 } 85 86 /* Initialisation that will allow to check if registering twice */ 87 pC->m_pReader = M4OSA_NULL; 88 pC->m_pReaderDataIt = M4OSA_NULL; 89 pC->m_uiNbRegisteredReaders = 0; 90 91 for (i = 0; i < M4READER_kMediaType_NB; i++ ) 92 { 93 pC->m_pReaderGlobalItTable[i] = M4OSA_NULL; 94 pC->m_pReaderDataItTable[i] = M4OSA_NULL; 95 } 96 97 pC->m_pVideoDecoder = M4OSA_NULL; 98#ifdef M4VSS_ENABLE_EXTERNAL_DECODERS 99 pC->m_pCurrentVideoDecoderUserData = M4OSA_NULL; 100#endif /* M4VSS_ENABLE_EXTERNAL_DECODERS */ 101 pC->m_uiNbRegisteredVideoDec = 0; 102 for (i = 0; i < M4DECODER_kVideoType_NB; i++ ) 103 { 104 pC->m_pVideoDecoderItTable[i] = M4OSA_NULL; 105#ifdef M4VSS_ENABLE_EXTERNAL_DECODERS 106 pC->m_pVideoDecoderUserDataTable[i] = M4OSA_NULL; 107#endif /* M4VSS_ENABLE_EXTERNAL_DECODERS */ 108 } 109 110 pC->m_pAudioDecoder = M4OSA_NULL; 111 for (i = 0; i < M4AD_kType_NB; i++ ) 112 { 113 pC->m_pAudioDecoderItTable[i] = M4OSA_NULL; 114 pC->m_pAudioDecoderFlagTable[i] = M4OSA_FALSE; 115 pC->m_pAudioDecoderUserDataTable[i] = M4OSA_NULL; 116 } 117 118 return M4NO_ERROR; 119} 120 121/** 122 ****************************************************************************** 123 * M4OSA_ERR M4MCS_registerWriter() 124 * @brief This function will register a specific file format writer. 125 * @note According to the Mediatype, this function will store in the internal context 126 * the writer context. 127 * @param pContext: (IN) Execution context. 128 * @return M4NO_ERROR: there is no error 129 * @return M4ERR_PARAMETER pContext,pWtrGlobalInterface or 130 * pWtrDataInterface is M4OSA_NULL 131 * (debug only), or invalid MediaType 132 ****************************************************************************** 133 */ 134M4OSA_ERR M4MCS_registerWriter(M4MCS_Context pContext, M4WRITER_OutputFileType MediaType, 135 M4WRITER_GlobalInterface* pWtrGlobalInterface, 136 M4WRITER_DataInterface* pWtrDataInterface) 137{ 138 M4MCS_InternalContext* pC = (M4MCS_InternalContext*)pContext; 139 140 /** 141 * Check input parameters */ 142 M4OSA_DEBUG_IF2((pC == M4OSA_NULL),M4ERR_PARAMETER, 143 "MCS: context is M4OSA_NULL in M4MCS_registerWriter"); 144 M4OSA_DEBUG_IF2((pWtrGlobalInterface == M4OSA_NULL),M4ERR_PARAMETER, 145 "pWtrGlobalInterface is M4OSA_NULL in M4MCS_registerWriter"); 146 M4OSA_DEBUG_IF2((pWtrDataInterface == M4OSA_NULL),M4ERR_PARAMETER, 147 "pWtrDataInterface is M4OSA_NULL in M4MCS_registerWriter"); 148 149 M4OSA_TRACE3_3("MCS: M4MCS_registerWriter called with pContext=0x%x,\ 150 pWtrGlobalInterface=0x%x, pWtrDataInterface=0x%x", pC,pWtrGlobalInterface, 151 pWtrDataInterface); 152 153 if((MediaType == M4WRITER_kUnknown) || (MediaType >= M4WRITER_kType_NB)) 154 { 155 M4OSA_DEBUG_IF1(M4OSA_TRUE, M4ERR_PARAMETER, "Invalid media type"); 156 return M4ERR_PARAMETER; 157 } 158 159 if (pC->WriterInterface[MediaType].pGlobalFcts != M4OSA_NULL) 160 { 161 /* a writer corresponding to this media type has already been registered !*/ 162 M4OSA_DEBUG_IF1(M4OSA_TRUE, M4ERR_PARAMETER, "This media type has already been registered"); 163 return M4ERR_PARAMETER; 164 } 165 166 /* 167 * Save writer interface in context */ 168 pC->WriterInterface[MediaType].pGlobalFcts = pWtrGlobalInterface; 169 pC->WriterInterface[MediaType].pDataFcts = pWtrDataInterface; 170 171 return M4NO_ERROR; 172} 173 174/** 175 ****************************************************************************** 176 * M4OSA_ERR M4MCS_registerEncoder() 177 * @brief This function will register a specific video encoder. 178 * @note According to the Mediatype, this function will store in the internal context 179 * the encoder context. 180 * @param pContext: (IN) Execution context. 181 * @return M4NO_ERROR: there is no error 182 * @return M4ERR_PARAMETER pContext or pEncGlobalInterface is M4OSA_NULL (debug only), 183 * or invalid MediaType 184 ****************************************************************************** 185 */ 186M4OSA_ERR M4MCS_registerVideoEncoder ( 187 M4MCS_Context pContext, 188 M4ENCODER_Format MediaType, 189 M4ENCODER_GlobalInterface *pEncGlobalInterface) 190{ 191 M4MCS_InternalContext* pC = (M4MCS_InternalContext*)pContext; 192 193 /** 194 * Check input parameters */ 195 M4OSA_DEBUG_IF2((pC == M4OSA_NULL),M4ERR_PARAMETER, 196 "MCS: context is M4OSA_NULL in M4MCS_registerVideoEncoder"); 197 M4OSA_DEBUG_IF2((pEncGlobalInterface == M4OSA_NULL),M4ERR_PARAMETER, 198 "pEncGlobalInterface is M4OSA_NULL in M4MCS_registerVideoEncoder"); 199 200 M4OSA_TRACE3_2("MCS: M4MCS_registerVideoEncoder called with pContext=0x%x,\ 201 pEncGlobalInterface=0x%x", pC, pEncGlobalInterface); 202 203 if (MediaType >= M4ENCODER_kVideo_NB) 204 { 205 M4OSA_DEBUG_IF1(M4OSA_TRUE, M4ERR_PARAMETER, "Invalid video encoder type"); 206 return M4ERR_PARAMETER; 207 } 208 209 if (pC->pVideoEncoderInterface[MediaType] != M4OSA_NULL) 210 { 211 /* can be legitimate, in cases where we have one version that can use external encoders 212 but which still has the built-in one to be able to work without an external encoder; in 213 this case the new encoder simply replaces the old one (i.e. we unregister it first). */ 214 M4OSA_free((M4OSA_MemAddr32)pC->pVideoEncoderInterface[MediaType]); 215 pC->pVideoEncoderInterface[MediaType] = M4OSA_NULL; 216 } 217 218 /* 219 * Save encoder interface in context */ 220 pC->pVideoEncoderInterface[MediaType] = pEncGlobalInterface; 221 /* The actual userData and external API will be set by the registration function in the case 222 of an external encoder (add it as a parameter to this function in the long run?) */ 223 pC->pVideoEncoderUserDataTable[MediaType] = M4OSA_NULL; 224 pC->pVideoEncoderExternalAPITable[MediaType] = M4OSA_NULL; 225 226 return M4NO_ERROR; 227} 228 229/** 230 ****************************************************************************** 231 * M4OSA_ERR M4MCS_registerAudioEncoder() 232 * @brief This function will register a specific audio encoder. 233 * @note According to the Mediatype, this function will store in the internal context 234 * the encoder context. 235 * @param pContext: (IN) Execution context. 236 * @param mediaType: (IN) The media type. 237 * @param pEncGlobalInterface: (OUT) the encoder interface functions. 238 * @return M4NO_ERROR: there is no error 239 * @return M4ERR_PARAMETER: pContext or pEncGlobalInterface is 240 * M4OSA_NULL (debug only) 241 ****************************************************************************** 242 */ 243M4OSA_ERR M4MCS_registerAudioEncoder( 244 M4MCS_Context pContext, 245 M4ENCODER_AudioFormat MediaType, 246 M4ENCODER_AudioGlobalInterface *pEncGlobalInterface) 247{ 248 M4MCS_InternalContext* pC = (M4MCS_InternalContext*)pContext; 249 250 /** 251 * Check input parameters */ 252 M4OSA_DEBUG_IF2((pC == M4OSA_NULL),M4ERR_PARAMETER, 253 "MCS: context is M4OSA_NULL in M4MCS_registerAudioEncoder"); 254 M4OSA_DEBUG_IF2((pEncGlobalInterface == M4OSA_NULL),M4ERR_PARAMETER, 255 "pEncGlobalInterface is M4OSA_NULL in M4MCS_registerAudioEncoder"); 256 257 M4OSA_TRACE3_2("MCS: M4MCS_registerAudioEncoder called with pContext=0x%x,\ 258 pEncGlobalInterface=0x%x", pC, pEncGlobalInterface); 259 260 if (MediaType >= M4ENCODER_kAudio_NB) 261 { 262 M4OSA_DEBUG_IF1(M4OSA_TRUE, M4ERR_PARAMETER, "Invalid audio encoder type"); 263 return M4ERR_PARAMETER; 264 } 265 266 if(M4OSA_NULL != pC->pAudioEncoderInterface[MediaType]) 267 { 268 M4OSA_free((M4OSA_MemAddr32)pC->pAudioEncoderInterface[MediaType]); 269 pC->pAudioEncoderInterface[MediaType] = M4OSA_NULL; 270 271 if(M4OSA_NULL != pC->pAudioEncoderUserDataTable[MediaType]) 272 { 273 M4OSA_free((M4OSA_MemAddr32)pC->pAudioEncoderUserDataTable[MediaType]); 274 pC->pAudioEncoderUserDataTable[MediaType] = M4OSA_NULL; 275 } 276 } 277 278 /* 279 * Save encoder interface in context */ 280 pC->pAudioEncoderInterface[MediaType] = pEncGlobalInterface; 281 pC->pAudioEncoderFlag[MediaType] = M4OSA_FALSE; /* internal encoder */ 282 283 return M4NO_ERROR; 284} 285 286/** 287 ************************************************************************ 288 * M4OSA_ERR M4MCS_registerReader() 289 * @brief Register reader. 290 * @param pContext (IN/OUT) MCS context. 291 * @return M4NO_ERROR: No error 292 * @return M4ERR_PARAMETER: A parameter is null (in DEBUG only) 293 ************************************************************************ 294 */ 295M4OSA_ERR M4MCS_registerReader( 296 M4MCS_Context pContext, 297 M4READER_MediaType mediaType, 298 M4READER_GlobalInterface *pRdrGlobalInterface, 299 M4READER_DataInterface *pRdrDataInterface) 300{ 301 M4MCS_InternalContext* pC = (M4MCS_InternalContext*)pContext; 302 303 M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER, "invalid context pointer"); 304 M4OSA_DEBUG_IF1((M4OSA_NULL == pRdrGlobalInterface), 305 M4ERR_PARAMETER, "M4MCS_registerReader: invalid pointer on global interface"); 306 M4OSA_DEBUG_IF1((M4OSA_NULL == pRdrDataInterface), 307 M4ERR_PARAMETER, "M4MCS_registerReader: invalid pointer on data interface"); 308 309 if (mediaType == M4READER_kMediaTypeUnknown || mediaType >= M4READER_kMediaType_NB) 310 { 311 M4OSA_DEBUG_IF1(M4OSA_TRUE, M4ERR_PARAMETER, "Invalid media type"); 312 return M4ERR_PARAMETER; 313 } 314 315 if (pC->m_pReaderGlobalItTable[mediaType] != M4OSA_NULL) 316 { 317 /* a reader corresponding to this media type has already been registered !*/ 318 M4OSA_DEBUG_IF1(M4OSA_TRUE, M4ERR_PARAMETER, "This media type has already been registered"); 319 return M4ERR_PARAMETER; 320 } 321 322 pC->m_pReaderGlobalItTable[mediaType] = pRdrGlobalInterface; 323 pC->m_pReaderDataItTable[mediaType] = pRdrDataInterface; 324 325 pC->m_uiNbRegisteredReaders++; 326 327 return M4NO_ERROR; 328} 329 330/** 331 ************************************************************************ 332 * M4OSA_ERR M4MCS_registerVideoDecoder() 333 * @brief Register video decoder 334 * @param pContext (IN/OUT) MCS context. 335 * @param decoderType (IN) Decoder type 336 * @param pDecoderInterface (IN) Decoder interface. 337 * @return M4NO_ERROR: No error 338 * @return M4ERR_PARAMETER: A parameter is null (in DEBUG only), or the decoder 339 * type is invalid 340 ************************************************************************ 341 */ 342M4OSA_ERR M4MCS_registerVideoDecoder( 343 M4MCS_Context pContext, 344 M4DECODER_VideoType decoderType, 345 M4DECODER_VideoInterface *pDecoderInterface) 346{ 347 M4MCS_InternalContext* pC = (M4MCS_InternalContext*)pContext; 348 349 M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER, "invalid context pointer"); 350 M4OSA_DEBUG_IF1((M4OSA_NULL == pDecoderInterface), M4ERR_PARAMETER, 351 "M4MCS_registerVideoDecoder: invalid pointer on decoder interface"); 352 353 if (decoderType >= M4DECODER_kVideoType_NB) 354 { 355 M4OSA_DEBUG_IF1(M4OSA_TRUE, M4ERR_PARAMETER, "Invalid video decoder type"); 356 return M4ERR_PARAMETER; 357 } 358 359 if (pC->m_pVideoDecoderItTable[decoderType] != M4OSA_NULL) 360 { 361#ifndef M4VSS_ENABLE_EXTERNAL_DECODERS 362 /* a decoder corresponding to this media type has already been registered !*/ 363 M4OSA_DEBUG_IF1(M4OSA_TRUE, M4ERR_PARAMETER, "Decoder has already been registered"); 364 return M4ERR_PARAMETER; 365#else /* external decoders are possible */ 366 /* can be legitimate, in cases where we have one version that can use external decoders 367 but which still has the built-in one to be able to work without an external decoder; in 368 this case the new decoder simply replaces the old one (i.e. we unregister it first). */ 369 M4OSA_free((M4OSA_MemAddr32)pC->m_pVideoDecoderItTable[decoderType]); 370 pC->m_pVideoDecoderItTable[decoderType] = M4OSA_NULL; 371 /* oh, and don't forget the user data, too. */ 372 if (pC->m_pVideoDecoderUserDataTable[decoderType] != M4OSA_NULL) 373 { 374 M4OSA_free((M4OSA_MemAddr32)pC->m_pVideoDecoderUserDataTable[decoderType]); 375 pC->m_pVideoDecoderUserDataTable[decoderType] = M4OSA_NULL; 376 } 377#endif /* are external decoders possible? */ 378 } 379 380 pC->m_pVideoDecoderItTable[decoderType] = pDecoderInterface; 381#ifdef M4VSS_ENABLE_EXTERNAL_DECODERS 382 pC->m_pVideoDecoderUserDataTable[decoderType] = M4OSA_NULL; 383 /* The actual userData will be set by the registration function in the case 384 of an external decoder (add it as a parameter to this function in the long run?) */ 385#endif /* M4VSS_ENABLE_EXTERNAL_DECODERS */ 386 pC->m_uiNbRegisteredVideoDec++; 387 388 return M4NO_ERROR; 389} 390 391/** 392 ************************************************************************ 393 * M4OSA_ERR M4MCS_registerAudioDecoder() 394 * @brief Register audio decoder 395 * @note This function is used internaly by the MCS to 396 * register audio decoders, 397 * @param context (IN/OUT) MCS context. 398 * @param decoderType (IN) Audio decoder type 399 * @param pDecoderInterface (IN) Audio decoder interface. 400 * @return M4NO_ERROR: No error 401 * @return M4ERR_PARAMETER: A parameter is null, or the decoder type is invalid(in DEBUG only) 402 ************************************************************************ 403 */ 404M4OSA_ERR M4MCS_registerAudioDecoder( 405 M4MCS_Context pContext, 406 M4AD_Type decoderType, 407 M4AD_Interface *pDecoderInterface) 408{ 409 M4MCS_InternalContext* pC = (M4MCS_InternalContext*)pContext; 410 411 M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER, "invalid context pointer"); 412 M4OSA_DEBUG_IF1((M4OSA_NULL == pDecoderInterface), M4ERR_PARAMETER, 413 "M4MCS_registerAudioDecoder: invalid pointer on decoder interface"); 414 415 if (decoderType >= M4AD_kType_NB) 416 { 417 M4OSA_DEBUG_IF1(M4OSA_TRUE, M4ERR_PARAMETER, "Invalid audio decoder type"); 418 return M4ERR_PARAMETER; 419 } 420 421 if(M4OSA_NULL != pC->m_pAudioDecoderItTable[decoderType]) 422 { 423 M4OSA_free((M4OSA_MemAddr32)pC->m_pAudioDecoderItTable[decoderType]); 424 pC->m_pAudioDecoderItTable[decoderType] = M4OSA_NULL; 425 426 if(M4OSA_NULL != pC->m_pAudioDecoderUserDataTable[decoderType]) 427 { 428 M4OSA_free((M4OSA_MemAddr32)pC->m_pAudioDecoderUserDataTable[decoderType]); 429 pC->m_pAudioDecoderUserDataTable[decoderType] = M4OSA_NULL; 430 } 431 } 432 pC->m_pAudioDecoderItTable[decoderType] = pDecoderInterface; 433 pC->m_pAudioDecoderFlagTable[decoderType] = M4OSA_FALSE; /* internal decoder */ 434 435 return M4NO_ERROR; 436} 437 438/** 439 ************************************************************************ 440 * M4OSA_ERR M4MCS_unRegisterAllWriters() 441 * @brief Unregister writer 442 * @param pContext (IN/OUT) MCS context. 443 * @return M4NO_ERROR: No error 444 * @return M4ERR_PARAMETER: A parameter is null (in DEBUG only) 445 ************************************************************************ 446 */ 447M4OSA_ERR M4MCS_unRegisterAllWriters(M4MCS_Context pContext) 448{ 449 M4MCS_InternalContext* pC = (M4MCS_InternalContext*)pContext; 450 M4OSA_Int32 i; 451 452 M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER, "invalid context pointer"); 453 454 for (i = 0; i < M4WRITER_kType_NB; i++) 455 { 456 if (pC->WriterInterface[i].pGlobalFcts != M4OSA_NULL) 457 { 458 M4OSA_free((M4OSA_MemAddr32)pC->WriterInterface[i].pGlobalFcts ); 459 pC->WriterInterface[i].pGlobalFcts = M4OSA_NULL; 460 } 461 if (pC->WriterInterface[i].pDataFcts != M4OSA_NULL) 462 { 463 M4OSA_free((M4OSA_MemAddr32)pC->WriterInterface[i].pDataFcts ); 464 pC->WriterInterface[i].pDataFcts = M4OSA_NULL; 465 } 466 } 467 468 pC->pWriterGlobalFcts = M4OSA_NULL; 469 pC->pWriterDataFcts = M4OSA_NULL; 470 471 return M4NO_ERROR; 472} 473 474/** 475 ************************************************************************ 476 * M4OSA_ERR M4MCS_unRegisterAllEncoders() 477 * @brief Unregister the encoders 478 * @param pContext (IN/OUT) MCS context. 479 * @return M4NO_ERROR: No error 480 * @return M4ERR_PARAMETER: A parameter is null (in DEBUG only) 481 ************************************************************************ 482 */ 483M4OSA_ERR M4MCS_unRegisterAllEncoders(M4MCS_Context pContext) 484{ 485 M4MCS_InternalContext* pC = (M4MCS_InternalContext*)pContext; 486 M4OSA_Int32 i; 487 488 M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER, "invalid context pointer"); 489 490 for (i = 0; i < M4ENCODER_kVideo_NB; i++) 491 { 492 if (pC->pVideoEncoderInterface[i] != M4OSA_NULL) 493 { 494 M4OSA_free( (M4OSA_MemAddr32)pC->pVideoEncoderInterface[i] ); 495 pC->pVideoEncoderInterface[i] = M4OSA_NULL; 496 } 497 } 498 499 for (i = 0; i < M4ENCODER_kAudio_NB; i++) 500 { 501 if (pC->pAudioEncoderInterface[i] != M4OSA_NULL) 502 { 503 /*Don't free external audio encoders interfaces*/ 504 if (M4OSA_FALSE == pC->pAudioEncoderFlag[i]) 505 { 506 M4OSA_free( (M4OSA_MemAddr32)pC->pAudioEncoderInterface[i] ); 507 } 508 pC->pAudioEncoderInterface[i] = M4OSA_NULL; 509 } 510 } 511 512 pC->pVideoEncoderGlobalFcts = M4OSA_NULL; 513 pC->pAudioEncoderGlobalFcts = M4OSA_NULL; 514 515 return M4NO_ERROR; 516} 517 518/** 519 ************************************************************************ 520 * M4OSA_ERR M4MCS_unRegisterAllReaders() 521 * @brief Unregister reader 522 * @param pContext (IN/OUT) MCS context. 523 * @return M4NO_ERROR: No error 524 * @return M4ERR_PARAMETER: A parameter is null (in DEBUG only) 525 ************************************************************************ 526 */ 527M4OSA_ERR M4MCS_unRegisterAllReaders(M4MCS_Context pContext) 528{ 529 M4MCS_InternalContext* pC = (M4MCS_InternalContext*)pContext; 530 M4OSA_Int32 i; 531 532 M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER, "invalid context pointer"); 533 534 for (i = 0; i < M4READER_kMediaType_NB; i++) 535 { 536 if (pC->m_pReaderGlobalItTable[i] != M4OSA_NULL) 537 { 538 M4OSA_free((M4OSA_MemAddr32)pC->m_pReaderGlobalItTable[i] ); 539 pC->m_pReaderGlobalItTable[i] = M4OSA_NULL; 540 } 541 if (pC->m_pReaderDataItTable[i] != M4OSA_NULL) 542 { 543 M4OSA_free((M4OSA_MemAddr32)pC->m_pReaderDataItTable[i] ); 544 pC->m_pReaderDataItTable[i] = M4OSA_NULL; 545 } 546 } 547 548 pC->m_uiNbRegisteredReaders = 0; 549 pC->m_pReader = M4OSA_NULL; 550 pC->m_pReaderDataIt = M4OSA_NULL; 551 552 return M4NO_ERROR; 553} 554 555/** 556 ************************************************************************ 557 * M4OSA_ERR M4MCS_unRegisterAllDecoders() 558 * @brief Unregister the decoders 559 * @param pContext (IN/OUT) MCS context. 560 * @return M4NO_ERROR: No error 561 * @return M4ERR_PARAMETER: A parameter is null (in DEBUG only) 562 ************************************************************************ 563 */ 564M4OSA_ERR M4MCS_unRegisterAllDecoders(M4MCS_Context pContext) 565{ 566 M4MCS_InternalContext* pC = (M4MCS_InternalContext*)pContext; 567 M4OSA_Int32 i; 568 569 M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER, "invalid context pointer"); 570 571 for (i = 0; i < M4DECODER_kVideoType_NB; i++) 572 { 573 if (pC->m_pVideoDecoderItTable[i] != M4OSA_NULL) 574 { 575 M4OSA_free( (M4OSA_MemAddr32)pC->m_pVideoDecoderItTable[i] ); 576 pC->m_pVideoDecoderItTable[i] = M4OSA_NULL; 577 } 578 } 579 580 for (i = 0; i < M4AD_kType_NB; i++) 581 { 582 if (pC->m_pAudioDecoderItTable[i] != M4OSA_NULL) 583 { 584 /*Don't free external audio decoders interfaces*/ 585 if (M4OSA_FALSE == pC->m_pAudioDecoderFlagTable[i]) 586 { 587 M4OSA_free( (M4OSA_MemAddr32)pC->m_pAudioDecoderItTable[i] ); 588 } 589 pC->m_pAudioDecoderItTable[i] = M4OSA_NULL; 590 } 591 } 592 593 pC->m_uiNbRegisteredVideoDec = 0; 594 pC->m_pVideoDecoder = M4OSA_NULL; 595 596 pC->m_pAudioDecoder = M4OSA_NULL; 597 598 return M4NO_ERROR; 599} 600 601/** 602 ************************************************************************ 603 * M4OSA_ERR M4MCS_setCurrentWriter() 604 * @brief Set current writer 605 * @param pContext (IN/OUT) MCS context. 606 * @param mediaType (IN) Media type. 607 * @return M4NO_ERROR: No error 608 * @return M4ERR_PARAMETER: A parameter is null (in DEBUG only) 609 * @return M4WAR_MCS_MEDIATYPE_NOT_SUPPORTED: Media type not supported 610 ************************************************************************ 611 */ 612M4OSA_ERR M4MCS_setCurrentWriter( M4MCS_Context pContext, 613 M4VIDEOEDITING_FileType mediaType) 614{ 615 M4MCS_InternalContext* pC = (M4MCS_InternalContext*)pContext; 616 M4WRITER_OutputFileType writerType; 617 618 M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER, "invalid context pointer"); 619 620 switch (mediaType) 621 { 622 case M4VIDEOEDITING_kFileType_3GPP: 623 case M4VIDEOEDITING_kFileType_MP4: 624 writerType = M4WRITER_k3GPP; 625 break; 626 case M4VIDEOEDITING_kFileType_AMR: 627 writerType = M4WRITER_kAMR; 628 break; 629 case M4VIDEOEDITING_kFileType_MP3: 630 writerType = M4WRITER_kMP3; 631 break; 632 case M4VIDEOEDITING_kFileType_PCM: 633 pC->b_isRawWriter = M4OSA_TRUE; 634 writerType = M4WRITER_kPCM; 635 break; 636 default: 637 M4OSA_DEBUG_IF1(M4OSA_TRUE, M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED, 638 "Writer type not supported"); 639 return M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED; 640 } 641 642 pC->pWriterGlobalFcts = pC->WriterInterface[writerType].pGlobalFcts; 643 pC->pWriterDataFcts = pC->WriterInterface[writerType].pDataFcts; 644 645 if (pC->pWriterGlobalFcts == M4OSA_NULL || pC->pWriterDataFcts == M4OSA_NULL) 646 { 647 M4OSA_DEBUG_IF1(M4OSA_TRUE, M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED, 648 "Writer type not supported"); 649 return M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED; 650 } 651 652 pC->pWriterDataFcts->pWriterContext = M4OSA_NULL; 653 654 return M4NO_ERROR; 655} 656 657/** 658 ************************************************************************ 659 * M4OSA_ERR M4MCS_setCurrentVideoEncoder() 660 * @brief Set a video encoder 661 * @param pContext (IN/OUT) MCS context. 662 * @param MediaType (IN) Encoder type 663 * @return M4NO_ERROR: No error 664 * @return M4ERR_PARAMETER: A parameter is null (in DEBUG only) 665 * @return M4WAR_MCS_MEDIATYPE_NOT_SUPPORTED: Media type not supported 666 ************************************************************************ 667 */ 668M4OSA_ERR M4MCS_setCurrentVideoEncoder( 669 M4MCS_Context pContext, 670 M4VIDEOEDITING_VideoFormat mediaType) 671{ 672 M4MCS_InternalContext* pC = (M4MCS_InternalContext*)pContext; 673 M4ENCODER_Format encoderType; 674 675 M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER, "invalid context pointer"); 676 677 switch (mediaType) 678 { 679 case M4VIDEOEDITING_kH263: 680 encoderType = M4ENCODER_kH263; 681 break; 682 case M4VIDEOEDITING_kMPEG4: 683 case M4VIDEOEDITING_kMPEG4_EMP: 684 encoderType = M4ENCODER_kMPEG4; 685 break; 686 case M4VIDEOEDITING_kH264: 687#ifdef M4VSS_SUPPORT_ENCODER_AVC 688 encoderType = M4ENCODER_kH264; 689 break; 690#endif 691 default: 692 M4OSA_DEBUG_IF1(M4OSA_TRUE, M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED, 693 "Video encoder type not supported"); 694 return M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED; 695 } 696 697 pC->pVideoEncoderGlobalFcts = pC->pVideoEncoderInterface[encoderType]; 698 pC->pCurrentVideoEncoderExternalAPI = pC->pVideoEncoderExternalAPITable[encoderType]; 699 pC->pCurrentVideoEncoderUserData = pC->pVideoEncoderUserDataTable[encoderType]; 700 701 if (pC->pVideoEncoderGlobalFcts == M4OSA_NULL) 702 { 703 M4OSA_DEBUG_IF1(M4OSA_TRUE, M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED, 704 "Video encoder type not supported"); 705 return M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED; 706 } 707 708 return M4NO_ERROR; 709} 710 711/** 712 ************************************************************************ 713 * M4OSA_ERR M4MCS_setCurrentAudioEncoder() 714 * @brief Set an audio encoder 715 * @param context (IN/OUT) MCS context. 716 * @param MediaType (IN) Encoder type 717 * @return M4NO_ERROR: No error 718 * @return M4ERR_PARAMETER: A parameter is null (in DEBUG only) 719 ************************************************************************ 720 */ 721M4OSA_ERR M4MCS_setCurrentAudioEncoder( 722 M4MCS_Context pContext, 723 M4VIDEOEDITING_AudioFormat mediaType) 724{ 725 M4MCS_InternalContext* pC = (M4MCS_InternalContext*)pContext; 726 M4ENCODER_AudioFormat encoderType; 727 728 M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER, "invalid context pointer"); 729 730 switch (mediaType) 731 { 732 case M4VIDEOEDITING_kAMR_NB: 733 encoderType = M4ENCODER_kAMRNB; 734 break; 735 case M4VIDEOEDITING_kAAC: 736 encoderType = M4ENCODER_kAAC; 737 break; 738 case M4VIDEOEDITING_kMP3: 739 encoderType = M4ENCODER_kMP3; 740 break; 741//EVRC 742// case M4VIDEOEDITING_kEVRC: 743// encoderType = M4ENCODER_kEVRC; 744// break; 745 default: 746 M4OSA_DEBUG_IF1(M4OSA_TRUE, M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED, 747 "Audio encoder type not supported"); 748 return M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED; 749 } 750 751 pC->pAudioEncoderGlobalFcts = pC->pAudioEncoderInterface[encoderType]; 752 pC->pCurrentAudioEncoderUserData = pC->pAudioEncoderUserDataTable[encoderType]; 753 754 if (pC->pAudioEncoderGlobalFcts == M4OSA_NULL) 755 { 756 M4OSA_DEBUG_IF1(M4OSA_TRUE, M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED, 757 "Audio encoder type not supported"); 758 return M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED; 759 } 760 761 return M4NO_ERROR; 762} 763 764/** 765 ************************************************************************ 766 * M4OSA_ERR M4MCS_setCurrentReader() 767 * @brief Set current reader 768 * @param pContext (IN/OUT) MCS context. 769 * @param mediaType (IN) Media type. 770 * @return M4NO_ERROR: No error 771 * @return M4ERR_PARAMETER: A parameter is null (in DEBUG only) 772 * @return M4WAR_MCS_MEDIATYPE_NOT_SUPPORTED: Media type not supported 773 ************************************************************************ 774 */ 775M4OSA_ERR M4MCS_setCurrentReader( M4MCS_Context pContext, 776 M4VIDEOEDITING_FileType mediaType) 777{ 778 M4MCS_InternalContext* pC = (M4MCS_InternalContext*)pContext; 779 M4READER_MediaType readerType; 780 781 M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER, "invalid context pointer"); 782 783 switch (mediaType) 784 { 785 case M4VIDEOEDITING_kFileType_3GPP: 786 case M4VIDEOEDITING_kFileType_MP4: 787 readerType = M4READER_kMediaType3GPP; 788 break; 789 case M4VIDEOEDITING_kFileType_AMR: 790 readerType = M4READER_kMediaTypeAMR; 791 break; 792 case M4VIDEOEDITING_kFileType_MP3: 793 readerType = M4READER_kMediaTypeMP3; 794 break; 795 default: 796 M4OSA_DEBUG_IF1(M4OSA_TRUE, M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED, 797 "Reader type not supported"); 798 return M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED; 799 } 800 801 pC->m_pReader = pC->m_pReaderGlobalItTable[readerType]; 802 pC->m_pReaderDataIt = pC->m_pReaderDataItTable[readerType]; 803 804 if (pC->m_pReader == M4OSA_NULL || pC->m_pReaderDataIt == M4OSA_NULL) 805 { 806 M4OSA_DEBUG_IF1(M4OSA_TRUE, M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED, 807 "Reader type not supported"); 808 return M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED; 809 } 810 return M4NO_ERROR; 811} 812 813/** 814 ************************************************************************ 815 * M4OSA_ERR M4MCS_setCurrentVideoDecoder() 816 * @brief Set a video decoder 817 * @param pContext (IN/OUT) MCS context. 818 * @param decoderType (IN) Decoder type 819 * @return M4NO_ERROR: No error 820 * @return M4ERR_PARAMETER: A parameter is null (in DEBUG only) 821 * @return M4WAR_MCS_MEDIATYPE_NOT_SUPPORTED: Media type not supported 822 ************************************************************************ 823 */ 824M4OSA_ERR M4MCS_setCurrentVideoDecoder( M4MCS_Context pContext, 825 M4_StreamType mediaType) 826{ 827 M4MCS_InternalContext* pC = (M4MCS_InternalContext*)pContext; 828 M4DECODER_VideoType decoderType; 829 830 M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER, "invalid context pointer"); 831 832 switch (mediaType) 833 { 834 case M4DA_StreamTypeVideoMpeg4: 835 case M4DA_StreamTypeVideoH263: 836 decoderType = M4DECODER_kVideoTypeMPEG4; 837 break; 838 case M4DA_StreamTypeVideoMpeg4Avc: 839 decoderType = M4DECODER_kVideoTypeAVC; 840 break; 841 default: 842 M4OSA_DEBUG_IF1(M4OSA_TRUE, M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED, 843 "Video decoder type not supported"); 844 return M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED; 845 } 846 847 pC->m_pVideoDecoder = pC->m_pVideoDecoderItTable[decoderType]; 848#ifdef M4VSS_ENABLE_EXTERNAL_DECODERS 849 pC->m_pCurrentVideoDecoderUserData = 850 pC->m_pVideoDecoderUserDataTable[decoderType]; 851#endif /* M4VSS_ENABLE_EXTERNAL_DECODERS */ 852 853 if (pC->m_pVideoDecoder == M4OSA_NULL) 854 { 855 M4OSA_DEBUG_IF1(M4OSA_TRUE, M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED, 856 "Video decoder type not supported"); 857 return M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED; 858 } 859 860 return M4NO_ERROR; 861} 862 863/** 864 ************************************************************************ 865 * M4OSA_ERR M4MCS_setCurrentAudioDecoder() 866 * @brief Set an audio decoder 867 * @param context (IN/OUT) MCS context. 868 * @param decoderType (IN) Decoder type 869 * @return M4NO_ERROR: No error 870 * @return M4ERR_PARAMETER: A parameter is null (in DEBUG only) 871 ************************************************************************ 872 */ 873M4OSA_ERR M4MCS_setCurrentAudioDecoder( M4MCS_Context pContext, 874 M4_StreamType mediaType) 875{ 876 M4MCS_InternalContext* pC = (M4MCS_InternalContext*)pContext; 877 M4AD_Type decoderType; 878 879 M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER, "invalid context pointer"); 880 881 switch (mediaType) 882 { 883 case M4DA_StreamTypeAudioAmrNarrowBand: 884 decoderType = M4AD_kTypeAMRNB; 885 break; 886 case M4DA_StreamTypeAudioAac: 887 case M4DA_StreamTypeAudioAacADTS: 888 case M4DA_StreamTypeAudioAacADIF: 889 decoderType = M4AD_kTypeAAC; 890 break; 891 case M4DA_StreamTypeAudioMp3: 892 decoderType = M4AD_kTypeMP3; 893 break; 894//EVRC 895// case M4DA_StreamTypeAudioEvrc: 896// decoderType = M4AD_kTypeEVRC; 897// break; 898 default: 899 M4OSA_DEBUG_IF1(M4OSA_TRUE, M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED, 900 "Audio decoder type not supported"); 901 return M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED; 902 } 903 904 pC->m_pAudioDecoder = pC->m_pAudioDecoderItTable[decoderType]; 905 pC->m_pCurrentAudioDecoderUserData = 906 pC->m_pAudioDecoderUserDataTable[decoderType]; 907 908 if (pC->m_pAudioDecoder == M4OSA_NULL) 909 { 910 M4OSA_DEBUG_IF1(M4OSA_TRUE, M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED, 911 "Audio decoder type not supported"); 912 return M4MCS_WAR_MEDIATYPE_NOT_SUPPORTED; 913 } 914 915 return M4NO_ERROR; 916} 917 918