History

asrc_anullsrc: implement a request_frame callback for returning frames

This is mainly useful for filters (like the sox synth), which overwrite the content of the passed data.

Stefano Sabatini committed 15 years ago

Commit e72aa521 parent 44ab77d3 files · +31 −7Browse files

Unified · Split

3 files
  1. doc/filters.texi +8 −2
  2. libavfilter/asrc_anullsrc.c +22 −4
  3. libavfilter/avfilter.h +1 −1
doc/filters.texi+8−2
@@ -309,8 +309,10 @@ value is "-1". · 308 unmodified lines
309309
310310 @section anullsrc
311311
312−Null audio source, never return audio frames. It is mainly useful as a
313−template and to be employed in analysis / debugging tools.
312+Null audio source, return unprocessed audio frames. It is mainly useful
313+as a template and to be employed in analysis / debugging tools, or as
314+the source for filters which ignore the input data (for example the sox
315+synth filter).
314316
315317 It accepts an optional sequence of @var{key}=@var{value} pairs,
316318 separated by ":".
@@ -331,6 +333,10 @@ is "stereo". · 14 unmodified lines
331333 Check the channel_layout_map definition in
332334 @file{libavcodec/audioconvert.c} for the mapping between strings and
333335 channel layout values.
336+
337+@item nb_samples, n
338+Set the number of samples per requested frames.
339+
334340 @end table
335341
336342 Follow some examples:
libavfilter/asrc_anullsrc.c+22−4
@@ -33,6 +33,8 @@ typedef struct { · 32 unmodified lines
3333 int64_t channel_layout;
3434 char *sample_rate_str;
3535 int sample_rate;
36+ int nb_samples; ///< number of samples per requested frame
37+ int64_t pts;
3638 } ANullContext;
3739
3840 #define OFFSET(x) offsetof(ANullContext, x)
@@ -42,6 +44,8 @@ static const AVOption anullsrc_options[]= { · 3 unmodified lines
4244 { "cl", "set channel_layout", OFFSET(channel_layout_str), FF_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0 },
4345 { "sample_rate", "set sample rate", OFFSET(sample_rate_str) , FF_OPT_TYPE_STRING, {.str = "44100"}, 0, 0 },
4446 { "r", "set sample rate", OFFSET(sample_rate_str) , FF_OPT_TYPE_STRING, {.str = "44100"}, 0, 0 },
47+ { "nb_samples", "set the number of samples per requested frame", OFFSET(nb_samples), FF_OPT_TYPE_INT, {.dbl = 1024}, 0, INT_MAX },
48+ { "n", "set the number of samples per requested frame", OFFSET(nb_samples), FF_OPT_TYPE_INT, {.dbl = 1024}, 0, INT_MAX },
4549 { NULL },
4650 };
4751
@@ -92,15 +96,29 @@ static int config_props(AVFilterLink *outlink) · 44 unmodified lines
9296 chans_nb = av_get_channel_layout_nb_channels(priv->channel_layout);
9397 av_get_channel_layout_string(buf, sizeof(buf), chans_nb, priv->channel_layout);
9498 av_log(outlink->src, AV_LOG_INFO,
95− "sample_rate:%d channel_layout:%"PRId64 " channel_layout_description:'%s'\n",
96− priv->sample_rate, priv->channel_layout, buf);
99+ "sample_rate:%d channel_layout:%"PRId64 " channel_layout_description:'%s' nb_samples:%d\n",
100+ priv->sample_rate, priv->channel_layout, buf, priv->nb_samples);
97101
98102 return 0;
99103 }
100104
101−static int request_frame(AVFilterLink *link)
105+static int request_frame(AVFilterLink *outlink)
102106 {
103− return -1;
107+ ANullContext *null = outlink->src->priv;
108+ AVFilterBufferRef *samplesref;
109+
110+ samplesref =
111+ avfilter_get_audio_buffer(outlink, AV_PERM_WRITE, null->nb_samples);
112+ samplesref->pts = null->pts;
113+ samplesref->pos = -1;
114+ samplesref->audio->channel_layout = null->channel_layout;
115+ samplesref->audio->sample_rate = outlink->sample_rate;
116+
117+ avfilter_filter_samples(outlink, avfilter_ref_buffer(samplesref, ~0));
118+ avfilter_unref_buffer(samplesref);
119+
120+ null->pts += null->nb_samples;
121+ return 0;
104122 }
105123
106124 AVFilter avfilter_asrc_anullsrc = {
libavfilter/avfilter.h+1−1
@@ -30,7 +30,7 @@ · 29 unmodified lines
3030
3131 #define LIBAVFILTER_VERSION_MAJOR 2
3232 #define LIBAVFILTER_VERSION_MINOR 43
33−#define LIBAVFILTER_VERSION_MICRO 1
33+#define LIBAVFILTER_VERSION_MICRO 2
3434
3535 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
3636 LIBAVFILTER_VERSION_MINOR, \

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