13306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ------------------------------------------------------------------
23306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong * Copyright (C) 1998-2009 PacketVideo
33306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong *
43306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong * Licensed under the Apache License, Version 2.0 (the "License");
53306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong * you may not use this file except in compliance with the License.
63306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong * You may obtain a copy of the License at
73306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong *
83306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong *      http://www.apache.org/licenses/LICENSE-2.0
93306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong *
103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong * Unless required by applicable law or agreed to in writing, software
113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong * distributed under the License is distributed on an "AS IS" BASIS,
123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong * express or implied.
143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong * See the License for the specific language governing permissions
153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong * and limitations under the License.
163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong * -------------------------------------------------------------------
173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong */
183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#include "mp4dec_lib.h"
193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#include "vlc_decode.h"
203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#include "bitstream.h"
213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#define OSCL_DISABLE_WARNING_CONDITIONAL_IS_CONSTANT
233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef DEC_INTERNAL_MEMORY_OPT
253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#define QCIF_MBS 99
263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#define QCIF_BS (4*QCIF_MBS)
273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#define QCIF_MB_ROWS 11
283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongextern uint8                IMEM_sliceNo[QCIF_MBS];
293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongextern uint8                IMEM_acPredFlag[QCIF_MBS];
303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongextern uint8                IMEM_headerInfo_Mode[QCIF_MBS];
313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongextern uint8                IMEM_headerInfo_CBP[QCIF_MBS];
323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongextern int                  IMEM_headerInfo_QPMB[QCIF_MBS];
333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongextern MacroBlock           IMEM_mblock;
343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongextern MOT                  IMEM_motX[QCIF_BS];
353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongextern MOT                  IMEM_motY[QCIF_BS];
363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongextern BitstreamDecVideo    IMEM_BitstreamDecVideo[4];
373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongextern typeDCStore          IMEM_predDC[QCIF_MBS];
383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongextern typeDCACStore        IMEM_predDCAC_col[QCIF_MB_ROWS+1];
393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongextern VideoDecData         IMEM_VideoDecData[1];
413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongextern Vop                  IMEM_currVop[1];
423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongextern Vop                  IMEM_prevVop[1];
433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongextern PIXEL                IMEM_currVop_yChan[QCIF_MBS*128*3];
443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongextern PIXEL                IMEM_prevVop_yChan[QCIF_MBS*128*3];
453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongextern uint8                IMEM_pstprcTypCur[6*QCIF_MBS];
463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongextern uint8                IMEM_pstprcTypPrv[6*QCIF_MBS];
473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongextern Vop                  IMEM_vopHEADER[2];
503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongextern Vol                  IMEM_VOL[2];
513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongextern Vop                  IMEM_vopHeader[2][1];
523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongextern Vol                  IMEM_vol[2][1];
533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Function : PVInitVideoDecoder()                                         */
583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Date     : 04/11/2000, 08/29/2000                                       */
593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Purpose  : Initialization of the MPEG-4 video decoder library.          */
603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*             The return type is Bool instead of PV_STATUS because         */
613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*             we don't want to expose PV_STATUS to (outside) programmers   */
623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*             that use our decoder library SDK.                            */
633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  In/out   :                                                              */
643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Return   : PV_TRUE if successed, PV_FALSE if failed.                    */
653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Modified :                                                              */
663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames DongOSCL_EXPORT_REF Bool PVInitVideoDecoder(VideoDecControls *decCtrl, uint8 *volbuf[],
683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                                        int32 *volbuf_size, int nLayers, int width, int height, MP4DecodingMode mode)
693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    VideoDecData *video = (VideoDecData *) decCtrl->videoDecoderData;
713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    Bool status = PV_TRUE;
723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int idx;
733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    BitstreamDecVideo *stream;
743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    oscl_memset(decCtrl, 0, sizeof(VideoDecControls)); /* fix a size bug.   03/28/2001 */
773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    decCtrl->nLayers = nLayers;
783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    for (idx = 0; idx < nLayers; idx++)
793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        decCtrl->volbuf[idx] = volbuf[idx];
813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        decCtrl->volbuf_size[idx] = volbuf_size[idx];
823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* memory allocation & initialization */
853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef DEC_INTERNAL_MEMORY_OPT
863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video = IMEM_VideoDecData;
873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#else
883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video = (VideoDecData *) oscl_malloc(sizeof(VideoDecData));
893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video != NULL)
913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        oscl_memset(video, 0, sizeof(VideoDecData));
933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->memoryUsage = sizeof(VideoDecData);
943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->numberOfLayers = nLayers;
953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef DEC_INTERNAL_MEMORY_OPT
963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->vol = (Vol **) IMEM_VOL;
973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#else
983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->vol = (Vol **) oscl_malloc(nLayers * sizeof(Vol *));
993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
1003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->vol == NULL) status = PV_FALSE;
1013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->memoryUsage += nLayers * sizeof(Vol *);
1023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        /* we need to setup this pointer for the application to */
1053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        /*    pass it around.                                   */
1063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        decCtrl->videoDecoderData = (void *) video;
1073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->videoDecControls = decCtrl;  /* yes. we have a cyclic */
1083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        /* references here :)    */
1093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        /* Allocating Vop space, this has to change when we add */
1113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        /*    spatial scalability to the decoder                */
1123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef DEC_INTERNAL_MEMORY_OPT
1133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->currVop = IMEM_currVop;
1143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->currVop == NULL) status = PV_FALSE;
1153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else oscl_memset(video->currVop, 0, sizeof(Vop));
1163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->prevVop = IMEM_prevVop;
1173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->prevVop == NULL) status = PV_FALSE;
1183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else oscl_memset(video->prevVop, 0, sizeof(Vop));
1193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->memoryUsage += (sizeof(Vop) * 2);
1203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->vopHeader = (Vop **) IMEM_vopHEADER;
1213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#else
1223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->currVop = (Vop *) oscl_malloc(sizeof(Vop));
1243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->currVop == NULL) status = PV_FALSE;
1253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else oscl_memset(video->currVop, 0, sizeof(Vop));
1263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->prevVop = (Vop *) oscl_malloc(sizeof(Vop));
1273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->prevVop == NULL) status = PV_FALSE;
1283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else oscl_memset(video->prevVop, 0, sizeof(Vop));
1293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->memoryUsage += (sizeof(Vop) * 2);
1303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->vopHeader = (Vop **) oscl_malloc(sizeof(Vop *) * nLayers);
1323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
1333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->vopHeader == NULL) status = PV_FALSE;
1343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else oscl_memset(video->vopHeader, 0, sizeof(Vop *)*nLayers);
1353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->memoryUsage += (sizeof(Vop *) * nLayers);
1363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->initialized = PV_FALSE;
1383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        /* Decode the header to get all information to allocate data */
1393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (status == PV_TRUE)
1403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
1413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            /* initialize decoded frame counter.   04/24/2001 */
1423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            video->frame_idx = -1;
1433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            for (idx = 0; idx < nLayers; idx++)
1463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
1473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef DEC_INTERNAL_MEMORY_OPT
1493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                video->vopHeader[idx] = IMEM_vopHeader[idx];
1503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#else
1513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                video->vopHeader[idx] = (Vop *) oscl_malloc(sizeof(Vop));
1523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
1533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (video->vopHeader[idx] == NULL)
1543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
1553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    status = PV_FALSE;
1563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    break;
1573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
1583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                else
1593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
1603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    oscl_memset(video->vopHeader[idx], 0, sizeof(Vop));
1613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    video->vopHeader[idx]->timeStamp = 0;
1623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    video->memoryUsage += (sizeof(Vop));
1633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
1643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef DEC_INTERNAL_MEMORY_OPT
1653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                video->vol[idx] = IMEM_vol[idx];
1663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                video->memoryUsage += sizeof(Vol);
1673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                oscl_memset(video->vol[idx], 0, sizeof(Vol));
1683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (video->vol[idx] == NULL) status = PV_FALSE;
1693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                stream = IMEM_BitstreamDecVideo;
1703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#else
1713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                video->vol[idx] = (Vol *) oscl_malloc(sizeof(Vol));
1723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (video->vol[idx] == NULL)
1733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
1743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    status = PV_FALSE;
1753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    break;
1763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
1773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                else
1783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
1793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    video->memoryUsage += sizeof(Vol);
1803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    oscl_memset(video->vol[idx], 0, sizeof(Vol));
1813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
1823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                stream = (BitstreamDecVideo *) oscl_malloc(sizeof(BitstreamDecVideo));
1843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
1853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                video->memoryUsage += sizeof(BitstreamDecVideo);
1863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (stream == NULL)
1873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
1883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    status = PV_FALSE;
1893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    break;
1903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
1913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                else
1923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
1933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    int32 buffer_size;
1943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    if ((buffer_size = BitstreamOpen(stream, idx)) < 0)
1953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    {
1963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        mp4dec_log("InitVideoDecoder(): Can't allocate bitstream buffer.\n");
1973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        status = PV_FALSE;
1983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        break;
1993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    }
2003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    video->memoryUsage += buffer_size;
2013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    video->vol[idx]->bitstream = stream;
2023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    video->vol[idx]->volID = idx;
2033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    video->vol[idx]->timeInc_offset = 0;  /*  11/12/01 */
2043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    video->vlcDecCoeffIntra = &VlcDecTCOEFShortHeader;
2053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    video->vlcDecCoeffInter = &VlcDecTCOEFShortHeader;
2063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    if (mode == MPEG4_MODE)
2073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    {
2083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        /* Set up VOL header bitstream for frame-based decoding.  08/30/2000 */
2093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        BitstreamReset(stream, decCtrl->volbuf[idx], decCtrl->volbuf_size[idx]);
2103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        switch (DecodeVOLHeader(video, idx))
2123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        {
2133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                            case PV_SUCCESS :
2143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                                if (status == PV_TRUE)
2153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                                    status = PV_TRUE;   /*  we want to make sure that if first layer is bad, second layer is good return PV_FAIL */
2163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                                else
2173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                                    status = PV_FALSE;
2183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                                break;
2193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef PV_TOLERATE_VOL_ERRORS
2203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                            case PV_BAD_VOLHEADER:
2213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                                status = PV_TRUE;
2223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                                break;
2233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
2243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                            default :
2253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                                status = PV_FALSE;
2263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                                break;
2273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        }
2283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    }
2303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    else
2313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    {
2323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        video->shortVideoHeader = PV_TRUE;
2333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    }
2343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    if (video->shortVideoHeader == PV_TRUE)
2363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    {
2373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        mode = H263_MODE;
2383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        /* Set max width and height.  In H.263 mode, we use    */
2393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        /*  volbuf_size[0] to pass in width and volbuf_size[1] */
2403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        /*  to pass in height.                    04/23/2001 */
2413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        video->prevVop->temporalRef = 0; /*  11/12/01 */
2423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        /* Compute some convenience variables:   04/23/2001 */
2433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        video->vol[idx]->quantType = 0;
2443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        video->vol[idx]->quantPrecision = 5;
2453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        video->vol[idx]->errorResDisable = 1;
2463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        video->vol[idx]->dataPartitioning = 0;
2473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        video->vol[idx]->useReverseVLC = 0;
2483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        video->intra_acdcPredDisable = 1;
2493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        video->vol[idx]->scalability = 0;
2503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        video->size = (int32)width * height;
2513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        video->displayWidth = video->width = width;
2533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        video->displayHeight = video->height = height;
2543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef PV_ANNEX_IJKT_SUPPORT
2553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        video->modified_quant = 0;
2563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        video->advanced_INTRA = 0;
2573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        video->deblocking = 0;
2583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        video->slice_structure = 0;
2593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
2603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    }
2613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
2633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
2643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
2663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (status != PV_FALSE)
2673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
2683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            status = PVAllocVideoData(decCtrl, width, height, nLayers);
2693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            video->initialized = PV_TRUE;
2703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
2713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
2723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else
2733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
2743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        status = PV_FALSE;
2753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
2763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (status == PV_FALSE) PVCleanUpVideoDecoder(decCtrl);
2783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return status;
2803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
2813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames DongBool PVAllocVideoData(VideoDecControls *decCtrl, int width, int height, int nLayers)
2833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
2843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    VideoDecData *video = (VideoDecData *) decCtrl->videoDecoderData;
2853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    Bool status = PV_TRUE;
2863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int nTotalMB;
2873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int nMBPerRow;
2883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int32 size;
2893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->shortVideoHeader == PV_TRUE)
2913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
2923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->displayWidth = video->width = width;
2933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->displayHeight = video->height = height;
2943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->nMBPerRow =
2963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            video->nMBinGOB  = video->width / MB_SIZE;
2973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->nMBPerCol =
2983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            video->nGOBinVop = video->height / MB_SIZE;
2993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->nTotalMB =
3003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            video->nMBPerRow * video->nMBPerCol;
3013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
3023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
3033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    size = (int32)sizeof(PIXEL) * video->width * video->height;
3043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef PV_MEMORY_POOL
3053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    decCtrl->size = size;
3063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#else
3073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef DEC_INTERNAL_MEMORY_OPT
3083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->currVop->yChan = IMEM_currVop_yChan; /* Allocate memory for all VOP OKA 3/2/1*/
3093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->currVop->yChan == NULL) status = PV_FALSE;
3103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->currVop->uChan = video->currVop->yChan + size;
3113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->currVop->vChan = video->currVop->uChan + (size >> 2);
3123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
3133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->prevVop->yChan = IMEM_prevVop_yChan; /* Allocate memory for all VOP OKA 3/2/1*/
3143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->prevVop->yChan == NULL) status = PV_FALSE;
3153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->prevVop->uChan = video->prevVop->yChan + size;
3163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->prevVop->vChan = video->prevVop->uChan + (size >> 2);
3173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#else
3183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->currVop->yChan = (PIXEL *) oscl_malloc(size * 3 / 2); /* Allocate memory for all VOP OKA 3/2/1*/
3193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->currVop->yChan == NULL) status = PV_FALSE;
3203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
3213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->currVop->uChan = video->currVop->yChan + size;
3223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->currVop->vChan = video->currVop->uChan + (size >> 2);
3233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->prevVop->yChan = (PIXEL *) oscl_malloc(size * 3 / 2); /* Allocate memory for all VOP OKA 3/2/1*/
3243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->prevVop->yChan == NULL) status = PV_FALSE;
3253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
3263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->prevVop->uChan = video->prevVop->yChan + size;
3273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->prevVop->vChan = video->prevVop->uChan + (size >> 2);
3283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
3293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->memoryUsage += (size * 3);
3303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif   // MEMORY_POOL
3313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* Note that baseVop, enhcVop is only used to hold enhancement */
3323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /*    layer header information.                  05/04/2000  */
3333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (nLayers > 1)
3343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
3353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->prevEnhcVop = (Vop *) oscl_malloc(sizeof(Vop));
3363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->memoryUsage += (sizeof(Vop));
3373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->prevEnhcVop == NULL)
3383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
3393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            status = PV_FALSE;
3403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
3413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else
3423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
3433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            oscl_memset(video->prevEnhcVop, 0, sizeof(Vop));
3443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifndef PV_MEMORY_POOL
3453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            video->prevEnhcVop->yChan = (PIXEL *) oscl_malloc(size * 3 / 2); /* Allocate memory for all VOP OKA 3/2/1*/
3463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (video->prevEnhcVop->yChan == NULL) status = PV_FALSE;
3473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            video->prevEnhcVop->uChan = video->prevEnhcVop->yChan + size;
3483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            video->prevEnhcVop->vChan = video->prevEnhcVop->uChan + (size >> 2);
3493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            video->memoryUsage += (3 * size / 2);
3503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
3513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
3523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
3533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
3543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* Allocating space for slices, AC prediction flag, and */
3553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /*    AC/DC prediction storage */
3563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    nTotalMB = video->nTotalMB;
3573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    nMBPerRow = video->nMBPerRow;
3583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
3593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef DEC_INTERNAL_MEMORY_OPT
3603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->sliceNo = (uint8 *)(IMEM_sliceNo);
3613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->sliceNo == NULL) status = PV_FALSE;
3623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->memoryUsage += nTotalMB;
3633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->acPredFlag = (uint8 *)(IMEM_acPredFlag);
3643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->acPredFlag == NULL) status = PV_FALSE;
3653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->memoryUsage += (nTotalMB);
3663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->predDC = (typeDCStore *)(IMEM_predDC);
3673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->predDC == NULL) status = PV_FALSE;
3683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->memoryUsage += (nTotalMB * sizeof(typeDCStore));
3693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->predDCAC_col = (typeDCACStore *)(IMEM_predDCAC_col);
3703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->predDCAC_col == NULL) status = PV_FALSE;
3713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->memoryUsage += ((nMBPerRow + 1) * sizeof(typeDCACStore));
3723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->predDCAC_row = video->predDCAC_col + 1;
3733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->headerInfo.Mode = (uint8 *)(IMEM_headerInfo_Mode);
3743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->headerInfo.Mode == NULL) status = PV_FALSE;
3753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->memoryUsage += nTotalMB;
3763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->headerInfo.CBP = (uint8 *)(IMEM_headerInfo_CBP);
3773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->headerInfo.CBP == NULL) status = PV_FALSE;
3783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->memoryUsage += nTotalMB;
3793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->QPMB = (int *)(IMEM_headerInfo_QPMB);
3803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->QPMB == NULL) status = PV_FALSE;
3813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->memoryUsage += (nTotalMB * sizeof(int));
3823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->mblock = &IMEM_mblock;
3833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->mblock == NULL) status = PV_FALSE;
3843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    oscl_memset(video->mblock->block, 0, sizeof(int16)*6*NCOEFF_BLOCK); //  Aug 23,2005
3853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
3863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->memoryUsage += sizeof(MacroBlock);
3873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->motX = (MOT *)(IMEM_motX);
3883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->motX == NULL) status = PV_FALSE;
3893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->motY = (MOT *)(IMEM_motY);
3903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->motY == NULL) status = PV_FALSE;
3913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->memoryUsage += (sizeof(MOT) * 8 * nTotalMB);
3923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#else
3933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->sliceNo = (uint8 *) oscl_malloc(nTotalMB);
3943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->sliceNo == NULL) status = PV_FALSE;
3953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->memoryUsage += nTotalMB;
3963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
3973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->acPredFlag = (uint8 *) oscl_malloc(nTotalMB * sizeof(uint8));
3983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->acPredFlag == NULL) status = PV_FALSE;
3993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->memoryUsage += (nTotalMB);
4003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->predDC = (typeDCStore *) oscl_malloc(nTotalMB * sizeof(typeDCStore));
4023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->predDC == NULL) status = PV_FALSE;
4033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->memoryUsage += (nTotalMB * sizeof(typeDCStore));
4043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->predDCAC_col = (typeDCACStore *) oscl_malloc((nMBPerRow + 1) * sizeof(typeDCACStore));
4063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->predDCAC_col == NULL) status = PV_FALSE;
4073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->memoryUsage += ((nMBPerRow + 1) * sizeof(typeDCACStore));
4083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* element zero will be used for storing vertical (col) AC coefficients */
4103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /*  the rest will be used for storing horizontal (row) AC coefficients  */
4113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->predDCAC_row = video->predDCAC_col + 1;        /*  ACDC */
4123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* Allocating HeaderInfo structure & Quantizer array */
4143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->headerInfo.Mode = (uint8 *) oscl_malloc(nTotalMB);
4153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->headerInfo.Mode == NULL) status = PV_FALSE;
4163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->memoryUsage += nTotalMB;
4173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->headerInfo.CBP = (uint8 *) oscl_malloc(nTotalMB);
4183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->headerInfo.CBP == NULL) status = PV_FALSE;
4193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->memoryUsage += nTotalMB;
4203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->QPMB = (int16 *) oscl_malloc(nTotalMB * sizeof(int16));
4213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->QPMB == NULL) status = PV_FALSE;
4223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->memoryUsage += (nTotalMB * sizeof(int));
4233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* Allocating macroblock space */
4253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->mblock = (MacroBlock *) oscl_malloc(sizeof(MacroBlock));
4263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->mblock == NULL)
4273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
4283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        status = PV_FALSE;
4293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
4303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else
4313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
4323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        oscl_memset(video->mblock->block, 0, sizeof(int16)*6*NCOEFF_BLOCK); //  Aug 23,2005
4333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->memoryUsage += sizeof(MacroBlock);
4353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
4363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* Allocating motion vector space */
4373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->motX = (MOT *) oscl_malloc(sizeof(MOT) * 4 * nTotalMB);
4383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->motX == NULL) status = PV_FALSE;
4393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->motY = (MOT *) oscl_malloc(sizeof(MOT) * 4 * nTotalMB);
4403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->motY == NULL) status = PV_FALSE;
4413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->memoryUsage += (sizeof(MOT) * 8 * nTotalMB);
4423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
4433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef PV_POSTPROC_ON
4453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* Allocating space for post-processing Mode */
4463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef DEC_INTERNAL_MEMORY_OPT
4473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->pstprcTypCur = IMEM_pstprcTypCur;
4483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->memoryUsage += (nTotalMB * 6);
4493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->pstprcTypCur == NULL)
4503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
4513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        status = PV_FALSE;
4523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
4533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else
4543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
4553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        oscl_memset(video->pstprcTypCur, 0, 4*nTotalMB + 2*nTotalMB);
4563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
4573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->pstprcTypPrv = IMEM_pstprcTypPrv;
4593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->memoryUsage += (nTotalMB * 6);
4603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->pstprcTypPrv == NULL)
4613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
4623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        status = PV_FALSE;
4633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
4643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else
4653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
4663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        oscl_memset(video->pstprcTypPrv, 0, nTotalMB*6);
4673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
4683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#else
4703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->pstprcTypCur = (uint8 *) oscl_malloc(nTotalMB * 6);
4713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->memoryUsage += (nTotalMB * 6);
4723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->pstprcTypCur == NULL)
4733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
4743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        status = PV_FALSE;
4753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
4763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else
4773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
4783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        oscl_memset(video->pstprcTypCur, 0, 4*nTotalMB + 2*nTotalMB);
4793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
4803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->pstprcTypPrv = (uint8 *) oscl_malloc(nTotalMB * 6);
4823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->memoryUsage += (nTotalMB * 6);
4833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->pstprcTypPrv == NULL)
4843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
4853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        status = PV_FALSE;
4863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
4873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else
4883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
4893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        oscl_memset(video->pstprcTypPrv, 0, nTotalMB*6);
4903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
4913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
4933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
4953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* initialize the decoder library */
4973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->prevVop->predictionType = I_VOP;
4983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->prevVop->timeStamp = 0;
4993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifndef PV_MEMORY_POOL
5003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    oscl_memset(video->prevVop->yChan, 16, sizeof(uint8)*size);     /*  10/31/01 */
5013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    oscl_memset(video->prevVop->uChan, 128, sizeof(uint8)*size / 2);
5023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    oscl_memset(video->currVop->yChan, 0, sizeof(uint8)*size*3 / 2);
5043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (nLayers > 1)
5053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
5063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        oscl_memset(video->prevEnhcVop->yChan, 0, sizeof(uint8)*size*3 / 2);
5073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->prevEnhcVop->timeStamp = 0;
5083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
5093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->concealFrame = video->prevVop->yChan;               /*  07/07/2001 */
5103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    decCtrl->outputFrame = video->prevVop->yChan;              /*  06/19/2002 */
5113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
5123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* always start from base layer */
5143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->currLayer = 0;
5153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return status;
5163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
5173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
5193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Function : PVResetVideoDecoder()                                        */
5203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Date     : 01/14/2002                                                   */
5213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Purpose  : Reset video timestamps                                       */
5223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  In/out   :                                                              */
5233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Return   : PV_TRUE if successed, PV_FALSE if failed.                    */
5243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Modified :                                                              */
5253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
5263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames DongBool PVResetVideoDecoder(VideoDecControls *decCtrl)
5273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
5283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    VideoDecData *video = (VideoDecData *) decCtrl->videoDecoderData;
5293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int idx;
5303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    for (idx = 0; idx < decCtrl->nLayers; idx++)
5323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
5333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->vopHeader[idx]->timeStamp = 0;
5343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
5353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->prevVop->timeStamp = 0;
5363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (decCtrl->nLayers > 1)
5373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->prevEnhcVop->timeStamp = 0;
5383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    oscl_memset(video->mblock->block, 0, sizeof(int16)*6*NCOEFF_BLOCK); //  Aug 23,2005
5403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return PV_TRUE;
5423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
5433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
5463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Function : PVCleanUpVideoDecoder()                                      */
5473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Date     : 04/11/2000, 08/29/2000                                       */
5483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Purpose  : Cleanup of the MPEG-4 video decoder library.                 */
5493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  In/out   :                                                              */
5503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Return   : PV_TRUE if successed, PV_FALSE if failed.                    */
5513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Modified :                                                              */
5523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
5533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames DongOSCL_EXPORT_REF Bool PVCleanUpVideoDecoder(VideoDecControls *decCtrl)
5543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
5553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int idx;
5563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    VideoDecData *video = (VideoDecData *) decCtrl->videoDecoderData;
5573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef DEC_INTERNAL_MEMORY_OPT
5583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video)
5593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
5603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef PV_POSTPROC_ON
5613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->pstprcTypCur = NULL;
5623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->pstprcTypPrv = NULL;
5633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
5643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->acPredFlag       = NULL;
5663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->sliceNo          = NULL;
5673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->motX             = NULL;
5683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->motY             = NULL;
5693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->mblock           = NULL;
5703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->QPMB             = NULL;
5713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->predDC           = NULL;
5723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->predDCAC_row     = NULL;
5733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->predDCAC_col     = NULL;
5743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->headerInfo.Mode  = NULL;
5753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->headerInfo.CBP   = NULL;
5763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->numberOfLayers > 1)
5773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
5783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (video->prevEnhcVop)
5793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
5803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                video->prevEnhcVop->uChan = NULL;
5813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                video->prevEnhcVop->vChan = NULL;
5823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (video->prevEnhcVop->yChan) oscl_free(video->prevEnhcVop->yChan);
5833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                oscl_free(video->prevEnhcVop);
5843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
5853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
5863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->currVop)
5873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
5883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            video->currVop->uChan = NULL;
5893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            video->currVop->vChan = NULL;
5903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (video->currVop->yChan)
5913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                video->currVop->yChan = NULL;
5923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            video->currVop = NULL;
5933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
5943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->prevVop)
5953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
5963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            video->prevVop->uChan = NULL;
5973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            video->prevVop->vChan = NULL;
5983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (video->prevVop->yChan)
5993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                video->prevVop->yChan = NULL;
6003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            video->prevVop = NULL;
6013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
6023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
6033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->vol)
6043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
6053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            for (idx = 0; idx < video->numberOfLayers; idx++)
6063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
6073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (video->vol[idx])
6083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
6093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    BitstreamClose(video->vol[idx]->bitstream);
6103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    video->vol[idx]->bitstream = NULL;
6113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    video->vol[idx] = NULL;
6123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
6133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                video->vopHeader[idx] = NULL;
6143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
6153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
6163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            video->vol = NULL;
6173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            video->vopHeader = NULL;
6183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
6193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
6203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video = NULL;
6213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        decCtrl->videoDecoderData = NULL;
6223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
6233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
6243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#else
6253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
6263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video)
6273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
6283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef PV_POSTPROC_ON
6293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->pstprcTypCur) oscl_free(video->pstprcTypCur);
6303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->pstprcTypPrv) oscl_free(video->pstprcTypPrv);
6313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
6323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->predDC) oscl_free(video->predDC);
6333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->predDCAC_row = NULL;
6343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->predDCAC_col) oscl_free(video->predDCAC_col);
6353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->motX) oscl_free(video->motX);
6363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->motY) oscl_free(video->motY);
6373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->mblock) oscl_free(video->mblock);
6383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->QPMB) oscl_free(video->QPMB);
6393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->headerInfo.Mode) oscl_free(video->headerInfo.Mode);
6403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->headerInfo.CBP) oscl_free(video->headerInfo.CBP);
6413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->sliceNo) oscl_free(video->sliceNo);
6423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->acPredFlag) oscl_free(video->acPredFlag);
6433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
6443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->numberOfLayers > 1)
6453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
6463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (video->prevEnhcVop)
6473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
6483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                video->prevEnhcVop->uChan = NULL;
6493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                video->prevEnhcVop->vChan = NULL;
6503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (video->prevEnhcVop->yChan) oscl_free(video->prevEnhcVop->yChan);
6513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                oscl_free(video->prevEnhcVop);
6523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
6533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
6543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->currVop)
6553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
6563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
6573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifndef PV_MEMORY_POOL
6583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            video->currVop->uChan = NULL;
6593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            video->currVop->vChan = NULL;
6603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (video->currVop->yChan)
6613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                oscl_free(video->currVop->yChan);
6623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
6633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            oscl_free(video->currVop);
6643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
6653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->prevVop)
6663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
6673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifndef PV_MEMORY_POOL
6683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            video->prevVop->uChan = NULL;
6693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            video->prevVop->vChan = NULL;
6703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (video->prevVop->yChan)
6713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                oscl_free(video->prevVop->yChan);
6723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
6733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            oscl_free(video->prevVop);
6743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
6753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
6763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->vol)
6773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
6783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            for (idx = 0; idx < video->numberOfLayers; idx++)
6793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
6803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (video->vol[idx])
6813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
6823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    if (video->vol[idx]->bitstream)
6833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    {
6843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        BitstreamClose(video->vol[idx]->bitstream);
6853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        oscl_free(video->vol[idx]->bitstream);
6863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    }
6873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    oscl_free(video->vol[idx]);
6883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
6893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
6903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
6913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            oscl_free(video->vol);
6923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
6933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
6943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        for (idx = 0; idx < video->numberOfLayers; idx++)
6953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
6963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (video->vopHeader[idx]) oscl_free(video->vopHeader[idx]);
6973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
6983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
6993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->vopHeader) oscl_free(video->vopHeader);
7003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
7013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        oscl_free(video);
7023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        decCtrl->videoDecoderData = NULL;
7033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
7043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
7053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return PV_TRUE;
7063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
7073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
7083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Function : PVGetVideoDimensions()                                       */
7093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Date     : 040505                                                       */
7103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Purpose  :                                                              */
7113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  In/out   :                                                              */
7123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Return   : the display_width and display_height of                      */
7133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*          the frame in the current layer.                                 */
7143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Note     : This is not a macro or inline function because we do         */
7153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*              not want to expose our internal data structure.             */
7163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Modified :                                                              */
7173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
7183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames DongOSCL_EXPORT_REF void PVGetVideoDimensions(VideoDecControls *decCtrl, int32 *display_width, int32 *display_height)
7193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
7203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    VideoDecData *video = (VideoDecData *)decCtrl->videoDecoderData;
7213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    *display_width = video->displayWidth;
7223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    *display_height = video->displayHeight;
7233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
7243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
725b9ff4b4f631239a6a37fe6588e025cb387150c0eAndreas HuberOSCL_EXPORT_REF void PVGetBufferDimensions(VideoDecControls *decCtrl, int32 *width, int32 *height) {
726b9ff4b4f631239a6a37fe6588e025cb387150c0eAndreas Huber    VideoDecData *video = (VideoDecData *)decCtrl->videoDecoderData;
727b9ff4b4f631239a6a37fe6588e025cb387150c0eAndreas Huber    *width = video->width;
728b9ff4b4f631239a6a37fe6588e025cb387150c0eAndreas Huber    *height = video->height;
729b9ff4b4f631239a6a37fe6588e025cb387150c0eAndreas Huber}
730b9ff4b4f631239a6a37fe6588e025cb387150c0eAndreas Huber
7313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
7323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Function : PVGetVideoTimeStamp()                                        */
7333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Date     : 04/27/2000, 08/29/2000                                       */
7343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Purpose  :                                                              */
7353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  In/out   :                                                              */
7363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Return   : current time stamp in millisecond.                           */
7373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Note     :                                                              */
7383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Modified :                                                              */
7393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
7403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Donguint32 PVGetVideoTimeStamp(VideoDecControls *decCtrl)
7413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
7423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    VideoDecData *video = (VideoDecData *)decCtrl->videoDecoderData;
7433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return video->currTimestamp;
7443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
7453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
7463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
7473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
7483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Function : PVSetPostProcType()                                          */
7493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Date     : 07/07/2000                                                   */
7503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Purpose  :                                                              */
7513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  In/out   :                                                              */
7523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Return   : Set post-processing filter type.                             */
7533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Note     :                                                              */
7543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Modified : . 08/29/2000 changes the name for consistency.               */
7553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
7563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames DongOSCL_EXPORT_REF void PVSetPostProcType(VideoDecControls *decCtrl, int mode)
7573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
7583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    VideoDecData *video = (VideoDecData *)decCtrl->videoDecoderData;
7593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    video->postFilterType = mode;
7603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
7613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
7623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
7633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
7643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Function : PVGetDecBitrate()                                            */
7653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Date     : 08/23/2000                                                   */
7663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Purpose  :                                                              */
7673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  In/out   :                                                              */
7683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Return   : This function returns the average bits per second.           */
7693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Note     :                                                              */
7703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Modified :                                                              */
7713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
7723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongint PVGetDecBitrate(VideoDecControls *decCtrl)
7733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
7743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    VideoDecData *video = (VideoDecData *)decCtrl->videoDecoderData;
7753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int     idx;
7763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int32   sum = 0;
7773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
7783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    for (idx = 0; idx < BITRATE_AVERAGE_WINDOW; idx++)
7793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
7803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        sum += video->nBitsPerVop[idx];
7813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
7823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    sum = (sum * video->frameRate) / (10 * BITRATE_AVERAGE_WINDOW);
7833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return (int) sum;
7843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
7853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
7863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
7873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
7883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Function : PVGetDecFramerate()                                          */
7893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Date     : 08/23/2000                                                   */
7903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Purpose  :                                                              */
7913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  In/out   :                                                              */
7923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Return   : This function returns the average frame per 10 second.       */
7933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Note     : The fps can be calculated by PVGetDecFramerate()/10          */
7943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Modified :                                                              */
7953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
7963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongint PVGetDecFramerate(VideoDecControls *decCtrl)
7973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
7983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    VideoDecData *video = (VideoDecData *)decCtrl->videoDecoderData;
7993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return video->frameRate;
8013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
8023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
8043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Function : PVGetOutputFrame()                                           */
8053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Date     : 05/07/2001                                                   */
8063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Purpose  :                                                              */
8073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  In/out   :                                                              */
8083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Return   : This function returns the pointer to the output frame        */
8093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Note     :                                                              */
8103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Modified :                                                              */
8113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
8123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Donguint8 *PVGetDecOutputFrame(VideoDecControls *decCtrl)
8133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
8143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return decCtrl->outputFrame;
8153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
8163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
8183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Function : PVGetLayerID()                                               */
8193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Date     : 07/09/2001                                                   */
8203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Purpose  :                                                              */
8213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  In/out   :                                                              */
8223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Return   : This function returns decoded frame layer id (BASE/ENHANCE)  */
8233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Note     :                                                              */
8243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Modified :                                                              */
8253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
8263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongint PVGetLayerID(VideoDecControls *decCtrl)
8273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
8283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    VideoDecData *video = (VideoDecData *)decCtrl->videoDecoderData;
8293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return video->currLayer;
8303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
8313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
8323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Function : PVGetDecMemoryUsage()                                        */
8333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Date     : 08/23/2000                                                   */
8343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Purpose  :                                                              */
8353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  In/out   :                                                              */
8363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Return   : This function returns the amount of memory used.             */
8373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Note     :                                                              */
8383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Modified :                                                              */
8393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
8403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongint32 PVGetDecMemoryUsage(VideoDecControls *decCtrl)
8413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
8423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    VideoDecData *video = (VideoDecData *)decCtrl->videoDecoderData;
8433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return video->memoryUsage;
8443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
8453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
8483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Function : PVGetDecBitstreamMode()                                      */
8493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Date     : 08/23/2000                                                   */
8503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Purpose  :                                                              */
8513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  In/out   :                                                              */
8523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Return   : This function returns the decoding mode of the baselayer     */
8533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*              bitstream.                                                  */
8543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Note     :                                                              */
8553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Modified :                                                              */
8563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
8573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames DongOSCL_EXPORT_REF MP4DecodingMode PVGetDecBitstreamMode(VideoDecControls *decCtrl)
8583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
8593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    VideoDecData *video = (VideoDecData *)decCtrl->videoDecoderData;
8603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (video->shortVideoHeader)
8613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
8623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return H263_MODE;
8633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
8643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else
8653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
8663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return MPEG4_MODE;
8673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
8683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
8693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
8723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Function : PVExtractVolHeader()                                         */
8733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Date     : 08/29/2000                                                   */
8743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Purpose  :                                                              */
8753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  In/out   :                                                              */
8763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Return   : Extract vol header of the bitstream from buffer[].           */
8773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Note     :                                                              */
8783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Modified :                                                              */
8793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
8803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames DongBool PVExtractVolHeader(uint8 *video_buffer, uint8 *vol_header, int32 *vol_header_size)
8813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
8823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int idx = -1;
8833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    uint8 start_code_prefix[] = { 0x00, 0x00, 0x01 };
8843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    uint8 h263_prefix[] = { 0x00, 0x00, 0x80 };
8853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (oscl_memcmp(h263_prefix, video_buffer, 3) == 0) /* we have short header stream */
8873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
8883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        oscl_memcpy(vol_header, video_buffer, 32);
8893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        *vol_header_size = 32;
8903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return TRUE;
8913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
8923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else
8933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
8943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (oscl_memcmp(start_code_prefix, video_buffer, 3) ||
8953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                (video_buffer[3] != 0xb0 && video_buffer[3] >= 0x20)) return FALSE;
8963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        do
8983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
8993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            idx++;
9003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            while (oscl_memcmp(start_code_prefix, video_buffer + idx, 3))
9013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
9023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                idx++;
9033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (idx + 3 >= *vol_header_size) goto quit;
9043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
9053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
9063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        while (video_buffer[idx+3] != 0xb3 && video_buffer[idx+3] != 0xb6);
9073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        oscl_memcpy(vol_header, video_buffer, idx);
9093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        *vol_header_size = idx;
9103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return TRUE;
9113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
9123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongquit:
9143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    oscl_memcpy(vol_header, video_buffer, *vol_header_size);
9153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return FALSE;
9163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
9173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
9203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Function : PVLocateFrameHeader()                                        */
9213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Date     : 04/8/2005                                                    */
9223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Purpose  :                                                              */
9233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  In/out   :                                                              */
9243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Return   : Return the offset to the first SC in the buffer              */
9253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Note     :                                                              */
9263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Modified :                                                              */
9273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
9283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongint32 PVLocateFrameHeader(uint8 *ptr, int32 size)
9293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
9303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int count = 0;
9313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int32 i = size;
9323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (size < 1)
9343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
9353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return 0;
9363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
9373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    while (i--)
9383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
9393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if ((count > 1) && (*ptr == 0x01))
9403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
9413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            i += 2;
9423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            break;
9433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
9443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (*ptr++)
9463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            count = 0;
9473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else
9483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            count++;
9493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
9503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return (size - (i + 1));
9513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
9523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
9553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Function : PVLocateH263FrameHeader()                                    */
9563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Date     : 04/8/2005                                                    */
9573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Purpose  :                                                              */
9583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  In/out   :                                                              */
9593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Return   : Return the offset to the first SC in the buffer              */
9603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Note     :                                                              */
9613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Modified :                                                              */
9623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
9633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongint32 PVLocateH263FrameHeader(uint8 *ptr, int32 size)
9643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
9653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int count = 0;
9663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int32 i = size;
9673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (size < 1)
9693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
9703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return 0;
9713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
9723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    while (i--)
9743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
9753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if ((count > 1) && ((*ptr & 0xFC) == 0x80))
9763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
9773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            i += 2;
9783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            break;
9793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
9803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (*ptr++)
9823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            count = 0;
9833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else
9843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            count++;
9853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
9863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return (size - (i + 1));
9873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
9883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
9913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Function : PVDecodeVideoFrame()                                         */
9923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Date     : 08/29/2000                                                   */
9933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Purpose  : Decode one video frame and return a YUV-12 image.            */
9943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  In/out   :                                                              */
9953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Return   :                                                              */
9963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Note     :                                                              */
9973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Modified : 04/17/2001 removed PV_EOS, PV_END_OF_BUFFER              */
9983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*           : 08/22/2002 break up into 2 functions PVDecodeVopHeader and */
9993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*                          PVDecodeVopBody                                 */
10003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
10013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames DongOSCL_EXPORT_REF Bool PVDecodeVideoFrame(VideoDecControls *decCtrl, uint8 *buffer[],
10023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                                        uint32 timestamp[], int32 buffer_size[], uint use_ext_timestamp[], uint8 *currYUV)
10033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
10043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    PV_STATUS status = PV_FAIL;
10053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    VopHeaderInfo header_info;
10063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
10073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    status = (PV_STATUS)PVDecodeVopHeader(decCtrl, buffer, timestamp, buffer_size, &header_info, use_ext_timestamp, currYUV);
10083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (status != PV_TRUE)
10093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return PV_FALSE;
10103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
10113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (PVDecodeVopBody(decCtrl, buffer_size) != PV_TRUE)
10123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
10133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return PV_FALSE;
10143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
10153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
10163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return PV_TRUE;
10173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
10183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
10193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
10203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Function : PVDecodeVopHeader()                                          */
10213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Date     : 08/22/2002                                                   */
10223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Purpose  : Determine target layer and decode vop header, modified from  */
10233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*              original PVDecodeVideoFrame.                                */
10243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  In/out   :                                                              */
10253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Return   :                                                              */
10263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Note     :                                                              */
10273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Modified :                                                              */
10283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
10293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames DongBool PVDecodeVopHeader(VideoDecControls *decCtrl, uint8 *buffer[],
10303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                       uint32 timestamp[], int32 buffer_size[], VopHeaderInfo *header_info, uint use_ext_timestamp [], uint8 *currYUV)
10313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
10323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    VideoDecData *video = (VideoDecData *) decCtrl->videoDecoderData;
10333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    Vol *currVol;
10343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    Vop *currVop = video->currVop;
10353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    Vop **vopHeader = video->vopHeader;
10363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    BitstreamDecVideo *stream;
10373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
10383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int target_layer;
10393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
10403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef PV_SUPPORT_TEMPORAL_SCALABILITY
10413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    PV_STATUS status = PV_FAIL;
10423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int idx;
10433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int32 display_time;
10443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
10453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* decide which frame to decode next */
10463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (decCtrl->nLayers > 1)
10473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
10483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        display_time = target_layer = -1;
10493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        for (idx = 0; idx < decCtrl->nLayers; idx++)
10503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
10513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            /* do we have data for this layer? */
10523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (buffer_size[idx] <= 0)
10533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
10543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                timestamp[idx] = -1;
10553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                continue;
10563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
10573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
10583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            /* did the application provide a timestamp for this vop? */
10593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (timestamp[idx] < 0)
10603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
10613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (vopHeader[idx]->timeStamp < 0)
10623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
10633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    /* decode the timestamp in the bitstream */
10643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    video->currLayer = idx;
10653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    stream = video->vol[idx]->bitstream;
10663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    BitstreamReset(stream, buffer[idx], buffer_size[idx]);
10673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
10683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    while ((status = DecodeVOPHeader(video, vopHeader[idx], FALSE)) != PV_SUCCESS)
10693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    {
10703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        /* Try to find a VOP header in the buffer.   08/30/2000. */
10713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        if (PVSearchNextM4VFrame(stream) != PV_SUCCESS)
10723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        {
10733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                            /* if we don't have data for enhancement layer, */
10743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                            /*    don't just stop.   09/07/2000.          */
10753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                            buffer_size[idx] = 0;
10763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                            break;
10773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        }
10783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    }
10793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    if (status == PV_SUCCESS)
10803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    {
10813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        vopHeader[idx]->timeStamp =
10823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                            timestamp[idx] = CalcVopDisplayTime(video->vol[idx], vopHeader[idx], video->shortVideoHeader);
10833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        if (idx == 0) vopHeader[idx]->refSelectCode = 1;
10843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    }
10853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
10863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                else
10873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
10883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    /* We've decoded this vop header in the previous run already. */
10893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    timestamp[idx] = vopHeader[idx]->timeStamp;
10903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
10913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
10923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
10933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            /* Use timestamps to select the next VOP to be decoded */
10943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (timestamp[idx] >= 0 && (display_time < 0 || display_time > timestamp[idx]))
10953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
10963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                display_time = timestamp[idx];
10973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                target_layer = idx;
10983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
10993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            else if (display_time == timestamp[idx])
11003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
11013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                /* we have to handle either SNR or spatial scalability here. */
11023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
11033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
11043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (target_layer < 0) return PV_FALSE;
11053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
11063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        /* set up for decoding the target layer */
11073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->currLayer = target_layer;
11083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        currVol = video->vol[target_layer];
11093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->bitstream = stream = currVol->bitstream;
11103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
11113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        /* We need to decode the vop header if external timestamp   */
11123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        /*    is provided.    10/04/2000                            */
11133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (vopHeader[target_layer]->timeStamp < 0)
11143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
11153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            stream = video->vol[target_layer]->bitstream;
11163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            BitstreamReset(stream, buffer[target_layer], buffer_size[target_layer]);
11173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
11183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            while (DecodeVOPHeader(video, vopHeader[target_layer], TRUE) != PV_SUCCESS)
11193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
11203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                /* Try to find a VOP header in the buffer.   08/30/2000. */
11213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (PVSearchNextM4VFrame(stream) != PV_SUCCESS)
11223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
11233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    /* if we don't have data for enhancement layer, */
11243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    /*    don't just stop.   09/07/2000.          */
11253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    buffer_size[target_layer] = 0;
11263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    break;
11273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
11283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
11293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            video->vol[target_layer]->timeInc_offset = vopHeader[target_layer]->timeInc;
11303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            video->vol[target_layer]->moduloTimeBase = timestamp[target_layer];
11313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            vopHeader[target_layer]->timeStamp = timestamp[target_layer];
11323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (target_layer == 0) vopHeader[target_layer]->refSelectCode = 1;
11333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
11343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
11353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else /* base layer only decoding */
11363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
11373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
11383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->currLayer = target_layer = 0;
11393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        currVol = video->vol[0];
11403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        video->bitstream = stream = currVol->bitstream;
11413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (buffer_size[0] <= 0) return PV_FALSE;
11423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        BitstreamReset(stream, buffer[0], buffer_size[0]);
11433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
11443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (video->shortVideoHeader)
11453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
11463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            while (DecodeShortHeader(video, vopHeader[0]) != PV_SUCCESS)
11473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
11483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (PVSearchNextH263Frame(stream) != PV_SUCCESS)
11493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
11503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    /* There is no vop header in the buffer,    */
11513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    /*   clean bitstream buffer.     2/5/2001   */
11523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    buffer_size[0] = 0;
11533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    if (video->initialized == PV_FALSE)
11543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    {
11553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        video->displayWidth = video->width = 0;
11563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        video->displayHeight = video->height = 0;
11573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    }
11583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    return PV_FALSE;
11593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
11603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
11613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
11623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (use_ext_timestamp[0])
11633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
11643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                /* MTB for H263 is absolute TR */
11653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                /* following line is equivalent to  round((timestamp[0]*30)/1001);   11/13/2001 */
11663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                video->vol[0]->moduloTimeBase = 30 * ((timestamp[0] + 17) / 1001) + (30 * ((timestamp[0] + 17) % 1001) / 1001);
11673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                vopHeader[0]->timeStamp = timestamp[0];
11683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
11693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            else
11703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                vopHeader[0]->timeStamp = CalcVopDisplayTime(currVol, vopHeader[0], video->shortVideoHeader);
11713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
11723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else
11733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
11743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            while (DecodeVOPHeader(video, vopHeader[0], FALSE) != PV_SUCCESS)
11753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
11763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                /* Try to find a VOP header in the buffer.   08/30/2000. */
11773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (PVSearchNextM4VFrame(stream) != PV_SUCCESS)
11783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
11793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    /* There is no vop header in the buffer,    */
11803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    /*   clean bitstream buffer.     2/5/2001   */
11813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    buffer_size[0] = 0;
11823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    return PV_FALSE;
11833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
11843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
11853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
11863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (use_ext_timestamp[0])
11873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
11883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                video->vol[0]->timeInc_offset = vopHeader[0]->timeInc;
11893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                video->vol[0]->moduloTimeBase = timestamp[0];  /*  11/12/2001 */
11903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                vopHeader[0]->timeStamp = timestamp[0];
11913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
11923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            else
11933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
11943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                vopHeader[0]->timeStamp = CalcVopDisplayTime(currVol, vopHeader[0], video->shortVideoHeader);
11953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
11963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
11973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
11983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        /* set up some base-layer only parameters */
11993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        vopHeader[0]->refSelectCode = 1;
12003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef PV_SUPPORT_TEMPORAL_SCALABILITY
12013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
12023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
12033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    timestamp[target_layer] = video->currTimestamp = vopHeader[target_layer]->timeStamp;
12043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef PV_MEMORY_POOL
12053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    vopHeader[target_layer]->yChan = (PIXEL *)currYUV;
12063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    vopHeader[target_layer]->uChan = (PIXEL *)currYUV + decCtrl->size;
12073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    vopHeader[target_layer]->vChan = (PIXEL *)(vopHeader[target_layer]->uChan) + (decCtrl->size >> 2);
12083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#else
12093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    vopHeader[target_layer]->yChan = currVop->yChan;
12103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    vopHeader[target_layer]->uChan = currVop->uChan;
12113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    vopHeader[target_layer]->vChan = currVop->vChan;
12123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
12133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    oscl_memcpy(currVop, vopHeader[target_layer], sizeof(Vop));
12143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef PV_SUPPORT_TEMPORAL_SCALABILITY
12163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    vopHeader[target_layer]->timeStamp = -1;
12173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
12183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* put header info into the structure */
12193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    header_info->currLayer = target_layer;
12203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    header_info->timestamp = video->currTimestamp;
12213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    header_info->frameType = (MP4FrameType)currVop->predictionType;
12223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    header_info->refSelCode = vopHeader[target_layer]->refSelectCode;
12233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    header_info->quantizer = currVop->quantizer;
12243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /***************************************/
12253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return PV_TRUE;
12273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
12283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
12313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Function : PVDecodeVopBody()                                            */
12323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Date     : 08/22/2002                                                   */
12333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Purpose  : Decode vop body after the header is decoded, modified from   */
12343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*              original PVDecodeVideoFrame.                                */
12353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  In/out   :                                                              */
12363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Return   :                                                              */
12373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Note     :                                                              */
12383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*  Modified :                                                              */
12393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ======================================================================== */
12403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames DongBool PVDecodeVopBody(VideoDecControls *decCtrl, int32 buffer_size[])
12413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
12423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    PV_STATUS status = PV_FAIL;
12433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    VideoDecData *video = (VideoDecData *) decCtrl->videoDecoderData;
12443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int target_layer = video->currLayer;
12453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    Vol *currVol = video->vol[target_layer];
12463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    Vop *currVop = video->currVop;
12473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    Vop *prevVop = video->prevVop;
12483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    Vop *tempVopPtr;
12493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int bytes_consumed = 0; /* Record how many bits we used in the buffer.   04/24/2001 */
12503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int idx;
12523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (currVop->vopCoded == 0)                  /*  07/03/2001 */
12543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
12553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        PV_BitstreamByteAlign(currVol->bitstream);
12563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        /* We should always clear up bitstream buffer.   10/10/2000 */
12573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        bytes_consumed = (getPointer(currVol->bitstream) + 7) >> 3;
12583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (bytes_consumed > currVol->bitstream->data_end_pos)
12603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
12613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            bytes_consumed = currVol->bitstream->data_end_pos;
12623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
12633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (bytes_consumed < buffer_size[target_layer])
12653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
12663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            /* If we only consume part of the bits in the buffer, take those */
12673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            /*  out.     04/24/2001 */
12683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            /*          oscl_memcpy(buffer[target_layer], buffer[target_layer]+bytes_consumed,
12693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                            (buffer_size[target_layer]-=bytes_consumed)); */
12703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            buffer_size[target_layer] -= bytes_consumed;
12713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
12723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else
12733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
12743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            buffer_size[target_layer] = 0;
12753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
12763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef PV_MEMORY_POOL
12773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (target_layer)
12793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
12803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (video->prevEnhcVop->timeStamp > video->prevVop->timeStamp)
12813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
12823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                video->prevVop = video->prevEnhcVop;
12833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
12843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
12853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        oscl_memcpy(currVop->yChan, video->prevVop->yChan, (decCtrl->size*3) / 2);
12873306cfee3bf38ab207a0504e49c2d492bb73ffbf