* [FFmpeg-devel] [PATCH 1/2] avcodec/libvpxenc: use av_fast_realloc() to resize the stats buffer
@ 2022-08-23 23:34 James Almer
2022-08-23 23:34 ` [FFmpeg-devel] [PATCH 2/2] avcodec/libaomenc: " James Almer
2022-08-24 17:59 ` [FFmpeg-devel] [PATCH 1/2] avcodec/libvpxenc: " James Zern
0 siblings, 2 replies; 4+ messages in thread
From: James Almer @ 2022-08-23 23:34 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavcodec/libvpxenc.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index e08df5fb96..bbbe56c0dc 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -80,6 +80,7 @@ typedef struct VPxEncoderContext {
struct vpx_image rawimg_alpha;
uint8_t is_alpha;
struct vpx_fixed_buf twopass_stats;
+ unsigned twopass_stats_size;
int deadline; //i.e., RT/GOOD/BEST
uint64_t sse[4];
int have_sse; /**< true if we have pending sse[] */
@@ -1356,16 +1357,20 @@ static int queue_frames(AVCodecContext *avctx, struct vpx_codec_ctx *encoder,
break;
case VPX_CODEC_STATS_PKT: {
struct vpx_fixed_buf *stats = &ctx->twopass_stats;
- int err;
+ uint8_t *tmp;
if (!pkt_out)
break;
- if ((err = av_reallocp(&stats->buf,
- stats->sz +
- pkt->data.twopass_stats.sz)) < 0) {
+ tmp = av_fast_realloc(stats->buf,
+ &ctx->twopass_stats_size,
+ stats->sz +
+ pkt->data.twopass_stats.sz);
+ if (!tmp) {
+ av_freep(&stats->buf);
stats->sz = 0;
av_log(avctx, AV_LOG_ERROR, "Stat buffer realloc failed\n");
- return err;
+ return AVERROR(ENOMEM);
}
+ stats->buf = tmp;
memcpy((uint8_t*)stats->buf + stats->sz,
pkt->data.twopass_stats.buf, pkt->data.twopass_stats.sz);
stats->sz += pkt->data.twopass_stats.sz;
--
2.37.2
_______________________________________________
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".
^ permalink raw reply [flat|nested] 4+ messages in thread
* [FFmpeg-devel] [PATCH 2/2] avcodec/libaomenc: use av_fast_realloc() to resize the stats buffer
2022-08-23 23:34 [FFmpeg-devel] [PATCH 1/2] avcodec/libvpxenc: use av_fast_realloc() to resize the stats buffer James Almer
@ 2022-08-23 23:34 ` James Almer
2022-08-24 18:00 ` James Zern
2022-08-24 17:59 ` [FFmpeg-devel] [PATCH 1/2] avcodec/libvpxenc: " James Zern
1 sibling, 1 reply; 4+ messages in thread
From: James Almer @ 2022-08-23 23:34 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavcodec/libaomenc.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 1fd69d59a7..485f554165 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -70,6 +70,7 @@ typedef struct AOMEncoderContext {
struct aom_codec_ctx encoder;
struct aom_image rawimg;
struct aom_fixed_buf twopass_stats;
+ unsigned twopass_stats_size;
struct FrameListData *coded_frame_list;
int cpu_used;
int auto_alt_ref;
@@ -1200,14 +1201,17 @@ static int queue_frames(AVCodecContext *avctx, AVPacket *pkt_out)
case AOM_CODEC_STATS_PKT:
{
struct aom_fixed_buf *stats = &ctx->twopass_stats;
- int err;
- if ((err = av_reallocp(&stats->buf,
- stats->sz +
- pkt->data.twopass_stats.sz)) < 0) {
+ uint8_t *tmp = av_fast_realloc(stats->buf,
+ &ctx->twopass_stats_size,
+ stats->sz +
+ pkt->data.twopass_stats.sz);
+ if (!tmp) {
+ av_freep(&stats->buf);
stats->sz = 0;
av_log(avctx, AV_LOG_ERROR, "Stat buffer realloc failed\n");
- return err;
+ return AVERROR(ENOMEM);
}
+ stats->buf = tmp;
memcpy((uint8_t *)stats->buf + stats->sz,
pkt->data.twopass_stats.buf, pkt->data.twopass_stats.sz);
stats->sz += pkt->data.twopass_stats.sz;
--
2.37.2
_______________________________________________
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".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/2] avcodec/libvpxenc: use av_fast_realloc() to resize the stats buffer
2022-08-23 23:34 [FFmpeg-devel] [PATCH 1/2] avcodec/libvpxenc: use av_fast_realloc() to resize the stats buffer James Almer
2022-08-23 23:34 ` [FFmpeg-devel] [PATCH 2/2] avcodec/libaomenc: " James Almer
@ 2022-08-24 17:59 ` James Zern
1 sibling, 0 replies; 4+ messages in thread
From: James Zern @ 2022-08-24 17:59 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Tue, Aug 23, 2022 at 4:34 PM James Almer <jamrial@gmail.com> wrote:
>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> libavcodec/libvpxenc.c | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
lgtm.
_______________________________________________
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".
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-08-24 18:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-23 23:34 [FFmpeg-devel] [PATCH 1/2] avcodec/libvpxenc: use av_fast_realloc() to resize the stats buffer James Almer
2022-08-23 23:34 ` [FFmpeg-devel] [PATCH 2/2] avcodec/libaomenc: " James Almer
2022-08-24 18:00 ` James Zern
2022-08-24 17:59 ` [FFmpeg-devel] [PATCH 1/2] avcodec/libvpxenc: " James Zern
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