M4VSS3GPP_Codecs.c revision 3b25fdc4a33b53cfcf67315c2d42ad699b8cefe2
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
651        }
652    }
653
654    for ( i = 0; i < M4AD_kType_NB; i++ )
655    {
656        if( pC->m_pAudioDecoderItTable[i] != M4OSA_NULL )
657        {
658#ifdef M4VSS_SUPPORT_OMX_CODECS
659
660            if( M4OSA_TRUE == pC->bAllowFreeingOMXCodecInterface )
661            {
662
663#endif
664                /*Don't free external audio decoders interfaces*/
665
666                if( M4OSA_FALSE == pC->m_pAudioDecoderFlagTable[i] )
667                {
668                    free(pC->m_pAudioDecoderItTable[i]);
669                }
670#ifdef M4VSS_SUPPORT_OMX_CODECS
671
672            }
673
674#endif
675
676            pC->m_pAudioDecoderItTable[i] = M4OSA_NULL;
677        }
678    }
679
680    pC->m_uiNbRegisteredVideoDec = 0;
681    pC->m_pVideoDecoder = M4OSA_NULL;
682
683    pC->m_pAudioDecoder = M4OSA_NULL;
684
685    return M4NO_ERROR;
686}
687
688/**
689 ************************************************************************
690 * M4OSA_ERR   M4VSS3GPP_setCurrentWriter()
691 * @brief    Set current writer
692 * @param    pContext            (IN/OUT) VSS context.
693 * @param    mediaType            (IN) Media type.
694 * @return    M4NO_ERROR:            No error
695 * @return    M4ERR_PARAMETER:                    A parameter is null (in DEBUG only)
696 * @return    M4WAR_VSS_MEDIATYPE_NOT_SUPPORTED:    Media type not supported
697 ************************************************************************
698 */
699M4OSA_ERR M4VSS3GPP_setCurrentWriter( M4VSS3GPP_MediaAndCodecCtxt *pC,
700                                     M4VIDEOEDITING_FileType mediaType )
701{
702    M4WRITER_OutputFileType writerType;
703
704    M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER,
705        "invalid context pointer");
706
707    switch( mediaType )
708    {
709        case M4VIDEOEDITING_kFileType_3GPP:
710            writerType = M4WRITER_k3GPP;
711            break;
712        default:
713            M4OSA_DEBUG_IF1(M4OSA_TRUE, M4VSS3GPP_ERR_INVALID_FILE_TYPE,
714                "Writer type not supported");
715            return M4VSS3GPP_ERR_INVALID_FILE_TYPE;
716    }
717
718    pC->pWriterGlobalFcts = pC->WriterInterface[writerType].pGlobalFcts;
719    pC->pWriterDataFcts = pC->WriterInterface[writerType].pDataFcts;
720
721    if( pC->pWriterGlobalFcts == M4OSA_NULL
722        || pC->pWriterDataFcts == M4OSA_NULL )
723    {
724        M4OSA_DEBUG_IF1(M4OSA_TRUE, M4VSS3GPP_ERR_INVALID_FILE_TYPE,
725            "Writer type not supported");
726        M4OSA_TRACE1_0("Writer type not supported");
727        return M4VSS3GPP_ERR_INVALID_FILE_TYPE;
728    }
729
730    pC->pWriterDataFcts->pWriterContext = M4OSA_NULL;
731
732    return M4NO_ERROR;
733}
734
735/**
736 ************************************************************************
737 * M4OSA_ERR   M4VSS3GPP_setCurrentVideoEncoder()
738 * @brief    Set a video encoder
739 * @param    pContext            (IN/OUT) VSS context.
740 * @param    MediaType           (IN) Encoder type
741 * @return    M4NO_ERROR:            No error
742 * @return    M4ERR_PARAMETER:                    A parameter is null (in DEBUG only)
743 * @return    M4WAR_VSS_MEDIATYPE_NOT_SUPPORTED:    Media type not supported
744 ************************************************************************
745 */
746M4OSA_ERR M4VSS3GPP_setCurrentVideoEncoder( M4VSS3GPP_MediaAndCodecCtxt *pC,
747                                           M4SYS_StreamType mediaType )
748{
749    M4ENCODER_Format encoderType;
750
751    M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER,
752        "invalid context pointer");
753    M4OSA_TRACE3_2("M4VSS3GPP_setCurrentVideoEncoder: pC=0x%x, mediaType=0x%x",
754        pC, mediaType);
755
756    switch( mediaType )
757    {
758        case M4SYS_kH263:
759            encoderType = M4ENCODER_kH263;
760            break;
761
762        case M4SYS_kMPEG_4:
763            encoderType = M4ENCODER_kMPEG4;
764            break;
765
766        case M4SYS_kH264:
767            encoderType = M4ENCODER_kH264;
768            break;
769
770        default:
771            M4OSA_DEBUG_IF1(M4OSA_TRUE,
772                M4VSS3GPP_ERR_EDITING_UNSUPPORTED_VIDEO_FORMAT,
773                "Video encoder type not supported");
774            return M4VSS3GPP_ERR_EDITING_UNSUPPORTED_VIDEO_FORMAT;
775    }
776
777    pC->pVideoEncoderGlobalFcts = pC->pVideoEncoderInterface[encoderType];
778    pC->pCurrentVideoEncoderExternalAPI =
779        pC->pVideoEncoderExternalAPITable[encoderType];
780    pC->pCurrentVideoEncoderUserData =
781        pC->pVideoEncoderUserDataTable[encoderType];
782
783    if( pC->pVideoEncoderGlobalFcts == M4OSA_NULL )
784    {
785        M4OSA_DEBUG_IF1(M4OSA_TRUE,
786            M4VSS3GPP_ERR_EDITING_UNSUPPORTED_VIDEO_FORMAT,
787            "Video encoder type not supported");
788        M4OSA_TRACE1_0("Video encoder type not supported");
789        return M4VSS3GPP_ERR_EDITING_UNSUPPORTED_VIDEO_FORMAT;
790    }
791
792    return M4NO_ERROR;
793}
794
795/**
796 ************************************************************************
797 * M4OSA_ERR   M4VSS3GPP_setCurrentAudioEncoder()
798 * @brief    Set an audio encoder
799 * @param    context            (IN/OUT) VSS context.
800 * @param    MediaType        (IN) Encoder type
801 * @return    M4NO_ERROR:            No error
802 * @return    M4ERR_PARAMETER:    A parameter is null (in DEBUG only)
803 ************************************************************************
804 */
805M4OSA_ERR M4VSS3GPP_setCurrentAudioEncoder( M4VSS3GPP_MediaAndCodecCtxt *pC,
806                                           M4SYS_StreamType mediaType )
807{
808    M4ENCODER_AudioFormat encoderType;
809
810    M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER,
811        "invalid context pointer");
812    M4OSA_TRACE3_2("M4VSS3GPP_setCurrentAudioEncoder: pC=0x%x, mediaType=0x%x",
813        pC, mediaType);
814
815    switch( mediaType )
816    {
817        case M4SYS_kAMR:
818            M4OSA_TRACE3_0(
819                "M4VSS3GPP_setCurrentAudioEncoder: encoder type AMR");
820            encoderType = M4ENCODER_kAMRNB;
821            break;
822
823        case M4SYS_kAAC:
824            M4OSA_TRACE3_0(
825                "M4VSS3GPP_setCurrentAudioEncoder: encoder type AAC");
826            encoderType = M4ENCODER_kAAC;
827            break;
828
829       default:
830            M4OSA_DEBUG_IF1(M4OSA_TRUE,
831                M4VSS3GPP_ERR_EDITING_UNSUPPORTED_AUDIO_FORMAT,
832                "Audio encoder type not supported");
833            return M4VSS3GPP_ERR_EDITING_UNSUPPORTED_AUDIO_FORMAT;
834    }
835
836    pC->pAudioEncoderGlobalFcts = pC->pAudioEncoderInterface[encoderType];
837    pC->pCurrentAudioEncoderUserData =
838        pC->pAudioEncoderUserDataTable[encoderType];
839
840    M4OSA_TRACE3_3(
841        "M4VSS3GPP_setCurrentAudioEncoder: pC->pAudioEncoderInterface[0x%x]=0x%x,\
842        pC->pAudioEncoderGlobalFcts = 0x%x",
843        encoderType, pC->pAudioEncoderInterface[encoderType],
844        pC->pAudioEncoderGlobalFcts);
845
846    if( pC->pAudioEncoderGlobalFcts == M4OSA_NULL )
847    {
848        M4OSA_DEBUG_IF1(M4OSA_TRUE,
849            M4VSS3GPP_ERR_EDITING_UNSUPPORTED_AUDIO_FORMAT,
850            "Audio encoder type not supported");
851        M4OSA_TRACE1_0("Audio encoder type not supported");
852        return M4VSS3GPP_ERR_EDITING_UNSUPPORTED_AUDIO_FORMAT;
853    }
854
855    return M4NO_ERROR;
856}
857
858/**
859 ************************************************************************
860 * M4OSA_ERR   M4VSS3GPP_setCurrentReader()
861 * @brief    Set current reader
862 * @param    pContext            (IN/OUT) VSS context.
863 * @param    mediaType            (IN) Media type.
864 * @return    M4NO_ERROR:            No error
865 * @return    M4ERR_PARAMETER:                    A parameter is null (in DEBUG only)
866 * @return    M4WAR_VSS_MEDIATYPE_NOT_SUPPORTED:    Media type not supported
867 ************************************************************************
868 */
869M4OSA_ERR M4VSS3GPP_setCurrentReader( M4VSS3GPP_MediaAndCodecCtxt *pC,
870                                     M4VIDEOEDITING_FileType mediaType )
871{
872    M4READER_MediaType readerType;
873
874    M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER,
875        "invalid context pointer");
876
877    switch( mediaType )
878    {
879        case M4VIDEOEDITING_kFileType_3GPP:
880        case M4VIDEOEDITING_kFileType_MP4:
881        case M4VIDEOEDITING_kFileType_M4V:
882            readerType = M4READER_kMediaType3GPP;
883            break;
884
885        case M4VIDEOEDITING_kFileType_AMR:
886            readerType = M4READER_kMediaTypeAMR;
887            break;
888
889        case M4VIDEOEDITING_kFileType_MP3:
890            readerType = M4READER_kMediaTypeMP3;
891            break;
892
893        case M4VIDEOEDITING_kFileType_PCM:
894            readerType = M4READER_kMediaTypePCM;
895            break;
896
897        default:
898            M4OSA_DEBUG_IF1(M4OSA_TRUE, M4VSS3GPP_ERR_INVALID_FILE_TYPE,
899                "Reader type not supported");
900            return M4VSS3GPP_ERR_INVALID_FILE_TYPE;
901    }
902
903    pC->m_pReader = pC->m_pReaderGlobalItTable[readerType];
904    pC->m_pReaderDataIt = pC->m_pReaderDataItTable[readerType];
905
906    if( pC->m_pReader == M4OSA_NULL || pC->m_pReaderDataIt == M4OSA_NULL )
907    {
908        M4OSA_DEBUG_IF1(M4OSA_TRUE, M4VSS3GPP_ERR_INVALID_FILE_TYPE,
909            "Reader type not supported");
910        M4OSA_TRACE1_0("Reader type not supported");
911        return M4VSS3GPP_ERR_INVALID_FILE_TYPE;
912    }
913    return M4NO_ERROR;
914}
915
916/**
917 ************************************************************************
918 * M4OSA_ERR   M4VSS3GPP_setCurrentVideoDecoder()
919 * @brief    Set a video decoder
920 * @param    pContext            (IN/OUT) VSS context.
921 * @param    decoderType        (IN) Decoder type
922 * @return    M4NO_ERROR:            No error
923 * @return    M4ERR_PARAMETER:                    A parameter is null (in DEBUG only)
924 * @return    M4WAR_VSS_MEDIATYPE_NOT_SUPPORTED:    Media type not supported
925 ************************************************************************
926 */
927M4OSA_ERR M4VSS3GPP_setCurrentVideoDecoder( M4VSS3GPP_MediaAndCodecCtxt *pC,
928                                           M4_StreamType mediaType )
929{
930    M4DECODER_VideoType decoderType;
931
932    M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER,
933        "invalid context pointer");
934    M4OSA_TRACE3_2("M4VSS3GPP_setCurrentVideoDecoder: pC=0x%x, mediaType=0x%x",
935        pC, mediaType);
936
937    switch( mediaType )
938    {
939        case M4DA_StreamTypeVideoMpeg4:
940        case M4DA_StreamTypeVideoH263:
941            decoderType = M4DECODER_kVideoTypeMPEG4;
942            break;
943
944        case M4DA_StreamTypeVideoMpeg4Avc:
945            decoderType = M4DECODER_kVideoTypeAVC;
946            break;
947
948        default:
949            M4OSA_DEBUG_IF1(M4OSA_TRUE,
950                M4VSS3GPP_ERR_UNSUPPORTED_INPUT_VIDEO_FORMAT,
951                "Video decoder type not supported");
952            return M4VSS3GPP_ERR_UNSUPPORTED_INPUT_VIDEO_FORMAT;
953    }
954
955    pC->m_pVideoDecoder = pC->m_pVideoDecoderItTable[decoderType];
956#ifdef M4VSS_ENABLE_EXTERNAL_DECODERS
957
958    pC->m_pCurrentVideoDecoderUserData =
959        pC->m_pVideoDecoderUserDataTable[decoderType];
960
961#endif /* M4VSS_ENABLE_EXTERNAL_DECODERS */
962
963    if( pC->m_pVideoDecoder == M4OSA_NULL )
964    {
965        M4OSA_DEBUG_IF1(M4OSA_TRUE,
966            M4VSS3GPP_ERR_UNSUPPORTED_INPUT_VIDEO_FORMAT,
967            "Video decoder type not supported");
968        M4OSA_TRACE1_0("Video decoder type not supported");
969        return M4VSS3GPP_ERR_UNSUPPORTED_INPUT_VIDEO_FORMAT;
970    }
971
972    return M4NO_ERROR;
973}
974
975/**
976 ************************************************************************
977 * M4OSA_ERR   M4VSS3GPP_setCurrentAudioDecoder()
978 * @brief    Set an audio decoder
979 * @param    context            (IN/OUT) VSS context.
980 * @param    decoderType        (IN) Decoder type
981 * @return    M4NO_ERROR:            No error
982 * @return    M4ERR_PARAMETER:    A parameter is null (in DEBUG only)
983 ************************************************************************
984 */
985M4OSA_ERR M4VSS3GPP_setCurrentAudioDecoder( M4VSS3GPP_MediaAndCodecCtxt *pC,
986                                           M4_StreamType mediaType )
987{
988    M4AD_Type decoderType;
989
990    M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER,
991        "invalid context pointer");
992    M4OSA_TRACE3_2("M4VSS3GPP_setCurrentAudioDecoder: pC=0x%x, mediaType=0x%x",
993        pC, mediaType);
994
995    switch( mediaType )
996    {
997        case M4DA_StreamTypeAudioAmrNarrowBand:
998            decoderType = M4AD_kTypeAMRNB;
999            break;
1000
1001        case M4DA_StreamTypeAudioAac:
1002        case M4DA_StreamTypeAudioAacADTS:
1003        case M4DA_StreamTypeAudioAacADIF:
1004            decoderType = M4AD_kTypeAAC;
1005            break;
1006
1007        case M4DA_StreamTypeAudioMp3:
1008            decoderType = M4AD_kTypeMP3;
1009            break;
1010
1011        case M4DA_StreamTypeAudioPcm:
1012            decoderType = M4AD_kTypePCM;
1013            break;
1014
1015        default:
1016            M4OSA_DEBUG_IF1(M4OSA_TRUE,
1017                M4VSS3GPP_ERR_UNSUPPORTED_INPUT_AUDIO_FORMAT,
1018                "Audio decoder type not supported");
1019            return M4VSS3GPP_ERR_UNSUPPORTED_INPUT_AUDIO_FORMAT;
1020    }
1021
1022    pC->m_pAudioDecoder = pC->m_pAudioDecoderItTable[decoderType];
1023    pC->pCurrentAudioDecoderUserData =
1024        pC->pAudioDecoderUserDataTable[decoderType];
1025
1026    if( pC->m_pAudioDecoder == M4OSA_NULL )
1027    {
1028        M4OSA_DEBUG_IF1(M4OSA_TRUE,
1029            M4VSS3GPP_ERR_UNSUPPORTED_INPUT_AUDIO_FORMAT,
1030            "Audio decoder type not supported");
1031        M4OSA_TRACE1_0("Audio decoder type not supported");
1032        return M4VSS3GPP_ERR_UNSUPPORTED_INPUT_AUDIO_FORMAT;
1033    }
1034
1035    return M4NO_ERROR;
1036}
1037