// Return TRUE if the data parsing finished, FALSE otherwise. // estream->pos is advanced. Data is only processed if esstream->error // is FALSE, parsing can set esstream->error to TRUE. static int sequence_header(struct bitstream *esstream) { dbg_print(DMT_VERBOSE, "Sequence header\n"); if (esstream->error || esstream->bitsleft <= 0) return 0; // We only get here after seeing that start code if (read_u32(esstream) != 0xB3010000) // LSB first (0x000001B3) fatal(EXIT_BUG_BUG, "Impossible!"); unsigned hor_size = (unsigned) read_bits(esstream,12); unsigned vert_size = (unsigned) read_bits(esstream,12); unsigned aspect_ratio = (unsigned) read_bits(esstream,4); unsigned frame_rate = (unsigned) read_bits(esstream,4); // Discard some information read_bits(esstream, 18+1+10+1); // load_intra_quantiser_matrix if (read_bits(esstream,1)) skip_bits(esstream, 8*64); // load_non_intra_quantiser_matrix if (read_bits(esstream,1)) skip_bits(esstream, 8*64); if (esstream->bitsleft < 0) return 0; // If we got the whole sequence, process if (hor_size!=current_hor_size || vert_size!=current_vert_size || aspect_ratio!=current_aspect_ratio || frame_rate!=current_frame_rate) { // If horizontal/vertical size, framerate and/or aspect // ratio are ilegal, we discard the // whole sequence info. if (vert_size >= 288 && vert_size <= 1088 && hor_size >= 352 && hor_size <= 1920 && hor_size / vert_size >= 352/576 && hor_size / vert_size <= 2 && frame_rate>0 && frame_rate<9 && aspect_ratio>0 && aspect_ratio<5) { mprint ("\n\nNew video information found"); if (pts_set==2) { unsigned cur_sec = (unsigned) ((current_pts - min_pts) / MPEG_CLOCK_FREQ); mprint (" at %02u:%02u",cur_sec/60, cur_sec % 60); } mprint ("\n"); mprint ("[%u * %u] [AR: %s] [FR: %s]", hor_size,vert_size, aspect_ratio_types[aspect_ratio], framerates_types[frame_rate]); // No newline, force the output of progressive info in picture // info part. current_progressive_sequence = 2; current_hor_size=hor_size; current_vert_size=vert_size; current_aspect_ratio=aspect_ratio; current_frame_rate=frame_rate; current_fps = framerates_values[current_frame_rate]; activity_video_info (hor_size,vert_size, aspect_ratio_types[aspect_ratio], framerates_types[frame_rate]); } else { dbg_print(DMT_VERBOSE, "\nInvalid sequence header:\n"); dbg_print(DMT_VERBOSE, "V: %u H: %u FR: %u AS: %u\n", vert_size, hor_size, frame_rate, aspect_ratio); esstream->error = 1; return 0; } } // Read complete return 1; }
// Return TRUE if the data parsing finished, FALSE otherwise. // estream->pos is advanced. Data is only processed if esstream->error // is FALSE, parsing can set esstream->error to TRUE. static int sequence_header(struct lib_cc_decode *ctx, struct bitstream *esstream) { debug("Sequence header\n"); if (esstream->error || esstream->bitsleft <= 0) return 0; // We only get here after seeing that start code if (read_u32(esstream) != 0xB3010000) // LSB first (0x000001B3) fatal(CCX_COMMON_EXIT_BUG_BUG, "sequence_header: read_u32(esstream) != 0xB3010000. Please file a bug report in GitHub.\n"); unsigned hor_size = (unsigned) read_bits(esstream,12); unsigned vert_size = (unsigned) read_bits(esstream,12); unsigned aspect_ratio = (unsigned) read_bits(esstream,4); unsigned frame_rate = (unsigned) read_bits(esstream,4); #if 0 ctx->freport.width = hor_size; ctx->freport.height = vert_size; ctx->freport.aspect_ratio = aspect_ratio; ctx->freport.frame_rate = frame_rate; #endif // Discard some information read_bits(esstream, 18+1+10+1); // load_intra_quantiser_matrix if (read_bits(esstream,1)) skip_bits(esstream, 8*64); // load_non_intra_quantiser_matrix if (read_bits(esstream,1)) skip_bits(esstream, 8*64); if (esstream->bitsleft < 0) return 0; // If we got the whole sequence, process if (hor_size!= ctx->current_hor_size || vert_size!= ctx->current_vert_size || aspect_ratio!=ctx->current_aspect_ratio || frame_rate!= ctx->current_frame_rate) { // If horizontal/vertical size, framerate and/or aspect // ratio are ilegal, we discard the // whole sequence info. if (vert_size >= 288 && vert_size <= 1088 && hor_size >= 352 && hor_size <= 1920 && (hor_size*100) / vert_size >= (352*100)/576 && // The weird *100 is to avoid using floats hor_size / vert_size <= 2 && frame_rate>0 && frame_rate<9 && aspect_ratio>0 && aspect_ratio<5) { mprint ("\n\nNew video information found"); mprint ("\n"); mprint ("[%u * %u] [AR: %s] [FR: %s]", hor_size,vert_size, aspect_ratio_types[aspect_ratio], framerates_types[frame_rate]); // No newline, force the output of progressive info in picture // info part. ctx->current_progressive_sequence = 2; ctx->current_hor_size = hor_size; ctx->current_vert_size = vert_size; ctx->current_aspect_ratio = aspect_ratio; ctx->current_frame_rate=frame_rate; current_fps = framerates_values[ctx->current_frame_rate]; activity_video_info (hor_size,vert_size, aspect_ratio_types[aspect_ratio], framerates_types[frame_rate]); } else { debug("\nInvalid sequence header:\n"); debug("V: %u H: %u FR: %u AS: %u\n", vert_size, hor_size, frame_rate, aspect_ratio); esstream->error = 1; return 0; } } // Read complete return 1; }