📄 video.c
字号:
* Initialize ring buffer of pict images now that dimensions of image space * are known. */#ifdef SH_MEM if (xinfo->display != NULL) { InstallXErrorHandler(xinfo->display); }#endif if (vid_stream->ring[0] == NULL) { for (i = 0; i < RING_BUF_SIZE; i++) { vid_stream->ring[i] = NewPictImage(vid_stream,xinfo); } }#ifdef SH_MEM if (xinfo->display != NULL) { DeInstallXErrorHandler(xinfo->display); }#endif /* Parse of aspect ratio code. */ get_bits4(data); vid_stream->aspect_ratio = (unsigned char) data; /* Parse off picture rate code. */ get_bits4(data); vid_stream->picture_rate = (unsigned char) data; /* Parse off bit rate. */ get_bits18(data); vid_stream->bit_rate = data; /* Flush marker bit. */ flush_bits(1); /* Parse off vbv buffer size. */ get_bits10(data); vid_stream->vbv_buffer_size = data;#ifdef not_def /* Lets not bother with this. Only increases memory image */ if (data*1024>vid_stream->max_buf_length) { unsigned int *newbuf; int sz=1024*data+1; /* If they actually want a bigger buffer than we default to, let them have it! (if we can) */ newbuf = (unsigned int *) realloc(vid_stream->buf_start, (unsigned int) 4*sz); if (newbuf!=(unsigned int *)NULL) { vid_stream->max_buf_length=sz; vid_stream->buffer= (vid_stream->buffer-vid_stream->buf_start)+newbuf; vid_stream->buf_start=newbuf; }}#endif /* Parse off contrained parameter flag. */ get_bits1(data); if (data) { vid_stream->const_param_flag = TRUE; } else vid_stream->const_param_flag = FALSE; /* * If intra_quant_matrix_flag set, parse off intra quant matrix values. */ get_bits1(data); if (data) { for (i = 0; i < 64; i++) { get_bits8(data); vid_stream->intra_quant_matrix[zigzag[i][1]][zigzag[i][0]] = (unsigned char) data; } } /* * If non intra quant matrix flag set, parse off non intra quant matrix * values. */ get_bits1(data); if (data) { for (i = 0; i < 64; i++) { get_bits8(data); vid_stream->non_intra_quant_matrix[zigzag[i][1]][zigzag[i][0]] = (unsigned char) data; } } /* Go to next start code. */ next_start_code(vid_stream); /* * If next start code is extension start code, parse off extension data. */ if (next_bits(32, EXT_START_CODE, vid_stream)) { flush_bits32; if (vid_stream->ext_data != NULL) { free(vid_stream->ext_data); vid_stream->ext_data = NULL; } vid_stream->ext_data = get_ext_data(vid_stream); } /* If next start code is user start code, parse off user data. */ if (next_bits(32, USER_START_CODE, vid_stream)) { flush_bits32; if (vid_stream->user_data != NULL) { free(vid_stream->user_data); vid_stream->user_data = NULL; } vid_stream->user_data = get_ext_data(vid_stream); } return PARSE_OK;}/* *-------------------------------------------------------------- * * ParseGOP -- * * Parses of group of pictures header from bit stream * associated with vid_stream. * * Results: * Values in gop header placed into video stream structure. * * Side effects: * Bit stream irreversibly parsed. * *-------------------------------------------------------------- */static intParseGOP(vid_stream) VidStream *vid_stream;{ unsigned int data; /* Flush group of pictures start code. */ flush_bits32; /* Parse off drop frame flag. */ get_bits1(data); if (data) { vid_stream->group.drop_flag = TRUE; } else vid_stream->group.drop_flag = FALSE; /* Parse off hour component of time code. */ get_bits5(data); vid_stream->group.tc_hours = data; /* Parse off minute component of time code. */ get_bits6(data); vid_stream->group.tc_minutes = data; /* Flush marker bit. */ flush_bits(1); /* Parse off second component of time code. */ get_bits6(data); vid_stream->group.tc_seconds = data; /* Parse off picture count component of time code. */ get_bits6(data); vid_stream->group.tc_pictures = data; /* Parse off closed gop and broken link flags. */ get_bits2(data); if (data > 1) { vid_stream->group.closed_gop = TRUE; if (data > 2) { vid_stream->group.broken_link = TRUE; } else vid_stream->group.broken_link = FALSE; } else { vid_stream->group.closed_gop = FALSE; if (data) { vid_stream->group.broken_link = TRUE; } else vid_stream->group.broken_link = FALSE; } /* Goto next start code. */ next_start_code(vid_stream); /* If next start code is extension data, parse off extension data. */ if (next_bits(32, EXT_START_CODE, vid_stream)) { flush_bits32; if (vid_stream->group.ext_data != NULL) { free(vid_stream->group.ext_data); vid_stream->group.ext_data = NULL; } vid_stream->group.ext_data = get_ext_data(vid_stream); } /* If next start code is user data, parse off user data. */ if (next_bits(32, USER_START_CODE,vid_stream)) { flush_bits32; if (vid_stream->group.user_data != NULL) { free(vid_stream->group.user_data); vid_stream->group.user_data = NULL; } vid_stream->group.user_data = get_ext_data(vid_stream); } return PARSE_OK;}/* *-------------------------------------------------------------- * * ParsePicture -- * * Parses picture header. Marks picture to be presented * at particular time given a time stamp. * * Results: * Values from picture header put into video stream structure. * * Side effects: * Bit stream irreversibly parsed. * *-------------------------------------------------------------- */static intParsePicture(vid_stream, time_stamp) VidStream *vid_stream; TimeStamp time_stamp;{ unsigned int data; int i; /* Flush header start code. */ flush_bits32; /* Parse off temporal reference. */ get_bits10(data); vid_stream->picture.temp_ref = data; /* Parse of picture type. */ get_bits3(data); vid_stream->picture.code_type = data; if ((vid_stream->picture.code_type == B_TYPE) && (/* No_B_Flag || */ (vid_stream->future == NULL) || ((vid_stream->past == NULL) && !(vid_stream->group.closed_gop)))) /* According to 2-D.5.1 (p D-18) this is ok, if the refereneces are OK */ return SKIP_PICTURE; if ((vid_stream->picture.code_type == P_TYPE) && (No_P_Flag || (vid_stream->future == NULL))) return SKIP_PICTURE;#ifdef ANALYSIS StartTime(); stat_a[0].frametype = vid_stream->picture.code_type; stat_a[0].number = 1; stat_a[0].totsize = 45; pictureSizeCount = bitCountRead();#endif /* Parse off vbv buffer delay value. */ get_bits16(data); vid_stream->picture.vbv_delay = data; /* If P or B type frame... */ if ((vid_stream->picture.code_type == P_TYPE) || (vid_stream->picture.code_type == B_TYPE)) { /* Parse off forward vector full pixel flag. */ get_bits1(data); if (data) { vid_stream->picture.full_pel_forw_vector = TRUE; } else { vid_stream->picture.full_pel_forw_vector = FALSE; } /* Parse of forw_r_code. */ get_bits3(data); /* Decode forw_r_code into forw_r_size and forw_f. */ vid_stream->picture.forw_r_size = data - 1; vid_stream->picture.forw_f = (1 << vid_stream->picture.forw_r_size); } /* If B type frame... */ if (vid_stream->picture.code_type == B_TYPE) { /* Parse off back vector full pixel flag. */ get_bits1(data); if (data) vid_stream->picture.full_pel_back_vector = TRUE; else vid_stream->picture.full_pel_back_vector = FALSE; /* Parse off back_r_code. */ get_bits3(data); /* Decode back_r_code into back_r_size and back_f. */ vid_stream->picture.back_r_size = data - 1; vid_stream->picture.back_f = (1 << vid_stream->picture.back_r_size); } /* Get extra bit picture info. */ if (vid_stream->picture.extra_info != NULL) { free(vid_stream->picture.extra_info); vid_stream->picture.extra_info = NULL; } vid_stream->picture.extra_info = get_extra_bit_info(vid_stream); /* Goto next start code. */ next_start_code(vid_stream); /* If start code is extension start code, parse off extension data. */ if (next_bits(32, EXT_START_CODE, vid_stream)) { flush_bits32; if (vid_stream->picture.ext_data != NULL) { free(vid_stream->picture.ext_data); vid_stream->picture.ext_data = NULL; } vid_stream->picture.ext_data = get_ext_data(vid_stream); } /* If start code is user start code, parse off user data. */ if (next_bits(32, USER_START_CODE, vid_stream)) { flush_bits32; if (vid_stream->picture.user_data != NULL) { free(vid_stream->picture.user_data); vid_stream->picture.user_data = NULL; } vid_stream->picture.user_data = get_ext_data(vid_stream); } /* Find a pict image structure in ring buffer not currently locked. */ i = 0; while (vid_stream->ring[i]->locked != 0) { if (++i >= RING_BUF_SIZE) { perror("Fatal error. Ring buffer full."); exit(1); } } /* Set current pict image structure to the one just found in ring. */ vid_stream->current = vid_stream->ring[i]; /* Set time stamp. */ vid_stream->current->show_time = time_stamp; /* Reset past macroblock address field. */ vid_stream->mblock.past_mb_addr = -1; return PARSE_OK;}/* *-------------------------------------------------------------- * * ParseSlice -- * * Parses off slice header. * * Results: * Values found in slice header put into video stream structure. * * Side effects: * Bit stream irreversibly parsed. * *-------------------------------------------------------------- */static intParseSlice(vid_stream) VidStream *vid_stream;{ unsigned int data; /* Flush slice start code. */ flush_bits(24); /* Parse off slice vertical position. */ get_bits8(data); vid_stream->slice.vert_pos = data; /* Parse off quantization scale. */ get_bits5(data); vid_stream->slice.quant_scale = data; /* Parse off extra bit slice info. */ if (vid_stream->slice.extra_info != NULL) { free(vid_stream->slice.extra_info); vid_stream->slice.extra_info = NULL; } vid_stream->slice.extra_info = get_extra_bit_info(vid_stream); /* Reset past intrablock address. */ vid_stream->mblock.past_intra_addr = -2; /* Reset previous recon motion vectors. */ vid_stream->mblock.recon_right_for_prev = 0; vid_stream->mblock.recon_down_for_prev = 0; vid_stream->mblock.recon_right_back_prev = 0; vid_stream->mblock.recon_down_back_prev = 0; /* Reset macroblock address. */ vid_stream->mblock.mb_address = ((vid_stream->slice.vert_pos - 1) * vid_stream->mb_width) - 1; /* Reset past dct dc y, cr, and cb values. */ vid_stream->block.dct_dc_y_past = 1024 << 3; vid_stream->block.dct_dc_cr_past = 1024 << 3; vid_stream->block.dct_dc_cb_past = 1024 << 3; return PARSE_OK;}/* *-------------------------------------------------------------- * * ParseMacroBlock -- * * Parseoff macroblock. Reconstructs DCT values. Applies * inverse DCT, reconstructs motion vectors, calculates and * set pixel values for macroblock in current pict image * structure. * * Results: * Here's where everything really happens. Welcome to the * heart of darkness. * * Side effects: * Bit stream irreversibly parsed off. * *-------------------------------------------------------------- */static int
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -