#include #define H261GLOBAL #include "h261vlc.h" #include "video_common.h" #include "bitio.h" void compile_h261vlc(void) { /* Compile psc */ psc = psc_desc; /* Compile gbsc */ gbsc = gbsc_desc; /* block eob */ // blk_eob = blk_eobdesc; for(int i=0; i < NUM_TCOEFF; i++) { tcoeff[i] = tcoeff_desc[i]; add_to_tree(&tcoeff_root, tcoeff_desc[i]); } /* Compile mvd */ for(int i=0; i < NUM_MVDS; i++) { mvd[i] = mvd_desc[i]; add_to_tree(&mvd_root, mvd_desc[i]); } /* Compile mba_addr */ for(int i=0; i < NUM_MBAADDRS; i++) { mba_addr[i] = mba_addrdesc[i]; add_to_tree(&mba_addr_root, mba_addrdesc[i]); } /* Compile mtypes */ for(int i=0; i < NUM_MTYPES; i++) { mtype[i] = mtype_desc[i]; add_to_tree(&mtype_root, mtype_desc[i]); } /* Compile cbps */ for(int i=0; i < NUM_CBPS; i++) { cbp[i] = cbp_desc[i]; add_to_tree(&cbp_root, cbp_desc[i]); } return; } void symbol_code::print(void) { u_char mask = 0; u_char rc = 0; printf("%d\t", symbol); for(int i=0; i < codelen; i++) { mask = 1 << (7 - (i%8)); rc = (bitstring[i/8] & mask) >> (7 - (i%8)); printf("%1d", rc); } printf("\n"); } void symbol_code::operator = (symbol_string& s) { char *bit = s.string; char tmp; int byte_index = 0; symbol = s.symbol; codelen = 0; bitstring[byte_index] = 0; while( (tmp = *bit++)) { /* Till the end of the string */ if(tmp == ' ') { continue; } if(tmp != '0' && tmp != '1') { #ifdef BOUNDS_CHECK bounds_error(__LINE__, __FILE__, __PRETTY_FUNCTION__); continue; #endif } if(tmp == '1') { bitstring[byte_index] |= 1 << (7 - codelen%8); } codelen++; #ifdef BOUNDS_CHECK if( (codelen >> 3) > BITSTRING_BUFSIZE) { bounds_error(__LINE__, __FILE__, __PRETTY_FUNCTION__); } #endif if(!(codelen % 8)) { byte_index ++; bitstring[byte_index] = 0; } } } #ifdef COMMENT void read_picture(void) { read_bits(psc); /* PSC */ read_bits(0,5); /* tr */ read_bits(6,6); /* PTYPE */ read_bits(0,1); /* PEI */ /* Conditional skip spare */ /* Skip spare */ for(int i=0; i < 12; i++) read_gob(); } void read_gob(void) { read_bits(); /* GBSC */ read_bits(); /* GN */ read_bits(); /* GQUANT */ read_bits(); /* GEI */ /* Conditional */ /* Skip spare */ for(int i=0; i < 33; i++) read_mb(); } void write_mb(void) { write_bits(); /* MBA */ write_bits(); /* MTYPE */ /* Conditional */ write_bits(); /* MQUANT */ /* Conditional */ write_bits(); /* MVD */ /* Conditional */ write_bits(); /* CBP */ /* Conditional */ for(int i=0; i < 6; i++) write_block(); } void read_mb(void) { read_bits(); /* MBA */ read_bits(); /* MTYPE */ /* Conditional */ read_bits(); /* MQUANT */ /* Conditional */ read_bits(); /* MVD */ /* Conditional */ read_bits(); /* CBP */ /* Conditional */ for(int i=0; i < 6; i++) read_block(); } void write_block(void) { /* Write transform coefficients with zig-zag scan */ write_eob(); } void read_block(void) { /* Read transform coefficients with zig-zag scan */ read_eob(); } void write_eob(void) { write_bits(); } void read_eob(void) { read_bits(); } #endif