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