summaryrefslogtreecommitdiffstats
path: root/libvideoeditor/vss/src/M4VSS3GPP_Codecs.c
blob: 1ced93798a3a92372701c5832b1d4cea7fc5227d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 *************************************************************************
 * @file   M4VSS3GPP_Codecs.c
 * @brief  VSS implementation
 * @note   This file contains all functions related to audio/video
 *            codec manipulations.
 *************************************************************************
 */

#include "NXPSW_CompilerSwitches.h"

#include "M4OSA_Debug.h"             /**< Include for OSAL debug services */
#include "M4VSS3GPP_ErrorCodes.h"
#include "M4VSS3GPP_InternalTypes.h" /**< Internal types of the VSS */

/**
 ************************************************************************
 * M4OSA_ERR   M4VSS3GPP_clearInterfaceTables()
 * @brief    Clear encoders, decoders, reader and writers interfaces tables
 * @param    pContext            (IN/OUT) VSS context.
 * @return    M4NO_ERROR:            No error
 * @return    M4ERR_PARAMETER:    The context is null
 ************************************************************************
 */
M4OSA_ERR M4VSS3GPP_clearInterfaceTables( M4VSS3GPP_MediaAndCodecCtxt *pC )
{
    M4OSA_UInt8 i;

    M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER,
        "invalid context pointer");

    /* Initialisation that will allow to check if registering twice */
    pC->pWriterGlobalFcts = M4OSA_NULL;
    pC->pWriterDataFcts = M4OSA_NULL;
    pC->pVideoEncoderGlobalFcts = M4OSA_NULL;
    pC->pAudioEncoderGlobalFcts = M4OSA_NULL;
    pC->pCurrentAudioEncoderUserData = M4OSA_NULL;
    pC->pCurrentAudioDecoderUserData = M4OSA_NULL;

    pC->pCurrentVideoEncoderExternalAPI = M4OSA_NULL;
    pC->pCurrentVideoEncoderUserData = M4OSA_NULL;

    for ( i = 0; i < M4WRITER_kType_NB; i++ )
    {
        pC->WriterInterface[i].pGlobalFcts = M4OSA_NULL;
        pC->WriterInterface[i].pDataFcts = M4OSA_NULL;
    }

    for ( i = 0; i < M4ENCODER_kVideo_NB; i++ )
    {
        pC->pVideoEncoderInterface[i] = M4OSA_NULL;
        pC->pVideoEncoderExternalAPITable[i] = M4OSA_NULL;
        pC->pVideoEncoderUserDataTable[i] = M4OSA_NULL;
    }

    for ( i = 0; i < M4ENCODER_kAudio_NB; i++ )
    {
        pC->pAudioEncoderInterface[i] = M4OSA_NULL;
        pC->pAudioEncoderFlag[i] = M4OSA_FALSE;
        pC->pAudioEncoderUserDataTable[i] = M4OSA_NULL;
    }

    /* Initialisation that will allow to check if registering twice */
    pC->m_pReader = M4OSA_NULL;
    pC->m_pReaderDataIt = M4OSA_NULL;
    pC->m_uiNbRegisteredReaders = 0;

    for ( i = 0; i < M4READER_kMediaType_NB; i++ )
    {
        pC->m_pReaderGlobalItTable[i] = M4OSA_NULL;
        pC->m_pReaderDataItTable[i] = M4OSA_NULL;
    }

    pC->m_pVideoDecoder = M4OSA_NULL;
#ifdef M4VSS_ENABLE_EXTERNAL_DECODERS

    pC->m_pCurrentVideoDecoderUserData = M4OSA_NULL;
#endif /* M4VSS_ENABLE_EXTERNAL_DECODERS */

    pC->m_uiNbRegisteredVideoDec = 0;

    for ( i = 0; i < M4DECODER_kVideoType_NB; i++ )
    {
        pC->m_pVideoDecoderItTable[i] = M4OSA_NULL;
#ifdef M4VSS_ENABLE_EXTERNAL_DECODERS

        pC->m_pVideoDecoderUserDataTable[i] = M4OSA_NULL;

#endif /* M4VSS_ENABLE_EXTERNAL_DECODERS */

    }

    pC->m_pAudioDecoder = M4OSA_NULL;

    for ( i = 0; i < M4AD_kType_NB; i++ )
    {
        pC->m_pAudioDecoderItTable[i] = M4OSA_NULL;
        pC->m_pAudioDecoderFlagTable[i] = M4OSA_FALSE;
        pC->pAudioDecoderUserDataTable[i] = M4OSA_NULL;
    }

    return M4NO_ERROR;
}

/**
 ******************************************************************************
 * M4OSA_ERR   M4VSS3GPP_registerWriter()
 * @brief    This function will register a specific file format writer.
 * @note    According to the Mediatype, this function will store in the internal
 *        context the writer context.
 * @param    pContext:    (IN) Execution context.
 * @return    M4NO_ERROR: there is no error
 * @return    M4ERR_PARAMETER    pContext,pWtrGlobalInterface or pWtrDataInterface is M4OSA_NULL
 *                          (debug only), or invalid MediaType
 ******************************************************************************
 */
M4OSA_ERR M4VSS3GPP_registerWriter( M4VSS3GPP_MediaAndCodecCtxt *pC,
                                   M4WRITER_OutputFileType MediaType,
                                   M4WRITER_GlobalInterface *pWtrGlobalInterface,
                                   M4WRITER_DataInterface *pWtrDataInterface )
{
    /**
    *    Check input parameters */
    M4OSA_DEBUG_IF2((pC == M4OSA_NULL), M4ERR_PARAMETER,
        "VSS: context is M4OSA_NULL in M4VSS3GPP_registerWriter");
    M4OSA_DEBUG_IF2((pWtrGlobalInterface == M4OSA_NULL), M4ERR_PARAMETER,
        "pWtrGlobalInterface is M4OSA_NULL in M4VSS3GPP_registerWriter");
    M4OSA_DEBUG_IF2((pWtrDataInterface == M4OSA_NULL), M4ERR_PARAMETER,
        "pWtrDataInterface is M4OSA_NULL in M4VSS3GPP_registerWriter");

    M4OSA_TRACE3_3(
        "VSS: M4VSS3GPP_registerWriter called with pContext=0x%x, pWtrGlobalInterface=0x%x,\
        pWtrDataInterface=0x%x",
        pC, pWtrGlobalInterface, pWtrDataInterface);

    if( ( MediaType == M4WRITER_kUnknown) || (MediaType >= M4WRITER_kType_NB) )
    {
        M4OSA_DEBUG_IF1(M4OSA_TRUE, M4ERR_PARAMETER, "Invalid media type");
        return M4ERR_PARAMETER;
    }

    if( pC->WriterInterface[MediaType].pGlobalFcts != M4OSA_NULL )
    {
        /* a writer corresponding to this media type has already been registered !*/
        M4OSA_DEBUG_IF1(M4OSA_TRUE, M4ERR_PARAMETER,
            "This media type has already been registered");
        return M4ERR_PARAMETER;
    }

    /*
    * Save writer interface in context */
    pC->WriterInterface[MediaType].pGlobalFcts = pWtrGlobalInterface;
    pC->WriterInterface[MediaType].pDataFcts = pWtrDataInterface;

    return M4NO_ERROR;
}

/**
 ******************************************************************************
 * M4OSA_ERR   M4VSS3GPP_registerVideoEncoder()
 * @brief    This function will register a specific video encoder.
 * @note    According to the Mediatype, this function will store in the internal
 *        context the encoder context.
 * @param    pContext:    (IN) Execution context.
 * @return    M4NO_ERROR: there is no error
 * @return    M4ERR_PARAMETER    pContext or pEncGlobalInterface is M4OSA_NULL (debug only),
 *                          or invalid MediaType
 ******************************************************************************
 */
M4OSA_ERR M4VSS3GPP_registerVideoEncoder( M4VSS3GPP_MediaAndCodecCtxt *pC,
                                         M4ENCODER_Format MediaType,
                                         M4ENCODER_GlobalInterface *pEncGlobalInterface )
{
    /**
    *    Check input parameters */
    M4OSA_DEBUG_IF2((pC == M4OSA_NULL), M4ERR_PARAMETER,
        "VSS: context is M4OSA_NULL in M4VSS3GPP_registerVideoEncoder");
    M4OSA_DEBUG_IF2((pEncGlobalInterface == M4OSA_NULL), M4ERR_PARAMETER,
        "pEncGlobalInterface is M4OSA_NULL in M4VSS3GPP_registerVideoEncoder");

    M4OSA_TRACE3_3(
        "VSS: M4VSS3GPP_registerEncoder called with pContext=0x%x, pEncGlobalInterface=0x%x,\
        MediaType=0x%x",
        pC, pEncGlobalInterface, MediaType);

    if( MediaType >= M4ENCODER_kVideo_NB )
    {
        M4OSA_DEBUG_IF1(M4OSA_TRUE, M4ERR_PARAMETER,
            "Invalid video encoder type");
        return M4ERR_PARAMETER;
    }

    if( pC->pVideoEncoderInterface[MediaType] != M4OSA_NULL )
    {
        /* can be legitimate, in cases where we have one version that can use external encoders
        but which still has the built-in one to be able to work without an external encoder; in
        this case the new encoder simply replaces the old one (i.e. we unregister it first). */
#ifdef M4VSS_SUPPORT_OMX_CODECS

        if( M4OSA_TRUE == pC->bAllowFreeingOMXCodecInterface )
        {

#endif

            free(pC->pVideoEncoderInterface[MediaType]);
#ifdef M4VSS_SUPPORT_OMX_CODECS

        }

#endif

        pC->pVideoEncoderInterface[MediaType] = M4OSA_NULL;
    }

    /*
    * Save encoder interface in context */
    pC->pVideoEncoderInterface[MediaType] = pEncGlobalInterface;
    /* The actual userData and external API will be set by the registration function in the case
    of an external encoder (add it as a parameter to this function in the long run?) */
    pC->pVideoEncoderUserDataTable[MediaType] = M4OSA_NULL;
    pC->pVideoEncoderExternalAPITable[MediaType] = M4OSA_NULL;

    return M4NO_ERROR;
}

/**
 ******************************************************************************
 * M4OSA_ERR   M4VSS3GPP_registerAudioEncoder()
 * @brief    This function will register a specific audio encoder.
 * @note    According to the Mediatype, this function will store in the internal
 *        context the encoder context.
 * @param    pContext:                (IN) Execution context.
 * @param    mediaType:                (IN) The media type.
 * @param    pEncGlobalInterface:    (OUT) the encoder interface functions.
 * @return    M4NO_ERROR: there is no error
 * @return    M4ERR_PARAMETER: pContext or pEncGlobalInterface is M4OSA_NULL (debug only)
 ******************************************************************************
 */
M4OSA_ERR M4VSS3GPP_registerAudioEncoder( M4VSS3GPP_MediaAndCodecCtxt *pC,
                                         M4ENCODER_AudioFormat MediaType,
                                         M4ENCODER_AudioGlobalInterface *pEncGlobalInterface )
{
    /**
    *    Check input parameters */
    M4OSA_DEBUG_IF2((pC == M4OSA_NULL), M4ERR_PARAMETER,
        "VSS: context is M4OSA_NULL in M4VSS3GPP_registerAudioEncoder");
    M4OSA_DEBUG_IF2((pEncGlobalInterface == M4OSA_NULL), M4ERR_PARAMETER,
        "pEncGlobalInterface is M4OSA_NULL in M4VSS3GPP_registerAudioEncoder");

    M4OSA_TRACE3_3(
        "VSS: M4VSS3GPP_registerAudioEncoder called pContext=0x%x, pEncGlobalInterface=0x%x,\
        MediaType=0x%x",
        pC, pEncGlobalInterface, MediaType);

    if( MediaType >= M4ENCODER_kAudio_NB )
    {
        M4OSA_DEBUG_IF1(M4OSA_TRUE, M4ERR_PARAMETER,
            "Invalid audio encoder type");
        return M4ERR_PARAMETER;
    }

    if( pC->pAudioEncoderInterface[MediaType] != M4OSA_NULL )
    {
        free(pC->pAudioEncoderInterface[MediaType]);
        pC->pAudioEncoderInterface[MediaType] = M4OSA_NULL;
    }
    /*
    * Save encoder interface in context */
    pC->pAudioEncoderInterface[MediaType] = pEncGlobalInterface;
    pC->pAudioEncoderFlag[MediaType] = M4OSA_FALSE; /* internal encoder */
    pC->pAudioEncoderUserDataTable[MediaType] = M4OSA_NULL;

    M4OSA_TRACE3_2(
        "M4VSS3GPP_registerAudioEncoder: pC->pAudioEncoderInterface[0x%x] = 0x%x",
        MediaType, pC->pAudioEncoderInterface[MediaType]);

    return M4NO_ERROR;
}

/**
 ************************************************************************
 * M4OSA_ERR   M4VSS3GPP_registerReader()
 * @brief    Register reader.
 * @param    pContext            (IN/OUT) VSS context.
 * @return    M4NO_ERROR:            No error
 * @return    M4ERR_PARAMETER:    A parameter is null (in DEBUG only)
 ************************************************************************
 */
M4OSA_ERR M4VSS3GPP_registerReader( M4VSS3GPP_MediaAndCodecCtxt *pC,
                                   M4READER_MediaType mediaType,
                                   M4READER_GlobalInterface *pRdrGlobalInterface,
                                   M4READER_DataInterface *pRdrDataInterface )
{
    M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER,
        "invalid context pointer");
    M4OSA_DEBUG_IF1((M4OSA_NULL == pRdrGlobalInterface), M4ERR_PARAMETER,
        "M4VSS3GPP_registerReader: invalid pointer on global interface");
    M4OSA_DEBUG_IF1((M4OSA_NULL == pRdrDataInterface), M4ERR_PARAMETER,
        "M4VSS3GPP_registerReader: invalid pointer on data interface");

    if( mediaType == M4READER_kMediaTypeUnknown
        || mediaType >= M4READER_kMediaType_NB )
    {
        M4OSA_DEBUG_IF1(M4OSA_TRUE, M4ERR_PARAMETER, "Invalid media type");
        return M4ERR_PARAMETER;
    }

    if( pC->m_pReaderGlobalItTable[mediaType] != M4OSA_NULL )
    {
        /* a reader corresponding to this media type has already been registered !*/
        M4OSA_DEBUG_IF1(M4OSA_TRUE, M4ERR_PARAMETER,
            "This media type has already been registered");
        return M4ERR_PARAMETER;
    }

    pC->m_pReaderGlobalItTable[mediaType] = pRdrGlobalInterface;
    pC->m_pReaderDataItTable[mediaType] = pRdrDataInterface;

    pC->m_uiNbRegisteredReaders++;

    return M4NO_ERROR;
}

/**
 ************************************************************************
 * M4OSA_ERR   M4VSS3GPP_registerVideoDecoder()
 * @brief    Register video decoder
 * @param    pContext                (IN/OUT) VSS context.
 * @param    decoderType            (IN) Decoder type
 * @param    pDecoderInterface    (IN) Decoder interface.
 * @return    M4NO_ERROR:            No error
 * @return    M4ERR_PARAMETER:    A parameter is null (in DEBUG only),
 *                                or the decoder type is invalid
 ************************************************************************
 */
M4OSA_ERR M4VSS3GPP_registerVideoDecoder( M4VSS3GPP_MediaAndCodecCtxt *pC,
                                         M4DECODER_VideoType decoderType,
                                         M4DECODER_VideoInterface *pDecoderInterface )
{
    M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER,
        "invalid context pointer");
    M4OSA_DEBUG_IF1((M4OSA_NULL == pDecoderInterface), M4ERR_PARAMETER,
        "M4VSS3GPP_registerVideoDecoder: invalid pointer on decoder interface");

    if( decoderType >= M4DECODER_kVideoType_NB )
    {
        M4OSA_DEBUG_IF1(M4OSA_TRUE, M4ERR_PARAMETER,
            "Invalid video decoder type");
        return M4ERR_PARAMETER;
    }

    if( pC->m_pVideoDecoderItTable[decoderType] != M4OSA_NULL )
    {
#ifndef M4VSS_ENABLE_EXTERNAL_DECODERS
        /* a decoder corresponding to this media type has already been registered !*/

        M4OSA_DEBUG_IF1(M4OSA_TRUE, M4ERR_PARAMETER,
            "Decoder has already been registered");
        return M4ERR_PARAMETER;

#else /* external decoders are possible */
        /* can be legitimate, in cases where we have one version that can use external decoders
        but which still has the built-in one to be able to work without an external decoder; in
        this case the new decoder simply replaces the old one (i.e. we unregister it first). */
#ifdef M4VSS_SUPPORT_OMX_CODECS

        if( M4OSA_TRUE == pC->bAllowFreeingOMXCodecInterface )
        {

#endif

            free(pC->m_pVideoDecoderItTable[decoderType]);
#ifdef M4VSS_SUPPORT_OMX_CODECS

        }

#endif

        pC->m_pVideoDecoderItTable[decoderType] = M4OSA_NULL;
        /* oh, and don't forget the user data, too. */
        if( pC->m_pVideoDecoderUserDataTable[decoderType] != M4OSA_NULL )
        {
            free(pC->m_pVideoDecoderUserDataTable[decoderType]);
            pC->m_pVideoDecoderUserDataTable[decoderType] = M4OSA_NULL;
        }
#endif /* are external decoders possible? */

    }

    pC->m_pVideoDecoderItTable[decoderType] = pDecoderInterface;
#ifdef M4VSS_ENABLE_EXTERNAL_DECODERS

    pC->m_pVideoDecoderUserDataTable[decoderType] = M4OSA_NULL;
    /* The actual userData will be set by the registration function in the case
    of an external decoder (add it as a parameter to this function in the long run?) */

#endif /* M4VSS_ENABLE_EXTERNAL_DECODERS */

    pC->m_uiNbRegisteredVideoDec++;

    return M4NO_ERROR;
}

/**
 ************************************************************************
 * M4OSA_ERR   M4VSS3GPP_registerAudioDecoder()
 * @brief    Register audio decoder
 * @note    This function is used internaly by the VSS to register NXP audio decoders,
 * @param    context                (IN/OUT) VSS context.
 * @param    decoderType            (IN) Audio decoder type
 * @param    pDecoderInterface    (IN) Audio decoder interface.
 * @return    M4NO_ERROR:            No error
 * @return    M4ERR_PARAMETER:   A parameter is null, or the decoder type is invalid(in DEBUG only)
 ************************************************************************
 */
M4OSA_ERR M4VSS3GPP_registerAudioDecoder( M4VSS3GPP_MediaAndCodecCtxt *pC,
                                         M4AD_Type decoderType, M4AD_Interface *pDecoderInterface)
{
    M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER,
        "invalid context pointer");
    M4OSA_DEBUG_IF1((M4OSA_NULL == pDecoderInterface), M4ERR_PARAMETER,
        "M4VSS3GPP_registerAudioDecoder: invalid pointer on decoder interface");

    if( decoderType >= M4AD_kType_NB )
    {
        M4OSA_DEBUG_IF1(M4OSA_TRUE, M4ERR_PARAMETER,
            "Invalid audio decoder type");
        return M4ERR_PARAMETER;
    }
    if(M4OSA_NULL != pC->m_pAudioDecoderItTable[decoderType])
    {
        free(pC->m_pAudioDecoderItTable[decoderType]);
        pC->m_pAudioDecoderItTable[decoderType] = M4OSA_NULL;

        if(M4OSA_NULL != pC->m_pAudioDecoderItTable[decoderType])
        {
            free(pC->m_pAudioDecoderItTable[decoderType]);
            pC->m_pAudioDecoderItTable[decoderType] = M4OSA_NULL;
        }
    }



    pC->m_pAudioDecoderItTable[decoderType] = pDecoderInterface;
    pC->m_pAudioDecoderFlagTable[decoderType] =
        M4OSA_FALSE; /* internal decoder */
    pC->pAudioDecoderUserDataTable[decoderType] = M4OSA_NULL;

    return M4NO_ERROR;
}

/**
 ************************************************************************
 * M4OSA_ERR   M4VSS3GPP_unRegisterAllWriters()
 * @brief    Unregister writer
 * @param    pContext            (IN/OUT) VSS context.
 * @return    M4NO_ERROR:            No error
 * @return    M4ERR_PARAMETER:    A parameter is null (in DEBUG only)
 ************************************************************************
 */
M4OSA_ERR M4VSS3GPP_unRegisterAllWriters( M4VSS3GPP_MediaAndCodecCtxt *pC )
{
    M4OSA_Int32 i;

    M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER,
        "invalid context pointer");

    for ( i = 0; i < M4WRITER_kType_NB; i++ )
    {
        if( pC->WriterInterface[i].pGlobalFcts != M4OSA_NULL )
        {
            free(pC->WriterInterface[i].pGlobalFcts);
            pC->WriterInterface[i].pGlobalFcts = M4OSA_NULL;
        }

        if( pC->WriterInterface[i].pDataFcts != M4OSA_NULL )
        {
            free(pC->WriterInterface[i].pDataFcts);
            pC->WriterInterface[i].pDataFcts = M4OSA_NULL;
        }
    }

    pC->pWriterGlobalFcts = M4OSA_NULL;
    pC->pWriterDataFcts = M4OSA_NULL;

    return M4NO_ERROR;
}

/**
 ************************************************************************
 * M4OSA_ERR   M4VSS3GPP_unRegisterAllEncoders()
 * @brief    Unregister the encoders
 * @param    pContext            (IN/OUT) VSS context.
 * @return    M4NO_ERROR:            No error
 * @return    M4ERR_PARAMETER:    A parameter is null (in DEBUG only)
 ************************************************************************
 */
M4OSA_ERR M4VSS3GPP_unRegisterAllEncoders( M4VSS3GPP_MediaAndCodecCtxt *pC )
{
    M4OSA_Int32 i;

    M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER,
        "invalid context pointer");
    M4OSA_TRACE3_1("M4VSS3GPP_unRegisterAllEncoders: pC=0x%x", pC);

    for ( i = 0; i < M4ENCODER_kVideo_NB; i++ )
    {
        if( pC->pVideoEncoderInterface[i] != M4OSA_NULL )
        {
#ifdef M4VSS_SUPPORT_OMX_CODECS

            if( M4OSA_TRUE == pC->bAllowFreeingOMXCodecInterface )
            {

#endif

                free(pC->pVideoEncoderInterface[i]);
#ifdef M4VSS_SUPPORT_OMX_CODECS

            }

#endif

            pC->pVideoEncoderInterface[i] = M4OSA_NULL;
        }
    }

    for ( i = 0; i < M4ENCODER_kAudio_NB; i++ )
    {
        if( pC->pAudioEncoderInterface[i] != M4OSA_NULL )
        {
#ifdef M4VSS_SUPPORT_OMX_CODECS

            if( M4OSA_TRUE == pC->bAllowFreeingOMXCodecInterface )
            {

#endif
                /*Don't free external audio encoders interfaces*/

                if( M4OSA_FALSE == pC->pAudioEncoderFlag[i] )
                {
                    free(pC->pAudioEncoderInterface[i]);
                }
#ifdef M4VSS_SUPPORT_OMX_CODECS

            }

#endif

            pC->pAudioEncoderInterface[i] = M4OSA_NULL;
        }
    }

    pC->pVideoEncoderGlobalFcts = M4OSA_NULL;
    pC->pAudioEncoderGlobalFcts = M4OSA_NULL;

    return M4NO_ERROR;
}

/**
 ************************************************************************
 * M4OSA_ERR   M4VSS3GPP_unRegisterAllReaders()
 * @brief    Unregister reader
 * @param    pContext            (IN/OUT) VSS context.
 * @return    M4NO_ERROR:            No error
 * @return    M4ERR_PARAMETER:    A parameter is null (in DEBUG only)
 ************************************************************************
 */
M4OSA_ERR M4VSS3GPP_unRegisterAllReaders( M4VSS3GPP_MediaAndCodecCtxt *pC )
{
    M4OSA_Int32 i;

    M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER,
        "invalid context pointer");

    for ( i = 0; i < M4READER_kMediaType_NB; i++ )
    {
        if( pC->m_pReaderGlobalItTable[i] != M4OSA_NULL )
        {
            free(pC->m_pReaderGlobalItTable[i]);
            pC->m_pReaderGlobalItTable[i] = M4OSA_NULL;
        }

        if( pC->m_pReaderDataItTable[i] != M4OSA_NULL )
        {
            free(pC->m_pReaderDataItTable[i]);
            pC->m_pReaderDataItTable[i] = M4OSA_NULL;
        }
    }

    pC->m_uiNbRegisteredReaders = 0;
    pC->m_pReader = M4OSA_NULL;
    pC->m_pReaderDataIt = M4OSA_NULL;

    return M4NO_ERROR;
}

/**
 ************************************************************************
 * M4OSA_ERR   M4VSS3GPP_unRegisterAllDecoders()
 * @brief    Unregister the decoders
 * @param    pContext            (IN/OUT) VSS context.
 * @return    M4NO_ERROR:            No error
 * @return    M4ERR_PARAMETER:    A parameter is null (in DEBUG only)
 ************************************************************************
 */
M4OSA_ERR M4VSS3GPP_unRegisterAllDecoders( M4VSS3GPP_MediaAndCodecCtxt *pC )
{
    M4OSA_Int32 i;

    M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER,
        "invalid context pointer");
    M4OSA_TRACE3_1("M4VSS3GPP_unRegisterAllDecoders: pC=0x%x", pC);

    for ( i = 0; i < M4DECODER_kVideoType_NB; i++ )
    {
        if( pC->m_pVideoDecoderItTable[i] != M4OSA_NULL )
        {
#ifdef M4VSS_SUPPORT_OMX_CODECS

            if( M4OSA_TRUE == pC->bAllowFreeingOMXCodecInterface )
            {

#endif

                free(pC->m_pVideoDecoderItTable[i]);
#ifdef M4VSS_SUPPORT_OMX_CODECS

            }

#endif

            pC->m_pVideoDecoderItTable[i] = M4OSA_NULL;

        }
    }

    for ( i = 0; i < M4AD_kType_NB; i++ )
    {
        if( pC->m_pAudioDecoderItTable[i] != M4OSA_NULL )
        {
#ifdef M4VSS_SUPPORT_OMX_CODECS

            if( M4OSA_TRUE == pC->bAllowFreeingOMXCodecInterface )
            {

#endif
                /*Don't free external audio decoders interfaces*/

                if( M4OSA_FALSE == pC->m_pAudioDecoderFlagTable[i] )
                {
                    free(pC->m_pAudioDecoderItTable[i]);
                }
#ifdef M4VSS_SUPPORT_OMX_CODECS

            }

#endif

            pC->m_pAudioDecoderItTable[i] = M4OSA_NULL;
        }
    }

    pC->m_uiNbRegisteredVideoDec = 0;
    pC->m_pVideoDecoder = M4OSA_NULL;

    pC->m_pAudioDecoder = M4OSA_NULL;

    return M4NO_ERROR;
}

/**
 ************************************************************************
 * M4OSA_ERR   M4VSS3GPP_setCurrentWriter()
 * @brief    Set current writer
 * @param    pContext            (IN/OUT) VSS context.
 * @param    mediaType            (IN) Media type.
 * @return    M4NO_ERROR:            No error
 * @return    M4ERR_PARAMETER:                    A parameter is null (in DEBUG only)
 * @return    M4WAR_VSS_MEDIATYPE_NOT_SUPPORTED:    Media type not supported
 ************************************************************************
 */
M4OSA_ERR M4VSS3GPP_setCurrentWriter( M4VSS3GPP_MediaAndCodecCtxt *pC,
                                     M4VIDEOEDITING_FileType mediaType )
{
    M4WRITER_OutputFileType writerType;

    M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER,
        "invalid context pointer");

    switch( mediaType )
    {
        case M4VIDEOEDITING_kFileType_3GPP:
            writerType = M4WRITER_k3GPP;
            break;
        default:
            M4OSA_DEBUG_IF1(M4OSA_TRUE, M4VSS3GPP_ERR_INVALID_FILE_TYPE,
                "Writer type not supported");
            return M4VSS3GPP_ERR_INVALID_FILE_TYPE;
    }

    pC->pWriterGlobalFcts = pC->WriterInterface[writerType].pGlobalFcts;
    pC->pWriterDataFcts = pC->WriterInterface[writerType].pDataFcts;

    if( pC->pWriterGlobalFcts == M4OSA_NULL
        || pC->pWriterDataFcts == M4OSA_NULL )
    {
        M4OSA_DEBUG_IF1(M4OSA_TRUE, M4VSS3GPP_ERR_INVALID_FILE_TYPE,
            "Writer type not supported");
        M4OSA_TRACE1_0("Writer type not supported");
        return M4VSS3GPP_ERR_INVALID_FILE_TYPE;
    }

    pC->pWriterDataFcts->pWriterContext = M4OSA_NULL;

    return M4NO_ERROR;
}

/**
 ************************************************************************
 * M4OSA_ERR   M4VSS3GPP_setCurrentVideoEncoder()
 * @brief    Set a video encoder
 * @param    pContext            (IN/OUT) VSS context.
 * @param    MediaType           (IN) Encoder type
 * @return    M4NO_ERROR:            No error
 * @return    M4ERR_PARAMETER:                    A parameter is null (in DEBUG only)
 * @return    M4WAR_VSS_MEDIATYPE_NOT_SUPPORTED:    Media type not supported
 ************************************************************************
 */
M4OSA_ERR M4VSS3GPP_setCurrentVideoEncoder( M4VSS3GPP_MediaAndCodecCtxt *pC,
                                           M4SYS_StreamType mediaType )
{
    M4ENCODER_Format encoderType;

    M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER,
        "invalid context pointer");
    M4OSA_TRACE3_2("M4VSS3GPP_setCurrentVideoEncoder: pC=0x%x, mediaType=0x%x",
        pC, mediaType);

    switch( mediaType )
    {
        case M4SYS_kH263:
            encoderType = M4ENCODER_kH263;
            break;

        case M4SYS_kMPEG_4:
            encoderType = M4ENCODER_kMPEG4;
            break;

        case M4SYS_kH264:
            encoderType = M4ENCODER_kH264;
            break;

        default:
            M4OSA_DEBUG_IF1(M4OSA_TRUE,
                M4VSS3GPP_ERR_EDITING_UNSUPPORTED_VIDEO_FORMAT,
                "Video encoder type not supported");
            return M4VSS3GPP_ERR_EDITING_UNSUPPORTED_VIDEO_FORMAT;
    }

    pC->pVideoEncoderGlobalFcts = pC->pVideoEncoderInterface[encoderType];
    pC->pCurrentVideoEncoderExternalAPI =
        pC->pVideoEncoderExternalAPITable[encoderType];
    pC->pCurrentVideoEncoderUserData =
        pC->pVideoEncoderUserDataTable[encoderType];

    if( pC->pVideoEncoderGlobalFcts == M4OSA_NULL )
    {
        M4OSA_DEBUG_IF1(M4OSA_TRUE,
            M4VSS3GPP_ERR_EDITING_UNSUPPORTED_VIDEO_FORMAT,
            "Video encoder type not supported");
        M4OSA_TRACE1_0("Video encoder type not supported");
        return M4VSS3GPP_ERR_EDITING_UNSUPPORTED_VIDEO_FORMAT;
    }

    return M4NO_ERROR;
}

/**
 ************************************************************************
 * M4OSA_ERR   M4VSS3GPP_setCurrentAudioEncoder()
 * @brief    Set an audio encoder
 * @param    context            (IN/OUT) VSS context.
 * @param    MediaType        (IN) Encoder type
 * @return    M4NO_ERROR:            No error
 * @return    M4ERR_PARAMETER:    A parameter is null (in DEBUG only)
 ************************************************************************
 */
M4OSA_ERR M4VSS3GPP_setCurrentAudioEncoder( M4VSS3GPP_MediaAndCodecCtxt *pC,
                                           M4SYS_StreamType mediaType )
{
    M4ENCODER_AudioFormat encoderType;

    M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER,
        "invalid context pointer");
    M4OSA_TRACE3_2("M4VSS3GPP_setCurrentAudioEncoder: pC=0x%x, mediaType=0x%x",
        pC, mediaType);

    switch( mediaType )
    {
        case M4SYS_kAMR:
            M4OSA_TRACE3_0(
                "M4VSS3GPP_setCurrentAudioEncoder: encoder type AMR");
            encoderType = M4ENCODER_kAMRNB;
            break;

        case M4SYS_kAAC:
            M4OSA_TRACE3_0(
                "M4VSS3GPP_setCurrentAudioEncoder: encoder type AAC");
            encoderType = M4ENCODER_kAAC;
            break;

       default:
            M4OSA_DEBUG_IF1(M4OSA_TRUE,
                M4VSS3GPP_ERR_EDITING_UNSUPPORTED_AUDIO_FORMAT,
                "Audio encoder type not supported");
            return M4VSS3GPP_ERR_EDITING_UNSUPPORTED_AUDIO_FORMAT;
    }

    pC->pAudioEncoderGlobalFcts = pC->pAudioEncoderInterface[encoderType];
    pC->pCurrentAudioEncoderUserData =
        pC->pAudioEncoderUserDataTable[encoderType];

    M4OSA_TRACE3_3(
        "M4VSS3GPP_setCurrentAudioEncoder: pC->pAudioEncoderInterface[0x%x]=0x%x,\
        pC->pAudioEncoderGlobalFcts = 0x%x",
        encoderType, pC->pAudioEncoderInterface[encoderType],
        pC->pAudioEncoderGlobalFcts);

    if( pC->pAudioEncoderGlobalFcts == M4OSA_NULL )
    {
        M4OSA_DEBUG_IF1(M4OSA_TRUE,
            M4VSS3GPP_ERR_EDITING_UNSUPPORTED_AUDIO_FORMAT,
            "Audio encoder type not supported");
        M4OSA_TRACE1_0("Audio encoder type not supported");
        return M4VSS3GPP_ERR_EDITING_UNSUPPORTED_AUDIO_FORMAT;
    }

    return M4NO_ERROR;
}

/**
 ************************************************************************
 * M4OSA_ERR   M4VSS3GPP_setCurrentReader()
 * @brief    Set current reader
 * @param    pContext            (IN/OUT) VSS context.
 * @param    mediaType            (IN) Media type.
 * @return    M4NO_ERROR:            No error
 * @return    M4ERR_PARAMETER:                    A parameter is null (in DEBUG only)
 * @return    M4WAR_VSS_MEDIATYPE_NOT_SUPPORTED:    Media type not supported
 ************************************************************************
 */
M4OSA_ERR M4VSS3GPP_setCurrentReader( M4VSS3GPP_MediaAndCodecCtxt *pC,
                                     M4VIDEOEDITING_FileType mediaType )
{
    M4READER_MediaType readerType;

    M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER,
        "invalid context pointer");

    switch( mediaType )
    {
        case M4VIDEOEDITING_kFileType_3GPP:
        case M4VIDEOEDITING_kFileType_MP4:
        case M4VIDEOEDITING_kFileType_M4V:
            readerType = M4READER_kMediaType3GPP;
            break;

        case M4VIDEOEDITING_kFileType_AMR:
            readerType = M4READER_kMediaTypeAMR;
            break;

        case M4VIDEOEDITING_kFileType_MP3:
            readerType = M4READER_kMediaTypeMP3;
            break;

        case M4VIDEOEDITING_kFileType_PCM:
            readerType = M4READER_kMediaTypePCM;
            break;

        default:
            M4OSA_DEBUG_IF1(M4OSA_TRUE, M4VSS3GPP_ERR_INVALID_FILE_TYPE,
                "Reader type not supported");
            return M4VSS3GPP_ERR_INVALID_FILE_TYPE;
    }

    pC->m_pReader = pC->m_pReaderGlobalItTable[readerType];
    pC->m_pReaderDataIt = pC->m_pReaderDataItTable[readerType];

    if( pC->m_pReader == M4OSA_NULL || pC->m_pReaderDataIt == M4OSA_NULL )
    {
        M4OSA_DEBUG_IF1(M4OSA_TRUE, M4VSS3GPP_ERR_INVALID_FILE_TYPE,
            "Reader type not supported");
        M4OSA_TRACE1_0("Reader type not supported");
        return M4VSS3GPP_ERR_INVALID_FILE_TYPE;
    }
    return M4NO_ERROR;
}

/**
 ************************************************************************
 * M4OSA_ERR   M4VSS3GPP_setCurrentVideoDecoder()
 * @brief    Set a video decoder
 * @param    pContext            (IN/OUT) VSS context.
 * @param    decoderType        (IN) Decoder type
 * @return    M4NO_ERROR:            No error
 * @return    M4ERR_PARAMETER:                    A parameter is null (in DEBUG only)
 * @return    M4WAR_VSS_MEDIATYPE_NOT_SUPPORTED:    Media type not supported
 ************************************************************************
 */
M4OSA_ERR M4VSS3GPP_setCurrentVideoDecoder( M4VSS3GPP_MediaAndCodecCtxt *pC,
                                           M4_StreamType mediaType )
{
    M4DECODER_VideoType decoderType;

    M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER,
        "invalid context pointer");
    M4OSA_TRACE3_2("M4VSS3GPP_setCurrentVideoDecoder: pC=0x%x, mediaType=0x%x",
        pC, mediaType);

    switch( mediaType )
    {
        case M4DA_StreamTypeVideoMpeg4:
        case M4DA_StreamTypeVideoH263:
            decoderType = M4DECODER_kVideoTypeMPEG4;
            break;

        case M4DA_StreamTypeVideoMpeg4Avc:
            decoderType = M4DECODER_kVideoTypeAVC;
            break;
        case M4DA_StreamTypeVideoARGB8888:
            decoderType = M4DECODER_kVideoTypeYUV420P;
            break;
        default:
            M4OSA_DEBUG_IF1(M4OSA_TRUE,
                M4VSS3GPP_ERR_UNSUPPORTED_INPUT_VIDEO_FORMAT,
                "Video decoder type not supported");
            return M4VSS3GPP_ERR_UNSUPPORTED_INPUT_VIDEO_FORMAT;
    }

    pC->m_pVideoDecoder = pC->m_pVideoDecoderItTable[decoderType];
#ifdef M4VSS_ENABLE_EXTERNAL_DECODERS

    pC->m_pCurrentVideoDecoderUserData =
        pC->m_pVideoDecoderUserDataTable[decoderType];

#endif /* M4VSS_ENABLE_EXTERNAL_DECODERS */

    if( pC->m_pVideoDecoder == M4OSA_NULL )
    {
        M4OSA_DEBUG_IF1(M4OSA_TRUE,
            M4VSS3GPP_ERR_UNSUPPORTED_INPUT_VIDEO_FORMAT,
            "Video decoder type not supported");
        M4OSA_TRACE1_0("Video decoder type not supported");
        return M4VSS3GPP_ERR_UNSUPPORTED_INPUT_VIDEO_FORMAT;
    }

    return M4NO_ERROR;
}

/**
 ************************************************************************
 * M4OSA_ERR   M4VSS3GPP_setCurrentAudioDecoder()
 * @brief    Set an audio decoder
 * @param    context            (IN/OUT) VSS context.
 * @param    decoderType        (IN) Decoder type
 * @return    M4NO_ERROR:            No error
 * @return    M4ERR_PARAMETER:    A parameter is null (in DEBUG only)
 ************************************************************************
 */
M4OSA_ERR M4VSS3GPP_setCurrentAudioDecoder( M4VSS3GPP_MediaAndCodecCtxt *pC,
                                           M4_StreamType mediaType )
{
    M4AD_Type decoderType;

    M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER,
        "invalid context pointer");
    M4OSA_TRACE3_2("M4VSS3GPP_setCurrentAudioDecoder: pC=0x%x, mediaType=0x%x",
        pC, mediaType);

    switch( mediaType )
    {
        case M4DA_StreamTypeAudioAmrNarrowBand:
            decoderType = M4AD_kTypeAMRNB;
            break;

        case M4DA_StreamTypeAudioAac:
        case M4DA_StreamTypeAudioAacADTS:
        case M4DA_StreamTypeAudioAacADIF:
            decoderType = M4AD_kTypeAAC;
            break;

        case M4DA_StreamTypeAudioMp3:
            decoderType = M4AD_kTypeMP3;
            break;

        case M4DA_StreamTypeAudioPcm:
            decoderType = M4AD_kTypePCM;
            break;

        default:
            M4OSA_DEBUG_IF1(M4OSA_TRUE,
                M4VSS3GPP_ERR_UNSUPPORTED_INPUT_AUDIO_FORMAT,
                "Audio decoder type not supported");
            return M4VSS3GPP_ERR_UNSUPPORTED_INPUT_AUDIO_FORMAT;
    }

    pC->m_pAudioDecoder = pC->m_pAudioDecoderItTable[decoderType];
    pC->pCurrentAudioDecoderUserData =
        pC->pAudioDecoderUserDataTable[decoderType];

    if( pC->m_pAudioDecoder == M4OSA_NULL )
    {
        M4OSA_DEBUG_IF1(M4OSA_TRUE,
            M4VSS3GPP_ERR_UNSUPPORTED_INPUT_AUDIO_FORMAT,
            "Audio decoder type not supported");
        M4OSA_TRACE1_0("Audio decoder type not supported");
        return M4VSS3GPP_ERR_UNSUPPORTED_INPUT_AUDIO_FORMAT;
    }

    return M4NO_ERROR;
}