lavc/mpegvideo_parser: reduce variable scopes

Drop some variables only used in a switch().
pull/390/head
Anton Khirnov 1 year ago
parent 3562993d82
commit 2c9eb49122
  1. 33
      libavcodec/mpegvideo_parser.c

@ -105,22 +105,17 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s,
{ {
struct MpvParseContext *pc = s->priv_data; struct MpvParseContext *pc = s->priv_data;
const uint8_t *buf_end = buf + buf_size; const uint8_t *buf_end = buf + buf_size;
uint32_t start_code; int bytes_left;
int frame_rate_index, ext_type, bytes_left;
int frame_rate_ext_n, frame_rate_ext_d;
int top_field_first, repeat_first_field, progressive_frame;
int horiz_size_ext, vert_size_ext, bit_rate_ext;
int did_set_size=0; int did_set_size=0;
int set_dim_ret = 0; int set_dim_ret = 0;
int bit_rate = 0; int bit_rate = 0;
int vbv_delay = 0; int vbv_delay = 0;
int chroma_format;
enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE; enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE;
//FIXME replace the crap with get_bits() //FIXME replace the crap with get_bits()
s->repeat_pict = 0; s->repeat_pict = 0;
while (buf < buf_end) { while (buf < buf_end) {
start_code= -1; uint32_t start_code = -1;
buf= avpriv_find_start_code(buf, buf_end, &start_code); buf= avpriv_find_start_code(buf, buf_end, &start_code);
bytes_left = buf_end - buf; bytes_left = buf_end - buf;
switch(start_code) { switch(start_code) {
@ -134,6 +129,8 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s,
break; break;
case SEQ_START_CODE: case SEQ_START_CODE:
if (bytes_left >= 7) { if (bytes_left >= 7) {
int frame_rate_index;
pc->width = (buf[0] << 4) | (buf[1] >> 4); pc->width = (buf[0] << 4) | (buf[1] >> 4);
pc->height = ((buf[1] & 0x0f) << 8) | buf[2]; pc->height = ((buf[1] & 0x0f) << 8) | buf[2];
if(!avctx->width || !avctx->height || !avctx->coded_width || !avctx->coded_height){ if(!avctx->width || !avctx->height || !avctx->coded_width || !avctx->coded_height){
@ -154,20 +151,18 @@ FF_ENABLE_DEPRECATION_WARNINGS
break; break;
case EXT_START_CODE: case EXT_START_CODE:
if (bytes_left >= 1) { if (bytes_left >= 1) {
ext_type = (buf[0] >> 4); switch (buf[0] >> 4) { // ext_type
switch(ext_type) {
case 0x1: /* sequence extension */ case 0x1: /* sequence extension */
if (bytes_left >= 6) { if (bytes_left >= 6) {
horiz_size_ext = ((buf[1] & 1) << 1) | (buf[2] >> 7); int horiz_size_ext = ((buf[1] & 1) << 1) | (buf[2] >> 7);
vert_size_ext = (buf[2] >> 5) & 3; int vert_size_ext = (buf[2] >> 5) & 3;
bit_rate_ext = ((buf[2] & 0x1F)<<7) | (buf[3]>>1); int bit_rate_ext = ((buf[2] & 0x1F)<<7) | (buf[3]>>1);
frame_rate_ext_n = (buf[5] >> 5) & 3; int frame_rate_ext_n = (buf[5] >> 5) & 3;
frame_rate_ext_d = (buf[5] & 0x1f); int frame_rate_ext_d = (buf[5] & 0x1f);
pc->progressive_sequence = buf[1] & (1 << 3); pc->progressive_sequence = buf[1] & (1 << 3);
avctx->has_b_frames= !(buf[5] >> 7); avctx->has_b_frames= !(buf[5] >> 7);
chroma_format = (buf[1] >> 1) & 3; switch ((buf[1] >> 1) & 3) { // chroma_format
switch (chroma_format) {
case 1: pix_fmt = AV_PIX_FMT_YUV420P; break; case 1: pix_fmt = AV_PIX_FMT_YUV420P; break;
case 2: pix_fmt = AV_PIX_FMT_YUV422P; break; case 2: pix_fmt = AV_PIX_FMT_YUV422P; break;
case 3: pix_fmt = AV_PIX_FMT_YUV444P; break; case 3: pix_fmt = AV_PIX_FMT_YUV444P; break;
@ -190,9 +185,9 @@ FF_ENABLE_DEPRECATION_WARNINGS
break; break;
case 0x8: /* picture coding extension */ case 0x8: /* picture coding extension */
if (bytes_left >= 5) { if (bytes_left >= 5) {
top_field_first = buf[3] & (1 << 7); int top_field_first = buf[3] & (1 << 7);
repeat_first_field = buf[3] & (1 << 1); int repeat_first_field = buf[3] & (1 << 1);
progressive_frame = buf[4] & (1 << 7); int progressive_frame = buf[4] & (1 << 7);
/* check if we must repeat the frame */ /* check if we must repeat the frame */
if (repeat_first_field) { if (repeat_first_field) {

Loading…
Cancel
Save