Home | History | Annotate | Download | only in src
      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    M4VSS3GPP_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 VSS. Potential support can
     22  *            be activated or de-activated
     23  *            using compilation flags set in the projects settings.
     24  *************************************************************************
     25  */
     26 
     27 #include "NXPSW_CompilerSwitches.h"
     28 
     29 
     30 #include "M4OSA_Debug.h"
     31 #include "M4VSS3GPP_InternalTypes.h"                /**< Include for VSS specific types */
     32 #include "M4VSS3GPP_InternalFunctions.h"            /**< Registration module */
     33 
     34 /* _______________________ */
     35 /*|                       |*/
     36 /*|  reader subscription  |*/
     37 /*|_______________________|*/
     38 
     39 /* Reader registration : at least one reader must be defined */
     40 #ifndef M4VSS_SUPPORT_READER_3GP
     41 #ifndef M4VSS_SUPPORT_READER_AMR
     42 #ifndef M4VSS_SUPPORT_READER_MP3
     43 #ifndef M4VSS_SUPPORT_READER_PCM
     44 #ifndef M4VSS_SUPPORT_AUDEC_NULL
     45 #error "no reader registered"
     46 #endif /* M4VSS_SUPPORT_AUDEC_NULL */
     47 #endif /* M4VSS_SUPPORT_READER_PCM */
     48 #endif /* M4VSS_SUPPORT_READER_MP3 */
     49 #endif /* M4VSS_SUPPORT_READER_AMR */
     50 #endif /* M4VSS_SUPPORT_READER_3GP */
     51 
     52 /* There must be at least one MPEG4 decoder */
     53 #if !defined(M4VSS_SUPPORT_VIDEC_3GP) && !defined(M4VSS_ENABLE_EXTERNAL_DECODERS)
     54 #error "Wait, what?"
     55 /* "Hey, this is the VSS3GPP speaking. Pray tell, how the heck do you expect me to be able to do
     56 any editing without a built-in video decoder, nor the possibility to receive an external one?!
     57 Seriously, I'd love to know." */
     58 #endif
     59 
     60 /* Include files for each reader to subscribe */
     61 #ifdef M4VSS_SUPPORT_READER_3GP
     62 #include "VideoEditor3gpReader.h"
     63 #endif
     64 #ifdef M4VSS_SUPPORT_READER_AMR
     65 #include "M4READER_Amr.h"
     66 #endif
     67 #ifdef M4VSS_SUPPORT_READER_MP3
     68 #include "VideoEditorMp3Reader.h"
     69 #endif
     70 #ifdef M4VSS_SUPPORT_READER_PCM
     71 #include "M4READER_Pcm.h"
     72 #endif
     73 
     74 
     75 /* ______________________________ */
     76 /*|                              |*/
     77 /*|  audio decoder subscription  |*/
     78 /*|______________________________|*/
     79 
     80 #include "VideoEditorAudioDecoder.h"
     81 #include "VideoEditorVideoDecoder.h"
     82 #include "M4DECODER_Null.h"
     83 #ifdef M4VSS_SUPPORT_AUDEC_NULL
     84 #include "M4AD_Null.h"
     85 #endif
     86 
     87 /* _______________________ */
     88 /*|                       |*/
     89 /*|  writer subscription  |*/
     90 /*|_______________________|*/
     91 
     92 /* Writer registration : at least one writer must be defined */
     93 //#ifndef M4VSS_SUPPORT_WRITER_AMR
     94 #ifndef M4VSS_SUPPORT_WRITER_3GPP
     95 #error "no writer registered"
     96 #endif /* M4VSS_SUPPORT_WRITER_3GPP */
     97 //#endif /* M4VSS_SUPPORT_WRITER_AMR */
     98 
     99 /* Include files for each writer to subscribe */
    100 //#ifdef M4VSS_SUPPORT_WRITER_AMR
    101 /*extern M4OSA_ERR M4WRITER_AMR_getInterfaces( M4WRITER_OutputFileType* Type,
    102 M4WRITER_GlobalInterface** SrcGlobalInterface,
    103 M4WRITER_DataInterface** SrcDataInterface);*/
    104 //#endif
    105 #ifdef M4VSS_SUPPORT_WRITER_3GPP
    106 extern M4OSA_ERR M4WRITER_3GP_getInterfaces( M4WRITER_OutputFileType* Type,
    107                                             M4WRITER_GlobalInterface** SrcGlobalInterface,
    108                                             M4WRITER_DataInterface** SrcDataInterface);
    109 #endif
    110 
    111 /* ______________________________ */
    112 /*|                              |*/
    113 /*|  video encoder subscription  |*/
    114 /*|______________________________|*/
    115 #include "VideoEditorAudioEncoder.h"
    116 #include "VideoEditorVideoEncoder.h"
    117 
    118 
    119 /* ______________________________ */
    120 /*|                              |*/
    121 /*|  audio encoder subscription  |*/
    122 /*|______________________________|*/
    123 
    124 
    125 #define M4ERR_CHECK_NULL_RETURN_VALUE(retval, pointer) if ((pointer) == M4OSA_NULL)\
    126     return ((M4OSA_ERR)(retval));
    127 
    128 /**
    129  ******************************************************************************
    130  * M4OSA_ERR M4VSS3GPP_SubscribeMediaAndCodec()
    131  * @brief    This function registers the reader, decoders, writers and encoders
    132  *          in the VSS.
    133  * @note
    134  * @param    pContext:    (IN) Execution context.
    135  * @return    M4NO_ERROR: there is no error
    136  * @return    M4ERR_PARAMETER    pContext is NULL
    137  ******************************************************************************
    138  */
    139 M4OSA_ERR M4VSS3GPP_subscribeMediaAndCodec(M4VSS3GPP_MediaAndCodecCtxt *pContext)
    140 {
    141     M4OSA_ERR                   err = M4NO_ERROR;
    142 
    143     M4READER_MediaType          readerMediaType;
    144     M4READER_GlobalInterface*   pReaderGlobalInterface;
    145     M4READER_DataInterface*     pReaderDataInterface;
    146 
    147     M4WRITER_OutputFileType     writerMediaType;
    148     M4WRITER_GlobalInterface*   pWriterGlobalInterface;
    149     M4WRITER_DataInterface*     pWriterDataInterface;
    150 
    151     M4AD_Type                   audioDecoderType;
    152     M4ENCODER_AudioFormat       audioCodecType;
    153     M4ENCODER_AudioGlobalInterface* pAudioCodecInterface;
    154     M4AD_Interface*             pAudioDecoderInterface;
    155 
    156     M4DECODER_VideoType         videoDecoderType;
    157     M4ENCODER_Format            videoCodecType;
    158     M4ENCODER_GlobalInterface*  pVideoCodecInterface;
    159     M4DECODER_VideoInterface*   pVideoDecoderInterface;
    160 
    161     M4ERR_CHECK_NULL_RETURN_VALUE(M4ERR_PARAMETER, pContext);
    162 
    163     /* _______________________ */
    164     /*|                       |*/
    165     /*|  reader subscription  |*/
    166     /*|_______________________|*/
    167 
    168     /* --- 3GP --- */
    169 
    170 #ifdef M4VSS_SUPPORT_READER_3GP
    171     err = VideoEditor3gpReader_getInterface( &readerMediaType, &pReaderGlobalInterface,
    172          &pReaderDataInterface);
    173     if (M4NO_ERROR != err)
    174     {
    175         M4OSA_TRACE1_0("M4READER_3GP interface allocation error");
    176         return err;
    177     }
    178     err = M4VSS3GPP_registerReader( pContext, readerMediaType, pReaderGlobalInterface,
    179         pReaderDataInterface);
    180     M4OSA_DEBUG_IF1((err != M4NO_ERROR), err,
    181         "M4VSS3GPP_subscribeMediaAndCodec: can't register 3GP reader");
    182 #endif /* M4VSS_SUPPORT_READER_3GP */
    183 
    184     /* --- AMR --- */
    185 
    186 #ifdef M4VSS_SUPPORT_READER_AMR
    187     err = M4READER_AMR_getInterfaces( &readerMediaType, &pReaderGlobalInterface,
    188         &pReaderDataInterface);
    189     if (M4NO_ERROR != err)
    190     {
    191         M4OSA_TRACE1_0("M4READER_AMR interface allocation error");
    192         return err;
    193     }
    194     err = M4VSS3GPP_registerReader( pContext, readerMediaType, pReaderGlobalInterface,
    195         pReaderDataInterface);
    196     M4OSA_DEBUG_IF1((err != M4NO_ERROR), err,
    197         "M4VSS3GPP_subscribeMediaAndCodec: can't register AMR reader");
    198 #endif /* M4VSS_SUPPORT_READER_AMR */
    199 
    200     /* --- MP3 --- */
    201 
    202 #ifdef M4VSS_SUPPORT_READER_MP3
    203     err = VideoEditorMp3Reader_getInterface( &readerMediaType, &pReaderGlobalInterface,
    204          &pReaderDataInterface);
    205     if (M4NO_ERROR != err)
    206     {
    207         M4OSA_TRACE1_0("M4READER_MP3 interface allocation error");
    208         return err;
    209     }
    210     err = M4VSS3GPP_registerReader( pContext, readerMediaType, pReaderGlobalInterface,
    211         pReaderDataInterface);
    212     M4OSA_DEBUG_IF1((err != M4NO_ERROR), err,
    213         "M4VSS3GPP_subscribeMediaAndCodec: can't register MP3 reader");
    214 #endif /* M4VSS_SUPPORT_READER_MP3 */
    215 
    216     /* --- PCM --- */
    217 
    218 #ifdef M4VSS_SUPPORT_READER_PCM
    219     err = M4READER_PCM_getInterfaces( &readerMediaType, &pReaderGlobalInterface,
    220         &pReaderDataInterface);
    221     if (M4NO_ERROR != err)
    222     {
    223         M4OSA_TRACE1_0("M4READER_PCM interface allocation error");
    224         return err;
    225     }
    226     err = M4VSS3GPP_registerReader( pContext, readerMediaType, pReaderGlobalInterface,
    227         pReaderDataInterface);
    228     M4OSA_DEBUG_IF1((err != M4NO_ERROR), err,
    229         "M4VSS3GPP_subscribeMediaAndCodec: can't register PCM reader");
    230 #endif /* M4VSS_SUPPORT_READER_PCM */
    231 
    232     /* ______________________________ */
    233     /*|                              |*/
    234     /*|  video decoder subscription  |*/
    235     /*|______________________________|*/
    236 
    237     /* --- MPEG4 & H263 --- */
    238 
    239 #ifdef M4VSS_SUPPORT_VIDEC_3GP
    240     err = VideoEditorVideoDecoder_getInterface_MPEG4(&videoDecoderType, (M4OSA_Void *)&pVideoDecoderInterface);
    241     if (M4NO_ERROR != err)
    242     {
    243         M4OSA_TRACE1_0("M4DECODER_MPEG4 interface allocation error");
    244         return err;
    245     }
    246     err = M4VSS3GPP_registerVideoDecoder( pContext, videoDecoderType, pVideoDecoderInterface);
    247     M4OSA_DEBUG_IF1((err != M4NO_ERROR), err,
    248         "M4VSS3GPP_subscribeMediaAndCodec: can't register MPEG4 decoder");
    249 #endif /* M4VSS_SUPPORT_VIDEC_3GP */
    250 
    251 #ifdef M4VSS_SUPPORT_VIDEO_AVC
    252     err = VideoEditorVideoDecoder_getInterface_H264(&videoDecoderType, (M4OSA_Void *)&pVideoDecoderInterface);
    253     if (M4NO_ERROR != err)
    254     {
    255         M4OSA_TRACE1_0("M4DECODER_H264 interface allocation error");
    256         return err;
    257     }
    258     err = M4VSS3GPP_registerVideoDecoder( pContext, videoDecoderType, pVideoDecoderInterface);
    259     M4OSA_DEBUG_IF1((err != M4NO_ERROR), err,
    260         "M4VSS3GPP_subscribeMediaAndCodec: can't register H264 decoder");
    261 #endif /* M4VSS_SUPPORT_VIDEC_3GP */
    262 
    263 #ifdef M4VSS_SUPPORT_VIDEC_NULL
    264     err = M4DECODER_NULL_getInterface(
    265               &videoDecoderType, &pVideoDecoderInterface);
    266     if (M4NO_ERROR != err) {
    267         M4OSA_TRACE1_0("M4VD NULL Decoder interface allocation error");
    268         return err;
    269     }
    270     err = M4VSS3GPP_registerVideoDecoder(
    271               pContext, videoDecoderType, pVideoDecoderInterface);
    272     M4OSA_DEBUG_IF1((err != M4NO_ERROR), err, "M4VSS3GPP_subscribeMediaAndCodec: \
    273         can't register video NULL decoder");
    274 #endif
    275     /* ______________________________ */
    276     /*|                              |*/
    277     /*|  audio decoder subscription  |*/
    278     /*|______________________________|*/
    279 
    280     /* --- AMRNB --- */
    281 
    282 #ifdef M4VSS_SUPPORT_AUDEC_AMRNB
    283     err = VideoEditorAudioDecoder_getInterface_AMRNB(&audioDecoderType, &pAudioDecoderInterface);
    284     if (M4NO_ERROR != err)
    285     {
    286         M4OSA_TRACE1_0("M4 AMRNB interface allocation error");
    287         return err;
    288     }
    289     err = M4VSS3GPP_registerAudioDecoder( pContext, audioDecoderType, pAudioDecoderInterface);
    290     M4OSA_DEBUG_IF1((err != M4NO_ERROR), err,
    291         "M4VSS3GPP_subscribeMediaAndCodec: can't register AMRNB decoder");
    292 #endif /* M4VSS_SUPPORT_AUDEC_AMRNB */
    293 
    294     /* --- AAC --- */
    295 
    296 #ifdef M4VSS_SUPPORT_AUDEC_AAC
    297     err = VideoEditorAudioDecoder_getInterface_AAC(&audioDecoderType, &pAudioDecoderInterface);
    298     if (M4NO_ERROR != err)
    299     {
    300         M4OSA_TRACE1_0("M4 AAC interface allocation error");
    301         return err;
    302     }
    303     err = M4VSS3GPP_registerAudioDecoder( pContext, audioDecoderType, pAudioDecoderInterface);
    304     M4OSA_DEBUG_IF1((err != M4NO_ERROR), err,
    305         "M4VSS3GPP_subscribeMediaAndCodec: can't register AAC decoder");
    306 #endif /* M4VSS_SUPPORT_AUDEC_AAC */
    307 
    308     /* --- MP3 --- */
    309 
    310 #ifdef M4VSS_SUPPORT_AUDEC_MP3
    311     err = VideoEditorAudioDecoder_getInterface_MP3(&audioDecoderType, &pAudioDecoderInterface);
    312     if (M4NO_ERROR != err)
    313     {
    314         M4OSA_TRACE1_0("M4 MP3 interface allocation error");
    315         return err;
    316     }
    317     err = M4VSS3GPP_registerAudioDecoder( pContext, audioDecoderType, pAudioDecoderInterface);
    318     M4OSA_DEBUG_IF1((err != M4NO_ERROR), err,
    319         "M4VSS3GPP_subscribeMediaAndCodec: can't register MP3 decoder");
    320 #endif  /* M4VSS_SUPPORT_AUDEC_MP3 */
    321 
    322 
    323     /* --- NULL --- */
    324 
    325 #ifdef M4VSS_SUPPORT_AUDEC_NULL
    326     err = M4AD_NULL_getInterface( &audioDecoderType, &pAudioDecoderInterface);
    327     if (M4NO_ERROR != err)
    328     {
    329         M4OSA_TRACE1_0("M4AD NULL Decoder interface allocation error");
    330         return err;
    331     }
    332     err = M4VSS3GPP_registerAudioDecoder( pContext, audioDecoderType, pAudioDecoderInterface);
    333     M4OSA_DEBUG_IF1((err != M4NO_ERROR), err,
    334         "M4VSS3GPP_subscribeMediaAndCodec: can't register EVRC decoder");
    335 #endif  /* M4VSS_SUPPORT_AUDEC_NULL */
    336 
    337     /* _______________________ */
    338     /*|                       |*/
    339     /*|  writer subscription  |*/
    340     /*|_______________________|*/
    341 
    342 
    343     /* --- 3GPP --- */
    344 
    345 #ifdef M4VSS_SUPPORT_WRITER_3GPP
    346     /* retrieves the 3GPP writer media type and pointer to functions*/
    347     err = M4WRITER_3GP_getInterfaces( &writerMediaType, &pWriterGlobalInterface,
    348         &pWriterDataInterface);
    349     if (M4NO_ERROR != err)
    350     {
    351         M4OSA_TRACE1_0("M4WRITER_3GP interface allocation error");
    352         return err;
    353     }
    354     err = M4VSS3GPP_registerWriter( pContext, writerMediaType, pWriterGlobalInterface,
    355         pWriterDataInterface);
    356     M4OSA_DEBUG_IF1((err != M4NO_ERROR), err,
    357         "M4VSS3GPP_subscribeMediaAndCodec: can't register 3GPP writer");
    358 #endif /* M4VSS_SUPPORT_WRITER_3GPP */
    359 
    360     /* ______________________________ */
    361     /*|                              |*/
    362     /*|  video encoder subscription  |*/
    363     /*|______________________________|*/
    364 
    365     /* --- MPEG4 --- */
    366 
    367 #ifdef M4VSS_SUPPORT_ENCODER_MPEG4
    368     /* retrieves the MPEG4 encoder type and pointer to functions*/
    369     err = VideoEditorVideoEncoder_getInterface_MPEG4(&videoCodecType, &pVideoCodecInterface,
    370          M4ENCODER_OPEN_ADVANCED);
    371     if (M4NO_ERROR != err)
    372     {
    373         M4OSA_TRACE1_0("M4MP4E_MPEG4 interface allocation error");
    374         return err;
    375     }
    376     err = M4VSS3GPP_registerVideoEncoder( pContext, videoCodecType, pVideoCodecInterface);
    377     M4OSA_DEBUG_IF1((err != M4NO_ERROR), err,
    378         "M4VSS3GPP_subscribeMediaAndCodec: can't register video MPEG4 encoder");
    379 #endif /* M4VSS_SUPPORT_ENCODER_MPEG4 */
    380 
    381     /* --- H263 --- */
    382 
    383 #ifdef M4VSS_SUPPORT_ENCODER_MPEG4
    384     /* retrieves the H263 encoder type and pointer to functions*/
    385     err = VideoEditorVideoEncoder_getInterface_H263(&videoCodecType, &pVideoCodecInterface,
    386          M4ENCODER_OPEN_ADVANCED);
    387     if (M4NO_ERROR != err)
    388     {
    389         M4OSA_TRACE1_0("M4MP4E_H263 interface allocation error");
    390         return err;
    391     }
    392     err = M4VSS3GPP_registerVideoEncoder( pContext, videoCodecType, pVideoCodecInterface);
    393     M4OSA_DEBUG_IF1((err != M4NO_ERROR), err,
    394         "M4VSS3GPP_subscribeMediaAndCodec: can't register video H263 encoder");
    395 #endif /* M4VSS_SUPPORT_ENCODER_MPEG4 */
    396 
    397 #ifdef M4VSS_SUPPORT_ENCODER_AVC
    398     /* retrieves the H264 encoder type and pointer to functions*/
    399     err = VideoEditorVideoEncoder_getInterface_H264(&videoCodecType, &pVideoCodecInterface,
    400          M4ENCODER_OPEN_ADVANCED);
    401     if (M4NO_ERROR != err)
    402     {
    403         M4OSA_TRACE1_0("M4VSS3GPP_subscribeMediaAndCodec: M4H264E interface allocation error");
    404         return err;
    405     }
    406     err = M4VSS3GPP_registerVideoEncoder( pContext, videoCodecType, pVideoCodecInterface);
    407     M4OSA_DEBUG_IF1((err != M4NO_ERROR), err,
    408         "M4VSS3GPP_subscribeMediaAndCodec: can't register video H264 encoder");
    409 #endif /* M4VSS_SUPPORT_ENCODER_AVC */
    410 
    411     /* ______________________________ */
    412     /*|                              |*/
    413     /*|  audio encoder subscription  |*/
    414     /*|______________________________|*/
    415 
    416     /* --- AMR --- */
    417 
    418 #ifdef M4VSS_SUPPORT_ENCODER_AMR
    419     /* retrieves the AMR encoder type and pointer to functions*/
    420     err = VideoEditorAudioEncoder_getInterface_AMRNB(&audioCodecType, &pAudioCodecInterface);
    421     if (M4NO_ERROR != err)
    422     {
    423         M4OSA_TRACE1_0("M4AMR interface allocation error");
    424         return err;
    425     }
    426     err = M4VSS3GPP_registerAudioEncoder( pContext, audioCodecType, pAudioCodecInterface);
    427     M4OSA_DEBUG_IF1((err != M4NO_ERROR), err,
    428         "M4VSS3GPP_subscribeMediaAndCodec: can't register audio AMR encoder");
    429 #endif /* M4VSS_SUPPORT_ENCODER_AMR */
    430 
    431     /* --- AAC --- */
    432 
    433 #ifdef M4VSS_SUPPORT_ENCODER_AAC
    434     /* retrieves the AAC encoder type and pointer to functions*/
    435     err = VideoEditorAudioEncoder_getInterface_AAC(&audioCodecType, &pAudioCodecInterface);
    436     if (M4NO_ERROR != err)
    437     {
    438         M4OSA_TRACE1_0("M4AAC interface allocation error");
    439         return err;
    440     }
    441     err = M4VSS3GPP_registerAudioEncoder( pContext, audioCodecType, pAudioCodecInterface);
    442     M4OSA_DEBUG_IF1((err != M4NO_ERROR), err,
    443         "M4VSS3GPP_subscribeMediaAndCodec: can't register audio AAC encoder");
    444 #endif /* M4VSS_SUPPORT_ENCODER_AAC */
    445 
    446     /* --- EVRC --- */
    447 
    448 #ifdef M4VSS_SUPPORT_ENCODER_EVRC
    449     /* retrieves the EVRC encoder type and pointer to functions*/
    450     err = M4EVRC_getInterfaces( &audioCodecType, &pAudioCodecInterface);
    451     if (M4NO_ERROR != err)
    452     {
    453         M4OSA_TRACE1_0("M4EVRC interface allocation error");
    454         return err;
    455     }
    456     err = M4VSS3GPP_registerAudioEncoder( pContext, audioCodecType, pAudioCodecInterface);
    457     M4OSA_DEBUG_IF1((err != M4NO_ERROR), err,
    458         "M4VSS3GPP_subscribeMediaAndCodec: can't register audio EVRC encoder");
    459 #endif /* M4VSS_SUPPORT_ENCODER_EVRC */
    460 
    461 #ifdef M4VSS_SUPPORT_OMX_CODECS
    462     pContext->bAllowFreeingOMXCodecInterface = M4OSA_TRUE;   /* when NXP SW codecs are registered,
    463                                                                then allow unregistration*/
    464 #endif
    465 
    466 
    467     return err;
    468 }
    469 
    470