X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=libavcodec%2Flcldec.c;h=4d97948042008df1a4bcda13da094aea08359699;hb=e76f2d11970484266e67a12961f2339a5c2fccf9;hp=d2482138abedb8b6937defb5590faae06633385a;hpb=36ef5369ee9b336febc2c270f8718cec4476cb85;p=ffmpeg diff --git a/libavcodec/lcldec.c b/libavcodec/lcldec.c index d2482138abe..4d979480420 100644 --- a/libavcodec/lcldec.c +++ b/libavcodec/lcldec.c @@ -41,10 +41,11 @@ #include #include +#include "libavutil/mem.h" #include "avcodec.h" #include "bytestream.h" +#include "internal.h" #include "lcl.h" -#include "libavutil/lzo.h" #if CONFIG_ZLIB_DECODER #include @@ -54,8 +55,6 @@ * Decoder context */ typedef struct LclDecContext { - AVFrame pic; - // Image type int imgtype; // Compression type @@ -131,7 +130,7 @@ static int zlib_decomp(AVCodecContext *avctx, const uint8_t *src, int src_len, i int zret = inflateReset(&c->zstream); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); - return -1; + return AVERROR_UNKNOWN; } c->zstream.next_in = src; c->zstream.avail_in = src_len; @@ -140,12 +139,12 @@ static int zlib_decomp(AVCodecContext *avctx, const uint8_t *src, int src_len, i zret = inflate(&c->zstream, Z_FINISH); if (zret != Z_OK && zret != Z_STREAM_END) { av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret); - return -1; + return AVERROR_UNKNOWN; } if (expected != (unsigned int)c->zstream.total_out) { av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %lu)\n", expected, c->zstream.total_out); - return -1; + return AVERROR_UNKNOWN; } return c->zstream.total_out; } @@ -157,8 +156,9 @@ static int zlib_decomp(AVCodecContext *avctx, const uint8_t *src, int src_len, i * Decode a frame * */ -static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) +static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; LclDecContext * const c = avctx->priv_data; @@ -171,21 +171,16 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac unsigned int height = avctx->height; // Real image height unsigned int mszh_dlen; unsigned char yq, y1q, uq, vq; - int uqvq; + int uqvq, ret; unsigned int mthread_inlen, mthread_outlen; unsigned int len = buf_size; - if(c->pic.data[0]) - avctx->release_buffer(avctx, &c->pic); - - c->pic.reference = 0; - c->pic.buffer_hints = FF_BUFFER_HINTS_VALID; - if(avctx->get_buffer(avctx, &c->pic) < 0){ + if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } - outptr = c->pic.data[0]; // Output image pointer + outptr = frame->data[0]; // Output image pointer /* Decompress frame */ switch (avctx->codec_id) { @@ -201,14 +196,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac if (mthread_outlen != mszh_dlen) { av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%d != %d)\n", mthread_outlen, mszh_dlen); - return -1; + return AVERROR_INVALIDDATA; } mszh_dlen = mszh_decomp(encoded + 8 + mthread_inlen, len - 8 - mthread_inlen, c->decomp_buf + mthread_outlen, c->decomp_size - mthread_outlen); if (mthread_outlen != mszh_dlen) { av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %d)\n", mthread_outlen, mszh_dlen); - return -1; + return AVERROR_INVALIDDATA; } encoded = c->decomp_buf; len = c->decomp_size; @@ -217,7 +212,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac if (c->decomp_size != mszh_dlen) { av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %d)\n", c->decomp_size, mszh_dlen); - return -1; + return AVERROR_INVALIDDATA; } encoded = c->decomp_buf; len = mszh_dlen; @@ -248,7 +243,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac } default: av_log(avctx, AV_LOG_ERROR, "BUG! Unknown MSZH compression in frame decoder.\n"); - return -1; + return AVERROR_INVALIDDATA; } break; #if CONFIG_ZLIB_DECODER @@ -265,7 +260,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac break; } } else if (c->flags & FLAG_MULTITHREAD) { - int ret; mthread_inlen = AV_RL32(encoded); mthread_inlen = FFMIN(mthread_inlen, len - 8); mthread_outlen = AV_RL32(encoded+4); @@ -285,7 +279,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac #endif default: av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in frame decoder compression switch.\n"); - return -1; + return AVERROR_INVALIDDATA; } @@ -369,14 +363,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac break; default: av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in pngfilter switch.\n"); - return -1; + return AVERROR_INVALIDDATA; } } /* Convert colorspace */ - y_out = c->pic.data[0] + (height - 1) * c->pic.linesize[0]; - u_out = c->pic.data[1] + (height - 1) * c->pic.linesize[1]; - v_out = c->pic.data[2] + (height - 1) * c->pic.linesize[2]; + y_out = frame->data[0] + (height - 1) * frame->linesize[0]; + u_out = frame->data[1] + (height - 1) * frame->linesize[1]; + v_out = frame->data[2] + (height - 1) * frame->linesize[2]; switch (c->imgtype) { case IMGTYPE_YUV111: for (row = 0; row < height; row++) { @@ -385,9 +379,9 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac u_out[col] = *encoded++ + 128; v_out[col] = *encoded++ + 128; } - y_out -= c->pic.linesize[0]; - u_out -= c->pic.linesize[1]; - v_out -= c->pic.linesize[2]; + y_out -= frame->linesize[0]; + u_out -= frame->linesize[1]; + v_out -= frame->linesize[2]; } break; case IMGTYPE_YUV422: @@ -400,14 +394,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac v_out[ col >> 1 ] = *encoded++ + 128; v_out[(col >> 1) + 1] = *encoded++ + 128; } - y_out -= c->pic.linesize[0]; - u_out -= c->pic.linesize[1]; - v_out -= c->pic.linesize[2]; + y_out -= frame->linesize[0]; + u_out -= frame->linesize[1]; + v_out -= frame->linesize[2]; } break; case IMGTYPE_RGB24: for (row = height - 1; row >= 0; row--) { - pixel_ptr = row * c->pic.linesize[0]; + pixel_ptr = row * frame->linesize[0]; memcpy(outptr + pixel_ptr, encoded, 3 * width); encoded += 3 * width; } @@ -420,9 +414,9 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac u_out[col >> 2] = *encoded++ + 128; v_out[col >> 2] = *encoded++ + 128; } - y_out -= c->pic.linesize[0]; - u_out -= c->pic.linesize[1]; - v_out -= c->pic.linesize[2]; + y_out -= frame->linesize[0]; + u_out -= frame->linesize[1]; + v_out -= frame->linesize[2]; } break; case IMGTYPE_YUV211: @@ -433,35 +427,34 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac u_out[col >> 1] = *encoded++ + 128; v_out[col >> 1] = *encoded++ + 128; } - y_out -= c->pic.linesize[0]; - u_out -= c->pic.linesize[1]; - v_out -= c->pic.linesize[2]; + y_out -= frame->linesize[0]; + u_out -= frame->linesize[1]; + v_out -= frame->linesize[2]; } break; case IMGTYPE_YUV420: - u_out = c->pic.data[1] + ((height >> 1) - 1) * c->pic.linesize[1]; - v_out = c->pic.data[2] + ((height >> 1) - 1) * c->pic.linesize[2]; + u_out = frame->data[1] + ((height >> 1) - 1) * frame->linesize[1]; + v_out = frame->data[2] + ((height >> 1) - 1) * frame->linesize[2]; for (row = 0; row < height - 1; row += 2) { for (col = 0; col < width - 1; col += 2) { memcpy(y_out + col, encoded, 2); encoded += 2; - memcpy(y_out + col - c->pic.linesize[0], encoded, 2); + memcpy(y_out + col - frame->linesize[0], encoded, 2); encoded += 2; u_out[col >> 1] = *encoded++ + 128; v_out[col >> 1] = *encoded++ + 128; } - y_out -= c->pic.linesize[0] << 1; - u_out -= c->pic.linesize[1]; - v_out -= c->pic.linesize[2]; + y_out -= frame->linesize[0] << 1; + u_out -= frame->linesize[1]; + v_out -= frame->linesize[2]; } break; default: av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in image decoder.\n"); - return -1; + return AVERROR_INVALIDDATA; } - *data_size = sizeof(AVFrame); - *(AVFrame*)data = c->pic; + *got_frame = 1; /* always report that the buffer was completely consumed */ return buf_size; @@ -476,7 +469,8 @@ static av_cold int decode_init(AVCodecContext *avctx) { LclDecContext * const c = avctx->priv_data; unsigned int basesize = avctx->width * avctx->height; - unsigned int max_basesize = FFALIGN(avctx->width, 4) * FFALIGN(avctx->height, 4) + AV_LZO_OUTPUT_PADDING; + unsigned int max_basesize = FFALIGN(avctx->width, 4) * + FFALIGN(avctx->height, 4); unsigned int max_decomp_size; if (avctx->extradata_size < 8) { @@ -495,37 +489,37 @@ static av_cold int decode_init(AVCodecContext *avctx) case IMGTYPE_YUV111: c->decomp_size = basesize * 3; max_decomp_size = max_basesize * 3; - avctx->pix_fmt = PIX_FMT_YUV444P; + avctx->pix_fmt = AV_PIX_FMT_YUV444P; av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 1:1:1.\n"); break; case IMGTYPE_YUV422: c->decomp_size = basesize * 2; max_decomp_size = max_basesize * 2; - avctx->pix_fmt = PIX_FMT_YUV422P; + avctx->pix_fmt = AV_PIX_FMT_YUV422P; av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:2:2.\n"); break; case IMGTYPE_RGB24: c->decomp_size = basesize * 3; max_decomp_size = max_basesize * 3; - avctx->pix_fmt = PIX_FMT_BGR24; + avctx->pix_fmt = AV_PIX_FMT_BGR24; av_log(avctx, AV_LOG_DEBUG, "Image type is RGB 24.\n"); break; case IMGTYPE_YUV411: c->decomp_size = basesize / 2 * 3; max_decomp_size = max_basesize / 2 * 3; - avctx->pix_fmt = PIX_FMT_YUV411P; + avctx->pix_fmt = AV_PIX_FMT_YUV411P; av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:1:1.\n"); break; case IMGTYPE_YUV211: c->decomp_size = basesize * 2; max_decomp_size = max_basesize * 2; - avctx->pix_fmt = PIX_FMT_YUV422P; + avctx->pix_fmt = AV_PIX_FMT_YUV422P; av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 2:1:1.\n"); break; case IMGTYPE_YUV420: c->decomp_size = basesize / 2 * 3; max_decomp_size = max_basesize / 2 * 3; - avctx->pix_fmt = PIX_FMT_YUV420P; + avctx->pix_fmt = AV_PIX_FMT_YUV420P; av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:2:0.\n"); break; default: @@ -624,8 +618,6 @@ static av_cold int decode_end(AVCodecContext *avctx) LclDecContext * const c = avctx->priv_data; av_freep(&c->decomp_buf); - if (c->pic.data[0]) - avctx->release_buffer(avctx, &c->pic); #if CONFIG_ZLIB_DECODER if (avctx->codec_id == AV_CODEC_ID_ZLIB) inflateEnd(&c->zstream); @@ -637,6 +629,7 @@ static av_cold int decode_end(AVCodecContext *avctx) #if CONFIG_MSZH_DECODER AVCodec ff_mszh_decoder = { .name = "mszh", + .long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) MSZH"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_MSZH, .priv_data_size = sizeof(LclDecContext), @@ -644,13 +637,13 @@ AVCodec ff_mszh_decoder = { .close = decode_end, .decode = decode_frame, .capabilities = CODEC_CAP_DR1, - .long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) MSZH"), }; #endif #if CONFIG_ZLIB_DECODER AVCodec ff_zlib_decoder = { .name = "zlib", + .long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) ZLIB"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_ZLIB, .priv_data_size = sizeof(LclDecContext), @@ -658,6 +651,5 @@ AVCodec ff_zlib_decoder = { .close = decode_end, .decode = decode_frame, .capabilities = CODEC_CAP_DR1, - .long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) ZLIB"), }; #endif