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