History

avfilter/af_aresample: Limit data per inserted packet

This avoids creating unwieldy large packets, which is allowed but does not seem to be a good idea

Michael Niedermayer committed 12 years ago

Commit 09024fe1 parent 97da6811 file · +16 −1Browse files

Unified · Split

libavfilter/af_aresample.c+16−1
@@ -41,6 +41,7 @@ typedef struct { · 40 unmodified lines
4141 struct SwrContext *swr;
4242 int64_t next_pts;
4343 int req_fullfilled;
44+ int more_data;
4445 } AResampleContext;
4546
4647 static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts)
@@ -186,7 +187,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref) · 139 unmodified lines
186187
187188 delay = swr_get_delay(aresample->swr, outlink->sample_rate);
188189 if (delay > 0)
189− n_out += delay;
190+ n_out += FFMIN(delay, FFMAX(4096, n_out));
190191
191192 outsamplesref = ff_get_audio_buffer(outlink, n_out);
192193
@@ -215,6 +216,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref) · 22 unmodified lines
215216 return 0;
216217 }
217218
219+ aresample->more_data = outsamplesref->nb_samples == n_out; // Indicate that there is probably more data in our buffers
220+
218221 outsamplesref->nb_samples = n_out;
219222
220223 ret = ff_filter_frame(outlink, outsamplesref);
@@ -261,11 +264,23 @@ static int request_frame(AVFilterLink *outlink) · 40 unmodified lines
261264 AVFilterLink *const inlink = outlink->src->inputs[0];
262265 int ret;
263266
267+ // First try to get data from the internal buffers
268+ if (aresample->more_data) {
269+ AVFrame *outsamplesref;
270+
271+ if (flush_frame(outlink, 0, &outsamplesref) >= 0) {
272+ return ff_filter_frame(outlink, outsamplesref);
273+ }
274+ }
275+ aresample->more_data = 0;
276+
277+ // Second request more data from the input
264278 aresample->req_fullfilled = 0;
265279 do{
266280 ret = ff_request_frame(ctx->inputs[0]);
267281 }while(!aresample->req_fullfilled && ret>=0);
268282
283+ // Third if we hit the end flush
269284 if (ret == AVERROR_EOF) {
270285 AVFrame *outsamplesref;
271286

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t