From 1f0c7020a1f08a7cbec2d629759ca33ea92bd89d Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 27 Aug 2011 10:16:14 +0200 Subject: [PATCH] mjpegdec: add 'extern_huff' private option. Deprecate CODEC_FLAG_EXTERN_HUFF --- libavcodec/avcodec.h | 2 ++ libavcodec/mjpegdec.c | 20 ++++++++++++++++++++ libavcodec/mjpegdec.h | 5 +++++ libavcodec/options.c | 2 ++ libavcodec/version.h | 3 +++ 5 files changed, 32 insertions(+) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 6cee81e460..f65c14d9f8 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -581,7 +581,9 @@ typedef struct RcOverride{ #define CODEC_FLAG_INPUT_PRESERVED 0x0100 #define CODEC_FLAG_PASS1 0x0200 ///< Use internal 2pass ratecontrol in first pass mode. #define CODEC_FLAG_PASS2 0x0400 ///< Use internal 2pass ratecontrol in second pass mode. +#if FF_API_MJPEG_GLOBAL_OPTS #define CODEC_FLAG_EXTERN_HUFF 0x1000 ///< Use external Huffman table (for MJPEG). +#endif #define CODEC_FLAG_GRAY 0x2000 ///< Only decode/encode grayscale. #define CODEC_FLAG_EMU_EDGE 0x4000 ///< Don't draw edges. #define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding. diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index b9db777fe1..168cc0bece 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -34,6 +34,7 @@ #include #include "libavutil/imgutils.h" +#include "libavutil/opt.h" #include "avcodec.h" #include "dsputil.h" #include "mjpeg.h" @@ -96,7 +97,11 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx) build_basic_mjpeg_vlc(s); +#if FF_API_MJPEG_GLOBAL_OPTS if (avctx->flags & CODEC_FLAG_EXTERN_HUFF) + s->extern_huff = 1; +#endif + if (s->extern_huff) { av_log(avctx, AV_LOG_INFO, "mjpeg: using external huffman table\n"); init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8); @@ -1597,6 +1602,20 @@ av_cold int ff_mjpeg_decode_end(AVCodecContext *avctx) return 0; } +#define OFFSET(x) offsetof(MJpegDecodeContext, x) +#define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM +static const AVOption options[] = { + { "extern_huff", "Use external huffman table.", OFFSET(extern_huff), FF_OPT_TYPE_INT, { 0 }, 0, 1, VD }, + { NULL }, +}; + +static const AVClass mjpegdec_class = { + .class_name = "MJPEG decoder", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + AVCodec ff_mjpeg_decoder = { .name = "mjpeg", .type = AVMEDIA_TYPE_VIDEO, @@ -1608,6 +1627,7 @@ AVCodec ff_mjpeg_decoder = { .capabilities = CODEC_CAP_DR1, .max_lowres = 3, .long_name = NULL_IF_CONFIG_SMALL("MJPEG (Motion JPEG)"), + .priv_class = &mjpegdec_class, }; AVCodec ff_thp_decoder = { diff --git a/libavcodec/mjpegdec.h b/libavcodec/mjpegdec.h index 52c256ee2f..bfa987d3c5 100644 --- a/libavcodec/mjpegdec.h +++ b/libavcodec/mjpegdec.h @@ -29,6 +29,8 @@ #ifndef AVCODEC_MJPEGDEC_H #define AVCODEC_MJPEGDEC_H +#include "libavutil/log.h" + #include "avcodec.h" #include "get_bits.h" #include "dsputil.h" @@ -36,6 +38,7 @@ #define MAX_COMPONENTS 4 typedef struct MJpegDecodeContext { + AVClass *class; AVCodecContext *avctx; GetBitContext gb; @@ -106,6 +109,8 @@ typedef struct MJpegDecodeContext { uint16_t (*ljpeg_buffer)[4]; unsigned int ljpeg_buffer_size; + + int extern_huff; } MJpegDecodeContext; int ff_mjpeg_decode_init(AVCodecContext *avctx); diff --git a/libavcodec/options.c b/libavcodec/options.c index 7828dc9473..843064fcf5 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -87,7 +87,9 @@ static const AVOption options[]={ {"input_preserved", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_INPUT_PRESERVED }, INT_MIN, INT_MAX, 0, "flags"}, {"pass1", "use internal 2pass ratecontrol in first pass mode", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_PASS1 }, INT_MIN, INT_MAX, 0, "flags"}, {"pass2", "use internal 2pass ratecontrol in second pass mode", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_PASS2 }, INT_MIN, INT_MAX, 0, "flags"}, +#if FF_API_MJPEG_GLOBAL_OPTS {"extern_huff", "use external huffman table (for mjpeg)", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_EXTERN_HUFF }, INT_MIN, INT_MAX, 0, "flags"}, +#endif {"gray", "only decode/encode grayscale", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_GRAY }, INT_MIN, INT_MAX, V|E|D, "flags"}, {"emu_edge", "don't draw edges", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_EMU_EDGE }, INT_MIN, INT_MAX, 0, "flags"}, {"psnr", "error[?] variables will be set during encoding", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_PSNR }, INT_MIN, INT_MAX, V|E, "flags"}, diff --git a/libavcodec/version.h b/libavcodec/version.h index 7abd993b98..d4c358e182 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -95,5 +95,8 @@ #ifndef FF_API_SNOW_GLOBAL_OPTS #define FF_API_SNOW_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 54) #endif +#ifndef FF_API_MJPEG_GLOBAL_OPTS +#define FF_API_MJPEG_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 54) +#endif #endif /* AVCODEC_VERSION_H */