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
309 309
310@section anullsrc310@section anullsrc
311 311
312Null audio source, never return audio frames. It is mainly useful as a312Null audio source, return unprocessed audio frames. It is mainly useful
313template and to be employed in analysis / debugging tools.313as a template and to be employed in analysis / debugging tools, or as
314the source for filters which ignore the input data (for example the sox
315synth filter).
314 316
315It accepts an optional sequence of @var{key}=@var{value} pairs,317It accepts an optional sequence of @var{key}=@var{value} pairs,
316separated by ":".318separated by ":".
@@ -331,6 +333,10 @@ is "stereo". · 14 unmodified lines
331Check the channel_layout_map definition in333Check the channel_layout_map definition in
332@file{libavcodec/audioconvert.c} for the mapping between strings and334@file{libavcodec/audioconvert.c} for the mapping between strings and
333channel layout values.335channel layout values.
336
337@item nb_samples, n
338Set the number of samples per requested frames.
339
334@end table340@end table
335 341
336Follow some examples:342Follow some examples:
libavfilter/asrc_anullsrc.c+22−4
@@ -33,6 +33,8 @@ typedef struct { · 32 unmodified lines
33 int64_t channel_layout;33 int64_t channel_layout;
34 char *sample_rate_str;34 char *sample_rate_str;
35 int sample_rate;35 int sample_rate;
36 int nb_samples; ///< number of samples per requested frame
37 int64_t pts;
36} ANullContext;38} ANullContext;
37 39
38#define OFFSET(x) offsetof(ANullContext, x)40#define OFFSET(x) offsetof(ANullContext, x)
@@ -42,6 +44,8 @@ static const AVOption anullsrc_options[]= { · 3 unmodified lines
42 { "cl", "set channel_layout", OFFSET(channel_layout_str), FF_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0 },44 { "cl", "set channel_layout", OFFSET(channel_layout_str), FF_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0 },
43 { "sample_rate", "set sample rate", OFFSET(sample_rate_str) , FF_OPT_TYPE_STRING, {.str = "44100"}, 0, 0 },45 { "sample_rate", "set sample rate", OFFSET(sample_rate_str) , FF_OPT_TYPE_STRING, {.str = "44100"}, 0, 0 },
44 { "r", "set sample rate", OFFSET(sample_rate_str) , FF_OPT_TYPE_STRING, {.str = "44100"}, 0, 0 },46 { "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 },
45 { NULL },49 { NULL },
46};50};
47 51
@@ -92,15 +96,29 @@ static int config_props(AVFilterLink *outlink) · 44 unmodified lines
92 chans_nb = av_get_channel_layout_nb_channels(priv->channel_layout);96 chans_nb = av_get_channel_layout_nb_channels(priv->channel_layout);
93 av_get_channel_layout_string(buf, sizeof(buf), chans_nb, priv->channel_layout);97 av_get_channel_layout_string(buf, sizeof(buf), chans_nb, priv->channel_layout);
94 av_log(outlink->src, AV_LOG_INFO,98 av_log(outlink->src, AV_LOG_INFO,
95 "sample_rate:%d channel_layout:%"PRId64 " channel_layout_description:'%s'\n",99 "sample_rate:%d channel_layout:%"PRId64 " channel_layout_description:'%s' nb_samples:%d\n",
96 priv->sample_rate, priv->channel_layout, buf);100 priv->sample_rate, priv->channel_layout, buf, priv->nb_samples);
97 101
98 return 0;102 return 0;
99}103}
100 104
101static int request_frame(AVFilterLink *link)105static int request_frame(AVFilterLink *outlink)
102{106{
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;
104}122}
105 123
106AVFilter avfilter_asrc_anullsrc = {124AVFilter avfilter_asrc_anullsrc = {
libavfilter/avfilter.h+1−1
@@ -30,7 +30,7 @@ · 29 unmodified lines
30 30
31#define LIBAVFILTER_VERSION_MAJOR 231#define LIBAVFILTER_VERSION_MAJOR 2
32#define LIBAVFILTER_VERSION_MINOR 4332#define LIBAVFILTER_VERSION_MINOR 43
33#define LIBAVFILTER_VERSION_MICRO 133#define LIBAVFILTER_VERSION_MICRO 2
34 34
35#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \35#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
36 LIBAVFILTER_VERSION_MINOR, \36 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