?? bitstream.c
字號:
#include <stdio.h>#include <stdlib.h>#include "bitstream.h"#include "zigzag.h"#include "../quant/quant_matrix.h"#include "../local_mem.h"#include "../define.h"#include "../vpe_m.h"//int old_time_incre;uint32_t time_increment_resolution;/***************************************************************************** * Functions ****************************************************************************/static int32_t vop_width[8] = {0, 128, 176, 352, 704, 1408, 0, 0};static int32_t vop_height[8] = {0, 96, 144, 288, 576, 1152, 0, 0};static uint32_t __inlinelog2bin(uint32_t value){/* Changed by Chenm001 */ int n = 0; while (value) { value >>= 1; n++; } return n;}/*static const uint32_t intra_dc_threshold_table[] = { 32, // never use 13, 15, 17, 19, 21, 23, 1,};*/voidbs_get_matrix(Bitstream * bs, uint8_t * matrix){ int i = 0, j = 0; int last, value = 0; do { last = value; j++; if (j == 8) { j=0; } value = BitstreamGetBits(bs, 8); matrix[scan_tables[0][i++]] = value; } while (value != 0 && i < 64); i--; /* fix little bug at coeff not full */ while (i < 64) { matrix[scan_tables[0][i++]] = last; }}boolbRead_video_packet_header(DECODER * dec, int *fcode_forward, int *fcode_backward, int32_t * mbnum){ int tmp; int coding_type; uint32_t * table = (uint32_t *)((uint32_t) dec->pu32BaseAddr + TABLE_OUTPUT_OFF); tmp = table[0]; // macroblock_number if (dec->h263==1) *mbnum = ((tmp & 0xFFFF) >> 2) * dec->mb_width; else { *mbnum = tmp & 0xFFFF; //extent bit if (tmp & BIT24) { tmp = table[2]; coding_type = tmp & 0xff; // hardware not support if (coding_type >= B_VOP) return -1; if (coding_type != I_VOP && *fcode_forward) *fcode_forward = (tmp >> 16) & 0xff; if (coding_type == B_VOP && *fcode_backward) *fcode_backward = 0; } } return 0;}/*decode headersreturns coding_type, or -1 if error*/#define VIDOBJ_START_CODE_MASK 0x0000001f#define VIDOBJLAY_START_CODE_MASK 0x0000000f#define VIDO_SHORT_HEADER_MASK 0x000003ff#define VIDO_SHORT_HEADER 0x8000#define VIDO_SHORT_HEADER_END 0x3fintBitstreamReadHeaders(Bitstream * bs, DECODER * dec, uint32_t * rounding, uint32_t * quant, uint32_t * fcode_forward, uint32_t * fcode_backward, uint32_t * intra_dc_threshold_bit){ uint32_t vol_ver_id; uint32_t coding_type; uint32_t start_code; uint32_t time_incr = 0; int32_t time_increment = 0; do { BitstreamByteAlign(bs); start_code = BitstreamShowBits(bs, 32);#ifndef FPGA mVpe_Indicator(0x93000000 | (start_code >> 16)); mVpe_Indicator(0x93000000 | (start_code & 0xFFFF));#endif if (start_code == VISOBJSEQ_START_CODE) { int profile; BitstreamSkip(bs, 32); /* visual_object_sequence_start_code */ profile = BitstreamGetBits(bs, 8); /* profile_and_level_indication */ } else if (start_code == VISOBJSEQ_STOP_CODE) { BitstreamSkip(bs, 32); /* visual_object_sequence_stop_code */ } else if (start_code == VISOBJ_START_CODE) { BitstreamSkip(bs, 32); /* visual_object_start_code */ if (BitstreamGetBit(bs)) /* is_visual_object_identified */ { vol_ver_id = BitstreamGetBits(bs, 4); /* visual_object_ver_id */ BitstreamSkip(bs, 3); /* visual_object_priority */ } else { vol_ver_id = 1; } if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO) /* visual_object_type */ { return -1; } BitstreamSkip(bs, 4); /* video_signal_type */ if (BitstreamGetBit(bs)) /* video_signal_type */ { BitstreamSkip(bs, 3); /* video_format */ BitstreamSkip(bs, 1); /* video_range */ if (BitstreamGetBit(bs)) /* color_description */ { BitstreamSkip(bs, 8); /* color_primaries */ BitstreamSkip(bs, 8); /* transfer_characteristics */ BitstreamSkip(bs, 8); /* matrix_coefficients */ } } } else if ((start_code & ~VIDOBJ_START_CODE_MASK) == VIDOBJ_START_CODE) { BitstreamSkip(bs, 32); /* video_object_start_code */ } else if ((start_code & ~VIDO_SHORT_HEADER_MASK) == VIDO_SHORT_HEADER) { int temp, pei, psupp = 0; uint32_t width, height; // ben add dec->h263 = 1; dec->quant_type = 0; *fcode_forward = 1; dec->quarterpel = 0; BitstreamSkip(bs, 22); BitstreamSkip(bs, 8); READ_MARKER(); temp = BitstreamGetBit(bs); // zero_bit dec->split_screen_indicator = BitstreamGetBit(bs); // split_screen_indicator dec->document_camera_indicator = BitstreamGetBit(bs); // document_camera_indicator dec->full_picture_freeze_release = BitstreamGetBit(bs); // full_picture_freeze_release dec->source_format = BitstreamGetBits(bs,3); // source_format dec->picture_coding_type = BitstreamGetBit(bs); // picture_coding_type temp = BitstreamGetBits(bs,4); // four_reserved_zero_bits *quant = BitstreamGetBits(bs,5); // quant temp = BitstreamGetBit(bs); // zero_bit do { pei = BitstreamGetBit(bs); if (pei == 1) psupp=BitstreamGetBits(bs,8); } while (pei == 1); width = vop_width[dec->source_format]; height = vop_height[dec->source_format];//ben add#if 0 dec->width = width; dec->height = height;#else /* for auto set width & height */ if (dec->width == 0) dec->width = width; if (dec->height == 0) dec->height = height; if (width != dec->width || height != dec->height) return -1;#endif return dec->picture_coding_type; } else if ((start_code & ~VIDOBJLAY_START_CODE_MASK) == VIDOBJLAY_START_CODE) { BitstreamSkip(bs, 32); /* video_object_layer_start_code */ BitstreamSkip(bs, 1); /* random_accessible_vol */ dec->h263 = 0; /* video_object_type_indication */ if (BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_SIMPLE && BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_CORE && BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_MAIN && BitstreamShowBits(bs, 8) != 0) /* BUGGY DIVX */ { return -1; } BitstreamSkip(bs, 8); if (BitstreamGetBit(bs)) /* is_object_layer_identifier */ { vol_ver_id = BitstreamGetBits(bs, 4); /* video_object_layer_verid */ BitstreamSkip(bs, 3); /* video_object_layer_priority */ } else { vol_ver_id = 1; } if (BitstreamGetBits(bs, 4) == VIDOBJLAY_AR_EXTPAR) /* aspect_ratio_info */ { BitstreamSkip(bs, 8); /* par_width */ BitstreamSkip(bs, 8); /* par_height */ } if (BitstreamGetBit(bs)) /* vol_control_parameters */ { BitstreamSkip(bs, 2); /* chroma_format */ dec->low_delay = (uint8_t)BitstreamGetBit(bs); /* low_delay */ if (BitstreamGetBit(bs)) /* vbv_parameters */ { BitstreamSkip(bs, 15); /* first_half_bitrate */ READ_MARKER(); BitstreamSkip(bs, 15); /* latter_half_bitrate */ READ_MARKER(); BitstreamSkip(bs, 15); /* first_half_vbv_buffer_size */ READ_MARKER(); BitstreamSkip(bs, 3); /* latter_half_vbv_buffer_size */ BitstreamSkip(bs, 11); /* first_half_vbv_occupancy */ READ_MARKER(); BitstreamSkip(bs, 15); /* latter_half_vbv_occupancy */ READ_MARKER(); } } dec->shape = BitstreamGetBits(bs, 2); /* video_object_layer_shape */ if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1) { BitstreamSkip(bs, 4); /* video_object_layer_shape_extension */ } READ_MARKER();/* *************************** for decode B-frame time *********************** */ time_increment_resolution = BitstreamGetBits(bs, 16); /* vop_time_increment_resolution *//* time_increment_resolution--; */ if (time_increment_resolution > 0) { dec->time_inc_bits = MAX(log2bin(time_increment_resolution-1), 1);
} else { /* dec->time_inc_bits = 0; */ /* for "old" xvid compatibility, set time_inc_bits = 1 */ dec->time_inc_bits = 1; }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -