From patchwork Tue Dec 27 18:02:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 1945 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp1594267vsb; Tue, 27 Dec 2016 10:02:24 -0800 (PST) X-Received: by 10.28.195.9 with SMTP id t9mr27668101wmf.92.1482861744800; Tue, 27 Dec 2016 10:02:24 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g2si46996175wmc.50.2016.12.27.10.02.24; Tue, 27 Dec 2016 10:02:24 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9A7BC689D2E; Tue, 27 Dec 2016 20:02:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef2.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0AAD3689CF4 for ; Tue, 27 Dec 2016 20:02:11 +0200 (EET) Received: from phare.normalesup.org (archicubes.ens.fr [129.199.129.80]) by nef2.ens.fr (8.13.6/1.01.28121999) with ESMTP id uBRI2DJq003061 for ; Tue, 27 Dec 2016 19:02:14 +0100 (CET) Received: by phare.normalesup.org (Postfix, from userid 1001) id D6467E00F9; Tue, 27 Dec 2016 19:02:13 +0100 (CET) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Tue, 27 Dec 2016 19:02:02 +0100 Message-Id: <20161227180210.23100-1-george@nsup.org> X-Mailer: git-send-email 2.11.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef2.ens.fr [129.199.96.32]); Tue, 27 Dec 2016 19:02:14 +0100 (CET) Subject: [FFmpeg-devel] [PATCH 1/9] lavfi/buffersink: add accessors for the stream properties. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" av_buffersink_get_frame_rate() did already exist; its argument becomes const. TODO minor version bump and APIChange entry Signed-off-by: Nicolas George --- libavfilter/buffersink.c | 25 +++++++++++++++++++------ libavfilter/buffersink.h | 22 ++++++++++++++++++++-- 2 files changed, 39 insertions(+), 8 deletions(-) The proposal of using a single function and a structure to return all fields did not raise a lot of enthousiasm. Furthermore, with the prospect of on-the-fly format change, having functions involved that can compute the returned value instead of just reading it from a field may prove useful. If there are no objections, I can push patches 1-5 independently from 6-9 diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c index 7b7b47747d..030ca80315 100644 --- a/libavfilter/buffersink.c +++ b/libavfilter/buffersink.c @@ -279,14 +279,27 @@ void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size) inlink->partial_buf_size = frame_size; } -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; +#define MAKE_AVFILTERLINK_ACCESSOR(type, field) \ +type av_buffersink_get_##field(const AVFilterContext *ctx) { \ + av_assert0(ctx->filter->uninit == uninit); \ + return ctx->inputs[0]->field; \ } +MAKE_AVFILTERLINK_ACCESSOR(enum AVMediaType , type ); +MAKE_AVFILTERLINK_ACCESSOR(AVRational , time_base ); +MAKE_AVFILTERLINK_ACCESSOR(int , format ); + +MAKE_AVFILTERLINK_ACCESSOR(AVRational , frame_rate ); +MAKE_AVFILTERLINK_ACCESSOR(int , w ); +MAKE_AVFILTERLINK_ACCESSOR(int , h ); +MAKE_AVFILTERLINK_ACCESSOR(AVRational , sample_aspect_ratio); + +MAKE_AVFILTERLINK_ACCESSOR(int , channels ); +MAKE_AVFILTERLINK_ACCESSOR(uint64_t , channel_layout ); +MAKE_AVFILTERLINK_ACCESSOR(int , sample_rate ); + +MAKE_AVFILTERLINK_ACCESSOR(AVBufferRef * , hw_frames_ctx ); + static av_cold int vsink_init(AVFilterContext *ctx, void *opaque) { BufferSinkContext *buf = ctx->priv; diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h index e399b91175..f51fa7c1dd 100644 --- a/libavfilter/buffersink.h +++ b/libavfilter/buffersink.h @@ -101,9 +101,27 @@ AVABufferSinkParams *av_abuffersink_params_alloc(void); void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size); /** - * Get the frame rate of the input. + * @defgroup lavfi_buffersink_accessors Buffer sink accessors + * Get the properties of the stream + * @{ */ -AVRational av_buffersink_get_frame_rate(AVFilterContext *ctx); + +enum AVMediaType av_buffersink_get_type (const AVFilterContext *ctx); +AVRational av_buffersink_get_time_base (const AVFilterContext *ctx); +int av_buffersink_get_format (const AVFilterContext *ctx); + +AVRational av_buffersink_get_frame_rate (const AVFilterContext *ctx); +int av_buffersink_get_w (const AVFilterContext *ctx); +int av_buffersink_get_h (const AVFilterContext *ctx); +AVRational av_buffersink_get_sample_aspect_ratio (const AVFilterContext *ctx); + +int av_buffersink_get_channels (const AVFilterContext *ctx); +uint64_t av_buffersink_get_channel_layout (const AVFilterContext *ctx); +int av_buffersink_get_sample_rate (const AVFilterContext *ctx); + +AVBufferRef * av_buffersink_get_hw_frames_ctx (const AVFilterContext *ctx); + +/** @} */ /** * Get a frame with filtered data from sink and put it in frame.