[PATCH] Implement avfilter_get_audio_buffer_ref_from_arrays().

Stefano Sabatini stefano.sabatini-lala
Mon Jan 31 00:07:41 CET 2011


---
 libavfilter/avfilter.c |   49 ++++++++++++++++++++++++++++++++++++++++++++++++
 libavfilter/avfilter.h |   19 ++++++++++++++++++
 2 files changed, 68 insertions(+), 0 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index d52d555..31af890 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -350,6 +350,55 @@ AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, int perms,
     return ret;
 }
 
+AVFilterBufferRef *
+avfilter_get_audio_buffer_ref_from_arrays(uint8_t *data[8], int linesize[8], int perms,
+                                          int nb_samples, enum AVSampleFormat sample_fmt,
+                                          int planar, int64_t channel_layout,
+                                          int nb_channels)
+{
+    AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer));
+    AVFilterBufferRef *samplesref = av_mallocz(sizeof(AVFilterBufferRef));
+
+    if (nb_channels < 0) {
+        if (channel_layout < 0)
+            goto fail;
+        nb_channels = av_get_channel_layout_nb_channels(channel_layout);
+    }
+
+    if (!samples || !samplesref)
+        goto fail;
+
+    samplesref->buf = samples;
+    samplesref->buf->free = ff_avfilter_default_free_buffer;
+    if (!(samplesref->audio = av_mallocz(sizeof(AVFilterBufferRefAudioProps))))
+        goto fail;
+
+    samplesref->audio->nb_samples     = nb_samples;
+    samplesref->audio->channel_layout = channel_layout;
+    samplesref->audio->planar         = planar;
+
+    /* make sure the buffer gets read permission or it's useless for output */
+    samplesref->perms = perms | AV_PERM_READ;
+
+    samples->refcount = 1;
+    samplesref->type = AVMEDIA_TYPE_AUDIO;
+    samplesref->format = sample_fmt;
+
+    memcpy(samples->data,        data,     sizeof(samples->data));
+    memcpy(samples->linesize,    linesize, sizeof(samples->linesize));
+    memcpy(samplesref->data,     data,     sizeof(samplesref->data));
+    memcpy(samplesref->linesize, linesize, sizeof(samplesref->linesize));
+
+    return samplesref;
+
+fail:
+    if (samplesref && samplesref->audio)
+        av_free(samplesref->audio);
+    av_free(samplesref);
+    av_free(samples);
+    return NULL;
+}
+
 int avfilter_request_frame(AVFilterLink *link)
 {
     FF_DPRINTF_START(NULL, request_frame); ff_dlog_link(NULL, link, 1);
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 22f8ff0..52da5d3 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -685,6 +685,25 @@ AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, int perms,
                                              int64_t channel_layout, int planar);
 
 /**
+ * Create an audio buffer reference wrapped around an already
+ * allocated samples buffer.
+ *
+ * @param data pointers to the samples plane buffers
+ * @param linesize linesize for the samples plane buffers
+ * @param perms the required access permissions
+ * @param nb_samples number of samples per channel
+ * @param sample_fmt     the format of each sample in the buffer to allocate
+ * @param planar         audio data layout - planar or packed
+ * @param channel_layout the channel layout of the buffer, <=0 if unknown
+ * @param nb_channels the number of channels, <= 0 if unknown
+ */
+AVFilterBufferRef *
+avfilter_get_audio_buffer_ref_from_arrays(uint8_t *data[8], int linesize[8], int perms,
+                                          int nb_samples, enum AVSampleFormat sample_fmt,
+                                          int planar, int64_t channel_layout,
+                                          int nb_channels);
+
+/**
  * Request an input frame from the filter at the other end of the link.
  *
  * @param link the input link
-- 
1.7.2.3


--Nq2Wo0NMKNjxTN9z
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="0006-Use-avfilter_get_audio_buffer_ref_from_arrays-in.patch"




More information about the ffmpeg-devel mailing list