You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
avcodec/tscc: Use ff_inflate_init/end()
Returns better error messages in case of error and deduplicates the inflateInit() code. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
2
configure
vendored
2
configure
vendored
@@ -2953,7 +2953,7 @@ truehd_decoder_select="mlp_parser"
|
|||||||
truehd_encoder_select="lpc audio_frame_queue"
|
truehd_encoder_select="lpc audio_frame_queue"
|
||||||
truemotion2_decoder_select="bswapdsp"
|
truemotion2_decoder_select="bswapdsp"
|
||||||
truespeech_decoder_select="bswapdsp"
|
truespeech_decoder_select="bswapdsp"
|
||||||
tscc_decoder_deps="zlib"
|
tscc_decoder_select="inflate_wrapper"
|
||||||
twinvq_decoder_select="mdct lsp sinewin"
|
twinvq_decoder_select="mdct lsp sinewin"
|
||||||
txd_decoder_select="texturedsp"
|
txd_decoder_select="texturedsp"
|
||||||
utvideo_decoder_select="bswapdsp llviddsp"
|
utvideo_decoder_select="bswapdsp llviddsp"
|
||||||
|
@@ -41,6 +41,7 @@
|
|||||||
#include "decode.h"
|
#include "decode.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "msrledec.h"
|
#include "msrledec.h"
|
||||||
|
#include "zlib_wrapper.h"
|
||||||
|
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
||||||
@@ -57,8 +58,7 @@ typedef struct TsccContext {
|
|||||||
unsigned char* decomp_buf;
|
unsigned char* decomp_buf;
|
||||||
GetByteContext gb;
|
GetByteContext gb;
|
||||||
int height;
|
int height;
|
||||||
int zlib_init_ok;
|
FFZStream zstream;
|
||||||
z_stream zstream;
|
|
||||||
|
|
||||||
uint32_t pal[256];
|
uint32_t pal[256];
|
||||||
} CamtasiaContext;
|
} CamtasiaContext;
|
||||||
@@ -69,6 +69,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
|
|||||||
const uint8_t *buf = avpkt->data;
|
const uint8_t *buf = avpkt->data;
|
||||||
int buf_size = avpkt->size;
|
int buf_size = avpkt->size;
|
||||||
CamtasiaContext * const c = avctx->priv_data;
|
CamtasiaContext * const c = avctx->priv_data;
|
||||||
|
z_stream *const zstream = &c->zstream.zstream;
|
||||||
AVFrame *frame = c->frame;
|
AVFrame *frame = c->frame;
|
||||||
int ret;
|
int ret;
|
||||||
int palette_has_changed = 0;
|
int palette_has_changed = 0;
|
||||||
@@ -77,16 +78,16 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
|
|||||||
palette_has_changed = ff_copy_palette(c->pal, avpkt, avctx);
|
palette_has_changed = ff_copy_palette(c->pal, avpkt, avctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = inflateReset(&c->zstream);
|
ret = inflateReset(zstream);
|
||||||
if (ret != Z_OK) {
|
if (ret != Z_OK) {
|
||||||
av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", ret);
|
av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", ret);
|
||||||
return AVERROR_UNKNOWN;
|
return AVERROR_UNKNOWN;
|
||||||
}
|
}
|
||||||
c->zstream.next_in = buf;
|
zstream->next_in = buf;
|
||||||
c->zstream.avail_in = buf_size;
|
zstream->avail_in = buf_size;
|
||||||
c->zstream.next_out = c->decomp_buf;
|
zstream->next_out = c->decomp_buf;
|
||||||
c->zstream.avail_out = c->decomp_size;
|
zstream->avail_out = c->decomp_size;
|
||||||
ret = inflate(&c->zstream, Z_FINISH);
|
ret = inflate(zstream, Z_FINISH);
|
||||||
// Z_DATA_ERROR means empty picture
|
// Z_DATA_ERROR means empty picture
|
||||||
if (ret == Z_DATA_ERROR && !palette_has_changed) {
|
if (ret == Z_DATA_ERROR && !palette_has_changed) {
|
||||||
return buf_size;
|
return buf_size;
|
||||||
@@ -102,7 +103,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
|
|||||||
|
|
||||||
if (ret != Z_DATA_ERROR) {
|
if (ret != Z_DATA_ERROR) {
|
||||||
bytestream2_init(&c->gb, c->decomp_buf,
|
bytestream2_init(&c->gb, c->decomp_buf,
|
||||||
c->decomp_size - c->zstream.avail_out);
|
c->decomp_size - zstream->avail_out);
|
||||||
ff_msrle_decode(avctx, frame, c->bpp, &c->gb);
|
ff_msrle_decode(avctx, frame, c->bpp, &c->gb);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +124,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
|
|||||||
static av_cold int decode_init(AVCodecContext *avctx)
|
static av_cold int decode_init(AVCodecContext *avctx)
|
||||||
{
|
{
|
||||||
CamtasiaContext * const c = avctx->priv_data;
|
CamtasiaContext * const c = avctx->priv_data;
|
||||||
int zret; // Zlib return code
|
|
||||||
|
|
||||||
c->avctx = avctx;
|
c->avctx = avctx;
|
||||||
|
|
||||||
@@ -151,21 +151,11 @@ static av_cold int decode_init(AVCodecContext *avctx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c->zstream.zalloc = Z_NULL;
|
|
||||||
c->zstream.zfree = Z_NULL;
|
|
||||||
c->zstream.opaque = Z_NULL;
|
|
||||||
zret = inflateInit(&c->zstream);
|
|
||||||
if (zret != Z_OK) {
|
|
||||||
av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
|
|
||||||
return AVERROR_UNKNOWN;
|
|
||||||
}
|
|
||||||
c->zlib_init_ok = 1;
|
|
||||||
|
|
||||||
c->frame = av_frame_alloc();
|
c->frame = av_frame_alloc();
|
||||||
if (!c->frame)
|
if (!c->frame)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
return 0;
|
return ff_inflate_init(&c->zstream, avctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold int decode_end(AVCodecContext *avctx)
|
static av_cold int decode_end(AVCodecContext *avctx)
|
||||||
@@ -174,9 +164,7 @@ static av_cold int decode_end(AVCodecContext *avctx)
|
|||||||
|
|
||||||
av_freep(&c->decomp_buf);
|
av_freep(&c->decomp_buf);
|
||||||
av_frame_free(&c->frame);
|
av_frame_free(&c->frame);
|
||||||
|
ff_inflate_end(&c->zstream);
|
||||||
if (c->zlib_init_ok)
|
|
||||||
inflateEnd(&c->zstream);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user