Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Anton Khirnov <anton@khirnov.net>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 4/9] lavc/mpegvideo_parser: reduce variable scopes
Date: Sun,  1 Oct 2023 14:55:47 +0200
Message-ID: <20231001125552.23976-4-anton@khirnov.net> (raw)
In-Reply-To: <20231001125552.23976-1-anton@khirnov.net>

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

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2023-10-01 12:56 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-01 12:55 [FFmpeg-devel] [PATCH 1/9] lavfi/yadif: update output frame durations Anton Khirnov
2023-10-01 12:55 ` [FFmpeg-devel] [PATCH 2/9] lavf/demux: restrict video parser duration handling to just GIF Anton Khirnov
2023-10-01 12:55 ` [FFmpeg-devel] [PATCH 3/9] lavf/gifdec: do not mark as notimestamps Anton Khirnov
2023-10-01 12:55 ` Anton Khirnov [this message]
2023-10-01 20:28   ` [FFmpeg-devel] [PATCH 4/9] lavc/mpegvideo_parser: reduce variable scopes Michael Niedermayer
2023-10-01 12:55 ` [FFmpeg-devel] [PATCH 5/9] lavc/mpegvideo_parser: improve exporting field-coding information Anton Khirnov
2023-10-01 12:55 ` [FFmpeg-devel] [PATCH 6/9] lavc/mpeg4videodec: do not invent a framerate from guessed numbers Anton Khirnov
2023-10-01 13:14   ` Andreas Rheinhardt
2023-10-02  8:56     ` Anton Khirnov
2023-10-01 12:55 ` [FFmpeg-devel] [PATCH 7/9] fftools/ffmpeg_dec: disregard demuxer timestamps for NOTIMESTAMPS formats Anton Khirnov
2023-10-01 13:18   ` Andreas Rheinhardt
2023-10-02  8:59     ` Anton Khirnov
2023-10-01 12:55 ` [FFmpeg-devel] [PATCH 8/9] fftools/ffmpeg_enc: do not round frame durations prematurely Anton Khirnov
2023-10-01 12:55 ` [FFmpeg-devel] [PATCH 9/9] fftools/ffmpeg: move derivation of frame duration from filter framerate Anton Khirnov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231001125552.23976-4-anton@khirnov.net \
    --to=anton@khirnov.net \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git