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 h264bsdDecodeMacroblockLayer 270c1bc742181ded4930842b46e9507372f0b1b963James Dong h264bsdMbPartPredMode 280c1bc742181ded4930842b46e9507372f0b1b963James Dong h264bsdNumMbPart 290c1bc742181ded4930842b46e9507372f0b1b963James Dong h264bsdNumSubMbPart 300c1bc742181ded4930842b46e9507372f0b1b963James Dong DecodeMbPred 310c1bc742181ded4930842b46e9507372f0b1b963James Dong DecodeSubMbPred 320c1bc742181ded4930842b46e9507372f0b1b963James Dong DecodeResidual 330c1bc742181ded4930842b46e9507372f0b1b963James Dong DetermineNc 340c1bc742181ded4930842b46e9507372f0b1b963James Dong CbpIntra16x16 350c1bc742181ded4930842b46e9507372f0b1b963James Dong h264bsdPredModeIntra16x16 360c1bc742181ded4930842b46e9507372f0b1b963James Dong h264bsdDecodeMacroblock 370c1bc742181ded4930842b46e9507372f0b1b963James Dong ProcessResidual 380c1bc742181ded4930842b46e9507372f0b1b963James Dong h264bsdSubMbPartMode 390c1bc742181ded4930842b46e9507372f0b1b963James Dong 400c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 410c1bc742181ded4930842b46e9507372f0b1b963James Dong 420c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 430c1bc742181ded4930842b46e9507372f0b1b963James Dong 1. Include headers 440c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 450c1bc742181ded4930842b46e9507372f0b1b963James Dong 460c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_macroblock_layer.h" 470c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_slice_header.h" 480c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_util.h" 490c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_vlc.h" 500c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_cavlc.h" 510c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_nal_unit.h" 520c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_neighbour.h" 530c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_transform.h" 540c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_intra_prediction.h" 550c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_inter_prediction.h" 560c1bc742181ded4930842b46e9507372f0b1b963James Dong 570c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_OMXDL 580c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxtypes.h" 590c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxVC.h" 600c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armVC.h" 610c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif /* H264DEC_OMXDL */ 620c1bc742181ded4930842b46e9507372f0b1b963James Dong 630c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 640c1bc742181ded4930842b46e9507372f0b1b963James Dong 2. External compiler flags 650c1bc742181ded4930842b46e9507372f0b1b963James Dong-------------------------------------------------------------------------------- 660c1bc742181ded4930842b46e9507372f0b1b963James Dong 670c1bc742181ded4930842b46e9507372f0b1b963James Dong-------------------------------------------------------------------------------- 680c1bc742181ded4930842b46e9507372f0b1b963James Dong 3. Module defines 690c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 700c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_OMXDL 710c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic const u32 chromaIndex[8] = { 256, 260, 288, 292, 320, 324, 352, 356 }; 720c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic const u32 lumaIndex[16] = { 0, 4, 64, 68, 730c1bc742181ded4930842b46e9507372f0b1b963James Dong 8, 12, 72, 76, 740c1bc742181ded4930842b46e9507372f0b1b963James Dong 128, 132, 192, 196, 750c1bc742181ded4930842b46e9507372f0b1b963James Dong 136, 140, 200, 204 }; 760c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif 770c1bc742181ded4930842b46e9507372f0b1b963James Dong/* mapping of dc coefficients array to luma blocks */ 780c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic const u32 dcCoeffIndex[16] = 790c1bc742181ded4930842b46e9507372f0b1b963James Dong {0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15}; 800c1bc742181ded4930842b46e9507372f0b1b963James Dong 810c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 820c1bc742181ded4930842b46e9507372f0b1b963James Dong 4. Local function prototypes 830c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 840c1bc742181ded4930842b46e9507372f0b1b963James Dong 850c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 DecodeMbPred(strmData_t *pStrmData, mbPred_t *pMbPred, 860c1bc742181ded4930842b46e9507372f0b1b963James Dong mbType_e mbType, u32 numRefIdxActive); 870c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 DecodeSubMbPred(strmData_t *pStrmData, subMbPred_t *pSubMbPred, 880c1bc742181ded4930842b46e9507372f0b1b963James Dong mbType_e mbType, u32 numRefIdxActive); 890c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 DecodeResidual(strmData_t *pStrmData, residual_t *pResidual, 900c1bc742181ded4930842b46e9507372f0b1b963James Dong mbStorage_t *pMb, mbType_e mbType, u32 codedBlockPattern); 910c1bc742181ded4930842b46e9507372f0b1b963James Dong 920c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_OMXDL 930c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 DetermineNc(mbStorage_t *pMb, u32 blockIndex, u8 *pTotalCoeff); 940c1bc742181ded4930842b46e9507372f0b1b963James Dong#else 950c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 DetermineNc(mbStorage_t *pMb, u32 blockIndex, i16 *pTotalCoeff); 960c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif 970c1bc742181ded4930842b46e9507372f0b1b963James Dong 980c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 CbpIntra16x16(mbType_e mbType); 990c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_OMXDL 1000c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 ProcessIntra4x4Residual(mbStorage_t *pMb, u8 *data, u32 constrainedIntraPred, 1010c1bc742181ded4930842b46e9507372f0b1b963James Dong macroblockLayer_t *mbLayer, const u8 **pSrc, image_t *image); 1020c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 ProcessChromaResidual(mbStorage_t *pMb, u8 *data, const u8 **pSrc ); 1030c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 ProcessIntra16x16Residual(mbStorage_t *pMb, u8 *data, u32 constrainedIntraPred, 1040c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 intraChromaPredMode, const u8 **pSrc, image_t *image); 1050c1bc742181ded4930842b46e9507372f0b1b963James Dong 1060c1bc742181ded4930842b46e9507372f0b1b963James Dong 1070c1bc742181ded4930842b46e9507372f0b1b963James Dong#else 1080c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 ProcessResidual(mbStorage_t *pMb, i32 residualLevel[][16], u32 *); 1090c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif 1100c1bc742181ded4930842b46e9507372f0b1b963James Dong 1110c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 1120c1bc742181ded4930842b46e9507372f0b1b963James Dong 1130c1bc742181ded4930842b46e9507372f0b1b963James Dong Function name: h264bsdDecodeMacroblockLayer 1140c1bc742181ded4930842b46e9507372f0b1b963James Dong 1150c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 1160c1bc742181ded4930842b46e9507372f0b1b963James Dong Parse macroblock specific information from bit stream. 1170c1bc742181ded4930842b46e9507372f0b1b963James Dong 1180c1bc742181ded4930842b46e9507372f0b1b963James Dong Inputs: 1190c1bc742181ded4930842b46e9507372f0b1b963James Dong pStrmData pointer to stream data structure 1200c1bc742181ded4930842b46e9507372f0b1b963James Dong pMb pointer to macroblock storage structure 1210c1bc742181ded4930842b46e9507372f0b1b963James Dong sliceType type of the current slice 1220c1bc742181ded4930842b46e9507372f0b1b963James Dong numRefIdxActive maximum reference index 1230c1bc742181ded4930842b46e9507372f0b1b963James Dong 1240c1bc742181ded4930842b46e9507372f0b1b963James Dong Outputs: 1250c1bc742181ded4930842b46e9507372f0b1b963James Dong pMbLayer stores the macroblock data parsed from stream 1260c1bc742181ded4930842b46e9507372f0b1b963James Dong 1270c1bc742181ded4930842b46e9507372f0b1b963James Dong Returns: 1280c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_OK success 1290c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_NOK end of stream or error in stream 1300c1bc742181ded4930842b46e9507372f0b1b963James Dong 1310c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 1320c1bc742181ded4930842b46e9507372f0b1b963James Dong 1330c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdDecodeMacroblockLayer(strmData_t *pStrmData, 1340c1bc742181ded4930842b46e9507372f0b1b963James Dong macroblockLayer_t *pMbLayer, mbStorage_t *pMb, u32 sliceType, 1350c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 numRefIdxActive) 1360c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 1370c1bc742181ded4930842b46e9507372f0b1b963James Dong 1380c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 1390c1bc742181ded4930842b46e9507372f0b1b963James Dong 1400c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 tmp, i, value; 1410c1bc742181ded4930842b46e9507372f0b1b963James Dong i32 itmp; 1420c1bc742181ded4930842b46e9507372f0b1b963James Dong mbPartPredMode_e partMode; 1430c1bc742181ded4930842b46e9507372f0b1b963James Dong 1440c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 1450c1bc742181ded4930842b46e9507372f0b1b963James Dong 1460c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pStrmData); 1470c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pMbLayer); 1480c1bc742181ded4930842b46e9507372f0b1b963James Dong 1490c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_NEON 1500c1bc742181ded4930842b46e9507372f0b1b963James Dong h264bsdClearMbLayer(pMbLayer, ((sizeof(macroblockLayer_t) + 63) & ~0x3F)); 1510c1bc742181ded4930842b46e9507372f0b1b963James Dong#else 1520c1bc742181ded4930842b46e9507372f0b1b963James Dong H264SwDecMemset(pMbLayer, 0, sizeof(macroblockLayer_t)); 1530c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif 1540c1bc742181ded4930842b46e9507372f0b1b963James Dong 1550c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 1560c1bc742181ded4930842b46e9507372f0b1b963James Dong 1570c1bc742181ded4930842b46e9507372f0b1b963James Dong if (IS_I_SLICE(sliceType)) 1580c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1590c1bc742181ded4930842b46e9507372f0b1b963James Dong if ((value + 6) > 31 || tmp != HANTRO_OK) 1600c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 1610c1bc742181ded4930842b46e9507372f0b1b963James Dong pMbLayer->mbType = (mbType_e)(value + 6); 1620c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1630c1bc742181ded4930842b46e9507372f0b1b963James Dong else 1640c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1650c1bc742181ded4930842b46e9507372f0b1b963James Dong if ((value + 1) > 31 || tmp != HANTRO_OK) 1660c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 1670c1bc742181ded4930842b46e9507372f0b1b963James Dong pMbLayer->mbType = (mbType_e)(value + 1); 1680c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1690c1bc742181ded4930842b46e9507372f0b1b963James Dong 1700c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pMbLayer->mbType == I_PCM) 1710c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1720c1bc742181ded4930842b46e9507372f0b1b963James Dong i32 *level; 1730c1bc742181ded4930842b46e9507372f0b1b963James Dong while( !h264bsdIsByteAligned(pStrmData) ) 1740c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1750c1bc742181ded4930842b46e9507372f0b1b963James Dong /* pcm_alignment_zero_bit */ 1760c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdGetBits(pStrmData, 1); 1770c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp) 1780c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 1790c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1800c1bc742181ded4930842b46e9507372f0b1b963James Dong 1810c1bc742181ded4930842b46e9507372f0b1b963James Dong level = pMbLayer->residual.level[0]; 1820c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 0; i < 384; i++) 1830c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1840c1bc742181ded4930842b46e9507372f0b1b963James Dong value = h264bsdGetBits(pStrmData, 8); 1850c1bc742181ded4930842b46e9507372f0b1b963James Dong if (value == END_OF_STREAM) 1860c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 1870c1bc742181ded4930842b46e9507372f0b1b963James Dong *level++ = (i32)value; 1880c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1890c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1900c1bc742181ded4930842b46e9507372f0b1b963James Dong else 1910c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1920c1bc742181ded4930842b46e9507372f0b1b963James Dong partMode = h264bsdMbPartPredMode(pMbLayer->mbType); 1930c1bc742181ded4930842b46e9507372f0b1b963James Dong if ( (partMode == PRED_MODE_INTER) && 1940c1bc742181ded4930842b46e9507372f0b1b963James Dong (h264bsdNumMbPart(pMbLayer->mbType) == 4) ) 1950c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1960c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = DecodeSubMbPred(pStrmData, &pMbLayer->subMbPred, 1970c1bc742181ded4930842b46e9507372f0b1b963James Dong pMbLayer->mbType, numRefIdxActive); 1980c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1990c1bc742181ded4930842b46e9507372f0b1b963James Dong else 2000c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2010c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = DecodeMbPred(pStrmData, &pMbLayer->mbPred, 2020c1bc742181ded4930842b46e9507372f0b1b963James Dong pMbLayer->mbType, numRefIdxActive); 2030c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2040c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 2050c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 2060c1bc742181ded4930842b46e9507372f0b1b963James Dong 2070c1bc742181ded4930842b46e9507372f0b1b963James Dong if (partMode != PRED_MODE_INTRA16x16) 2080c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2090c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombMapped(pStrmData, &value, 2100c1bc742181ded4930842b46e9507372f0b1b963James Dong (u32)(partMode == PRED_MODE_INTRA4x4)); 2110c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 2120c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 2130c1bc742181ded4930842b46e9507372f0b1b963James Dong pMbLayer->codedBlockPattern = value; 2140c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2150c1bc742181ded4930842b46e9507372f0b1b963James Dong else 2160c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2170c1bc742181ded4930842b46e9507372f0b1b963James Dong pMbLayer->codedBlockPattern = CbpIntra16x16(pMbLayer->mbType); 2180c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2190c1bc742181ded4930842b46e9507372f0b1b963James Dong 2200c1bc742181ded4930842b46e9507372f0b1b963James Dong if ( pMbLayer->codedBlockPattern || 2210c1bc742181ded4930842b46e9507372f0b1b963James Dong (partMode == PRED_MODE_INTRA16x16) ) 2220c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2230c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp); 2240c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK || (itmp < -26) || (itmp > 25) ) 2250c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 2260c1bc742181ded4930842b46e9507372f0b1b963James Dong pMbLayer->mbQpDelta = itmp; 2270c1bc742181ded4930842b46e9507372f0b1b963James Dong 2280c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = DecodeResidual(pStrmData, &pMbLayer->residual, pMb, 2290c1bc742181ded4930842b46e9507372f0b1b963James Dong pMbLayer->mbType, pMbLayer->codedBlockPattern); 2300c1bc742181ded4930842b46e9507372f0b1b963James Dong 2310c1bc742181ded4930842b46e9507372f0b1b963James Dong pStrmData->strmBuffReadBits = 2320c1bc742181ded4930842b46e9507372f0b1b963James Dong (u32)(pStrmData->pStrmCurrPos - pStrmData->pStrmBuffStart) * 8 + 2330c1bc742181ded4930842b46e9507372f0b1b963James Dong pStrmData->bitPosInWord; 2340c1bc742181ded4930842b46e9507372f0b1b963James Dong 2350c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 2360c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 2370c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2380c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2390c1bc742181ded4930842b46e9507372f0b1b963James Dong 2400c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_OK); 2410c1bc742181ded4930842b46e9507372f0b1b963James Dong 2420c1bc742181ded4930842b46e9507372f0b1b963James Dong} 2430c1bc742181ded4930842b46e9507372f0b1b963James Dong 2440c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 2450c1bc742181ded4930842b46e9507372f0b1b963James Dong 2460c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: h264bsdMbPartPredMode 2470c1bc742181ded4930842b46e9507372f0b1b963James Dong 2480c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 2490c1bc742181ded4930842b46e9507372f0b1b963James Dong Returns the prediction mode of a macroblock type 2500c1bc742181ded4930842b46e9507372f0b1b963James Dong 2510c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 2520c1bc742181ded4930842b46e9507372f0b1b963James Dong 2530c1bc742181ded4930842b46e9507372f0b1b963James DongmbPartPredMode_e h264bsdMbPartPredMode(mbType_e mbType) 2540c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 2550c1bc742181ded4930842b46e9507372f0b1b963James Dong 2560c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 2570c1bc742181ded4930842b46e9507372f0b1b963James Dong 2580c1bc742181ded4930842b46e9507372f0b1b963James Dong 2590c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 2600c1bc742181ded4930842b46e9507372f0b1b963James Dong 2610c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(mbType <= 31); 2620c1bc742181ded4930842b46e9507372f0b1b963James Dong 2630c1bc742181ded4930842b46e9507372f0b1b963James Dong if ((mbType <= P_8x8ref0)) 2640c1bc742181ded4930842b46e9507372f0b1b963James Dong return(PRED_MODE_INTER); 2650c1bc742181ded4930842b46e9507372f0b1b963James Dong else if (mbType == I_4x4) 2660c1bc742181ded4930842b46e9507372f0b1b963James Dong return(PRED_MODE_INTRA4x4); 2670c1bc742181ded4930842b46e9507372f0b1b963James Dong else 2680c1bc742181ded4930842b46e9507372f0b1b963James Dong return(PRED_MODE_INTRA16x16); 2690c1bc742181ded4930842b46e9507372f0b1b963James Dong 2700c1bc742181ded4930842b46e9507372f0b1b963James Dong} 2710c1bc742181ded4930842b46e9507372f0b1b963James Dong 2720c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 2730c1bc742181ded4930842b46e9507372f0b1b963James Dong 2740c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: h264bsdNumMbPart 2750c1bc742181ded4930842b46e9507372f0b1b963James Dong 2760c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 2770c1bc742181ded4930842b46e9507372f0b1b963James Dong Returns the amount of macroblock partitions in a macroblock type 2780c1bc742181ded4930842b46e9507372f0b1b963James Dong 2790c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 2800c1bc742181ded4930842b46e9507372f0b1b963James Dong 2810c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdNumMbPart(mbType_e mbType) 2820c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 2830c1bc742181ded4930842b46e9507372f0b1b963James Dong 2840c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 2850c1bc742181ded4930842b46e9507372f0b1b963James Dong 2860c1bc742181ded4930842b46e9507372f0b1b963James Dong 2870c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 2880c1bc742181ded4930842b46e9507372f0b1b963James Dong 2890c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(h264bsdMbPartPredMode(mbType) == PRED_MODE_INTER); 2900c1bc742181ded4930842b46e9507372f0b1b963James Dong 2910c1bc742181ded4930842b46e9507372f0b1b963James Dong switch (mbType) 2920c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2930c1bc742181ded4930842b46e9507372f0b1b963James Dong case P_L0_16x16: 2940c1bc742181ded4930842b46e9507372f0b1b963James Dong case P_Skip: 2950c1bc742181ded4930842b46e9507372f0b1b963James Dong return(1); 2960c1bc742181ded4930842b46e9507372f0b1b963James Dong 2970c1bc742181ded4930842b46e9507372f0b1b963James Dong case P_L0_L0_16x8: 2980c1bc742181ded4930842b46e9507372f0b1b963James Dong case P_L0_L0_8x16: 2990c1bc742181ded4930842b46e9507372f0b1b963James Dong return(2); 3000c1bc742181ded4930842b46e9507372f0b1b963James Dong 3010c1bc742181ded4930842b46e9507372f0b1b963James Dong /* P_8x8 or P_8x8ref0 */ 3020c1bc742181ded4930842b46e9507372f0b1b963James Dong default: 3030c1bc742181ded4930842b46e9507372f0b1b963James Dong return(4); 3040c1bc742181ded4930842b46e9507372f0b1b963James Dong } 3050c1bc742181ded4930842b46e9507372f0b1b963James Dong 3060c1bc742181ded4930842b46e9507372f0b1b963James Dong} 3070c1bc742181ded4930842b46e9507372f0b1b963James Dong 3080c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 3090c1bc742181ded4930842b46e9507372f0b1b963James Dong 3100c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: h264bsdNumSubMbPart 3110c1bc742181ded4930842b46e9507372f0b1b963James Dong 3120c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 3130c1bc742181ded4930842b46e9507372f0b1b963James Dong Returns the amount of sub-partitions in a sub-macroblock type 3140c1bc742181ded4930842b46e9507372f0b1b963James Dong 3150c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 3160c1bc742181ded4930842b46e9507372f0b1b963James Dong 3170c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdNumSubMbPart(subMbType_e subMbType) 3180c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 3190c1bc742181ded4930842b46e9507372f0b1b963James Dong 3200c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 3210c1bc742181ded4930842b46e9507372f0b1b963James Dong 3220c1bc742181ded4930842b46e9507372f0b1b963James Dong 3230c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 3240c1bc742181ded4930842b46e9507372f0b1b963James Dong 3250c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(subMbType <= P_L0_4x4); 3260c1bc742181ded4930842b46e9507372f0b1b963James Dong 3270c1bc742181ded4930842b46e9507372f0b1b963James Dong switch (subMbType) 3280c1bc742181ded4930842b46e9507372f0b1b963James Dong { 3290c1bc742181ded4930842b46e9507372f0b1b963James Dong case P_L0_8x8: 3300c1bc742181ded4930842b46e9507372f0b1b963James Dong return(1); 3310c1bc742181ded4930842b46e9507372f0b1b963James Dong 3320c1bc742181ded4930842b46e9507372f0b1b963James Dong case P_L0_8x4: 3330c1bc742181ded4930842b46e9507372f0b1b963James Dong case P_L0_4x8: 3340c1bc742181ded4930842b46e9507372f0b1b963James Dong return(2); 3350c1bc742181ded4930842b46e9507372f0b1b963James Dong 3360c1bc742181ded4930842b46e9507372f0b1b963James Dong /* P_L0_4x4 */ 3370c1bc742181ded4930842b46e9507372f0b1b963James Dong default: 3380c1bc742181ded4930842b46e9507372f0b1b963James Dong return(4); 3390c1bc742181ded4930842b46e9507372f0b1b963James Dong } 3400c1bc742181ded4930842b46e9507372f0b1b963James Dong 3410c1bc742181ded4930842b46e9507372f0b1b963James Dong} 3420c1bc742181ded4930842b46e9507372f0b1b963James Dong 3430c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 3440c1bc742181ded4930842b46e9507372f0b1b963James Dong 3450c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: DecodeMbPred 3460c1bc742181ded4930842b46e9507372f0b1b963James Dong 3470c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 3480c1bc742181ded4930842b46e9507372f0b1b963James Dong Parse macroblock prediction information from bit stream and store 3490c1bc742181ded4930842b46e9507372f0b1b963James Dong in 'pMbPred'. 3500c1bc742181ded4930842b46e9507372f0b1b963James Dong 3510c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 3520c1bc742181ded4930842b46e9507372f0b1b963James Dong 3530c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 DecodeMbPred(strmData_t *pStrmData, mbPred_t *pMbPred, mbType_e mbType, 3540c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 numRefIdxActive) 3550c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 3560c1bc742181ded4930842b46e9507372f0b1b963James Dong 3570c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 3580c1bc742181ded4930842b46e9507372f0b1b963James Dong 3590c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 tmp, i, j, value; 3600c1bc742181ded4930842b46e9507372f0b1b963James Dong i32 itmp; 3610c1bc742181ded4930842b46e9507372f0b1b963James Dong 3620c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 3630c1bc742181ded4930842b46e9507372f0b1b963James Dong 3640c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pStrmData); 3650c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pMbPred); 3660c1bc742181ded4930842b46e9507372f0b1b963James Dong 3670c1bc742181ded4930842b46e9507372f0b1b963James Dong switch (h264bsdMbPartPredMode(mbType)) 3680c1bc742181ded4930842b46e9507372f0b1b963James Dong { 3690c1bc742181ded4930842b46e9507372f0b1b963James Dong case PRED_MODE_INTER: /* PRED_MODE_INTER */ 3700c1bc742181ded4930842b46e9507372f0b1b963James Dong if (numRefIdxActive > 1) 3710c1bc742181ded4930842b46e9507372f0b1b963James Dong { 3720c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = h264bsdNumMbPart(mbType), j = 0; i--; j++) 3730c1bc742181ded4930842b46e9507372f0b1b963James Dong { 3740c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombTruncated(pStrmData, &value, 3750c1bc742181ded4930842b46e9507372f0b1b963James Dong (u32)(numRefIdxActive > 2)); 3760c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK || value >= numRefIdxActive) 3770c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 3780c1bc742181ded4930842b46e9507372f0b1b963James Dong 3790c1bc742181ded4930842b46e9507372f0b1b963James Dong pMbPred->refIdxL0[j] = value; 3800c1bc742181ded4930842b46e9507372f0b1b963James Dong } 3810c1bc742181ded4930842b46e9507372f0b1b963James Dong } 3820c1bc742181ded4930842b46e9507372f0b1b963James Dong 3830c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = h264bsdNumMbPart(mbType), j = 0; i--; j++) 3840c1bc742181ded4930842b46e9507372f0b1b963James Dong { 3850c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp); 3860c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 3870c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 3880c1bc742181ded4930842b46e9507372f0b1b963James Dong pMbPred->mvdL0[j].hor = (i16)itmp; 3890c1bc742181ded4930842b46e9507372f0b1b963James Dong 3900c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp); 3910c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 3920c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 3930c1bc742181ded4930842b46e9507372f0b1b963James Dong pMbPred->mvdL0[j].ver = (i16)itmp; 3940c1bc742181ded4930842b46e9507372f0b1b963James Dong } 3950c1bc742181ded4930842b46e9507372f0b1b963James Dong break; 3960c1bc742181ded4930842b46e9507372f0b1b963James Dong 3970c1bc742181ded4930842b46e9507372f0b1b963James Dong case PRED_MODE_INTRA4x4: 3980c1bc742181ded4930842b46e9507372f0b1b963James Dong for (itmp = 0, i = 0; itmp < 2; itmp++) 3990c1bc742181ded4930842b46e9507372f0b1b963James Dong { 4000c1bc742181ded4930842b46e9507372f0b1b963James Dong value = h264bsdShowBits32(pStrmData); 4010c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = 0; 4020c1bc742181ded4930842b46e9507372f0b1b963James Dong for (j = 8; j--; i++) 4030c1bc742181ded4930842b46e9507372f0b1b963James Dong { 4040c1bc742181ded4930842b46e9507372f0b1b963James Dong pMbPred->prevIntra4x4PredModeFlag[i] = 4050c1bc742181ded4930842b46e9507372f0b1b963James Dong value & 0x80000000 ? HANTRO_TRUE : HANTRO_FALSE; 4060c1bc742181ded4930842b46e9507372f0b1b963James Dong value <<= 1; 4070c1bc742181ded4930842b46e9507372f0b1b963James Dong if (!pMbPred->prevIntra4x4PredModeFlag[i]) 4080c1bc742181ded4930842b46e9507372f0b1b963James Dong { 4090c1bc742181ded4930842b46e9507372f0b1b963James Dong pMbPred->remIntra4x4PredMode[i] = value>>29; 4100c1bc742181ded4930842b46e9507372f0b1b963James Dong value <<= 3; 4110c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp++; 4120c1bc742181ded4930842b46e9507372f0b1b963James Dong } 4130c1bc742181ded4930842b46e9507372f0b1b963James Dong } 4140c1bc742181ded4930842b46e9507372f0b1b963James Dong if (h264bsdFlushBits(pStrmData, 8 + 3*tmp) == END_OF_STREAM) 4150c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 4160c1bc742181ded4930842b46e9507372f0b1b963James Dong } 4170c1bc742181ded4930842b46e9507372f0b1b963James Dong /* fall-through */ 4180c1bc742181ded4930842b46e9507372f0b1b963James Dong 4190c1bc742181ded4930842b46e9507372f0b1b963James Dong case PRED_MODE_INTRA16x16: 4200c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 4210c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK || value > 3) 4220c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 4230c1bc742181ded4930842b46e9507372f0b1b963James Dong pMbPred->intraChromaPredMode = value; 4240c1bc742181ded4930842b46e9507372f0b1b963James Dong break; 4250c1bc742181ded4930842b46e9507372f0b1b963James Dong } 4260c1bc742181ded4930842b46e9507372f0b1b963James Dong 4270c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_OK); 4280c1bc742181ded4930842b46e9507372f0b1b963James Dong 4290c1bc742181ded4930842b46e9507372f0b1b963James Dong} 4300c1bc742181ded4930842b46e9507372f0b1b963James Dong 4310c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 4320c1bc742181ded4930842b46e9507372f0b1b963James Dong 4330c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: DecodeSubMbPred 4340c1bc742181ded4930842b46e9507372f0b1b963James Dong 4350c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 4360c1bc742181ded4930842b46e9507372f0b1b963James Dong Parse sub-macroblock prediction information from bit stream and 4370c1bc742181ded4930842b46e9507372f0b1b963James Dong store in 'pMbPred'. 4380c1bc742181ded4930842b46e9507372f0b1b963James Dong 4390c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 4400c1bc742181ded4930842b46e9507372f0b1b963James Dong 4410c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 DecodeSubMbPred(strmData_t *pStrmData, subMbPred_t *pSubMbPred, 4420c1bc742181ded4930842b46e9507372f0b1b963James Dong mbType_e mbType, u32 numRefIdxActive) 4430c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 4440c1bc742181ded4930842b46e9507372f0b1b963James Dong 4450c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 4460c1bc742181ded4930842b46e9507372f0b1b963James Dong 4470c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 tmp, i, j, value; 4480c1bc742181ded4930842b46e9507372f0b1b963James Dong i32 itmp; 4490c1bc742181ded4930842b46e9507372f0b1b963James Dong 4500c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 4510c1bc742181ded4930842b46e9507372f0b1b963James Dong 4520c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pStrmData); 4530c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pSubMbPred); 4540c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(h264bsdMbPartPredMode(mbType) == PRED_MODE_INTER); 4550c1bc742181ded4930842b46e9507372f0b1b963James Dong 4560c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 0; i < 4; i++) 4570c1bc742181ded4930842b46e9507372f0b1b963James Dong { 4580c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value); 4590c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK || value > 3) 4600c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 4610c1bc742181ded4930842b46e9507372f0b1b963James Dong pSubMbPred->subMbType[i] = (subMbType_e)value; 4620c1bc742181ded4930842b46e9507372f0b1b963James Dong } 4630c1bc742181ded4930842b46e9507372f0b1b963James Dong 4640c1bc742181ded4930842b46e9507372f0b1b963James Dong if ( (numRefIdxActive > 1) && (mbType != P_8x8ref0) ) 4650c1bc742181ded4930842b46e9507372f0b1b963James Dong { 4660c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 0; i < 4; i++) 4670c1bc742181ded4930842b46e9507372f0b1b963James Dong { 4680c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombTruncated(pStrmData, &value, 4690c1bc742181ded4930842b46e9507372f0b1b963James Dong (u32)(numRefIdxActive > 2)); 4700c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK || value >= numRefIdxActive) 4710c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 4720c1bc742181ded4930842b46e9507372f0b1b963James Dong pSubMbPred->refIdxL0[i] = value; 4730c1bc742181ded4930842b46e9507372f0b1b963James Dong } 4740c1bc742181ded4930842b46e9507372f0b1b963James Dong } 4750c1bc742181ded4930842b46e9507372f0b1b963James Dong 4760c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 0; i < 4; i++) 4770c1bc742181ded4930842b46e9507372f0b1b963James Dong { 4780c1bc742181ded4930842b46e9507372f0b1b963James Dong j = 0; 4790c1bc742181ded4930842b46e9507372f0b1b963James Dong for (value = h264bsdNumSubMbPart(pSubMbPred->subMbType[i]); 4800c1bc742181ded4930842b46e9507372f0b1b963James Dong value--; j++) 4810c1bc742181ded4930842b46e9507372f0b1b963James Dong { 4820c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp); 4830c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 4840c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 4850c1bc742181ded4930842b46e9507372f0b1b963James Dong pSubMbPred->mvdL0[i][j].hor = (i16)itmp; 4860c1bc742181ded4930842b46e9507372f0b1b963James Dong 4870c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp); 4880c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 4890c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 4900c1bc742181ded4930842b46e9507372f0b1b963James Dong pSubMbPred->mvdL0[i][j].ver = (i16)itmp; 4910c1bc742181ded4930842b46e9507372f0b1b963James Dong } 4920c1bc742181ded4930842b46e9507372f0b1b963James Dong } 4930c1bc742181ded4930842b46e9507372f0b1b963James Dong 4940c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_OK); 4950c1bc742181ded4930842b46e9507372f0b1b963James Dong 4960c1bc742181ded4930842b46e9507372f0b1b963James Dong} 4970c1bc742181ded4930842b46e9507372f0b1b963James Dong 4980c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_OMXDL 4990c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 5000c1bc742181ded4930842b46e9507372f0b1b963James Dong 5010c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: DecodeResidual 5020c1bc742181ded4930842b46e9507372f0b1b963James Dong 5030c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 5040c1bc742181ded4930842b46e9507372f0b1b963James Dong Parse residual information from bit stream and store in 'pResidual'. 5050c1bc742181ded4930842b46e9507372f0b1b963James Dong 5060c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 5070c1bc742181ded4930842b46e9507372f0b1b963James Dong 5080c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 DecodeResidual(strmData_t *pStrmData, residual_t *pResidual, 5090c1bc742181ded4930842b46e9507372f0b1b963James Dong mbStorage_t *pMb, mbType_e mbType, u32 codedBlockPattern) 5100c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 5110c1bc742181ded4930842b46e9507372f0b1b963James Dong 5120c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 5130c1bc742181ded4930842b46e9507372f0b1b963James Dong 5140c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 i, j; 5150c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 blockCoded; 5160c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 blockIndex; 5170c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 is16x16; 5180c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_INT nc; 5190c1bc742181ded4930842b46e9507372f0b1b963James Dong OMXResult omxRes; 5200c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_U8 *pPosCoefBuf; 5210c1bc742181ded4930842b46e9507372f0b1b963James Dong 5220c1bc742181ded4930842b46e9507372f0b1b963James Dong 5230c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 5240c1bc742181ded4930842b46e9507372f0b1b963James Dong 5250c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pStrmData); 5260c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pResidual); 5270c1bc742181ded4930842b46e9507372f0b1b963James Dong 5280c1bc742181ded4930842b46e9507372f0b1b963James Dong pPosCoefBuf = pResidual->posCoefBuf; 5290c1bc742181ded4930842b46e9507372f0b1b963James Dong 5300c1bc742181ded4930842b46e9507372f0b1b963James Dong /* luma DC is at index 24 */ 5310c1bc742181ded4930842b46e9507372f0b1b963James Dong if (h264bsdMbPartPredMode(mbType) == PRED_MODE_INTRA16x16) 5320c1bc742181ded4930842b46e9507372f0b1b963James Dong { 5330c1bc742181ded4930842b46e9507372f0b1b963James Dong nc = (OMX_INT)DetermineNc(pMb, 0, pResidual->totalCoeff); 5340c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifndef H264DEC_NEON 5350c1bc742181ded4930842b46e9507372f0b1b963James Dong omxRes = omxVCM4P10_DecodeCoeffsToPairCAVLC( 5360c1bc742181ded4930842b46e9507372f0b1b963James Dong (const OMX_U8 **) (&pStrmData->pStrmCurrPos), 5370c1bc742181ded4930842b46e9507372f0b1b963James Dong (OMX_S32*) (&pStrmData->bitPosInWord), 5380c1bc742181ded4930842b46e9507372f0b1b963James Dong &pResidual->totalCoeff[24], 5390c1bc742181ded4930842b46e9507372f0b1b963James Dong &pPosCoefBuf, 5400c1bc742181ded4930842b46e9507372f0b1b963James Dong nc, 5410c1bc742181ded4930842b46e9507372f0b1b963James Dong 16); 5420c1bc742181ded4930842b46e9507372f0b1b963James Dong#else 5430c1bc742181ded4930842b46e9507372f0b1b963James Dong omxRes = armVCM4P10_DecodeCoeffsToPair( 5440c1bc742181ded4930842b46e9507372f0b1b963James Dong (const OMX_U8 **) (&pStrmData->pStrmCurrPos), 5450c1bc742181ded4930842b46e9507372f0b1b963James Dong (OMX_S32*) (&pStrmData->bitPosInWord), 5460c1bc742181ded4930842b46e9507372f0b1b963James Dong &pResidual->totalCoeff[24], 5470c1bc742181ded4930842b46e9507372f0b1b963James Dong &pPosCoefBuf, 5480c1bc742181ded4930842b46e9507372f0b1b963James Dong nc, 5490c1bc742181ded4930842b46e9507372f0b1b963James Dong 16); 5500c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif 5510c1bc742181ded4930842b46e9507372f0b1b963James Dong if (omxRes != OMX_Sts_NoErr) 5520c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 5530c1bc742181ded4930842b46e9507372f0b1b963James Dong is16x16 = HANTRO_TRUE; 5540c1bc742181ded4930842b46e9507372f0b1b963James Dong } 5550c1bc742181ded4930842b46e9507372f0b1b963James Dong else 5560c1bc742181ded4930842b46e9507372f0b1b963James Dong is16x16 = HANTRO_FALSE; 5570c1bc742181ded4930842b46e9507372f0b1b963James Dong 5580c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 4, blockIndex = 0; i--;) 5590c1bc742181ded4930842b46e9507372f0b1b963James Dong { 5600c1bc742181ded4930842b46e9507372f0b1b963James Dong /* luma cbp in bits 0-3 */ 5610c1bc742181ded4930842b46e9507372f0b1b963James Dong blockCoded = codedBlockPattern & 0x1; 5620c1bc742181ded4930842b46e9507372f0b1b963James Dong codedBlockPattern >>= 1; 5630c1bc742181ded4930842b46e9507372f0b1b963James Dong if (blockCoded) 5640c1bc742181ded4930842b46e9507372f0b1b963James Dong { 5650c1bc742181ded4930842b46e9507372f0b1b963James Dong for (j = 4; j--; blockIndex++) 5660c1bc742181ded4930842b46e9507372f0b1b963James Dong { 5670c1bc742181ded4930842b46e9507372f0b1b963James Dong nc = (OMX_INT)DetermineNc(pMb,blockIndex,pResidual->totalCoeff); 5680c1bc742181ded4930842b46e9507372f0b1b963James Dong if (is16x16) 5690c1bc742181ded4930842b46e9507372f0b1b963James Dong { 5700c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifndef H264DEC_NEON 5710c1bc742181ded4930842b46e9507372f0b1b963James Dong omxRes = omxVCM4P10_DecodeCoeffsToPairCAVLC( 5720c1bc742181ded4930842b46e9507372f0b1b963James Dong (const OMX_U8 **) (&pStrmData->pStrmCurrPos), 5730c1bc742181ded4930842b46e9507372f0b1b963James Dong (OMX_S32*) (&pStrmData->bitPosInWord), 5740c1bc742181ded4930842b46e9507372f0b1b963James Dong &pResidual->totalCoeff[blockIndex], 5750c1bc742181ded4930842b46e9507372f0b1b963James Dong &pPosCoefBuf, 5760c1bc742181ded4930842b46e9507372f0b1b963James Dong nc, 5770c1bc742181ded4930842b46e9507372f0b1b963James Dong 15); 5780c1bc742181ded4930842b46e9507372f0b1b963James Dong#else 5790c1bc742181ded4930842b46e9507372f0b1b963James Dong omxRes = armVCM4P10_DecodeCoeffsToPair( 5800c1bc742181ded4930842b46e9507372f0b1b963James Dong (const OMX_U8 **) (&pStrmData->pStrmCurrPos), 5810c1bc742181ded4930842b46e9507372f0b1b963James Dong (OMX_S32*) (&pStrmData->bitPosInWord), 5820c1bc742181ded4930842b46e9507372f0b1b963James Dong &pResidual->totalCoeff[blockIndex], 5830c1bc742181ded4930842b46e9507372f0b1b963James Dong &pPosCoefBuf, 5840c1bc742181ded4930842b46e9507372f0b1b963James Dong nc, 5850c1bc742181ded4930842b46e9507372f0b1b963James Dong 15); 5860c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif 5870c1bc742181ded4930842b46e9507372f0b1b963James Dong } 5880c1bc742181ded4930842b46e9507372f0b1b963James Dong else 5890c1bc742181ded4930842b46e9507372f0b1b963James Dong { 5900c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifndef H264DEC_NEON 5910c1bc742181ded4930842b46e9507372f0b1b963James Dong omxRes = omxVCM4P10_DecodeCoeffsToPairCAVLC( 5920c1bc742181ded4930842b46e9507372f0b1b963James Dong (const OMX_U8 **) (&pStrmData->pStrmCurrPos), 5930c1bc742181ded4930842b46e9507372f0b1b963James Dong (OMX_S32*) (&pStrmData->bitPosInWord), 5940c1bc742181ded4930842b46e9507372f0b1b963James Dong &pResidual->totalCoeff[blockIndex], 5950c1bc742181ded4930842b46e9507372f0b1b963James Dong &pPosCoefBuf, 5960c1bc742181ded4930842b46e9507372f0b1b963James Dong nc, 5970c1bc742181ded4930842b46e9507372f0b1b963James Dong 16); 5980c1bc742181ded4930842b46e9507372f0b1b963James Dong#else 5990c1bc742181ded4930842b46e9507372f0b1b963James Dong omxRes = armVCM4P10_DecodeCoeffsToPair( 6000c1bc742181ded4930842b46e9507372f0b1b963James Dong (const OMX_U8 **) (&pStrmData->pStrmCurrPos), 6010c1bc742181ded4930842b46e9507372f0b1b963James Dong (OMX_S32*) (&pStrmData->bitPosInWord), 6020c1bc742181ded4930842b46e9507372f0b1b963James Dong &pResidual->totalCoeff[blockIndex], 6030c1bc742181ded4930842b46e9507372f0b1b963James Dong &pPosCoefBuf, 6040c1bc742181ded4930842b46e9507372f0b1b963James Dong nc, 6050c1bc742181ded4930842b46e9507372f0b1b963James Dong 16); 6060c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif 6070c1bc742181ded4930842b46e9507372f0b1b963James Dong } 6080c1bc742181ded4930842b46e9507372f0b1b963James Dong if (omxRes != OMX_Sts_NoErr) 6090c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 6100c1bc742181ded4930842b46e9507372f0b1b963James Dong } 6110c1bc742181ded4930842b46e9507372f0b1b963James Dong } 6120c1bc742181ded4930842b46e9507372f0b1b963James Dong else 6130c1bc742181ded4930842b46e9507372f0b1b963James Dong blockIndex += 4; 6140c1bc742181ded4930842b46e9507372f0b1b963James Dong } 6150c1bc742181ded4930842b46e9507372f0b1b963James Dong 6160c1bc742181ded4930842b46e9507372f0b1b963James Dong /* chroma DC block are at indices 25 and 26 */ 6170c1bc742181ded4930842b46e9507372f0b1b963James Dong blockCoded = codedBlockPattern & 0x3; 6180c1bc742181ded4930842b46e9507372f0b1b963James Dong if (blockCoded) 6190c1bc742181ded4930842b46e9507372f0b1b963James Dong { 6200c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifndef H264DEC_NEON 6210c1bc742181ded4930842b46e9507372f0b1b963James Dong omxRes = omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC( 6220c1bc742181ded4930842b46e9507372f0b1b963James Dong (const OMX_U8**) (&pStrmData->pStrmCurrPos), 6230c1bc742181ded4930842b46e9507372f0b1b963James Dong (OMX_S32*) (&pStrmData->bitPosInWord), 6240c1bc742181ded4930842b46e9507372f0b1b963James Dong &pResidual->totalCoeff[25], 6250c1bc742181ded4930842b46e9507372f0b1b963James Dong &pPosCoefBuf); 6260c1bc742181ded4930842b46e9507372f0b1b963James Dong#else 6270c1bc742181ded4930842b46e9507372f0b1b963James Dong omxRes = armVCM4P10_DecodeCoeffsToPair( 6280c1bc742181ded4930842b46e9507372f0b1b963James Dong (const OMX_U8**) (&pStrmData->pStrmCurrPos), 6290c1bc742181ded4930842b46e9507372f0b1b963James Dong (OMX_S32*) (&pStrmData->bitPosInWord), 6300c1bc742181ded4930842b46e9507372f0b1b963James Dong &pResidual->totalCoeff[25], 6310c1bc742181ded4930842b46e9507372f0b1b963James Dong &pPosCoefBuf, 6320c1bc742181ded4930842b46e9507372f0b1b963James Dong 17, 6330c1bc742181ded4930842b46e9507372f0b1b963James Dong 4); 6340c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif 6350c1bc742181ded4930842b46e9507372f0b1b963James Dong if (omxRes != OMX_Sts_NoErr) 6360c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 6370c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifndef H264DEC_NEON 6380c1bc742181ded4930842b46e9507372f0b1b963James Dong omxRes = omxVCM4P10_DecodeChromaDcCoeffsToPairCAVLC( 6390c1bc742181ded4930842b46e9507372f0b1b963James Dong (const OMX_U8**) (&pStrmData->pStrmCurrPos), 6400c1bc742181ded4930842b46e9507372f0b1b963James Dong (OMX_S32*) (&pStrmData->bitPosInWord), 6410c1bc742181ded4930842b46e9507372f0b1b963James Dong &pResidual->totalCoeff[26], 6420c1bc742181ded4930842b46e9507372f0b1b963James Dong &pPosCoefBuf); 6430c1bc742181ded4930842b46e9507372f0b1b963James Dong#else 6440c1bc742181ded4930842b46e9507372f0b1b963James Dong omxRes = armVCM4P10_DecodeCoeffsToPair( 6450c1bc742181ded4930842b46e9507372f0b1b963James Dong (const OMX_U8**) (&pStrmData->pStrmCurrPos), 6460c1bc742181ded4930842b46e9507372f0b1b963James Dong (OMX_S32*) (&pStrmData->bitPosInWord), 6470c1bc742181ded4930842b46e9507372f0b1b963James Dong &pResidual->totalCoeff[26], 6480c1bc742181ded4930842b46e9507372f0b1b963James Dong &pPosCoefBuf, 6490c1bc742181ded4930842b46e9507372f0b1b963James Dong 17, 6500c1bc742181ded4930842b46e9507372f0b1b963James Dong 4); 6510c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif 6520c1bc742181ded4930842b46e9507372f0b1b963James Dong if (omxRes != OMX_Sts_NoErr) 6530c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 6540c1bc742181ded4930842b46e9507372f0b1b963James Dong } 6550c1bc742181ded4930842b46e9507372f0b1b963James Dong 6560c1bc742181ded4930842b46e9507372f0b1b963James Dong /* chroma AC */ 6570c1bc742181ded4930842b46e9507372f0b1b963James Dong blockCoded = codedBlockPattern & 0x2; 6580c1bc742181ded4930842b46e9507372f0b1b963James Dong if (blockCoded) 6590c1bc742181ded4930842b46e9507372f0b1b963James Dong { 6600c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 8; i--;blockIndex++) 6610c1bc742181ded4930842b46e9507372f0b1b963James Dong { 6620c1bc742181ded4930842b46e9507372f0b1b963James Dong nc = (OMX_INT)DetermineNc(pMb, blockIndex, pResidual->totalCoeff); 6630c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifndef H264DEC_NEON 6640c1bc742181ded4930842b46e9507372f0b1b963James Dong omxRes = omxVCM4P10_DecodeCoeffsToPairCAVLC( 6650c1bc742181ded4930842b46e9507372f0b1b963James Dong (const OMX_U8 **) (&pStrmData->pStrmCurrPos), 6660c1bc742181ded4930842b46e9507372f0b1b963James Dong (OMX_S32*) (&pStrmData->bitPosInWord), 6670c1bc742181ded4930842b46e9507372f0b1b963James Dong &pResidual->totalCoeff[blockIndex], 6680c1bc742181ded4930842b46e9507372f0b1b963James Dong &pPosCoefBuf, 6690c1bc742181ded4930842b46e9507372f0b1b963James Dong nc, 6700c1bc742181ded4930842b46e9507372f0b1b963James Dong 15); 6710c1bc742181ded4930842b46e9507372f0b1b963James Dong#else 6720c1bc742181ded4930842b46e9507372f0b1b963James Dong omxRes = armVCM4P10_DecodeCoeffsToPair( 6730c1bc742181ded4930842b46e9507372f0b1b963James Dong (const OMX_U8 **) (&pStrmData->pStrmCurrPos), 6740c1bc742181ded4930842b46e9507372f0b1b963James Dong (OMX_S32*) (&pStrmData->bitPosInWord), 6750c1bc742181ded4930842b46e9507372f0b1b963James Dong &pResidual->totalCoeff[blockIndex], 6760c1bc742181ded4930842b46e9507372f0b1b963James Dong &pPosCoefBuf, 6770c1bc742181ded4930842b46e9507372f0b1b963James Dong nc, 6780c1bc742181ded4930842b46e9507372f0b1b963James Dong 15); 6790c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif 6800c1bc742181ded4930842b46e9507372f0b1b963James Dong if (omxRes != OMX_Sts_NoErr) 6810c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 6820c1bc742181ded4930842b46e9507372f0b1b963James Dong } 6830c1bc742181ded4930842b46e9507372f0b1b963James Dong } 6840c1bc742181ded4930842b46e9507372f0b1b963James Dong 6850c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_OK); 6860c1bc742181ded4930842b46e9507372f0b1b963James Dong 6870c1bc742181ded4930842b46e9507372f0b1b963James Dong} 6880c1bc742181ded4930842b46e9507372f0b1b963James Dong 6890c1bc742181ded4930842b46e9507372f0b1b963James Dong#else 6900c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 6910c1bc742181ded4930842b46e9507372f0b1b963James Dong 6920c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: DecodeResidual 6930c1bc742181ded4930842b46e9507372f0b1b963James Dong 6940c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 6950c1bc742181ded4930842b46e9507372f0b1b963James Dong Parse residual information from bit stream and store in 'pResidual'. 6960c1bc742181ded4930842b46e9507372f0b1b963James Dong 6970c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 6980c1bc742181ded4930842b46e9507372f0b1b963James Dong 6990c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 DecodeResidual(strmData_t *pStrmData, residual_t *pResidual, 7000c1bc742181ded4930842b46e9507372f0b1b963James Dong mbStorage_t *pMb, mbType_e mbType, u32 codedBlockPattern) 7010c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 7020c1bc742181ded4930842b46e9507372f0b1b963James Dong 7030c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 7040c1bc742181ded4930842b46e9507372f0b1b963James Dong 7050c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 i, j, tmp; 7060c1bc742181ded4930842b46e9507372f0b1b963James Dong i32 nc; 7070c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 blockCoded; 7080c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 blockIndex; 7090c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 is16x16; 7100c1bc742181ded4930842b46e9507372f0b1b963James Dong i32 (*level)[16]; 7110c1bc742181ded4930842b46e9507372f0b1b963James Dong 7120c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 7130c1bc742181ded4930842b46e9507372f0b1b963James Dong 7140c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pStrmData); 7150c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pResidual); 7160c1bc742181ded4930842b46e9507372f0b1b963James Dong 7170c1bc742181ded4930842b46e9507372f0b1b963James Dong level = pResidual->level; 7180c1bc742181ded4930842b46e9507372f0b1b963James Dong 7190c1bc742181ded4930842b46e9507372f0b1b963James Dong /* luma DC is at index 24 */ 7200c1bc742181ded4930842b46e9507372f0b1b963James Dong if (h264bsdMbPartPredMode(mbType) == PRED_MODE_INTRA16x16) 7210c1bc742181ded4930842b46e9507372f0b1b963James Dong { 7220c1bc742181ded4930842b46e9507372f0b1b963James Dong nc = (i32)DetermineNc(pMb, 0, pResidual->totalCoeff); 7230c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeResidualBlockCavlc(pStrmData, level[24], nc, 16); 7240c1bc742181ded4930842b46e9507372f0b1b963James Dong if ((tmp & 0xF) != HANTRO_OK) 7250c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 7260c1bc742181ded4930842b46e9507372f0b1b963James Dong pResidual->totalCoeff[24] = (tmp >> 4) & 0xFF; 7270c1bc742181ded4930842b46e9507372f0b1b963James Dong is16x16 = HANTRO_TRUE; 7280c1bc742181ded4930842b46e9507372f0b1b963James Dong } 7290c1bc742181ded4930842b46e9507372f0b1b963James Dong else 7300c1bc742181ded4930842b46e9507372f0b1b963James Dong is16x16 = HANTRO_FALSE; 7310c1bc742181ded4930842b46e9507372f0b1b963James Dong 7320c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 4, blockIndex = 0; i--;) 7330c1bc742181ded4930842b46e9507372f0b1b963James Dong { 7340c1bc742181ded4930842b46e9507372f0b1b963James Dong /* luma cbp in bits 0-3 */ 7350c1bc742181ded4930842b46e9507372f0b1b963James Dong blockCoded = codedBlockPattern & 0x1; 7360c1bc742181ded4930842b46e9507372f0b1b963James Dong codedBlockPattern >>= 1; 7370c1bc742181ded4930842b46e9507372f0b1b963James Dong if (blockCoded) 7380c1bc742181ded4930842b46e9507372f0b1b963James Dong { 7390c1bc742181ded4930842b46e9507372f0b1b963James Dong for (j = 4; j--; blockIndex++) 7400c1bc742181ded4930842b46e9507372f0b1b963James Dong { 7410c1bc742181ded4930842b46e9507372f0b1b963James Dong nc = (i32)DetermineNc(pMb, blockIndex, pResidual->totalCoeff); 7420c1bc742181ded4930842b46e9507372f0b1b963James Dong if (is16x16) 7430c1bc742181ded4930842b46e9507372f0b1b963James Dong { 7440c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeResidualBlockCavlc(pStrmData, 7450c1bc742181ded4930842b46e9507372f0b1b963James Dong level[blockIndex] + 1, nc, 15); 7460c1bc742181ded4930842b46e9507372f0b1b963James Dong pResidual->coeffMap[blockIndex] = tmp >> 15; 7470c1bc742181ded4930842b46e9507372f0b1b963James Dong } 7480c1bc742181ded4930842b46e9507372f0b1b963James Dong else 7490c1bc742181ded4930842b46e9507372f0b1b963James Dong { 7500c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeResidualBlockCavlc(pStrmData, 7510c1bc742181ded4930842b46e9507372f0b1b963James Dong level[blockIndex], nc, 16); 7520c1bc742181ded4930842b46e9507372f0b1b963James Dong pResidual->coeffMap[blockIndex] = tmp >> 16; 7530c1bc742181ded4930842b46e9507372f0b1b963James Dong } 7540c1bc742181ded4930842b46e9507372f0b1b963James Dong if ((tmp & 0xF) != HANTRO_OK) 7550c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 7560c1bc742181ded4930842b46e9507372f0b1b963James Dong pResidual->totalCoeff[blockIndex] = (tmp >> 4) & 0xFF; 7570c1bc742181ded4930842b46e9507372f0b1b963James Dong } 7580c1bc742181ded4930842b46e9507372f0b1b963James Dong } 7590c1bc742181ded4930842b46e9507372f0b1b963James Dong else 7600c1bc742181ded4930842b46e9507372f0b1b963James Dong blockIndex += 4; 7610c1bc742181ded4930842b46e9507372f0b1b963James Dong } 7620c1bc742181ded4930842b46e9507372f0b1b963James Dong 7630c1bc742181ded4930842b46e9507372f0b1b963James Dong /* chroma DC block are at indices 25 and 26 */ 7640c1bc742181ded4930842b46e9507372f0b1b963James Dong blockCoded = codedBlockPattern & 0x3; 7650c1bc742181ded4930842b46e9507372f0b1b963James Dong if (blockCoded) 7660c1bc742181ded4930842b46e9507372f0b1b963James Dong { 7670c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeResidualBlockCavlc(pStrmData, level[25], -1, 4); 7680c1bc742181ded4930842b46e9507372f0b1b963James Dong if ((tmp & 0xF) != HANTRO_OK) 7690c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 7700c1bc742181ded4930842b46e9507372f0b1b963James Dong pResidual->totalCoeff[25] = (tmp >> 4) & 0xFF; 7710c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeResidualBlockCavlc(pStrmData, level[25]+4, -1, 4); 7720c1bc742181ded4930842b46e9507372f0b1b963James Dong if ((tmp & 0xF) != HANTRO_OK) 7730c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 7740c1bc742181ded4930842b46e9507372f0b1b963James Dong pResidual->totalCoeff[26] = (tmp >> 4) & 0xFF; 7750c1bc742181ded4930842b46e9507372f0b1b963James Dong } 7760c1bc742181ded4930842b46e9507372f0b1b963James Dong 7770c1bc742181ded4930842b46e9507372f0b1b963James Dong /* chroma AC */ 7780c1bc742181ded4930842b46e9507372f0b1b963James Dong blockCoded = codedBlockPattern & 0x2; 7790c1bc742181ded4930842b46e9507372f0b1b963James Dong if (blockCoded) 7800c1bc742181ded4930842b46e9507372f0b1b963James Dong { 7810c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 8; i--;blockIndex++) 7820c1bc742181ded4930842b46e9507372f0b1b963James Dong { 7830c1bc742181ded4930842b46e9507372f0b1b963James Dong nc = (i32)DetermineNc(pMb, blockIndex, pResidual->totalCoeff); 7840c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdDecodeResidualBlockCavlc(pStrmData, 7850c1bc742181ded4930842b46e9507372f0b1b963James Dong level[blockIndex] + 1, nc, 15); 7860c1bc742181ded4930842b46e9507372f0b1b963James Dong if ((tmp & 0xF) != HANTRO_OK) 7870c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp); 7880c1bc742181ded4930842b46e9507372f0b1b963James Dong pResidual->totalCoeff[blockIndex] = (tmp >> 4) & 0xFF; 7890c1bc742181ded4930842b46e9507372f0b1b963James Dong pResidual->coeffMap[blockIndex] = (tmp >> 15); 7900c1bc742181ded4930842b46e9507372f0b1b963James Dong } 7910c1bc742181ded4930842b46e9507372f0b1b963James Dong } 7920c1bc742181ded4930842b46e9507372f0b1b963James Dong 7930c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_OK); 7940c1bc742181ded4930842b46e9507372f0b1b963James Dong 7950c1bc742181ded4930842b46e9507372f0b1b963James Dong} 7960c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif 7970c1bc742181ded4930842b46e9507372f0b1b963James Dong 7980c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 7990c1bc742181ded4930842b46e9507372f0b1b963James Dong 8000c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: DetermineNc 8010c1bc742181ded4930842b46e9507372f0b1b963James Dong 8020c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 8030c1bc742181ded4930842b46e9507372f0b1b963James Dong Returns the nC of a block. 8040c1bc742181ded4930842b46e9507372f0b1b963James Dong 8050c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 8060c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_OMXDL 8070c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 DetermineNc(mbStorage_t *pMb, u32 blockIndex, u8 *pTotalCoeff) 8080c1bc742181ded4930842b46e9507372f0b1b963James Dong#else 8090c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 DetermineNc(mbStorage_t *pMb, u32 blockIndex, i16 *pTotalCoeff) 8100c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif 8110c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 8120c1bc742181ded4930842b46e9507372f0b1b963James Dong/*lint -e702 */ 8130c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 8140c1bc742181ded4930842b46e9507372f0b1b963James Dong 8150c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 tmp; 8160c1bc742181ded4930842b46e9507372f0b1b963James Dong i32 n; 8170c1bc742181ded4930842b46e9507372f0b1b963James Dong const neighbour_t *neighbourA, *neighbourB; 8180c1bc742181ded4930842b46e9507372f0b1b963James Dong u8 neighbourAindex, neighbourBindex; 8190c1bc742181ded4930842b46e9507372f0b1b963James Dong 8200c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 8210c1bc742181ded4930842b46e9507372f0b1b963James Dong 8220c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(blockIndex < 24); 8230c1bc742181ded4930842b46e9507372f0b1b963James Dong 8240c1bc742181ded4930842b46e9507372f0b1b963James Dong /* if neighbour block belongs to current macroblock totalCoeff array 8250c1bc742181ded4930842b46e9507372f0b1b963James Dong * mbStorage has not been set/updated yet -> use pTotalCoeff */ 8260c1bc742181ded4930842b46e9507372f0b1b963James Dong neighbourA = h264bsdNeighbour4x4BlockA(blockIndex); 8270c1bc742181ded4930842b46e9507372f0b1b963James Dong neighbourB = h264bsdNeighbour4x4BlockB(blockIndex); 8280c1bc742181ded4930842b46e9507372f0b1b963James Dong neighbourAindex = neighbourA->index; 8290c1bc742181ded4930842b46e9507372f0b1b963James Dong neighbourBindex = neighbourB->index; 8300c1bc742181ded4930842b46e9507372f0b1b963James Dong if (neighbourA->mb == MB_CURR && neighbourB->mb == MB_CURR) 8310c1bc742181ded4930842b46e9507372f0b1b963James Dong { 8320c1bc742181ded4930842b46e9507372f0b1b963James Dong n = (pTotalCoeff[neighbourAindex] + 8330c1bc742181ded4930842b46e9507372f0b1b963James Dong pTotalCoeff[neighbourBindex] + 1)>>1; 8340c1bc742181ded4930842b46e9507372f0b1b963James Dong } 8350c1bc742181ded4930842b46e9507372f0b1b963James Dong else if (neighbourA->mb == MB_CURR) 8360c1bc742181ded4930842b46e9507372f0b1b963James Dong { 8370c1bc742181ded4930842b46e9507372f0b1b963James Dong n = pTotalCoeff[neighbourAindex]; 8380c1bc742181ded4930842b46e9507372f0b1b963James Dong if (h264bsdIsNeighbourAvailable(pMb, pMb->mbB)) 8390c1bc742181ded4930842b46e9507372f0b1b963James Dong { 8400c1bc742181ded4930842b46e9507372f0b1b963James Dong n = (n + pMb->mbB->totalCoeff[neighbourBindex] + 1) >> 1; 8410c1bc742181ded4930842b46e9507372f0b1b963James Dong } 8420c1bc742181ded4930842b46e9507372f0b1b963James Dong } 8430c1bc742181ded4930842b46e9507372f0b1b963James Dong else if (neighbourB->mb == MB_CURR) 8440c1bc742181ded4930842b46e9507372f0b1b963James Dong { 8450c1bc742181ded4930842b46e9507372f0b1b963James Dong n = pTotalCoeff[neighbourBindex]; 8460c1bc742181ded4930842b46e9507372f0b1b963James Dong if (h264bsdIsNeighbourAvailable(pMb, pMb->mbA)) 8470c1bc742181ded4930842b46e9507372f0b1b963James Dong { 8480c1bc742181ded4930842b46e9507372f0b1b963James Dong n = (n + pMb->mbA->totalCoeff[neighbourAindex] + 1) >> 1; 8490c1bc742181ded4930842b46e9507372f0b1b963James Dong } 8500c1bc742181ded4930842b46e9507372f0b1b963James Dong } 8510c1bc742181ded4930842b46e9507372f0b1b963James Dong else 8520c1bc742181ded4930842b46e9507372f0b1b963James Dong { 8530c1bc742181ded4930842b46e9507372f0b1b963James Dong n = tmp = 0; 8540c1bc742181ded4930842b46e9507372f0b1b963James Dong if (h264bsdIsNeighbourAvailable(pMb, pMb->mbA)) 8550c1bc742181ded4930842b46e9507372f0b1b963James Dong { 8560c1bc742181ded4930842b46e9507372f0b1b963James Dong n = pMb->mbA->totalCoeff[neighbourAindex]; 8570c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = 1; 8580c1bc742181ded4930842b46e9507372f0b1b963James Dong } 8590c1bc742181ded4930842b46e9507372f0b1b963James Dong if (h264bsdIsNeighbourAvailable(pMb, pMb->mbB)) 8600c1bc742181ded4930842b46e9507372f0b1b963James Dong { 8610c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp) 8620c1bc742181ded4930842b46e9507372f0b1b963James Dong n = (n + pMb->mbB->totalCoeff[neighbourBindex] + 1) >> 1; 8630c1bc742181ded4930842b46e9507372f0b1b963James Dong else 8640c1bc742181ded4930842b46e9507372f0b1b963James Dong n = pMb->mbB->totalCoeff[neighbourBindex]; 8650c1bc742181ded4930842b46e9507372f0b1b963James Dong } 8660c1bc742181ded4930842b46e9507372f0b1b963James Dong } 8670c1bc742181ded4930842b46e9507372f0b1b963James Dong return((u32)n); 8680c1bc742181ded4930842b46e9507372f0b1b963James Dong/*lint +e702 */ 8690c1bc742181ded4930842b46e9507372f0b1b963James Dong} 8700c1bc742181ded4930842b46e9507372f0b1b963James Dong 8710c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 8720c1bc742181ded4930842b46e9507372f0b1b963James Dong 8730c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: CbpIntra16x16 8740c1bc742181ded4930842b46e9507372f0b1b963James Dong 8750c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 8760c1bc742181ded4930842b46e9507372f0b1b963James Dong Returns the coded block pattern for intra 16x16 macroblock. 8770c1bc742181ded4930842b46e9507372f0b1b963James Dong 8780c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 8790c1bc742181ded4930842b46e9507372f0b1b963James Dong 8800c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 CbpIntra16x16(mbType_e mbType) 8810c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 8820c1bc742181ded4930842b46e9507372f0b1b963James Dong 8830c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 8840c1bc742181ded4930842b46e9507372f0b1b963James Dong 8850c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 cbp; 8860c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 tmp; 8870c1bc742181ded4930842b46e9507372f0b1b963James Dong 8880c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 8890c1bc742181ded4930842b46e9507372f0b1b963James Dong 8900c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(mbType >= I_16x16_0_0_0 && mbType <= I_16x16_3_2_1); 8910c1bc742181ded4930842b46e9507372f0b1b963James Dong 8920c1bc742181ded4930842b46e9507372f0b1b963James Dong if (mbType >= I_16x16_0_0_1) 8930c1bc742181ded4930842b46e9507372f0b1b963James Dong cbp = 15; 8940c1bc742181ded4930842b46e9507372f0b1b963James Dong else 8950c1bc742181ded4930842b46e9507372f0b1b963James Dong cbp = 0; 8960c1bc742181ded4930842b46e9507372f0b1b963James Dong 8970c1bc742181ded4930842b46e9507372f0b1b963James Dong /* tmp is 0 for I_16x16_0_0_0 mb type */ 8980c1bc742181ded4930842b46e9507372f0b1b963James Dong /* ignore lint warning on arithmetic on enum's */ 8990c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = /*lint -e(656)*/(mbType - I_16x16_0_0_0) >> 2; 9000c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp > 2) 9010c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp -= 3; 9020c1bc742181ded4930842b46e9507372f0b1b963James Dong 9030c1bc742181ded4930842b46e9507372f0b1b963James Dong cbp += tmp << 4; 9040c1bc742181ded4930842b46e9507372f0b1b963James Dong 9050c1bc742181ded4930842b46e9507372f0b1b963James Dong return(cbp); 9060c1bc742181ded4930842b46e9507372f0b1b963James Dong 9070c1bc742181ded4930842b46e9507372f0b1b963James Dong} 9080c1bc742181ded4930842b46e9507372f0b1b963James Dong 9090c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 9100c1bc742181ded4930842b46e9507372f0b1b963James Dong 9110c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: h264bsdPredModeIntra16x16 9120c1bc742181ded4930842b46e9507372f0b1b963James Dong 9130c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 9140c1bc742181ded4930842b46e9507372f0b1b963James Dong Returns the prediction mode for intra 16x16 macroblock. 9150c1bc742181ded4930842b46e9507372f0b1b963James Dong 9160c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 9170c1bc742181ded4930842b46e9507372f0b1b963James Dong 9180c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdPredModeIntra16x16(mbType_e mbType) 9190c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 9200c1bc742181ded4930842b46e9507372f0b1b963James Dong 9210c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 9220c1bc742181ded4930842b46e9507372f0b1b963James Dong 9230c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 tmp; 9240c1bc742181ded4930842b46e9507372f0b1b963James Dong 9250c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 9260c1bc742181ded4930842b46e9507372f0b1b963James Dong 9270c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(mbType >= I_16x16_0_0_0 && mbType <= I_16x16_3_2_1); 9280c1bc742181ded4930842b46e9507372f0b1b963James Dong 9290c1bc742181ded4930842b46e9507372f0b1b963James Dong /* tmp is 0 for I_16x16_0_0_0 mb type */ 9300c1bc742181ded4930842b46e9507372f0b1b963James Dong /* ignore lint warning on arithmetic on enum's */ 9310c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = /*lint -e(656)*/(mbType - I_16x16_0_0_0); 9320c1bc742181ded4930842b46e9507372f0b1b963James Dong 9330c1bc742181ded4930842b46e9507372f0b1b963James Dong return(tmp & 0x3); 9340c1bc742181ded4930842b46e9507372f0b1b963James Dong 9350c1bc742181ded4930842b46e9507372f0b1b963James Dong} 9360c1bc742181ded4930842b46e9507372f0b1b963James Dong 9370c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 9380c1bc742181ded4930842b46e9507372f0b1b963James Dong 9390c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: h264bsdDecodeMacroblock 9400c1bc742181ded4930842b46e9507372f0b1b963James Dong 9410c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 9420c1bc742181ded4930842b46e9507372f0b1b963James Dong Decode one macroblock and write into output image. 9430c1bc742181ded4930842b46e9507372f0b1b963James Dong 9440c1bc742181ded4930842b46e9507372f0b1b963James Dong Inputs: 9450c1bc742181ded4930842b46e9507372f0b1b963James Dong pMb pointer to macroblock specific information 9460c1bc742181ded4930842b46e9507372f0b1b963James Dong mbLayer pointer to current macroblock data from stream 9470c1bc742181ded4930842b46e9507372f0b1b963James Dong currImage pointer to output image 9480c1bc742181ded4930842b46e9507372f0b1b963James Dong dpb pointer to decoded picture buffer 9490c1bc742181ded4930842b46e9507372f0b1b963James Dong qpY pointer to slice QP 9500c1bc742181ded4930842b46e9507372f0b1b963James Dong mbNum current macroblock number 9510c1bc742181ded4930842b46e9507372f0b1b963James Dong constrainedIntraPred flag specifying if neighbouring inter 9520c1bc742181ded4930842b46e9507372f0b1b963James Dong macroblocks are used in intra prediction 9530c1bc742181ded4930842b46e9507372f0b1b963James Dong 9540c1bc742181ded4930842b46e9507372f0b1b963James Dong Outputs: 9550c1bc742181ded4930842b46e9507372f0b1b963James Dong pMb structure is updated with current macroblock 9560c1bc742181ded4930842b46e9507372f0b1b963James Dong currImage decoded macroblock is written into output image 9570c1bc742181ded4930842b46e9507372f0b1b963James Dong 9580c1bc742181ded4930842b46e9507372f0b1b963James Dong Returns: 9590c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_OK success 9600c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_NOK error in macroblock decoding 9610c1bc742181ded4930842b46e9507372f0b1b963James Dong 9620c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 9630c1bc742181ded4930842b46e9507372f0b1b963James Dong 9640c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdDecodeMacroblock(mbStorage_t *pMb, macroblockLayer_t *pMbLayer, 9650c1bc742181ded4930842b46e9507372f0b1b963James Dong image_t *currImage, dpbStorage_t *dpb, i32 *qpY, u32 mbNum, 9660c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 constrainedIntraPredFlag, u8* data) 9670c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 9680c1bc742181ded4930842b46e9507372f0b1b963James Dong 9690c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 9700c1bc742181ded4930842b46e9507372f0b1b963James Dong 9710c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 i, tmp; 9720c1bc742181ded4930842b46e9507372f0b1b963James Dong mbType_e mbType; 9730c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_OMXDL 9740c1bc742181ded4930842b46e9507372f0b1b963James Dong const u8 *pSrc; 9750c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif 9760c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 9770c1bc742181ded4930842b46e9507372f0b1b963James Dong 9780c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pMb); 9790c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pMbLayer); 9800c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(currImage); 9810c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(qpY && *qpY < 52); 9820c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(mbNum < currImage->width*currImage->height); 9830c1bc742181ded4930842b46e9507372f0b1b963James Dong 9840c1bc742181ded4930842b46e9507372f0b1b963James Dong mbType = pMbLayer->mbType; 9850c1bc742181ded4930842b46e9507372f0b1b963James Dong pMb->mbType = mbType; 9860c1bc742181ded4930842b46e9507372f0b1b963James Dong 9870c1bc742181ded4930842b46e9507372f0b1b963James Dong pMb->decoded++; 9880c1bc742181ded4930842b46e9507372f0b1b963James Dong 9890c1bc742181ded4930842b46e9507372f0b1b963James Dong h264bsdSetCurrImageMbPointers(currImage, mbNum); 9900c1bc742181ded4930842b46e9507372f0b1b963James Dong 9910c1bc742181ded4930842b46e9507372f0b1b963James Dong if (mbType == I_PCM) 9920c1bc742181ded4930842b46e9507372f0b1b963James Dong { 9930c1bc742181ded4930842b46e9507372f0b1b963James Dong u8 *pData = (u8*)data; 9940c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_OMXDL 9950c1bc742181ded4930842b46e9507372f0b1b963James Dong u8 *tot = pMb->totalCoeff; 9960c1bc742181ded4930842b46e9507372f0b1b963James Dong#else 9970c1bc742181ded4930842b46e9507372f0b1b963James Dong i16 *tot = pMb->totalCoeff; 9980c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif 9990c1bc742181ded4930842b46e9507372f0b1b963James Dong i32 *lev = pMbLayer->residual.level[0]; 10000c1bc742181ded4930842b46e9507372f0b1b963James Dong 10010c1bc742181ded4930842b46e9507372f0b1b963James Dong pMb->qpY = 0; 10020c1bc742181ded4930842b46e9507372f0b1b963James Dong 10030c1bc742181ded4930842b46e9507372f0b1b963James Dong /* if decoded flag > 1 -> mb has already been successfully decoded and 10040c1bc742181ded4930842b46e9507372f0b1b963James Dong * written to output -> do not write again */ 10050c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pMb->decoded > 1) 10060c1bc742181ded4930842b46e9507372f0b1b963James Dong { 10070c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 24; i--;) 10080c1bc742181ded4930842b46e9507372f0b1b963James Dong *tot++ = 16; 10090c1bc742181ded4930842b46e9507372f0b1b963James Dong return HANTRO_OK; 10100c1bc742181ded4930842b46e9507372f0b1b963James Dong } 10110c1bc742181ded4930842b46e9507372f0b1b963James Dong 10120c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 24; i--;) 10130c1bc742181ded4930842b46e9507372f0b1b963James Dong { 10140c1bc742181ded4930842b46e9507372f0b1b963James Dong *tot++ = 16; 10150c1bc742181ded4930842b46e9507372f0b1b963James Dong for (tmp = 16; tmp--;) 10160c1bc742181ded4930842b46e9507372f0b1b963James Dong *pData++ = (u8)(*lev++); 10170c1bc742181ded4930842b46e9507372f0b1b963James Dong } 10180c1bc742181ded4930842b46e9507372f0b1b963James Dong h264bsdWriteMacroblock(currImage, (u8*)data); 10190c1bc742181ded4930842b46e9507372f0b1b963James Dong 10200c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_OK); 10210c1bc742181ded4930842b46e9507372f0b1b963James Dong } 10220c1bc742181ded4930842b46e9507372f0b1b963James Dong else 10230c1bc742181ded4930842b46e9507372f0b1b963James Dong { 10240c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_OMXDL 10250c1bc742181ded4930842b46e9507372f0b1b963James Dong if (h264bsdMbPartPredMode(mbType) == PRED_MODE_INTER) 10260c1bc742181ded4930842b46e9507372f0b1b963James Dong { 10270c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdInterPrediction(pMb, pMbLayer, dpb, mbNum, 10280c1bc742181ded4930842b46e9507372f0b1b963James Dong currImage, (u8*)data); 10290c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) return (tmp); 10300c1bc742181ded4930842b46e9507372f0b1b963James Dong } 10310c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif 10320c1bc742181ded4930842b46e9507372f0b1b963James Dong if (mbType != P_Skip) 10330c1bc742181ded4930842b46e9507372f0b1b963James Dong { 10340c1bc742181ded4930842b46e9507372f0b1b963James Dong H264SwDecMemcpy(pMb->totalCoeff, 10350c1bc742181ded4930842b46e9507372f0b1b963James Dong pMbLayer->residual.totalCoeff, 10360c1bc742181ded4930842b46e9507372f0b1b963James Dong 27*sizeof(*pMb->totalCoeff)); 10370c1bc742181ded4930842b46e9507372f0b1b963James Dong 10380c1bc742181ded4930842b46e9507372f0b1b963James Dong /* update qpY */ 10390c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pMbLayer->mbQpDelta) 10400c1bc742181ded4930842b46e9507372f0b1b963James Dong { 10410c1bc742181ded4930842b46e9507372f0b1b963James Dong *qpY = *qpY + pMbLayer->mbQpDelta; 10420c1bc742181ded4930842b46e9507372f0b1b963James Dong if (*qpY < 0) *qpY += 52; 10430c1bc742181ded4930842b46e9507372f0b1b963James Dong else if (*qpY >= 52) *qpY -= 52; 10440c1bc742181ded4930842b46e9507372f0b1b963James Dong } 10450c1bc742181ded4930842b46e9507372f0b1b963James Dong pMb->qpY = (u32)*qpY; 10460c1bc742181ded4930842b46e9507372f0b1b963James Dong 10470c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_OMXDL 10480c1bc742181ded4930842b46e9507372f0b1b963James Dong pSrc = pMbLayer->residual.posCoefBuf; 10490c1bc742181ded4930842b46e9507372f0b1b963James Dong 10500c1bc742181ded4930842b46e9507372f0b1b963James Dong if (h264bsdMbPartPredMode(mbType) == PRED_MODE_INTER) 10510c1bc742181ded4930842b46e9507372f0b1b963James Dong { 10520c1bc742181ded4930842b46e9507372f0b1b963James Dong OMXResult res; 10530c1bc742181ded4930842b46e9507372f0b1b963James Dong u8 *p; 10540c1bc742181ded4930842b46e9507372f0b1b963James Dong u8 *totalCoeff = pMb->totalCoeff; 10550c1bc742181ded4930842b46e9507372f0b1b963James Dong 10560c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 0; i < 16; i++, totalCoeff++) 10570c1bc742181ded4930842b46e9507372f0b1b963James Dong { 10580c1bc742181ded4930842b46e9507372f0b1b963James Dong p = data + lumaIndex[i]; 10590c1bc742181ded4930842b46e9507372f0b1b963James Dong if (*totalCoeff) 10600c1bc742181ded4930842b46e9507372f0b1b963James Dong { 10610c1bc742181ded4930842b46e9507372f0b1b963James Dong res = omxVCM4P10_DequantTransformResidualFromPairAndAdd( 10620c1bc742181ded4930842b46e9507372f0b1b963James Dong &pSrc, p, 0, p, 16, 16, *qpY, *totalCoeff); 10630c1bc742181ded4930842b46e9507372f0b1b963James Dong if (res != OMX_Sts_NoErr) 10640c1bc742181ded4930842b46e9507372f0b1b963James Dong return (HANTRO_NOK); 10650c1bc742181ded4930842b46e9507372f0b1b963James Dong } 10660c1bc742181ded4930842b46e9507372f0b1b963James Dong } 10670c1bc742181ded4930842b46e9507372f0b1b963James Dong 10680c1bc742181ded4930842b46e9507372f0b1b963James Dong } 10690c1bc742181ded4930842b46e9507372f0b1b963James Dong else if (h264bsdMbPartPredMode(mbType) == PRED_MODE_INTRA4x4) 10700c1bc742181ded4930842b46e9507372f0b1b963James Dong { 10710c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = ProcessIntra4x4Residual(pMb, 10720c1bc742181ded4930842b46e9507372f0b1b963James Dong data, 10730c1bc742181ded4930842b46e9507372f0b1b963James Dong constrainedIntraPredFlag, 10740c1bc742181ded4930842b46e9507372f0b1b963James Dong pMbLayer, 10750c1bc742181ded4930842b46e9507372f0b1b963James Dong &pSrc, 10760c1bc742181ded4930842b46e9507372f0b1b963James Dong currImage); 10770c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 10780c1bc742181ded4930842b46e9507372f0b1b963James Dong return (tmp); 10790c1bc742181ded4930842b46e9507372f0b1b963James Dong } 10800c1bc742181ded4930842b46e9507372f0b1b963James Dong else if (h264bsdMbPartPredMode(mbType) == PRED_MODE_INTRA16x16) 10810c1bc742181ded4930842b46e9507372f0b1b963James Dong { 10820c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = ProcessIntra16x16Residual(pMb, 10830c1bc742181ded4930842b46e9507372f0b1b963James Dong data, 10840c1bc742181ded4930842b46e9507372f0b1b963James Dong constrainedIntraPredFlag, 10850c1bc742181ded4930842b46e9507372f0b1b963James Dong pMbLayer->mbPred.intraChromaPredMode, 10860c1bc742181ded4930842b46e9507372f0b1b963James Dong &pSrc, 10870c1bc742181ded4930842b46e9507372f0b1b963James Dong currImage); 10880c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 10890c1bc742181ded4930842b46e9507372f0b1b963James Dong return (tmp); 10900c1bc742181ded4930842b46e9507372f0b1b963James Dong } 10910c1bc742181ded4930842b46e9507372f0b1b963James Dong 10920c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = ProcessChromaResidual(pMb, data, &pSrc); 10930c1bc742181ded4930842b46e9507372f0b1b963James Dong 10940c1bc742181ded4930842b46e9507372f0b1b963James Dong#else 10950c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = ProcessResidual(pMb, pMbLayer->residual.level, 10960c1bc742181ded4930842b46e9507372f0b1b963James Dong pMbLayer->residual.coeffMap); 10970c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif 10980c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) 10990c1bc742181ded4930842b46e9507372f0b1b963James Dong return (tmp); 11000c1bc742181ded4930842b46e9507372f0b1b963James Dong } 11010c1bc742181ded4930842b46e9507372f0b1b963James Dong else 11020c1bc742181ded4930842b46e9507372f0b1b963James Dong { 11030c1bc742181ded4930842b46e9507372f0b1b963James Dong H264SwDecMemset(pMb->totalCoeff, 0, 27*sizeof(*pMb->totalCoeff)); 11040c1bc742181ded4930842b46e9507372f0b1b963James Dong pMb->qpY = (u32)*qpY; 11050c1bc742181ded4930842b46e9507372f0b1b963James Dong } 11060c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_OMXDL 11070c1bc742181ded4930842b46e9507372f0b1b963James Dong /* if decoded flag > 1 -> mb has already been successfully decoded and 11080c1bc742181ded4930842b46e9507372f0b1b963James Dong * written to output -> do not write again */ 11090c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pMb->decoded > 1) 11100c1bc742181ded4930842b46e9507372f0b1b963James Dong return HANTRO_OK; 11110c1bc742181ded4930842b46e9507372f0b1b963James Dong 11120c1bc742181ded4930842b46e9507372f0b1b963James Dong h264bsdWriteMacroblock(currImage, data); 11130c1bc742181ded4930842b46e9507372f0b1b963James Dong#else 11140c1bc742181ded4930842b46e9507372f0b1b963James Dong if (h264bsdMbPartPredMode(mbType) != PRED_MODE_INTER) 11150c1bc742181ded4930842b46e9507372f0b1b963James Dong { 11160c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdIntraPrediction(pMb, pMbLayer, currImage, mbNum, 11170c1bc742181ded4930842b46e9507372f0b1b963James Dong constrainedIntraPredFlag, (u8*)data); 11180c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) return (tmp); 11190c1bc742181ded4930842b46e9507372f0b1b963James Dong } 11200c1bc742181ded4930842b46e9507372f0b1b963James Dong else 11210c1bc742181ded4930842b46e9507372f0b1b963James Dong { 11220c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = h264bsdInterPrediction(pMb, pMbLayer, dpb, mbNum, 11230c1bc742181ded4930842b46e9507372f0b1b963James Dong currImage, (u8*)data); 11240c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp != HANTRO_OK) return (tmp); 11250c1bc742181ded4930842b46e9507372f0b1b963James Dong } 11260c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif 11270c1bc742181ded4930842b46e9507372f0b1b963James Dong } 11280c1bc742181ded4930842b46e9507372f0b1b963James Dong 11290c1bc742181ded4930842b46e9507372f0b1b963James Dong return HANTRO_OK; 11300c1bc742181ded4930842b46e9507372f0b1b963James Dong} 11310c1bc742181ded4930842b46e9507372f0b1b963James Dong 11320c1bc742181ded4930842b46e9507372f0b1b963James Dong 11330c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_OMXDL 11340c1bc742181ded4930842b46e9507372f0b1b963James Dong 11350c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 11360c1bc742181ded4930842b46e9507372f0b1b963James Dong 11370c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: ProcessChromaResidual 11380c1bc742181ded4930842b46e9507372f0b1b963James Dong 11390c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 11400c1bc742181ded4930842b46e9507372f0b1b963James Dong Process the residual data of chroma with 11410c1bc742181ded4930842b46e9507372f0b1b963James Dong inverse quantization and inverse transform. 11420c1bc742181ded4930842b46e9507372f0b1b963James Dong 11430c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 11440c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 ProcessChromaResidual(mbStorage_t *pMb, u8 *data, const u8 **pSrc ) 11450c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 11460c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 i; 11470c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 chromaQp; 11480c1bc742181ded4930842b46e9507372f0b1b963James Dong i16 *pDc; 11490c1bc742181ded4930842b46e9507372f0b1b963James Dong i16 dc[4 + 4] = {0,0,0,0,0,0,0,0}; 11500c1bc742181ded4930842b46e9507372f0b1b963James Dong u8 *totalCoeff; 11510c1bc742181ded4930842b46e9507372f0b1b963James Dong OMXResult result; 11520c1bc742181ded4930842b46e9507372f0b1b963James Dong u8 *p; 11530c1bc742181ded4930842b46e9507372f0b1b963James Dong 11540c1bc742181ded4930842b46e9507372f0b1b963James Dong /* chroma DC processing. First chroma dc block is block with index 25 */ 11550c1bc742181ded4930842b46e9507372f0b1b963James Dong chromaQp = 11560c1bc742181ded4930842b46e9507372f0b1b963James Dong h264bsdQpC[CLIP3(0, 51, (i32)pMb->qpY + pMb->chromaQpIndexOffset)]; 11570c1bc742181ded4930842b46e9507372f0b1b963James Dong 11580c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pMb->totalCoeff[25]) 11590c1bc742181ded4930842b46e9507372f0b1b963James Dong { 11600c1bc742181ded4930842b46e9507372f0b1b963James Dong pDc = dc; 11610c1bc742181ded4930842b46e9507372f0b1b963James Dong result = omxVCM4P10_TransformDequantChromaDCFromPair( 11620c1bc742181ded4930842b46e9507372f0b1b963James Dong pSrc, 11630c1bc742181ded4930842b46e9507372f0b1b963James Dong pDc, 11640c1bc742181ded4930842b46e9507372f0b1b963James Dong (i32)chromaQp); 11650c1bc742181ded4930842b46e9507372f0b1b963James Dong if (result != OMX_Sts_NoErr) 11660c1bc742181ded4930842b46e9507372f0b1b963James Dong return (HANTRO_NOK); 11670c1bc742181ded4930842b46e9507372f0b1b963James Dong } 11680c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pMb->totalCoeff[26]) 11690c1bc742181ded4930842b46e9507372f0b1b963James Dong { 11700c1bc742181ded4930842b46e9507372f0b1b963James Dong pDc = dc+4; 11710c1bc742181ded4930842b46e9507372f0b1b963James Dong result = omxVCM4P10_TransformDequantChromaDCFromPair( 11720c1bc742181ded4930842b46e9507372f0b1b963James Dong pSrc, 11730c1bc742181ded4930842b46e9507372f0b1b963James Dong pDc, 11740c1bc742181ded4930842b46e9507372f0b1b963James Dong (i32)chromaQp); 11750c1bc742181ded4930842b46e9507372f0b1b963James Dong if (result != OMX_Sts_NoErr) 11760c1bc742181ded4930842b46e9507372f0b1b963James Dong return (HANTRO_NOK); 11770c1bc742181ded4930842b46e9507372f0b1b963James Dong } 11780c1bc742181ded4930842b46e9507372f0b1b963James Dong 11790c1bc742181ded4930842b46e9507372f0b1b963James Dong pDc = dc; 11800c1bc742181ded4930842b46e9507372f0b1b963James Dong totalCoeff = pMb->totalCoeff + 16; 11810c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 0; i < 8; i++, pDc++, totalCoeff++) 11820c1bc742181ded4930842b46e9507372f0b1b963James Dong { 11830c1bc742181ded4930842b46e9507372f0b1b963James Dong /* chroma prediction */ 11840c1bc742181ded4930842b46e9507372f0b1b963James Dong if (*totalCoeff || *pDc) 11850c1bc742181ded4930842b46e9507372f0b1b963James Dong { 11860c1bc742181ded4930842b46e9507372f0b1b963James Dong p = data + chromaIndex[i]; 11870c1bc742181ded4930842b46e9507372f0b1b963James Dong result = omxVCM4P10_DequantTransformResidualFromPairAndAdd( 11880c1bc742181ded4930842b46e9507372f0b1b963James Dong pSrc, 11890c1bc742181ded4930842b46e9507372f0b1b963James Dong p, 11900c1bc742181ded4930842b46e9507372f0b1b963James Dong pDc, 11910c1bc742181ded4930842b46e9507372f0b1b963James Dong p, 11920c1bc742181ded4930842b46e9507372f0b1b963James Dong 8, 11930c1bc742181ded4930842b46e9507372f0b1b963James Dong 8, 11940c1bc742181ded4930842b46e9507372f0b1b963James Dong (i32)chromaQp, 11950c1bc742181ded4930842b46e9507372f0b1b963James Dong *totalCoeff); 11960c1bc742181ded4930842b46e9507372f0b1b963James Dong if (result != OMX_Sts_NoErr) 11970c1bc742181ded4930842b46e9507372f0b1b963James Dong return (HANTRO_NOK); 11980c1bc742181ded4930842b46e9507372f0b1b963James Dong } 11990c1bc742181ded4930842b46e9507372f0b1b963James Dong } 12000c1bc742181ded4930842b46e9507372f0b1b963James Dong 12010c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_OK); 12020c1bc742181ded4930842b46e9507372f0b1b963James Dong} 12030c1bc742181ded4930842b46e9507372f0b1b963James Dong 12040c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 12050c1bc742181ded4930842b46e9507372f0b1b963James Dong 12060c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: ProcessIntra16x16Residual 12070c1bc742181ded4930842b46e9507372f0b1b963James Dong 12080c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 12090c1bc742181ded4930842b46e9507372f0b1b963James Dong Process the residual data of luma with 12100c1bc742181ded4930842b46e9507372f0b1b963James Dong inverse quantization and inverse transform. 12110c1bc742181ded4930842b46e9507372f0b1b963James Dong 12120c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 12130c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 ProcessIntra16x16Residual(mbStorage_t *pMb, 12140c1bc742181ded4930842b46e9507372f0b1b963James Dong u8 *data, 12150c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 constrainedIntraPred, 12160c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 intraChromaPredMode, 12170c1bc742181ded4930842b46e9507372f0b1b963James Dong const u8** pSrc, 12180c1bc742181ded4930842b46e9507372f0b1b963James Dong image_t *image) 12190c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 12200c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 i; 12210c1bc742181ded4930842b46e9507372f0b1b963James Dong i16 *pDc; 12220c1bc742181ded4930842b46e9507372f0b1b963James Dong i16 dc[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; 12230c1bc742181ded4930842b46e9507372f0b1b963James Dong u8 *totalCoeff; 12240c1bc742181ded4930842b46e9507372f0b1b963James Dong OMXResult result; 12250c1bc742181ded4930842b46e9507372f0b1b963James Dong u8 *p; 12260c1bc742181ded4930842b46e9507372f0b1b963James Dong 12270c1bc742181ded4930842b46e9507372f0b1b963James Dong totalCoeff = pMb->totalCoeff; 12280c1bc742181ded4930842b46e9507372f0b1b963James Dong 12290c1bc742181ded4930842b46e9507372f0b1b963James Dong if (totalCoeff[24]) 12300c1bc742181ded4930842b46e9507372f0b1b963James Dong { 12310c1bc742181ded4930842b46e9507372f0b1b963James Dong pDc = dc; 12320c1bc742181ded4930842b46e9507372f0b1b963James Dong result = omxVCM4P10_TransformDequantLumaDCFromPair( 12330c1bc742181ded4930842b46e9507372f0b1b963James Dong pSrc, 12340c1bc742181ded4930842b46e9507372f0b1b963James Dong pDc, 12350c1bc742181ded4930842b46e9507372f0b1b963James Dong (i32)pMb->qpY); 12360c1bc742181ded4930842b46e9507372f0b1b963James Dong if (result != OMX_Sts_NoErr) 12370c1bc742181ded4930842b46e9507372f0b1b963James Dong return (HANTRO_NOK); 12380c1bc742181ded4930842b46e9507372f0b1b963James Dong } 12390c1bc742181ded4930842b46e9507372f0b1b963James Dong /* Intra 16x16 pred */ 12400c1bc742181ded4930842b46e9507372f0b1b963James Dong if (h264bsdIntra16x16Prediction(pMb, data, image->luma, 12410c1bc742181ded4930842b46e9507372f0b1b963James Dong image->width*16, constrainedIntraPred) != HANTRO_OK) 12420c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 12430c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 0; i < 16; i++, totalCoeff++) 12440c1bc742181ded4930842b46e9507372f0b1b963James Dong { 12450c1bc742181ded4930842b46e9507372f0b1b963James Dong p = data + lumaIndex[i]; 12460c1bc742181ded4930842b46e9507372f0b1b963James Dong pDc = &dc[dcCoeffIndex[i]]; 12470c1bc742181ded4930842b46e9507372f0b1b963James Dong if (*totalCoeff || *pDc) 12480c1bc742181ded4930842b46e9507372f0b1b963James Dong { 12490c1bc742181ded4930842b46e9507372f0b1b963James Dong result = omxVCM4P10_DequantTransformResidualFromPairAndAdd( 12500c1bc742181ded4930842b46e9507372f0b1b963James Dong pSrc, 12510c1bc742181ded4930842b46e9507372f0b1b963James Dong p, 12520c1bc742181ded4930842b46e9507372f0b1b963James Dong pDc, 12530c1bc742181ded4930842b46e9507372f0b1b963James Dong p, 12540c1bc742181ded4930842b46e9507372f0b1b963James Dong 16, 12550c1bc742181ded4930842b46e9507372f0b1b963James Dong 16, 12560c1bc742181ded4930842b46e9507372f0b1b963James Dong (i32)pMb->qpY, 12570c1bc742181ded4930842b46e9507372f0b1b963James Dong *totalCoeff); 12580c1bc742181ded4930842b46e9507372f0b1b963James Dong if (result != OMX_Sts_NoErr) 12590c1bc742181ded4930842b46e9507372f0b1b963James Dong return (HANTRO_NOK); 12600c1bc742181ded4930842b46e9507372f0b1b963James Dong } 12610c1bc742181ded4930842b46e9507372f0b1b963James Dong } 12620c1bc742181ded4930842b46e9507372f0b1b963James Dong 12630c1bc742181ded4930842b46e9507372f0b1b963James Dong if (h264bsdIntraChromaPrediction(pMb, data + 256, 12640c1bc742181ded4930842b46e9507372f0b1b963James Dong image, 12650c1bc742181ded4930842b46e9507372f0b1b963James Dong intraChromaPredMode, 12660c1bc742181ded4930842b46e9507372f0b1b963James Dong constrainedIntraPred) != HANTRO_OK) 12670c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 12680c1bc742181ded4930842b46e9507372f0b1b963James Dong 12690c1bc742181ded4930842b46e9507372f0b1b963James Dong return HANTRO_OK; 12700c1bc742181ded4930842b46e9507372f0b1b963James Dong} 12710c1bc742181ded4930842b46e9507372f0b1b963James Dong 12720c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 12730c1bc742181ded4930842b46e9507372f0b1b963James Dong 12740c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: ProcessIntra4x4Residual 12750c1bc742181ded4930842b46e9507372f0b1b963James Dong 12760c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 12770c1bc742181ded4930842b46e9507372f0b1b963James Dong Process the residual data of luma with 12780c1bc742181ded4930842b46e9507372f0b1b963James Dong inverse quantization and inverse transform. 12790c1bc742181ded4930842b46e9507372f0b1b963James Dong 12800c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 12810c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 ProcessIntra4x4Residual(mbStorage_t *pMb, 12820c1bc742181ded4930842b46e9507372f0b1b963James Dong u8 *data, 12830c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 constrainedIntraPred, 12840c1bc742181ded4930842b46e9507372f0b1b963James Dong macroblockLayer_t *mbLayer, 12850c1bc742181ded4930842b46e9507372f0b1b963James Dong const u8 **pSrc, 12860c1bc742181ded4930842b46e9507372f0b1b963James Dong image_t *image) 12870c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 12880c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 i; 12890c1bc742181ded4930842b46e9507372f0b1b963James Dong u8 *totalCoeff; 12900c1bc742181ded4930842b46e9507372f0b1b963James Dong OMXResult result; 12910c1bc742181ded4930842b46e9507372f0b1b963James Dong u8 *p; 12920c1bc742181ded4930842b46e9507372f0b1b963James Dong 12930c1bc742181ded4930842b46e9507372f0b1b963James Dong totalCoeff = pMb->totalCoeff; 12940c1bc742181ded4930842b46e9507372f0b1b963James Dong 12950c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 0; i < 16; i++, totalCoeff++) 12960c1bc742181ded4930842b46e9507372f0b1b963James Dong { 12970c1bc742181ded4930842b46e9507372f0b1b963James Dong p = data + lumaIndex[i]; 12980c1bc742181ded4930842b46e9507372f0b1b963James Dong if (h264bsdIntra4x4Prediction(pMb, p, mbLayer, image->luma, 12990c1bc742181ded4930842b46e9507372f0b1b963James Dong image->width*16, constrainedIntraPred, i) != HANTRO_OK) 13000c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 13010c1bc742181ded4930842b46e9507372f0b1b963James Dong 13020c1bc742181ded4930842b46e9507372f0b1b963James Dong if (*totalCoeff) 13030c1bc742181ded4930842b46e9507372f0b1b963James Dong { 13040c1bc742181ded4930842b46e9507372f0b1b963James Dong result = omxVCM4P10_DequantTransformResidualFromPairAndAdd( 13050c1bc742181ded4930842b46e9507372f0b1b963James Dong pSrc, 13060c1bc742181ded4930842b46e9507372f0b1b963James Dong p, 13070c1bc742181ded4930842b46e9507372f0b1b963James Dong NULL, 13080c1bc742181ded4930842b46e9507372f0b1b963James Dong p, 13090c1bc742181ded4930842b46e9507372f0b1b963James Dong 16, 13100c1bc742181ded4930842b46e9507372f0b1b963James Dong 16, 13110c1bc742181ded4930842b46e9507372f0b1b963James Dong (i32)pMb->qpY, 13120c1bc742181ded4930842b46e9507372f0b1b963James Dong *totalCoeff); 13130c1bc742181ded4930842b46e9507372f0b1b963James Dong if (result != OMX_Sts_NoErr) 13140c1bc742181ded4930842b46e9507372f0b1b963James Dong return (HANTRO_NOK); 13150c1bc742181ded4930842b46e9507372f0b1b963James Dong } 13160c1bc742181ded4930842b46e9507372f0b1b963James Dong } 13170c1bc742181ded4930842b46e9507372f0b1b963James Dong 13180c1bc742181ded4930842b46e9507372f0b1b963James Dong if (h264bsdIntraChromaPrediction(pMb, data + 256, 13190c1bc742181ded4930842b46e9507372f0b1b963James Dong image, 13200c1bc742181ded4930842b46e9507372f0b1b963James Dong mbLayer->mbPred.intraChromaPredMode, 13210c1bc742181ded4930842b46e9507372f0b1b963James Dong constrainedIntraPred) != HANTRO_OK) 13220c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 13230c1bc742181ded4930842b46e9507372f0b1b963James Dong 13240c1bc742181ded4930842b46e9507372f0b1b963James Dong return HANTRO_OK; 13250c1bc742181ded4930842b46e9507372f0b1b963James Dong} 13260c1bc742181ded4930842b46e9507372f0b1b963James Dong 13270c1bc742181ded4930842b46e9507372f0b1b963James Dong#else /* H264DEC_OMXDL */ 13280c1bc742181ded4930842b46e9507372f0b1b963James Dong 13290c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 13300c1bc742181ded4930842b46e9507372f0b1b963James Dong 13310c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: ProcessResidual 13320c1bc742181ded4930842b46e9507372f0b1b963James Dong 13330c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 13340c1bc742181ded4930842b46e9507372f0b1b963James Dong Process the residual data of one macroblock with 13350c1bc742181ded4930842b46e9507372f0b1b963James Dong inverse quantization and inverse transform. 13360c1bc742181ded4930842b46e9507372f0b1b963James Dong 13370c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 13380c1bc742181ded4930842b46e9507372f0b1b963James Dong 13390c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 ProcessResidual(mbStorage_t *pMb, i32 residualLevel[][16], u32 *coeffMap) 13400c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 13410c1bc742181ded4930842b46e9507372f0b1b963James Dong 13420c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 13430c1bc742181ded4930842b46e9507372f0b1b963James Dong 13440c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 i; 13450c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 chromaQp; 13460c1bc742181ded4930842b46e9507372f0b1b963James Dong i32 (*blockData)[16]; 13470c1bc742181ded4930842b46e9507372f0b1b963James Dong i32 (*blockDc)[16]; 13480c1bc742181ded4930842b46e9507372f0b1b963James Dong i16 *totalCoeff; 13490c1bc742181ded4930842b46e9507372f0b1b963James Dong i32 *chromaDc; 13500c1bc742181ded4930842b46e9507372f0b1b963James Dong const u32 *dcCoeffIdx; 13510c1bc742181ded4930842b46e9507372f0b1b963James Dong 13520c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 13530c1bc742181ded4930842b46e9507372f0b1b963James Dong 13540c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(pMb); 13550c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(residualLevel); 13560c1bc742181ded4930842b46e9507372f0b1b963James Dong 13570c1bc742181ded4930842b46e9507372f0b1b963James Dong /* set pointers to DC coefficient blocks */ 13580c1bc742181ded4930842b46e9507372f0b1b963James Dong blockDc = residualLevel + 24; 13590c1bc742181ded4930842b46e9507372f0b1b963James Dong 13600c1bc742181ded4930842b46e9507372f0b1b963James Dong blockData = residualLevel; 13610c1bc742181ded4930842b46e9507372f0b1b963James Dong totalCoeff = pMb->totalCoeff; 13620c1bc742181ded4930842b46e9507372f0b1b963James Dong if (h264bsdMbPartPredMode(pMb->mbType) == PRED_MODE_INTRA16x16) 13630c1bc742181ded4930842b46e9507372f0b1b963James Dong { 13640c1bc742181ded4930842b46e9507372f0b1b963James Dong if (totalCoeff[24]) 13650c1bc742181ded4930842b46e9507372f0b1b963James Dong { 13660c1bc742181ded4930842b46e9507372f0b1b963James Dong h264bsdProcessLumaDc(*blockDc, pMb->qpY); 13670c1bc742181ded4930842b46e9507372f0b1b963James Dong } 13680c1bc742181ded4930842b46e9507372f0b1b963James Dong dcCoeffIdx = dcCoeffIndex; 13690c1bc742181ded4930842b46e9507372f0b1b963James Dong 13700c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 16; i--; blockData++, totalCoeff++, coeffMap++) 13710c1bc742181ded4930842b46e9507372f0b1b963James Dong { 13720c1bc742181ded4930842b46e9507372f0b1b963James Dong /* set dc coefficient of luma block */ 13730c1bc742181ded4930842b46e9507372f0b1b963James Dong (*blockData)[0] = (*blockDc)[*dcCoeffIdx++]; 13740c1bc742181ded4930842b46e9507372f0b1b963James Dong if ((*blockData)[0] || *totalCoeff) 13750c1bc742181ded4930842b46e9507372f0b1b963James Dong { 13760c1bc742181ded4930842b46e9507372f0b1b963James Dong if (h264bsdProcessBlock(*blockData, pMb->qpY, 1, *coeffMap) != 13770c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_OK) 13780c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 13790c1bc742181ded4930842b46e9507372f0b1b963James Dong } 13800c1bc742181ded4930842b46e9507372f0b1b963James Dong else 13810c1bc742181ded4930842b46e9507372f0b1b963James Dong MARK_RESIDUAL_EMPTY(*blockData); 13820c1bc742181ded4930842b46e9507372f0b1b963James Dong } 13830c1bc742181ded4930842b46e9507372f0b1b963James Dong } 13840c1bc742181ded4930842b46e9507372f0b1b963James Dong else 13850c1bc742181ded4930842b46e9507372f0b1b963James Dong { 13860c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 16; i--; blockData++, totalCoeff++, coeffMap++) 13870c1bc742181ded4930842b46e9507372f0b1b963James Dong { 13880c1bc742181ded4930842b46e9507372f0b1b963James Dong if (*totalCoeff) 13890c1bc742181ded4930842b46e9507372f0b1b963James Dong { 13900c1bc742181ded4930842b46e9507372f0b1b963James Dong if (h264bsdProcessBlock(*blockData, pMb->qpY, 0, *coeffMap) != 13910c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_OK) 13920c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 13930c1bc742181ded4930842b46e9507372f0b1b963James Dong } 13940c1bc742181ded4930842b46e9507372f0b1b963James Dong else 13950c1bc742181ded4930842b46e9507372f0b1b963James Dong MARK_RESIDUAL_EMPTY(*blockData); 13960c1bc742181ded4930842b46e9507372f0b1b963James Dong } 13970c1bc742181ded4930842b46e9507372f0b1b963James Dong } 13980c1bc742181ded4930842b46e9507372f0b1b963James Dong 13990c1bc742181ded4930842b46e9507372f0b1b963James Dong /* chroma DC processing. First chroma dc block is block with index 25 */ 14000c1bc742181ded4930842b46e9507372f0b1b963James Dong chromaQp = 14010c1bc742181ded4930842b46e9507372f0b1b963James Dong h264bsdQpC[CLIP3(0, 51, (i32)pMb->qpY + pMb->chromaQpIndexOffset)]; 14020c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pMb->totalCoeff[25] || pMb->totalCoeff[26]) 14030c1bc742181ded4930842b46e9507372f0b1b963James Dong h264bsdProcessChromaDc(residualLevel[25], chromaQp); 14040c1bc742181ded4930842b46e9507372f0b1b963James Dong chromaDc = residualLevel[25]; 14050c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 8; i--; blockData++, totalCoeff++, coeffMap++) 14060c1bc742181ded4930842b46e9507372f0b1b963James Dong { 14070c1bc742181ded4930842b46e9507372f0b1b963James Dong /* set dc coefficient of chroma block */ 14080c1bc742181ded4930842b46e9507372f0b1b963James Dong (*blockData)[0] = *chromaDc++; 14090c1bc742181ded4930842b46e9507372f0b1b963James Dong if ((*blockData)[0] || *totalCoeff) 14100c1bc742181ded4930842b46e9507372f0b1b963James Dong { 14110c1bc742181ded4930842b46e9507372f0b1b963James Dong if (h264bsdProcessBlock(*blockData, chromaQp, 1,*coeffMap) != 14120c1bc742181ded4930842b46e9507372f0b1b963James Dong HANTRO_OK) 14130c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_NOK); 14140c1bc742181ded4930842b46e9507372f0b1b963James Dong } 14150c1bc742181ded4930842b46e9507372f0b1b963James Dong else 14160c1bc742181ded4930842b46e9507372f0b1b963James Dong MARK_RESIDUAL_EMPTY(*blockData); 14170c1bc742181ded4930842b46e9507372f0b1b963James Dong } 14180c1bc742181ded4930842b46e9507372f0b1b963James Dong 14190c1bc742181ded4930842b46e9507372f0b1b963James Dong return(HANTRO_OK); 14200c1bc742181ded4930842b46e9507372f0b1b963James Dong} 14210c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif /* H264DEC_OMXDL */ 14220c1bc742181ded4930842b46e9507372f0b1b963James Dong 14230c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 14240c1bc742181ded4930842b46e9507372f0b1b963James Dong 14250c1bc742181ded4930842b46e9507372f0b1b963James Dong Function: h264bsdSubMbPartMode 14260c1bc742181ded4930842b46e9507372f0b1b963James Dong 14270c1bc742181ded4930842b46e9507372f0b1b963James Dong Functional description: 14280c1bc742181ded4930842b46e9507372f0b1b963James Dong Returns the macroblock's sub-partition mode. 14290c1bc742181ded4930842b46e9507372f0b1b963James Dong 14300c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 14310c1bc742181ded4930842b46e9507372f0b1b963James Dong 14320c1bc742181ded4930842b46e9507372f0b1b963James DongsubMbPartMode_e h264bsdSubMbPartMode(subMbType_e subMbType) 14330c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 14340c1bc742181ded4930842b46e9507372f0b1b963James Dong 14350c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */ 14360c1bc742181ded4930842b46e9507372f0b1b963James Dong 14370c1bc742181ded4930842b46e9507372f0b1b963James Dong 14380c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */ 14390c1bc742181ded4930842b46e9507372f0b1b963James Dong 14400c1bc742181ded4930842b46e9507372f0b1b963James Dong ASSERT(subMbType < 4); 14410c1bc742181ded4930842b46e9507372f0b1b963James Dong 14420c1bc742181ded4930842b46e9507372f0b1b963James Dong return((subMbPartMode_e)subMbType); 14430c1bc742181ded4930842b46e9507372f0b1b963James Dong 14440c1bc742181ded4930842b46e9507372f0b1b963James Dong} 14450c1bc742181ded4930842b46e9507372f0b1b963James Dong 14460c1bc742181ded4930842b46e9507372f0b1b963James Dong 1447