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
41 struct SwrContext *swr;41 struct SwrContext *swr;
42 int64_t next_pts;42 int64_t next_pts;
43 int req_fullfilled;43 int req_fullfilled;
44 int more_data;
44} AResampleContext;45} AResampleContext;
45 46
46static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts)47static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts)
@@ -186,7 +187,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref) · 139 unmodified lines
186 187
187 delay = swr_get_delay(aresample->swr, outlink->sample_rate);188 delay = swr_get_delay(aresample->swr, outlink->sample_rate);
188 if (delay > 0)189 if (delay > 0)
189 n_out += delay;190 n_out += FFMIN(delay, FFMAX(4096, n_out));
190 191
191 outsamplesref = ff_get_audio_buffer(outlink, n_out);192 outsamplesref = ff_get_audio_buffer(outlink, n_out);
192 193
@@ -215,6 +216,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref) · 22 unmodified lines
215 return 0;216 return 0;
216 }217 }
217 218
219 aresample->more_data = outsamplesref->nb_samples == n_out; // Indicate that there is probably more data in our buffers
220
218 outsamplesref->nb_samples = n_out;221 outsamplesref->nb_samples = n_out;
219 222
220 ret = ff_filter_frame(outlink, outsamplesref);223 ret = ff_filter_frame(outlink, outsamplesref);
@@ -261,11 +264,23 @@ static int request_frame(AVFilterLink *outlink) · 40 unmodified lines
261 AVFilterLink *const inlink = outlink->src->inputs[0];264 AVFilterLink *const inlink = outlink->src->inputs[0];
262 int ret;265 int ret;
263 266
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
264 aresample->req_fullfilled = 0;278 aresample->req_fullfilled = 0;
265 do{279 do{
266 ret = ff_request_frame(ctx->inputs[0]);280 ret = ff_request_frame(ctx->inputs[0]);
267 }while(!aresample->req_fullfilled && ret>=0);281 }while(!aresample->req_fullfilled && ret>=0);
268 282
283 // Third if we hit the end flush
269 if (ret == AVERROR_EOF) {284 if (ret == AVERROR_EOF) {
270 AVFrame *outsamplesref;285 AVFrame *outsamplesref;
271 286

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