Sigrid Haflínudóttirfix lots of warningsfbf22d96 years agoHistory
1447 lines · 41.2 KB · C
RawDownload
/* * Copyright (C) 2009 The Android Open Source Project * Modified for use by h264bsd standalone library * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /*------------------------------------------------------------------------------     Table of contents      1. Include headers     2. External compiler flags     3. Module defines     4. Local function prototypes     5. Functions          h264bsdDecodeMacroblockLayer          h264bsdMbPartPredMode          h264bsdNumMbPart          h264bsdNumSubMbPart          DecodeMbPred          DecodeSubMbPred          DecodeResidual          DetermineNc          CbpIntra16x16          h264bsdPredModeIntra16x16          h264bsdDecodeMacroblock          ProcessResidual          h264bsdSubMbPartMode ------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------    1. Include headers------------------------------------------------------------------------------*/ #include "h264bsd_macroblock_layer.h"#include "h264bsd_slice_header.h"#include "h264bsd_util.h"#include "h264bsd_vlc.h"#include "h264bsd_cavlc.h"#include "h264bsd_nal_unit.h"#include "h264bsd_neighbour.h"#include "h264bsd_transform.h"#include "h264bsd_intra_prediction.h"#include "h264bsd_inter_prediction.h" #ifdef H264DEC_OMXDL#include "omxtypes.h"#include "omxVC.h"#include "armVC.h"#endif /* H264DEC_OMXDL */ /*------------------------------------------------------------------------------    2. External compiler flags-------------------------------------------------------------------------------- --------------------------------------------------------------------------------    3. Module defines------------------------------------------------------------------------------*/#ifdef H264DEC_OMXDLstatic const u32 chromaIndex[8] = { 256, 260, 288, 292, 320, 324, 352, 356 };static const u32 lumaIndex[16] = {   0,   4,  64,  68,                                     8,  12,  72,  76,                                   128, 132, 192, 196,                                   136, 140, 200, 204 };#endif/* mapping of dc coefficients array to luma blocks */static const u32 dcCoeffIndex[16] =    {0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15}; /*------------------------------------------------------------------------------    4. Local function prototypes------------------------------------------------------------------------------*/ static u32 DecodeMbPred(strmData_t *pStrmData, mbPred_t *pMbPred,    mbType_e mbType, u32 numRefIdxActive);static u32 DecodeSubMbPred(strmData_t *pStrmData, subMbPred_t *pSubMbPred,    mbType_e mbType, u32 numRefIdxActive);static u32 DecodeResidual(strmData_t *pStrmData, residual_t *pResidual,    mbStorage_t *pMb, mbType_e mbType, u32 codedBlockPattern); #ifdef H264DEC_OMXDLstatic u32 DetermineNc(mbStorage_t *pMb, u32 blockIndex, u8 *pTotalCoeff);#elsestatic u32 DetermineNc(mbStorage_t *pMb, u32 blockIndex, i16 *pTotalCoeff);#endif static u32 CbpIntra16x16(mbType_e mbType);#ifdef H264DEC_OMXDLstatic u32 ProcessIntra4x4Residual(mbStorage_t *pMb, u8 *data, u32 constrainedIntraPred,                    macroblockLayer_t *mbLayer, const u8 **pSrc, image_t *image);static u32 ProcessChromaResidual(mbStorage_t *pMb, u8 *data, const u8 **pSrc );static u32 ProcessIntra16x16Residual(mbStorage_t *pMb, u8 *data, u32 constrainedIntraPred,                    u32 intraChromaPredMode, const u8 **pSrc, image_t *image);  #elsestatic u32 ProcessResidual(mbStorage_t *pMb, i32 residualLevel[][16], u32 *);#endif /*------------------------------------------------------------------------------     Function name: h264bsdDecodeMacroblockLayer         Functional description:          Parse macroblock specific information from bit stream.         Inputs:          pStrmData         pointer to stream data structure          pMb               pointer to macroblock storage structure          sliceType         type of the current slice          numRefIdxActive   maximum reference index         Outputs:          pMbLayer          stores the macroblock data parsed from stream         Returns:          HANTRO_OK         success          HANTRO_NOK        end of stream or error in stream ------------------------------------------------------------------------------*/ u32 h264bsdDecodeMacroblockLayer(strmData_t *pStrmData,    macroblockLayer_t *pMbLayer, mbStorage_t *pMb, u32 sliceType,    u32 numRefIdxActive){ /* Variables */     u32 tmp, i, value;    i32 itmp;    mbPartPredMode_e partMode; /* Code */     ASSERT(pStrmData);    ASSERT(pMbLayer); #ifdef H264DEC_NEON    h264bsdClearMbLayer(pMbLayer, ((sizeof(macroblockLayer_t) + 63) & ~0x3F));#else    memset(pMbLayer, 0, sizeof(macroblockLayer_t));#endif     tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);     if (IS_I_SLICE(sliceType))    {        if ((value + 6) > 31 || tmp != HANTRO_OK)            return(HANTRO_NOK);        pMbLayer->mbType = (mbType_e)(value + 6);    }    else    {        if ((value + 1) > 31 || tmp != HANTRO_OK)            return(HANTRO_NOK);        pMbLayer->mbType = (mbType_e)(value + 1);    }     if (pMbLayer->mbType == I_PCM)    {        i32 *level;        while( !h264bsdIsByteAligned(pStrmData) )        {            /* pcm_alignment_zero_bit */            tmp = h264bsdGetBits(pStrmData, 1);            if (tmp)                return(HANTRO_NOK);        }         level = pMbLayer->residual.level[0];        for (i = 0; i < 384; i++)        {            value = h264bsdGetBits(pStrmData, 8);            if (value == END_OF_STREAM)                return(HANTRO_NOK);            *level++ = (i32)value;        }    }    else    {        partMode = h264bsdMbPartPredMode(pMbLayer->mbType);        if ( (partMode == PRED_MODE_INTER) &&             (h264bsdNumMbPart(pMbLayer->mbType) == 4) )        {            tmp = DecodeSubMbPred(pStrmData, &pMbLayer->subMbPred,                pMbLayer->mbType, numRefIdxActive);        }        else        {            tmp = DecodeMbPred(pStrmData, &pMbLayer->mbPred,                pMbLayer->mbType, numRefIdxActive);        }        if (tmp != HANTRO_OK)            return(tmp);         if (partMode != PRED_MODE_INTRA16x16)        {            tmp = h264bsdDecodeExpGolombMapped(pStrmData, &value,                (u32)(partMode == PRED_MODE_INTRA4x4));            if (tmp != HANTRO_OK)                return(tmp);            pMbLayer->codedBlockPattern = value;        }        else        {            pMbLayer->codedBlockPattern = CbpIntra16x16(pMbLayer->mbType);        }         if ( pMbLayer->codedBlockPattern ||             (partMode == PRED_MODE_INTRA16x16) )        {            tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);            if (tmp != HANTRO_OK || (itmp < -26) || (itmp > 25) )                return(HANTRO_NOK);            pMbLayer->mbQpDelta = itmp;             tmp = DecodeResidual(pStrmData, &pMbLayer->residual, pMb,                pMbLayer->mbType, pMbLayer->codedBlockPattern);             pStrmData->strmBuffReadBits =                (u32)(pStrmData->pStrmCurrPos - pStrmData->pStrmBuffStart) * 8 +                pStrmData->bitPosInWord;             if (tmp != HANTRO_OK)                return(tmp);        }    }     return(HANTRO_OK); } /*------------------------------------------------------------------------------     Function: h264bsdMbPartPredMode         Functional description:          Returns the prediction mode of a macroblock type ------------------------------------------------------------------------------*/ mbPartPredMode_e h264bsdMbPartPredMode(mbType_e mbType){ /* Variables */  /* Code */     ASSERT(mbType <= 31);     if ((mbType <= P_8x8ref0))        return(PRED_MODE_INTER);    else if (mbType == I_4x4)        return(PRED_MODE_INTRA4x4);    else        return(PRED_MODE_INTRA16x16); } /*------------------------------------------------------------------------------     Function: h264bsdNumMbPart         Functional description:          Returns the amount of macroblock partitions in a macroblock type ------------------------------------------------------------------------------*/ u32 h264bsdNumMbPart(mbType_e mbType){ /* Variables */  /* Code */     ASSERT(h264bsdMbPartPredMode(mbType) == PRED_MODE_INTER);     switch (mbType)    {        case P_L0_16x16:        case P_Skip:            return(1);         case P_L0_L0_16x8:        case P_L0_L0_8x16:            return(2);         /* P_8x8 or P_8x8ref0 */        default:            return(4);    } } /*------------------------------------------------------------------------------     Function: h264bsdNumSubMbPart         Functional description:          Returns the amount of sub-partitions in a sub-macroblock type ------------------------------------------------------------------------------*/ u32 h264bsdNumSubMbPart(subMbType_e subMbType){ /* Variables */  /* Code */     ASSERT(subMbType <= P_L0_4x4);     switch (subMbType)    {        case P_L0_8x8:            return(1);         case P_L0_8x4:        case P_L0_4x8:            return(2);         /* P_L0_4x4 */        default:            return(4);    } } /*------------------------------------------------------------------------------     Function: DecodeMbPred         Functional description:          Parse macroblock prediction information from bit stream and store          in 'pMbPred'. ------------------------------------------------------------------------------*/ static u32 DecodeMbPred(strmData_t *pStrmData, mbPred_t *pMbPred, mbType_e mbType,    u32 numRefIdxActive){ /* Variables */     u32 tmp, i, j, value;    i32 itmp; /* Code */     ASSERT(pStrmData);    ASSERT(pMbPred);     switch (h264bsdMbPartPredMode(mbType))    {        case PRED_MODE_INTER: /* PRED_MODE_INTER */            if (numRefIdxActive > 1)            {                for (i = h264bsdNumMbPart(mbType), j = 0; i--;  j++)                {                    tmp = h264bsdDecodeExpGolombTruncated(pStrmData, &value,                        (u32)(numRefIdxActive > 2));                    if (tmp != HANTRO_OK || value >= numRefIdxActive)                        return(HANTRO_NOK);                     pMbPred->refIdxL0[j] = value;                }            }             for (i = h264bsdNumMbPart(mbType), j = 0; i--;  j++)            {                tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);                if (tmp != HANTRO_OK)                    return(tmp);                pMbPred->mvdL0[j].hor = (i16)itmp;                 tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);                if (tmp != HANTRO_OK)                    return(tmp);                pMbPred->mvdL0[j].ver = (i16)itmp;            }            break;         case PRED_MODE_INTRA4x4:            for (itmp = 0, i = 0; itmp < 2; itmp++)            {                value = h264bsdShowBits32(pStrmData);                tmp = 0;                for (j = 8; j--; i++)                {                    pMbPred->prevIntra4x4PredModeFlag[i] =                        value & 0x80000000 ? HANTRO_TRUE : HANTRO_FALSE;                    value <<= 1;                    if (!pMbPred->prevIntra4x4PredModeFlag[i])                    {                        pMbPred->remIntra4x4PredMode[i] = value>>29;                        value <<= 3;                        tmp++;                    }                }                if (h264bsdFlushBits(pStrmData, 8 + 3*tmp) == END_OF_STREAM)                    return(HANTRO_NOK);            }            /* fall-through */         case PRED_MODE_INTRA16x16:            tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);            if (tmp != HANTRO_OK || value > 3)                return(HANTRO_NOK);            pMbPred->intraChromaPredMode = value;            break;    }     return(HANTRO_OK); } /*------------------------------------------------------------------------------     Function: DecodeSubMbPred         Functional description:          Parse sub-macroblock prediction information from bit stream and          store in 'pMbPred'. ------------------------------------------------------------------------------*/ static u32 DecodeSubMbPred(strmData_t *pStrmData, subMbPred_t *pSubMbPred,    mbType_e mbType, u32 numRefIdxActive){ /* Variables */     u32 tmp, i, j, value;    i32 itmp; /* Code */     ASSERT(pStrmData);    ASSERT(pSubMbPred);    ASSERT(h264bsdMbPartPredMode(mbType) == PRED_MODE_INTER);     for (i = 0; i < 4; i++)    {        tmp = h264bsdDecodeExpGolombUnsigned(pStrmData, &value);        if (tmp != HANTRO_OK || value > 3)            return(HANTRO_NOK);        pSubMbPred->subMbType[i] = (subMbType_e)value;    }     if ( (numRefIdxActive > 1) && (mbType != P_8x8ref0) )    {        for (i = 0; i < 4; i++)        {            tmp = h264bsdDecodeExpGolombTruncated(pStrmData, &value,                (u32)(numRefIdxActive > 2));            if (tmp != HANTRO_OK || value >= numRefIdxActive)                return(HANTRO_NOK);            pSubMbPred->refIdxL0[i] = value;        }    }     for (i = 0; i < 4; i++)    {        j = 0;        for (value = h264bsdNumSubMbPart(pSubMbPred->subMbType[i]);             value--; j++)        {            tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);            if (tmp != HANTRO_OK)                return(tmp);            pSubMbPred->mvdL0[i][j].hor = (i16)itmp;             tmp = h264bsdDecodeExpGolombSigned(pStrmData, &itmp);            if (tmp != HANTRO_OK)                return(tmp);            pSubMbPred->mvdL0[i][j].ver = (i16)itmp;        }    }     return(HANTRO_OK); } #ifdef H264DEC_OMXDL/*------------------------------------------------------------------------------

Lines 1–500 of 1447.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t