⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 video_mpeg2.c

📁 基于linux的DVD播放器程序
💻 C
📖 第 1 页 / 共 3 页
字号:
/* Ogle - A video player * Copyright (C) 2000, 2001 Bj鰎n Englund, H錵an Hjort * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/types.h>#include <unistd.h>#include <inttypes.h>#include <signal.h>#include "debug_print.h"#include "video_stream.h"#include "video_types.h"#ifdef HAVE_MLIB#include <mlib_types.h>#include <mlib_status.h>#include <mlib_sys.h>#include <mlib_video.h>#include <mlib_algebra.h>#else#ifdef HAVE_MMX#include "mmx.h"#include "mmx_mlib.h"#else#include "c_mlib.h"#endif#endif#include "common.h"#include "c_getbits.h"#include "video_tables.h"#define NEW_TABLES 0#if NEW_TABLES#include "new_table.h"#endif/* #include <libcpc.h> */extern yuv_image_t *dst_image;extern yuv_image_t *fwd_ref_image;extern void next_start_code(void);extern void exit_program(int exitcode) ATTRIBUTE_NORETURN;#if PRAGMA_NORETURN#pragma does_not_return (exit_program) #endifextern void motion_comp(void);extern void motion_comp_add_coeff(unsigned int i);extern int get_vlc(const vlc_table_t *table, char *func);/*  Functions defined within this file:    void mpeg2_slice(void);  void block_intra(unsigned int);  void block_non_intra(unsigned int);  void macroblock(void);  int macroblock_modes(void);  void coded_block_pattern(void);  void reset_dc_dct_pred(void);  void reset_PMV();  void reset_vectors();  void motion_vectors(unsigned int s);  void motion_vector(int r, int s);*/staticvoid reset_dc_dct_pred(void){  DPRINTFI(3, "Resetting dc_dct_pred\n");    /* Table 7-2. Relation between intra_dc_precision and the predictor     reset value */  /*  switch(pic.coding_ext.intra_dc_precision) {  case 0:    mb.dc_dct_pred[0] = 128;    mb.dc_dct_pred[1] = 128;    mb.dc_dct_pred[2] = 128;    break;  case 1:    mb.dc_dct_pred[0] = 256;    mb.dc_dct_pred[1] = 256;    mb.dc_dct_pred[2] = 256;    break;  case 2:    mb.dc_dct_pred[0] = 512;    mb.dc_dct_pred[1] = 512;    mb.dc_dct_pred[2] = 512;    break;  case 3:    mb.dc_dct_pred[0] = 1024;    mb.dc_dct_pred[1] = 1024;    mb.dc_dct_pred[2] = 1024;    break;  default:    fprintf(stderr, "*** reset_dc_dct_pred(), invalid intra_dc_precision\n");    exit_program(1);    break;  }  */  mb.dc_dct_pred[0] = 128 << pic.coding_ext.intra_dc_precision;  mb.dc_dct_pred[1] = 128 << pic.coding_ext.intra_dc_precision;  mb.dc_dct_pred[2] = 128 << pic.coding_ext.intra_dc_precision;}staticvoid reset_PMV(void){  DPRINTFI(3, "Resetting PMV\n");  pic.PMV[0][0][0] = 0;  pic.PMV[0][0][1] = 0;  pic.PMV[0][1][0] = 0;  pic.PMV[0][1][1] = 0;  pic.PMV[1][0][0] = 0;  pic.PMV[1][0][1] = 0;  pic.PMV[1][1][0] = 0;  pic.PMV[1][1][1] = 0;}staticvoid reset_vectors(void){  DPRINTFI(3, "Resetting motion vectors\n");    mb.vector[0][0][0] = 0;  mb.vector[0][0][1] = 0;  mb.vector[1][0][0] = 0;  mb.vector[1][0][1] = 0;  mb.vector[0][1][0] = 0;  mb.vector[0][1][1] = 0;  mb.vector[1][1][0] = 0;  mb.vector[1][1][1] = 0;}#if NEW_TABLES/* 6.2.6 Block */staticvoid block_intra(unsigned int i){  const base_table_t *top_table;    unsigned int n;  int inverse_quantisation_sum;     DPRINTFI(3, "pattern_code(%d) set\n", i);    //cpc_count_usr_events(1);    { /* Reset all coefficients to 0. */    int m;    for(m=0; m<16; m++)      *(((uint64_t *)mb.QFS) + m) = 0;  }          /* DC - component */  {    unsigned int dct_dc_size;    int dct_diff;        if(i < 4) {      dct_dc_size = get_vlc(table_b12, "dct_dc_size_luminance (b12)");      DPRINTF(4, "luma_size: %d\n", dct_dc_size);    } else {      dct_dc_size = get_vlc(table_b13, "dct_dc_size_chrominance (b13)");      DPRINTF(4, "chroma_size: %d\n", dct_dc_size);    }         if(dct_dc_size != 0) {      int half_range = 1<<(dct_dc_size-1);      int dct_dc_differential = GETBITS(dct_dc_size, "dct_dc_differential");            DPRINTF(4, "diff_val: %d, ", dct_dc_differential);            if(dct_dc_differential >= half_range) {	dct_diff = dct_dc_differential;      } else {	dct_diff = (dct_dc_differential+1)-(2*half_range);      }      DPRINTF(4, "%d\n", dct_diff);            } else {      dct_diff = 0;    }          {      // qfs is always between 0 and 2^(8+dct_dc_size)-1, i.e unsigned.      unsigned int qfs;      int cc;            /* Table 7-1. Definition of cc, colour component index */       cc = (i>>2) + ((i>>2) & i);            qfs = mb.dc_dct_pred[cc] + dct_diff;      mb.dc_dct_pred[cc] = qfs;      DPRINTF(4, "QFS[0]: %d\n", qfs);            /* inverse quantisation */      {	// mb.intra_dc_mult is 1, 2 , 4 or 8, i.e unsigned.	unsigned int f = mb.intra_dc_mult * qfs;#if 0	if(f > 2047) {	  fprintf(stderr, "Clipp (block_intra first)\n");	  f = 2047;	} #endif	mb.QFS[0] = f;	inverse_quantisation_sum = f + 1;      }      n = 1;    }  }      /* AC - components */    top_table = top_b14;  if(pic.coding_ext.intra_vlc_format) {    top_table = top_b15;  }      while(1) {    unsigned int bits;    unsigned int i, f, val, sgn;    //get_dct_intra(&runlevel,"dct_dc_subsequent");        // We need the first and the following 8 bits    bits = nextbits(16);        if((bits >> 10) == 1) {    //if(top == entry_for_escape) { // entry_for_escape {24, 8 }    //if(top->offset == 24) {      val = getbits(6+6+12);      n += (val >> 12) & 0x3f;      val &= 0xfff;      sgn = (val >= 2048); // sgn = val >> 11;      if(val >= 2048)	val = 4096 - val;    } else {      index_table_t const *const sub	= &sub_table[TOP_OFFSET(top_table, bits >> 8) + 		    ((0xff & bits) >> TOP_IBITS(top_table, bits >> 8))];      val = VLC_LEVEL(*sub);      n += VLC_RUN(*sub);      // Make sure the code for EOB is compensated for this, it is.      sgn = getbits(VLC_CODE_BITS(*sub)+1+1) & 1;            // End of block, can't happen for esq. but we might need error check?      if(n >= 64)	break;    }        /* inverse quantisation */    i = inverse_scan[pic.coding_ext.alternate_scan][n++];    f = (val 	 * mb.quantiser_scale	 * seq.header.intra_inverse_quantiser_matrix[i])/16;    #if 0    if((f - sgn) > 2047)      f = 2047 + sgn;#endif        inverse_quantisation_sum += f; // The last bit is the same in f and -f.        // mb.QFS[i] = sgn ? -f : f;    mb.QFS[i] = (f ^ -sgn) + sgn;  }    //cpc_count_usr_events(0);  mb.QFS[63] ^= inverse_quantisation_sum & 1;    DPRINTF(4, "nr of coeffs: %d\n", n);}/* 6.2.6 Block */staticvoid block_non_intra(unsigned int b){  index_table_t const *sub;  index_table_t const sub_firt_dc = VLC_RL( 1, 0, 1 );  unsigned int bits;    unsigned int n = 0;  int inverse_quantisation_sum = 1;    DPRINTF(3, "pattern_code(%d) set\n", b);    //cpc_count_usr_events(1);  { /* Reset all coefficients to 0. */    int m;    for(m=0; m<16; m++)      *(((uint64_t *)mb.QFS) + m) = 0;  }    // We need the first and the following 8 bits  bits = nextbits(16);    sub = &sub_firt_dc;   if(bits >> 15) { // if(top->offset < 2) {    goto sub_entry;  }     while(1) {    unsigned int i, f, val, sgn;        if((bits>>10) == 1) {    //if(top->offset == 24) { // offset_for_escape { 24, 8 }      val = getbits(6+6+12);      n += (val >> 12) & 0x3f;      val &= 0xfff;      sgn = (val >= 2048); // sgn = val >> 11;      if(val >= 2048)	val = 4096 - val;    } else {      sub = &sub_table[TOP_OFFSET(top_b14, bits >> 8) +		      ((0xff & bits) >> TOP_IBITS(top_b14, bits >> 8))];    sub_entry:      val = VLC_LEVEL(*sub);      n += VLC_RUN(*sub);      // Make sure the code for EOB and DCT_DC_FIRST is compensated, it is.      sgn = getbits(VLC_CODE_BITS(*sub) + 1 + 1) & 1;            // End of block, can't happen for esq. but we might need error check?      if(n >= 64)	break;    }        /* inverse quantisation */    i = inverse_scan[pic.coding_ext.alternate_scan][n++];    f = ((val * 2 + 1)	 * mb.quantiser_scale	 * seq.header.non_intra_inverse_quantiser_matrix[i])/32;#if 0    if((f - sgn) > 2047)      f = 2047 + sgn;#endif        inverse_quantisation_sum += f; // The last bit is the same in f and -f.        // mb.QFS[i] = sgn ? -f : f;    mb.QFS[i] = (f ^ -sgn) + sgn;        /* Start of next code */        // We need the first and the following 8 bits    bits = nextbits(16);  }    //cpc_count_usr_events(0);    mb.QFS[63] ^= inverse_quantisation_sum & 1;    DPRINTF(4, "nr of coeffs: %d\n", n);}#else /* NEW_TABLES *//* 6.2.6 Block */staticvoid block_intra(unsigned int i){  unsigned int n;  int inverse_quantisation_sum;    unsigned int left;  unsigned int offset;  uint32_t word;    DPRINTFI(3, "pattern_code(%d) set\n", i);    //cpc_count_usr_events(1);    { /* Reset all coefficients to 0. */    int m;    for(m=0; m<16; m++)      *(((uint64_t *)mb.QFS) + m) = 0;  }      /* DC - component */  {    unsigned int dct_dc_size;    int dct_diff;        if(i < 4) {      dct_dc_size = get_vlc(table_b12, "dct_dc_size_luminance (b12)");      DPRINTF(4, "luma_size: %d\n", dct_dc_size);    } else {      dct_dc_size = get_vlc(table_b13, "dct_dc_size_chrominance (b13)");      DPRINTF(4, "chroma_size: %d\n", dct_dc_size);    }         if(dct_dc_size != 0) {      int half_range = 1<<(dct_dc_size-1);      int dct_dc_differential = GETBITS(dct_dc_size, "dct_dc_differential");            DPRINTF(4, "diff_val: %d, ", dct_dc_differential);            if(dct_dc_differential >= half_range) {	dct_diff = dct_dc_differential;      } else {	dct_diff = (dct_dc_differential+1)-(2*half_range);      }      DPRINTF(4, "%d\n", dct_diff);            } else {      dct_diff = 0;    }          {      // qfs is always between 0 and 2^(8+dct_dc_size)-1, i.e unsigned.      unsigned int qfs;      int cc;            /* Table 7-1. Definition of cc, colour component index */       cc = (i>>2) + ((i>>2) & i);            qfs = mb.dc_dct_pred[cc] + dct_diff;      mb.dc_dct_pred[cc] = qfs;      DPRINTF(4, "QFS[0]: %d\n", qfs);            /* inverse quantisation */      {	// mb.intra_dc_mult is 1, 2 , 4 or 8, i.e unsigned.	unsigned int f = mb.intra_dc_mult * qfs;#if 0	if(f > 2047) {	  fprintf(stderr, "Clipp (block_intra first)\n");	  f = 2047;	} #endif	mb.QFS[0] = f;	inverse_quantisation_sum = f + 1;      }      n = 1;    }  }      /* AC - components */    left = bits_left;  offset = offs;  word = nextbits(24);  while( 1 ) {    //get_dct_intra(&runlevel,"dct_dc_subsequent");        const DCTtab *tab;    /*    const unsigned int code = nextbits(16); */    const unsigned int code = (word >> (24-16));        if(code>=16384) {      if (pic.coding_ext.intra_vlc_format)	tab = &DCTtab0a[(code >> 8) - 4];   // 15      else	tab = &DCTtabnext[(code >> 12) - 4];  // 14      /* EOB here for both cases */    }    else if(code>=1024) {      if (pic.coding_ext.intra_vlc_format)	tab = &DCTtab0a[(code >> 8) - 4];   // 15      else	tab = &DCTtab0[(code >> 8) - 4];   // 14      /* Escape here for both cases */    }    else if(code>=512)      if (pic.coding_ext.intra_vlc_format)	tab = &DCTtab1a[(code >> 6) - 8];  // 15

⌨️ 快捷键说明

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