1 /*
2 * MxPEG decoder
3 * Copyright (c) 2011 Anatoly Nenashev
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 /**
24 * @file
25 * MxPEG decoder
26 */
27
31
44
46 {
49 int i;
50
53
54 for (i = 0; i < 2; ++i)
56
60
61 return 0;
62 }
63
65 {
67
73 }
74
77 }
78
80 const uint8_t *buf_ptr,
int buf_size)
81 {
83 if (buf_size < 2)
84 return 0;
87
88 return 0;
89 }
90
92 const uint8_t *buf_ptr,
int buf_size)
93 {
94 unsigned bitmask_size, mb_count;
95 int i;
96
100
101 bitmask_size = (mb_count + 7) >> 3;
102 if (bitmask_size > buf_size - 12) {
104 "MXM bitmask is not complete\n");
106 }
107
114 "MXM bitmask memory allocation error\n");
116 }
117
122 "Completion bitmask memory allocation error\n");
124 }
125
127 }
128
129 memcpy(s->
mxm_bitmask, buf_ptr + 12, bitmask_size);
131
133 uint8_t completion_check = 0xFF;
134 for (i = 0; i < bitmask_size; ++i) {
137 }
139 }
140
141 return 0;
142 }
143
145 const uint8_t *buf_ptr,
int buf_size)
146 {
148 if (buf_size < 2)
149 return 0;
151 if (len > 14 && len <= buf_size && !strncmp(buf_ptr + 2, "MXM", 3)) {
153 }
155
157 }
158
161 {
165 "Picture dimensions stored in SOF and MXM mismatch\n");
167 }
168
169 if (reference_ptr->
data[0]) {
170 int i;
175 "Dimensions of current and reference picture mismatch\n");
177 }
178 }
179 }
180
181 return 0;
182 }
183
185 void *
data,
int *got_frame,
187 {
189 int buf_size = avpkt->
size;
192 const uint8_t *buf_end, *buf_ptr;
193 const uint8_t *unescaped_buf_ptr;
194 int unescaped_buf_size;
197
199 buf_end = buf + buf_size;
202 while (buf_ptr < buf_end) {
204 &unescaped_buf_ptr, &unescaped_buf_size);
205 if (start_code < 0)
206 goto the_end;
207 {
209
210 if (start_code >=
APP0 && start_code <=
APP15) {
212 }
213
214 switch (start_code) {
217 goto the_end;
218 break;
220 goto the_end;
223 if (ret < 0) {
225 "quantization table decode error\n");
227 }
228 break;
231 if (ret < 0) {
233 "huffman table decode error\n");
235 }
236 break;
239 unescaped_buf_size);
240 if (ret < 0)
242 break;
246 if (ret < 0) {
248 "SOF data decode error\n");
250 }
253 "Interlaced mode not supported in MxPEG\n");
255 }
257 break;
261 "Can not process SOS without SOF data, skipping\n");
262 break;
263 }
267 "First picture has no SOF, skipping\n");
268 break;
269 }
272 "Non-key frame has no MXM, skipping\n");
273 break;
274 }
275 /* use stored SOF data to allocate current picture */
283 } else {
286 }
287
291 break;
292
293 /* allocate dummy reference picture if needed */
294 if (!reference_ptr->
data[0] &&
298
302 } else {
306 }
307
308 break;
309 }
310
312 }
313
314 }
315
316 the_end:
319 if (ret < 0)
321 *got_frame = 1;
322
325
329 else
330 *got_frame = 0;
331 }
332 }
333
334 return buf_ptr -
buf;
335 }
336
347 .max_lowres = 3,
349 };
uint8_t * completion_bitmask
This structure describes decoded (raw) audio or video data.
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)
static int mxpeg_check_dimensions(MXpegDecodeContext *s, MJpegDecodeContext *jpg, AVFrame *reference_ptr)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
int ff_mjpeg_decode_dht(MJpegDecodeContext *s)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
MJPEG encoder and decoder.
static int mxpeg_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static int get_bits_count(const GetBitContext *s)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int mxpeg_decode_mxm(MXpegDecodeContext *s, const uint8_t *buf_ptr, int buf_size)
#define AV_EF_EXPLODE
abort decoding on minor error detection
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
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. ...
const char * name
Name of the codec implementation.
int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
enum AVPictureType pict_type
Picture type of the frame.
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
static av_cold int mxpeg_decode_init(AVCodecContext *avctx)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
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 const uint8_t start_code[]
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static int mxpeg_decode_com(MXpegDecodeContext *s, const uint8_t *buf_ptr, int buf_size)
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)
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
common internal api header.
static av_cold int mxpeg_decode_end(AVCodecContext *avctx)
static int mxpeg_decode_app(MXpegDecodeContext *s, const uint8_t *buf_ptr, int buf_size)
int got_picture
we found a SOF and picture is valid, too.
int key_frame
1 -> keyframe, 0-> not
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)
This structure stores compressed data.
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...