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