| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2011 Stefano Sabatini | ||
| 3 | * Copyright (c) 2011 Mina Nagy Zaki | ||
| 4 | * | ||
| 5 | * This file is part of FFmpeg. | ||
| 6 | * | ||
| 7 | * FFmpeg is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with FFmpeg; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | /** | ||
| 23 | * @file | ||
| 24 | * resampling audio filter | ||
| 25 | */ | ||
| 26 | |||
| 27 | #include "libavutil/avstring.h" | ||
| 28 | #include "libavutil/channel_layout.h" | ||
| 29 | #include "libavutil/downmix_info.h" | ||
| 30 | #include "libavutil/opt.h" | ||
| 31 | #include "libavutil/samplefmt.h" | ||
| 32 | #include "libavutil/avassert.h" | ||
| 33 | #include "libswresample/swresample.h" | ||
| 34 | #include "avfilter.h" | ||
| 35 | #include "audio.h" | ||
| 36 | #include "filters.h" | ||
| 37 | #include "formats.h" | ||
| 38 | |||
| 39 | typedef struct AResampleContext { | ||
| 40 | const AVClass *class; | ||
| 41 | int sample_rate_arg; | ||
| 42 | double ratio; | ||
| 43 | struct SwrContext *swr; | ||
| 44 | int64_t next_pts; | ||
| 45 | int more_data; | ||
| 46 | } AResampleContext; | ||
| 47 | |||
| 48 | 2349 | static av_cold int preinit(AVFilterContext *ctx) | |
| 49 | { | ||
| 50 | 2349 | AResampleContext *aresample = ctx->priv; | |
| 51 | |||
| 52 | 2349 | aresample->next_pts = AV_NOPTS_VALUE; | |
| 53 | 2349 | aresample->swr = swr_alloc(); | |
| 54 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2349 times.
|
2349 | if (!aresample->swr) |
| 55 | ✗ | return AVERROR(ENOMEM); | |
| 56 | |||
| 57 | 2349 | return 0; | |
| 58 | } | ||
| 59 | |||
| 60 | 2349 | static av_cold void uninit(AVFilterContext *ctx) | |
| 61 | { | ||
| 62 | 2349 | AResampleContext *aresample = ctx->priv; | |
| 63 | 2349 | swr_free(&aresample->swr); | |
| 64 | 2349 | } | |
| 65 | |||
| 66 | 1490 | static int query_formats(const AVFilterContext *ctx, | |
| 67 | AVFilterFormatsConfig **cfg_in, | ||
| 68 | AVFilterFormatsConfig **cfg_out) | ||
| 69 | { | ||
| 70 | 1490 | const AResampleContext *aresample = ctx->priv; | |
| 71 | enum AVSampleFormat out_format; | ||
| 72 | 1490 | AVChannelLayout out_layout = { 0 }; | |
| 73 | int64_t out_rate; | ||
| 74 | |||
| 75 | AVFilterFormats *in_formats, *out_formats; | ||
| 76 | AVFilterFormats *in_samplerates, *out_samplerates; | ||
| 77 | AVFilterChannelLayouts *in_layouts, *out_layouts; | ||
| 78 | int ret; | ||
| 79 | |||
| 80 |
2/2✓ Branch 0 taken 640 times.
✓ Branch 1 taken 850 times.
|
1490 | if (aresample->sample_rate_arg > 0) |
| 81 | 640 | av_opt_set_int(aresample->swr, "osr", aresample->sample_rate_arg, 0); | |
| 82 | 1490 | av_opt_get_sample_fmt(aresample->swr, "osf", 0, &out_format); | |
| 83 | 1490 | av_opt_get_int(aresample->swr, "osr", 0, &out_rate); | |
| 84 | |||
| 85 | 1490 | in_formats = ff_all_formats(AVMEDIA_TYPE_AUDIO); | |
| 86 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1490 times.
|
1490 | if ((ret = ff_formats_ref(in_formats, &cfg_in[0]->formats)) < 0) |
| 87 | ✗ | return ret; | |
| 88 | |||
| 89 | 1490 | in_samplerates = ff_all_samplerates(); | |
| 90 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1490 times.
|
1490 | if ((ret = ff_formats_ref(in_samplerates, &cfg_in[0]->samplerates)) < 0) |
| 91 | ✗ | return ret; | |
| 92 | |||
| 93 | 1490 | in_layouts = ff_all_channel_counts(); | |
| 94 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1490 times.
|
1490 | if ((ret = ff_channel_layouts_ref(in_layouts, &cfg_in[0]->channel_layouts)) < 0) |
| 95 | ✗ | return ret; | |
| 96 | |||
| 97 |
2/2✓ Branch 0 taken 640 times.
✓ Branch 1 taken 850 times.
|
1490 | if(out_rate > 0) { |
| 98 | 640 | int ratelist[] = { out_rate, -1 }; | |
| 99 | 640 | out_samplerates = ff_make_format_list(ratelist); | |
| 100 | } else { | ||
| 101 | 850 | out_samplerates = ff_all_samplerates(); | |
| 102 | } | ||
| 103 | |||
| 104 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1490 times.
|
1490 | if ((ret = ff_formats_ref(out_samplerates, &cfg_out[0]->samplerates)) < 0) |
| 105 | ✗ | return ret; | |
| 106 | |||
| 107 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1490 times.
|
1490 | if(out_format != AV_SAMPLE_FMT_NONE) { |
| 108 | ✗ | int formatlist[] = { out_format, -1 }; | |
| 109 | ✗ | out_formats = ff_make_format_list(formatlist); | |
| 110 | } else | ||
| 111 | 1490 | out_formats = ff_all_formats(AVMEDIA_TYPE_AUDIO); | |
| 112 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1490 times.
|
1490 | if ((ret = ff_formats_ref(out_formats, &cfg_out[0]->formats)) < 0) |
| 113 | ✗ | return ret; | |
| 114 | |||
| 115 | 1490 | av_opt_get_chlayout(aresample->swr, "ochl", 0, &out_layout); | |
| 116 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1490 times.
|
1490 | if (av_channel_layout_check(&out_layout)) { |
| 117 | ✗ | const AVChannelLayout layout_list[] = { out_layout, { 0 } }; | |
| 118 | ✗ | out_layouts = ff_make_channel_layout_list(layout_list); | |
| 119 | } else | ||
| 120 | 1490 | out_layouts = ff_all_channel_counts(); | |
| 121 | 1490 | av_channel_layout_uninit(&out_layout); | |
| 122 | |||
| 123 | 1490 | return ff_channel_layouts_ref(out_layouts, &cfg_out[0]->channel_layouts); | |
| 124 | } | ||
| 125 | |||
| 126 | #define SWR_CH_MAX 64 | ||
| 127 | |||
| 128 | 1490 | static int config_output(AVFilterLink *outlink) | |
| 129 | { | ||
| 130 | int ret; | ||
| 131 | 1490 | AVFilterContext *ctx = outlink->src; | |
| 132 | 1490 | AVFilterLink *inlink = ctx->inputs[0]; | |
| 133 | 1490 | AResampleContext *aresample = ctx->priv; | |
| 134 | 1490 | AVChannelLayout out_layout = { 0 }; | |
| 135 | int64_t out_rate; | ||
| 136 | const AVFrameSideData *sd; | ||
| 137 | enum AVSampleFormat out_format; | ||
| 138 | char inchl_buf[128], outchl_buf[128]; | ||
| 139 | |||
| 140 | 1490 | ret = swr_alloc_set_opts2(&aresample->swr, | |
| 141 | 1490 | &outlink->ch_layout, outlink->format, outlink->sample_rate, | |
| 142 | 1490 | &inlink->ch_layout, inlink->format, inlink->sample_rate, | |
| 143 | 0, ctx); | ||
| 144 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1490 times.
|
1490 | if (ret < 0) |
| 145 | ✗ | return ret; | |
| 146 | |||
| 147 | 1490 | sd = av_frame_side_data_get(inlink->side_data, inlink->nb_side_data, | |
| 148 | AV_FRAME_DATA_DOWNMIX_INFO); | ||
| 149 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1485 times.
|
1490 | if (sd) { |
| 150 | 5 | const AVDownmixInfo *di = (AVDownmixInfo *)sd->data; | |
| 151 | 5 | enum AVMatrixEncoding matrix_encoding = AV_MATRIX_ENCODING_NONE; | |
| 152 | double center_mix_level, surround_mix_level; | ||
| 153 | |||
| 154 |
3/3✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 3 times.
|
5 | switch (di->preferred_downmix_type) { |
| 155 | 1 | case AV_DOWNMIX_TYPE_LTRT: | |
| 156 | 1 | matrix_encoding = AV_MATRIX_ENCODING_DOLBY; | |
| 157 | 1 | center_mix_level = di->center_mix_level_ltrt; | |
| 158 | 1 | surround_mix_level = di->surround_mix_level_ltrt; | |
| 159 | 1 | break; | |
| 160 | 1 | case AV_DOWNMIX_TYPE_DPLII: | |
| 161 | 1 | matrix_encoding = AV_MATRIX_ENCODING_DPLII; | |
| 162 | 1 | center_mix_level = di->center_mix_level_ltrt; | |
| 163 | 1 | surround_mix_level = di->surround_mix_level_ltrt; | |
| 164 | 1 | break; | |
| 165 | 3 | default: | |
| 166 | 3 | center_mix_level = di->center_mix_level; | |
| 167 | 3 | surround_mix_level = di->surround_mix_level; | |
| 168 | 3 | break; | |
| 169 | } | ||
| 170 | |||
| 171 | 5 | av_log(ctx, AV_LOG_VERBOSE, "Mix levels: center %f - " | |
| 172 | "surround %f - lfe %f.\n", | ||
| 173 | 5 | center_mix_level, surround_mix_level, di->lfe_mix_level); | |
| 174 | |||
| 175 | 5 | av_opt_set_double(aresample->swr, "clev", center_mix_level, 0); | |
| 176 | 5 | av_opt_set_double(aresample->swr, "slev", surround_mix_level, 0); | |
| 177 | 5 | av_opt_set_double(aresample->swr, "lfe_mix_level", di->lfe_mix_level, 0); | |
| 178 | 5 | av_opt_set_int(aresample->swr, "matrix_encoding", matrix_encoding, 0); | |
| 179 | |||
| 180 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | if (av_channel_layout_compare(&outlink->ch_layout, &out_layout)) |
| 181 | 5 | av_frame_side_data_remove(&outlink->side_data, &outlink->nb_side_data, | |
| 182 | AV_FRAME_DATA_DOWNMIX_INFO); | ||
| 183 | } | ||
| 184 | |||
| 185 | 1490 | ret = swr_init(aresample->swr); | |
| 186 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1490 times.
|
1490 | if (ret < 0) |
| 187 | ✗ | return ret; | |
| 188 | |||
| 189 | 1490 | av_opt_get_int(aresample->swr, "osr", 0, &out_rate); | |
| 190 | 1490 | av_opt_get_chlayout(aresample->swr, "ochl", 0, &out_layout); | |
| 191 | 1490 | av_opt_get_sample_fmt(aresample->swr, "osf", 0, &out_format); | |
| 192 | 1490 | outlink->time_base = (AVRational) {1, out_rate}; | |
| 193 | |||
| 194 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1490 times.
|
1490 | av_assert0(outlink->sample_rate == out_rate); |
| 195 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1490 times.
|
1490 | av_assert0(!av_channel_layout_compare(&outlink->ch_layout, &out_layout)); |
| 196 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1490 times.
|
1490 | av_assert0(outlink->format == out_format); |
| 197 | |||
| 198 | 1490 | av_channel_layout_uninit(&out_layout); | |
| 199 | |||
| 200 | 1490 | aresample->ratio = (double)outlink->sample_rate / inlink->sample_rate; | |
| 201 | |||
| 202 | 1490 | av_channel_layout_describe(&inlink ->ch_layout, inchl_buf, sizeof(inchl_buf)); | |
| 203 | 1490 | av_channel_layout_describe(&outlink->ch_layout, outchl_buf, sizeof(outchl_buf)); | |
| 204 | |||
| 205 | 1490 | av_log(ctx, AV_LOG_VERBOSE, "ch:%d chl:%s fmt:%s r:%dHz -> ch:%d chl:%s fmt:%s r:%dHz\n", | |
| 206 | 1490 | inlink ->ch_layout.nb_channels, inchl_buf, av_get_sample_fmt_name(inlink->format), inlink->sample_rate, | |
| 207 | 1490 | outlink->ch_layout.nb_channels, outchl_buf, av_get_sample_fmt_name(outlink->format), outlink->sample_rate); | |
| 208 | 1490 | return 0; | |
| 209 | } | ||
| 210 | |||
| 211 | 221286 | static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref, AVFrame **outsamplesref_ret) | |
| 212 | { | ||
| 213 | 221286 | AVFilterContext *ctx = inlink->dst; | |
| 214 | 221286 | AResampleContext *aresample = ctx->priv; | |
| 215 | 221286 | const int n_in = insamplesref->nb_samples; | |
| 216 | int64_t delay; | ||
| 217 | 221286 | int n_out = n_in * aresample->ratio + 32; | |
| 218 | 221286 | AVFilterLink *const outlink = inlink->dst->outputs[0]; | |
| 219 | AVFrame *outsamplesref; | ||
| 220 | int ret; | ||
| 221 | |||
| 222 | 221286 | *outsamplesref_ret = NULL; | |
| 223 | 221286 | delay = swr_get_delay(aresample->swr, outlink->sample_rate); | |
| 224 |
2/2✓ Branch 0 taken 7761 times.
✓ Branch 1 taken 213525 times.
|
221286 | if (delay > 0) |
| 225 | 7761 | n_out += FFMIN(delay, FFMAX(4096, n_out)); | |
| 226 | |||
| 227 | 221286 | outsamplesref = ff_get_audio_buffer(outlink, n_out); | |
| 228 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 221286 times.
|
221286 | if (!outsamplesref) |
| 229 | ✗ | return AVERROR(ENOMEM); | |
| 230 | |||
| 231 | 221286 | av_frame_copy_props(outsamplesref, insamplesref); | |
| 232 | 221286 | outsamplesref->format = outlink->format; | |
| 233 | 221286 | ret = av_channel_layout_copy(&outsamplesref->ch_layout, &outlink->ch_layout); | |
| 234 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 221286 times.
|
221286 | if (ret < 0) { |
| 235 | ✗ | av_frame_free(&outsamplesref); | |
| 236 | ✗ | return ret; | |
| 237 | } | ||
| 238 | 221286 | outsamplesref->sample_rate = outlink->sample_rate; | |
| 239 | |||
| 240 |
2/2✓ Branch 1 taken 535 times.
✓ Branch 2 taken 220751 times.
|
221286 | if (av_channel_layout_compare(&outsamplesref->ch_layout, &insamplesref->ch_layout)) |
| 241 | 535 | av_frame_side_data_remove_by_props(&outsamplesref->side_data, &outsamplesref->nb_side_data, | |
| 242 | AV_SIDE_DATA_PROP_CHANNEL_DEPENDENT); | ||
| 243 | |||
| 244 |
1/2✓ Branch 0 taken 221286 times.
✗ Branch 1 not taken.
|
221286 | if(insamplesref->pts != AV_NOPTS_VALUE) { |
| 245 | 221286 | int64_t inpts = av_rescale(insamplesref->pts, inlink->time_base.num * (int64_t)outlink->sample_rate * inlink->sample_rate, inlink->time_base.den); | |
| 246 | 221286 | int64_t outpts= swr_next_pts(aresample->swr, inpts); | |
| 247 | 221286 | aresample->next_pts = | |
| 248 |
2/2✓ Branch 0 taken 221284 times.
✓ Branch 1 taken 2 times.
|
221286 | outsamplesref->pts = ROUNDED_DIV(outpts, inlink->sample_rate); |
| 249 | } else { | ||
| 250 | ✗ | outsamplesref->pts = AV_NOPTS_VALUE; | |
| 251 | } | ||
| 252 | 221286 | n_out = swr_convert(aresample->swr, outsamplesref->extended_data, n_out, | |
| 253 | 221286 | (void *)insamplesref->extended_data, n_in); | |
| 254 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 221286 times.
|
221286 | if (n_out <= 0) { |
| 255 | ✗ | av_frame_free(&outsamplesref); | |
| 256 | ✗ | return 0; | |
| 257 | } | ||
| 258 | |||
| 259 | 221286 | aresample->more_data = outsamplesref->nb_samples == n_out; // Indicate that there is probably more data in our buffers | |
| 260 | |||
| 261 | 221286 | outsamplesref->nb_samples = n_out; | |
| 262 | |||
| 263 | 221286 | *outsamplesref_ret = outsamplesref; | |
| 264 | 221286 | return 1; | |
| 265 | } | ||
| 266 | |||
| 267 | 2041 | static int flush_frame(AVFilterLink *outlink, int final, AVFrame **outsamplesref_ret) | |
| 268 | { | ||
| 269 | 2041 | AVFilterContext *ctx = outlink->src; | |
| 270 | 2041 | AResampleContext *aresample = ctx->priv; | |
| 271 | 2041 | AVFilterLink *const inlink = outlink->src->inputs[0]; | |
| 272 | AVFrame *outsamplesref; | ||
| 273 | 2041 | int n_out = 4096; | |
| 274 | int64_t pts; | ||
| 275 | |||
| 276 | 2041 | outsamplesref = ff_get_audio_buffer(outlink, n_out); | |
| 277 | 2041 | *outsamplesref_ret = outsamplesref; | |
| 278 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2041 times.
|
2041 | if (!outsamplesref) |
| 279 | ✗ | return AVERROR(ENOMEM); | |
| 280 | |||
| 281 | 2041 | pts = swr_next_pts(aresample->swr, INT64_MIN); | |
| 282 |
1/2✓ Branch 0 taken 2041 times.
✗ Branch 1 not taken.
|
2041 | pts = ROUNDED_DIV(pts, inlink->sample_rate); |
| 283 | |||
| 284 |
2/2✓ Branch 0 taken 127 times.
✓ Branch 1 taken 1914 times.
|
2041 | n_out = swr_convert(aresample->swr, outsamplesref->extended_data, n_out, final ? NULL : (void*)outsamplesref->extended_data, 0); |
| 285 |
2/2✓ Branch 0 taken 1282 times.
✓ Branch 1 taken 759 times.
|
2041 | if (n_out <= 0) { |
| 286 | 1282 | av_frame_free(&outsamplesref); | |
| 287 | 1282 | return n_out; | |
| 288 | } | ||
| 289 | |||
| 290 | 759 | outsamplesref->sample_rate = outlink->sample_rate; | |
| 291 | 759 | outsamplesref->nb_samples = n_out; | |
| 292 | |||
| 293 | 759 | outsamplesref->pts = pts; | |
| 294 | |||
| 295 | 759 | return 1; | |
| 296 | } | ||
| 297 | |||
| 298 | 447055 | static int activate(AVFilterContext *ctx) | |
| 299 | { | ||
| 300 | 447055 | AVFilterLink *inlink = ctx->inputs[0]; | |
| 301 | 447055 | AVFilterLink *outlink = ctx->outputs[0]; | |
| 302 | 447055 | AResampleContext *aresample = ctx->priv; | |
| 303 | AVFrame *frame; | ||
| 304 | 447055 | int ret = 0, status; | |
| 305 | int64_t pts; | ||
| 306 | |||
| 307 |
2/2✓ Branch 1 taken 1103 times.
✓ Branch 2 taken 445952 times.
|
447055 | FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink); |
| 308 | |||
| 309 | // First try to get data from the internal buffers | ||
| 310 |
2/2✓ Branch 0 taken 127 times.
✓ Branch 1 taken 445825 times.
|
445952 | if (aresample->more_data) { |
| 311 | AVFrame *outsamplesref; | ||
| 312 | |||
| 313 | 127 | ret = flush_frame(outlink, 0, &outsamplesref); | |
| 314 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 127 times.
|
127 | if (ret < 0) |
| 315 | 123 | return ret; | |
| 316 |
2/2✓ Branch 0 taken 123 times.
✓ Branch 1 taken 4 times.
|
127 | if (ret > 0) |
| 317 | 123 | return ff_filter_frame(outlink, outsamplesref); | |
| 318 | } | ||
| 319 | 445829 | aresample->more_data = 0; | |
| 320 | |||
| 321 | // Then consume frames from inlink | ||
| 322 |
2/2✓ Branch 1 taken 221286 times.
✓ Branch 2 taken 224543 times.
|
445829 | while ((ret = ff_inlink_consume_frame(inlink, &frame))) { |
| 323 | AVFrame *outsamplesref; | ||
| 324 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 221286 times.
|
221286 | if (ret < 0) |
| 325 | 221286 | return ret; | |
| 326 | |||
| 327 | 221286 | ret = filter_frame(inlink, frame, &outsamplesref); | |
| 328 | 221286 | av_frame_free(&frame); | |
| 329 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 221286 times.
|
221286 | if (ret < 0) |
| 330 | ✗ | return ret; | |
| 331 |
1/2✓ Branch 0 taken 221286 times.
✗ Branch 1 not taken.
|
221286 | if (ret > 0) |
| 332 | 221286 | return ff_filter_frame(outlink, outsamplesref); | |
| 333 | } | ||
| 334 | |||
| 335 | // If we hit the end flush | ||
| 336 |
2/2✓ Branch 1 taken 1914 times.
✓ Branch 2 taken 222629 times.
|
224543 | if (ff_inlink_acknowledge_status(inlink, &status, &pts)) { |
| 337 | AVFrame *outsamplesref; | ||
| 338 | |||
| 339 | 1914 | ret = flush_frame(outlink, 1, &outsamplesref); | |
| 340 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1914 times.
|
1914 | if (ret < 0) |
| 341 | ✗ | return ret; | |
| 342 |
2/2✓ Branch 0 taken 636 times.
✓ Branch 1 taken 1278 times.
|
1914 | if (ret > 0) |
| 343 | 636 | return ff_filter_frame(outlink, outsamplesref); | |
| 344 | 1278 | ff_outlink_set_status(outlink, status, aresample->next_pts); | |
| 345 | 1278 | return 0; | |
| 346 | } | ||
| 347 | |||
| 348 | // If not, request more data from the input | ||
| 349 |
1/2✓ Branch 1 taken 222629 times.
✗ Branch 2 not taken.
|
222629 | FF_FILTER_FORWARD_WANTED(outlink, inlink); |
| 350 | |||
| 351 | ✗ | return FFERROR_NOT_READY; | |
| 352 | } | ||
| 353 | |||
| 354 | ✗ | static const AVClass *resample_child_class_iterate(void **iter) | |
| 355 | { | ||
| 356 | ✗ | const AVClass *c = *iter ? NULL : swr_get_class(); | |
| 357 | ✗ | *iter = (void*)(uintptr_t)c; | |
| 358 | ✗ | return c; | |
| 359 | } | ||
| 360 | |||
| 361 | 6689 | static void *resample_child_next(void *obj, void *prev) | |
| 362 | { | ||
| 363 | 6689 | AResampleContext *s = obj; | |
| 364 |
2/2✓ Branch 0 taken 5409 times.
✓ Branch 1 taken 1280 times.
|
6689 | return prev ? NULL : s->swr; |
| 365 | } | ||
| 366 | |||
| 367 | #define OFFSET(x) offsetof(AResampleContext, x) | ||
| 368 | #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM | ||
| 369 | |||
| 370 | static const AVOption options[] = { | ||
| 371 | {"sample_rate", NULL, OFFSET(sample_rate_arg), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS }, | ||
| 372 | {NULL} | ||
| 373 | }; | ||
| 374 | |||
| 375 | static const AVClass aresample_class = { | ||
| 376 | .class_name = "aresample", | ||
| 377 | .item_name = av_default_item_name, | ||
| 378 | .option = options, | ||
| 379 | .version = LIBAVUTIL_VERSION_INT, | ||
| 380 | .child_class_iterate = resample_child_class_iterate, | ||
| 381 | .child_next = resample_child_next, | ||
| 382 | }; | ||
| 383 | |||
| 384 | static const AVFilterPad aresample_outputs[] = { | ||
| 385 | { | ||
| 386 | .name = "default", | ||
| 387 | .config_props = config_output, | ||
| 388 | .type = AVMEDIA_TYPE_AUDIO, | ||
| 389 | }, | ||
| 390 | }; | ||
| 391 | |||
| 392 | const FFFilter ff_af_aresample = { | ||
| 393 | .p.name = "aresample", | ||
| 394 | .p.description = NULL_IF_CONFIG_SMALL("Resample audio data."), | ||
| 395 | .p.priv_class = &aresample_class, | ||
| 396 | .preinit = preinit, | ||
| 397 | .activate = activate, | ||
| 398 | .uninit = uninit, | ||
| 399 | .priv_size = sizeof(AResampleContext), | ||
| 400 | FILTER_INPUTS(ff_audio_default_filterpad), | ||
| 401 | FILTER_OUTPUTS(aresample_outputs), | ||
| 402 | FILTER_QUERY_FUNC2(query_formats), | ||
| 403 | }; | ||
| 404 |