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