10c1bc742181ded4930842b46e9507372f0b1b963James Dong/*
20c1bc742181ded4930842b46e9507372f0b1b963James Dong * Copyright (C) 2009 The Android Open Source Project
30c1bc742181ded4930842b46e9507372f0b1b963James Dong *
40c1bc742181ded4930842b46e9507372f0b1b963James Dong * Licensed under the Apache License, Version 2.0 (the "License");
50c1bc742181ded4930842b46e9507372f0b1b963James Dong * you may not use this file except in compliance with the License.
60c1bc742181ded4930842b46e9507372f0b1b963James Dong * You may obtain a copy of the License at
70c1bc742181ded4930842b46e9507372f0b1b963James Dong *
80c1bc742181ded4930842b46e9507372f0b1b963James Dong *      http://www.apache.org/licenses/LICENSE-2.0
90c1bc742181ded4930842b46e9507372f0b1b963James Dong *
100c1bc742181ded4930842b46e9507372f0b1b963James Dong * Unless required by applicable law or agreed to in writing, software
110c1bc742181ded4930842b46e9507372f0b1b963James Dong * distributed under the License is distributed on an "AS IS" BASIS,
120c1bc742181ded4930842b46e9507372f0b1b963James Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130c1bc742181ded4930842b46e9507372f0b1b963James Dong * See the License for the specific language governing permissions and
140c1bc742181ded4930842b46e9507372f0b1b963James Dong * limitations under the License.
150c1bc742181ded4930842b46e9507372f0b1b963James Dong */
160c1bc742181ded4930842b46e9507372f0b1b963James Dong
170c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
180c1bc742181ded4930842b46e9507372f0b1b963James Dong
190c1bc742181ded4930842b46e9507372f0b1b963James Dong    Table of contents
200c1bc742181ded4930842b46e9507372f0b1b963James Dong
210c1bc742181ded4930842b46e9507372f0b1b963James Dong     1. Include headers
220c1bc742181ded4930842b46e9507372f0b1b963James Dong     2. External compiler flags
230c1bc742181ded4930842b46e9507372f0b1b963James Dong     3. Module defines
240c1bc742181ded4930842b46e9507372f0b1b963James Dong     4. Local function prototypes
250c1bc742181ded4930842b46e9507372f0b1b963James Dong     5. Functions
260c1bc742181ded4930842b46e9507372f0b1b963James Dong          H264SwDecInit
270c1bc742181ded4930842b46e9507372f0b1b963James Dong          H264SwDecGetInfo
280c1bc742181ded4930842b46e9507372f0b1b963James Dong          H264SwDecRelease
290c1bc742181ded4930842b46e9507372f0b1b963James Dong          H264SwDecDecode
300c1bc742181ded4930842b46e9507372f0b1b963James Dong          H264SwDecGetAPIVersion
310c1bc742181ded4930842b46e9507372f0b1b963James Dong          H264SwDecNextPicture
320c1bc742181ded4930842b46e9507372f0b1b963James Dong
330c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
340c1bc742181ded4930842b46e9507372f0b1b963James Dong
350c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
360c1bc742181ded4930842b46e9507372f0b1b963James Dong    1. Include headers
370c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
380c1bc742181ded4930842b46e9507372f0b1b963James Dong#include <stdlib.h>
393e255fa2dbe9d7b05818964ddc9f6ea6bf24ec14Elliott Hughes#include <string.h>
400c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "basetype.h"
410c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_container.h"
420c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "H264SwDecApi.h"
430c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_decoder.h"
440c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_util.h"
450c1bc742181ded4930842b46e9507372f0b1b963James Dong
4684333e0475bc911adc16417f4ca327c975cf6c36Andreas Huber#define UNUSED(x) (void)(x)
4784333e0475bc911adc16417f4ca327c975cf6c36Andreas Huber
480c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
490c1bc742181ded4930842b46e9507372f0b1b963James Dong       Version Information
500c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
510c1bc742181ded4930842b46e9507372f0b1b963James Dong
520c1bc742181ded4930842b46e9507372f0b1b963James Dong#define H264SWDEC_MAJOR_VERSION 2
530c1bc742181ded4930842b46e9507372f0b1b963James Dong#define H264SWDEC_MINOR_VERSION 3
540c1bc742181ded4930842b46e9507372f0b1b963James Dong
550c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
560c1bc742181ded4930842b46e9507372f0b1b963James Dong    2. External compiler flags
570c1bc742181ded4930842b46e9507372f0b1b963James Dong--------------------------------------------------------------------------------
580c1bc742181ded4930842b46e9507372f0b1b963James Dong
590c1bc742181ded4930842b46e9507372f0b1b963James DongH264DEC_TRACE           Trace H264 Decoder API function calls.
600c1bc742181ded4930842b46e9507372f0b1b963James DongH264DEC_EVALUATION      Compile evaluation version, restricts number of frames
610c1bc742181ded4930842b46e9507372f0b1b963James Dong                        that can be decoded
620c1bc742181ded4930842b46e9507372f0b1b963James Dong
630c1bc742181ded4930842b46e9507372f0b1b963James Dong--------------------------------------------------------------------------------
640c1bc742181ded4930842b46e9507372f0b1b963James Dong    3. Module defines
650c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
660c1bc742181ded4930842b46e9507372f0b1b963James Dong
670c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_TRACE
680c1bc742181ded4930842b46e9507372f0b1b963James Dong#include <stdio.h>
690c1bc742181ded4930842b46e9507372f0b1b963James Dong#define DEC_API_TRC(str)    H264SwDecTrace(str)
700c1bc742181ded4930842b46e9507372f0b1b963James Dong#else
710c1bc742181ded4930842b46e9507372f0b1b963James Dong#define DEC_API_TRC(str)
720c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif
730c1bc742181ded4930842b46e9507372f0b1b963James Dong
740c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_EVALUATION
750c1bc742181ded4930842b46e9507372f0b1b963James Dong#define H264DEC_EVALUATION_LIMIT   500
760c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif
770c1bc742181ded4930842b46e9507372f0b1b963James Dong
780c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid H264SwDecTrace(char *string) {
7984333e0475bc911adc16417f4ca327c975cf6c36Andreas Huber    UNUSED(string);
800c1bc742181ded4930842b46e9507372f0b1b963James Dong}
810c1bc742181ded4930842b46e9507372f0b1b963James Dong
820c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid* H264SwDecMalloc(u32 size) {
830c1bc742181ded4930842b46e9507372f0b1b963James Dong    return malloc(size);
840c1bc742181ded4930842b46e9507372f0b1b963James Dong}
850c1bc742181ded4930842b46e9507372f0b1b963James Dong
860c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid H264SwDecFree(void *ptr) {
870c1bc742181ded4930842b46e9507372f0b1b963James Dong    free(ptr);
880c1bc742181ded4930842b46e9507372f0b1b963James Dong}
890c1bc742181ded4930842b46e9507372f0b1b963James Dong
900c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid H264SwDecMemcpy(void *dest, void *src, u32 count) {
910c1bc742181ded4930842b46e9507372f0b1b963James Dong    memcpy(dest, src, count);
920c1bc742181ded4930842b46e9507372f0b1b963James Dong}
930c1bc742181ded4930842b46e9507372f0b1b963James Dong
940c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid H264SwDecMemset(void *ptr, i32 value, u32 count) {
950c1bc742181ded4930842b46e9507372f0b1b963James Dong    memset(ptr, value, count);
960c1bc742181ded4930842b46e9507372f0b1b963James Dong}
970c1bc742181ded4930842b46e9507372f0b1b963James Dong
980c1bc742181ded4930842b46e9507372f0b1b963James Dong
990c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
1000c1bc742181ded4930842b46e9507372f0b1b963James Dong
1010c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: H264SwDecInit()
1020c1bc742181ded4930842b46e9507372f0b1b963James Dong
1030c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
1040c1bc742181ded4930842b46e9507372f0b1b963James Dong            Initialize decoder software. Function reserves memory for the
1050c1bc742181ded4930842b46e9507372f0b1b963James Dong            decoder instance and calls h264bsdInit to initialize the
1060c1bc742181ded4930842b46e9507372f0b1b963James Dong            instance data.
1070c1bc742181ded4930842b46e9507372f0b1b963James Dong
1080c1bc742181ded4930842b46e9507372f0b1b963James Dong        Inputs:
1090c1bc742181ded4930842b46e9507372f0b1b963James Dong            noOutputReordering  flag to indicate decoder that it doesn't have
1100c1bc742181ded4930842b46e9507372f0b1b963James Dong                                to try to provide output pictures in display
1110c1bc742181ded4930842b46e9507372f0b1b963James Dong                                order, saves memory
1120c1bc742181ded4930842b46e9507372f0b1b963James Dong
1130c1bc742181ded4930842b46e9507372f0b1b963James Dong        Outputs:
1140c1bc742181ded4930842b46e9507372f0b1b963James Dong            decInst             pointer to initialized instance is stored here
1150c1bc742181ded4930842b46e9507372f0b1b963James Dong
1160c1bc742181ded4930842b46e9507372f0b1b963James Dong        Returns:
1170c1bc742181ded4930842b46e9507372f0b1b963James Dong            H264SWDEC_OK        successfully initialized the instance
1180c1bc742181ded4930842b46e9507372f0b1b963James Dong            H264SWDEC_INITFAIL  initialization failed
1190c1bc742181ded4930842b46e9507372f0b1b963James Dong            H264SWDEC_PARAM_ERR invalid parameters
1200c1bc742181ded4930842b46e9507372f0b1b963James Dong            H264SWDEC_MEM_FAIL  memory allocation failed
1210c1bc742181ded4930842b46e9507372f0b1b963James Dong
1220c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
1230c1bc742181ded4930842b46e9507372f0b1b963James Dong
1240c1bc742181ded4930842b46e9507372f0b1b963James DongH264SwDecRet H264SwDecInit(H264SwDecInst *decInst, u32 noOutputReordering)
1250c1bc742181ded4930842b46e9507372f0b1b963James Dong{
1260c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 rv = 0;
1270c1bc742181ded4930842b46e9507372f0b1b963James Dong
1280c1bc742181ded4930842b46e9507372f0b1b963James Dong    decContainer_t *pDecCont;
1290c1bc742181ded4930842b46e9507372f0b1b963James Dong
1300c1bc742181ded4930842b46e9507372f0b1b963James Dong    DEC_API_TRC("H264SwDecInit#");
1310c1bc742181ded4930842b46e9507372f0b1b963James Dong
1320c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* check that right shift on negative numbers is performed signed */
1330c1bc742181ded4930842b46e9507372f0b1b963James Dong    /*lint -save -e* following check causes multiple lint messages */
1340c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ( ((-1)>>1) != (-1) )
1350c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1360c1bc742181ded4930842b46e9507372f0b1b963James Dong        DEC_API_TRC("H264SwDecInit# ERROR: Right shift is not signed");
1370c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(H264SWDEC_INITFAIL);
1380c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1390c1bc742181ded4930842b46e9507372f0b1b963James Dong    /*lint -restore */
1400c1bc742181ded4930842b46e9507372f0b1b963James Dong
1410c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (decInst == NULL)
1420c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1430c1bc742181ded4930842b46e9507372f0b1b963James Dong        DEC_API_TRC("H264SwDecInit# ERROR: decInst == NULL");
1440c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(H264SWDEC_PARAM_ERR);
1450c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1460c1bc742181ded4930842b46e9507372f0b1b963James Dong
1470c1bc742181ded4930842b46e9507372f0b1b963James Dong    pDecCont = (decContainer_t *)H264SwDecMalloc(sizeof(decContainer_t));
1480c1bc742181ded4930842b46e9507372f0b1b963James Dong
1490c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (pDecCont == NULL)
1500c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1510c1bc742181ded4930842b46e9507372f0b1b963James Dong        DEC_API_TRC("H264SwDecInit# ERROR: Memory allocation failed");
1520c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(H264SWDEC_MEMFAIL);
1530c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1540c1bc742181ded4930842b46e9507372f0b1b963James Dong
1550c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_TRACE
1560c1bc742181ded4930842b46e9507372f0b1b963James Dong    sprintf(pDecCont->str, "H264SwDecInit# decInst %p noOutputReordering %d",
1570c1bc742181ded4930842b46e9507372f0b1b963James Dong            (void*)decInst, noOutputReordering);
1580c1bc742181ded4930842b46e9507372f0b1b963James Dong    DEC_API_TRC(pDecCont->str);
1590c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif
1600c1bc742181ded4930842b46e9507372f0b1b963James Dong
1610c1bc742181ded4930842b46e9507372f0b1b963James Dong    rv = h264bsdInit(&pDecCont->storage, noOutputReordering);
1620c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (rv != HANTRO_OK)
1630c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1640c1bc742181ded4930842b46e9507372f0b1b963James Dong        H264SwDecRelease(pDecCont);
1650c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(H264SWDEC_MEMFAIL);
1660c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1670c1bc742181ded4930842b46e9507372f0b1b963James Dong
1680c1bc742181ded4930842b46e9507372f0b1b963James Dong    pDecCont->decStat  = INITIALIZED;
1690c1bc742181ded4930842b46e9507372f0b1b963James Dong    pDecCont->picNumber = 0;
1700c1bc742181ded4930842b46e9507372f0b1b963James Dong
1710c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_TRACE
1720c1bc742181ded4930842b46e9507372f0b1b963James Dong    sprintf(pDecCont->str, "H264SwDecInit# OK: return %p", (void*)pDecCont);
1730c1bc742181ded4930842b46e9507372f0b1b963James Dong    DEC_API_TRC(pDecCont->str);
1740c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif
1750c1bc742181ded4930842b46e9507372f0b1b963James Dong
1760c1bc742181ded4930842b46e9507372f0b1b963James Dong    *decInst = (decContainer_t *)pDecCont;
1770c1bc742181ded4930842b46e9507372f0b1b963James Dong
1780c1bc742181ded4930842b46e9507372f0b1b963James Dong    return(H264SWDEC_OK);
1790c1bc742181ded4930842b46e9507372f0b1b963James Dong
1800c1bc742181ded4930842b46e9507372f0b1b963James Dong}
1810c1bc742181ded4930842b46e9507372f0b1b963James Dong
1820c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
1830c1bc742181ded4930842b46e9507372f0b1b963James Dong
1840c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: H264SwDecGetInfo()
1850c1bc742181ded4930842b46e9507372f0b1b963James Dong
1860c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
1870c1bc742181ded4930842b46e9507372f0b1b963James Dong            This function provides read access to decoder information. This
1880c1bc742181ded4930842b46e9507372f0b1b963James Dong            function should not be called before H264SwDecDecode function has
1890c1bc742181ded4930842b46e9507372f0b1b963James Dong            indicated that headers are ready.
1900c1bc742181ded4930842b46e9507372f0b1b963James Dong
1910c1bc742181ded4930842b46e9507372f0b1b963James Dong        Inputs:
1920c1bc742181ded4930842b46e9507372f0b1b963James Dong            decInst     decoder instance
1930c1bc742181ded4930842b46e9507372f0b1b963James Dong
1940c1bc742181ded4930842b46e9507372f0b1b963James Dong        Outputs:
1950c1bc742181ded4930842b46e9507372f0b1b963James Dong            pDecInfo    pointer to info struct where data is written
1960c1bc742181ded4930842b46e9507372f0b1b963James Dong
1970c1bc742181ded4930842b46e9507372f0b1b963James Dong        Returns:
1980c1bc742181ded4930842b46e9507372f0b1b963James Dong            H264SWDEC_OK            success
1990c1bc742181ded4930842b46e9507372f0b1b963James Dong            H264SWDEC_PARAM_ERR     invalid parameters
2000c1bc742181ded4930842b46e9507372f0b1b963James Dong            H264SWDEC_HDRS_NOT_RDY  information not available yet
2010c1bc742181ded4930842b46e9507372f0b1b963James Dong
2020c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
2030c1bc742181ded4930842b46e9507372f0b1b963James Dong
2040c1bc742181ded4930842b46e9507372f0b1b963James DongH264SwDecRet H264SwDecGetInfo(H264SwDecInst decInst, H264SwDecInfo *pDecInfo)
2050c1bc742181ded4930842b46e9507372f0b1b963James Dong{
2060c1bc742181ded4930842b46e9507372f0b1b963James Dong
2070c1bc742181ded4930842b46e9507372f0b1b963James Dong    storage_t *pStorage;
2080c1bc742181ded4930842b46e9507372f0b1b963James Dong
2090c1bc742181ded4930842b46e9507372f0b1b963James Dong    DEC_API_TRC("H264SwDecGetInfo#");
2100c1bc742181ded4930842b46e9507372f0b1b963James Dong
2110c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (decInst == NULL || pDecInfo == NULL)
2120c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
2130c1bc742181ded4930842b46e9507372f0b1b963James Dong        DEC_API_TRC("H264SwDecGetInfo# ERROR: decInst or pDecInfo is NULL");
2140c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(H264SWDEC_PARAM_ERR);
2150c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2160c1bc742181ded4930842b46e9507372f0b1b963James Dong
2170c1bc742181ded4930842b46e9507372f0b1b963James Dong    pStorage = &(((decContainer_t *)decInst)->storage);
2180c1bc742181ded4930842b46e9507372f0b1b963James Dong
2190c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (pStorage->activeSps == NULL || pStorage->activePps == NULL)
2200c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
2210c1bc742181ded4930842b46e9507372f0b1b963James Dong        DEC_API_TRC("H264SwDecGetInfo# ERROR: Headers not decoded yet");
2220c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(H264SWDEC_HDRS_NOT_RDY);
2230c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2240c1bc742181ded4930842b46e9507372f0b1b963James Dong
2250c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_TRACE
2260c1bc742181ded4930842b46e9507372f0b1b963James Dong    sprintf(((decContainer_t*)decInst)->str,
2270c1bc742181ded4930842b46e9507372f0b1b963James Dong        "H264SwDecGetInfo# decInst %p  pDecInfo %p", decInst, (void*)pDecInfo);
2280c1bc742181ded4930842b46e9507372f0b1b963James Dong    DEC_API_TRC(((decContainer_t*)decInst)->str);
2290c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif
2300c1bc742181ded4930842b46e9507372f0b1b963James Dong
2310c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* h264bsdPicWidth and -Height return dimensions in macroblock units,
2320c1bc742181ded4930842b46e9507372f0b1b963James Dong     * picWidth and -Height in pixels */
2330c1bc742181ded4930842b46e9507372f0b1b963James Dong    pDecInfo->picWidth        = h264bsdPicWidth(pStorage) << 4;
2340c1bc742181ded4930842b46e9507372f0b1b963James Dong    pDecInfo->picHeight       = h264bsdPicHeight(pStorage) << 4;
2350c1bc742181ded4930842b46e9507372f0b1b963James Dong    pDecInfo->videoRange      = h264bsdVideoRange(pStorage);
2360c1bc742181ded4930842b46e9507372f0b1b963James Dong    pDecInfo->matrixCoefficients = h264bsdMatrixCoefficients(pStorage);
2370c1bc742181ded4930842b46e9507372f0b1b963James Dong
2380c1bc742181ded4930842b46e9507372f0b1b963James Dong    h264bsdCroppingParams(pStorage,
2390c1bc742181ded4930842b46e9507372f0b1b963James Dong        &pDecInfo->croppingFlag,
2400c1bc742181ded4930842b46e9507372f0b1b963James Dong        &pDecInfo->cropParams.cropLeftOffset,
2410c1bc742181ded4930842b46e9507372f0b1b963James Dong        &pDecInfo->cropParams.cropOutWidth,
2420c1bc742181ded4930842b46e9507372f0b1b963James Dong        &pDecInfo->cropParams.cropTopOffset,
2430c1bc742181ded4930842b46e9507372f0b1b963James Dong        &pDecInfo->cropParams.cropOutHeight);
2440c1bc742181ded4930842b46e9507372f0b1b963James Dong
2450c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* sample aspect ratio */
2460c1bc742181ded4930842b46e9507372f0b1b963James Dong    h264bsdSampleAspectRatio(pStorage,
2470c1bc742181ded4930842b46e9507372f0b1b963James Dong                             &pDecInfo->parWidth,
2480c1bc742181ded4930842b46e9507372f0b1b963James Dong                             &pDecInfo->parHeight);
2490c1bc742181ded4930842b46e9507372f0b1b963James Dong
2500c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* profile */
2510c1bc742181ded4930842b46e9507372f0b1b963James Dong    pDecInfo->profile = h264bsdProfile(pStorage);
2520c1bc742181ded4930842b46e9507372f0b1b963James Dong
2530c1bc742181ded4930842b46e9507372f0b1b963James Dong    DEC_API_TRC("H264SwDecGetInfo# OK");
2540c1bc742181ded4930842b46e9507372f0b1b963James Dong
2550c1bc742181ded4930842b46e9507372f0b1b963James Dong    return(H264SWDEC_OK);
2560c1bc742181ded4930842b46e9507372f0b1b963James Dong
2570c1bc742181ded4930842b46e9507372f0b1b963James Dong}
2580c1bc742181ded4930842b46e9507372f0b1b963James Dong
2590c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
2600c1bc742181ded4930842b46e9507372f0b1b963James Dong
2610c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: H264SwDecRelease()
2620c1bc742181ded4930842b46e9507372f0b1b963James Dong
2630c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
2640c1bc742181ded4930842b46e9507372f0b1b963James Dong            Release the decoder instance. Function calls h264bsdShutDown to
2650c1bc742181ded4930842b46e9507372f0b1b963James Dong            release instance data and frees the memory allocated for the
2660c1bc742181ded4930842b46e9507372f0b1b963James Dong            instance.
2670c1bc742181ded4930842b46e9507372f0b1b963James Dong
2680c1bc742181ded4930842b46e9507372f0b1b963James Dong        Inputs:
2690c1bc742181ded4930842b46e9507372f0b1b963James Dong            decInst     Decoder instance
2700c1bc742181ded4930842b46e9507372f0b1b963James Dong
2710c1bc742181ded4930842b46e9507372f0b1b963James Dong        Outputs:
2720c1bc742181ded4930842b46e9507372f0b1b963James Dong            none
2730c1bc742181ded4930842b46e9507372f0b1b963James Dong
2740c1bc742181ded4930842b46e9507372f0b1b963James Dong        Returns:
2750c1bc742181ded4930842b46e9507372f0b1b963James Dong            none
2760c1bc742181ded4930842b46e9507372f0b1b963James Dong
2770c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
2780c1bc742181ded4930842b46e9507372f0b1b963James Dong
2790c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid H264SwDecRelease(H264SwDecInst decInst)
2800c1bc742181ded4930842b46e9507372f0b1b963James Dong{
2810c1bc742181ded4930842b46e9507372f0b1b963James Dong
2820c1bc742181ded4930842b46e9507372f0b1b963James Dong    decContainer_t *pDecCont;
2830c1bc742181ded4930842b46e9507372f0b1b963James Dong
2840c1bc742181ded4930842b46e9507372f0b1b963James Dong    DEC_API_TRC("H264SwDecRelease#");
2850c1bc742181ded4930842b46e9507372f0b1b963James Dong
2860c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (decInst == NULL)
2870c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
2880c1bc742181ded4930842b46e9507372f0b1b963James Dong        DEC_API_TRC("H264SwDecRelease# ERROR: decInst == NULL");
2890c1bc742181ded4930842b46e9507372f0b1b963James Dong        return;
2900c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2910c1bc742181ded4930842b46e9507372f0b1b963James Dong
2920c1bc742181ded4930842b46e9507372f0b1b963James Dong    pDecCont = (decContainer_t*)decInst;
2930c1bc742181ded4930842b46e9507372f0b1b963James Dong
2940c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_TRACE
2950c1bc742181ded4930842b46e9507372f0b1b963James Dong    sprintf(pDecCont->str, "H264SwDecRelease# decInst %p",decInst);
2960c1bc742181ded4930842b46e9507372f0b1b963James Dong    DEC_API_TRC(pDecCont->str);
2970c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif
2980c1bc742181ded4930842b46e9507372f0b1b963James Dong
2990c1bc742181ded4930842b46e9507372f0b1b963James Dong    h264bsdShutdown(&pDecCont->storage);
3000c1bc742181ded4930842b46e9507372f0b1b963James Dong
3010c1bc742181ded4930842b46e9507372f0b1b963James Dong    H264SwDecFree(pDecCont);
3020c1bc742181ded4930842b46e9507372f0b1b963James Dong
3030c1bc742181ded4930842b46e9507372f0b1b963James Dong}
3040c1bc742181ded4930842b46e9507372f0b1b963James Dong
3050c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
3060c1bc742181ded4930842b46e9507372f0b1b963James Dong
3070c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: H264SwDecDecode
3080c1bc742181ded4930842b46e9507372f0b1b963James Dong
3090c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
3100c1bc742181ded4930842b46e9507372f0b1b963James Dong            Decode stream data. Calls h264bsdDecode to do the actual decoding.
3110c1bc742181ded4930842b46e9507372f0b1b963James Dong
3120c1bc742181ded4930842b46e9507372f0b1b963James Dong        Input:
3130c1bc742181ded4930842b46e9507372f0b1b963James Dong            decInst     decoder instance
3140c1bc742181ded4930842b46e9507372f0b1b963James Dong            pInput      pointer to input struct
3150c1bc742181ded4930842b46e9507372f0b1b963James Dong
3160c1bc742181ded4930842b46e9507372f0b1b963James Dong        Outputs:
3170c1bc742181ded4930842b46e9507372f0b1b963James Dong            pOutput     pointer to output struct
3180c1bc742181ded4930842b46e9507372f0b1b963James Dong
3190c1bc742181ded4930842b46e9507372f0b1b963James Dong        Returns:
3200c1bc742181ded4930842b46e9507372f0b1b963James Dong            H264SWDEC_NOT_INITIALIZED   decoder instance not initialized yet
3210c1bc742181ded4930842b46e9507372f0b1b963James Dong            H264SWDEC_PARAM_ERR         invalid parameters
3220c1bc742181ded4930842b46e9507372f0b1b963James Dong
3230c1bc742181ded4930842b46e9507372f0b1b963James Dong            H264SWDEC_STRM_PROCESSED    stream buffer decoded
3240c1bc742181ded4930842b46e9507372f0b1b963James Dong            H264SWDEC_HDRS_RDY_BUFF_NOT_EMPTY   headers decoded,
3250c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                stream buffer not finished
3260c1bc742181ded4930842b46e9507372f0b1b963James Dong            H264SWDEC_PIC_RDY                   decoding of a picture finished
3270c1bc742181ded4930842b46e9507372f0b1b963James Dong            H264SWDEC_PIC_RDY_BUFF_NOT_EMPTY    decoding of a picture finished,
3280c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                stream buffer not finished
3290c1bc742181ded4930842b46e9507372f0b1b963James Dong            H264SWDEC_STRM_ERR                  serious error in decoding, no
3300c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                valid parameter sets available
3310c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                to decode picture data
3320c1bc742181ded4930842b46e9507372f0b1b963James Dong            H264SWDEC_EVALUATION_LIMIT_EXCEEDED this can only occur when
3330c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                evaluation version is used,
3340c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                max number of frames reached
3350c1bc742181ded4930842b46e9507372f0b1b963James Dong
3360c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
3370c1bc742181ded4930842b46e9507372f0b1b963James Dong
3380c1bc742181ded4930842b46e9507372f0b1b963James DongH264SwDecRet H264SwDecDecode(H264SwDecInst decInst, H264SwDecInput *pInput,
3390c1bc742181ded4930842b46e9507372f0b1b963James Dong                  H264SwDecOutput *pOutput)
3400c1bc742181ded4930842b46e9507372f0b1b963James Dong{
3410c1bc742181ded4930842b46e9507372f0b1b963James Dong
3420c1bc742181ded4930842b46e9507372f0b1b963James Dong    decContainer_t *pDecCont;
3430c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 strmLen;
3440c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 numReadBytes;
3450c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 *tmpStream;
3460c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 decResult = 0;
3470c1bc742181ded4930842b46e9507372f0b1b963James Dong    H264SwDecRet returnValue = H264SWDEC_STRM_PROCESSED;
3480c1bc742181ded4930842b46e9507372f0b1b963James Dong
3490c1bc742181ded4930842b46e9507372f0b1b963James Dong    DEC_API_TRC("H264SwDecDecode#");
3500c1bc742181ded4930842b46e9507372f0b1b963James Dong
3510c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Check that function input parameters are valid */
3520c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (pInput == NULL || pOutput == NULL)
3530c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
3540c1bc742181ded4930842b46e9507372f0b1b963James Dong        DEC_API_TRC("H264SwDecDecode# ERROR: pInput or pOutput is NULL");
3550c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(H264SWDEC_PARAM_ERR);
3560c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
3570c1bc742181ded4930842b46e9507372f0b1b963James Dong
3580c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ((pInput->pStream == NULL) || (pInput->dataLen == 0))
3590c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
3600c1bc742181ded4930842b46e9507372f0b1b963James Dong        DEC_API_TRC("H264SwDecDecode# ERROR: Invalid input parameters");
3610c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(H264SWDEC_PARAM_ERR);
3620c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
3630c1bc742181ded4930842b46e9507372f0b1b963James Dong
3640c1bc742181ded4930842b46e9507372f0b1b963James Dong    pDecCont = (decContainer_t *)decInst;
3650c1bc742181ded4930842b46e9507372f0b1b963James Dong
3660c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Check if decoder is in an incorrect mode */
3670c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (decInst == NULL || pDecCont->decStat == UNINITIALIZED)
3680c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
3690c1bc742181ded4930842b46e9507372f0b1b963James Dong        DEC_API_TRC("H264SwDecDecode# ERROR: Decoder not initialized");
3700c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(H264SWDEC_NOT_INITIALIZED);
3710c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
3720c1bc742181ded4930842b46e9507372f0b1b963James Dong
3730c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_EVALUATION
3740c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (pDecCont->picNumber >= H264DEC_EVALUATION_LIMIT)
3750c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(H264SWDEC_EVALUATION_LIMIT_EXCEEDED);
3760c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif
3770c1bc742181ded4930842b46e9507372f0b1b963James Dong
3780c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_TRACE
3790c1bc742181ded4930842b46e9507372f0b1b963James Dong    sprintf(pDecCont->str, "H264SwDecDecode# decInst %p  pInput %p  pOutput %p",
3800c1bc742181ded4930842b46e9507372f0b1b963James Dong            decInst, (void*)pInput, (void*)pOutput);
3810c1bc742181ded4930842b46e9507372f0b1b963James Dong    DEC_API_TRC(pDecCont->str);
3820c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif
3830c1bc742181ded4930842b46e9507372f0b1b963James Dong
3840c1bc742181ded4930842b46e9507372f0b1b963James Dong    pOutput->pStrmCurrPos   = NULL;
3850c1bc742181ded4930842b46e9507372f0b1b963James Dong
3860c1bc742181ded4930842b46e9507372f0b1b963James Dong    numReadBytes = 0;
3870c1bc742181ded4930842b46e9507372f0b1b963James Dong    strmLen = pInput->dataLen;
3880c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmpStream = pInput->pStream;
3890c1bc742181ded4930842b46e9507372f0b1b963James Dong    pDecCont->storage.intraConcealmentFlag = pInput->intraConcealmentMethod;
3900c1bc742181ded4930842b46e9507372f0b1b963James Dong
3910c1bc742181ded4930842b46e9507372f0b1b963James Dong    do
3920c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
3930c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* Return HDRS_RDY after DPB flush caused by new SPS */
3940c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (pDecCont->decStat == NEW_HEADERS)
3950c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
3960c1bc742181ded4930842b46e9507372f0b1b963James Dong            decResult = H264BSD_HDRS_RDY;
3970c1bc742181ded4930842b46e9507372f0b1b963James Dong            pDecCont->decStat = INITIALIZED;
3980c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
3990c1bc742181ded4930842b46e9507372f0b1b963James Dong        else /* Continue decoding normally */
4000c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
4010c1bc742181ded4930842b46e9507372f0b1b963James Dong            decResult = h264bsdDecode(&pDecCont->storage, tmpStream, strmLen,
4020c1bc742181ded4930842b46e9507372f0b1b963James Dong                pInput->picId, &numReadBytes);
4030c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
4040c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmpStream += numReadBytes;
4050c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* check if too many bytes are read from stream */
4060c1bc742181ded4930842b46e9507372f0b1b963James Dong        if ( (i32)(strmLen - numReadBytes) >= 0 )
4070c1bc742181ded4930842b46e9507372f0b1b963James Dong            strmLen -= numReadBytes;
4080c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
4090c1bc742181ded4930842b46e9507372f0b1b963James Dong            strmLen = 0;
4100c1bc742181ded4930842b46e9507372f0b1b963James Dong
4110c1bc742181ded4930842b46e9507372f0b1b963James Dong        pOutput->pStrmCurrPos = tmpStream;
4120c1bc742181ded4930842b46e9507372f0b1b963James Dong
4130c1bc742181ded4930842b46e9507372f0b1b963James Dong        switch (decResult)
4140c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
4150c1bc742181ded4930842b46e9507372f0b1b963James Dong            case H264BSD_HDRS_RDY:
4160c1bc742181ded4930842b46e9507372f0b1b963James Dong
4170c1bc742181ded4930842b46e9507372f0b1b963James Dong                if(pDecCont->storage.dpb->flushed &&
4180c1bc742181ded4930842b46e9507372f0b1b963James Dong                   pDecCont->storage.dpb->numOut !=
4190c1bc742181ded4930842b46e9507372f0b1b963James Dong                   pDecCont->storage.dpb->outIndex)
4200c1bc742181ded4930842b46e9507372f0b1b963James Dong                {
4210c1bc742181ded4930842b46e9507372f0b1b963James Dong                    /* output first all DPB stored pictures
4220c1bc742181ded4930842b46e9507372f0b1b963James Dong                     * DPB flush caused by new SPS */
4230c1bc742181ded4930842b46e9507372f0b1b963James Dong                    pDecCont->storage.dpb->flushed = 0;
4240c1bc742181ded4930842b46e9507372f0b1b963James Dong                    pDecCont->decStat = NEW_HEADERS;
4250c1bc742181ded4930842b46e9507372f0b1b963James Dong                    returnValue = H264SWDEC_PIC_RDY_BUFF_NOT_EMPTY;
4260c1bc742181ded4930842b46e9507372f0b1b963James Dong                    strmLen = 0;
4270c1bc742181ded4930842b46e9507372f0b1b963James Dong                }
4280c1bc742181ded4930842b46e9507372f0b1b963James Dong                else
4290c1bc742181ded4930842b46e9507372f0b1b963James Dong                {
4300c1bc742181ded4930842b46e9507372f0b1b963James Dong                    returnValue = H264SWDEC_HDRS_RDY_BUFF_NOT_EMPTY;
4310c1bc742181ded4930842b46e9507372f0b1b963James Dong                    strmLen = 0;
4320c1bc742181ded4930842b46e9507372f0b1b963James Dong                }
4330c1bc742181ded4930842b46e9507372f0b1b963James Dong                break;
4340c1bc742181ded4930842b46e9507372f0b1b963James Dong
4350c1bc742181ded4930842b46e9507372f0b1b963James Dong            case H264BSD_PIC_RDY:
4360c1bc742181ded4930842b46e9507372f0b1b963James Dong                pDecCont->picNumber++;
4370c1bc742181ded4930842b46e9507372f0b1b963James Dong
4380c1bc742181ded4930842b46e9507372f0b1b963James Dong                if (strmLen == 0)
4390c1bc742181ded4930842b46e9507372f0b1b963James Dong                    returnValue = H264SWDEC_PIC_RDY;
4400c1bc742181ded4930842b46e9507372f0b1b963James Dong                else
4410c1bc742181ded4930842b46e9507372f0b1b963James Dong                    returnValue = H264SWDEC_PIC_RDY_BUFF_NOT_EMPTY;
4420c1bc742181ded4930842b46e9507372f0b1b963James Dong
4430c1bc742181ded4930842b46e9507372f0b1b963James Dong                strmLen = 0;
4440c1bc742181ded4930842b46e9507372f0b1b963James Dong                break;
4450c1bc742181ded4930842b46e9507372f0b1b963James Dong
4460c1bc742181ded4930842b46e9507372f0b1b963James Dong            case H264BSD_PARAM_SET_ERROR:
4470c1bc742181ded4930842b46e9507372f0b1b963James Dong                if ( !h264bsdCheckValidParamSets(&pDecCont->storage) &&
4480c1bc742181ded4930842b46e9507372f0b1b963James Dong                     strmLen == 0 )
4490c1bc742181ded4930842b46e9507372f0b1b963James Dong                {
4500c1bc742181ded4930842b46e9507372f0b1b963James Dong                    returnValue = H264SWDEC_STRM_ERR;
4510c1bc742181ded4930842b46e9507372f0b1b963James Dong                }
4520c1bc742181ded4930842b46e9507372f0b1b963James Dong                break;
4530c1bc742181ded4930842b46e9507372f0b1b963James Dong            case H264BSD_MEMALLOC_ERROR:
4540c1bc742181ded4930842b46e9507372f0b1b963James Dong                {
4550c1bc742181ded4930842b46e9507372f0b1b963James Dong                    returnValue = H264SWDEC_MEMFAIL;
4560c1bc742181ded4930842b46e9507372f0b1b963James Dong                    strmLen = 0;
4570c1bc742181ded4930842b46e9507372f0b1b963James Dong                }
4580c1bc742181ded4930842b46e9507372f0b1b963James Dong                break;
4590c1bc742181ded4930842b46e9507372f0b1b963James Dong            default:
4600c1bc742181ded4930842b46e9507372f0b1b963James Dong                break;
4610c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
4620c1bc742181ded4930842b46e9507372f0b1b963James Dong
4630c1bc742181ded4930842b46e9507372f0b1b963James Dong    } while (strmLen);
4640c1bc742181ded4930842b46e9507372f0b1b963James Dong
4650c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_TRACE
4660c1bc742181ded4930842b46e9507372f0b1b963James Dong    sprintf(pDecCont->str, "H264SwDecDecode# OK: DecResult %d",
4670c1bc742181ded4930842b46e9507372f0b1b963James Dong            returnValue);
4680c1bc742181ded4930842b46e9507372f0b1b963James Dong    DEC_API_TRC(pDecCont->str);
4690c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif
4700c1bc742181ded4930842b46e9507372f0b1b963James Dong
4710c1bc742181ded4930842b46e9507372f0b1b963James Dong    return(returnValue);
4720c1bc742181ded4930842b46e9507372f0b1b963James Dong
4730c1bc742181ded4930842b46e9507372f0b1b963James Dong}
4740c1bc742181ded4930842b46e9507372f0b1b963James Dong
4750c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
4760c1bc742181ded4930842b46e9507372f0b1b963James Dong
4770c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: H264SwDecGetAPIVersion
4780c1bc742181ded4930842b46e9507372f0b1b963James Dong
4790c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
4800c1bc742181ded4930842b46e9507372f0b1b963James Dong            Return version information of the API
4810c1bc742181ded4930842b46e9507372f0b1b963James Dong
4820c1bc742181ded4930842b46e9507372f0b1b963James Dong        Inputs:
4830c1bc742181ded4930842b46e9507372f0b1b963James Dong            none
4840c1bc742181ded4930842b46e9507372f0b1b963James Dong
4850c1bc742181ded4930842b46e9507372f0b1b963James Dong        Outputs:
4860c1bc742181ded4930842b46e9507372f0b1b963James Dong            none
4870c1bc742181ded4930842b46e9507372f0b1b963James Dong
4880c1bc742181ded4930842b46e9507372f0b1b963James Dong        Returns:
4890c1bc742181ded4930842b46e9507372f0b1b963James Dong            API version
4900c1bc742181ded4930842b46e9507372f0b1b963James Dong
4910c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
4920c1bc742181ded4930842b46e9507372f0b1b963James Dong
4930c1bc742181ded4930842b46e9507372f0b1b963James DongH264SwDecApiVersion H264SwDecGetAPIVersion()
4940c1bc742181ded4930842b46e9507372f0b1b963James Dong{
4950c1bc742181ded4930842b46e9507372f0b1b963James Dong    H264SwDecApiVersion ver;
4960c1bc742181ded4930842b46e9507372f0b1b963James Dong
4970c1bc742181ded4930842b46e9507372f0b1b963James Dong    ver.major = H264SWDEC_MAJOR_VERSION;
4980c1bc742181ded4930842b46e9507372f0b1b963James Dong    ver.minor = H264SWDEC_MINOR_VERSION;
4990c1bc742181ded4930842b46e9507372f0b1b963James Dong
5000c1bc742181ded4930842b46e9507372f0b1b963James Dong    return(ver);
5010c1bc742181ded4930842b46e9507372f0b1b963James Dong}
5020c1bc742181ded4930842b46e9507372f0b1b963James Dong
5030c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
5040c1bc742181ded4930842b46e9507372f0b1b963James Dong
5050c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: H264SwDecNextPicture
5060c1bc742181ded4930842b46e9507372f0b1b963James Dong
5070c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
5080c1bc742181ded4930842b46e9507372f0b1b963James Dong            Get next picture in display order if any available.
5090c1bc742181ded4930842b46e9507372f0b1b963James Dong
5100c1bc742181ded4930842b46e9507372f0b1b963James Dong        Input:
5110c1bc742181ded4930842b46e9507372f0b1b963James Dong            decInst     decoder instance.
5120c1bc742181ded4930842b46e9507372f0b1b963James Dong            flushBuffer force output of all buffered pictures
5130c1bc742181ded4930842b46e9507372f0b1b963James Dong
5140c1bc742181ded4930842b46e9507372f0b1b963James Dong        Output:
5150c1bc742181ded4930842b46e9507372f0b1b963James Dong            pOutput     pointer to output structure
5160c1bc742181ded4930842b46e9507372f0b1b963James Dong
5170c1bc742181ded4930842b46e9507372f0b1b963James Dong        Returns:
5180c1bc742181ded4930842b46e9507372f0b1b963James Dong            H264SWDEC_OK            no pictures available for display
5190c1bc742181ded4930842b46e9507372f0b1b963James Dong            H264SWDEC_PIC_RDY       picture available for display
5200c1bc742181ded4930842b46e9507372f0b1b963James Dong            H264SWDEC_PARAM_ERR     invalid parameters
5210c1bc742181ded4930842b46e9507372f0b1b963James Dong
5220c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
5230c1bc742181ded4930842b46e9507372f0b1b963James Dong
5240c1bc742181ded4930842b46e9507372f0b1b963James DongH264SwDecRet H264SwDecNextPicture(H264SwDecInst decInst,
5250c1bc742181ded4930842b46e9507372f0b1b963James Dong    H264SwDecPicture *pOutput, u32 flushBuffer)
5260c1bc742181ded4930842b46e9507372f0b1b963James Dong{
5270c1bc742181ded4930842b46e9507372f0b1b963James Dong
5280c1bc742181ded4930842b46e9507372f0b1b963James Dong    decContainer_t *pDecCont;
5290c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 numErrMbs, isIdrPic, picId;
5300c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 *pOutPic;
5310c1bc742181ded4930842b46e9507372f0b1b963James Dong
5320c1bc742181ded4930842b46e9507372f0b1b963James Dong    DEC_API_TRC("H264SwDecNextPicture#");
5330c1bc742181ded4930842b46e9507372f0b1b963James Dong
5340c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (decInst == NULL || pOutput == NULL)
5350c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5360c1bc742181ded4930842b46e9507372f0b1b963James Dong        DEC_API_TRC("H264SwDecNextPicture# ERROR: decInst or pOutput is NULL");
5370c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(H264SWDEC_PARAM_ERR);
5380c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5390c1bc742181ded4930842b46e9507372f0b1b963James Dong
5400c1bc742181ded4930842b46e9507372f0b1b963James Dong    pDecCont = (decContainer_t*)decInst;
5410c1bc742181ded4930842b46e9507372f0b1b963James Dong
5420c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_TRACE
5430c1bc742181ded4930842b46e9507372f0b1b963James Dong    sprintf(pDecCont->str, "H264SwDecNextPicture# decInst %p pOutput %p %s %d",
5440c1bc742181ded4930842b46e9507372f0b1b963James Dong            decInst, (void*)pOutput, "flushBuffer", flushBuffer);
5450c1bc742181ded4930842b46e9507372f0b1b963James Dong    DEC_API_TRC(pDecCont->str);
5460c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif
5470c1bc742181ded4930842b46e9507372f0b1b963James Dong
5480c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (flushBuffer)
5490c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdFlushBuffer(&pDecCont->storage);
5500c1bc742181ded4930842b46e9507372f0b1b963James Dong
5510c1bc742181ded4930842b46e9507372f0b1b963James Dong    pOutPic = (u32*)h264bsdNextOutputPicture(&pDecCont->storage, &picId,
5520c1bc742181ded4930842b46e9507372f0b1b963James Dong                                             &isIdrPic, &numErrMbs);
5530c1bc742181ded4930842b46e9507372f0b1b963James Dong
5540c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (pOutPic == NULL)
5550c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5560c1bc742181ded4930842b46e9507372f0b1b963James Dong        DEC_API_TRC("H264SwDecNextPicture# OK: return H264SWDEC_OK");
5570c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(H264SWDEC_OK);
5580c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5590c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
5600c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5610c1bc742181ded4930842b46e9507372f0b1b963James Dong        pOutput->pOutputPicture = pOutPic;
5620c1bc742181ded4930842b46e9507372f0b1b963James Dong        pOutput->picId          = picId;
5630c1bc742181ded4930842b46e9507372f0b1b963James Dong        pOutput->isIdrPicture   = isIdrPic;
5640c1bc742181ded4930842b46e9507372f0b1b963James Dong        pOutput->nbrOfErrMBs    = numErrMbs;
5650c1bc742181ded4930842b46e9507372f0b1b963James Dong        DEC_API_TRC("H264SwDecNextPicture# OK: return H264SWDEC_PIC_RDY");
5660c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(H264SWDEC_PIC_RDY);
5670c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5680c1bc742181ded4930842b46e9507372f0b1b963James Dong
5690c1bc742181ded4930842b46e9507372f0b1b963James Dong}
5700c1bc742181ded4930842b46e9507372f0b1b963James Dong
5710c1bc742181ded4930842b46e9507372f0b1b963James Dong
572