| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) Stefano Sabatini | stefasab at gmail.com | ||
| 3 | * Copyright (c) S.N. Hemanth Meenakshisundaram | smeenaks at ucsd.edu | ||
| 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 | #include "libavutil/avassert.h" | ||
| 23 | #include "libavutil/channel_layout.h" | ||
| 24 | #include "libavutil/common.h" | ||
| 25 | #include "libavutil/cpu.h" | ||
| 26 | #include "libavutil/eval.h" | ||
| 27 | |||
| 28 | #include "audio.h" | ||
| 29 | #include "avfilter.h" | ||
| 30 | #include "avfilter_internal.h" | ||
| 31 | #include "filters.h" | ||
| 32 | #include "framepool.h" | ||
| 33 | |||
| 34 | const AVFilterPad ff_audio_default_filterpad[1] = { | ||
| 35 | { | ||
| 36 | .name = "default", | ||
| 37 | .type = AVMEDIA_TYPE_AUDIO, | ||
| 38 | } | ||
| 39 | }; | ||
| 40 | |||
| 41 | ✗ | AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples) | |
| 42 | { | ||
| 43 | ✗ | return ff_get_audio_buffer(link->dst->outputs[0], nb_samples); | |
| 44 | } | ||
| 45 | |||
| 46 | 277388 | AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples) | |
| 47 | { | ||
| 48 | 277388 | AVFrame *frame = NULL; | |
| 49 | 277388 | FilterLinkInternal *const li = ff_link_internal(link); | |
| 50 | 277388 | int channels = link->ch_layout.nb_channels; | |
| 51 | 277388 | int align = av_cpu_max_align(); | |
| 52 | |||
| 53 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 277388 times.
|
277388 | if (ff_frame_pool_audio_reinit(&li->frame_pool, channels, nb_samples, |
| 54 | 277388 | link->format, align) < 0) | |
| 55 | ✗ | return NULL; | |
| 56 | |||
| 57 | 277388 | frame = ff_frame_pool_get(&li->frame_pool); | |
| 58 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 277388 times.
|
277388 | if (!frame) |
| 59 | ✗ | return NULL; | |
| 60 | |||
| 61 | 277388 | frame->nb_samples = nb_samples; | |
| 62 |
3/4✓ Branch 0 taken 242084 times.
✓ Branch 1 taken 35304 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 242084 times.
|
519472 | if (link->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC && |
| 63 | 242084 | av_channel_layout_copy(&frame->ch_layout, &link->ch_layout) < 0) { | |
| 64 | ✗ | av_frame_free(&frame); | |
| 65 | ✗ | return NULL; | |
| 66 | } | ||
| 67 | 277388 | frame->sample_rate = link->sample_rate; | |
| 68 | |||
| 69 | 277388 | av_samples_set_silence(frame->extended_data, 0, nb_samples, channels, link->format); | |
| 70 | |||
| 71 | 277388 | return frame; | |
| 72 | } | ||
| 73 | |||
| 74 | 277423 | AVFrame *ff_get_audio_buffer(AVFilterLink *link, int nb_samples) | |
| 75 | { | ||
| 76 | 277423 | AVFrame *ret = NULL; | |
| 77 | |||
| 78 |
2/2✓ Branch 0 taken 350 times.
✓ Branch 1 taken 277073 times.
|
277423 | if (link->dstpad->get_buffer.audio) |
| 79 | 350 | ret = link->dstpad->get_buffer.audio(link, nb_samples); | |
| 80 | |||
| 81 |
2/2✓ Branch 0 taken 277073 times.
✓ Branch 1 taken 350 times.
|
277423 | if (!ret) |
| 82 | 277073 | ret = ff_default_get_audio_buffer(link, nb_samples); | |
| 83 | |||
| 84 | 277423 | return ret; | |
| 85 | } | ||
| 86 | |||
| 87 | 16 | int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx) | |
| 88 | { | ||
| 89 | char *tail; | ||
| 90 | 16 | double srate = av_strtod(arg, &tail); | |
| 91 |
4/8✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 16 times.
|
16 | if (*tail || srate < 1 || (int)srate != srate || srate > INT_MAX) { |
| 92 | ✗ | av_log(log_ctx, AV_LOG_ERROR, "Invalid sample rate '%s'\n", arg); | |
| 93 | ✗ | return AVERROR(EINVAL); | |
| 94 | } | ||
| 95 | 16 | *ret = srate; | |
| 96 | 16 | return 0; | |
| 97 | } | ||
| 98 | |||
| 99 | 69 | int ff_parse_channel_layout(AVChannelLayout *ret, int *nret, const char *arg, | |
| 100 | void *log_ctx) | ||
| 101 | { | ||
| 102 | 69 | AVChannelLayout chlayout = { 0 }; | |
| 103 | int res; | ||
| 104 | |||
| 105 | 69 | res = av_channel_layout_from_string(&chlayout, arg); | |
| 106 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 64 times.
|
69 | if (res < 0) { |
| 107 | 5 | av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n", arg); | |
| 108 | 5 | return AVERROR(EINVAL); | |
| 109 | } | ||
| 110 | |||
| 111 |
3/4✓ Branch 0 taken 13 times.
✓ Branch 1 taken 51 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13 times.
|
64 | if (chlayout.order == AV_CHANNEL_ORDER_UNSPEC && !nret) { |
| 112 | ✗ | av_log(log_ctx, AV_LOG_ERROR, "Unknown channel layout '%s' is not supported.\n", arg); | |
| 113 | ✗ | return AVERROR(EINVAL); | |
| 114 | } | ||
| 115 | 64 | *ret = chlayout; | |
| 116 |
1/2✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
|
64 | if (nret) |
| 117 | 64 | *nret = chlayout.nb_channels; | |
| 118 | |||
| 119 | 64 | return 0; | |
| 120 | } | ||
| 121 |