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