/*
* MJPEG decoder
- * Copyright (c) 2000, 2001 Fabrice Bellard.
+ * Copyright (c) 2000, 2001 Fabrice Bellard
* Copyright (c) 2003 Alex Beregszaszi
* Copyright (c) 2003-2004 Michael Niedermayer
*
*/
/**
- * @file mjpegdec.c
+ * @file libavcodec/mjpegdec.c
* MJPEG decoder.
*/
s->start_code = -1;
s->first_picture = 1;
s->org_height = avctx->coded_height;
+ avctx->chroma_sample_location = AVCHROMA_LOC_CENTER;
build_basic_mjpeg_vlc(s);
}
s->picture.pict_type= FF_I_TYPE;
s->picture.key_frame= 1;
+ s->got_picture = 1;
for(i=0; i<3; i++){
s->linesize[i]= s->picture.linesize[i] << s->interlaced;
}
}
}
- /* (< 1350) buggy workaround for Spectralfan.mov, should be fixed */
- if (s->restart_interval && (s->restart_interval < 1350) &&
- !--s->restart_count) {
+
+ if (s->restart_interval && !--s->restart_count) {
align_get_bits(&s->gb);
skip_bits(&s->gb, 16); /* skip RSTn */
for (i=0; i<nb_components; i++) /* reset dc */
int ff_mjpeg_decode_sos(MJpegDecodeContext *s)
{
int len, nb_components, i, h, v, predictor, point_transform;
- int vmax, hmax, index, id;
+ int index, id;
const int block_size= s->lossless ? 1 : 8;
int ilv, prev_shift;
av_log(s->avctx, AV_LOG_ERROR, "decode_sos: invalid len (%d)\n", len);
return -1;
}
- vmax = 0;
- hmax = 0;
for(i=0;i<nb_components;i++) {
id = get_bits(&s->gb, 8) - 1;
av_log(s->avctx, AV_LOG_DEBUG, "component: %d\n", id);
if (s->dc_index[i] < 0 || s->ac_index[i] < 0 ||
s->dc_index[i] >= 4 || s->ac_index[i] >= 4)
goto out_of_range;
-#if 0 //buggy
- switch(s->start_code)
- {
- case SOF0:
- if (dc_index[i] > 1 || ac_index[i] > 1)
- goto out_of_range;
- break;
- case SOF1:
- case SOF2:
- if (dc_index[i] > 3 || ac_index[i] > 3)
- goto out_of_range;
- break;
- case SOF3:
- if (dc_index[i] > 3 || ac_index[i] != 0)
- goto out_of_range;
- break;
- }
-#endif
+ if (!s->vlcs[0][s->dc_index[i]].table || !s->vlcs[1][s->ac_index[i]].table)
+ goto out_of_range;
}
predictor= get_bits(&s->gb, 8); /* JPEG Ss / lossless JPEG predictor /JPEG-LS NEAR */
skip_bits(&s->gb, 8);
if(s->lossless){
- if(ENABLE_JPEGLS_DECODER && s->ls){
+ if(CONFIG_JPEGLS_DECODER && s->ls){
// for(){
// reset_ls_coding_parameters(s, 0);
/* buggy AVID, it puts EOI only at every 10th frame */
/* also this fourcc is used by non-avid files too, it holds some
informations, but it's always present in AVID creates files */
- if (id == ff_get_fourcc("AVI1"))
+ if (id == AV_RL32("AVI1"))
{
/* structure:
4bytes AVI1
// len -= 2;
- if (id == ff_get_fourcc("JFIF"))
+ if (id == AV_RL32("JFIF"))
{
int t_w, t_h, v1, v2;
skip_bits(&s->gb, 8); /* the trailing zero-byte */
goto out;
}
- if (id == ff_get_fourcc("Adob") && (get_bits(&s->gb, 8) == 'e'))
+ if (id == AV_RL32("Adob") && (get_bits(&s->gb, 8) == 'e'))
{
if (s->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(s->avctx, AV_LOG_INFO, "mjpeg: Adobe header found\n");
goto out;
}
- if (id == ff_get_fourcc("LJIF")){
+ if (id == AV_RL32("LJIF")){
if (s->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(s->avctx, AV_LOG_INFO, "Pegasus lossless jpeg header found\n");
skip_bits(&s->gb, 16); /* version ? */
id = (get_bits(&s->gb, 16) << 16) | get_bits(&s->gb, 16);
id = be2me_32(id);
len -= 4;
- if (id == ff_get_fourcc("mjpg")) /* Apple MJPEG-A */
+ if (id == AV_RL32("mjpg")) /* Apple MJPEG-A */
{
#if 0
skip_bits(&s->gb, 32); /* field size */
}
val = -1;
found:
-#ifdef DEBUG
- av_log(NULL, AV_LOG_VERBOSE, "find_marker skipped %d bytes\n", skipped);
-#endif
+ dprintf(NULL, "find_marker skipped %d bytes\n", skipped);
*pbuf_ptr = buf_ptr;
return val;
}
int ff_mjpeg_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
- const uint8_t *buf, int buf_size)
+ AVPacket *avpkt)
{
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
MJpegDecodeContext *s = avctx->priv_data;
const uint8_t *buf_end, *buf_ptr;
int start_code;
AVFrame *picture = data;
+ s->got_picture = 0; // picture from previous image can not be reused
buf_ptr = buf;
buf_end = buf + buf_size;
while (buf_ptr < buf_end) {
}
break;
case SOF0:
+ case SOF1:
s->lossless=0;
s->ls=0;
s->progressive=0;
return -1;
break;
case LSE:
- if (!ENABLE_JPEGLS_DECODER || ff_jpegls_decode_lse(s) < 0)
+ if (!CONFIG_JPEGLS_DECODER || ff_jpegls_decode_lse(s) < 0)
return -1;
break;
case EOI:
if ((s->buggy_avid && !s->interlaced) || s->restart_interval)
break;
eoi_parser:
+ if (!s->got_picture) {
+ av_log(avctx, AV_LOG_WARNING, "Found EOI before any SOF, ignoring\n");
+ break;
+ }
{
if (s->interlaced) {
s->bottom_field ^= 1;
}
break;
case SOS:
+ if (!s->got_picture) {
+ av_log(avctx, AV_LOG_WARNING, "Can not process SOS before SOF, skipping\n");
+ break;
+ }
ff_mjpeg_decode_sos(s);
/* buggy avid puts EOI every 10-20th frame */
/* if restart period is over process EOI */
case DRI:
mjpeg_decode_dri(s);
break;
- case SOF1:
case SOF5:
case SOF6:
case SOF7:
}
}
}
+ if (s->got_picture) {
+ av_log(avctx, AV_LOG_WARNING, "EOI missing, emulating\n");
+ goto eoi_parser;
+ }
+ av_log(avctx, AV_LOG_FATAL, "No JPEG data found in image\n");
+ return -1;
the_end:
av_log(avctx, AV_LOG_DEBUG, "mjpeg decode frame unused %td bytes\n", buf_end - buf_ptr);
// return buf_end - buf_ptr;
MJpegDecodeContext *s = avctx->priv_data;
int i, j;
+ if (s->picture.data[0])
+ avctx->release_buffer(avctx, &s->picture);
+
av_free(s->buffer);
av_free(s->qscale_table);