It is the same as avfilter_get_audio_buffer_ref_from_arrays except it has a "channels" and the channel layout can be 0.
Unified · Split
| @@ -58,9 +58,9 @@ AVFilterBufferRef *ff_default_get_audio_buffer(AVFilterLink *link, int perms, · 57 unmodified lines | |||
| 58 | if (av_samples_alloc(data, &linesize, nb_channels, nb_samples, link->format, 0) < 0) | 58 | if (av_samples_alloc(data, &linesize, nb_channels, nb_samples, link->format, 0) < 0) |
| 59 | goto fail; | 59 | goto fail; |
| 60 | 60 | ||
| 61 | samplesref = avfilter_get_audio_buffer_ref_from_arrays(data, linesize, full_perms, | 61 | samplesref = avfilter_get_audio_buffer_ref_from_arrays_channels( |
| 62 | nb_samples, link->format, | 62 | data, linesize, full_perms, nb_samples, link->format, |
| 63 | link->channel_layout); | 63 | link->channels, link->channel_layout); |
| 64 | if (!samplesref) | 64 | if (!samplesref) |
| 65 | goto fail; | 65 | goto fail; |
| 66 | 66 | ||
| @@ -92,13 +92,14 @@ AVFilterBufferRef *ff_get_audio_buffer(AVFilterLink *link, int perms, · 25 unmodified lines | |||
| 92 | return ret; | 92 | return ret; |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data, | 95 | AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays_channels(uint8_t **data, |
| 96 | int linesize,int perms, | 96 | int linesize, |
| 97 | int nb_samples, | 97 | int perms, |
| 98 | enum AVSampleFormat sample_fmt, | 98 | int nb_samples, |
| 99 | uint64_t channel_layout) | 99 | enum AVSampleFormat sample_fmt, |
| 100 | int channels, | ||
| 101 | uint64_t channel_layout) | ||
| 100 | { | 102 | { |
| 101 | int channels = av_get_channel_layout_nb_channels(channel_layout); | ||
| 102 | int planes; | 103 | int planes; |
| 103 | AVFilterBuffer *samples = av_mallocz(sizeof(*samples)); | 104 | AVFilterBuffer *samples = av_mallocz(sizeof(*samples)); |
| 104 | AVFilterBufferRef *samplesref = av_mallocz(sizeof(*samplesref)); | 105 | AVFilterBufferRef *samplesref = av_mallocz(sizeof(*samplesref)); |
| @@ -106,6 +107,10 @@ AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data, · 1 unmodified line | |||
| 106 | if (!samples || !samplesref) | 107 | if (!samples || !samplesref) |
| 107 | goto fail; | 108 | goto fail; |
| 108 | 109 | ||
| 110 | av_assert0(channels); | ||
| 111 | av_assert0(channel_layout == 0 || | ||
| 112 | channels == av_get_channel_layout_nb_channels(channel_layout)); | ||
| 113 | |||
| 109 | samplesref->buf = samples; | 114 | samplesref->buf = samples; |
| 110 | samplesref->buf->free = ff_avfilter_default_free_buffer; | 115 | samplesref->buf->free = ff_avfilter_default_free_buffer; |
| 111 | if (!(samplesref->audio = av_mallocz(sizeof(*samplesref->audio)))) | 116 | if (!(samplesref->audio = av_mallocz(sizeof(*samplesref->audio)))) |
| @@ -163,6 +168,18 @@ fail: · 51 unmodified lines | |||
| 163 | return NULL; | 168 | return NULL; |
| 164 | } | 169 | } |
| 165 | 170 | ||
| 171 | AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data, | ||
| 172 | int linesize,int perms, | ||
| 173 | int nb_samples, | ||
| 174 | enum AVSampleFormat sample_fmt, | ||
| 175 | uint64_t channel_layout) | ||
| 176 | { | ||
| 177 | int channels = av_get_channel_layout_nb_channels(channel_layout); | ||
| 178 | return avfilter_get_audio_buffer_ref_from_arrays_channels(data, linesize, perms, | ||
| 179 | nb_samples, sample_fmt, | ||
| 180 | channels, channel_layout); | ||
| 181 | } | ||
| 182 | |||
| 166 | static int default_filter_frame(AVFilterLink *link, AVFilterBufferRef *frame) | 183 | static int default_filter_frame(AVFilterLink *link, AVFilterBufferRef *frame) |
| 167 | { | 184 | { |
| 168 | return ff_filter_frame(link->dst->outputs[0], frame); | 185 | return ff_filter_frame(link->dst->outputs[0], frame); |
| @@ -93,6 +93,7 @@ AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_frame(const AVFrame *frame · 92 unmodified lines | |||
| 93 | int perms) | 93 | int perms) |
| 94 | { | 94 | { |
| 95 | AVFilterBufferRef *samplesref; | 95 | AVFilterBufferRef *samplesref; |
| 96 | int channels = av_frame_get_channels(frame); | ||
| 96 | int64_t layout = av_frame_get_channel_layout(frame); | 97 | int64_t layout = av_frame_get_channel_layout(frame); |
| 97 | 98 | ||
| 98 | if(av_frame_get_channels(frame) > 8) // libavfilter does not suport more than 8 channels FIXME, remove once libavfilter is fixed | 99 | if(av_frame_get_channels(frame) > 8) // libavfilter does not suport more than 8 channels FIXME, remove once libavfilter is fixed |
| @@ -103,9 +104,9 @@ AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_frame(const AVFrame *frame · 4 unmodified lines | |||
| 103 | return NULL; | 104 | return NULL; |
| 104 | } | 105 | } |
| 105 | 106 | ||
| 106 | samplesref = avfilter_get_audio_buffer_ref_from_arrays((uint8_t **)frame->data, frame->linesize[0], perms, | 107 | samplesref = avfilter_get_audio_buffer_ref_from_arrays_channels( |
| 107 | frame->nb_samples, frame->format, | 108 | (uint8_t **)frame->data, frame->linesize[0], perms, |
| 108 | av_frame_get_channel_layout(frame)); | 109 | frame->nb_samples, frame->format, channels, layout); |
| 109 | if (!samplesref) | 110 | if (!samplesref) |
| 110 | return NULL; | 111 | return NULL; |
| 111 | if (avfilter_copy_frame_props(samplesref, frame) < 0) { | 112 | if (avfilter_copy_frame_props(samplesref, frame) < 0) { |
| @@ -765,6 +765,9 @@ avfilter_get_video_buffer_ref_from_arrays(uint8_t * const data[4], const int lin · 764 unmodified lines | |||
| 765 | * Create an audio buffer reference wrapped around an already | 765 | * Create an audio buffer reference wrapped around an already |
| 766 | * allocated samples buffer. | 766 | * allocated samples buffer. |
| 767 | * | 767 | * |
| 768 | * See avfilter_get_audio_buffer_ref_from_arrays_channels() for a version | ||
| 769 | * that can handle unknown channel layouts. | ||
| 770 | * | ||
| 768 | * @param data pointers to the samples plane buffers | 771 | * @param data pointers to the samples plane buffers |
| 769 | * @param linesize linesize for the samples plane buffers | 772 | * @param linesize linesize for the samples plane buffers |
| 770 | * @param perms the required access permissions | 773 | * @param perms the required access permissions |
| @@ -778,6 +781,27 @@ AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data, · 7 unmodified lines | |||
| 778 | int nb_samples, | 781 | int nb_samples, |
| 779 | enum AVSampleFormat sample_fmt, | 782 | enum AVSampleFormat sample_fmt, |
| 780 | uint64_t channel_layout); | 783 | uint64_t channel_layout); |
| 784 | /** | ||
| 785 | * Create an audio buffer reference wrapped around an already | ||
| 786 | * allocated samples buffer. | ||
| 787 | * | ||
| 788 | * @param data pointers to the samples plane buffers | ||
| 789 | * @param linesize linesize for the samples plane buffers | ||
| 790 | * @param perms the required access permissions | ||
| 791 | * @param nb_samples number of samples per channel | ||
| 792 | * @param sample_fmt the format of each sample in the buffer to allocate | ||
| 793 | * @param channels the number of channels of the buffer | ||
| 794 | * @param channel_layout the channel layout of the buffer, | ||
| 795 | * must be either 0 or consistent with channels | ||
| 796 | */ | ||
| 797 | AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays_channels(uint8_t **data, | ||
| 798 | int linesize, | ||
| 799 | int perms, | ||
| 800 | int nb_samples, | ||
| 801 | enum AVSampleFormat sample_fmt, | ||
| 802 | int channels, | ||
| 803 | uint64_t channel_layout); | ||
| 804 | |||
| 781 | 805 | ||
| 782 | 806 | ||
| 783 | #define AVFILTER_CMD_FLAG_ONE 1 ///< Stop once a filter understood the command (for target=all for example), fast filters are favored automatically | 807 | #define AVFILTER_CMD_FLAG_ONE 1 ///< Stop once a filter understood the command (for target=all for example), fast filters are favored automatically |
| @@ -81,6 +81,8 @@ int av_asrc_buffer_add_samples(AVFilterContext *ctx, · 80 unmodified lines | |||
| 81 | { | 81 | { |
| 82 | AVFilterBufferRef *samplesref; | 82 | AVFilterBufferRef *samplesref; |
| 83 | 83 | ||
| 84 | if (!channel_layout) | ||
| 85 | return AVERROR(EINVAL); | ||
| 84 | samplesref = avfilter_get_audio_buffer_ref_from_arrays( | 86 | samplesref = avfilter_get_audio_buffer_ref_from_arrays( |
| 85 | data, linesize[0], AV_PERM_WRITE, | 87 | data, linesize[0], AV_PERM_WRITE, |
| 86 | nb_samples, | 88 | nb_samples, |