[FFmpeg-devel] [PATCH 01/10] lavfi: add avfilter_get_audio_buffer_ref_from_arrays_nolayout.

Stefano Sabatini stefasab at gmail.com
Sun Dec 30 19:49:32 CET 2012


On date Sunday 2012-12-30 18:13:41 +0100, Nicolas George encoded:
> It is the same as avfilter_get_audio_buffer_ref_from_arrays
> except it has a "channels" and the channel layout can be 0.
> 
> Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
> ---
>  libavfilter/audio.c      |   34 +++++++++++++++++++++++++---------
>  libavfilter/avcodec.c    |    7 ++++---
>  libavfilter/avfilter.h   |   21 +++++++++++++++++++++
>  libavfilter/internal.h   |    1 +
>  libavfilter/src_buffer.c |    2 ++
>  5 files changed, 53 insertions(+), 12 deletions(-)
> 
> 
> I am not really happy about the name of the function, but it was the best I
> could come with. One concern is to avoid names that may be used by the fork
> with a different prototype; otherwise I would have used simply ...arrays2.

_arrays2() should be fine as well (and shorter), and "nolayout" is
confusing (since layout *can* be specified).

> 
> Patches 3-10/10 are unchanged since the last time I sent them, there is no
> need to flood everybody's mailboxes with them.
> http://ffmpeg.org/pipermail/ffmpeg-devel/2012-December/136364.html
> 
> 
> diff --git a/libavfilter/audio.c b/libavfilter/audio.c
> index 3564896..c5ee09f 100644
> --- a/libavfilter/audio.c
> +++ b/libavfilter/audio.c
> @@ -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)
>          goto fail;
>  
> -    samplesref = avfilter_get_audio_buffer_ref_from_arrays(data, linesize, full_perms,
> -                                                           nb_samples, link->format,
> -                                                           link->channel_layout);
> +    samplesref = avfilter_get_audio_buffer_ref_from_arrays_nolayout(
> +        data, linesize, full_perms, nb_samples, link->format,
> +        link->channels, link->channel_layout);
>      if (!samplesref)
>          goto fail;
>  
> @@ -92,13 +92,13 @@ AVFilterBufferRef *ff_get_audio_buffer(AVFilterLink *link, int perms,
>      return ret;
>  }
>  
> -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)
> +AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays_nolayout(uint8_t **data,
> +                                                                      int linesize,int perms,
> +                                                                      int nb_samples,
> +                                                                      enum AVSampleFormat sample_fmt,
> +                                                                      int channels,
> +                                                                      uint64_t channel_layout)
>  {
> -    int channels = av_get_channel_layout_nb_channels(channel_layout);
>      int planes;
>      AVFilterBuffer    *samples    = av_mallocz(sizeof(*samples));
>      AVFilterBufferRef *samplesref = av_mallocz(sizeof(*samplesref));
> @@ -106,6 +106,10 @@ AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
>      if (!samples || !samplesref)
>          goto fail;
>  
> +    av_assert0(channels);
> +    av_assert0(channel_layout == 0 || 
> +               channels == av_get_channel_layout_nb_channels(channel_layout));
> +
>      samplesref->buf         = samples;
>      samplesref->buf->free   = ff_avfilter_default_free_buffer;
>      if (!(samplesref->audio = av_mallocz(sizeof(*samplesref->audio))))
> @@ -163,6 +167,18 @@ fail:
>      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_nolayout(data, linesize, perms,
> +                                                              nb_samples, sample_fmt,
> +                                                              channels, channel_layout);
> +}
> +
>  static int default_filter_frame(AVFilterLink *link, AVFilterBufferRef *frame)
>  {
>      return ff_filter_frame(link->dst->outputs[0], frame);
> diff --git a/libavfilter/avcodec.c b/libavfilter/avcodec.c
> index 2533bd8..10a2eff 100644
> --- a/libavfilter/avcodec.c
> +++ b/libavfilter/avcodec.c
> @@ -93,6 +93,7 @@ AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_frame(const AVFrame *frame
>                                                              int perms)
>  {
>      AVFilterBufferRef *samplesref;
> +    int channels = av_frame_get_channels(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
> @@ -103,9 +104,9 @@ AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_frame(const AVFrame *frame
>          return NULL;
>      }
>  
> -    samplesref = avfilter_get_audio_buffer_ref_from_arrays((uint8_t **)frame->data, frame->linesize[0], perms,
> -                                                  frame->nb_samples, frame->format,
> -                                                  av_frame_get_channel_layout(frame));
> +    samplesref = avfilter_get_audio_buffer_ref_from_arrays_nolayout(
> +        (uint8_t **)frame->data, frame->linesize[0], perms,
> +        frame->nb_samples, frame->format, channels, layout);
>      if (!samplesref)
>          return NULL;
>      if (avfilter_copy_frame_props(samplesref, frame) < 0) {
> diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
> index 3849c7b..41eda1e 100644
> --- a/libavfilter/avfilter.h
> +++ b/libavfilter/avfilter.h
> @@ -778,6 +778,27 @@ AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
>                                                               int nb_samples,
>                                                               enum AVSampleFormat sample_fmt,
>                                                               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_nolayout(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

> diff --git a/libavfilter/internal.h b/libavfilter/internal.h
> index d098156..8361d2e 100644
> --- a/libavfilter/internal.h
> +++ b/libavfilter/internal.h
> @@ -357,6 +357,7 @@ int ff_request_frame(AVFilterLink *link);
>  AVFilterBufferRef *ff_copy_buffer_ref(AVFilterLink *outlink,
>                                        AVFilterBufferRef *ref);
>  
> +
>  /**
>   * Find the index of a link.
>   *

spurious

> diff --git a/libavfilter/src_buffer.c b/libavfilter/src_buffer.c
> index acd490b..a997034 100644
> --- a/libavfilter/src_buffer.c
> +++ b/libavfilter/src_buffer.c
> @@ -81,6 +81,8 @@ int av_asrc_buffer_add_samples(AVFilterContext *ctx,
>  {
>      AVFilterBufferRef *samplesref;
>  
> +    if (!channel_layout)
> +        return AVERROR(EINVAL);

av_log ERROR?

>      samplesref = avfilter_get_audio_buffer_ref_from_arrays(
>                       data, linesize[0], AV_PERM_WRITE,
>                       nb_samples,
> -- 

LGTM otherwise, thanks.
-- 
FFmpeg = Faithless and Fiendish Mastering Ponderous Emblematic Genius


More information about the ffmpeg-devel mailing list