avcodec/zmbvenc: Use ff_deflate_init/end() wrappers
They emit better error messages (it does not claim that inflateInit failed upon an error from deflateInit!) and uses our allocation functions. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
parent
9cae7f9450
commit
e85095b524
2
configure
vendored
2
configure
vendored
@ -2995,7 +2995,7 @@ zerocodec_decoder_select="inflate_wrapper"
|
|||||||
zlib_decoder_select="inflate_wrapper"
|
zlib_decoder_select="inflate_wrapper"
|
||||||
zlib_encoder_deps="zlib"
|
zlib_encoder_deps="zlib"
|
||||||
zmbv_decoder_select="inflate_wrapper"
|
zmbv_decoder_select="inflate_wrapper"
|
||||||
zmbv_encoder_deps="zlib"
|
zmbv_encoder_select="deflate_wrapper"
|
||||||
|
|
||||||
# hardware accelerators
|
# hardware accelerators
|
||||||
crystalhd_deps="libcrystalhd_libcrystalhd_if_h"
|
crystalhd_deps="libcrystalhd_libcrystalhd_if_h"
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "avcodec.h"
|
#include "avcodec.h"
|
||||||
#include "encode.h"
|
#include "encode.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
#include "zlib_wrapper.h"
|
||||||
|
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
||||||
@ -74,8 +75,7 @@ typedef struct ZmbvEncContext {
|
|||||||
int keyint, curfrm;
|
int keyint, curfrm;
|
||||||
int bypp;
|
int bypp;
|
||||||
enum ZmbvFormat fmt;
|
enum ZmbvFormat fmt;
|
||||||
int zlib_init_ok;
|
FFZStream zstream;
|
||||||
z_stream zstream;
|
|
||||||
|
|
||||||
int score_tab[ZMBV_BLOCK * ZMBV_BLOCK * 4 + 1];
|
int score_tab[ZMBV_BLOCK * ZMBV_BLOCK * 4 + 1];
|
||||||
} ZmbvEncContext;
|
} ZmbvEncContext;
|
||||||
@ -169,6 +169,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
const AVFrame *pict, int *got_packet)
|
const AVFrame *pict, int *got_packet)
|
||||||
{
|
{
|
||||||
ZmbvEncContext * const c = avctx->priv_data;
|
ZmbvEncContext * const c = avctx->priv_data;
|
||||||
|
z_stream *const zstream = &c->zstream.zstream;
|
||||||
const AVFrame * const p = pict;
|
const AVFrame * const p = pict;
|
||||||
uint8_t *src, *prev, *buf;
|
uint8_t *src, *prev, *buf;
|
||||||
uint32_t *palptr;
|
uint32_t *palptr;
|
||||||
@ -262,21 +263,21 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (keyframe)
|
if (keyframe)
|
||||||
deflateReset(&c->zstream);
|
deflateReset(zstream);
|
||||||
|
|
||||||
c->zstream.next_in = c->work_buf;
|
zstream->next_in = c->work_buf;
|
||||||
c->zstream.avail_in = work_size;
|
zstream->avail_in = work_size;
|
||||||
c->zstream.total_in = 0;
|
zstream->total_in = 0;
|
||||||
|
|
||||||
c->zstream.next_out = c->comp_buf;
|
zstream->next_out = c->comp_buf;
|
||||||
c->zstream.avail_out = c->comp_size;
|
zstream->avail_out = c->comp_size;
|
||||||
c->zstream.total_out = 0;
|
zstream->total_out = 0;
|
||||||
if(deflate(&c->zstream, Z_SYNC_FLUSH) != Z_OK){
|
if (deflate(zstream, Z_SYNC_FLUSH) != Z_OK) {
|
||||||
av_log(avctx, AV_LOG_ERROR, "Error compressing data\n");
|
av_log(avctx, AV_LOG_ERROR, "Error compressing data\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pkt_size = c->zstream.total_out + 1 + 6*keyframe;
|
pkt_size = zstream->total_out + 1 + 6 * keyframe;
|
||||||
if ((ret = ff_get_encode_buffer(avctx, pkt, pkt_size, 0)) < 0)
|
if ((ret = ff_get_encode_buffer(avctx, pkt, pkt_size, 0)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
buf = pkt->data;
|
buf = pkt->data;
|
||||||
@ -292,7 +293,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
*buf++ = ZMBV_BLOCK; // block height
|
*buf++ = ZMBV_BLOCK; // block height
|
||||||
pkt->flags |= AV_PKT_FLAG_KEY;
|
pkt->flags |= AV_PKT_FLAG_KEY;
|
||||||
}
|
}
|
||||||
memcpy(buf, c->comp_buf, c->zstream.total_out);
|
memcpy(buf, c->comp_buf, zstream->total_out);
|
||||||
|
|
||||||
*got_packet = 1;
|
*got_packet = 1;
|
||||||
|
|
||||||
@ -307,8 +308,7 @@ static av_cold int encode_end(AVCodecContext *avctx)
|
|||||||
av_freep(&c->work_buf);
|
av_freep(&c->work_buf);
|
||||||
|
|
||||||
av_freep(&c->prev_buf);
|
av_freep(&c->prev_buf);
|
||||||
if (c->zlib_init_ok)
|
ff_deflate_end(&c->zstream);
|
||||||
deflateEnd(&c->zstream);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -319,7 +319,6 @@ static av_cold int encode_end(AVCodecContext *avctx)
|
|||||||
static av_cold int encode_init(AVCodecContext *avctx)
|
static av_cold int encode_init(AVCodecContext *avctx)
|
||||||
{
|
{
|
||||||
ZmbvEncContext * const c = avctx->priv_data;
|
ZmbvEncContext * const c = avctx->priv_data;
|
||||||
int zret; // Zlib return code
|
|
||||||
int i;
|
int i;
|
||||||
int lvl = 9;
|
int lvl = 9;
|
||||||
int prev_size, prev_offset;
|
int prev_size, prev_offset;
|
||||||
@ -408,17 +407,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
|
|||||||
}
|
}
|
||||||
c->prev = c->prev_buf + prev_offset;
|
c->prev = c->prev_buf + prev_offset;
|
||||||
|
|
||||||
c->zstream.zalloc = Z_NULL;
|
return ff_deflate_init(&c->zstream, lvl, avctx);
|
||||||
c->zstream.zfree = Z_NULL;
|
|
||||||
c->zstream.opaque = Z_NULL;
|
|
||||||
zret = deflateInit(&c->zstream, lvl);
|
|
||||||
if (zret != Z_OK) {
|
|
||||||
av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
c->zlib_init_ok = 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const AVCodec ff_zmbv_encoder = {
|
const AVCodec ff_zmbv_encoder = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user