On 11/27/2012 01:40 PM, Anton Khirnov wrote:
> Any alleged performance benefits gained from the split are purely
> mythological and do not justify added code complexity.
> ---
>  libavfilter/audio.c    |   47 -----------
>  libavfilter/audio.h    |   13 ---
>  libavfilter/avfilter.c |   62 ++++++++++++++
>  libavfilter/avfilter.h |   32 ++------
>  libavfilter/internal.h |   54 ++++---------
>  libavfilter/video.c    |  210 
> ------------------------------------------------
>  libavfilter/video.h    |   47 -----------
>  7 files changed, 86 insertions(+), 379 deletions(-)
> 
> diff --git a/libavfilter/audio.c b/libavfilter/audio.c
> index 48e038b..bbe12b2 100644
> --- a/libavfilter/audio.c
> +++ b/libavfilter/audio.c
> @@ -146,50 +146,3 @@ fail:
>      av_freep(&samples);
>      return NULL;
>  }
> -
> -static int default_filter_samples(AVFilterLink *link,
> -                                  AVFilterBufferRef *samplesref)
> -{
> -    return ff_filter_samples(link->dst->outputs[0], samplesref);
> -}
> -
> -int ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
> -{
> -    int (*filter_samples)(AVFilterLink *, AVFilterBufferRef *);
> -    AVFilterPad *dst = link->dstpad;
> -    AVFilterBufferRef *buf_out;
> -
> -    FF_DPRINTF_START(NULL, filter_samples); ff_dlog_link(NULL, link, 1);
> -
> -    if (!(filter_samples = dst->filter_samples))
> -        filter_samples = default_filter_samples;
> -
> -    /* prepare to copy the samples if the buffer has insufficient 
> permissions */
> -    if ((dst->min_perms & samplesref->perms) != dst->min_perms ||
> -        dst->rej_perms & samplesref->perms) {
> -        av_log(link->dst, AV_LOG_DEBUG,
> -               "Copying audio data in avfilter (have perms %x, need %x, 
> reject %x)\n",
> -               samplesref->perms, link->dstpad->min_perms, 
> link->dstpad->rej_perms);
> -
> -        buf_out = ff_default_get_audio_buffer(link, dst->min_perms,
> -                                              samplesref->audio->nb_samples);
> -        if (!buf_out) {
> -            avfilter_unref_buffer(samplesref);
> -            return AVERROR(ENOMEM);
> -        }
> -        buf_out->pts                = samplesref->pts;
> -        buf_out->audio->sample_rate = samplesref->audio->sample_rate;
> -
> -        /* Copy actual data into new samples buffer */
> -        av_samples_copy(buf_out->extended_data, samplesref->extended_data,
> -                        0, 0, samplesref->audio->nb_samples,
> -                        
> av_get_channel_layout_nb_channels(link->channel_layout),
> -                        link->format);
> -
> -        avfilter_unref_buffer(samplesref);
> -    } else
> -        buf_out = samplesref;
> -
> -    return filter_samples(link, buf_out);
> -}
> -
> diff --git a/libavfilter/audio.h b/libavfilter/audio.h
> index fa448e2..a377503 100644
> --- a/libavfilter/audio.h
> +++ b/libavfilter/audio.h
> @@ -42,17 +42,4 @@ AVFilterBufferRef *ff_null_get_audio_buffer(AVFilterLink 
> *link, int perms,
>  AVFilterBufferRef *ff_get_audio_buffer(AVFilterLink *link, int perms,
>                                               int nb_samples);
>  
> -/**
> - * Send a buffer of audio samples to the next filter.
> - *
> - * @param link       the output link over which the audio samples are being 
> sent
> - * @param samplesref a reference to the buffer of audio samples being sent. 
> The
> - *                   receiving filter will free this reference when it no 
> longer
> - *                   needs it or pass it on to the next filter.
> - *
> - * @return >= 0 on success, a negative AVERROR on error. The receiving filter
> - * is responsible for unreferencing samplesref in case of error.
> - */
> -int ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref);
> -
>  #endif /* AVFILTER_AUDIO_H */
> diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> index c7db857..86288f8 100644
> --- a/libavfilter/avfilter.c
> +++ b/libavfilter/avfilter.c
> @@ -23,12 +23,16 @@
>  
>  #include "libavutil/channel_layout.h"
>  #include "libavutil/common.h"
> +#include "libavutil/imgutils.h"
>  #include "libavutil/pixdesc.h"
>  #include "libavutil/rational.h"
> +#include "libavutil/samplefmt.h"
>  
> +#include "audio.h"
>  #include "avfilter.h"
>  #include "formats.h"
>  #include "internal.h"
> +#include "video.h"
>  
>  unsigned avfilter_version(void) {
>      return LIBAVFILTER_VERSION_INT;
> @@ -446,3 +450,61 @@ enum AVMediaType avfilter_pad_get_type(AVFilterPad 
> *pads, int pad_idx)
>  {
>      return pads[pad_idx].type;
>  }
> +
> +static int default_filter_frame(AVFilterLink *link, AVFilterBufferRef *frame)
> +{
> +    return ff_filter_frame(link->dst->outputs[0], frame);
> +}
> +
> +int ff_filter_frame(AVFilterLink *link, AVFilterBufferRef *frame)
> +{
> +    int (*filter_frame)(AVFilterLink *, AVFilterBufferRef *);
> +    AVFilterPad *dst = link->dstpad;
> +    AVFilterBufferRef *out;
> +    int perms = frame->perms;
> +
> +    FF_DPRINTF_START(NULL, filter_frame);
> +    ff_dlog_link(NULL, link, 1);
> +
> +    if (!(filter_frame = dst->filter_frame))
> +        filter_frame = default_filter_frame;
> +
> +    if (frame->linesize[0] < 0)
> +        perms |= AV_PERM_NEG_LINESIZES;
> +    /* prepare to copy the frame if the buffer has insufficient permissions 
> */
> +    if ((dst->min_perms & perms) != dst->min_perms ||
> +        dst->rej_perms & perms) {
> +        av_log(link->dst, AV_LOG_DEBUG,
> +               "Copying data in avfilter (have perms %x, need %x, reject 
> %x)\n",
> +               perms, link->dstpad->min_perms, link->dstpad->rej_perms);
> +
> +        if (link->type == AVMEDIA_TYPE_VIDEO) {
> +            out = ff_get_video_buffer(link, dst->min_perms,
> +                                      link->w, link->h);
> +        } else {
> +            out = ff_get_audio_buffer(link, dst->min_perms,
> +                                      frame->audio->nb_samples);
> +        }
> +        if (!out) {
> +            avfilter_unref_buffer(frame);
> +            return AVERROR(ENOMEM);
> +        }
> +        avfilter_copy_buffer_ref_props(out, frame);
> +

make it a switch please

> +        if (link->type == AVMEDIA_TYPE_VIDEO) {
> +            av_image_copy(out->data, out->linesize, frame->data, 
> frame->linesize,
> +                          frame->format, frame->video->w, frame->video->h);
> +        } else {
> +            av_samples_copy(out->extended_data, frame->extended_data,
> +                            0, 0, frame->audio->nb_samples,
> +                            
> av_get_channel_layout_nb_channels(frame->audio->channel_layout),
> +                            frame->format);
> +        }
> +
> +
> +        avfilter_unref_buffer(frame);
> +    } else
> +        out = frame;
> +
> +    return filter_frame(link, out);
> +}


The rest looks fine.

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to