| @@ -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 | |
| 101 | static int request_frame(AVFilterLink *link) | 105 | static 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 | |
| 106 | AVFilter avfilter_asrc_anullsrc = { | 124 | AVFilter avfilter_asrc_anullsrc = { |