mjpegdec.c File Reference

MJPEG decoder. More...

#include <assert.h>
#include "libavutil/imgutils.h"
#include "libavutil/opt.h"
#include "avcodec.h"
#include "dsputil.h"
#include "mjpeg.h"
#include "mjpegdec.h"
#include "jpeglsdec.h"

Go to the source code of this file.

Macros

#define REFINE_BIT(j)
 
#define ZERO_RUN
 
#define OFFSET(x)   offsetof(MJpegDecodeContext, x)
 
#define VD   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
 

Functions

static int build_vlc (VLC *vlc, const uint8_t *bits_table, const uint8_t *val_table, int nb_codes, int use_static, int is_ac)
 
static void build_basic_mjpeg_vlc (MJpegDecodeContext *s)
 
av_cold int ff_mjpeg_decode_init (AVCodecContext *avctx)
 
int ff_mjpeg_decode_dqt (MJpegDecodeContext *s)
 
int ff_mjpeg_decode_dht (MJpegDecodeContext *s)
 
int ff_mjpeg_decode_sof (MJpegDecodeContext *s)
 
static int mjpeg_decode_dc (MJpegDecodeContext *s, int dc_index)
 
static int decode_block (MJpegDecodeContext *s, DCTELEM *block, int component, int dc_index, int ac_index, int16_t *quant_matrix)
 
static int decode_dc_progressive (MJpegDecodeContext *s, DCTELEM *block, int component, int dc_index, int16_t *quant_matrix, int Al)
 
static int decode_block_progressive (MJpegDecodeContext *s, DCTELEM *block, uint8_t *last_nnz, int ac_index, int16_t *quant_matrix, int ss, int se, int Al, int *EOBRUN)
 
static int decode_block_refinement (MJpegDecodeContext *s, DCTELEM *block, uint8_t *last_nnz, int ac_index, int16_t *quant_matrix, int ss, int se, int Al, int *EOBRUN)
 
static int ljpeg_decode_rgb_scan (MJpegDecodeContext *s, int predictor, int point_transform)
 
static int ljpeg_decode_yuv_scan (MJpegDecodeContext *s, int predictor, int point_transform, int nb_components)
 
static av_always_inline void mjpeg_copy_block (uint8_t *dst, const uint8_t *src, int linesize, int lowres)
 
static int mjpeg_decode_scan (MJpegDecodeContext *s, int nb_components, int Ah, int Al, const uint8_t *mb_bitmask, const AVFrame *reference)
 
static int mjpeg_decode_scan_progressive_ac (MJpegDecodeContext *s, int ss, int se, int Ah, int Al, const uint8_t *mb_bitmask, const AVFrame *reference)
 
int ff_mjpeg_decode_sos (MJpegDecodeContext *s, const uint8_t *mb_bitmask, const AVFrame *reference)
 
static int mjpeg_decode_dri (MJpegDecodeContext *s)
 
static int mjpeg_decode_app (MJpegDecodeContext *s)
 
static int mjpeg_decode_com (MJpegDecodeContext *s)
 
static int find_marker (const uint8_t **pbuf_ptr, const uint8_t *buf_end)
 
int ff_mjpeg_find_marker (MJpegDecodeContext *s, const uint8_t **buf_ptr, const uint8_t *buf_end, const uint8_t **unescaped_buf_ptr, int *unescaped_buf_size)
 
int ff_mjpeg_decode_frame (AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
 
av_cold int ff_mjpeg_decode_end (AVCodecContext *avctx)
 

Variables

static const AVOption options []
 
static const AVClass mjpegdec_class
 
AVCodec ff_mjpeg_decoder
 
AVCodec ff_thp_decoder
 

Detailed Description

MJPEG decoder.

Definition in file mjpegdec.c.

Macro Definition Documentation

#define OFFSET (   x)    offsetof(MJpegDecodeContext, x)

Definition at line 1679 of file mjpegdec.c.

#define REFINE_BIT (   j)
Value:
{ \
UPDATE_CACHE(re, &s->gb); \
sign = block[j] >> 15; \
block[j] += SHOW_UBITS(re, &s->gb, 1) * \
((quant_matrix[j] ^ sign) - sign) << Al; \
LAST_SKIP_BITS(re, &s->gb, 1); \
}
#define UPDATE_CACHE(name, gb)
Definition: get_bits.h:160
static DCTELEM block[64]
Definition: dct-test.c:189
#define LAST_SKIP_BITS(name, gb, num)
Definition: get_bits.h:180
#define SHOW_UBITS(name, gb, num)
Definition: get_bits.h:186
float re
Definition: fft-test.c:61

Definition at line 565 of file mjpegdec.c.

Referenced by decode_block_refinement().

Definition at line 1680 of file mjpegdec.c.

#define ZERO_RUN
Value:
for (; ; i++) { \
if (i > last) { \
i += run; \
if (i > se) { \
av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i); \
return -1; \
} \
break; \
} \
j = s->scantable.permutated[i]; \
if (block[j]) \
else if (run-- == 0) \
break; \
}
uint8_t run
Definition: svq3.c:123
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:140
static DCTELEM block[64]
Definition: dct-test.c:189
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:111
#define REFINE_BIT(j)
Definition: mjpegdec.c:565

Definition at line 573 of file mjpegdec.c.

Referenced by decode_block_refinement().

Function Documentation

static void build_basic_mjpeg_vlc ( MJpegDecodeContext s)
static

Definition at line 69 of file mjpegdec.c.

Referenced by ff_mjpeg_decode_init().

static int build_vlc ( VLC vlc,
const uint8_t *  bits_table,
const uint8_t *  val_table,
int  nb_codes,
int  use_static,
int  is_ac 
)
static

Definition at line 45 of file mjpegdec.c.

Referenced by build_basic_mjpeg_vlc(), and ff_mjpeg_decode_dht().

static int decode_block ( MJpegDecodeContext s,
DCTELEM block,
int  component,
int  dc_index,
int  ac_index,
int16_t *  quant_matrix 
)
static

Definition at line 427 of file mjpegdec.c.

Referenced by mjpeg_decode_scan().

static int decode_block_progressive ( MJpegDecodeContext s,
DCTELEM block,
uint8_t *  last_nnz,
int  ac_index,
int16_t *  quant_matrix,
int  ss,
int  se,
int  Al,
int *  EOBRUN 
)
static

Definition at line 493 of file mjpegdec.c.

Referenced by mjpeg_decode_scan_progressive_ac().

static int decode_block_refinement ( MJpegDecodeContext s,
DCTELEM block,
uint8_t *  last_nnz,
int  ac_index,
int16_t *  quant_matrix,
int  ss,
int  se,
int  Al,
int *  EOBRUN 
)
static

Definition at line 591 of file mjpegdec.c.

Referenced by mjpeg_decode_scan_progressive_ac().

static int decode_dc_progressive ( MJpegDecodeContext s,
DCTELEM block,
int  component,
int  dc_index,
int16_t *  quant_matrix,
int  Al 
)
static

Definition at line 475 of file mjpegdec.c.

Referenced by mjpeg_decode_scan().

int ff_mjpeg_decode_dht ( MJpegDecodeContext s)
int ff_mjpeg_decode_dqt ( MJpegDecodeContext s)

Definition at line 129 of file mjpegdec.c.

Referenced by ff_mjpeg_decode_frame(), mjpegb_decode_frame(), and mxpeg_decode_frame().

av_cold int ff_mjpeg_decode_end ( AVCodecContext avctx)

Definition at line 1655 of file mjpegdec.c.

Referenced by mxpeg_decode_end().

int ff_mjpeg_decode_frame ( AVCodecContext avctx,
void data,
int *  data_size,
AVPacket avpkt 
)

Definition at line 1463 of file mjpegdec.c.

Referenced by sp5x_decode_frame().

av_cold int ff_mjpeg_decode_init ( AVCodecContext avctx)

Definition at line 85 of file mjpegdec.c.

Referenced by mxpeg_decode_init().

int ff_mjpeg_decode_sof ( MJpegDecodeContext s)

Definition at line 215 of file mjpegdec.c.

Referenced by ff_mjpeg_decode_frame(), mjpegb_decode_frame(), and mxpeg_decode_frame().

int ff_mjpeg_decode_sos ( MJpegDecodeContext s,
const uint8_t *  mb_bitmask,
const AVFrame reference 
)

Definition at line 1030 of file mjpegdec.c.

Referenced by ff_mjpeg_decode_frame(), mjpegb_decode_frame(), and mxpeg_decode_frame().

int ff_mjpeg_find_marker ( MJpegDecodeContext s,
const uint8_t **  buf_ptr,
const uint8_t *  buf_end,
const uint8_t **  unescaped_buf_ptr,
int *  unescaped_buf_size 
)

Definition at line 1375 of file mjpegdec.c.

Referenced by ff_mjpeg_decode_frame(), and mxpeg_decode_frame().

static int find_marker ( const uint8_t **  pbuf_ptr,
const uint8_t *  buf_end 
)
static

Definition at line 1347 of file mjpegdec.c.

Referenced by ff_mjpeg_find_marker().

static int ljpeg_decode_rgb_scan ( MJpegDecodeContext s,
int  predictor,
int  point_transform 
)
static

Definition at line 656 of file mjpegdec.c.

Referenced by ff_mjpeg_decode_sos().

static int ljpeg_decode_yuv_scan ( MJpegDecodeContext s,
int  predictor,
int  point_transform,
int  nb_components 
)
static

Definition at line 727 of file mjpegdec.c.

Referenced by ff_mjpeg_decode_sos().

static av_always_inline void mjpeg_copy_block ( uint8_t *  dst,
const uint8_t *  src,
int  linesize,
int  lowres 
)
static

Definition at line 816 of file mjpegdec.c.

Referenced by mjpeg_decode_scan(), and mjpeg_decode_scan_progressive_ac().

static int mjpeg_decode_app ( MJpegDecodeContext s)
static

Definition at line 1165 of file mjpegdec.c.

Referenced by ff_mjpeg_decode_frame().

static int mjpeg_decode_com ( MJpegDecodeContext s)
static

Definition at line 1310 of file mjpegdec.c.

Referenced by ff_mjpeg_decode_frame().

static int mjpeg_decode_dc ( MJpegDecodeContext s,
int  dc_index 
)
inlinestatic
static int mjpeg_decode_dri ( MJpegDecodeContext s)
static

Definition at line 1153 of file mjpegdec.c.

Referenced by ff_mjpeg_decode_frame().

static int mjpeg_decode_scan ( MJpegDecodeContext s,
int  nb_components,
int  Ah,
int  Al,
const uint8_t *  mb_bitmask,
const AVFrame reference 
)
static

Definition at line 831 of file mjpegdec.c.

Referenced by ff_mjpeg_decode_sos().

static int mjpeg_decode_scan_progressive_ac ( MJpegDecodeContext s,
int  ss,
int  se,
int  Ah,
int  Al,
const uint8_t *  mb_bitmask,
const AVFrame reference 
)
static

Definition at line 958 of file mjpegdec.c.

Referenced by ff_mjpeg_decode_sos().

Variable Documentation

AVCodec ff_mjpeg_decoder
Initial value:
= {
.name = "mjpeg",
.priv_data_size = sizeof(MJpegDecodeContext),
.capabilities = CODEC_CAP_DR1,
.max_lowres = 3,
.long_name = NULL_IF_CONFIG_SMALL("MJPEG (Motion JPEG)"),
.priv_class = &mjpegdec_class,
}
static const AVClass mjpegdec_class
Definition: mjpegdec.c:1687
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:228
static int init(AVCodecParserContext *s)
Definition: h264_parser.c:336
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:719
av_cold int ff_mjpeg_decode_end(AVCodecContext *avctx)
Definition: mjpegdec.c:1655
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:191
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:327
struct MJpegDecodeContext MJpegDecodeContext
av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
Definition: mjpegdec.c:85
int ff_mjpeg_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
Definition: mjpegdec.c:1463

Definition at line 1694 of file mjpegdec.c.

AVCodec ff_thp_decoder
Initial value:
= {
.name = "thp",
.id = CODEC_ID_THP,
.priv_data_size = sizeof(MJpegDecodeContext),
.capabilities = CODEC_CAP_DR1,
.max_lowres = 3,
.long_name = NULL_IF_CONFIG_SMALL("Nintendo Gamecube THP video"),
}
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:228
static int init(AVCodecParserContext *s)
Definition: h264_parser.c:336
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:719
av_cold int ff_mjpeg_decode_end(AVCodecContext *avctx)
Definition: mjpegdec.c:1655
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:191
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:327
struct MJpegDecodeContext MJpegDecodeContext
av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
Definition: mjpegdec.c:85
int ff_mjpeg_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
Definition: mjpegdec.c:1463

Definition at line 1708 of file mjpegdec.c.

const AVClass mjpegdec_class
static
Initial value:
= {
.class_name = "MJPEG decoder",
.item_name = av_default_item_name,
.option = options,
}
LIBAVUTIL_VERSION_INT
Definition: eval.c:50
av_default_item_name
Definition: dnxhdenc.c:43
static const AVOption options[]
Definition: mjpegdec.c:1681

Definition at line 1687 of file mjpegdec.c.

const AVOption options[]
static
Initial value:
= {
{ "extern_huff", "Use external huffman table.",
OFFSET(extern_huff), AV_OPT_TYPE_INT, { 0 }, 0, 1, VD },
{ NULL },
}
NULL
Definition: eval.c:50
#define OFFSET(x)
Definition: mjpegdec.c:1679
#define VD
Definition: mjpegdec.c:1680

Definition at line 1681 of file mjpegdec.c.