This is mainly useful for filters (like the sox synth), which
overwrite the content of the passed data.
| ... | ... |
@@ -309,8 +309,10 @@ value is "-1". |
| 309 | 309 |
|
| 310 | 310 |
@section anullsrc |
| 311 | 311 |
|
| 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). |
|
| 314 | 316 |
|
| 315 | 317 |
It accepts an optional sequence of @var{key}=@var{value} pairs,
|
| 316 | 318 |
separated by ":". |
| ... | ... |
@@ -331,6 +333,10 @@ is "stereo". |
| 331 | 331 |
Check the channel_layout_map definition in |
| 332 | 332 |
@file{libavcodec/audioconvert.c} for the mapping between strings and
|
| 333 | 333 |
channel layout values. |
| 334 |
+ |
|
| 335 |
+@item nb_samples, n |
|
| 336 |
+Set the number of samples per requested frames. |
|
| 337 |
+ |
|
| 334 | 338 |
@end table |
| 335 | 339 |
|
| 336 | 340 |
Follow some examples: |
| ... | ... |
@@ -33,6 +33,8 @@ typedef struct {
|
| 33 | 33 |
int64_t channel_layout; |
| 34 | 34 |
char *sample_rate_str; |
| 35 | 35 |
int sample_rate; |
| 36 |
+ int nb_samples; ///< number of samples per requested frame |
|
| 37 |
+ int64_t pts; |
|
| 36 | 38 |
} ANullContext; |
| 37 | 39 |
|
| 38 | 40 |
#define OFFSET(x) offsetof(ANullContext, x) |
| ... | ... |
@@ -42,6 +44,8 @@ static const AVOption anullsrc_options[]= {
|
| 42 | 42 |
{ "cl", "set channel_layout", OFFSET(channel_layout_str), FF_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0 },
|
| 43 | 43 |
{ "sample_rate", "set sample rate", OFFSET(sample_rate_str) , FF_OPT_TYPE_STRING, {.str = "44100"}, 0, 0 },
|
| 44 | 44 |
{ "r", "set sample rate", OFFSET(sample_rate_str) , FF_OPT_TYPE_STRING, {.str = "44100"}, 0, 0 },
|
| 45 |
+ { "nb_samples", "set the number of samples per requested frame", OFFSET(nb_samples), FF_OPT_TYPE_INT, {.dbl = 1024}, 0, INT_MAX },
|
|
| 46 |
+ { "n", "set the number of samples per requested frame", OFFSET(nb_samples), FF_OPT_TYPE_INT, {.dbl = 1024}, 0, INT_MAX },
|
|
| 45 | 47 |
{ NULL },
|
| 46 | 48 |
}; |
| 47 | 49 |
|
| ... | ... |
@@ -92,15 +96,29 @@ static int config_props(AVFilterLink *outlink) |
| 92 | 92 |
chans_nb = av_get_channel_layout_nb_channels(priv->channel_layout); |
| 93 | 93 |
av_get_channel_layout_string(buf, sizeof(buf), chans_nb, priv->channel_layout); |
| 94 | 94 |
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); |
|
| 95 |
+ "sample_rate:%d channel_layout:%"PRId64 " channel_layout_description:'%s' nb_samples:%d\n", |
|
| 96 |
+ priv->sample_rate, priv->channel_layout, buf, priv->nb_samples); |
|
| 97 | 97 |
|
| 98 | 98 |
return 0; |
| 99 | 99 |
} |
| 100 | 100 |
|
| 101 |
-static int request_frame(AVFilterLink *link) |
|
| 101 |
+static int request_frame(AVFilterLink *outlink) |
|
| 102 | 102 |
{
|
| 103 |
- return -1; |
|
| 103 |
+ ANullContext *null = outlink->src->priv; |
|
| 104 |
+ AVFilterBufferRef *samplesref; |
|
| 105 |
+ |
|
| 106 |
+ samplesref = |
|
| 107 |
+ avfilter_get_audio_buffer(outlink, AV_PERM_WRITE, null->nb_samples); |
|
| 108 |
+ samplesref->pts = null->pts; |
|
| 109 |
+ samplesref->pos = -1; |
|
| 110 |
+ samplesref->audio->channel_layout = null->channel_layout; |
|
| 111 |
+ samplesref->audio->sample_rate = outlink->sample_rate; |
|
| 112 |
+ |
|
| 113 |
+ avfilter_filter_samples(outlink, avfilter_ref_buffer(samplesref, ~0)); |
|
| 114 |
+ avfilter_unref_buffer(samplesref); |
|
| 115 |
+ |
|
| 116 |
+ null->pts += null->nb_samples; |
|
| 117 |
+ return 0; |
|
| 104 | 118 |
} |
| 105 | 119 |
|
| 106 | 120 |
AVFilter avfilter_asrc_anullsrc = {
|
| ... | ... |
@@ -30,7 +30,7 @@ |
| 30 | 30 |
|
| 31 | 31 |
#define LIBAVFILTER_VERSION_MAJOR 2 |
| 32 | 32 |
#define LIBAVFILTER_VERSION_MINOR 43 |
| 33 |
-#define LIBAVFILTER_VERSION_MICRO 1 |
|
| 33 |
+#define LIBAVFILTER_VERSION_MICRO 2 |
|
| 34 | 34 |
|
| 35 | 35 |
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ |
| 36 | 36 |
LIBAVFILTER_VERSION_MINOR, \ |