[FFmpeg-devel] [PATCH] DV muxer: reduce audio fifo size to AVCODEC_MAX_AUDIO_FRAME_SIZE
Janne Grunau
janne-ffmpeg
Thu Sep 10 22:12:14 CEST 2009
Hi,
after changing the fifo avaible space check to av_fifo_space, it's
possible to realloc the audio fifos in the DV muxer. The default size is
100 * AVCODEC_MAX_AUDIO_FRAME_SIZE, currently 19 megabyte per stream.
The short sample muxed during lavftest doesn't need to realloc the fifo
from the new default size of AVCODEC_MAX_AUDIO_FRAME_SIZE. The largest
realloc I've seen during testing was to 6M. Reducing the memory
consumption of the DV muxer by a factor of 2 (meassured with massif).
Janne
DV muxer: reduce audio fifo size to AVCODEC_MAX_AUDIO_FRAME_SIZE
reallocs audio fifo size up to 128 * AVCODEC_MAX_AUDIO_FRAME_SIZE
if necessary
---
libavformat/dvenc.c | 17 +++++++++++++++--
1 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/libavformat/dvenc.c b/libavformat/dvenc.c
index a385782..448ac73 100644
--- a/libavformat/dvenc.c
+++ b/libavformat/dvenc.c
@@ -234,6 +234,7 @@ int dv_assemble_frame(DVMuxContext *c, AVStream* st,
uint8_t* data, int data_size, uint8_t** frame)
{
int i, reqasize;
+ unsigned int fifo_alloc_cap;
*frame = &c->frame_buf[0];
reqasize = 4 * dv_audio_frame_size(c->sys, c->frames);
@@ -251,8 +252,20 @@ int dv_assemble_frame(DVMuxContext *c, AVStream* st,
for (i = 0; i < c->n_ast && st != c->ast[i]; i++);
/* FIXME: we have to have more sensible approach than this one */
- if (av_fifo_space(c->audio_data[i]) < data_size)
+ if (av_fifo_space(c->audio_data[i]) < data_size) {
+ fifo_alloc_cap = av_fifo_size(c->audio_data[i])
+ + av_fifo_space(c->audio_data[i]);
+
+ if (fifo_alloc_cap > 100 * AVCODEC_MAX_AUDIO_FRAME_SIZE) {
av_log(st->codec, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient video data or severe sync problem.\n", c->frames);
+ } else {
+ if (av_fifo_realloc2(c->audio_data[i], 2 * fifo_alloc_cap) < 0)
+ return AVERROR(ENOMEM);
+
+ av_log(st->codec, AV_LOG_DEBUG, "Audio Fifo for audio stream "
+ "%d reallocated to %d bytes\n", i, 2 * fifo_alloc_cap);
+ }
+ }
av_fifo_generic_write(c->audio_data[i], data, data_size, NULL);
/* Let us see if we've got enough audio for one DV frame. */
@@ -337,7 +350,7 @@ DVMuxContext* dv_init_mux(AVFormatContext* s)
c->start_time = (time_t)s->timestamp;
for (i=0; i < c->n_ast; i++) {
- if (c->ast[i] && !(c->audio_data[i]=av_fifo_alloc(100*AVCODEC_MAX_AUDIO_FRAME_SIZE))) {
+ if (c->ast[i] && !(c->audio_data[i]=av_fifo_alloc(AVCODEC_MAX_AUDIO_FRAME_SIZE))) {
while (i > 0) {
i--;
av_fifo_free(c->audio_data[i]);
More information about the ffmpeg-devel
mailing list