54 for (
i = 0;
i < 2; ++
i)
70 if (!
s->picture[0] || !
s->picture[1])
73 s->jpg.picture_ptr =
s->picture[0];
78 const uint8_t *buf_ptr,
int buf_size)
90 const uint8_t *buf_ptr,
int buf_size)
92 unsigned bitmask_size, mb_count;
97 mb_count =
s->mb_width *
s->mb_height;
99 bitmask_size = (mb_count + 7) >> 3;
100 if (bitmask_size > buf_size - 12) {
102 "MXM bitmask is not complete\n");
106 if (
s->bitmask_size != bitmask_size) {
110 if (!
s->mxm_bitmask) {
112 "MXM bitmask memory allocation error\n");
118 if (!
s->completion_bitmask) {
120 "Completion bitmask memory allocation error\n");
124 s->bitmask_size = bitmask_size;
127 memcpy(
s->mxm_bitmask, buf_ptr + 12, bitmask_size);
128 s->got_mxm_bitmask = 1;
130 if (!
s->has_complete_frame) {
131 uint8_t completion_check = 0xFF;
132 for (
i = 0;
i < bitmask_size; ++
i) {
133 s->completion_bitmask[
i] |=
s->mxm_bitmask[
i];
134 completion_check &=
s->completion_bitmask[
i];
136 s->has_complete_frame = !(completion_check ^ 0xFF);
143 const uint8_t *buf_ptr,
int buf_size)
149 if (
len > 14 &&
len <= buf_size && !strncmp(buf_ptr + 2,
"MXM", 3)) {
160 if ((jpg->
width + 0x0F)>>4 !=
s->mb_width ||
161 (jpg->
height + 0x0F)>>4 !=
s->mb_height) {
163 "Picture dimensions stored in SOF and MXM mismatch\n");
167 if (reference_ptr->
data[0]) {
173 "Dimensions of current and reference picture mismatch\n");
183 void *
data,
int *got_frame,
187 int buf_size = avpkt->
size;
190 const uint8_t *buf_end, *buf_ptr;
191 const uint8_t *unescaped_buf_ptr;
192 int unescaped_buf_size;
200 buf_end = buf + buf_size;
202 s->got_mxm_bitmask = 0;
203 s->got_sof_data = !!
s->got_sof_data;
204 while (buf_ptr < buf_end) {
206 &unescaped_buf_ptr, &unescaped_buf_size);
227 "quantization table decode error\n");
235 "huffman table decode error\n");
246 if (
s->got_sof_data > 1) {
248 "Multiple SOF in a frame\n");
254 "SOF data decode error\n");
260 "Interlaced mode not supported in MxPEG\n");
267 if (!
s->got_sof_data) {
269 "Can not process SOS without SOF data, skipping\n");
275 "First picture has no SOF, skipping\n");
278 if (!
s->got_mxm_bitmask){
280 "Non-key frame has no MXM, skipping\n");
296 if (
s->got_mxm_bitmask) {
297 AVFrame *reference_ptr =
s->picture[
s->picture_index ^ 1];
302 if (!reference_ptr->
data[0] &&
331 s->picture_index ^= 1;
334 if (!
s->has_complete_frame) {
335 if (!
s->got_mxm_bitmask)
336 s->has_complete_frame = 1;
342 return buf_ptr - buf;
#define AV_EF_EXPLODE
abort decoding on minor error detection
static av_cold int init(AVCodecContext *avctx)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
static void skip_bits(GetBitContext *s, int n)
static int get_bits_count(const GetBitContext *s)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
@ AVDISCARD_ALL
discard all
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
MJPEG encoder and decoder.
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)
av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
int ff_mjpeg_decode_dqt(MJpegDecodeContext *s)
av_cold int ff_mjpeg_decode_end(AVCodecContext *avctx)
int ff_mjpeg_decode_sos(MJpegDecodeContext *s, const uint8_t *mb_bitmask, int mb_bitmask_size, const AVFrame *reference)
int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
int ff_mjpeg_decode_dht(MJpegDecodeContext *s)
static av_cold int mxpeg_decode_init(AVCodecContext *avctx)
static int mxpeg_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static int mxpeg_check_dimensions(MXpegDecodeContext *s, MJpegDecodeContext *jpg, AVFrame *reference_ptr)
static int mxpeg_decode_com(MXpegDecodeContext *s, const uint8_t *buf_ptr, int buf_size)
static int mxpeg_decode_mxm(MXpegDecodeContext *s, const uint8_t *buf_ptr, int buf_size)
static int mxpeg_decode_app(MXpegDecodeContext *s, const uint8_t *buf_ptr, int buf_size)
static av_cold int mxpeg_decode_end(AVCodecContext *avctx)
main external API structure.
enum AVDiscard skip_frame
Skip decoding for selected frames.
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int key_frame
1 -> keyframe, 0-> not
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
enum AVPictureType pict_type
Picture type of the frame.
This structure stores compressed data.
int got_picture
we found a SOF and picture is valid, too.
uint8_t * completion_bitmask