recongob.c

来自「symbian 下的helix player源代码」· C语言 代码 · 共 1,202 行 · 第 1/4 页

C
1,202
字号
/* ***** BEGIN LICENSE BLOCK *****
 * Source last modified: $Id: Recongob.c,v 1.4.34.1 2004/07/09 01:56:22 hubbe Exp $
 * 
 * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
 * 
 * The contents of this file, and the files included with this file,
 * are subject to the current version of the RealNetworks Public
 * Source License (the "RPSL") available at
 * http://www.helixcommunity.org/content/rpsl unless you have licensed
 * the file under the current version of the RealNetworks Community
 * Source License (the "RCSL") available at
 * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
 * will apply. You may also obtain the license terms directly from
 * RealNetworks.  You may not use this file except in compliance with
 * the RPSL or, if you have a valid RCSL with RealNetworks applicable
 * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
 * the rights, obligations and limitations governing use of the
 * contents of the file.
 * 
 * Alternatively, the contents of this file may be used under the
 * terms of the GNU General Public License Version 2 or later (the
 * "GPL") in which case the provisions of the GPL are applicable
 * instead of those above. If you wish to allow use of your version of
 * this file only under the terms of the GPL, and not to allow others
 * to use your version of this file under the terms of either the RPSL
 * or RCSL, indicate your decision by deleting the provisions above
 * and replace them with the notice and other provisions required by
 * the GPL. If you do not delete the provisions above, a recipient may
 * use your version of this file under the terms of any one of the
 * RPSL, the RCSL or the GPL.
 * 
 * This file is part of the Helix DNA Technology. RealNetworks is the
 * developer of the Original Code and owns the copyrights in the
 * portions it created.
 * 
 * This file, and the files included with this file, is distributed
 * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
 * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
 * ENJOYMENT OR NON-INFRINGEMENT.
 * 
 * Technology Compatibility Kit Test Suite(s) Location:
 *    http://www.helixcommunity.org/content/tck
 * 
 * Contributor(s):
 * 
 * ***** END LICENSE BLOCK ***** */

#include "hxtypes.h"

#ifdef _MACINTOSH
#include <string.h> // for memset
#endif
//#include <string.h>
//#include <stdio.h>
#include <stdlib.h>
#include "dllindex.h"
#include "h261defs.h"
#include "h261func.h"
#include "h263plus.h"

extern S16 Recon [QUANT_MAX - QUANT_MIN + 1] [N_SYM_INDICES];

//#define DISPLAY_DIFFERENCE  // Display quantized pred. error (don't use prev. frame)

#ifdef TESTING
#define CHECKSYM(a)     a   // Check symbol types to verify decoder state tables
#else
#define CHECKSYM(a)         // Don't check symbol types
#endif

#define GRAY    (128)

#ifdef DO_H263_PLUS
extern void PredBframePlus( MACROBLOCK_DESCR * mb,  // Macroblock to be predicted
                        PICTURE * prevPic,      // Prev. picture (forward pred)
                        PICTURE * nextPic,      // Next P-picture (backward pred)
                        PICTURE * Bpic          // Output picture where pred is placed
                        );
#endif

// Declarations of local functions
static void reconBframe( MACROBLOCK_DESCR * mb, PICTURE * Bpic );
static void gray_mb( MACROBLOCK_DESCR * mb, PICTURE * pic );
static void fill_mb( MACROBLOCK_DESCR * mb, PICTURE * pic, PIXEL value );

#ifdef DO_H263_PLUS
static void idct32x32( MACROBLOCK_DESCR * mb,   // Macroblock to be reconstructed
                       PICTURE * tempPic,       // Store 16-bit IDCT values here
                       int intra                // INTER block if zero, otherwise INTRA
                       );
static void filtAddClip32x32( MACROBLOCK_DESCR * mb,// Macroblock to be reconstructed
                              PICTURE * pic,    // Input: motion-comp prediction w/ filtered
                                                // intra borders; output: reconstr. picture
                              PICTURE * tempPic // 16-bit IDCT values
                              );
static void filtAddClip( PIXEL x[], int xdim,       // Output pixels
                         S16 idct_out[], int idim,  // Input IDCT values
                         int hSize, int vSize       // Input block size for IDCT values
                        );
#endif

// ReconGob - Reconstruct one GOB of a picture
// state->i > 0 indicates that we are reentering after previous timeout
extern int ReconGob( GOB_DESCR * gob, MACROBLOCK_DESCR mb[],
                     PICTURE * prev_pic, PICTURE * pic, PICTURE * Bpic, 
                     int advancedPred, int PBframe, int PBframeCap, int reducedResUpdate,
                     int advancedIntraMode, H261DecState *state, int maxComp )
#define CLEAN NO
{
    int mbnum, i, col, dummy[4], reconBflag;
    int intra;
    PICTURE *tempPic;
    CHECKSYM( char msg[120]; ) /* Flawfinder: ignore */

    if (PBframe && PBframeCap) {
        reconBflag = 1; // Reconstruct B frame
    } else {
        reconBflag = 0; // Don't do B frame
    }
    tempPic = Bpic; // Use as work array in Reduced-res. Update mode
    if (state->i > 0) {
        // We timed out last time: restore state
        i     = state->i;
        mbnum = state->mbnum;
        col   = state->col;
    } else {
        // Reset state
        i = 0;
        mbnum = gob->first_col + gob->first_row * gob->mb_offset;
        col = gob->first_col;   // Used to check when we reach end of line
    }
#ifndef DISPLAY_DIFFERENCE  // Do proper reconstruction
    if (pic->y.nhor == prev_pic->y.nhor  &&  pic->y.nvert == prev_pic->y.nvert) {
        // Size of prev_pic is OK; use it if specified
        while (i < gob->num_mb) {
            //printf("recon_gob:  mbnum = %d   type = %d\n", mbnum, mb[mbnum].mtype);
            switch (mb[mbnum].mtype) {
            case MTYPE_SKIP:
                mb[mbnum].mv_x = 0;
                mb[mbnum].mv_y = 0;
                if (reducedResUpdate) {
                    MotionComp32x32( &mb[mbnum], prev_pic, pic);
                    if (advancedPred) {
                        Overlap32x32( &mb[mbnum], prev_pic, pic,
                                gob->mb_width, gob->mb_offset, dummy );
                    }
                } else {
                    MotionComp( &mb[mbnum], prev_pic, pic);
                    if (advancedPred) {
                        OverlapMC( &mb[mbnum], PBframe, prev_pic, pic,
                                gob->mb_width, gob->mb_offset, dummy );
                    }
                    if (reconBflag) {   // Repeat prev. picture in B frame
                        MotionComp( &mb[mbnum], prev_pic, Bpic );
                    }
                }
                break;
            
            case MTYPE263_INTER:
            case MTYPE263_INTER_Q:
            case MTYPE263_INTER4V:
                if (reducedResUpdate) {
                    MotionComp32x32( &mb[mbnum], prev_pic, pic);
                    if (advancedPred) {
                        Overlap32x32( &mb[mbnum], prev_pic, pic,
                                gob->mb_width, gob->mb_offset, dummy );
                        state->actComp += 4;   // Increment computation measure
                    }
                    intra = NO;
                    ReconReducedResMb( &mb[mbnum], pic, intra, tempPic );
                    state->actComp += 4;   // Increment computation measure
                } else {
                    MotionComp263( &mb[mbnum], prev_pic, pic);
                    if (advancedPred) {
                        OverlapMC( &mb[mbnum], PBframe, prev_pic, pic,
                                gob->mb_width, gob->mb_offset, dummy );
                        ++state->actComp;   // Increment computation measure
                    }
                    ReconInter( &mb[mbnum], pic, CLEAN);
                    ++state->actComp;   // Increment computation measure
                    if (reconBflag) {   // Reconstruct B frame
					    if(PBframe == H263PLUS_IMPROVED_PBFRAME_MODE) {
						    PredBframePlus( &mb[mbnum], prev_pic, pic, Bpic );
					    } else {
						    PredBframe( &mb[mbnum], prev_pic, pic, Bpic );
					    }
                        reconBframe( &mb[mbnum], Bpic );
                        ++state->actComp;   // Increment computation measure
                    }
                }
                break;
            case MTYPE263_INTRA:
            case MTYPE263_INTRA_Q:
                if (reducedResUpdate) {
                    Fill32x32( &mb[mbnum], pic, 0 );
                    intra = YES;
                    ReconReducedResMb( &mb[mbnum], pic, intra, tempPic );
                    state->actComp += 4;   // Increment computation measure
                } else {
                    if(advancedIntraMode)
                        ReconAdvancedIntra( &mb[mbnum], pic, CLEAN );
                    else
                        ReconIntra( &mb[mbnum], pic, CLEAN );
                    ++state->actComp;   // Increment computation measure
                    if (reconBflag) {   // Reconstruct B frame
                        if(PBframe==H263PLUS_IMPROVED_PBFRAME_MODE) {
						    PredBframePlus( &mb[mbnum], prev_pic, pic, Bpic );
					    } else {
                            PredBframe( &mb[mbnum], prev_pic, pic, Bpic );
                        }
                        reconBframe( &mb[mbnum], Bpic );
                        ++state->actComp;   // Increment computation measure
                    }
                }
                break;
            
            case MTYPE_INTER:
            case MTYPE_INTER_MQUANT:
                mb[mbnum].mv_x = 0;
                mb[mbnum].mv_y = 0;
                MotionComp( &mb[mbnum], prev_pic, pic);
                ReconInter( &mb[mbnum], pic, CLEAN);
                ++state->actComp;   // Increment computation measure
                break;
            case MTYPE_MCFILT_CBP:
            case MTYPE_MCFILT_MQUANT:
                LoopFilter( &mb[mbnum], prev_pic, pic);
                ReconInter( &mb[mbnum], pic, CLEAN);
                state->actComp += 2;    // Increment computation measure
                break;
            case MTYPE_MCFILT_NOCBP:
                LoopFilter( &mb[mbnum], prev_pic, pic);
                ++state->actComp;   // Increment computation measure
                break;
            case MTYPE_INTRA:
            case MTYPE_INTRA_MQUANT:
                //printf("Calling ReconIntra, mbnum = %d \n", mbnum);
                ReconIntra( &mb[mbnum], pic, CLEAN );
                ++state->actComp;   // Increment computation measure
                break;
            case MTYPE_MC_CBP:
            case MTYPE_MC_MQUANT:
                MotionComp( &mb[mbnum], prev_pic, pic);
                ReconInter( &mb[mbnum], pic, CLEAN);
                ++state->actComp;   // Increment computation measure
                break;
            case MTYPE_MC_NOCBP:
                MotionComp( &mb[mbnum], prev_pic, pic);
                break;
            default:
                CHECKSYM( sprintf( msg, "PROGRAM ERROR: MTYPE = %d in recon_gob", mb[mbnum].mtype); /* Flawfinder: ignore */
                    H261ErrMsg( msg );
                    state->i = 0;   // Indicate that we finished without timing out
                    return( H261_ERROR ); )
                break;
            }
            i++, mbnum++;
            col++;
            if (col == gob->mb_width) { // Start on next row of macroblocks
                mbnum += gob->mb_offset - gob->mb_width;
                col = 0;
            }
            if (maxComp > 0  &&  state->actComp >= maxComp) {
                // We have timed out: save state and return
                state->i    = i;
                state->mbnum= mbnum;
                state->col  = col;
                return OK;
            }
        }
        state->i = 0;   // Indicate that we finished without timing out
        return (OK);
    } else
#endif
    {   // Don't use prev_pic, i.e., reconstruct difference image
        while (i < gob->num_mb) {
            switch (mb[mbnum].mtype) {
            case MTYPE_SKIP:
            case MTYPE_MCFILT_NOCBP:
            case MTYPE_MC_NOCBP:
                if (reducedResUpdate) {
                    Fill32x32( &mb[mbnum], pic, GRAY);
                } else {
                    gray_mb( &mb[mbnum], pic);
                    if (reconBflag) {   // Reconstruct B frame
                        gray_mb( &mb[mbnum], Bpic );
                    }
                }
                break;
            case MTYPE263_INTER:
            case MTYPE263_INTER_Q:
            case MTYPE263_INTER4V:
            case MTYPE_INTER:
            case MTYPE_INTER_MQUANT:
            case MTYPE_MCFILT_CBP:
            case MTYPE_MCFILT_MQUANT:
            case MTYPE_MC_CBP:
            case MTYPE_MC_MQUANT:
                if (reducedResUpdate) {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?