Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'libavfilter/audio.c')
-rw-r--r--libavfilter/audio.c96
1 files changed, 89 insertions, 7 deletions
diff --git a/libavfilter/audio.c b/libavfilter/audio.c
index 3e12c697ce..31f6796437 100644
--- a/libavfilter/audio.c
+++ b/libavfilter/audio.c
@@ -1,21 +1,25 @@
/*
- * This file is part of Libav.
+ * Copyright (c) Stefano Sabatini | stefasab at gmail.com
+ * Copyright (c) S.N. Hemanth Meenakshisundaram | smeenaks at ucsd.edu
*
- * Libav is free software; you can redistribute it and/or
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavutil/avassert.h"
#include "libavutil/audioconvert.h"
#include "audio.h"
@@ -29,6 +33,38 @@ AVFilterBufferRef *ff_null_get_audio_buffer(AVFilterLink *link, int perms,
}
AVFilterBufferRef *ff_default_get_audio_buffer(AVFilterLink *link, int perms,
+ int nb_samples)
+{
+ AVFilterBufferRef *samplesref = NULL;
+ int linesize[8] = {0};
+ uint8_t *data[8] = {0};
+ int ch, nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);
+
+ /* right now we don't support more than 8 channels */
+ av_assert0(nb_channels <= 8);
+
+ /* Calculate total buffer size, round to multiple of 16 to be SIMD friendly */
+ if (av_samples_alloc(data, linesize,
+ nb_channels, nb_samples,
+ av_get_alt_sample_fmt(link->format, link->planar),
+ 16) < 0)
+ return NULL;
+
+ for (ch = 1; link->planar && ch < nb_channels; ch++)
+ linesize[ch] = linesize[0];
+ samplesref =
+ avfilter_get_audio_buffer_ref_from_arrays(data, linesize, perms,
+ nb_samples, link->format,
+ link->channel_layout, link->planar);
+ if (!samplesref) {
+ av_free(data[0]);
+ return NULL;
+ }
+
+ return samplesref;
+}
+
+static AVFilterBufferRef *ff_default_get_audio_buffer_alt(AVFilterLink *link, int perms,
int nb_samples)
{
AVFilterBufferRef *samplesref = NULL;
@@ -44,7 +80,7 @@ AVFilterBufferRef *ff_default_get_audio_buffer(AVFilterLink *link, int perms,
if (av_samples_alloc(data, &linesize, nb_channels, nb_samples, link->format, 0) < 0)
goto fail;
- samplesref = avfilter_get_audio_buffer_ref_from_arrays(data, linesize, perms,
+ samplesref = avfilter_get_audio_buffer_ref_from_arrays_alt(data, linesize, perms,
nb_samples, link->format,
link->channel_layout);
if (!samplesref)
@@ -76,7 +112,49 @@ AVFilterBufferRef *ff_get_audio_buffer(AVFilterLink *link, int perms,
return ret;
}
-AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
+AVFilterBufferRef *
+avfilter_get_audio_buffer_ref_from_arrays(uint8_t *data[8], int linesize[8], int perms,
+ int nb_samples, enum AVSampleFormat sample_fmt,
+ uint64_t channel_layout, int planar)
+{
+ AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer));
+ AVFilterBufferRef *samplesref = av_mallocz(sizeof(AVFilterBufferRef));
+
+ 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_freep(&samplesref->audio);
+ av_freep(&samplesref);
+ av_freep(&samples);
+ return NULL;
+}
+
+AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays_alt(uint8_t **data,
int linesize,int perms,
int nb_samples,
enum AVSampleFormat sample_fmt,
@@ -174,6 +252,7 @@ void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
{
void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *);
AVFilterPad *dst = link->dstpad;
+ int64_t pts;
FF_DPRINTF_START(NULL, filter_samples); ff_dlog_link(NULL, link, 1);
@@ -197,6 +276,8 @@ void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
link->cur_buf->audio->sample_rate = samplesref->audio->sample_rate;
/* Copy actual data into new samples buffer */
+ for (i = 0; samplesref->data[i] && i < 8; i++)
+ memcpy(link->cur_buf->data[i], samplesref->data[i], samplesref->linesize[0]);
for (i = 0; i < planes; i++)
memcpy(link->cur_buf->extended_data[i], samplesref->extended_data[i], samplesref->linesize[0]);
@@ -204,6 +285,7 @@ void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
} else
link->cur_buf = samplesref;
+ pts = link->cur_buf->pts;
filter_samples(link, link->cur_buf);
+ ff_update_link_current_pts(link, pts);
}
-