From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH 19/21] avcodec/pngenc: Use ff_deflate_init/end() wrappers Date: Tue, 15 Mar 2022 21:06:09 +0100 Message-ID: <AS1PR01MB9564E990C355A6E5512C9A618F109@AS1PR01MB9564.eurprd01.prod.exchangelabs.com> (raw) In-Reply-To: <AS1PR01MB956473F7529A463D0DFC230B8F109@AS1PR01MB9564.eurprd01.prod.exchangelabs.com> They return nicer error messages. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- configure | 6 ++---- libavcodec/png.c | 10 --------- libavcodec/png.h | 4 ---- libavcodec/pngenc.c | 49 ++++++++++++++++++++++----------------------- 4 files changed, 26 insertions(+), 43 deletions(-) diff --git a/configure b/configure index 8f36699d0c..a3d4b224f4 100755 --- a/configure +++ b/configure @@ -2761,8 +2761,7 @@ amv_decoder_select="sp5x_decoder exif" amv_encoder_select="jpegtables mpegvideoenc" ape_decoder_select="bswapdsp llauddsp" apng_decoder_select="inflate_wrapper" -apng_encoder_deps="zlib" -apng_encoder_select="llvidencdsp" +apng_encoder_select="deflate_wrapper llvidencdsp" aptx_decoder_select="audio_frame_queue" aptx_encoder_select="audio_frame_queue" aptx_hd_decoder_select="audio_frame_queue" @@ -2906,8 +2905,7 @@ opus_decoder_deps="swresample" opus_decoder_select="mdct15" opus_encoder_select="audio_frame_queue mdct15" png_decoder_select="inflate_wrapper" -png_encoder_deps="zlib" -png_encoder_select="llvidencdsp" +png_encoder_select="deflate_wrapper llvidencdsp" prores_decoder_select="blockdsp idctdsp" prores_encoder_select="fdctdsp" qcelp_decoder_select="lsp" diff --git a/libavcodec/png.c b/libavcodec/png.c index e772eaad26..34f649815a 100644 --- a/libavcodec/png.c +++ b/libavcodec/png.c @@ -38,16 +38,6 @@ static const uint8_t ff_png_pass_xshift[NB_PASSES] = { 3, 3, 2, 2, 1, 1, 0 }; -void *ff_png_zalloc(void *opaque, unsigned int items, unsigned int size) -{ - return av_calloc(items, size); -} - -void ff_png_zfree(void *opaque, void *ptr) -{ - av_free(ptr); -} - int ff_png_get_nb_channels(int color_type) { int channels; diff --git a/libavcodec/png.h b/libavcodec/png.h index a15560131f..01171e682e 100644 --- a/libavcodec/png.h +++ b/libavcodec/png.h @@ -52,10 +52,6 @@ /* Mask to determine which y pixels are valid in a pass */ extern const uint8_t ff_png_pass_ymask[NB_PASSES]; -void *ff_png_zalloc(void *opaque, unsigned int items, unsigned int size); - -void ff_png_zfree(void *opaque, void *ptr); - int ff_png_get_nb_channels(int color_type); /* compute the row size of an interleaved pass */ diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c index 0b75f948d5..b34a94db21 100644 --- a/libavcodec/pngenc.c +++ b/libavcodec/pngenc.c @@ -26,6 +26,7 @@ #include "lossless_videoencdsp.h" #include "png.h" #include "apng.h" +#include "zlib_wrapper.h" #include "libavutil/avassert.h" #include "libavutil/crc.h" @@ -56,7 +57,7 @@ typedef struct PNGEncContext { int filter_type; - z_stream zstream; + FFZStream zstream; uint8_t buf[IOBUF_SIZE]; int dpi; ///< Physical pixel density, in dots per inch, if set int dpm; ///< Physical pixel density, in dots per meter, if set @@ -272,19 +273,20 @@ static void png_write_image_data(AVCodecContext *avctx, static int png_write_row(AVCodecContext *avctx, const uint8_t *data, int size) { PNGEncContext *s = avctx->priv_data; + z_stream *const zstream = &s->zstream.zstream; int ret; - s->zstream.avail_in = size; - s->zstream.next_in = data; - while (s->zstream.avail_in > 0) { - ret = deflate(&s->zstream, Z_NO_FLUSH); + zstream->avail_in = size; + zstream->next_in = data; + while (zstream->avail_in > 0) { + ret = deflate(zstream, Z_NO_FLUSH); if (ret != Z_OK) return -1; - if (s->zstream.avail_out == 0) { + if (zstream->avail_out == 0) { if (s->bytestream_end - s->bytestream > IOBUF_SIZE + 100) png_write_image_data(avctx, s->buf, IOBUF_SIZE); - s->zstream.avail_out = IOBUF_SIZE; - s->zstream.next_out = s->buf; + zstream->avail_out = IOBUF_SIZE; + zstream->next_out = s->buf; } } return 0; @@ -432,6 +434,7 @@ static int encode_headers(AVCodecContext *avctx, const AVFrame *pict) static int encode_frame(AVCodecContext *avctx, const AVFrame *pict) { PNGEncContext *s = avctx->priv_data; + z_stream *const zstream = &s->zstream.zstream; const AVFrame *const p = pict; int y, len, ret; int row_size, pass_row_size; @@ -459,8 +462,8 @@ static int encode_frame(AVCodecContext *avctx, const AVFrame *pict) } /* put each row */ - s->zstream.avail_out = IOBUF_SIZE; - s->zstream.next_out = s->buf; + zstream->avail_out = IOBUF_SIZE; + zstream->next_out = s->buf; if (s->is_progressive) { int pass; @@ -496,14 +499,14 @@ static int encode_frame(AVCodecContext *avctx, const AVFrame *pict) } /* compress last bytes */ for (;;) { - ret = deflate(&s->zstream, Z_FINISH); + ret = deflate(zstream, Z_FINISH); if (ret == Z_OK || ret == Z_STREAM_END) { - len = IOBUF_SIZE - s->zstream.avail_out; + len = IOBUF_SIZE - zstream->avail_out; if (len > 0 && s->bytestream_end - s->bytestream > len + 100) { png_write_image_data(avctx, s->buf, len); } - s->zstream.avail_out = IOBUF_SIZE; - s->zstream.next_out = s->buf; + zstream->avail_out = IOBUF_SIZE; + zstream->next_out = s->buf; if (ret == Z_STREAM_END) break; } else { @@ -518,7 +521,7 @@ the_end: av_freep(&crow_base); av_freep(&progressive_buf); av_freep(&top_buf); - deflateReset(&s->zstream); + deflateReset(zstream); return ret; } @@ -530,7 +533,8 @@ static int encode_png(AVCodecContext *avctx, AVPacket *pkt, int enc_row_size; int64_t max_packet_size; - enc_row_size = deflateBound(&s->zstream, (avctx->width * s->bits_per_pixel + 7) >> 3); + enc_row_size = deflateBound(&s->zstream.zstream, + (avctx->width * s->bits_per_pixel + 7) >> 3); max_packet_size = AV_INPUT_BUFFER_MIN_SIZE + // headers avctx->height * ( @@ -858,7 +862,8 @@ static int encode_apng(AVCodecContext *avctx, AVPacket *pkt, } } - enc_row_size = deflateBound(&s->zstream, (avctx->width * s->bits_per_pixel + 7) >> 3); + enc_row_size = deflateBound(&s->zstream.zstream, + (avctx->width * s->bits_per_pixel + 7) >> 3); max_packet_size = AV_INPUT_BUFFER_MIN_SIZE + // headers avctx->height * ( @@ -1065,23 +1070,17 @@ static av_cold int png_enc_init(AVCodecContext *avctx) } s->bits_per_pixel = ff_png_get_nb_channels(s->color_type) * s->bit_depth; - s->zstream.zalloc = ff_png_zalloc; - s->zstream.zfree = ff_png_zfree; - s->zstream.opaque = NULL; compression_level = avctx->compression_level == FF_COMPRESSION_DEFAULT ? Z_DEFAULT_COMPRESSION : av_clip(avctx->compression_level, 0, 9); - if (deflateInit(&s->zstream, compression_level) != Z_OK) - return -1; - - return 0; + return ff_deflate_init(&s->zstream, compression_level, avctx); } static av_cold int png_enc_close(AVCodecContext *avctx) { PNGEncContext *s = avctx->priv_data; - deflateEnd(&s->zstream); + ff_deflate_end(&s->zstream); av_frame_free(&s->last_frame); av_frame_free(&s->prev_frame); av_freep(&s->last_frame_packet); -- 2.32.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-03-15 20:09 UTC|newest] Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-03-15 20:03 [FFmpeg-devel] [PATCH 01/21] avcodec/pngenc: Avoid potentially truncating integers Andreas Rheinhardt 2022-03-15 20:05 ` [FFmpeg-devel] [PATCH 02/21] avcodec/zlib_wrapper: Add wrappers for zlib inflateInit, inflateEnd Andreas Rheinhardt 2022-03-16 19:24 ` Tomas Härdin 2022-03-16 19:32 ` Andreas Rheinhardt 2022-03-16 20:07 ` Tomas Härdin 2022-03-17 7:29 ` Andreas Rheinhardt 2022-03-15 20:05 ` [FFmpeg-devel] [PATCH 03/21] avcodec/zmbv: Use ff_inflate_init/end() Andreas Rheinhardt 2022-03-16 19:31 ` Tomas Härdin 2022-03-15 20:05 ` [FFmpeg-devel] [PATCH 04/21] avcodec/zerocodec: " Andreas Rheinhardt 2022-03-15 20:05 ` [FFmpeg-devel] [PATCH 05/21] avcodec/wcmv: " Andreas Rheinhardt 2022-03-15 20:05 ` [FFmpeg-devel] [PATCH 06/21] avcodec/tscc: " Andreas Rheinhardt 2022-03-15 20:05 ` [FFmpeg-devel] [PATCH 07/21] avcodec/rasc: " Andreas Rheinhardt 2022-03-15 20:05 ` [FFmpeg-devel] [PATCH 08/21] avcodec/mwsc: " Andreas Rheinhardt 2022-03-15 20:05 ` [FFmpeg-devel] [PATCH 09/21] avcodec/mvha: " Andreas Rheinhardt 2022-03-15 20:06 ` [FFmpeg-devel] [PATCH 10/21] avcodec/mscc: " Andreas Rheinhardt 2022-03-15 20:06 ` [FFmpeg-devel] [PATCH 11/21] avcodec/lcldec: Use ff_inflate_init/end(), cleanup generically Andreas Rheinhardt 2022-03-15 20:06 ` [FFmpeg-devel] [PATCH 12/21] avcodec/flashsv: Use ff_inflate_init/end() Andreas Rheinhardt 2022-03-15 20:06 ` [FFmpeg-devel] [PATCH 13/21] avcodec/zlib_wrapper: Use our allocation, freeing functions Andreas Rheinhardt 2022-03-15 20:06 ` [FFmpeg-devel] [PATCH 14/21] avcodec/lscrdec: Don't open and close z_streams unnecessarily Andreas Rheinhardt 2022-03-15 20:06 ` [FFmpeg-devel] [PATCH 15/21] avcodec/pngdec: " Andreas Rheinhardt 2022-03-15 20:06 ` [FFmpeg-devel] [PATCH 16/21] avcodec/pngenc: Don't use deflateInit2() with default parameters Andreas Rheinhardt 2022-03-15 20:06 ` [FFmpeg-devel] [PATCH 17/21] avcodec/zlib_wrapper: Add wrapper for deflateInit() Andreas Rheinhardt 2022-03-15 20:06 ` [FFmpeg-devel] [PATCH 18/21] avcodec/zmbvenc: Use ff_deflate_init/end() wrappers Andreas Rheinhardt 2022-03-16 20:03 ` Tomas Härdin 2022-03-15 20:06 ` Andreas Rheinhardt [this message] 2022-03-15 20:06 ` [FFmpeg-devel] [PATCH 20/21] avcodec/lclenc: " Andreas Rheinhardt 2022-03-15 20:06 ` [FFmpeg-devel] [PATCH 21/21] avcodec/flashsv2enc: Avoid opening and closing z_stream Andreas Rheinhardt
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=AS1PR01MB9564E990C355A6E5512C9A618F109@AS1PR01MB9564.eurprd01.prod.exchangelabs.com \ --to=andreas.rheinhardt@outlook.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git