// Return TRUE if all was read. FALSE if a problem occured: // If a bitstream syntax problem occured the bitstream will // point to after the problem, in case we run out of data the bitstream // will point to where we want to restart after getting more. static int read_seq_info(struct bitstream *esstream) { dbg_print(DMT_VERBOSE, "Read Sequence Info\n"); // We only get here after seeing that start code if (next_u32(esstream) != 0xB3010000) // LSB first (0x000001B3) fatal(EXIT_BUG_BUG, "read_seq_info: Impossible!"); // If we get here esstream points to the start of a sequence_header_code // should we run out of data in esstream this is where we want to restart // after getting more. unsigned char *video_seq_start = esstream->pos; sequence_header(esstream); sequence_ext(esstream); // FIXME: if sequence extension is missing this is not MPEG-2, // or broken. Set bitstream error. //extension_and_user_data(esstream); if (esstream->error) return 0; if (esstream->bitsleft < 0) { init_bitstream(esstream, video_seq_start, esstream->end); return 0; } dbg_print(DMT_VERBOSE, "Read Sequence Info - processed\n\n"); return 1; }
/* * decode headers from one input stream * until an End of Sequence or picture start code * is found */ int Get_Hdr() { unsigned int code; for (;;) { /* look for next_start_code */ next_start_code(); code = Get_Bits32(); switch (code) { case SEQUENCE_HEADER_CODE: sequence_header(); break; case GROUP_START_CODE: group_of_pictures_header(); break; case PICTURE_START_CODE: picture_header(); return 1; break; case SEQUENCE_END_CODE: return 0; break; default: if (!Quiet_Flag) fprintf(stderr,"Unexpected next_start_code %08x (ignored)\n",code); break; } } }
// Return TRUE if all was read. FALSE if a problem occured: // If a bitstream syntax problem occured the bitstream will // point to after the problem, in case we run out of data the bitstream // will point to where we want to restart after getting more. static int read_seq_info(struct lib_cc_decode *ctx, struct bitstream *esstream) { debug("Read Sequence Info\n"); // We only get here after seeing that start code if (next_u32(esstream) != 0xB3010000) // LSB first (0x000001B3) fatal(CCX_COMMON_EXIT_BUG_BUG, "read_seq_info: next_u32(esstream) != 0xB3010000. Please file a bug report in GitHub.\n"); // If we get here esstream points to the start of a sequence_header_code // should we run out of data in esstream this is where we want to restart // after getting more. unsigned char *video_seq_start = esstream->pos; sequence_header(ctx, esstream); sequence_ext(ctx, esstream); // FIXME: if sequence extension is missing this is not MPEG-2, // or broken. Set bitstream error. //extension_and_user_data(esstream); if (esstream->error) return 0; if (esstream->bitsleft < 0) { init_bitstream(esstream, video_seq_start, esstream->end); return 0; } debug("Read Sequence Info - processed\n\n"); return 1; }
int main(int argc, char* argv[]) { char tmpStr[256]; col = 0; verbose_level = 1; sequence_headers = 0; sequence_extensions = 0; user_data_bytes = 0; sequence_scalable_extension_present = 0; printf("bbVINFO - version 1.7, by Brent Beyeler ([email protected])\n"); printf(" speed increases by, Apachez and Christian Vogelgsang\n\n"); if (argc < 2) { printf("\nbbVINFO is an MPEG video stream analyzer\n\n"); printf("Usage: bbVINFO MPEG video filename <verbose level 1..3, default = 1>\n\n"); printf("Examples:\n"); printf(" To list all packet start codes (excluding slice codes) to file test.txt\n"); printf(" bbVINFO test.mpg 1 > test.txt\n\n"); printf(" To list all packets (excluding slice packets) in detail\n"); printf(" bbVINFO test.vob 2\n\n"); printf(" To list all packets (including slice packets) in detail to file test.txt\n"); printf(" bbVINFO test.mpg 3 > test.txt\n\n"); exit (1); } init_getbits(argv[1]); strcpy(tmpStr, argv[1]); // strlwr(tmpStr); if (argc > 2) { sscanf(argv[2], "%d", &verbose_level); if (verbose_level < 1) verbose_level = 1; if (verbose_level > 3) verbose_level = 3; } next_start_code(); if (getbits(8) != SEQUENCE_HEADER_CODE) { printf("\nFile is not an MPEG Video Stream\n"); exit(1); } next_start_code(); if (getbits(8) != EXTENSION_START_CODE) mpeg2 = 0; else mpeg2 = 1; printf("\nFile %s is an MPEG-%d video stream\n", argv[1], mpeg2 + 1); finish_getbits(); init_getbits(argv[1]); next_start_code(); sequence_header(); if (mpeg2) sequence_extension(); do { extension_and_user_data(0); do { if (nextbits(8) == GROUP_START_CODE) { group_of_pictures_header(); extension_and_user_data(1); } picture_header(); if (mpeg2) picture_coding_extension(); extension_and_user_data(2); picture_data(); } while ((nextbits(8) == PICTURE_START_CODE) || (nextbits(8) == GROUP_START_CODE)); if (nextbits(8) != SEQUENCE_END_CODE) { sequence_header(); if (mpeg2) sequence_extension(); } } while (nextbits(8) != SEQUENCE_END_CODE); zprintf(1, "\nsequence_end_code = 0x000001%02X\n", getbits(8)); finish_getbits(); return (0); }
// Open function modified by Donald Graft as part of fix for dropped frames and random frame access. int CMPEG2Decoder::Open(const char *path) { char buf[2048], *buf_p; Choose_Prediction(this->fastMC); char ID[80], PASS[80] = "DGIndexProjectFile16"; DWORD i, j, size, code, type, tff, rff, film, ntsc, gop, top, bottom, mapping; int repeat_on, repeat_off, repeat_init; int vob_id, cell_id; __int64 position; int HadI; CMPEG2Decoder* out = this; out->VF_File = fopen(path, "r"); if (fgets(ID, 79, out->VF_File)==NULL) return 1; if (strstr(ID, "DGIndexProjectFile") == NULL) return 5; if (strncmp(ID, PASS, 20)) return 2; fscanf(out->VF_File, "%d\n", &File_Limit); i = File_Limit; while (i) { Infilename[File_Limit-i] = (char*)aligned_malloc(_MAX_PATH, 16); fgets(Infilename[File_Limit-i], _MAX_PATH - 1, out->VF_File); // Strip newline. Infilename[File_Limit-i][strlen(Infilename[File_Limit-i])-1] = 0; if (PathIsRelative(Infilename[File_Limit-i])) { char *p, d2v_stem[_MAX_PATH], open_path[_MAX_PATH]; if (PathIsRelative(path)) { GetCurrentDirectory(_MAX_PATH, d2v_stem); if (*(d2v_stem + strlen(d2v_stem) - 1) != '\\') strcat(d2v_stem, "\\"); strcat(d2v_stem, path); } else { strcpy(d2v_stem, path); } p = d2v_stem + strlen(d2v_stem); while (*p != '\\' && p != d2v_stem) p--; if (p != d2v_stem) { p[1] = 0; strcat(d2v_stem, Infilename[File_Limit-i]); PathCanonicalize(open_path, d2v_stem); if ((Infile[File_Limit-i] = _open(open_path, _O_RDONLY | _O_BINARY))==-1) return 3; } else { // This should never happen because the code should guarantee that d2v_stem has a '\' character. return 3; } } else { if ((Infile[File_Limit-i] = _open(Infilename[File_Limit-i], _O_RDONLY | _O_BINARY))==-1) return 3; } i--; } fscanf(out->VF_File, "\nStream_Type=%d\n", &SystemStream_Flag); if (SystemStream_Flag == 2) { fscanf(out->VF_File, "MPEG2_Transport_PID=%x,%x,%x\n", &MPEG2_Transport_VideoPID, &MPEG2_Transport_AudioPID, &MPEG2_Transport_PCRPID); fscanf(out->VF_File, "Transport_Packet_Size=%d\n", &TransportPacketSize); } fscanf(out->VF_File, "MPEG_Type=%d\n", &mpeg_type); fscanf(out->VF_File, "iDCT_Algorithm=%d\n", &IDCT_Flag); switch (IDCT_Flag) { case IDCT_MMX: idctFunc = MMX_IDCT; break; case IDCT_SSEMMX: idctFunc = SSEMMX_IDCT; if (!cpu.ssemmx) { IDCT_Flag = IDCT_MMX; idctFunc = MMX_IDCT; } break; case IDCT_FPU: if (!fpuinit) { Initialize_FPU_IDCT(); fpuinit = true; } idctFunc = FPU_IDCT; break; case IDCT_REF: if (!refinit) { refinit = true; } idctFunc = REF_IDCT; break; case IDCT_SSE2MMX: idctFunc = SSE2MMX_IDCT; if (!cpu.sse2mmx) { IDCT_Flag = IDCT_SSEMMX; idctFunc = SSEMMX_IDCT; if (!cpu.ssemmx) { IDCT_Flag = IDCT_MMX; idctFunc = MMX_IDCT; } } break; case IDCT_SKALSSE: idctFunc = Skl_IDct16_Sparse_SSE; //Skl_IDct16_SSE; if (!cpu.ssemmx) { IDCT_Flag = IDCT_MMX; idctFunc = MMX_IDCT; } break; case IDCT_SIMPLEIDCT: idctFunc = simple_idct_mmx; if (!cpu.ssemmx) { IDCT_Flag = IDCT_MMX; idctFunc = MMX_IDCT; } break; } File_Flag = 0; _lseeki64(Infile[0], 0, SEEK_SET); Initialize_Buffer(); do { if (Fault_Flag == OUT_OF_BITS) return 4; next_start_code(); code = Get_Bits(32); } while (code!=SEQUENCE_HEADER_CODE); sequence_header(); mb_width = (horizontal_size+15)/16; mb_height = progressive_sequence ? (vertical_size+15)/16 : 2*((vertical_size+31)/32); QP = (int*)aligned_malloc(sizeof(int)*mb_width*mb_height, 32); backwardQP = (int*)aligned_malloc(sizeof(int)*mb_width*mb_height, 32); auxQP = (int*)aligned_malloc(sizeof(int)*mb_width*mb_height, 32); Coded_Picture_Width = 16 * mb_width; Coded_Picture_Height = 16 * mb_height; Chroma_Width = (chroma_format==CHROMA444) ? Coded_Picture_Width : Coded_Picture_Width>>1; Chroma_Height = (chroma_format!=CHROMA420) ? Coded_Picture_Height : Coded_Picture_Height>>1; block_count = ChromaFormat[chroma_format]; for (i=0; i<8; i++) { p_block[i] = (short *)aligned_malloc(sizeof(short)*64 + 64, 32); block[i] = (short *)((long)p_block[i] + 64 - (long)p_block[i]%64); } for (i=0; i<3; i++) { if (i==0) size = Coded_Picture_Width * Coded_Picture_Height; else size = Chroma_Width * Chroma_Height; backward_reference_frame[i] = (unsigned char*)aligned_malloc(2*size+4096, 32); //>>> cheap safety bump forward_reference_frame[i] = (unsigned char*)aligned_malloc(2*size+4096, 32); auxframe[i] = (unsigned char*)aligned_malloc(2*size+4096, 32); } fscanf(out->VF_File, "YUVRGB_Scale=%d\n", &pc_scale); fscanf(out->VF_File, "Luminance_Filter=%d,%d\n", &i, &j); if (i==0 && j==0) Luminance_Flag = 0; else { Luminance_Flag = 1; InitializeLuminanceFilter(i, j); } fscanf(out->VF_File, "Clipping=%d,%d,%d,%d\n", &Clip_Left, &Clip_Right, &Clip_Top, &Clip_Bottom); fscanf(out->VF_File, "Aspect_Ratio=%s\n", Aspect_Ratio); fscanf(out->VF_File, "Picture_Size=%dx%d\n", &D2V_Width, &D2V_Height); Clip_Width = Coded_Picture_Width; Clip_Height = Coded_Picture_Height; if (upConv > 0 && chroma_format == 1) { // these are labeled u422 and v422, but I'm only using them as a temporary // storage place for YV12 chroma before upsampling to 4:2:2 so that's why its // /4 and not /2 -- (tritical - 1/05/2005) int tpitch = (((Chroma_Width+15)>>4)<<4); // mod 16 chroma pitch needed to work with YV12PICTs u422 = (unsigned char*)aligned_malloc((tpitch * Coded_Picture_Height / 2)+2048, 32); v422 = (unsigned char*)aligned_malloc((tpitch * Coded_Picture_Height / 2)+2048, 32); auxFrame1 = create_YV12PICT(Coded_Picture_Height,Coded_Picture_Width,chroma_format+1); auxFrame2 = create_YV12PICT(Coded_Picture_Height,Coded_Picture_Width,chroma_format+1); }