]> git.sesse.net Git - ffmpeg/commitdiff
Merge commit '966689442ed843019dc0722a49bfb0ac51755d19'
authorMichael Niedermayer <michaelni@gmx.at>
Sun, 28 Jul 2013 09:26:57 +0000 (11:26 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Sun, 28 Jul 2013 09:26:57 +0000 (11:26 +0200)
* commit '966689442ed843019dc0722a49bfb0ac51755d19':
  buffersink: K&R formatting cosmetics

Conflicts:
libavfilter/buffersink.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavfilter/buffersink.c

index 8eb31aebad200e8d57174c2cf5c9143a21953511,9ec5995236b7fcc45e6a39476a93ae43d41c20f2..9c81d4d29e1482f33c02e65654c0325f6f1f89bc
  #include "internal.h"
  
  typedef struct {
 -    AVFrame *cur_frame;          ///< last frame delivered on the sink
 +    const AVClass *class;
 +    AVFifoBuffer *fifo;                      ///< FIFO buffer of video frame references
 +    unsigned warning_limit;
 +
 +    /* only used for video */
 +    enum AVPixelFormat *pixel_fmts;           ///< list of accepted pixel formats, must be terminated with -1
 +    int pixel_fmts_size;
 +
 +    /* only used for audio */
 +    enum AVSampleFormat *sample_fmts;       ///< list of accepted sample formats, terminated by AV_SAMPLE_FMT_NONE
 +    int sample_fmts_size;
 +    int64_t *channel_layouts;               ///< list of accepted channel layouts, terminated by -1
 +    int channel_layouts_size;
 +    int *channel_counts;                    ///< list of accepted channel counts, terminated by -1
 +    int channel_counts_size;
 +    int all_channel_counts;
 +    int *sample_rates;                      ///< list of accepted sample rates, terminated by -1
 +    int sample_rates_size;
 +
 +    /* only used for compat API */
-     AVAudioFifo  *audio_fifo;    ///< FIFO for audio samples
+     AVAudioFifo *audio_fifo;     ///< FIFO for audio samples
      int64_t next_pts;            ///< interpolating audio pts
  } BufferSinkContext;
  
@@@ -218,52 -134,8 +217,51 @@@ int attribute_align_arg av_buffersink_g
      }
  
      return ret;
  }
  
 +AVBufferSinkParams *av_buffersink_params_alloc(void)
 +{
 +    static const int pixel_fmts[] = { AV_PIX_FMT_NONE };
 +    AVBufferSinkParams *params = av_malloc(sizeof(AVBufferSinkParams));
 +    if (!params)
 +        return NULL;
 +
 +    params->pixel_fmts = pixel_fmts;
 +    return params;
 +}
 +
 +AVABufferSinkParams *av_abuffersink_params_alloc(void)
 +{
 +    AVABufferSinkParams *params = av_mallocz(sizeof(AVABufferSinkParams));
 +
 +    if (!params)
 +        return NULL;
 +    return params;
 +}
 +
 +#define FIFO_INIT_SIZE 8
 +
 +static av_cold int common_init(AVFilterContext *ctx)
 +{
 +    BufferSinkContext *buf = ctx->priv;
 +
 +    buf->fifo = av_fifo_alloc(FIFO_INIT_SIZE*sizeof(AVFilterBufferRef *));
 +    if (!buf->fifo) {
 +        av_log(ctx, AV_LOG_ERROR, "Failed to allocate fifo\n");
 +        return AVERROR(ENOMEM);
 +    }
 +    buf->warning_limit = 100;
 +    return 0;
 +}
 +
 +void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size)
 +{
 +    AVFilterLink *inlink = ctx->inputs[0];
 +
 +    inlink->min_samples = inlink->max_samples =
 +    inlink->partial_buf_size = frame_size;
 +}
 +
  #if FF_API_AVFILTERBUFFER
  static void compat_free_buffer(AVFilterBuffer *buf)
  {
@@@ -351,256 -208,42 +349,256 @@@ int attribute_align_arg av_buffersink_g
  }
  #endif
  
 +AVRational av_buffersink_get_frame_rate(AVFilterContext *ctx)
 +{
 +    av_assert0(   !strcmp(ctx->filter->name, "buffersink")
 +               || !strcmp(ctx->filter->name, "ffbuffersink"));
 +
 +    return ctx->inputs[0]->frame_rate;
 +}
 +
 +int attribute_align_arg av_buffersink_poll_frame(AVFilterContext *ctx)
 +{
 +    BufferSinkContext *buf = ctx->priv;
 +    AVFilterLink *inlink = ctx->inputs[0];
 +
 +    av_assert0(   !strcmp(ctx->filter->name, "buffersink")
 +               || !strcmp(ctx->filter->name, "abuffersink")
 +               || !strcmp(ctx->filter->name, "ffbuffersink")
 +               || !strcmp(ctx->filter->name, "ffabuffersink"));
 +
 +    return av_fifo_size(buf->fifo)/sizeof(AVFilterBufferRef *) + ff_poll_frame(inlink);
 +}
 +
 +static av_cold int vsink_init(AVFilterContext *ctx, void *opaque)
 +{
 +    BufferSinkContext *buf = ctx->priv;
 +    AVBufferSinkParams *params = opaque;
 +    int ret;
 +
 +    if (params) {
 +        if ((ret = av_opt_set_int_list(buf, "pix_fmts", params->pixel_fmts, AV_PIX_FMT_NONE, 0)) < 0)
 +            return ret;
 +    }
 +
 +    return common_init(ctx);
 +}
 +
 +#define CHECK_LIST_SIZE(field) \
 +        if (buf->field ## _size % sizeof(*buf->field)) { \
 +            av_log(ctx, AV_LOG_ERROR, "Invalid size for " #field ": %d, " \
 +                   "should be multiple of %d\n", \
 +                   buf->field ## _size, (int)sizeof(*buf->field)); \
 +            return AVERROR(EINVAL); \
 +        }
 +static int vsink_query_formats(AVFilterContext *ctx)
 +{
 +    BufferSinkContext *buf = ctx->priv;
 +    AVFilterFormats *formats = NULL;
 +    unsigned i;
 +    int ret;
 +
 +    CHECK_LIST_SIZE(pixel_fmts)
 +    if (buf->pixel_fmts_size) {
 +        for (i = 0; i < NB_ITEMS(buf->pixel_fmts); i++)
 +            if ((ret = ff_add_format(&formats, buf->pixel_fmts[i])) < 0) {
 +                ff_formats_unref(&formats);
 +                return ret;
 +            }
 +        ff_set_common_formats(ctx, formats);
 +    } else {
 +        ff_default_query_formats(ctx);
 +    }
 +
 +    return 0;
 +}
 +
 +static av_cold int asink_init(AVFilterContext *ctx, void *opaque)
 +{
 +    BufferSinkContext *buf = ctx->priv;
 +    AVABufferSinkParams *params = opaque;
 +    int ret;
 +
 +    if (params) {
 +        if ((ret = av_opt_set_int_list(buf, "sample_fmts",     params->sample_fmts,  AV_SAMPLE_FMT_NONE, 0)) < 0 ||
 +            (ret = av_opt_set_int_list(buf, "sample_rates",    params->sample_rates,    -1, 0)) < 0 ||
 +            (ret = av_opt_set_int_list(buf, "channel_layouts", params->channel_layouts, -1, 0)) < 0 ||
 +            (ret = av_opt_set_int_list(buf, "channel_counts",  params->channel_counts,  -1, 0)) < 0 ||
 +            (ret = av_opt_set_int(buf, "all_channel_counts", params->all_channel_counts, 0)) < 0)
 +            return ret;
 +    }
 +    return common_init(ctx);
 +}
 +
 +static int asink_query_formats(AVFilterContext *ctx)
 +{
 +    BufferSinkContext *buf = ctx->priv;
 +    AVFilterFormats *formats = NULL;
 +    AVFilterChannelLayouts *layouts = NULL;
 +    unsigned i;
 +    int ret;
 +
 +    CHECK_LIST_SIZE(sample_fmts)
 +    CHECK_LIST_SIZE(sample_rates)
 +    CHECK_LIST_SIZE(channel_layouts)
 +    CHECK_LIST_SIZE(channel_counts)
 +
 +    if (buf->sample_fmts_size) {
 +        for (i = 0; i < NB_ITEMS(buf->sample_fmts); i++)
 +            if ((ret = ff_add_format(&formats, buf->sample_fmts[i])) < 0) {
 +                ff_formats_unref(&formats);
 +                return ret;
 +            }
 +        ff_set_common_formats(ctx, formats);
 +    }
 +
 +    if (buf->channel_layouts_size || buf->channel_counts_size ||
 +        buf->all_channel_counts) {
 +        for (i = 0; i < NB_ITEMS(buf->channel_layouts); i++)
 +            if ((ret = ff_add_channel_layout(&layouts, buf->channel_layouts[i])) < 0) {
 +                ff_channel_layouts_unref(&layouts);
 +                return ret;
 +            }
 +        for (i = 0; i < NB_ITEMS(buf->channel_counts); i++)
 +            if ((ret = ff_add_channel_layout(&layouts, FF_COUNT2LAYOUT(buf->channel_counts[i]))) < 0) {
 +                ff_channel_layouts_unref(&layouts);
 +                return ret;
 +            }
 +        if (buf->all_channel_counts) {
 +            if (layouts)
 +                av_log(ctx, AV_LOG_WARNING,
 +                       "Conflicting all_channel_counts and list in options\n");
 +            else if (!(layouts = ff_all_channel_counts()))
 +                return AVERROR(ENOMEM);
 +        }
 +        ff_set_common_channel_layouts(ctx, layouts);
 +    }
 +
 +    if (buf->sample_rates_size) {
 +        formats = NULL;
 +        for (i = 0; i < NB_ITEMS(buf->sample_rates); i++)
 +            if ((ret = ff_add_format(&formats, buf->sample_rates[i])) < 0) {
 +                ff_formats_unref(&formats);
 +                return ret;
 +            }
 +        ff_set_common_samplerates(ctx, formats);
 +    }
 +
 +    return 0;
 +}
 +
 +#define OFFSET(x) offsetof(BufferSinkContext, x)
 +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 +static const AVOption buffersink_options[] = {
 +    { "pix_fmts", "set the supported pixel formats", OFFSET(pixel_fmts), AV_OPT_TYPE_BINARY, .flags = FLAGS },
 +    { NULL },
 +};
 +#undef FLAGS
 +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 +static const AVOption abuffersink_options[] = {
 +    { "sample_fmts",     "set the supported sample formats",  OFFSET(sample_fmts),     AV_OPT_TYPE_BINARY, .flags = FLAGS },
 +    { "sample_rates",    "set the supported sample rates",    OFFSET(sample_rates),    AV_OPT_TYPE_BINARY, .flags = FLAGS },
 +    { "channel_layouts", "set the supported channel layouts", OFFSET(channel_layouts), AV_OPT_TYPE_BINARY, .flags = FLAGS },
 +    { "channel_counts",  "set the supported channel counts",  OFFSET(channel_counts),  AV_OPT_TYPE_BINARY, .flags = FLAGS },
 +    { "all_channel_counts", "accept all channel counts", OFFSET(all_channel_counts), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS },
 +    { NULL },
 +};
 +#undef FLAGS
 +
 +AVFILTER_DEFINE_CLASS(buffersink);
 +AVFILTER_DEFINE_CLASS(abuffersink);
 +
 +#if FF_API_AVFILTERBUFFER
 +
 +#define ffbuffersink_options buffersink_options
 +#define ffabuffersink_options abuffersink_options
 +AVFILTER_DEFINE_CLASS(ffbuffersink);
 +AVFILTER_DEFINE_CLASS(ffabuffersink);
 +
 +static const AVFilterPad ffbuffersink_inputs[] = {
 +    {
 +        .name      = "default",
 +        .type      = AVMEDIA_TYPE_VIDEO,
 +        .filter_frame = filter_frame,
 +    },
 +    { NULL },
 +};
 +
 +AVFilter avfilter_vsink_ffbuffersink = {
 +    .name      = "ffbuffersink",
 +    .description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them available to the end of the filter graph."),
 +    .priv_size = sizeof(BufferSinkContext),
 +    .priv_class = &ffbuffersink_class,
 +    .init_opaque = vsink_init,
 +    .uninit    = uninit,
 +
 +    .query_formats = vsink_query_formats,
 +    .inputs        = ffbuffersink_inputs,
 +    .outputs       = NULL,
 +};
 +
 +static const AVFilterPad ffabuffersink_inputs[] = {
 +    {
 +        .name           = "default",
 +        .type           = AVMEDIA_TYPE_AUDIO,
 +        .filter_frame   = filter_frame,
 +    },
 +    { NULL },
 +};
 +
 +AVFilter avfilter_asink_ffabuffersink = {
 +    .name      = "ffabuffersink",
 +    .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."),
 +    .init_opaque = asink_init,
 +    .uninit    = uninit,
 +    .priv_size = sizeof(BufferSinkContext),
 +    .priv_class = &ffabuffersink_class,
 +    .query_formats = asink_query_formats,
 +    .inputs        = ffabuffersink_inputs,
 +    .outputs       = NULL,
 +};
 +#endif /* FF_API_AVFILTERBUFFER */
 +
  static const AVFilterPad avfilter_vsink_buffer_inputs[] = {
      {
-         .name        = "default",
-         .type        = AVMEDIA_TYPE_VIDEO,
+         .name         = "default",
+         .type         = AVMEDIA_TYPE_VIDEO,
          .filter_frame = filter_frame,
 -        .needs_fifo   = 1
      },
      { NULL }
  };
  
  AVFilter avfilter_vsink_buffer = {
-     .name      = "buffersink",
+     .name        = "buffersink",
      .description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them available to the end of the filter graph."),
-     .priv_size = sizeof(BufferSinkContext),
-     .priv_class = &buffersink_class,
+     .priv_size   = sizeof(BufferSinkContext),
++    .priv_class  = &buffersink_class,
 +    .init_opaque = vsink_init,
-     .uninit    = uninit,
+     .uninit      = uninit,
  
-     .inputs    = avfilter_vsink_buffer_inputs,
-     .outputs   = NULL,
 +    .query_formats = vsink_query_formats,
+     .inputs      = avfilter_vsink_buffer_inputs,
+     .outputs     = NULL,
  };
  
  static const AVFilterPad avfilter_asink_abuffer_inputs[] = {
      {
-         .name           = "default",
-         .type           = AVMEDIA_TYPE_AUDIO,
-         .filter_frame   = filter_frame,
+         .name         = "default",
+         .type         = AVMEDIA_TYPE_AUDIO,
+         .filter_frame = filter_frame,
 -        .needs_fifo   = 1
      },
      { NULL }
  };
  
  AVFilter avfilter_asink_abuffer = {
-     .name      = "abuffersink",
+     .name        = "abuffersink",
      .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."),
-     .priv_class = &abuffersink_class,
-     .priv_size = sizeof(BufferSinkContext),
++    .priv_class  = &abuffersink_class,
+     .priv_size   = sizeof(BufferSinkContext),
 +    .init_opaque = asink_init,
-     .uninit    = uninit,
+     .uninit      = uninit,
  
-     .inputs    = avfilter_asink_abuffer_inputs,
-     .outputs   = NULL,
 +    .query_formats = asink_query_formats,
+     .inputs      = avfilter_asink_abuffer_inputs,
+     .outputs     = NULL,
  };