1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 /** 17 ************************************************************************ 18 * @file M4MCS_MediaAndCodecSubscription.c 19 * @brief Media readers and codecs subscription 20 * @note This file implements the subscription of supported media 21 * readers and decoders for the MCS. Potential support can 22 * be activated or de-activated 23 * using compilation flags set in the projects settings. 24 ************************************************************************ 25 */ 26 27 /** 28 ******************************************************************** 29 * Includes 30 ******************************************************************** 31 */ 32 #include "NXPSW_CompilerSwitches.h" 33 34 35 #include "M4OSA_Debug.h" 36 #include "M4MCS_InternalTypes.h" /**< Include for MCS specific types */ 37 #include "M4MCS_InternalFunctions.h" /**< Registration module */ 38 39 /* _______________________ */ 40 /*| |*/ 41 /*| reader subscription |*/ 42 /*|_______________________|*/ 43 44 /* Reader registration : at least one reader must be defined */ 45 #ifndef M4VSS_SUPPORT_READER_3GP 46 #ifndef M4VSS_SUPPORT_READER_AMR 47 #ifndef M4VSS_SUPPORT_READER_MP3 48 #error "no reader registered" 49 #endif /* M4VSS_SUPPORT_READER_MP3 */ 50 #endif /* M4VSS_SUPPORT_READER_AMR */ 51 #endif /* M4VSS_SUPPORT_READER_3GP */ 52 53 /* Include files for each reader to subscribe */ 54 #ifdef M4VSS_SUPPORT_READER_3GP 55 #include "VideoEditor3gpReader.h" 56 #endif 57 58 #ifdef M4VSS_SUPPORT_READER_AMR 59 #include "M4READER_Amr.h" 60 #endif 61 #ifdef M4VSS_SUPPORT_READER_MP3 62 #include "VideoEditorMp3Reader.h" 63 #endif 64 65 /* ______________________________ */ 66 /*| |*/ 67 /*| video decoder subscription |*/ 68 /*|______________________________|*/ 69 70 #include "VideoEditorAudioDecoder.h" 71 #include "VideoEditorVideoDecoder.h" 72 73 74 75 /* _______________________ */ 76 /*| |*/ 77 /*| writer subscription |*/ 78 /*|_______________________|*/ 79 80 /* Writer registration : at least one writer must be defined */ 81 #ifndef M4VSS_SUPPORT_WRITER_AMR 82 #ifndef M4VSS_SUPPORT_WRITER_3GPP 83 #ifndef M4VSS_SUPPORT_WRITER_PCM 84 #ifndef M4VSS_SUPPORT_WRITER_MP3 85 #error "no writer registered" 86 #endif /* M4VSS_SUPPORT_WRITER_MP3 */ 87 #endif /* M4VSS_SUPPORT_WRITER_PCM */ 88 #endif /* M4VSS_SUPPORT_WRITER_3GPP */ 89 #endif /* M4VSS_SUPPORT_WRITER_AMR */ 90 91 /* Include files for each writer to subscribe */ 92 #ifdef M4VSS_SUPPORT_WRITER_AMR 93 extern M4OSA_ERR M4WRITER_AMR_getInterfaces( M4WRITER_OutputFileType* Type, 94 M4WRITER_GlobalInterface** SrcGlobalInterface, 95 M4WRITER_DataInterface** SrcDataInterface); 96 #endif 97 #ifdef M4VSS_SUPPORT_WRITER_3GPP 98 extern M4OSA_ERR M4WRITER_3GP_getInterfaces( M4WRITER_OutputFileType* Type, 99 M4WRITER_GlobalInterface** SrcGlobalInterface, 100 M4WRITER_DataInterface** SrcDataInterface); 101 #endif 102 #ifdef M4VSS_SUPPORT_WRITER_PCM 103 extern M4OSA_ERR M4WRITER_PCM_getInterfaces( M4WRITER_OutputFileType* Type, 104 M4WRITER_GlobalInterface** SrcGlobalInterface, 105 M4WRITER_DataInterface** SrcDataInterface); 106 #endif 107 #ifdef M4VSS_SUPPORT_WRITER_MP3 108 extern M4OSA_ERR M4WRITER_MP3_getInterfaces( M4WRITER_OutputFileType* Type, 109 M4WRITER_GlobalInterface** SrcGlobalInterface, 110 M4WRITER_DataInterface** SrcDataInterface); 111 #endif 112 113 /* ______________________________ */ 114 /*| |*/ 115 /*| video encoder subscription |*/ 116 /*|______________________________|*/ 117 #include "VideoEditorAudioEncoder.h" 118 #include "VideoEditorVideoEncoder.h" 119 120 121 /* Include files for each video encoder to subscribe */ 122 #ifdef M4VSS_SUPPORT_ENCODER_MPEG4 123 //#include "M4MP4E_interface.h" 124 #endif 125 126 127 #define M4ERR_CHECK_NULL_RETURN_VALUE(retval, pointer) \ 128 if ((pointer) == M4OSA_NULL) return ((M4OSA_ERR)(retval)); 129 130 /** 131 ****************************************************************************** 132 * M4OSA_ERR M4MCS_SubscribeMediaAndCodec(M4MCS_Context pContext); 133 * @brief This function registers the reader, decoders, writers and encoders 134 * in the MCS. 135 * @note 136 * @param pContext: (IN) Execution context. 137 * @return M4NO_ERROR: there is no error 138 * @return M4ERR_PARAMETER pContext is NULL 139 ****************************************************************************** 140 */ 141 M4OSA_ERR M4MCS_subscribeMediaAndCodec(M4MCS_Context pContext) 142 { 143 M4OSA_ERR err = M4NO_ERROR; 144 145 M4READER_MediaType readerMediaType; 146 M4READER_GlobalInterface* pReaderGlobalInterface; 147 M4READER_DataInterface* pReaderDataInterface; 148 149 M4WRITER_OutputFileType writerMediaType; 150 M4WRITER_GlobalInterface* pWriterGlobalInterface; 151 M4WRITER_DataInterface* pWriterDataInterface; 152 153 M4AD_Type audioDecoderType; 154 M4ENCODER_AudioFormat audioCodecType; 155 M4ENCODER_AudioGlobalInterface* pAudioCodecInterface; 156 M4AD_Interface* pAudioDecoderInterface; 157 158 M4DECODER_VideoType videoDecoderType; 159 M4ENCODER_Format videoCodecType; 160 M4ENCODER_GlobalInterface* pVideoCodecInterface; 161 M4DECODER_VideoInterface* pVideoDecoderInterface; 162 163 M4ERR_CHECK_NULL_RETURN_VALUE(M4ERR_PARAMETER, pContext); 164 165 /* _______________________ */ 166 /*| |*/ 167 /*| reader subscription |*/ 168 /*|_______________________|*/ 169 170 /* --- 3GP --- */ 171 172 #ifdef M4VSS_SUPPORT_READER_3GP 173 err = VideoEditor3gpReader_getInterface(&readerMediaType, 174 &pReaderGlobalInterface, 175 &pReaderDataInterface); 176 if (M4NO_ERROR != err) 177 { 178 M4OSA_TRACE1_0("M4READER_3GP interface allocation error"); 179 return err; 180 } 181 err = M4MCS_registerReader( pContext, readerMediaType, 182 pReaderGlobalInterface, 183 pReaderDataInterface); 184 M4OSA_DEBUG_IF1((err != M4NO_ERROR), err, 185 "M4MCS_subscribeMediaAndCodec: can't register 3GP reader"); 186 #endif /* M4VSS_SUPPORT_READER_3GP */ 187 188 /* --- AMR --- */ 189 190 #ifdef M4VSS_SUPPORT_READER_AMR 191 err = M4READER_AMR_getInterfaces( &readerMediaType, 192 &pReaderGlobalInterface, 193 &pReaderDataInterface); 194 if (M4NO_ERROR != err) 195 { 196 M4OSA_TRACE1_0("M4READER_AMR interface allocation error"); 197 return err; 198 } 199 err = M4MCS_registerReader( pContext, readerMediaType, 200 pReaderGlobalInterface, 201 pReaderDataInterface); 202 M4OSA_DEBUG_IF1((err != M4NO_ERROR), err, 203 "M4MCS_subscribeMediaAndCodec: can't register AMR reader"); 204 #endif /* M4VSS_SUPPORT_READER_AMR */ 205 206 /* --- MP3 --- */ 207 208 #ifdef M4VSS_SUPPORT_READER_MP3 209 210 err = VideoEditorMp3Reader_getInterface(&readerMediaType, 211 &pReaderGlobalInterface, 212 &pReaderDataInterface); 213 if (M4NO_ERROR != err) 214 { 215 M4OSA_TRACE1_0("M4READER_MP3 interface allocation error"); 216 return err; 217 } 218 err = M4MCS_registerReader( pContext, readerMediaType, 219 pReaderGlobalInterface, 220 pReaderDataInterface); 221 M4OSA_DEBUG_IF1((err != M4NO_ERROR), err, 222 "M4MCS_subscribeMediaAndCodec: can't register MP3 reader"); 223 #endif /* M4VSS_SUPPORT_READER_MP3 */ 224 225 /* ______________________________ */ 226 /*| |*/ 227 /*| video decoder subscription |*/ 228 /*|______________________________|*/ 229 230 /* --- MPEG4 & H263 --- */ 231 232 #ifdef M4VSS_SUPPORT_VIDEC_3GP 233 234 err = VideoEditorVideoDecoder_getInterface_MPEG4( &videoDecoderType, 235 (M4OSA_Void *)&pVideoDecoderInterface); 236 if (M4NO_ERROR != err) 237 { 238 M4OSA_TRACE1_0("M4DECODER_MPEG4 interface allocation error"); 239 return err; 240 } 241 err = M4MCS_registerVideoDecoder( pContext, videoDecoderType, 242 pVideoDecoderInterface); 243 M4OSA_DEBUG_IF1((err != M4NO_ERROR), err, 244 "M4MCS_subscribeMediaAndCodec: can't register MPEG4 decoder"); 245 #endif /* M4VSS_SUPPORT_VIDEC_3GP */ 246 247 248 #ifdef M4VSS_SUPPORT_VIDEO_AVC 249 250 err = VideoEditorVideoDecoder_getInterface_H264( &videoDecoderType, 251 (M4OSA_Void *)&pVideoDecoderInterface); 252 253 if (M4NO_ERROR != err) 254 { 255 M4OSA_TRACE1_0("M4DECODER_AVC interface allocation error"); 256 return err; 257 } 258 err = M4MCS_registerVideoDecoder( pContext, videoDecoderType, 259 pVideoDecoderInterface); 260 M4OSA_DEBUG_IF1((err != M4NO_ERROR), err, 261 "M4MCS_subscribeMediaAndCodec: can't register AVC decoder"); 262 #endif /* M4VSS_SUPPORT_VIDEO_AVC */ 263 264 265 /* ______________________________ */ 266 /*| |*/ 267 /*| audio decoder subscription |*/ 268 /*|______________________________|*/ 269 270 /* --- AMRNB --- */ 271 272 #ifdef M4VSS_SUPPORT_AUDEC_AMRNB 273 err = VideoEditorAudioDecoder_getInterface_AMRNB(&audioDecoderType, 274 &pAudioDecoderInterface); 275 if (M4NO_ERROR != err) 276 { 277 M4OSA_TRACE1_0("M4AD PHILIPS AMRNB interface allocation error"); 278 return err; 279 } 280 err = M4MCS_registerAudioDecoder( pContext, audioDecoderType, 281 pAudioDecoderInterface); 282 M4OSA_DEBUG_IF1((err != M4NO_ERROR), err, 283 "M4MCS_subscribeMediaAndCodec: can't register PHILIPS AMRNB decoder"); 284 #endif /* M4VSS_SUPPORT_AUDEC_AMRNB */ 285 286 /* --- AAC --- */ 287 288 #ifdef M4VSS_SUPPORT_AUDEC_AAC 289 290 err = VideoEditorAudioDecoder_getInterface_AAC(&audioDecoderType, 291 &pAudioDecoderInterface); 292 if (M4NO_ERROR != err) 293 { 294 M4OSA_TRACE1_0("M4AD PHILIPS AAC interface allocation error"); 295 return err; 296 } 297 err = M4MCS_registerAudioDecoder( pContext, audioDecoderType, 298 pAudioDecoderInterface); 299 M4OSA_DEBUG_IF1((err != M4NO_ERROR), err, 300 "M4MCS_subscribeMediaAndCodec: can't register PHILIPS AAC decoder"); 301 #endif /* M4VSS_SUPPORT_AUDEC_AAC */ 302 303 /* --- MP3 --- */ 304 305 #ifdef M4VSS_SUPPORT_AUDEC_MP3 306 307 err = VideoEditorAudioDecoder_getInterface_MP3(&audioDecoderType, 308 &pAudioDecoderInterface); 309 if (M4NO_ERROR != err) 310 { 311 M4OSA_TRACE1_0("M4AD PHILIPS MP3 interface allocation error"); 312 return err; 313 } 314 err = M4MCS_registerAudioDecoder( pContext, audioDecoderType, 315 pAudioDecoderInterface); 316 M4OSA_DEBUG_IF1((err != M4NO_ERROR), err, 317 "M4MCS_subscribeMediaAndCodec: can't register PHILIPS MP3 decoder"); 318 #endif /* M4VSS_SUPPORT_AUDEC_MP3 */ 319 320 /* --- EVRC --- */ 321 322 323 /* _______________________ */ 324 /*| |*/ 325 /*| writer subscription |*/ 326 /*|_______________________|*/ 327 328 /* --- PCM --- */ 329 330 331 /* --- 3GPP --- */ 332 333 #ifdef M4VSS_SUPPORT_WRITER_3GPP 334 /* retrieves the 3GPP writer media type and pointer to functions*/ 335 err = M4WRITER_3GP_getInterfaces( &writerMediaType, 336 &pWriterGlobalInterface, 337 &pWriterDataInterface); 338 if (M4NO_ERROR != err) 339 { 340 M4OSA_TRACE1_0("M4WRITER_3GP interface allocation error"); 341 return err; 342 } 343 err = M4MCS_registerWriter( pContext, writerMediaType, 344 pWriterGlobalInterface, 345 pWriterDataInterface); 346 M4OSA_DEBUG_IF1((err != M4NO_ERROR), err, 347 "M4MCS_subscribeMediaAndCodec: can't register 3GPP writer"); 348 #endif /* M4VSS_SUPPORT_WRITER_3GPP */ 349 350 351 /* ______________________________ */ 352 /*| |*/ 353 /*| video encoder subscription |*/ 354 /*|______________________________|*/ 355 356 /* --- MPEG4 --- */ 357 358 #ifdef M4VSS_SUPPORT_ENCODER_MPEG4 359 /* retrieves the MPEG4 encoder type and pointer to functions*/ 360 err = VideoEditorVideoEncoder_getInterface_MPEG4(&videoCodecType, 361 &pVideoCodecInterface, 362 M4ENCODER_OPEN_ADVANCED); 363 if (M4NO_ERROR != err) 364 { 365 M4OSA_TRACE1_0("M4MP4E_MPEG4 interface allocation error"); 366 return err; 367 } 368 err = M4MCS_registerVideoEncoder( pContext, videoCodecType, 369 pVideoCodecInterface); 370 M4OSA_DEBUG_IF1((err != M4NO_ERROR), err, 371 "M4MCS_subscribeMediaAndCodec: can't register video MPEG4 encoder"); 372 #endif /* M4VSS_SUPPORT_ENCODER_MPEG4 */ 373 374 /* --- H263 --- */ 375 376 #ifdef M4VSS_SUPPORT_ENCODER_MPEG4 377 /* retrieves the H263 encoder type and pointer to functions*/ 378 err = VideoEditorVideoEncoder_getInterface_H263(&videoCodecType, 379 &pVideoCodecInterface, 380 M4ENCODER_OPEN_ADVANCED); 381 382 if (M4NO_ERROR != err) 383 { 384 M4OSA_TRACE1_0("M4MP4E_H263 interface allocation error"); 385 return err; 386 } 387 err = M4MCS_registerVideoEncoder( pContext, videoCodecType, 388 pVideoCodecInterface); 389 M4OSA_DEBUG_IF1((err != M4NO_ERROR), err, 390 "M4MCS_subscribeMediaAndCodec: can't register video H263 encoder"); 391 #endif /* M4VSS_SUPPORT_ENCODER_MPEG4 */ 392 393 #ifdef M4VSS_SUPPORT_ENCODER_AVC 394 /* retrieves the H263 encoder type and pointer to functions*/ 395 err = VideoEditorVideoEncoder_getInterface_H264(&videoCodecType, 396 &pVideoCodecInterface, 397 M4ENCODER_OPEN_ADVANCED); 398 if (M4NO_ERROR != err) 399 { 400 M4OSA_TRACE1_0("M4H264E interface allocation error"); 401 return err; 402 } 403 err = M4MCS_registerVideoEncoder( pContext, videoCodecType, pVideoCodecInterface); 404 M4OSA_DEBUG_IF1((err != M4NO_ERROR), err, 405 "M4MCS_subscribeMediaAndCodec: can't register video H264 encoder"); 406 #endif /* M4VSS_SUPPORT_ENCODER_AVC */ 407 408 /* ______________________________ */ 409 /*| |*/ 410 /*| audio encoder subscription |*/ 411 /*|______________________________|*/ 412 413 /* --- AMR --- */ 414 415 #ifdef M4VSS_SUPPORT_ENCODER_AMR 416 /* retrieves the AMR encoder type and pointer to functions*/ 417 err = VideoEditorAudioEncoder_getInterface_AMRNB(&audioCodecType, 418 &pAudioCodecInterface); 419 if (M4NO_ERROR != err) 420 { 421 M4OSA_TRACE1_0("M4AMR interface allocation error"); 422 return err; 423 } 424 err = M4MCS_registerAudioEncoder( pContext, audioCodecType, 425 pAudioCodecInterface); 426 M4OSA_DEBUG_IF1((err != M4NO_ERROR), err, 427 "M4MCS_subscribeMediaAndCodec: can't register audio AMR encoder"); 428 #endif /* M4VSS_SUPPORT_ENCODER_AMR */ 429 430 /* --- AAC --- */ 431 432 #ifdef M4VSS_SUPPORT_ENCODER_AAC 433 /* retrieves the AAC encoder type and pointer to functions*/ 434 err = VideoEditorAudioEncoder_getInterface_AAC(&audioCodecType, 435 &pAudioCodecInterface); 436 if (M4NO_ERROR != err) 437 { 438 M4OSA_TRACE1_0("M4AAC interface allocation error"); 439 return err; 440 } 441 err = M4MCS_registerAudioEncoder( pContext, audioCodecType, 442 pAudioCodecInterface); 443 M4OSA_DEBUG_IF1((err != M4NO_ERROR), err, 444 "M4MCS_subscribeMediaAndCodec: can't register audio AAC encoder"); 445 #endif /* M4VSS_SUPPORT_ENCODER_AAC */ 446 447 448 449 /* --- MP3 --- */ 450 #ifdef M4VSS_SUPPORT_ENCODER_MP3 451 /* retrieves the MP3 encoder type and pointer to functions*/ 452 err = VideoEditorAudioEncoder_getInterface_MP3(&audioCodecType, 453 &pAudioCodecInterface); 454 if (M4NO_ERROR != err) 455 { 456 M4OSA_TRACE1_0("M4MP3E interface allocation error"); 457 return err; 458 } 459 err = M4MCS_registerAudioEncoder( pContext, audioCodecType, 460 pAudioCodecInterface); 461 M4OSA_DEBUG_IF1((err != M4NO_ERROR), err, 462 "M4MCS_subscribeMediaAndCodec: can't register audio MP3 encoder"); 463 #endif /* M4VSS_SUPPORT_ENCODER_MP3 */ 464 465 return err; 466 } 467 468