On Sat, Oct 17, 2015 at 10:34:23PM +0200, Matthieu Bouron wrote:
> From: Matthieu Bouron <matthieu.bou...@stupeflix.com>
> 
> ---
>  libavcodec/mjpegdec.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
> index 1a86b7b..8a90e94 100644
> --- a/libavcodec/mjpegdec.c
> +++ b/libavcodec/mjpegdec.c
> @@ -2038,6 +2038,21 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx, void 
> *data, int *got_frame,
>              return AVERROR(ENOSYS);
>          }
>  
> +        if (avctx->skip_frame == AVDISCARD_ALL) {
> +            int i, found = 0;
> +            static const int sofs[] = { SOF0, SOF1, SOF2, SOF3, SOF48 };
> +
> +            for (i = 0; i < FF_ARRAY_ELEMS(sofs); i++) {
> +                if (start_code == sofs[i]) {
> +                    found = 1;
> +                    break;
> +                }
> +            }
> +            if (!found) {
> +                continue;
> +            }
> +        }
> +
>          switch (start_code) {
>          case SOI:
>              s->restart_interval = 0;
> @@ -2158,6 +2173,11 @@ eoi_parser:
>          av_log(avctx, AV_LOG_WARNING, "EOI missing, emulating\n");
>          goto eoi_parser;
>      }
> +
> +    if (avctx->skip_frame == AVDISCARD_ALL) {
> +        return buf_ptr - buf;
> +    }
> +
>      av_log(avctx, AV_LOG_FATAL, "No JPEG data found in image\n");
>      return AVERROR_INVALIDDATA;
>  fail:
> -- 
> 2.6.1
>

Patch updated, the markers are now properly skipped (which also fixes a
crash).

Matthieu
>From 0171134975fbb34531fcb06330dda83bdc164a41 Mon Sep 17 00:00:00 2001
From: Matthieu Bouron <matthieu.bou...@stupeflix.com>
Date: Fri, 9 Oct 2015 15:15:15 +0200
Subject: [PATCH 2/3] lavc/mjpegdec: honor skip_frame option

---
 libavcodec/mjpegdec.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 1a86b7b..a3015b9 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -2038,6 +2038,21 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
             return AVERROR(ENOSYS);
         }
 
+        if (avctx->skip_frame == AVDISCARD_ALL) {
+            int i, found = 0;
+            static const int sofs[] = { SOF0, SOF1, SOF2, SOF3, SOF48 };
+
+            for (i = 0; i < FF_ARRAY_ELEMS(sofs); i++) {
+                if (start_code == sofs[i]) {
+                    found = 1;
+                    break;
+                }
+            }
+            if (!found) {
+                goto skip;
+            }
+        }
+
         switch (start_code) {
         case SOI:
             s->restart_interval = 0;
@@ -2148,6 +2163,7 @@ eoi_parser:
             break;
         }
 
+skip:
         /* eof process start code */
         buf_ptr += (get_bits_count(&s->gb) + 7) / 8;
         av_log(avctx, AV_LOG_DEBUG,
@@ -2158,6 +2174,11 @@ eoi_parser:
         av_log(avctx, AV_LOG_WARNING, "EOI missing, emulating\n");
         goto eoi_parser;
     }
+
+    if (avctx->skip_frame == AVDISCARD_ALL) {
+        return buf_ptr - buf;
+    }
+
     av_log(avctx, AV_LOG_FATAL, "No JPEG data found in image\n");
     return AVERROR_INVALIDDATA;
 fail:
-- 
2.6.1

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

Reply via email to