History

lavfi: add avfilter_get_audio_buffer_ref_from_arrays_channels.

It is the same as avfilter_get_audio_buffer_ref_from_arrays except it has a "channels" and the channel layout can be 0.

Nicolas George committed 13 years ago

Commit 2eb2e171 parent f105fe54 files · +56 −12Browse files

Unified · Split

4 files
  1. libavfilter/audio.c +26 −9
  2. libavfilter/avcodec.c +4 −3
  3. libavfilter/avfilter.h +24 −0
  4. libavfilter/src_buffer.c +2 −0
libavfilter/audio.c+26−9
@@ -58,9 +58,9 @@ AVFilterBufferRef *ff_default_get_audio_buffer(AVFilterLink *link, int perms, · 57 unmodified lines
5858 if (av_samples_alloc(data, &linesize, nb_channels, nb_samples, link->format, 0) < 0)
5959 goto fail;
6060
61− samplesref = avfilter_get_audio_buffer_ref_from_arrays(data, linesize, full_perms,
62− nb_samples, link->format,
63− link->channel_layout);
61+ samplesref = avfilter_get_audio_buffer_ref_from_arrays_channels(
62+ data, linesize, full_perms, nb_samples, link->format,
63+ link->channels, link->channel_layout);
6464 if (!samplesref)
6565 goto fail;
6666
@@ -92,13 +92,14 @@ AVFilterBufferRef *ff_get_audio_buffer(AVFilterLink *link, int perms, · 25 unmodified lines
9292 return ret;
9393 }
9494
95−AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
96− int linesize,int perms,
97− int nb_samples,
98− enum AVSampleFormat sample_fmt,
99− uint64_t channel_layout)
95+AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays_channels(uint8_t **data,
96+ int linesize,
97+ int perms,
98+ int nb_samples,
99+ enum AVSampleFormat sample_fmt,
100+ int channels,
101+ uint64_t channel_layout)
100102 {
101− int channels = av_get_channel_layout_nb_channels(channel_layout);
102103 int planes;
103104 AVFilterBuffer *samples = av_mallocz(sizeof(*samples));
104105 AVFilterBufferRef *samplesref = av_mallocz(sizeof(*samplesref));
@@ -106,6 +107,10 @@ AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data, · 1 unmodified line
106107 if (!samples || !samplesref)
107108 goto fail;
108109
110+ av_assert0(channels);
111+ av_assert0(channel_layout == 0 ||
112+ channels == av_get_channel_layout_nb_channels(channel_layout));
113+
109114 samplesref->buf = samples;
110115 samplesref->buf->free = ff_avfilter_default_free_buffer;
111116 if (!(samplesref->audio = av_mallocz(sizeof(*samplesref->audio))))
@@ -163,6 +168,18 @@ fail: · 51 unmodified lines
163168 return NULL;
164169 }
165170
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+
166183 static int default_filter_frame(AVFilterLink *link, AVFilterBufferRef *frame)
167184 {
168185 return ff_filter_frame(link->dst->outputs[0], frame);
libavfilter/avcodec.c+4−3
@@ -93,6 +93,7 @@ AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_frame(const AVFrame *frame · 92 unmodified lines
9393 int perms)
9494 {
9595 AVFilterBufferRef *samplesref;
96+ int channels = av_frame_get_channels(frame);
9697 int64_t layout = av_frame_get_channel_layout(frame);
9798
9899 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
103104 return NULL;
104105 }
105106
106− samplesref = avfilter_get_audio_buffer_ref_from_arrays((uint8_t **)frame->data, frame->linesize[0], perms,
107− frame->nb_samples, frame->format,
108− av_frame_get_channel_layout(frame));
107+ samplesref = avfilter_get_audio_buffer_ref_from_arrays_channels(
108+ (uint8_t **)frame->data, frame->linesize[0], perms,
109+ frame->nb_samples, frame->format, channels, layout);
109110 if (!samplesref)
110111 return NULL;
111112 if (avfilter_copy_frame_props(samplesref, frame) < 0) {
libavfilter/avfilter.h+24−0
@@ -765,6 +765,9 @@ avfilter_get_video_buffer_ref_from_arrays(uint8_t * const data[4], const int lin · 764 unmodified lines
765765 * Create an audio buffer reference wrapped around an already
766766 * allocated samples buffer.
767767 *
768+ * See avfilter_get_audio_buffer_ref_from_arrays_channels() for a version
769+ * that can handle unknown channel layouts.
770+ *
768771 * @param data pointers to the samples plane buffers
769772 * @param linesize linesize for the samples plane buffers
770773 * @param perms the required access permissions
@@ -778,6 +781,27 @@ AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data, · 7 unmodified lines
778781 int nb_samples,
779782 enum AVSampleFormat sample_fmt,
780783 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+
781805
782806
783807 #define AVFILTER_CMD_FLAG_ONE 1 ///< Stop once a filter understood the command (for target=all for example), fast filters are favored automatically
libavfilter/src_buffer.c+2−0
@@ -81,6 +81,8 @@ int av_asrc_buffer_add_samples(AVFilterContext *ctx, · 80 unmodified lines
8181 {
8282 AVFilterBufferRef *samplesref;
8383
84+ if (!channel_layout)
85+ return AVERROR(EINVAL);
8486 samplesref = avfilter_get_audio_buffer_ref_from_arrays(
8587 data, linesize[0], AV_PERM_WRITE,
8688 nb_samples,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t