summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-03-15 18:28:54 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-03-19 00:18:36 +0100
commitc3c2b5423d33bcfa792b3ab26dd26a50a3590a59 (patch)
tree27499ca0db83847961e8634e58e69e3265b96105
parent1692a97251896035ce4055eb101bb6c2f9b0fae1 (diff)
avcodec/lclenc: Use ff_deflate_init/end() wrappers
They return nicer error messages on error; furthermore, they also use our allocation functions. It also stops calling deflateEnd() on a z_stream that might not have been successfully initialized. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
-rwxr-xr-xconfigure2
-rw-r--r--libavcodec/lclenc.c36
2 files changed, 15 insertions, 23 deletions
diff --git a/configure b/configure
index 562e664372..e834133614 100755
--- a/configure
+++ b/configure
@@ -2991,7 +2991,7 @@ xma2_decoder_select="wmapro_decoder"
ylc_decoder_select="bswapdsp"
zerocodec_decoder_select="inflate_wrapper"
zlib_decoder_select="inflate_wrapper"
-zlib_encoder_deps="zlib"
+zlib_encoder_select="deflate_wrapper"
zmbv_decoder_select="inflate_wrapper"
zmbv_encoder_select="deflate_wrapper"
diff --git a/libavcodec/lclenc.c b/libavcodec/lclenc.c
index 7deea4f20a..afa99d1f92 100644
--- a/libavcodec/lclenc.c
+++ b/libavcodec/lclenc.c
@@ -45,6 +45,7 @@
#include "encode.h"
#include "internal.h"
#include "lcl.h"
+#include "zlib_wrapper.h"
#include "libavutil/internal.h"
#include "libavutil/mem.h"
@@ -60,16 +61,17 @@ typedef struct LclEncContext {
int compression;
// Flags
int flags;
- z_stream zstream;
+ FFZStream zstream;
} LclEncContext;
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *p, int *got_packet)
{
LclEncContext *c = avctx->priv_data;
+ z_stream *const zstream = &c->zstream.zstream;
int i, ret;
int zret; // Zlib return code
- int max_size = deflateBound(&c->zstream, avctx->width * avctx->height * 3);
+ int max_size = deflateBound(zstream, avctx->width * avctx->height * 3);
if ((ret = ff_alloc_packet(avctx, pkt, max_size)) < 0)
return ret;
@@ -79,30 +81,30 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
return -1;
}
- zret = deflateReset(&c->zstream);
+ zret = deflateReset(zstream);
if (zret != Z_OK) {
av_log(avctx, AV_LOG_ERROR, "Deflate reset error: %d\n", zret);
return -1;
}
- c->zstream.next_out = pkt->data;
- c->zstream.avail_out = pkt->size;
+ zstream->next_out = pkt->data;
+ zstream->avail_out = pkt->size;
for(i = avctx->height - 1; i >= 0; i--) {
- c->zstream.next_in = p->data[0]+p->linesize[0]*i;
- c->zstream.avail_in = avctx->width*3;
- zret = deflate(&c->zstream, Z_NO_FLUSH);
+ zstream->next_in = p->data[0] + p->linesize[0] * i;
+ zstream->avail_in = avctx->width * 3;
+ zret = deflate(zstream, Z_NO_FLUSH);
if (zret != Z_OK) {
av_log(avctx, AV_LOG_ERROR, "Deflate error: %d\n", zret);
return -1;
}
}
- zret = deflate(&c->zstream, Z_FINISH);
+ zret = deflate(zstream, Z_FINISH);
if (zret != Z_STREAM_END) {
av_log(avctx, AV_LOG_ERROR, "Deflate error: %d\n", zret);
return -1;
}
- pkt->size = c->zstream.total_out;
+ pkt->size = zstream->total_out;
*got_packet = 1;
return 0;
@@ -111,7 +113,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
static av_cold int encode_init(AVCodecContext *avctx)
{
LclEncContext *c = avctx->priv_data;
- int zret; // Zlib return code
c->avctx= avctx;
@@ -138,23 +139,14 @@ static av_cold int encode_init(AVCodecContext *avctx)
avctx->extradata[7]= CODEC_ZLIB;
c->avctx->extradata_size= 8;
- c->zstream.zalloc = Z_NULL;
- c->zstream.zfree = Z_NULL;
- c->zstream.opaque = Z_NULL;
- zret = deflateInit(&c->zstream, c->compression);
- if (zret != Z_OK) {
- av_log(avctx, AV_LOG_ERROR, "Deflate init error: %d\n", zret);
- return AVERROR_UNKNOWN;
- }
-
- return 0;
+ return ff_deflate_init(&c->zstream, c->compression, avctx);
}
static av_cold int encode_end(AVCodecContext *avctx)
{
LclEncContext *c = avctx->priv_data;
- deflateEnd(&c->zstream);
+ ff_deflate_end(&c->zstream);
return 0;
}