[FFmpeg-devel] [PATCH 4/9] lavc/mpegvideo_parser: reduce variable scopes

Anton Khirnov anton at khirnov.net
Sun Oct 1 15:55:47 EEST 2023


Drop some variables only used in a switch().
---
 libavcodec/mpegvideo_parser.c | 33 ++++++++++++++-------------------
 1 file changed, 14 insertions(+), 19 deletions(-)

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



More information about the ffmpeg-devel mailing list