1 /*
2 * Apple MJPEG-B decoder
3 * Copyright (c) 2002 Alex Beregszaszi
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * Apple MJPEG-B decoder.
25 */
26
27 #include <inttypes.h>
28
33
36 if(offs >= size){
38 return 0;
39 }
40 return offs;
41 }
42
44 void *
data,
int *got_frame,
46 {
48 int buf_size = avpkt->
size;
50 const uint8_t *buf_end, *buf_ptr;
52 uint32_t dqt_offs, dht_offs, sof_offs, sos_offs, second_field_offs;
53 uint32_t field_size, sod_offs;
54 int ret;
55
57 buf_end = buf + buf_size;
59
61 /* reset on every SOI */
65
66 if (buf_end - buf_ptr >= 1 << 28)
68
69 init_get_bits(&hgb, buf_ptr,
/*buf_size*/(buf_end - buf_ptr)*8);
70
72
74 {
77 }
78
81 skip_bits(&hgb, 32);
/* padded field size */
82 second_field_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"second_field_offs is %d and size is %d\n");
84 second_field_offs);
85
86 dqt_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"dqt is %d and size is %d\n");
88 if (dqt_offs)
89 {
90 init_get_bits(&s->
gb, buf_ptr+dqt_offs, (buf_end - (buf_ptr+dqt_offs))*8);
95 }
96
97 dht_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"dht is %d and size is %d\n");
99 if (dht_offs)
100 {
101 init_get_bits(&s->
gb, buf_ptr+dht_offs, (buf_end - (buf_ptr+dht_offs))*8);
104 }
105
106 sof_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"sof is %d and size is %d\n");
108 if (sof_offs)
109 {
110 init_get_bits(&s->
gb, buf_ptr+sof_offs, (buf_end - (buf_ptr+sof_offs))*8);
113 return -1;
114 }
115
116 sos_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"sos is %d and size is %d\n");
118 sod_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"sof is %d and size is %d\n");
120 if (sos_offs)
121 {
123 8 *
FFMIN(field_size, buf_end - buf_ptr - sos_offs));
129 }
130
133 /* if not bottom field, do not output image yet */
135 {
136 buf_ptr = buf + second_field_offs;
138 }
139 }
140
141 //XXX FIXME factorize, this looks very similar to the EOI code
142
145 return buf_size;
146 }
147
149 return ret;
150 *got_frame = 1;
151
155 }
156
157 return buf_size;
158 }
159
170 .max_lowres = 3,
172 };
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
ptrdiff_t const GLvoid * data
#define AV_LOG_WARNING
Something somehow does not look correct.
static av_cold int init(AVCodecContext *avctx)
int ff_mjpeg_decode_dqt(MJpegDecodeContext *s)
int qscale[4]
quantizer scale calculated from quant_matrixes
int ff_mjpeg_decode_dht(MJpegDecodeContext *s)
MJPEG encoder and decoder.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
AVCodec ff_mjpegb_decoder
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
av_cold int ff_mjpeg_decode_end(AVCodecContext *avctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
const char * name
Name of the codec implementation.
int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
#define AV_EF_EXPLODE
abort decoding on minor error detection
static int read_header(FFV1Context *f)
static int mjpegb_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Libavcodec external API header.
main external API structure.
static void skip_bits(GetBitContext *s, int n)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
int ff_mjpeg_decode_sos(MJpegDecodeContext *s, const uint8_t *mb_bitmask, int mb_bitmask_size, const AVFrame *reference)
av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
common internal api header.
#define MKBETAG(a, b, c, d)
int got_picture
we found a SOF and picture is valid, too.
static uint32_t read_offs(AVCodecContext *avctx, GetBitContext *gb, uint32_t size, const char *err_msg)
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.