X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fmjpegbdec.c;h=66cf2d43ce16ab46425014b7daf047fc33519b49;hb=eac3ac1fe0774b65316852616b2672702dbc3f31;hp=8c8514f2c58005f4c02615f85dc5015e6ca2387f;hpb=36ef5369ee9b336febc2c270f8718cec4476cb85;p=ffmpeg diff --git a/libavcodec/mjpegbdec.c b/libavcodec/mjpegbdec.c index 8c8514f2c58..66cf2d43ce1 100644 --- a/libavcodec/mjpegbdec.c +++ b/libavcodec/mjpegbdec.c @@ -24,6 +24,8 @@ * Apple MJPEG-B decoder. */ +#include + #include "avcodec.h" #include "mjpeg.h" #include "mjpegdec.h" @@ -38,17 +40,17 @@ static uint32_t read_offs(AVCodecContext *avctx, GetBitContext *gb, uint32_t siz } static int mjpegb_decode_frame(AVCodecContext *avctx, - void *data, int *data_size, + void *data, int *got_frame, 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; - AVFrame *picture = data; GetBitContext hgb; /* for the header */ uint32_t dqt_offs, dht_offs, sof_offs, sos_offs, second_field_offs; uint32_t field_size, sod_offs; + int ret; buf_ptr = buf; buf_end = buf + buf_size; @@ -73,13 +75,14 @@ read_header: } field_size = get_bits_long(&hgb, 32); /* field size */ - av_log(avctx, AV_LOG_DEBUG, "field size: 0x%x\n", field_size); + av_log(avctx, AV_LOG_DEBUG, "field size: 0x%"PRIx32"\n", field_size); skip_bits(&hgb, 32); /* padded field size */ second_field_offs = read_offs(avctx, &hgb, buf_end - buf_ptr, "second_field_offs is %d and size is %d\n"); - av_log(avctx, AV_LOG_DEBUG, "second field offs: 0x%x\n", second_field_offs); + av_log(avctx, AV_LOG_DEBUG, "second field offs: 0x%"PRIx32"\n", + second_field_offs); dqt_offs = read_offs(avctx, &hgb, buf_end - buf_ptr, "dqt is %d and size is %d\n"); - av_log(avctx, AV_LOG_DEBUG, "dqt offs: 0x%x\n", dqt_offs); + av_log(avctx, AV_LOG_DEBUG, "dqt offs: 0x%"PRIx32"\n", dqt_offs); if (dqt_offs) { init_get_bits(&s->gb, buf_ptr+dqt_offs, (buf_end - (buf_ptr+dqt_offs))*8); @@ -90,7 +93,7 @@ read_header: } dht_offs = read_offs(avctx, &hgb, buf_end - buf_ptr, "dht is %d and size is %d\n"); - av_log(avctx, AV_LOG_DEBUG, "dht offs: 0x%x\n", dht_offs); + av_log(avctx, AV_LOG_DEBUG, "dht offs: 0x%"PRIx32"\n", dht_offs); if (dht_offs) { init_get_bits(&s->gb, buf_ptr+dht_offs, (buf_end - (buf_ptr+dht_offs))*8); @@ -99,7 +102,7 @@ read_header: } sof_offs = read_offs(avctx, &hgb, buf_end - buf_ptr, "sof is %d and size is %d\n"); - av_log(avctx, AV_LOG_DEBUG, "sof offs: 0x%x\n", sof_offs); + av_log(avctx, AV_LOG_DEBUG, "sof offs: 0x%"PRIx32"\n", sof_offs); if (sof_offs) { init_get_bits(&s->gb, buf_ptr+sof_offs, (buf_end - (buf_ptr+sof_offs))*8); @@ -109,9 +112,9 @@ read_header: } sos_offs = read_offs(avctx, &hgb, buf_end - buf_ptr, "sos is %d and size is %d\n"); - av_log(avctx, AV_LOG_DEBUG, "sos offs: 0x%x\n", sos_offs); + av_log(avctx, AV_LOG_DEBUG, "sos offs: 0x%"PRIx32"\n", sos_offs); sod_offs = read_offs(avctx, &hgb, buf_end - buf_ptr, "sof is %d and size is %d\n"); - av_log(avctx, AV_LOG_DEBUG, "sod offs: 0x%x\n", sod_offs); + av_log(avctx, AV_LOG_DEBUG, "sod offs: 0x%"PRIx32"\n", sod_offs); if (sos_offs) { init_get_bits(&s->gb, buf_ptr + sos_offs, @@ -136,17 +139,13 @@ read_header: //XXX FIXME factorize, this looks very similar to the EOI code - *picture= *s->picture_ptr; - *data_size = sizeof(AVFrame); - - if(!s->lossless){ - picture->quality= FFMAX3(s->qscale[0], s->qscale[1], s->qscale[2]); - picture->qstride= 0; - picture->qscale_table= s->qscale_table; - memset(picture->qscale_table, picture->quality, (s->width+15)/16); - if(avctx->debug & FF_DEBUG_QP) - av_log(avctx, AV_LOG_DEBUG, "QP: %d\n", picture->quality); - picture->quality*= FF_QP2LAMBDA; + if ((ret = av_frame_ref(data, s->picture_ptr)) < 0) + return ret; + *got_frame = 1; + + if (!s->lossless && avctx->debug & FF_DEBUG_QP) { + av_log(avctx, AV_LOG_DEBUG, "QP: %d\n", + FFMAX3(s->qscale[0], s->qscale[1], s->qscale[2])); } return buf_size; @@ -154,6 +153,7 @@ read_header: AVCodec ff_mjpegb_decoder = { .name = "mjpegb", + .long_name = NULL_IF_CONFIG_SMALL("Apple MJPEG-B"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_MJPEGB, .priv_data_size = sizeof(MJpegDecodeContext), @@ -161,5 +161,4 @@ AVCodec ff_mjpegb_decoder = { .close = ff_mjpeg_decode_end, .decode = mjpegb_decode_frame, .capabilities = CODEC_CAP_DR1, - .long_name = NULL_IF_CONFIG_SMALL("Apple MJPEG-B"), };