📄 video.c
字号:
if (vid_stream->future != NULL) { vid_stream->current = vid_stream->future; ExecuteDisplay(vid_stream); } /* Sequence done. Return NULL to caller to indicate just that. */ DestroyVidStream(curVidStream); mpeg_debug (("mpegVidRsrc: movie done, returning NULL\n")); return (NULL); break; case SEQ_START_CODE: /* Sequence start code. Parse sequence header. */ mpeg_debug (("SEQ_START_CODE\n")); if (ParseSeqHead(vid_stream) != PARSE_OK) goto error; /* * Return after sequence start code so that application above can use * info in header. */ goto done; case GOP_START_CODE: /* Group of Pictures start code. Parse gop header. */ mpeg_debug (("GOP_START_CODE\n")); if (ParseGOP(vid_stream) != PARSE_OK) goto error; case PICTURE_START_CODE: /* Picture start code. Parse picture header and first slice header. */ mpeg_debug (("PICTURE_START_CODE\n")); status = ParsePicture(vid_stream, time_stamp); if (status == SKIP_PICTURE) { next_start_code();/* fprintf(stderr, "Skipping picture..."); */ while (!next_bits(32, PICTURE_START_CODE)) { if (next_bits(32, GOP_START_CODE)) break; else if (next_bits(32, SEQ_END_CODE)) break; flush_bits(24); next_start_code(); }/* fprintf(stderr, "Done.\n"); */ goto done; } else if (status != PARSE_OK) goto error; if (ParseSlice(vid_stream) != PARSE_OK) goto error; break; default: /* Check for slice start code. */ mpeg_debug (("something else (%08x)\n", data)); if ((data >= SLICE_MIN_START_CODE) && (data <= SLICE_MAX_START_CODE)) { /* Slice start code. Parse slice header. */ if (ParseSlice(vid_stream) != PARSE_OK) goto error; } break; } /* Parse next MB_QUANTUM macroblocks. */ for (i = 0; i < MB_QUANTUM; i++) { /* Check to see if actually a startcode and not a macroblock. */ if (!next_bits(23, 0x00000000)) { /* Not start code. Parse Macroblock. */ if (ParseMacroBlock(vid_stream) != PARSE_OK) goto error; } else { /* Not macroblock, actually start code. Get start code. */ next_start_code(); show_bits32(data); /* * If start code is outside range of slice start codes, frame is * complete, display frame. */ if ((data < SLICE_MIN_START_CODE) || (data > SLICE_MAX_START_CODE)) { DoPictureDisplay(vid_stream); } break; } } /* Return pointer to video stream structure. */ goto done;error: fprintf(stderr, "Error!!!!\n"); next_start_code(); goto done;done: /* Copy global bit i/o variables back into vid_stream. */ vid_stream->buffer = bitBuffer; vid_stream->buf_length = bufLength; vid_stream->bit_offset = bitOffset; return vid_stream;}/* *-------------------------------------------------------------- * * ParseSeqHead -- * * Assumes bit stream is at the begining of the sequence * header start code. Parses off the sequence header. * * Results: * Fills the vid_stream structure with values derived and * decoded from the sequence header. Allocates the pict image * structures based on the dimensions of the image space * found in the sequence header. * * Side effects: * Bit stream irreversibly parsed off. * *-------------------------------------------------------------- */static intParseSeqHead(vid_stream) VidStream *vid_stream;{ unsigned int data; int i; /* Flush off sequence start code. */ flush_bits32; /* Get horizontal size of image space. */ get_bits12(data); vid_stream->h_size = data; /* Get vertical size of image space. */ get_bits12(data); vid_stream->v_size = data; /* Calculate macroblock width and height of image space. */ vid_stream->mb_width = (vid_stream->h_size + 15) / 16; vid_stream->mb_height = (vid_stream->v_size + 15) / 16; /* If dither type is MBORDERED allocate ditherFlags. */#if (ENABLE_DITHER) if (ditherType == MBORDERED_DITHER) { ditherFlags = (char *) malloc(vid_stream->mb_width*vid_stream->mb_height); }#endif /* Initialize lmaxx, lmaxy, cmaxx, cmaxy. */ lmaxx = vid_stream->mb_width*16-1; lmaxy = vid_stream->mb_height*16-1; cmaxx = vid_stream->mb_width*8-1; cmaxy = vid_stream->mb_height*8-1; /* * Initialize ring buffer of pict images now that dimensions of image space * are known. */ if (vid_stream->ring[0] == NULL) { for (i = 0; i < RING_BUF_SIZE; i++) { vid_stream->ring[i] = NewPictImage(vid_stream->mb_width * 16, vid_stream->mb_height * 16); } } /* 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; /* 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(); /* * If next start code is extension start code, parse off extension data. */ if (next_bits(32, EXT_START_CODE)) { 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(); } /* If next start code is user start code, parse off user data. */ if (next_bits(32, USER_START_CODE)) { 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(); } 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. WWWWWWOOOOOOOSSSSSSHHHHH!!! */ 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(); /* If next start code is extension data, parse off extension data. */ if (next_bits(32, EXT_START_CODE)) { 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(); } /* If next start code is user data, parse off user data. */ if (next_bits(32, USER_START_CODE)) { 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(); } 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->past == NULL) || (vid_stream->future == NULL))) return SKIP_PICTURE; if ((vid_stream->picture.code_type == P_TYPE) && (No_P_Flag || (vid_stream->future == NULL))) return SKIP_PICTURE; /* 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 == 2) || (vid_stream->picture.code_type == 3)) { /* 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 == 3) { /* 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(); /* Goto next start code. */ next_start_code();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -