VideoEditor3gpReader.cpp revision 13ecfb62545e521f807239864dc74ca1c295e3fa
1/*
2 * Copyright (C) 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   VideoEditor3gpReader.cpp
20* @brief  StageFright shell 3GP Reader
21*************************************************************************
22*/
23
24#define LOG_NDEBUG 1
25#define LOG_TAG "VIDEOEDITOR_3GPREADER"
26
27/**
28 * HEADERS
29 *
30 */
31#define VIDEOEDITOR_BITSTREAM_PARSER
32
33#include "M4OSA_Debug.h"
34#include "VideoEditor3gpReader.h"
35#include "M4SYS_AccessUnit.h"
36#include "VideoEditorUtils.h"
37#include "M4READER_3gpCom.h"
38#include "M4_Common.h"
39#include "M4OSA_FileWriter.h"
40
41#ifdef VIDEOEDITOR_BITSTREAM_PARSER
42#include "M4OSA_CoreID.h"
43#include "M4OSA_Error.h"
44#include "M4OSA_Memory.h"
45#include "M4_Utils.h"
46#endif
47
48#include "ESDS.h"
49#include "utils/Log.h"
50#include <media/stagefright/MediaBufferGroup.h>
51#include <media/stagefright/DataSource.h>
52#include <media/stagefright/FileSource.h>
53#include <media/stagefright/MediaBuffer.h>
54#include <media/stagefright/MediaDefs.h>
55#include <media/stagefright/MediaExtractor.h>
56#include <media/stagefright/MediaDebug.h>
57#include <media/stagefright/MediaSource.h>
58#include <media/stagefright/MetaData.h>
59
60/**
61 * SOURCE CLASS
62 */
63namespace android {
64/**
65 * ENGINE INTERFACE
66 */
67
68/**
69 ************************************************************************
70 * @brief   Array of AMR NB/WB bitrates
71 * @note    Array to match the mode and the bit rate
72 ************************************************************************
73*/
74const M4OSA_UInt32 VideoEditor3gpReader_AmrBitRate [2 /* 8kHz / 16kHz     */]
75                                                   [9 /* the bitrate mode */] =
76{
77    {4750, 5150, 5900,  6700,  7400,  7950,  10200, 12200, 0},
78    {6600, 8850, 12650, 14250, 15850, 18250, 19850, 23050, 23850}
79};
80
81/**
82 *******************************************************************************
83 * structure VideoEditor3gpReader_Context
84 * @brief:This structure defines the context of the StageFright 3GP shell Reader
85 *******************************************************************************
86*/
87typedef struct {
88    sp<DataSource>              mDataSource;
89    sp<MediaExtractor>          mExtractor;
90    sp<MediaSource>             mAudioSource;
91    sp<MediaSource>             mVideoSource;
92    M4_StreamHandler*           mAudioStreamHandler;
93    M4_StreamHandler*           mVideoStreamHandler;
94    M4SYS_AccessUnit            mAudioAu;
95    M4SYS_AccessUnit            mVideoAu;
96    M4OSA_Time                  mMaxDuration;
97    int32_t                     mFileSize;
98    M4_StreamType               mStreamType;
99    M4OSA_UInt32                mStreamId;
100    int32_t                     mTracks;
101    int32_t                     mCurrTrack;
102    M4OSA_Bool                  mAudioSeeking;
103    M4OSA_Time                  mAudioSeekTime;
104    M4OSA_Bool                  mVideoSeeking;
105    M4OSA_Time                  mVideoSeekTime;
106
107} VideoEditor3gpReader_Context;
108
109#ifdef VIDEOEDITOR_BITSTREAM_PARSER
110/**
111 ************************************************************************
112 * structure    VideoEditor3gpReader_BitStreamParserContext
113 * @brief       Internal BitStreamParser context
114 ************************************************************************
115*/
116typedef struct {
117    M4OSA_UInt32*   mPbitStream;   /**< bitstream pointer (32bits aligned) */
118    M4OSA_Int32     mSize;         /**< bitstream size in bytes */
119    M4OSA_Int32     mIndex;        /**< byte index */
120    M4OSA_Int32     mBitIndex;     /**< bit index */
121    M4OSA_Int32     mStructSize;   /**< size of structure */
122} VideoEditor3gpReader_BitStreamParserContext;
123
124/**
125 *******************************************************************************
126 * @brief   Allocates the context and initializes internal data.
127 * @param   pContext    (OUT)  Pointer to the BitStreamParser context to create.
128 * @param   bitStream   A pointer to the bitstream
129 * @param   size        The size of the bitstream in bytes
130 *******************************************************************************
131*/
132static void VideoEditor3gpReader_BitStreamParserInit(void** pContext,
133        void* pBitStream, M4OSA_Int32 size) {
134    VideoEditor3gpReader_BitStreamParserContext* pStreamContext;
135
136    *pContext=M4OSA_NULL;
137    pStreamContext = (VideoEditor3gpReader_BitStreamParserContext*)M4OSA_malloc(
138        sizeof(VideoEditor3gpReader_BitStreamParserContext), M4READER_3GP,
139            (M4OSA_Char*)"3GP BitStreamParser Context");
140    if (M4OSA_NULL == pStreamContext) {
141        return;
142    }
143    pStreamContext->mPbitStream=(M4OSA_UInt32*)pBitStream;
144    pStreamContext->mSize=size;
145    pStreamContext->mIndex=0;
146    pStreamContext->mBitIndex=0;
147    pStreamContext->mStructSize =
148        sizeof(VideoEditor3gpReader_BitStreamParserContext);
149
150    *pContext=pStreamContext;
151}
152/**
153 **********************************************************************
154 * @brief   Clean up context
155 * @param   pContext    (IN/OUT)  BitStreamParser context.
156 **********************************************************************
157*/
158static void VideoEditor3gpReader_BitStreamParserCleanUp(void* pContext) {
159    M4OSA_free((M4OSA_Int32*)pContext);
160}
161/**
162 *****************************************************************************
163 * @brief   Read the next <length> bits in the bitstream.
164 * @note    The function does not update the bitstream pointer.
165 * @param   pContext    (IN/OUT) BitStreamParser context.
166 * @param   length      (IN) The number of bits to extract from the bitstream
167 * @return  the read bits
168 *****************************************************************************
169*/
170static M4OSA_UInt32 VideoEditor3gpReader_BitStreamParserShowBits(void* pContext,
171        M4OSA_Int32 length) {
172    VideoEditor3gpReader_BitStreamParserContext* pStreamContext =
173        (VideoEditor3gpReader_BitStreamParserContext*)pContext;
174
175    M4OSA_UInt32 u_mask;
176    M4OSA_UInt32 retval;
177    M4OSA_Int32 i_ovf;
178
179    M4OSA_DEBUG_IF1((M4OSA_NULL==pStreamContext), 0,
180        "VideoEditor3gpReader_BitStreamParserShowBits:invalid context pointer");
181
182    retval=(M4OSA_UInt32)GET_MEMORY32(pStreamContext->\
183        mPbitStream[ pStreamContext->mIndex ]);
184    i_ovf = pStreamContext->mBitIndex + length - 32;
185    u_mask = (length >= 32) ? 0xffffffff: (1 << length) - 1;
186
187    /* do we have enough bits availble in the current word(32bits)*/
188    if (i_ovf <= 0) {
189        retval=(retval >> (- i_ovf)) & u_mask;
190    } else {
191        M4OSA_UInt32 u_nextword = (M4OSA_UInt32)GET_MEMORY32(
192            pStreamContext->mPbitStream[ pStreamContext->mIndex + 1 ]);
193        M4OSA_UInt32 u_msb_mask, u_msb_value, u_lsb_mask, u_lsb_value;
194
195        u_msb_mask = ((1 << (32 - pStreamContext->mBitIndex)) - 1) << i_ovf;
196        u_msb_value = retval << i_ovf;
197        u_lsb_mask = (1 << i_ovf) - 1;
198        u_lsb_value = u_nextword >> (32 - i_ovf);
199        retval= (u_msb_value & u_msb_mask ) | (u_lsb_value & u_lsb_mask);
200    }
201    /* return the bits...*/
202    return retval;
203}
204/**
205 ************************************************************************
206 * @brief   Increment the bitstream pointer of <length> bits.
207 * @param   pContext    (IN/OUT) BitStreamParser context.
208 * @param   length      (IN) The number of bit to shift the bitstream
209 ************************************************************************
210*/
211static void VideoEditor3gpReader_BitStreamParserFlushBits(void* pContext,
212        M4OSA_Int32 length) {
213    VideoEditor3gpReader_BitStreamParserContext* pStreamContext=(
214        VideoEditor3gpReader_BitStreamParserContext*)pContext;
215    M4OSA_Int32 val;
216
217    if (M4OSA_NULL == pStreamContext) {
218        return;
219    }
220    val=pStreamContext->mBitIndex + length;
221    /* update the bits...*/
222    pStreamContext->mBitIndex += length;
223
224    if (val - 32 >= 0) {
225        /* update the bits...*/
226        pStreamContext->mBitIndex -= 32;
227        /* update the words*/
228        pStreamContext->mIndex++;
229    }
230}
231
232static M4OSA_UInt32 VideoEditor3gpReader_BitStreamParserGetBits(
233        void* pContext,M4OSA_Int32 bitPos, M4OSA_Int32 bitLength) {
234    VideoEditor3gpReader_BitStreamParserContext* pStreamContext =
235        (VideoEditor3gpReader_BitStreamParserContext*)pContext;
236
237    M4OSA_Int32 bitLocation, bitIndex;
238    M4OSA_UInt32 retval=0;
239
240    M4OSA_DEBUG_IF1((M4OSA_NULL==pStreamContext), 0,
241        "VideoEditor3gpReader_BitStreamParserGetBits: invalid context pointer");
242
243    /* computes the word location*/
244    bitLocation=bitPos/32;
245    bitIndex=(bitPos) % 32;
246
247    if (bitLocation < pStreamContext->mSize) {
248        M4OSA_UInt32 u_mask;
249        M4OSA_Int32 i_ovf = bitIndex + bitLength - 32;
250        retval=(M4OSA_UInt32)GET_MEMORY32(
251            pStreamContext->mPbitStream[ bitLocation ]);
252
253        u_mask = (bitLength >= 32) ? 0xffffffff: (1 << bitLength) - 1;
254
255        if (i_ovf <= 0) {
256            retval=(retval >> (- i_ovf)) & u_mask;
257        } else {
258            M4OSA_UInt32 u_nextword = (M4OSA_UInt32)GET_MEMORY32(
259                pStreamContext->mPbitStream[ bitLocation + 1 ]);
260            M4OSA_UInt32 u_msb_mask, u_msb_value, u_lsb_mask, u_lsb_value;
261
262            u_msb_mask = ((1 << (32 - bitIndex)) - 1) << i_ovf;
263            u_msb_value = retval << i_ovf;
264            u_lsb_mask = (1 << i_ovf) - 1;
265            u_lsb_value = u_nextword >> (32 - i_ovf);
266            retval= (u_msb_value & u_msb_mask ) | (u_lsb_value & u_lsb_mask);
267        }
268    }
269    return retval;
270}
271
272static void VideoEditor3gpReader_BitStreamParserRestart(void* pContext) {
273    VideoEditor3gpReader_BitStreamParserContext* pStreamContext =
274        (VideoEditor3gpReader_BitStreamParserContext*)pContext;
275
276    if (M4OSA_NULL == pStreamContext) {
277        return;
278    }
279    /* resets the bitstream pointers*/
280    pStreamContext->mIndex=0;
281    pStreamContext->mBitIndex=0;
282}
283/**
284 *******************************************************************************
285 * @brief  Get a pointer to the current byte pointed by the bitstream pointer.
286 * @note   It should be used carefully as the pointer is in the bitstream itself
287 *         and no copy is made.
288 * @param  pContext    (IN/OUT)  BitStreamParser context.
289 * @return Pointer to the current location in the bitstream
290 *******************************************************************************
291*/
292static M4OSA_UInt8*  VideoEditor3gpReader_GetCurrentbitStreamPointer(
293        void* pContext) {
294    VideoEditor3gpReader_BitStreamParserContext* pStreamContext =
295        (VideoEditor3gpReader_BitStreamParserContext*)pContext;
296    M4OSA_DEBUG_IF1((M4OSA_NULL==pStreamContext), 0, "invalid context pointer");
297
298    return (M4OSA_UInt8*)((M4OSA_UInt8*)pStreamContext->mPbitStream + \
299        pStreamContext->mIndex * sizeof(M4OSA_UInt32) + \
300        pStreamContext->mBitIndex/8) ;
301}
302
303static M4OSA_Int32 VideoEditor3gpReader_BitStreamParserGetSize(void* pContext) {
304    VideoEditor3gpReader_BitStreamParserContext* pStreamContext =
305        (VideoEditor3gpReader_BitStreamParserContext*)pContext;
306    M4OSA_DEBUG_IF1((M4OSA_NULL==pStreamContext), 0, "invalid context pointer");
307
308    return pStreamContext->mSize;
309}
310
311
312static void VideoEditor3gpReader_MPEG4BitStreamParserInit(void** pContext,
313        void* pBitStream, M4OSA_Int32 size) {
314    VideoEditor3gpReader_BitStreamParserInit(pContext, pBitStream, size);
315}
316static M4OSA_Int32 VideoEditor3gpReader_GetMpegLengthFromInteger(void* pContext,
317        M4OSA_UInt32 val) {
318    M4OSA_UInt32 length=0;
319    M4OSA_UInt32 numBytes=0;
320    M4OSA_UInt32 b=0;
321
322    M4OSA_DEBUG_IF1((M4OSA_NULL==pContext), 0, "invalid context pointer");
323
324    /* the length is encoded as a sequence of bytes. The highest bit is used
325    to indicate that the length continues on the next byte.
326
327    The length can be: 0x80 0x80 0x80 0x22
328    of just            0x22 (highest bit not set)
329
330    */
331
332    do {
333        b=(val & ((0xff)<< (8 * numBytes)))>> (8 * numBytes);
334        length=(length << 7) | (b & 0x7f);
335        numBytes++;
336    } while ((b & 0x80) && numBytes < 4);
337
338    return length;
339}
340
341/**
342 *******************************************************************************
343 * @brief  Decode an MPEG4 Systems descriptor size from an encoded SDL size data
344 * @note   The value is read from the current bitstream location.
345 * @param  pContext    (IN/OUT)  BitStreamParser context.
346 * @return Size in a human readable form
347 *******************************************************************************
348*/
349static M4OSA_Int32 VideoEditor3gpReader_GetMpegLengthFromStream(void* pContext){
350    M4OSA_UInt32 length=0;
351    M4OSA_UInt32 numBytes=0;
352    M4OSA_UInt32 b=0;
353
354    M4OSA_DEBUG_IF1((M4OSA_NULL==pContext), 0, "invalid context pointer");
355
356    /* the length is encoded as a sequence of bytes. The highest bit is used
357    to indicate that the length continues on the next byte.
358
359    The length can be: 0x80 0x80 0x80 0x22
360    of just            0x22 (highest bit not set)
361    */
362
363    do {
364        b=VideoEditor3gpReader_BitStreamParserShowBits(pContext, 8);
365        VideoEditor3gpReader_BitStreamParserFlushBits(pContext, 8);
366        length=(length << 7) | (b & 0x7f);
367        numBytes++;
368    } while ((b & 0x80) && numBytes < 4);
369
370    return length;
371}
372#endif /* VIDEOEDITOR_BITSTREAM_PARSER */
373/**
374************************************************************************
375* @brief    create an instance of the 3gp reader
376 * @note    allocates the context
377 *
378 * @param   pContext:       (OUT)   pointer on a reader context
379 *
380 * @return  M4NO_ERROR              there is no error
381 * @return  M4ERR_ALLOC             a memory allocation has failed
382 * @return  M4ERR_PARAMETER         at least one parameter is not valid
383************************************************************************
384*/
385
386M4OSA_ERR VideoEditor3gpReader_create(M4OSA_Context *pContext) {
387    VideoEditor3gpReader_Context* pC = NULL;
388    M4OSA_ERR err = M4NO_ERROR;
389    VIDEOEDITOR_CHECK(M4OSA_NULL != pContext , M4ERR_PARAMETER);
390
391    LOGV("VideoEditor3gpReader_create begin");
392
393    /* Context allocation & initialization */
394    SAFE_MALLOC(pC, VideoEditor3gpReader_Context, 1, "VideoEditor3gpReader");
395
396    memset(pC, sizeof(VideoEditor3gpReader_Context), 0);
397
398    pC->mAudioStreamHandler  = M4OSA_NULL;
399    pC->mAudioAu.dataAddress = M4OSA_NULL;
400    pC->mVideoStreamHandler  = M4OSA_NULL;
401    pC->mVideoAu.dataAddress = M4OSA_NULL;
402
403    pC->mAudioSeeking = M4OSA_FALSE;
404    pC->mAudioSeekTime = 0;
405
406    pC->mVideoSeeking = M4OSA_FALSE;
407    pC->mVideoSeekTime = 0;
408
409    M4OSA_INT64_FROM_INT32(pC->mMaxDuration, 0);
410    *pContext=pC;
411
412cleanUp:
413    if ( M4NO_ERROR == err ) {
414        LOGV("VideoEditor3gpReader_create no error");
415    } else {
416        LOGV("VideoEditor3gpReader_create ERROR 0x%X", err);
417    }
418    LOGV("VideoEditor3gpReader_create end ");
419    return err;
420}
421
422/**
423**************************************************************************
424* @brief    destroy the instance of the 3gp reader
425* @note after this call the context is invalid
426* @param    context:        (IN)    Context of the reader
427* @return   M4NO_ERROR              there is no error
428* @return   M4ERR_PARAMETER         pContext parameter is not properly set
429**************************************************************************
430*/
431
432M4OSA_ERR VideoEditor3gpReader_destroy(M4OSA_Context pContext) {
433    M4OSA_ERR err = M4NO_ERROR;
434    VideoEditor3gpReader_Context* pC = M4OSA_NULL;
435
436    LOGV("VideoEditor3gpReader_destroy begin");
437
438    VIDEOEDITOR_CHECK(M4OSA_NULL != pContext, M4ERR_PARAMETER);
439    pC = (VideoEditor3gpReader_Context*)pContext;
440
441    SAFE_FREE(pC->mAudioAu.dataAddress);
442    pC->mAudioAu.dataAddress = M4OSA_NULL;
443    SAFE_FREE(pC->mVideoAu.dataAddress);
444    pC->mVideoAu.dataAddress = M4OSA_NULL;
445    SAFE_FREE(pC);
446    pContext = M4OSA_NULL;
447
448cleanUp:
449    if( M4NO_ERROR == err ) {
450        LOGV("VideoEditor3gpReader_destroy no error");
451    }
452    else
453    {
454        LOGV("VideoEditor3gpReader_destroy ERROR 0x%X", err);
455    }
456
457    LOGV("VideoEditor3gpReader_destroy end ");
458    return err;
459}
460
461/**
462************************************************************************
463* @brief    open the reader and initializes its created instance
464* @note     this function open the media file
465* @param    context:            (IN)    Context of the reader
466* @param    pFileDescriptor:    (IN)    Pointer to proprietary data identifying
467*                                       the media to open
468* @return   M4NO_ERROR                  there is no error
469* @return   M4ERR_PARAMETER             the context is NULL
470************************************************************************
471*/
472
473M4OSA_ERR VideoEditor3gpReader_open(M4OSA_Context pContext,
474        M4OSA_Void* pFileDescriptor) {
475    VideoEditor3gpReader_Context* pC = (VideoEditor3gpReader_Context*)pContext;
476    M4OSA_ERR err = M4NO_ERROR;
477
478    LOGV("VideoEditor3gpReader_open start ");
479    M4OSA_DEBUG_IF1((M4OSA_NULL == pC),  M4ERR_PARAMETER,
480        "VideoEditor3gpReader_open: invalid context pointer");
481    M4OSA_DEBUG_IF1((M4OSA_NULL == pFileDescriptor), M4ERR_PARAMETER,
482        "VideoEditor3gpReader_open: invalid pointer pFileDescriptor");
483
484    LOGV("VideoEditor3gpReader_open Datasource start %s",
485        (char*)pFileDescriptor);
486    pC->mDataSource = DataSource::CreateFromURI((char*)pFileDescriptor);
487
488    if (pC->mDataSource == NULL) {
489        LOGV("VideoEditor3gpReader_open Datasource error");
490        return M4ERR_PARAMETER;
491    }
492
493    pC->mExtractor = MediaExtractor::Create(pC->mDataSource,
494        MEDIA_MIMETYPE_CONTAINER_MPEG4);
495
496    if (pC->mExtractor == NULL) {
497        LOGV("VideoEditor3gpReader_open extractor error");
498        return M4ERR_PARAMETER;
499    }
500
501    LOGV("VideoEditor3gpReader_open end ");
502    return err;
503}
504
505/**
506************************************************************************
507* @brief    close the reader
508* @note     close the 3GP file
509* @param    context:        (IN)    Context of the reader
510* @return   M4NO_ERROR              there is no error
511* @return   M4ERR_PARAMETER         the context is NULL
512* @return   M4ERR_BAD_CONTEXT       provided context is not a valid one
513************************************************************************
514*/
515M4OSA_ERR VideoEditor3gpReader_close(M4OSA_Context context) {
516    VideoEditor3gpReader_Context *pC = (VideoEditor3gpReader_Context*)context;
517    M4READER_AudioSbrUserdata *pAudioSbrUserData;
518    M4_AccessUnit *pAU;
519    M4OSA_ERR err = M4NO_ERROR;
520
521    LOGV("VideoEditor3gpReader_close begin");
522
523    M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER,
524        "VideoEditor3gpReader_close: invalid context pointer");
525
526    if (pC->mAudioStreamHandler) {
527        LOGV("VideoEditor3gpReader_close Audio");
528
529        if (M4OSA_NULL != pC->mAudioStreamHandler->m_pDecoderSpecificInfo) {
530            M4OSA_free((M4OSA_MemAddr32)pC->mAudioStreamHandler->\
531                m_pDecoderSpecificInfo);
532            pC->mAudioStreamHandler->m_decoderSpecificInfoSize = 0;
533            pC->mAudioStreamHandler->m_pDecoderSpecificInfo = M4OSA_NULL;
534        }
535
536        if ((M4DA_StreamTypeAudioAac == pC->mAudioStreamHandler->m_streamType)
537            && (M4OSA_NULL != pC->mAudioStreamHandler->m_pUserData)) {
538            pAudioSbrUserData = (M4READER_AudioSbrUserdata*)(\
539                pC->mAudioStreamHandler->m_pUserData);
540
541            pAU = (M4_AccessUnit*)pAudioSbrUserData->m_pFirstAU;
542            if (M4OSA_NULL != pAU) {
543                M4OSA_free((M4OSA_MemAddr32)pAU);
544            }
545
546            if (M4OSA_NULL != pAudioSbrUserData->m_pAacDecoderUserConfig) {
547                M4OSA_free((M4OSA_MemAddr32)pAudioSbrUserData->\
548                    m_pAacDecoderUserConfig);
549            }
550            M4OSA_free((M4OSA_MemAddr32)pAudioSbrUserData);
551            pC->mAudioStreamHandler->m_pUserData = M4OSA_NULL;
552        }
553
554        if (pC->mAudioStreamHandler->m_pESDSInfo != M4OSA_NULL) {
555            M4OSA_free((M4OSA_MemAddr32)pC->mAudioStreamHandler->m_pESDSInfo);
556            pC->mAudioStreamHandler->m_pESDSInfo = M4OSA_NULL;
557            pC->mAudioStreamHandler->m_ESDSInfoSize = 0;
558        }
559        /* Finally destroy the stream handler */
560        M4OSA_free((M4OSA_MemAddr32)pC->mAudioStreamHandler);
561        pC->mAudioStreamHandler = M4OSA_NULL;
562
563        pC->mAudioSource->stop();
564        pC->mAudioSource.clear();
565    }
566    if (pC->mVideoStreamHandler) {
567        LOGV("VideoEditor3gpReader_close Video ");
568
569        if(M4OSA_NULL != pC->mVideoStreamHandler->m_pDecoderSpecificInfo) {
570            M4OSA_free((M4OSA_MemAddr32)pC->mVideoStreamHandler->\
571                m_pDecoderSpecificInfo);
572            pC->mVideoStreamHandler->m_decoderSpecificInfoSize = 0;
573            pC->mVideoStreamHandler->m_pDecoderSpecificInfo = M4OSA_NULL;
574        }
575
576        if(M4OSA_NULL != pC->mVideoStreamHandler->m_pH264DecoderSpecificInfo) {
577            M4OSA_free((M4OSA_MemAddr32)pC->mVideoStreamHandler->\
578                m_pH264DecoderSpecificInfo);
579            pC->mVideoStreamHandler->m_H264decoderSpecificInfoSize = 0;
580            pC->mVideoStreamHandler->m_pH264DecoderSpecificInfo = M4OSA_NULL;
581        }
582
583        if(pC->mVideoStreamHandler->m_pESDSInfo != M4OSA_NULL) {
584            M4OSA_free((M4OSA_MemAddr32)pC->mVideoStreamHandler->m_pESDSInfo);
585            pC->mVideoStreamHandler->m_pESDSInfo = M4OSA_NULL;
586            pC->mVideoStreamHandler->m_ESDSInfoSize = 0;
587        }
588
589        /* Finally destroy the stream handler */
590        M4OSA_free((M4OSA_MemAddr32)pC->mVideoStreamHandler);
591        pC->mVideoStreamHandler = M4OSA_NULL;
592
593        pC->mVideoSource->stop();
594        pC->mVideoSource.clear();
595    }
596    pC->mDataSource.clear();
597
598    LOGV("VideoEditor3gpReader_close end");
599    return err;
600}
601
602/**
603************************************************************************
604* @brief    get an option from the 3gp reader
605* @note     it allows the caller to retrieve a property value:
606*
607* @param    context:        (IN)    Context of the reader
608* @param    optionId:       (IN)    indicates the option to get
609* @param    pValue:         (OUT)   pointer to structure or value (allocated
610*                                   by user) where option is stored
611*
612* @return   M4NO_ERROR              there is no error
613* @return   M4ERR_BAD_CONTEXT       provided context is not a valid one
614* @return   M4ERR_PARAMETER         at least one parameter is not properly set
615* @return   M4ERR_BAD_OPTION_ID     when the option ID is not a valid one
616* @return   M4ERR_VIDEO_NOT_H263    No video stream H263 in file.
617* @return   M4ERR_NO_VIDEO_STREAM_RETRIEVED_YET
618*           Function 3gpReader_getNextStreamHandler must be called before
619************************************************************************
620*/
621M4OSA_ERR VideoEditor3gpReader_getOption(M4OSA_Context context,
622        M4OSA_OptionID optionId, M4OSA_DataOption pValue) {
623    VideoEditor3gpReader_Context* pC = (VideoEditor3gpReader_Context*)context;
624    M4OSA_ERR err = M4NO_ERROR;
625
626    LOGV("VideoEditor3gpReader_getOption begin %d", optionId);
627
628    M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER,
629        "invalid context pointer");
630    M4OSA_DEBUG_IF1((M4OSA_NULL == pValue), M4ERR_PARAMETER,
631        "VideoEditor3gpReader_getOption: invalid pointer on value");
632
633    switch (optionId) {
634    case M4READER_kOptionID_Duration:
635        {
636            LOGV("VideoEditor3gpReader_getOption duration %d",pC->mMaxDuration);
637            M4OSA_TIME_SET(*(M4OSA_Time*)pValue, pC->mMaxDuration);
638        }
639        break;
640    case M4READER_kOptionID_Version:
641        /* not used */
642        LOGV("VideoEditor3gpReader_getOption: M4READER_kOptionID_Version");
643        break;
644
645    case M4READER_kOptionID_Copyright:
646        /* not used */
647        LOGV(">>>>>>>   M4READER_kOptionID_Copyright");
648        break;
649
650    case M4READER_kOptionID_CreationTime:
651        /* not used */
652        LOGV("VideoEditor3gpReader_getOption M4READER_kOptionID_CreationTime");
653    break;
654
655    case M4READER_kOptionID_Bitrate:
656        {
657            M4OSA_UInt32* pBitrate = (M4OSA_UInt32*)pValue;
658
659            if (pC->mMaxDuration != 0) {
660                M4OSA_UInt32 ui32Tmp = (M4OSA_UInt32)pC->mMaxDuration;
661                *pBitrate = (M4OSA_UInt32)((M4OSA_Double)pC->mFileSize * \
662                    8000.0 / (M4OSA_Double)ui32Tmp);
663                LOGV("3gpReader_getOption bitrate:  %d", *pBitrate);
664            }
665            *pBitrate = 384000; //check
666            LOGV("VideoEditor3gpReader_getOption bitrate %ld", *pBitrate);
667        }
668    break;
669    case M4READER_3GP_kOptionID_H263Properties:
670        {
671#if 0
672            if(M4OSA_NULL == pC->mVideoStreamHandler) {
673                LOGV("VideoEditor3gpReader_getOption no videoStream retrieved");
674
675                err = M4ERR_NO_VIDEO_STREAM_RETRIEVED_YET;
676                break;
677            }
678            if((M4DA_StreamTypeVideoH263 != pC->mVideoStreamHandler->\
679                mStreamType) || (pC->mVideoStreamHandler->\
680                m_decoderSpecificInfoSize < 7)) {
681                LOGV("VideoEditor3gpReader_getOption DSI Size %d",
682                    pC->mVideoStreamHandler->m_decoderSpecificInfoSize);
683
684                err = M4ERR_VIDEO_NOT_H263;
685                break;
686            }
687
688            /* MAGICAL in the decoder confi H263: the 7th byte is the profile
689             * number, 6th byte is the level number */
690            ((M4READER_3GP_H263Properties *)pValue)->uiProfile =
691                pC->mVideoStreamHandler->m_pDecoderSpecificInfo[6];
692            ((M4READER_3GP_H263Properties *)pValue)->uiLevel =
693                pC->mVideoStreamHandler->m_pDecoderSpecificInfo[5];
694#endif
695            LOGV("VideoEditor3gpReader_getOption M4READER_3GP_kOptionID_\
696            H263Properties end");
697        }
698        break;
699    case M4READER_3GP_kOptionID_PurpleLabsDrm:
700        LOGV("VideoEditor3gpReaderOption M4READER_3GP_kOptionID_PurpleLabsDrm");
701        /* not used */
702        break;
703
704    case M4READER_kOptionID_GetNumberOfAudioAu:
705        /* not used */
706        LOGV("VideoEditor3gpReadeOption M4READER_kOptionID_GetNumberOfAudioAu");
707    break;
708
709    case M4READER_kOptionID_GetNumberOfVideoAu:
710        /* not used */
711        LOGV("VideoEditor3gpReader_getOption :GetNumberOfVideoAu");
712    break;
713
714    case M4READER_kOptionID_GetMetadata:
715        /* not used */
716        LOGV("VideoEditor3gpReader_getOption M4READER_kOptionID_GetMetadata");
717    break;
718
719    case M4READER_kOptionID_3gpFtypBox:
720        /* used only for SEMC */
721        LOGV("VideoEditor3gpReader_getOption M4READER_kOptionID_3gpFtypBox");
722        err = M4ERR_BAD_OPTION_ID; //check this
723        break;
724
725#ifdef OPTIONID_GET_NEXT_VIDEO_CTS
726    case M4READER_3GP_kOptionID_getNextVideoCTS:
727        /* not used */
728        LOGV("VideoEditor3gpReader_getOption: getNextVideoCTS");
729        break;
730#endif
731    default:
732        {
733            err = M4ERR_BAD_OPTION_ID;
734            LOGV("VideoEditor3gpReader_getOption M4ERR_BAD_OPTION_ID");
735        }
736        break;
737    }
738    LOGV("VideoEditor3gpReader_getOption end: optionID: x%x", optionId);
739    return err;
740}
741/**
742************************************************************************
743* @brief    set an option on the 3gp reader
744* @note No option can be set yet.
745* @param    context:        (IN)    Context of the reader
746* @param    optionId:       (IN)    indicates the option to set
747* @param    pValue:         (IN)    pointer to structure or value (allocated
748*                                   by user) where option is stored
749* @return   M4NO_ERROR              there is no error
750* @return   M4ERR_BAD_CONTEXT       provided context is not a valid one
751* @return   M4ERR_PARAMETER         at least one parameter is not properly set
752* @return   M4ERR_BAD_OPTION_ID     when the option ID is not a valid one
753************************************************************************
754*/
755M4OSA_ERR VideoEditor3gpReader_setOption(M4OSA_Context context,
756        M4OSA_OptionID optionId, M4OSA_DataOption pValue) {
757    VideoEditor3gpReader_Context* pC = (VideoEditor3gpReader_Context*)context;
758    M4OSA_ERR err = M4NO_ERROR;
759
760    /* Check function parameters */
761    M4OSA_DEBUG_IF1((M4OSA_NULL == pC), M4ERR_PARAMETER,
762        "invalid context pointer");
763    M4OSA_DEBUG_IF1((M4OSA_NULL == pValue), M4ERR_PARAMETER,
764        "invalid value pointer");
765
766    LOGV("VideoEditor3gpReader_setOption begin %d",optionId);
767
768    switch(optionId) {
769        case M4READER_kOptionID_SetOsaFileReaderFctsPtr:
770        break;
771
772        case M4READER_3GP_kOptionID_AudioOnly:
773        break;
774
775        case M4READER_3GP_kOptionID_VideoOnly:
776        break;
777
778        case M4READER_3GP_kOptionID_FastOpenMode:
779        break;
780
781        case M4READER_kOptionID_MaxMetadataSize:
782        break;
783
784        default:
785        {
786            LOGV("VideoEditor3gpReader_setOption: returns M4ERR_BAD_OPTION_ID");
787            err = M4ERR_BAD_OPTION_ID;
788        }
789        break;
790    }
791    LOGV("VideoEditor3gpReader_setOption end ");
792    return err;
793}
794/**
795 ************************************************************************
796 * @brief   fill the access unit structure with initialization values
797 * @param   context:        (IN)     Context of the reader
798 * @param   pStreamHandler: (IN)     pointer to the stream handler to which
799 *                                   the access unit will be associated
800 * @param   pAccessUnit:    (IN/OUT) pointer to the access unit (allocated
801 *                                   by the caller) to initialize
802 * @return  M4NO_ERROR               there is no error
803 * @return  M4ERR_PARAMETER          at least one parameter is not properly set
804 ************************************************************************
805*/
806M4OSA_ERR VideoEditor3gpReader_fillAuStruct(M4OSA_Context context,
807        M4_StreamHandler *pStreamHandler, M4_AccessUnit *pAccessUnit) {
808    VideoEditor3gpReader_Context* pC = (VideoEditor3gpReader_Context*)context;
809    M4OSA_ERR err= M4NO_ERROR;
810
811    M4OSA_DEBUG_IF1((pC == 0),             M4ERR_PARAMETER,
812        "VideoEditor3gpReader_fillAuStruct: invalid context");
813    M4OSA_DEBUG_IF1((pStreamHandler == 0), M4ERR_PARAMETER,
814        "VideoEditor3gpReader_fillAuStruc invalid pointer to M4_StreamHandler");
815    M4OSA_DEBUG_IF1((pAccessUnit == 0),    M4ERR_PARAMETER,
816        "VideoEditor3gpReader_fillAuStruct: invalid pointer to M4_AccessUnit");
817
818    LOGV("VideoEditor3gpReader_fillAuStruct begin");
819
820    /* Initialize pAccessUnit structure */
821    pAccessUnit->m_size         = 0;
822    pAccessUnit->m_CTS          = 0;
823    pAccessUnit->m_DTS          = 0;
824    pAccessUnit->m_attribute    = 0;
825    pAccessUnit->m_dataAddress  = M4OSA_NULL;
826    pAccessUnit->m_maxsize      = pStreamHandler->m_maxAUSize;
827    pAccessUnit->m_streamID     = pStreamHandler->m_streamId;
828    pAccessUnit->m_structSize   = sizeof(M4_AccessUnit);
829
830    LOGV("VideoEditor3gpReader_fillAuStruct end");
831    return M4NO_ERROR;
832}
833
834/**
835********************************************************************************
836* @brief    jump into the stream at the specified time
837* @note
838* @param    context:        (IN)   Context of the reader
839* @param    pStreamHandler  (IN)   the stream handler of the stream to make jump
840* @param    pTime           (I/O)IN  the time to jump to (in ms)
841*                                OUT the time to which the stream really jumped
842* @return   M4NO_ERROR             there is no error
843* @return   M4ERR_PARAMETER        at least one parameter is not properly set
844********************************************************************************
845*/
846M4OSA_ERR VideoEditor3gpReader_jump(M4OSA_Context context,
847        M4_StreamHandler *pStreamHandler, M4OSA_Int32* pTime) {
848    VideoEditor3gpReader_Context* pC = (VideoEditor3gpReader_Context*)context;
849    M4OSA_ERR err = M4NO_ERROR;
850    M4SYS_AccessUnit* pAu;
851    M4OSA_Time time64;
852    M4OSA_Double timeDouble;
853
854    M4OSA_DEBUG_IF1((pC == 0), M4ERR_PARAMETER,
855        "VideoEditor3gpReader_jump: invalid context");
856    M4OSA_DEBUG_IF1((pStreamHandler == 0), M4ERR_PARAMETER,
857        "VideoEditor3gpReader_jump: invalid pointer to M4_StreamHandler");
858    M4OSA_DEBUG_IF1((pTime == 0), M4ERR_PARAMETER,
859        "VideoEditor3gpReader_jump: invalid time pointer");
860
861    LOGV("VideoEditor3gpReader_jump begin");
862
863    if (*pTime == (pStreamHandler->m_duration)) {
864        *pTime -= 1;
865    }
866    M4OSA_INT64_FROM_INT32(time64, *pTime);
867
868    LOGV("VideoEditor3gpReader_jump time us %ld ", time64);
869
870    if ((pC->mAudioStreamHandler != M4OSA_NULL) &&
871            (pStreamHandler->m_streamId == pC->mAudioStreamHandler->m_streamId))
872            {
873        pAu = &pC->mAudioAu;
874        pAu->CTS = time64;
875        pAu->DTS = time64;
876
877        time64 = time64 * 1000; /* Convert the time into micro sec */
878        pC->mAudioSeeking = M4OSA_TRUE;
879        pC->mAudioSeekTime = time64;
880        LOGV("VideoEditor3gpReader_jump AUDIO time us %ld ", time64);
881    } else if ((pC->mVideoStreamHandler != M4OSA_NULL) &&
882            (pStreamHandler->m_streamId == pC->mVideoStreamHandler->m_streamId))
883            {
884        pAu = &pC->mVideoAu;
885        pAu->CTS = time64;
886        pAu->DTS = time64;
887
888        time64 = time64 * 1000; /* Convert the time into micro sec */
889        pC->mVideoSeeking = M4OSA_TRUE;
890        pC->mVideoSeekTime = time64;
891        LOGV("VideoEditor3gpReader_jump VIDEO time us %ld ", time64);
892    } else {
893        LOGV("VideoEditor3gpReader_jump passed StreamHandler is not known\n");
894        return M4ERR_PARAMETER;
895    }
896    time64 = time64 / 1000; /* Convert the time into milli sec */
897    LOGV("VideoEditor3gpReader_jump time ms before seekset %ld ", time64);
898
899    M4OSA_INT64_TO_DOUBLE(timeDouble, time64);
900    *pTime = (M4OSA_Int32)timeDouble;
901
902    LOGV("VideoEditor3gpReader_jump end");
903    err = M4NO_ERROR;
904    return err;
905}
906/**
907********************************************************************************
908* @brief    reset the stream, that is seek it to beginning and make it ready
909* @note
910* @param    context:        (IN)    Context of the reader
911* @param    pStreamHandler  (IN)    The stream handler of the stream to reset
912* @return   M4NO_ERROR              there is no error
913* @return   M4ERR_PARAMETER         at least one parameter is not properly set
914********************************************************************************
915*/
916M4OSA_ERR VideoEditor3gpReader_reset(M4OSA_Context context,
917        M4_StreamHandler *pStreamHandler) {
918    VideoEditor3gpReader_Context* pC = (VideoEditor3gpReader_Context*)context;
919    M4OSA_ERR err = M4NO_ERROR;
920    M4SYS_StreamID streamIdArray[2];
921    M4SYS_AccessUnit* pAu;
922    M4OSA_Time time64;
923
924    M4OSA_DEBUG_IF1((pC == 0), M4ERR_PARAMETER,
925        "VideoEditor3gpReader_reset: invalid context");
926    M4OSA_DEBUG_IF1((pStreamHandler == 0), M4ERR_PARAMETER,
927        "VideoEditor3gpReader_reset: invalid pointer to M4_StreamHandler");
928
929    M4OSA_INT64_FROM_INT32(time64, 0);
930
931    LOGV("VideoEditor3gpReader_reset begin");
932
933    if (pStreamHandler == (M4_StreamHandler*)pC->mAudioStreamHandler) {
934        pAu = &pC->mAudioAu;
935    } else if (pStreamHandler == (M4_StreamHandler*)pC->mVideoStreamHandler) {
936        pAu = &pC->mVideoAu;
937    } else {
938        LOGV("VideoEditor3gpReader_reset passed StreamHandler is not known\n");
939        return M4ERR_PARAMETER;
940    }
941
942    pAu->CTS = time64;
943    pAu->DTS = time64;
944
945    LOGV("VideoEditor3gpReader_reset end");
946    return err;
947}
948
949/**
950********************************************************************************
951* @brief  Gets an access unit (AU) from the stream handler source.
952* @note   An AU is the smallest possible amount of data to be decoded by decoder
953*
954* @param    context:        (IN) Context of the reader
955* @param    pStreamHandler  (IN) The stream handler of the stream to make jump
956* @param    pAccessUnit     (IO) Pointer to access unit to fill with read data
957* @return   M4NO_ERROR           there is no error
958* @return   M4ERR_PARAMETER      at least one parameter is not properly set
959* @returns  M4ERR_ALLOC          memory allocation failed
960* @returns  M4WAR_NO_MORE_AU     there are no more access unit in the stream
961********************************************************************************
962*/
963M4OSA_ERR VideoEditor3gpReader_getNextAu(M4OSA_Context context,
964        M4_StreamHandler *pStreamHandler, M4_AccessUnit *pAccessUnit) {
965    VideoEditor3gpReader_Context* pC=(VideoEditor3gpReader_Context*)context;
966    M4OSA_ERR err = M4NO_ERROR;
967    M4SYS_AccessUnit* pAu;
968    int64_t tempTime64 = 0;
969    MediaBuffer *mMediaBuffer = NULL;
970    MediaSource::ReadOptions options;
971    M4OSA_Bool flag = M4OSA_FALSE;
972    status_t error;
973    int32_t i32Tmp = 0;
974
975    M4OSA_DEBUG_IF1((pReaderContext == 0), M4ERR_PARAMETER,
976        "VideoEditor3gpReader_getNextAu: invalid context");
977    M4OSA_DEBUG_IF1((pStreamHandler == 0), M4ERR_PARAMETER,
978        "VideoEditor3gpReader_getNextAu: invalid pointer to M4_StreamHandler");
979    M4OSA_DEBUG_IF1((pAccessUnit == 0),    M4ERR_PARAMETER,
980        "VideoEditor3gpReader_getNextAu: invalid pointer to M4_AccessUnit");
981
982    LOGV("VideoEditor3gpReader_getNextAu begin");
983
984    if (pStreamHandler == (M4_StreamHandler*)pC->mAudioStreamHandler) {
985        LOGV("VideoEditor3gpReader_getNextAu audio stream");
986        pAu = &pC->mAudioAu;
987        if (pC->mAudioSeeking == M4OSA_TRUE) {
988            LOGV("VideoEditor3gpReader_getNextAu audio seek time: %ld",
989                pC->mAudioSeekTime);
990            options.setSeekTo(pC->mAudioSeekTime);
991            pC->mAudioSource->read(&mMediaBuffer, &options);
992
993            mMediaBuffer->meta_data()->findInt64(kKeyTime,
994                (int64_t*)&tempTime64);
995            options.clearSeekTo();
996            pC->mAudioSeeking = M4OSA_FALSE;
997            flag = M4OSA_TRUE;
998        } else {
999            LOGV("VideoEditor3gpReader_getNextAu audio no seek:");
1000            pC->mAudioSource->read(&mMediaBuffer, &options);
1001            if (mMediaBuffer != NULL) {
1002                mMediaBuffer->meta_data()->findInt64(kKeyTime,
1003                    (int64_t*)&tempTime64);
1004            }
1005        }
1006    } else if (pStreamHandler == (M4_StreamHandler*)pC->mVideoStreamHandler) {
1007        LOGV("VideoEditor3gpReader_getNextAu video steram ");
1008        pAu = &pC->mVideoAu;
1009        if(pC->mVideoSeeking == M4OSA_TRUE) {
1010            flag = M4OSA_TRUE;
1011            LOGV("VideoEditor3gpReader_getNextAu seek: %ld",pC->mVideoSeekTime);
1012            options.setSeekTo(pC->mVideoSeekTime,
1013                MediaSource::ReadOptions::SEEK_PREVIOUS_SYNC);
1014            do
1015            {
1016                if (mMediaBuffer != NULL) {
1017                    LOGV("VideoEditor3gpReader_getNextAu free the MediaBuffer");
1018                    mMediaBuffer->release();
1019                }
1020                error = pC->mVideoSource->read(&mMediaBuffer, &options);
1021                LOGV("VE3gpReader_getNextAu MediaBuffer %x , error %d",
1022                    mMediaBuffer, error);
1023                if (mMediaBuffer != NULL)
1024                {
1025                    if (mMediaBuffer->meta_data()->findInt32(kKeyIsSyncFrame,
1026                        &i32Tmp) && i32Tmp) {
1027                            LOGV("SYNC FRAME FOUND--%d", i32Tmp);
1028                        pAu->attribute = AU_RAP;
1029                    }
1030                    mMediaBuffer->meta_data()->findInt64(kKeyTime,
1031                        (int64_t*)&tempTime64);
1032                } else {
1033                    break;
1034                }
1035                options.clearSeekTo();
1036            } while(tempTime64 < pC->mVideoSeekTime);
1037
1038            LOGV("VE3gpReader_getNextAu: video  time with seek  = %lld:",
1039                tempTime64);
1040            pC->mVideoSeeking = M4OSA_FALSE;
1041        } else {
1042            LOGV("VideoEditor3gpReader_getNextAu video no seek:");
1043            pC->mVideoSource->read(&mMediaBuffer, &options);
1044
1045            if(mMediaBuffer != NULL) {
1046                if (mMediaBuffer->meta_data()->findInt32(kKeyIsSyncFrame,
1047                    &i32Tmp) && i32Tmp) {
1048                    LOGV("SYNC FRAME FOUND--%d", i32Tmp);
1049                    pAu->attribute = AU_RAP;
1050                }
1051                mMediaBuffer->meta_data()->findInt64(kKeyTime,
1052                    (int64_t*)&tempTime64);
1053                LOGV("VE3gpReader_getNextAu: video no seek time = %lld:",
1054                    tempTime64);
1055            }else {
1056                LOGV("VE3gpReader_getNextAu:video no seek time buffer is NULL");
1057            }
1058        }
1059    } else {
1060        LOGV("VideoEditor3gpReader_getNextAu M4ERR_PARAMETER");
1061        return M4ERR_PARAMETER;
1062    }
1063
1064    if (mMediaBuffer != NULL) {
1065        if( (pAu->dataAddress == NULL) ||  (pAu->size < \
1066            mMediaBuffer->range_length())) {
1067            if(pAu->dataAddress != NULL) {
1068                M4OSA_free((M4OSA_Int32*)pAu->dataAddress);
1069                pAu->dataAddress = NULL;
1070            }
1071            LOGV("Buffer lenght = %d ,%d",(mMediaBuffer->range_length() +\
1072                3) & ~0x3,(mMediaBuffer->range_length()));
1073
1074            pAu->dataAddress = (M4OSA_Int32*)M4OSA_malloc(
1075                (mMediaBuffer->range_length() + 3) & ~0x3,M4READER_3GP,
1076                    (M4OSA_Char*)"pAccessUnit->m_dataAddress" );
1077            if(pAu->dataAddress == NULL) {
1078                LOGV("VideoEditor3gpReader_getNextAu malloc failed");
1079                return M4ERR_ALLOC;
1080            }
1081        }
1082        pAu->size = mMediaBuffer->range_length();
1083
1084        memcpy((M4OSA_MemAddr8)pAu->dataAddress,
1085            (const char *)mMediaBuffer->data() + mMediaBuffer->range_offset(),
1086            mMediaBuffer->range_length());
1087
1088        if( (pStreamHandler == (M4_StreamHandler*)pC->mVideoStreamHandler)  &&
1089            (pStreamHandler->m_streamType == M4DA_StreamTypeVideoMpeg4Avc) ) {
1090            M4OSA_UInt32 size = mMediaBuffer->range_length();
1091            M4OSA_UInt8 *lbuffer;
1092
1093            lbuffer = (M4OSA_UInt8 *) pAu->dataAddress;
1094            LOGV("pAccessUnit->m_dataAddress size = %x",size);
1095
1096            lbuffer[0] = (size >> 24) & 0xFF;
1097            lbuffer[1] = (size >> 16) & 0xFF;
1098            lbuffer[2] = (size >> 8) & 0xFF;
1099            lbuffer[3] = (size) & 0xFF;
1100        }
1101
1102        pAu->CTS = tempTime64;
1103
1104        pAu->CTS = pAu->CTS / 1000; //converting the microsec to millisec
1105        LOGV("VideoEditor3gpReader_getNextAu CTS = %ld",pAu->CTS);
1106
1107        pAu->DTS  = pAu->CTS;
1108        if (pStreamHandler == (M4_StreamHandler*)pC->mAudioStreamHandler) {
1109            pAu->attribute = M4SYS_kFragAttrOk;
1110        }
1111        mMediaBuffer->release();
1112
1113        pAccessUnit->m_dataAddress = (M4OSA_Int8*) pAu->dataAddress;
1114        pAccessUnit->m_size = pAu->size;
1115        pAccessUnit->m_maxsize = pAu->size;
1116        pAccessUnit->m_CTS = pAu->CTS;
1117        pAccessUnit->m_DTS = pAu->DTS;
1118        pAccessUnit->m_attribute = pAu->attribute;
1119
1120    } else {
1121        LOGV("VideoEditor3gpReader_getNextAu: M4WAR_NO_MORE_AU (EOS) reached");
1122        pAccessUnit->m_size = 0;
1123        err = M4WAR_NO_MORE_AU;
1124    }
1125    options.clearSeekTo();
1126
1127    pAu->nbFrag = 0;
1128    mMediaBuffer = NULL;
1129    LOGV("VideoEditor3gpReader_getNextAu end ");
1130
1131    return err;
1132}
1133/**
1134 *******************************************************************************
1135 * @brief   Split the AVC DSI in its different components and write it in
1136 *          ONE memory buffer
1137 * @note
1138 * @param   pStreamHandler:         (IN/OUT) The MPEG4-AVC stream
1139 * @param   pDecoderConfigLocal:    (IN) The DSI buffer
1140 * @param   decoderConfigSizeLocal: (IN) The DSI buffer size
1141 * @return  M4NO_ERROR              there is no error
1142 * @return  ERR_FILE_SYNTAX_ERROR   pDecoderConfigLocal is NULL
1143 *******************************************************************************
1144*/
1145static M4OSA_ERR VideoEditor3gpReader_AnalyseAvcDsi(
1146        M4_StreamHandler *pStreamHandler, M4OSA_Int32* pDecoderConfigLocal,
1147        M4OSA_Int32 decoderConfigSizeLocal) {
1148    struct _avcSpecificInfo *pAvcSpecInfo = M4OSA_NULL;
1149    M4OSA_UInt32 uiSpecInfoSize;
1150    M4OSA_Context pBitParserContext = M4OSA_NULL;
1151    M4OSA_MemAddr8 pPos;
1152
1153    /**
1154     * First parsing to get the total allocation size (we must not do
1155     * multiple malloc, but only one instead) */
1156    {
1157        M4OSA_Int32 val;
1158        M4OSA_UInt32 i,j;
1159        M4OSA_UInt8 nalUnitLength;
1160        M4OSA_UInt8  numOfSequenceParameterSets;
1161        M4OSA_UInt32 uiTotalSizeOfSPS = 0;
1162        M4OSA_UInt8  numOfPictureParameterSets;
1163        M4OSA_UInt32 uiTotalSizeOfPPS = 0;
1164        M4OSA_UInt32 uiSize;
1165        struct _avcSpecificInfo avcSpIf;
1166
1167        avcSpIf.m_nalUnitLength = 0;
1168
1169        if (M4OSA_NULL == pDecoderConfigLocal) {
1170            return M4ERR_READER3GP_DECODER_CONFIG_ERROR;
1171        }
1172
1173        VideoEditor3gpReader_MPEG4BitStreamParserInit(&pBitParserContext,
1174            pDecoderConfigLocal, decoderConfigSizeLocal);
1175
1176        if (M4OSA_NULL == pBitParserContext) {
1177            return M4ERR_ALLOC;
1178        }
1179
1180        VideoEditor3gpReader_BitStreamParserFlushBits(pBitParserContext, 8);
1181                                       /* 8 bits -- configuration version */
1182        VideoEditor3gpReader_BitStreamParserFlushBits(pBitParserContext, 8);
1183                                       /* 8 bits -- avc profile indication*/
1184        VideoEditor3gpReader_BitStreamParserFlushBits(pBitParserContext, 8);
1185                                       /* 8 bits -- profile compatibility */
1186        VideoEditor3gpReader_BitStreamParserFlushBits(pBitParserContext, 8);
1187                                       /* 8 bits -- avc level indication*/
1188        val=VideoEditor3gpReader_BitStreamParserShowBits(pBitParserContext, 8);
1189                       /* 6 bits reserved 111111b 2 bits length Size minus one*/
1190        VideoEditor3gpReader_BitStreamParserFlushBits(pBitParserContext, 8);
1191                                       /* m_nalUnitLength */
1192
1193        nalUnitLength = (M4OSA_UInt8)((val & 0x03) + 1);/*0b11111100*/
1194        if (nalUnitLength > 4) {
1195            pStreamHandler->m_decoderSpecificInfoSize = 0;
1196            pStreamHandler->m_pDecoderSpecificInfo = M4OSA_NULL;
1197            VideoEditor3gpReader_BitStreamParserCleanUp(pBitParserContext);
1198        } else {
1199            /**
1200             * SPS table */
1201            val=VideoEditor3gpReader_BitStreamParserShowBits(pBitParserContext,
1202            8);/* 3 bits-reserved 111b-5 bits number of sequence parameter set*/
1203            numOfSequenceParameterSets = val & 0x1F;
1204            /*1F instead of E0*/ /*0b11100000*/ /*Number of seq parameter sets*/
1205            VideoEditor3gpReader_BitStreamParserFlushBits(pBitParserContext, 8);
1206            for (i=0; i < numOfSequenceParameterSets; i++) {
1207                /**
1208                 * Get the size of this element */
1209                uiSize =
1210                    (M4OSA_UInt32)VideoEditor3gpReader_BitStreamParserShowBits(
1211                    pBitParserContext, 16);
1212                uiTotalSizeOfSPS += uiSize;
1213                VideoEditor3gpReader_BitStreamParserFlushBits(
1214                    pBitParserContext, 16);
1215                /**
1216                 *Read the element(dont keep it, we only want size right now) */
1217                for (j=0; j<uiSize; j++) {
1218                    VideoEditor3gpReader_BitStreamParserFlushBits(
1219                        pBitParserContext, 8);
1220                }
1221            }
1222
1223            /**
1224             * SPS table */
1225            numOfPictureParameterSets=(M4OSA_UInt8)\
1226                VideoEditor3gpReader_BitStreamParserShowBits(pBitParserContext,
1227                    8);
1228            VideoEditor3gpReader_BitStreamParserFlushBits(pBitParserContext, 8);
1229            for (i=0; i < numOfPictureParameterSets; i++) {
1230                /**
1231                 * Get the size of this element */
1232                uiSize = (M4OSA_UInt32)
1233                    VideoEditor3gpReader_BitStreamParserShowBits(
1234                    pBitParserContext, 16);
1235                uiTotalSizeOfPPS += uiSize;
1236                VideoEditor3gpReader_BitStreamParserFlushBits(
1237                    pBitParserContext, 16);
1238                /**
1239                 *Read the element(dont keep it,we only want size right now)*/
1240                for (j=0; j<uiSize; j++) {
1241                    VideoEditor3gpReader_BitStreamParserFlushBits(
1242                        pBitParserContext, 8);
1243                }
1244            }
1245
1246            /**
1247             * Compute the size of the full buffer */
1248            uiSpecInfoSize = sizeof(struct _avcSpecificInfo) +
1249                     numOfSequenceParameterSets * sizeof(struct _parameterSet)
1250                     + /**< size of the table of SPS elements */
1251                     numOfPictureParameterSets  * sizeof(struct _parameterSet)
1252                     + /**< size of the table of PPS elements */
1253                     uiTotalSizeOfSPS +
1254                     uiTotalSizeOfPPS;
1255            /**
1256             * Allocate the buffer */
1257            pAvcSpecInfo =(struct _avcSpecificInfo*)M4OSA_malloc(uiSpecInfoSize,
1258                M4READER_3GP, (M4OSA_Char*)"MPEG-4 AVC DecoderSpecific");
1259            if (M4OSA_NULL == pAvcSpecInfo) {
1260                VideoEditor3gpReader_BitStreamParserCleanUp(pBitParserContext);
1261                return M4ERR_ALLOC;
1262            }
1263
1264            /**
1265             * Set the pointers to the correct part of the buffer */
1266            pAvcSpecInfo->m_nalUnitLength = nalUnitLength;
1267            pAvcSpecInfo->m_numOfSequenceParameterSets =
1268                numOfSequenceParameterSets;
1269            pAvcSpecInfo->m_numOfPictureParameterSets  =
1270                numOfPictureParameterSets;
1271
1272            /* We place the SPS param sets table after m_pPictureParameterSet */
1273            pAvcSpecInfo->m_pSequenceParameterSet= (struct _parameterSet*)(
1274                (M4OSA_MemAddr8)(&pAvcSpecInfo->m_pPictureParameterSet) +
1275                sizeof(pAvcSpecInfo->m_pPictureParameterSet));
1276            /*We place the PPS param sets table after the SPS param sets table*/
1277            pAvcSpecInfo->m_pPictureParameterSet = (struct _parameterSet*)(
1278                (M4OSA_MemAddr8)(pAvcSpecInfo->m_pSequenceParameterSet) +
1279                (numOfSequenceParameterSets * sizeof(struct _parameterSet)));
1280            /**< The data will be placed after the PPS param sets table */
1281            pPos = (M4OSA_MemAddr8)pAvcSpecInfo->m_pPictureParameterSet +
1282                (numOfPictureParameterSets * sizeof(struct _parameterSet));
1283
1284            /**
1285             * reset the bit parser */
1286            VideoEditor3gpReader_BitStreamParserCleanUp(pBitParserContext);
1287        }
1288    }
1289
1290    /**
1291     * Second parsing to copy the data */
1292    if (M4OSA_NULL != pAvcSpecInfo) {
1293        M4OSA_Int32 i,j;
1294
1295        VideoEditor3gpReader_MPEG4BitStreamParserInit(&pBitParserContext,
1296            pDecoderConfigLocal, decoderConfigSizeLocal);
1297
1298        if (M4OSA_NULL == pBitParserContext) {
1299            M4OSA_free((M4OSA_MemAddr32)pAvcSpecInfo);
1300            return M4ERR_ALLOC;
1301        }
1302
1303        VideoEditor3gpReader_BitStreamParserFlushBits(pBitParserContext, 8);
1304            /* 8 bits -- configuration version */
1305        VideoEditor3gpReader_BitStreamParserFlushBits(pBitParserContext, 8);
1306            /* 8 bits -- avc profile indication*/
1307        VideoEditor3gpReader_BitStreamParserFlushBits(pBitParserContext, 8);
1308            /* 8 bits -- profile compatibility */
1309        VideoEditor3gpReader_BitStreamParserFlushBits(pBitParserContext, 8);
1310            /* 8 bits -- avc level indication*/
1311        VideoEditor3gpReader_BitStreamParserFlushBits(pBitParserContext, 8);
1312            /* m_nalUnitLength */
1313        VideoEditor3gpReader_BitStreamParserFlushBits(pBitParserContext, 8);
1314        /* 3 bits -- reserved 111b -- 5 bits number of sequence parameter set*/
1315
1316        for (i=0; i < pAvcSpecInfo->m_numOfSequenceParameterSets; i++) {
1317            pAvcSpecInfo->m_pSequenceParameterSet[i].m_length =
1318                (M4OSA_UInt16)VideoEditor3gpReader_BitStreamParserShowBits(
1319                pBitParserContext, 16);
1320            VideoEditor3gpReader_BitStreamParserFlushBits(pBitParserContext,16);
1321
1322            pAvcSpecInfo->m_pSequenceParameterSet[i].m_pParameterSetUnit =
1323                (M4OSA_UInt8*)pPos;  /**< current position in the buffer */
1324            pPos += pAvcSpecInfo->m_pSequenceParameterSet[i].m_length;
1325                /**< increment the position in the buffer */
1326            for (j=0; j<pAvcSpecInfo->m_pSequenceParameterSet[i].m_length;j++){
1327                pAvcSpecInfo->m_pSequenceParameterSet[i].m_pParameterSetUnit[j]=
1328                    (M4OSA_UInt8)VideoEditor3gpReader_BitStreamParserShowBits(
1329                    pBitParserContext, 8);
1330                VideoEditor3gpReader_BitStreamParserFlushBits(
1331                    pBitParserContext, 8);
1332            }
1333        }
1334
1335        VideoEditor3gpReader_BitStreamParserFlushBits(pBitParserContext, 8);
1336            /* number of pîcture parameter set*/
1337
1338        for (i=0; i < pAvcSpecInfo->m_numOfPictureParameterSets; i++) {
1339            pAvcSpecInfo->m_pPictureParameterSet[i].m_length =
1340                (M4OSA_UInt16)VideoEditor3gpReader_BitStreamParserShowBits(
1341                pBitParserContext, 16);
1342            VideoEditor3gpReader_BitStreamParserFlushBits(pBitParserContext,16);
1343
1344            pAvcSpecInfo->m_pPictureParameterSet[i].m_pParameterSetUnit =
1345                (M4OSA_UInt8*)pPos;   /**< current position in the buffer */
1346            pPos += pAvcSpecInfo->m_pPictureParameterSet[i].m_length;
1347                /**< increment the position in the buffer */
1348            for (j=0; j<pAvcSpecInfo->m_pPictureParameterSet[i].m_length; j++) {
1349                pAvcSpecInfo->m_pPictureParameterSet[i].m_pParameterSetUnit[j] =
1350                    (M4OSA_UInt8)VideoEditor3gpReader_BitStreamParserShowBits(
1351                    pBitParserContext, 8);
1352                VideoEditor3gpReader_BitStreamParserFlushBits(
1353                    pBitParserContext, 8);
1354            }
1355        }
1356        VideoEditor3gpReader_BitStreamParserCleanUp(pBitParserContext);
1357        pStreamHandler->m_decoderSpecificInfoSize = uiSpecInfoSize;
1358        pStreamHandler->m_pDecoderSpecificInfo = (M4OSA_UInt8*)pAvcSpecInfo;
1359    }
1360    pStreamHandler->m_H264decoderSpecificInfoSize  =  decoderConfigSizeLocal;
1361    pStreamHandler->m_pH264DecoderSpecificInfo  = (M4OSA_UInt8*)M4OSA_malloc(
1362        decoderConfigSizeLocal, M4READER_3GP,
1363        (M4OSA_Char*)"MPEG-4 AVC DecoderSpecific");
1364    if (M4OSA_NULL == pStreamHandler->m_pH264DecoderSpecificInfo) {
1365        goto cleanup;
1366    }
1367
1368    M4OSA_memcpy((M4OSA_MemAddr8 ) pStreamHandler->m_pH264DecoderSpecificInfo,
1369        (M4OSA_MemAddr8 )pDecoderConfigLocal,
1370        pStreamHandler->m_H264decoderSpecificInfoSize);
1371    return M4NO_ERROR;
1372cleanup:
1373    VideoEditor3gpReader_BitStreamParserCleanUp(pBitParserContext);
1374    return M4ERR_READER3GP_DECODER_CONFIG_ERROR;
1375}
1376/**
1377********************************************************************************
1378* @brief    Get the next stream found in the 3gp file
1379* @note
1380* @param    context:     (IN)    Context of the reader
1381* @param    pMediaFamily: OUT)   pointer to a user allocated
1382*                                M4READER_MediaFamily that will be filled
1383*                                with the media family of the found stream
1384* @param    pStreamHandler:(OUT) pointer to StreamHandler that will be allocated
1385*                                and filled with the found stream description
1386* @return   M4NO_ERROR              there is no error
1387* @return   M4ERR_BAD_CONTEXT       provided context is not a valid one
1388* @return   M4ERR_PARAMETER         at least one parameter is not properly set
1389* @return   M4WAR_NO_MORE_STREAM    no more available stream in the media
1390********************************************************************************
1391*/
1392M4OSA_ERR VideoEditor3gpReader_getNextStreamHandler(M4OSA_Context context,
1393        M4READER_MediaFamily *pMediaFamily,
1394        M4_StreamHandler **pStreamHandler) {
1395    VideoEditor3gpReader_Context* pC=(VideoEditor3gpReader_Context*)context;
1396    M4OSA_ERR err = M4NO_ERROR;
1397    M4SYS_StreamID streamIdArray[2];
1398    M4SYS_StreamDescription streamDesc;
1399    M4_AudioStreamHandler* pAudioStreamHandler;
1400    M4_VideoStreamHandler* pVideoStreamHandler;
1401    M4OSA_Int8 *DecoderSpecificInfo = M4OSA_NULL;
1402    M4OSA_Int32 decoderSpecificInfoSize =0, maxAUSize = 0;
1403
1404    M4_StreamType streamType = M4DA_StreamTypeUnknown;
1405    M4OSA_UInt8 temp, i, trackCount;
1406    M4OSA_Bool haveAudio = M4OSA_FALSE;
1407    M4OSA_Bool haveVideo = M4OSA_FALSE;
1408    sp<MetaData> meta  = NULL;
1409    int64_t Duration = 0;
1410    M4OSA_UInt8* DecoderSpecific = M4OSA_NULL ;
1411    uint32_t type;
1412    const void *data;
1413    size_t size;
1414    const void *codec_specific_data;
1415    size_t codec_specific_data_size;
1416    M4OSA_Int32  ptempTime;
1417
1418    LOGV("VideoEditor3gpReader_getNextStreamHandler begin");
1419
1420    M4OSA_DEBUG_IF1((pC == 0), M4ERR_PARAMETER,
1421        "VideoEditor3gpReader_getNextStreamHandler: invalid context");
1422    M4OSA_DEBUG_IF1((pMediaFamily   == 0), M4ERR_PARAMETER,
1423        "getNextStreamHandler: invalid pointer to MediaFamily");
1424    M4OSA_DEBUG_IF1((pStreamHandler == 0), M4ERR_PARAMETER,
1425        "getNextStreamHandler: invalid pointer to StreamHandler");
1426
1427    trackCount = pC->mExtractor->countTracks();
1428    temp = pC->mCurrTrack;
1429
1430    if(temp >= trackCount) {
1431        LOGV("VideoEditor3gpReader_getNextStreamHandler error = %d",
1432            M4WAR_NO_MORE_STREAM);
1433        return (M4WAR_NO_MORE_STREAM);
1434    } else {
1435        const char *mime;
1436        meta = pC->mExtractor->getTrackMetaData(temp);
1437        CHECK(meta->findCString(kKeyMIMEType, &mime));
1438
1439        if (!haveVideo && !strncasecmp(mime, "video/", 6)) {
1440            pC->mVideoSource = pC->mExtractor->getTrack(temp);
1441            pC->mVideoSource->start();
1442
1443            *pMediaFamily = M4READER_kMediaFamilyVideo;
1444            haveVideo = true;
1445            LOGV("VideoEditor3gpReader_getNextStreamHandler getTrack called");
1446            if (!strcasecmp(mime, MEDIA_MIMETYPE_VIDEO_AVC)) {
1447                streamType = M4DA_StreamTypeVideoMpeg4Avc;
1448            } else if (!strcasecmp(mime, MEDIA_MIMETYPE_VIDEO_H263)) {
1449                streamType = M4DA_StreamTypeVideoH263;
1450            } else if (!strcasecmp(mime, MEDIA_MIMETYPE_VIDEO_MPEG4)) {
1451                streamType = M4DA_StreamTypeVideoMpeg4;
1452            } else {
1453                LOGV("VideoEditor3gpReaderGetNextStreamHandler streamTypeNONE");
1454            }
1455            LOGV("VideoEditor3gpReader_getNextStreamHandler: stream type: %d ",
1456                streamType);
1457
1458            if(streamType != M4DA_StreamTypeUnknown) {
1459                pC->mStreamType = streamType;
1460                pC->mStreamId = pC->mCurrTrack;
1461
1462                pVideoStreamHandler = (M4_VideoStreamHandler*)M4OSA_malloc
1463                    (sizeof(M4_VideoStreamHandler), M4READER_3GP,
1464                    (M4OSA_Char*)"M4_VideoStreamHandler");
1465                if (M4OSA_NULL == pVideoStreamHandler) {
1466                    return M4ERR_ALLOC;
1467                }
1468                pVideoStreamHandler->m_structSize=sizeof(M4_VideoStreamHandler);
1469
1470                meta->findInt32(kKeyWidth,
1471                    (int32_t*)&(pVideoStreamHandler->m_videoWidth));
1472                meta->findInt32(kKeyHeight,
1473                    (int32_t*)&(pVideoStreamHandler->m_videoHeight));
1474
1475                (*pStreamHandler)  = (M4_StreamHandler*)(pVideoStreamHandler);
1476                meta->findInt64(kKeyDuration,
1477                    (int64_t*)&(Duration));
1478                ((*pStreamHandler)->m_duration) =
1479                    (int32_t)((Duration)/1000); // conversion to mS
1480                pC->mMaxDuration = ((*pStreamHandler)->m_duration);
1481                LOGV("VideoEditor3gpReader_getNextStreamHandler m_duration %d",
1482                    (*pStreamHandler)->m_duration);
1483
1484                pC->mFileSize  = 0;
1485
1486                meta->findInt32(kKeyMaxInputSize, (int32_t*)&(maxAUSize));
1487                if(maxAUSize == 0) {
1488                    maxAUSize = 70000;
1489                }
1490                (*pStreamHandler)->m_maxAUSize = maxAUSize;
1491                LOGV("<<<<<<<<<<   video: mMaxAUSize from MP4 extractor: %d",
1492                    (*pStreamHandler)->m_maxAUSize);
1493
1494                //check this
1495                pVideoStreamHandler->m_averageFrameRate = 15;
1496                if( (M4DA_StreamTypeVideoH263       == streamType) ||
1497                    (M4DA_StreamTypeVideoMpeg4Avc   == streamType)){
1498                    ((M4_StreamHandler*)pVideoStreamHandler)->m_averageBitRate =
1499                        384000;
1500                }
1501                pC->mVideoStreamHandler =
1502                    (M4_StreamHandler*)(pVideoStreamHandler);
1503
1504                /* Get the DSI info */
1505                if(M4DA_StreamTypeVideoH263 == streamType) {
1506                    if (meta->findData(kKeyESDS, &type, &data, &size)) {
1507                        ESDS esds((const char *)data, size);
1508                        CHECK_EQ(esds.InitCheck(), OK);
1509
1510                        esds.getCodecSpecificInfo(
1511                            &codec_specific_data, &codec_specific_data_size);
1512                        (*pStreamHandler)->m_decoderSpecificInfoSize =
1513                            codec_specific_data_size;
1514                        if ((*pStreamHandler)->m_decoderSpecificInfoSize != 0) {
1515                            DecoderSpecific = (M4OSA_UInt8*)M4OSA_malloc(
1516                                (*pStreamHandler)->m_decoderSpecificInfoSize,
1517                                M4READER_3GP,(M4OSA_Char*)"H263 DSI");
1518                            if (M4OSA_NULL == DecoderSpecific) {
1519                                return M4ERR_ALLOC;
1520                            }
1521                            M4OSA_memcpy((M4OSA_MemAddr8)DecoderSpecific,
1522                                (M4OSA_MemAddr8)codec_specific_data,
1523                                codec_specific_data_size);
1524                            (*pStreamHandler)->m_pDecoderSpecificInfo =
1525                                DecoderSpecific;
1526                        }
1527                        else {
1528                            (*pStreamHandler)->m_pDecoderSpecificInfo =
1529                                M4OSA_NULL;
1530                        }
1531                    } else {
1532                        LOGV("VE_getNextStreamHandler: H263 dsi not found");
1533                        (*pStreamHandler)->m_pDecoderSpecificInfo = M4OSA_NULL;
1534                        (*pStreamHandler)->m_decoderSpecificInfoSize = 0;
1535                        (*pStreamHandler)->m_H264decoderSpecificInfoSize = 0;
1536                        (*pStreamHandler)->m_pH264DecoderSpecificInfo =
1537                            M4OSA_NULL;
1538                        (*pStreamHandler)->m_pESDSInfo = M4OSA_NULL;
1539                        (*pStreamHandler)->m_ESDSInfoSize = 0;
1540                    }
1541                }
1542                else if(M4DA_StreamTypeVideoMpeg4Avc == streamType) {
1543                    if(meta->findData(kKeyAVCC, &type, &data, &size)) {
1544                        decoderSpecificInfoSize = size;
1545                        if (decoderSpecificInfoSize != 0) {
1546                            DecoderSpecificInfo = (M4OSA_Int8*)M4OSA_malloc(
1547                                decoderSpecificInfoSize, M4READER_3GP,
1548                                (M4OSA_Char*)"H264 DecoderSpecific" );
1549                            if (M4OSA_NULL == DecoderSpecificInfo) {
1550                                LOGV("VideoEditor3gp_getNextStream is NULL ");
1551                                return M4ERR_ALLOC;
1552                            }
1553                            M4OSA_memcpy((M4OSA_MemAddr8)DecoderSpecificInfo,
1554                                (M4OSA_MemAddr8)data, decoderSpecificInfoSize);
1555                        } else {
1556                            LOGV("DSI Size %d", decoderSpecificInfoSize);
1557                            DecoderSpecificInfo = M4OSA_NULL;
1558                        }
1559                    }
1560                    (*pStreamHandler)->m_pESDSInfo = M4OSA_NULL;
1561                    (*pStreamHandler)->m_ESDSInfoSize = 0;
1562
1563                    err = VideoEditor3gpReader_AnalyseAvcDsi(*pStreamHandler,
1564                    (M4OSA_Int32*)DecoderSpecificInfo, decoderSpecificInfoSize);
1565
1566                    if (M4NO_ERROR != err) {
1567                        return err;
1568                    }
1569                    LOGV("decsize %d, h264decsize %d: %d", (*pStreamHandler)->\
1570                        m_decoderSpecificInfoSize, (*pStreamHandler)->\
1571                        m_H264decoderSpecificInfoSize);
1572
1573                    if(M4OSA_NULL != DecoderSpecificInfo) {
1574                        M4OSA_free((M4OSA_MemAddr32)DecoderSpecificInfo);
1575                        DecoderSpecificInfo = M4OSA_NULL;
1576                    }
1577                } else if( (M4DA_StreamTypeVideoMpeg4 == streamType) ) {
1578                    if (meta->findData(kKeyESDS, &type, &data, &size)) {
1579                        ESDS esds((const char *)data, size);
1580                        CHECK_EQ(esds.InitCheck(), OK);
1581
1582                        (*pStreamHandler)->m_ESDSInfoSize = size;
1583                        (*pStreamHandler)->m_pESDSInfo = (M4OSA_UInt8*)\
1584                        M4OSA_malloc((*pStreamHandler)->m_ESDSInfoSize,
1585                        M4READER_3GP, (M4OSA_Char*)"H263 DecoderSpecific" );
1586                        if (M4OSA_NULL == (*pStreamHandler)->m_pESDSInfo) {
1587                            return M4ERR_ALLOC;
1588                        }
1589                        M4OSA_memcpy((M4OSA_MemAddr8)(*pStreamHandler)->\
1590                            m_pESDSInfo, (M4OSA_MemAddr8)data, size);
1591
1592                        esds.getCodecSpecificInfo(&codec_specific_data,
1593                            &codec_specific_data_size);
1594                        LOGV("VE MP4 dsisize: %d, %x", codec_specific_data_size,
1595                            codec_specific_data);
1596
1597                        (*pStreamHandler)->m_decoderSpecificInfoSize =
1598                            codec_specific_data_size;
1599                        if ((*pStreamHandler)->m_decoderSpecificInfoSize != 0) {
1600                            DecoderSpecific = (M4OSA_UInt8*)M4OSA_malloc(
1601                                (*pStreamHandler)->m_decoderSpecificInfoSize,
1602                                M4READER_3GP, (M4OSA_Char*)" DecoderSpecific" );
1603                            if (M4OSA_NULL == DecoderSpecific) {
1604                                return M4ERR_ALLOC;
1605                            }
1606                            M4OSA_memcpy((M4OSA_MemAddr8)DecoderSpecific,
1607                                (M4OSA_MemAddr8)codec_specific_data,
1608                                codec_specific_data_size);
1609                            (*pStreamHandler)->m_pDecoderSpecificInfo =
1610                                DecoderSpecific;
1611                        }
1612                        else {
1613                            (*pStreamHandler)->m_pDecoderSpecificInfo =
1614                                M4OSA_NULL;
1615                        }
1616                        (*pStreamHandler)->m_pH264DecoderSpecificInfo =
1617                            M4OSA_NULL;
1618                        (*pStreamHandler)->m_H264decoderSpecificInfoSize = 0;
1619                    }
1620                } else {
1621                    LOGV("VideoEditor3gpReader_getNextStream NO video stream");
1622                    return M4ERR_READER_UNKNOWN_STREAM_TYPE;
1623                }
1624            }
1625            else {
1626                LOGV("VideoEditor3gpReader_getNextStream NO video stream");
1627                return M4ERR_READER_UNKNOWN_STREAM_TYPE;
1628            }
1629
1630        } else if (!haveAudio && !strncasecmp(mime, "audio/", 6)) {
1631            LOGV("VideoEditor3gpReader_getNextStream audio getTrack called");
1632            pC->mAudioSource = pC->mExtractor->getTrack(pC->mCurrTrack);
1633            pC->mAudioSource->start();
1634            *pMediaFamily = M4READER_kMediaFamilyAudio;
1635
1636            if(!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AMR_NB)) {
1637                streamType = M4DA_StreamTypeAudioAmrNarrowBand;
1638            } else if(!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AMR_WB)) {
1639                streamType = M4DA_StreamTypeAudioAmrWideBand;
1640            }
1641            else if(!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AAC)) {
1642                streamType = M4DA_StreamTypeAudioAac;
1643            } else {
1644                LOGV("VideoEditor3gpReader_getNextStrea streamtype Unknown ");
1645            }
1646            if(streamType != M4DA_StreamTypeUnknown) {
1647                pC->mStreamType = streamType;
1648                pC->mStreamId = pC->mCurrTrack;
1649
1650                LOGV("VE streamtype %d ,id %d",  streamType, pC->mCurrTrack);
1651
1652                pAudioStreamHandler = (M4_AudioStreamHandler*)M4OSA_malloc
1653                    (sizeof(M4_AudioStreamHandler), M4READER_3GP,
1654                    (M4OSA_Char*)"M4_AudioStreamHandler");
1655                if (M4OSA_NULL == pAudioStreamHandler) {
1656                    return M4ERR_ALLOC;
1657                }
1658                pAudioStreamHandler->m_structSize=sizeof(M4_AudioStreamHandler);
1659                pAudioStreamHandler->m_byteSampleSize   = 0;
1660                pAudioStreamHandler->m_nbChannels       = 0;
1661                pAudioStreamHandler->m_samplingFrequency= 0;
1662                pAudioStreamHandler->m_byteFrameLength  = 0;
1663
1664                (*pStreamHandler) = (M4_StreamHandler*)(pAudioStreamHandler);
1665                pC->mAudioStreamHandler =
1666                    (M4_StreamHandler*)(pAudioStreamHandler);
1667                (*pStreamHandler)->m_averageBitRate = 0;
1668                haveAudio = true;
1669                pC->mAudioStreamHandler=(M4_StreamHandler*)pAudioStreamHandler;
1670                pC->mAudioStreamHandler->m_pESDSInfo = M4OSA_NULL;
1671                pC->mAudioStreamHandler->m_ESDSInfoSize = 0;
1672
1673                meta->findInt32(kKeyMaxInputSize, (int32_t*)&(maxAUSize));
1674                if(maxAUSize == 0) {
1675                    maxAUSize = 70000;
1676                }
1677                (*pStreamHandler)->m_maxAUSize = maxAUSize;
1678                LOGV("VE Audio mMaxAUSize from MP4 extractor: %d", maxAUSize);
1679            }
1680            if((M4DA_StreamTypeAudioAmrNarrowBand == streamType) ||
1681                (M4DA_StreamTypeAudioAmrWideBand == streamType)) {
1682                M4OSA_UInt32 freqIndex = 0; /**< AMR NB */
1683                M4OSA_UInt32 modeSet;
1684                M4OSA_UInt32 i;
1685                M4OSA_Context pBitParserContext = M4OSA_NULL;
1686
1687                if(M4DA_StreamTypeAudioAmrWideBand == streamType) {
1688                    freqIndex = 1; /**< AMR WB */
1689                }
1690
1691                if (meta->findData(kKeyESDS, &type, &data, &size)) {
1692                    ESDS esds((const char *)data, size);
1693                    CHECK_EQ(esds.InitCheck(), OK);
1694
1695                    esds.getCodecSpecificInfo(&codec_specific_data,
1696                        &codec_specific_data_size);
1697                    (*pStreamHandler)->m_decoderSpecificInfoSize =
1698                        codec_specific_data_size;
1699
1700                    if ((*pStreamHandler)->m_decoderSpecificInfoSize != 0) {
1701                        DecoderSpecific = (M4OSA_UInt8*)M4OSA_malloc(
1702                            (*pStreamHandler)->m_decoderSpecificInfoSize,
1703                            M4READER_3GP, (M4OSA_Char*)"H263 DecoderSpecific" );
1704                        if (M4OSA_NULL == DecoderSpecific) {
1705                            return M4ERR_ALLOC;
1706                        }
1707                        M4OSA_memcpy((M4OSA_MemAddr8)DecoderSpecific,
1708                            (M4OSA_MemAddr8)codec_specific_data,
1709                            codec_specific_data_size);
1710                        (*pStreamHandler)->m_pDecoderSpecificInfo =
1711                            DecoderSpecific;
1712                    } else {
1713                        (*pStreamHandler)->m_pDecoderSpecificInfo = M4OSA_NULL;
1714                    }
1715                } else {
1716                    M4OSA_UChar AmrDsi[] =
1717                        {'P','H','L','P',0x00, 0x00, 0x80, 0x00, 0x01,};
1718                    (*pStreamHandler)->m_decoderSpecificInfoSize = 9;
1719                    DecoderSpecific = (M4OSA_UInt8*)M4OSA_malloc(
1720                        (*pStreamHandler)->m_decoderSpecificInfoSize,
1721                        M4READER_3GP, (M4OSA_Char*)"H263 DecoderSpecific" );
1722                    if (M4OSA_NULL == DecoderSpecific) {
1723                        return M4ERR_ALLOC;
1724                    }
1725                    if(freqIndex ==0) {
1726                        AmrDsi[8] = 0x01;
1727                    } else {
1728                        AmrDsi[8] = 0x02;
1729                    }
1730                    for(i = 0; i< 9; i++) {
1731                        DecoderSpecific[i] = AmrDsi[i];
1732                    }
1733                    (*pStreamHandler)->m_pDecoderSpecificInfo = DecoderSpecific;
1734                }
1735                (*pStreamHandler)->m_averageBitRate =
1736                    VideoEditor3gpReader_AmrBitRate[freqIndex][7];
1737            } else if((M4DA_StreamTypeAudioAac == streamType)) {
1738                if (meta->findData(kKeyESDS, &type, &data, &size)) {
1739                    ESDS esds((const char *)data, size);
1740                    CHECK_EQ(esds.InitCheck(), OK);
1741
1742                    (*pStreamHandler)->m_ESDSInfoSize = size;
1743                    (*pStreamHandler)->m_pESDSInfo = (M4OSA_UInt8*)M4OSA_malloc(
1744                        (*pStreamHandler)->m_ESDSInfoSize, M4READER_3GP,
1745                        (M4OSA_Char*)"H263 DecoderSpecific" );
1746                    if (M4OSA_NULL == (*pStreamHandler)->m_pESDSInfo) {
1747                        return M4ERR_ALLOC;
1748                    }
1749                    M4OSA_memcpy((M4OSA_MemAddr8)(*pStreamHandler)->m_pESDSInfo,
1750                    (M4OSA_MemAddr8)data, size);
1751                    esds.getCodecSpecificInfo(&codec_specific_data,
1752                        &codec_specific_data_size);
1753
1754                    LOGV("VEdsi %d,%x",codec_specific_data_size,
1755                        codec_specific_data);
1756
1757                    (*pStreamHandler)->m_decoderSpecificInfoSize =
1758                        codec_specific_data_size;
1759                    if ((*pStreamHandler)->m_decoderSpecificInfoSize != 0) {
1760                        DecoderSpecific = (M4OSA_UInt8*)M4OSA_malloc(
1761                            (*pStreamHandler)->m_decoderSpecificInfoSize,
1762                            M4READER_3GP, (M4OSA_Char*)"H263 DecoderSpecific" );
1763                        if (M4OSA_NULL == DecoderSpecific) {
1764                            return M4ERR_ALLOC;
1765                        }
1766                        M4OSA_memcpy((M4OSA_MemAddr8)DecoderSpecific,
1767                            (M4OSA_MemAddr8)codec_specific_data,
1768                            codec_specific_data_size);
1769                        (*pStreamHandler)->m_pDecoderSpecificInfo =
1770                            DecoderSpecific;
1771                    } else {
1772                        (*pStreamHandler)->m_pDecoderSpecificInfo = M4OSA_NULL;
1773                    }
1774                }
1775            } else {
1776                LOGV("VideoEditor3gpReader_getNextStream mStreamType: none ");
1777                return M4ERR_READER_UNKNOWN_STREAM_TYPE;
1778            }
1779        } else {
1780            LOGV("VE noaudio-video stream:pC->mCurrTrack = %d ",pC->mCurrTrack);
1781            pC->mCurrTrack++; //Increment current track to get the next track
1782            return M4ERR_READER_UNKNOWN_STREAM_TYPE;
1783        }
1784        LOGV("VE StreamType: %d, stremhandler %x",streamType, *pStreamHandler );
1785        (*pStreamHandler)->m_streamType = streamType;
1786        (*pStreamHandler)->m_streamId   = pC->mStreamId;
1787        (*pStreamHandler)->m_pUserData  = M4OSA_NULL;
1788        (*pStreamHandler)->m_structSize = sizeof(M4_StreamHandler);
1789        (*pStreamHandler)->m_bStreamIsOK = M4OSA_TRUE;
1790
1791        meta->findInt64(kKeyDuration,
1792            (int64_t*)&(Duration));
1793
1794        (*pStreamHandler)->m_duration = (int32_t)(Duration / 1000);
1795
1796        pC->mMaxDuration = ((*pStreamHandler)->m_duration);
1797        LOGV("VE str duration duration: %d ", (*pStreamHandler)->m_duration);
1798
1799        /* In AAC case: Put the first AU in pAudioStreamHandler->m_pUserData
1800         *since decoder has to know if stream contains SBR data(Implicit sig) */
1801        if(M4DA_StreamTypeAudioAac == (*pStreamHandler)->m_streamType) {
1802            M4READER_AudioSbrUserdata*  pAudioSbrUserdata;
1803
1804            pAudioSbrUserdata = (M4READER_AudioSbrUserdata*)M4OSA_malloc(
1805                sizeof(M4READER_AudioSbrUserdata),M4READER_3GP,
1806                (M4OSA_Char*)"M4READER_AudioSbrUserdata");
1807            if (M4OSA_NULL == pAudioSbrUserdata) {
1808                err = M4ERR_ALLOC;
1809                goto Error;
1810            }
1811            (*pStreamHandler)->m_pUserData = pAudioSbrUserdata;
1812            pAudioSbrUserdata->m_bIsSbrEnabled = M4OSA_FALSE;
1813
1814            pAudioSbrUserdata->m_pFirstAU = (M4_AccessUnit*)M4OSA_malloc(
1815                sizeof(M4_AccessUnit),M4READER_3GP, (M4OSA_Char*)"1st AAC AU");
1816            if (M4OSA_NULL == pAudioSbrUserdata->m_pFirstAU) {
1817                pAudioSbrUserdata->m_pAacDecoderUserConfig = M4OSA_NULL;
1818                err = M4ERR_ALLOC;
1819                goto Error;
1820            }
1821            pAudioSbrUserdata->m_pAacDecoderUserConfig = (M4_AacDecoderConfig*)\
1822                M4OSA_malloc(sizeof(M4_AacDecoderConfig),M4READER_3GP,
1823                (M4OSA_Char*)"m_pAacDecoderUserConfig");
1824            if (M4OSA_NULL == pAudioSbrUserdata->m_pAacDecoderUserConfig) {
1825                err = M4ERR_ALLOC;
1826                goto Error;
1827            }
1828        }
1829        if(M4DA_StreamTypeAudioAac == (*pStreamHandler)->m_streamType) {
1830            M4_AudioStreamHandler* pAudioStreamHandler =
1831                (M4_AudioStreamHandler*)(*pStreamHandler);
1832            M4READER_AudioSbrUserdata* pUserData = (M4READER_AudioSbrUserdata*)\
1833                (pAudioStreamHandler->m_basicProperties.m_pUserData);
1834
1835            err = VideoEditor3gpReader_fillAuStruct(pC, (*pStreamHandler),
1836                (M4_AccessUnit*)pUserData->m_pFirstAU);
1837            if (M4NO_ERROR != err) {
1838                goto Error;
1839            }
1840            err = VideoEditor3gpReader_getNextAu(pC, (*pStreamHandler),
1841                (M4_AccessUnit*)pUserData->m_pFirstAU);
1842            if (M4NO_ERROR != err) {
1843                goto Error;
1844            }
1845            err = VideoEditor3gpReader_reset(pC, (*pStreamHandler));
1846            if (M4NO_ERROR != err) {
1847                goto Error;
1848            }
1849        }
1850    }
1851    pC->mCurrTrack++; //Increment the current track to get next track
1852    LOGV("pC->mCurrTrack = %d",pC->mCurrTrack);
1853
1854    if (!haveAudio && !haveVideo) {
1855        *pMediaFamily=M4READER_kMediaFamilyUnknown;
1856        return M4ERR_READER_UNKNOWN_STREAM_TYPE;
1857    }
1858Error:
1859    LOGV("VideoEditor3gpReader_getNextStreamHandler end error = %d",err);
1860    return err;
1861}
1862
1863M4OSA_ERR VideoEditor3gpReader_getPrevRapTime(M4OSA_Context context,
1864    M4_StreamHandler *pStreamHandler, M4OSA_Int32* pTime)
1865{
1866    VideoEditor3gpReader_Context *pC = (VideoEditor3gpReader_Context*)context;
1867    M4OSA_ERR err = M4NO_ERROR;
1868    MediaBuffer *mMediaBuffer = M4OSA_NULL;
1869    MediaSource::ReadOptions options;
1870    M4OSA_Time time64;
1871    int64_t tempTime64 = 0;
1872    status_t error;
1873
1874    LOGV("VideoEditor3gpReader_getPrevRapTime begin");
1875
1876    M4OSA_DEBUG_IF1((pC == 0), M4ERR_PARAMETER,
1877        "VideoEditor3gpReader_getPrevRapTime: invalid context");
1878    M4OSA_DEBUG_IF1((pStreamHandler == 0), M4ERR_PARAMETER,
1879        "VideoEditor3gpReader_getPrevRapTime invalid pointer to StreamHandler");
1880    M4OSA_DEBUG_IF1((pTime == 0), M4ERR_PARAMETER,
1881        "VideoEditor3gpReader_getPrevRapTime: invalid time pointer");
1882    if (*pTime == (pStreamHandler->m_duration)) {
1883		*pTime -= 1;
1884	}
1885    M4OSA_INT64_FROM_INT32(time64, *pTime);
1886    time64 = time64 * 1000;
1887
1888    LOGV("VideoEditor3gpReader_getPrevRapTime seek time: %ld",time64);
1889    options.setSeekTo(time64, MediaSource::ReadOptions::SEEK_PREVIOUS_SYNC);
1890    error = pC->mVideoSource->read(&mMediaBuffer, &options);
1891    if (error != OK) {
1892        //Can not get the previous Sync.
1893        //Must be end of stream.
1894		return M4WAR_NO_MORE_AU;
1895    }
1896
1897    mMediaBuffer->meta_data()->findInt64(kKeyTime, (int64_t*)&tempTime64);
1898    LOGV("VideoEditor3gpReader_getPrevRapTime read time %ld, %x", tempTime64,
1899        mMediaBuffer);
1900
1901    (*pTime) =  (tempTime64) / 1000;
1902
1903    if(mMediaBuffer != M4OSA_NULL) {
1904        LOGV(" mMediaBuffer size = %d length %d", mMediaBuffer->size(),
1905            mMediaBuffer->range_length());
1906        mMediaBuffer->release();
1907        mMediaBuffer = M4OSA_NULL;
1908    }
1909    options.clearSeekTo();
1910
1911    if(error != OK) {
1912        LOGV("VideoEditor3gpReader_getPrevRapTime end \
1913            M4WAR_READER_INFORMATION_NOT_PRESENT");
1914        return M4WAR_READER_INFORMATION_NOT_PRESENT;
1915    } else {
1916        LOGV("VideoEditor3gpReader_getPrevRapTime end: err %x", err);
1917        err = M4NO_ERROR;
1918        return err;
1919    }
1920}
1921
1922extern "C" {
1923M4OSA_ERR VideoEditor3gpReader_getInterface(M4READER_MediaType *pMediaType,
1924        M4READER_GlobalInterface **pRdrGlobalInterface,
1925        M4READER_DataInterface **pRdrDataInterface) {
1926
1927    M4OSA_ERR err = M4NO_ERROR;
1928
1929    VIDEOEDITOR_CHECK(M4OSA_NULL != pMediaType,      M4ERR_PARAMETER);
1930    VIDEOEDITOR_CHECK(M4OSA_NULL != pRdrGlobalInterface, M4ERR_PARAMETER);
1931    VIDEOEDITOR_CHECK(M4OSA_NULL != pRdrDataInterface, M4ERR_PARAMETER);
1932
1933    LOGV("VideoEditor3gpReader_getInterface begin");
1934    LOGV("VideoEditor3gpReader_getInterface %d 0x%x 0x%x", *pMediaType,
1935        *pRdrGlobalInterface,*pRdrDataInterface);
1936
1937    SAFE_MALLOC(*pRdrGlobalInterface, M4READER_GlobalInterface, 1,
1938        "VideoEditor3gpReader_getInterface");
1939    SAFE_MALLOC(*pRdrDataInterface, M4READER_DataInterface, 1,
1940        "VideoEditor3gpReader_getInterface");
1941
1942    *pMediaType = M4READER_kMediaType3GPP;
1943
1944    (*pRdrGlobalInterface)->m_pFctCreate       = VideoEditor3gpReader_create;
1945    (*pRdrGlobalInterface)->m_pFctDestroy      = VideoEditor3gpReader_destroy;
1946    (*pRdrGlobalInterface)->m_pFctOpen         = VideoEditor3gpReader_open;
1947    (*pRdrGlobalInterface)->m_pFctClose        = VideoEditor3gpReader_close;
1948    (*pRdrGlobalInterface)->m_pFctGetOption    = VideoEditor3gpReader_getOption;
1949    (*pRdrGlobalInterface)->m_pFctSetOption    = VideoEditor3gpReader_setOption;
1950    (*pRdrGlobalInterface)->m_pFctGetNextStream =
1951        VideoEditor3gpReader_getNextStreamHandler;
1952    (*pRdrGlobalInterface)->m_pFctFillAuStruct =
1953        VideoEditor3gpReader_fillAuStruct;
1954    (*pRdrGlobalInterface)->m_pFctStart        = M4OSA_NULL;
1955    (*pRdrGlobalInterface)->m_pFctStop         = M4OSA_NULL;
1956    (*pRdrGlobalInterface)->m_pFctJump         = VideoEditor3gpReader_jump;
1957    (*pRdrGlobalInterface)->m_pFctReset        = VideoEditor3gpReader_reset;
1958    (*pRdrGlobalInterface)->m_pFctGetPrevRapTime =
1959        VideoEditor3gpReader_getPrevRapTime;
1960    (*pRdrDataInterface)->m_pFctGetNextAu      = VideoEditor3gpReader_getNextAu;
1961    (*pRdrDataInterface)->m_readerContext      = M4OSA_NULL;
1962
1963cleanUp:
1964    if( M4NO_ERROR == err ) {
1965        LOGV("VideoEditor3gpReader_getInterface no error");
1966    } else {
1967        SAFE_FREE(*pRdrGlobalInterface);
1968        SAFE_FREE(*pRdrDataInterface);
1969
1970        LOGV("VideoEditor3gpReader_getInterface ERROR 0x%X", err);
1971    }
1972    LOGV("VideoEditor3gpReader_getInterface end");
1973    return err;
1974}
1975
1976}  /* extern "C" */
1977
1978}  /* namespace android */
1979
1980
1981