mirror of
https://github.com/nyanmisaka/ffmpeg-rockchip.git
synced 2025-10-10 19:20:38 +08:00
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.
This commit is contained in:
@@ -58,9 +58,9 @@ AVFilterBufferRef *ff_default_get_audio_buffer(AVFilterLink *link, int perms,
|
|||||||
if (av_samples_alloc(data, &linesize, nb_channels, nb_samples, link->format, 0) < 0)
|
if (av_samples_alloc(data, &linesize, nb_channels, nb_samples, link->format, 0) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
samplesref = avfilter_get_audio_buffer_ref_from_arrays(data, linesize, full_perms,
|
samplesref = avfilter_get_audio_buffer_ref_from_arrays_channels(
|
||||||
nb_samples, link->format,
|
data, linesize, full_perms, nb_samples, link->format,
|
||||||
link->channel_layout);
|
link->channels, link->channel_layout);
|
||||||
if (!samplesref)
|
if (!samplesref)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
@@ -92,13 +92,14 @@ AVFilterBufferRef *ff_get_audio_buffer(AVFilterLink *link, int perms,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
|
AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays_channels(uint8_t **data,
|
||||||
int linesize,int perms,
|
int linesize,
|
||||||
|
int perms,
|
||||||
int nb_samples,
|
int nb_samples,
|
||||||
enum AVSampleFormat sample_fmt,
|
enum AVSampleFormat sample_fmt,
|
||||||
|
int channels,
|
||||||
uint64_t channel_layout)
|
uint64_t channel_layout)
|
||||||
{
|
{
|
||||||
int channels = av_get_channel_layout_nb_channels(channel_layout);
|
|
||||||
int planes;
|
int planes;
|
||||||
AVFilterBuffer *samples = av_mallocz(sizeof(*samples));
|
AVFilterBuffer *samples = av_mallocz(sizeof(*samples));
|
||||||
AVFilterBufferRef *samplesref = av_mallocz(sizeof(*samplesref));
|
AVFilterBufferRef *samplesref = av_mallocz(sizeof(*samplesref));
|
||||||
@@ -106,6 +107,10 @@ AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
|
|||||||
if (!samples || !samplesref)
|
if (!samples || !samplesref)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
av_assert0(channels);
|
||||||
|
av_assert0(channel_layout == 0 ||
|
||||||
|
channels == av_get_channel_layout_nb_channels(channel_layout));
|
||||||
|
|
||||||
samplesref->buf = samples;
|
samplesref->buf = samples;
|
||||||
samplesref->buf->free = ff_avfilter_default_free_buffer;
|
samplesref->buf->free = ff_avfilter_default_free_buffer;
|
||||||
if (!(samplesref->audio = av_mallocz(sizeof(*samplesref->audio))))
|
if (!(samplesref->audio = av_mallocz(sizeof(*samplesref->audio))))
|
||||||
@@ -163,6 +168,18 @@ fail:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
|
||||||
|
int linesize,int perms,
|
||||||
|
int nb_samples,
|
||||||
|
enum AVSampleFormat sample_fmt,
|
||||||
|
uint64_t channel_layout)
|
||||||
|
{
|
||||||
|
int channels = av_get_channel_layout_nb_channels(channel_layout);
|
||||||
|
return avfilter_get_audio_buffer_ref_from_arrays_channels(data, linesize, perms,
|
||||||
|
nb_samples, sample_fmt,
|
||||||
|
channels, channel_layout);
|
||||||
|
}
|
||||||
|
|
||||||
static int default_filter_frame(AVFilterLink *link, AVFilterBufferRef *frame)
|
static int default_filter_frame(AVFilterLink *link, AVFilterBufferRef *frame)
|
||||||
{
|
{
|
||||||
return ff_filter_frame(link->dst->outputs[0], frame);
|
return ff_filter_frame(link->dst->outputs[0], frame);
|
||||||
|
@@ -93,6 +93,7 @@ AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_frame(const AVFrame *frame
|
|||||||
int perms)
|
int perms)
|
||||||
{
|
{
|
||||||
AVFilterBufferRef *samplesref;
|
AVFilterBufferRef *samplesref;
|
||||||
|
int channels = av_frame_get_channels(frame);
|
||||||
int64_t layout = av_frame_get_channel_layout(frame);
|
int64_t layout = av_frame_get_channel_layout(frame);
|
||||||
|
|
||||||
if(av_frame_get_channels(frame) > 8) // libavfilter does not suport more than 8 channels FIXME, remove once libavfilter is fixed
|
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
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
samplesref = avfilter_get_audio_buffer_ref_from_arrays((uint8_t **)frame->data, frame->linesize[0], perms,
|
samplesref = avfilter_get_audio_buffer_ref_from_arrays_channels(
|
||||||
frame->nb_samples, frame->format,
|
(uint8_t **)frame->data, frame->linesize[0], perms,
|
||||||
av_frame_get_channel_layout(frame));
|
frame->nb_samples, frame->format, channels, layout);
|
||||||
if (!samplesref)
|
if (!samplesref)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (avfilter_copy_frame_props(samplesref, frame) < 0) {
|
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
|
|||||||
* Create an audio buffer reference wrapped around an already
|
* Create an audio buffer reference wrapped around an already
|
||||||
* allocated samples buffer.
|
* allocated samples buffer.
|
||||||
*
|
*
|
||||||
|
* See avfilter_get_audio_buffer_ref_from_arrays_channels() for a version
|
||||||
|
* that can handle unknown channel layouts.
|
||||||
|
*
|
||||||
* @param data pointers to the samples plane buffers
|
* @param data pointers to the samples plane buffers
|
||||||
* @param linesize linesize for the samples plane buffers
|
* @param linesize linesize for the samples plane buffers
|
||||||
* @param perms the required access permissions
|
* @param perms the required access permissions
|
||||||
@@ -778,6 +781,27 @@ AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
|
|||||||
int nb_samples,
|
int nb_samples,
|
||||||
enum AVSampleFormat sample_fmt,
|
enum AVSampleFormat sample_fmt,
|
||||||
uint64_t channel_layout);
|
uint64_t channel_layout);
|
||||||
|
/**
|
||||||
|
* 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 channels the number of channels of the buffer
|
||||||
|
* @param channel_layout the channel layout of the buffer,
|
||||||
|
* must be either 0 or consistent with channels
|
||||||
|
*/
|
||||||
|
AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays_channels(uint8_t **data,
|
||||||
|
int linesize,
|
||||||
|
int perms,
|
||||||
|
int nb_samples,
|
||||||
|
enum AVSampleFormat sample_fmt,
|
||||||
|
int channels,
|
||||||
|
uint64_t channel_layout);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define AVFILTER_CMD_FLAG_ONE 1 ///< Stop once a filter understood the command (for target=all for example), fast filters are favored automatically
|
#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,
|
|||||||
{
|
{
|
||||||
AVFilterBufferRef *samplesref;
|
AVFilterBufferRef *samplesref;
|
||||||
|
|
||||||
|
if (!channel_layout)
|
||||||
|
return AVERROR(EINVAL);
|
||||||
samplesref = avfilter_get_audio_buffer_ref_from_arrays(
|
samplesref = avfilter_get_audio_buffer_ref_from_arrays(
|
||||||
data, linesize[0], AV_PERM_WRITE,
|
data, linesize[0], AV_PERM_WRITE,
|
||||||
nb_samples,
|
nb_samples,
|
||||||
|
Reference in New Issue
Block a user