diff mbox series

[FFmpeg-devel,7/7] lavfi/buffersink: deprecate functions obsoleted by AV_BUFFERSINK_FLAG_PARAMS

Message ID 20240923150146.31693-7-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,1/7] lavfi/buffersink: set AVFrame.time_base | expand

Checks

Context Check Description
yinshiyou/configure_loongarch64 warning Failed to apply patch
andriy/configure_x86 warning Failed to apply patch

Commit Message

Anton Khirnov Sept. 23, 2024, 3:01 p.m. UTC
That is all av_buffersink_get_*() except type and frame_rate, for which
AVFrame does not currently have fields.
---
 doc/APIchanges              | 12 +++++++++++-
 libavfilter/buffersink.c    |  4 ++++
 libavfilter/buffersink.h    | 19 ++++++++++++++++++-
 libavfilter/version_major.h |  1 +
 4 files changed, 34 insertions(+), 2 deletions(-)

Comments

Nicolas George Sept. 23, 2024, 3:56 p.m. UTC | #1
Anton Khirnov (12024-09-23):
> That is all av_buffersink_get_*() except type and frame_rate, for which
> AVFrame does not currently have fields.

NAK: an API that requires an allocated AVFrame to retrieve the
parameters is significantly worst than the existing.
Anton Khirnov Sept. 23, 2024, 4:24 p.m. UTC | #2
Quoting Nicolas George (2024-09-23 17:56:47)
> Anton Khirnov (12024-09-23):
> > That is all av_buffersink_get_*() except type and frame_rate, for which
> > AVFrame does not currently have fields.
> 
> NAK: an API that requires an allocated AVFrame to retrieve the
> parameters is significantly worst than the existing.

I fail to see how that is a problem, since you need an allocated AVFrame
to use the buffersink API anyway.

Not to mention that even if one allocates a dedicated AVFrame for the
parameters, the cost is trivial compared to actual filtering since it's
typically only done once per filtergraph.

On the other hand, the cost of a bloated symbol table is paid by
everyone whether they use the functions or not.
Nicolas George Sept. 23, 2024, 4:59 p.m. UTC | #3
Anton Khirnov (12024-09-23):
> I fail to see
>		how that is a problem, since you need an allocated AVFrame
> to use the buffersink API anyway.

Not at the same point in code.

> Not to mention that even if one allocates a dedicated AVFrame for the
> parameters, the cost is trivial compared to actual filtering since it's
> typically only done once per filtergraph.

CPU time is not the only issue.

> On the other hand, the cost of a bloated symbol table is paid by
> everyone whether they use the functions or not.

Benchmark?
diff mbox series

Patch

diff --git a/doc/APIchanges b/doc/APIchanges
index 5ddd7189f8..971750bfe7 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -4,7 +4,17 @@  API changes, most recent first:
 
 2024-09-xx - xxxxxxxxxx - lavfi 10.4.100
   Buffersink now sets AVFrame.time_base on the frames it outputs.
-  Add AV_BUFFERSINK_FLAG_PARAMS.
+  Add AV_BUFFERSINK_FLAG_PARAMS; deprecate
+  - av_buffersink_get_time_base()
+  - av_buffersink_get_w()
+  - av_buffersink_get_h()
+  - av_buffersink_get_sample_aspect_ratio()
+  - av_buffersink_get_colorspace()
+  - av_buffersink_get_color_range()
+  - av_buffersink_get_channels()
+  - av_buffersink_get_channel_layout()
+  - av_buffersink_get_sample_rate()
+  - av_buffersink_get_hw_frames_ctx()
 
 2024-09-23 - xxxxxxxxxx - lavc 61.18.100 - avcodec.h
   Add a new flag AV_CODEC_EXPORT_DATA_ENHANCEMENTS for export_side_data.
diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c
index d9cd074f17..e0c32d5f10 100644
--- a/libavfilter/buffersink.c
+++ b/libavfilter/buffersink.c
@@ -234,6 +234,7 @@  type av_buffersink_get_##field(const AVFilterContext *ctx) { \
 }
 
 MAKE_AVFILTERLINK_ACCESSOR(enum AVMediaType , type               )
+#if FF_API_BUFFERSINK_GET
 MAKE_AVFILTERLINK_ACCESSOR(AVRational       , time_base          )
 MAKE_AVFILTERLINK_ACCESSOR(int              , format             )
 
@@ -244,6 +245,7 @@  MAKE_AVFILTERLINK_ACCESSOR(enum AVColorSpace, colorspace)
 MAKE_AVFILTERLINK_ACCESSOR(enum AVColorRange, color_range)
 
 MAKE_AVFILTERLINK_ACCESSOR(int              , sample_rate        )
+#endif
 
 AVRational av_buffersink_get_frame_rate(const AVFilterContext *ctx)
 {
@@ -252,6 +254,7 @@  AVRational av_buffersink_get_frame_rate(const AVFilterContext *ctx)
     return l->frame_rate;
 }
 
+#if FF_API_BUFFERSINK_GET
 AVBufferRef* av_buffersink_get_hw_frames_ctx(const AVFilterContext *ctx)
 {
     FilterLink *l = ff_filter_link(ctx->inputs[0]);
@@ -277,6 +280,7 @@  int av_buffersink_get_ch_layout(const AVFilterContext *ctx, AVChannelLayout *out
     *out = ch_layout;
     return 0;
 }
+#endif
 
 #define CHECK_LIST_SIZE(field) \
         if (buf->field ## _size % sizeof(*buf->field)) { \
diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h
index 9c4468af5b..ef5aae8857 100644
--- a/libavfilter/buffersink.h
+++ b/libavfilter/buffersink.h
@@ -124,22 +124,39 @@  void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size);
  */
 
 enum AVMediaType av_buffersink_get_type                (const AVFilterContext *ctx);
+AVRational       av_buffersink_get_frame_rate          (const AVFilterContext *ctx);
+
+#if FF_API_BUFFERSINK_GET
+/**
+ * @deprecated Use av_buffersink_get_frame_flags() with AV_BUFFERSINK_FLAG_PARAMS
+ */
+attribute_deprecated
 AVRational       av_buffersink_get_time_base           (const AVFilterContext *ctx);
+attribute_deprecated
 int              av_buffersink_get_format              (const AVFilterContext *ctx);
 
-AVRational       av_buffersink_get_frame_rate          (const AVFilterContext *ctx);
+attribute_deprecated
 int              av_buffersink_get_w                   (const AVFilterContext *ctx);
+attribute_deprecated
 int              av_buffersink_get_h                   (const AVFilterContext *ctx);
+attribute_deprecated
 AVRational       av_buffersink_get_sample_aspect_ratio (const AVFilterContext *ctx);
+attribute_deprecated
 enum AVColorSpace av_buffersink_get_colorspace         (const AVFilterContext *ctx);
+attribute_deprecated
 enum AVColorRange av_buffersink_get_color_range        (const AVFilterContext *ctx);
 
+attribute_deprecated
 int              av_buffersink_get_channels            (const AVFilterContext *ctx);
+attribute_deprecated
 int              av_buffersink_get_ch_layout           (const AVFilterContext *ctx,
                                                         AVChannelLayout *ch_layout);
+attribute_deprecated
 int              av_buffersink_get_sample_rate         (const AVFilterContext *ctx);
 
+attribute_deprecated
 AVBufferRef *    av_buffersink_get_hw_frames_ctx       (const AVFilterContext *ctx);
+#endif
 
 /** @} */
 
diff --git a/libavfilter/version_major.h b/libavfilter/version_major.h
index c5e660eeda..0ca3b0e358 100644
--- a/libavfilter/version_major.h
+++ b/libavfilter/version_major.h
@@ -36,5 +36,6 @@ 
  */
 
 #define FF_API_LINK_PUBLIC     (LIBAVFILTER_VERSION_MAJOR < 11)
+#define FF_API_BUFFERSINK_GET  (LIBAVFILTER_VERSION_MAJOR < 11)
 
 #endif /* AVFILTER_VERSION_MAJOR_H */