You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
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>
This commit is contained in:
2
configure
vendored
2
configure
vendored
@@ -2991,7 +2991,7 @@ xma2_decoder_select="wmapro_decoder"
|
|||||||
ylc_decoder_select="bswapdsp"
|
ylc_decoder_select="bswapdsp"
|
||||||
zerocodec_decoder_select="inflate_wrapper"
|
zerocodec_decoder_select="inflate_wrapper"
|
||||||
zlib_decoder_select="inflate_wrapper"
|
zlib_decoder_select="inflate_wrapper"
|
||||||
zlib_encoder_deps="zlib"
|
zlib_encoder_select="deflate_wrapper"
|
||||||
zmbv_decoder_select="inflate_wrapper"
|
zmbv_decoder_select="inflate_wrapper"
|
||||||
zmbv_encoder_select="deflate_wrapper"
|
zmbv_encoder_select="deflate_wrapper"
|
||||||
|
|
||||||
|
@@ -45,6 +45,7 @@
|
|||||||
#include "encode.h"
|
#include "encode.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "lcl.h"
|
#include "lcl.h"
|
||||||
|
#include "zlib_wrapper.h"
|
||||||
#include "libavutil/internal.h"
|
#include "libavutil/internal.h"
|
||||||
#include "libavutil/mem.h"
|
#include "libavutil/mem.h"
|
||||||
|
|
||||||
@@ -60,16 +61,17 @@ typedef struct LclEncContext {
|
|||||||
int compression;
|
int compression;
|
||||||
// Flags
|
// Flags
|
||||||
int flags;
|
int flags;
|
||||||
z_stream zstream;
|
FFZStream zstream;
|
||||||
} LclEncContext;
|
} LclEncContext;
|
||||||
|
|
||||||
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
||||||
const AVFrame *p, int *got_packet)
|
const AVFrame *p, int *got_packet)
|
||||||
{
|
{
|
||||||
LclEncContext *c = avctx->priv_data;
|
LclEncContext *c = avctx->priv_data;
|
||||||
|
z_stream *const zstream = &c->zstream.zstream;
|
||||||
int i, ret;
|
int i, ret;
|
||||||
int zret; // Zlib return code
|
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)
|
if ((ret = ff_alloc_packet(avctx, pkt, max_size)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
@@ -79,30 +81,30 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
zret = deflateReset(&c->zstream);
|
zret = deflateReset(zstream);
|
||||||
if (zret != Z_OK) {
|
if (zret != Z_OK) {
|
||||||
av_log(avctx, AV_LOG_ERROR, "Deflate reset error: %d\n", zret);
|
av_log(avctx, AV_LOG_ERROR, "Deflate reset error: %d\n", zret);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
c->zstream.next_out = pkt->data;
|
zstream->next_out = pkt->data;
|
||||||
c->zstream.avail_out = pkt->size;
|
zstream->avail_out = pkt->size;
|
||||||
|
|
||||||
for(i = avctx->height - 1; i >= 0; i--) {
|
for(i = avctx->height - 1; i >= 0; i--) {
|
||||||
c->zstream.next_in = p->data[0]+p->linesize[0]*i;
|
zstream->next_in = p->data[0] + p->linesize[0] * i;
|
||||||
c->zstream.avail_in = avctx->width*3;
|
zstream->avail_in = avctx->width * 3;
|
||||||
zret = deflate(&c->zstream, Z_NO_FLUSH);
|
zret = deflate(zstream, Z_NO_FLUSH);
|
||||||
if (zret != Z_OK) {
|
if (zret != Z_OK) {
|
||||||
av_log(avctx, AV_LOG_ERROR, "Deflate error: %d\n", zret);
|
av_log(avctx, AV_LOG_ERROR, "Deflate error: %d\n", zret);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
zret = deflate(&c->zstream, Z_FINISH);
|
zret = deflate(zstream, Z_FINISH);
|
||||||
if (zret != Z_STREAM_END) {
|
if (zret != Z_STREAM_END) {
|
||||||
av_log(avctx, AV_LOG_ERROR, "Deflate error: %d\n", zret);
|
av_log(avctx, AV_LOG_ERROR, "Deflate error: %d\n", zret);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pkt->size = c->zstream.total_out;
|
pkt->size = zstream->total_out;
|
||||||
*got_packet = 1;
|
*got_packet = 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -111,7 +113,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
static av_cold int encode_init(AVCodecContext *avctx)
|
static av_cold int encode_init(AVCodecContext *avctx)
|
||||||
{
|
{
|
||||||
LclEncContext *c = avctx->priv_data;
|
LclEncContext *c = avctx->priv_data;
|
||||||
int zret; // Zlib return code
|
|
||||||
|
|
||||||
c->avctx= avctx;
|
c->avctx= avctx;
|
||||||
|
|
||||||
@@ -138,23 +139,14 @@ static av_cold int encode_init(AVCodecContext *avctx)
|
|||||||
avctx->extradata[7]= CODEC_ZLIB;
|
avctx->extradata[7]= CODEC_ZLIB;
|
||||||
c->avctx->extradata_size= 8;
|
c->avctx->extradata_size= 8;
|
||||||
|
|
||||||
c->zstream.zalloc = Z_NULL;
|
return ff_deflate_init(&c->zstream, c->compression, avctx);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static av_cold int encode_end(AVCodecContext *avctx)
|
static av_cold int encode_end(AVCodecContext *avctx)
|
||||||
{
|
{
|
||||||
LclEncContext *c = avctx->priv_data;
|
LclEncContext *c = avctx->priv_data;
|
||||||
|
|
||||||
deflateEnd(&c->zstream);
|
ff_deflate_end(&c->zstream);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user