av_log(s->avctx, AV_LOG_INFO, "AVID: len:%d %d\n", len, len > 14 ? buf[12] : -1);
}
+static void init_idct(AVCodecContext *avctx)
+{
+ MJpegDecodeContext *s = avctx->priv_data;
+
+ ff_idctdsp_init(&s->idsp, avctx);
+ ff_init_scantable(s->idsp.idct_permutation, &s->scantable,
+ ff_zigzag_direct);
+}
+
av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
{
MJpegDecodeContext *s = avctx->priv_data;
s->avctx = avctx;
ff_blockdsp_init(&s->bdsp, avctx);
ff_hpeldsp_init(&s->hdsp, avctx->flags);
- ff_idctdsp_init(&s->idsp, avctx);
- ff_init_scantable(s->idsp.idct_permutation, &s->scantable,
- ff_zigzag_direct);
+ init_idct(avctx);
s->buffer_size = 0;
s->buffer = NULL;
s->start_code = -1;
/* XXX: verify len field validity */
len = get_bits(&s->gb, 16);
- s->avctx->bits_per_raw_sample =
bits = get_bits(&s->gb, 8);
if (bits > 16 || bits < 1) {
return AVERROR_INVALIDDATA;
}
+ if (s->avctx->bits_per_raw_sample != bits) {
+ av_log(s->avctx, AV_LOG_INFO, "Changeing bps to %d\n", bits);
+ s->avctx->bits_per_raw_sample = bits;
+ init_idct(s->avctx);
+ }
if (s->pegasus_rct)
bits = 9;
if (bits == 9 && !s->pegasus_rct)
dc = mjpeg_decode_dc(s, s->dc_index[i]);
if(dc == 0xFFFFF)
return -1;
- if(bits<=8){
+ if ( h * mb_x + x >= s->width
+ || v * mb_y + y >= s->height) {
+ // Nothing to do
+ } else if (bits<=8) {
ptr = s->picture_ptr->data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
if(y==0 && toprow){
if(x==0 && leftcol){
dc = mjpeg_decode_dc(s, s->dc_index[i]);
if(dc == 0xFFFFF)
return -1;
- if(bits<=8){
+ if ( h * mb_x + x >= s->width
+ || v * mb_y + y >= s->height) {
+ // Nothing to do
+ } else if (bits<=8) {
ptr = s->picture_ptr->data[c] +
(linesize * (v * mb_y + y)) +
(h * mb_x + x); //FIXME optimize this crap
return AVERROR(ENOSYS);
}
+ if (avctx->skip_frame == AVDISCARD_ALL) {
+ switch(start_code) {
+ case SOF0:
+ case SOF1:
+ case SOF2:
+ case SOF3:
+ case SOF48:
+ case SOI:
+ case SOS:
+ case EOI:
+ break;
+ default:
+ goto skip;
+ }
+ }
+
switch (start_code) {
case SOI:
s->restart_interval = 0;
if (s->bottom_field == !s->interlace_polarity)
break;
}
+ if (avctx->skip_frame == AVDISCARD_ALL) {
+ s->got_picture = 0;
+ goto the_end_no_picture;
+ }
if ((ret = av_frame_ref(frame, s->picture_ptr)) < 0)
return ret;
*got_frame = 1;
goto the_end;
case SOS:
s->cur_scan++;
+ if (avctx->skip_frame == AVDISCARD_ALL)
+ break;
+
if ((ret = ff_mjpeg_decode_sos(s, NULL, 0, NULL)) < 0 &&
(avctx->err_recognition & AV_EF_EXPLODE))
goto fail;
break;
}
+skip:
/* eof process start code */
buf_ptr += (get_bits_count(&s->gb) + 7) / 8;
av_log(avctx, AV_LOG_DEBUG,
av_dict_copy(avpriv_frame_get_metadatap(data), s->exif_metadata, 0);
av_dict_free(&s->exif_metadata);
+the_end_no_picture:
av_log(avctx, AV_LOG_DEBUG, "decode frame unused %"PTRDIFF_SPECIFIER" bytes\n",
buf_end - buf_ptr);
// return buf_end - buf_ptr;
.capabilities = AV_CODEC_CAP_DR1,
.max_lowres = 3,
.priv_class = &mjpegdec_class,
- .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
+ .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
+ FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
};
#endif
#if CONFIG_THP_DECODER