From patchwork Wed Feb 21 22:25:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Langdale X-Patchwork-Id: 7694 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.150.33 with SMTP id c30csp1322632jai; Wed, 21 Feb 2018 14:31:35 -0800 (PST) X-Google-Smtp-Source: AH8x226YYc0+MJbUXd5sF1HnVsr327QrHv1yyLrSwkEJtAnyzCZuOfHQHveWZXSiirfrkbEqmNbE X-Received: by 10.223.138.153 with SMTP id y25mr4384674wry.257.1519252295282; Wed, 21 Feb 2018 14:31:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519252295; cv=none; d=google.com; s=arc-20160816; b=hH3QMtEOnd5K2QbDVclEOli7xoTGzES3zniz2kH09zgHn0jTRVoRCcLr/UVrWuv27j 1Bo1B/XarymTbY8V33FpGwwN2NngX7SiKz/lObMmU1uJ1xP2JSDvnUBXfbQXe0U6uo4O E8EUCKbEL3QDiRhMXnQ9ySMs9Iitj8l9vEeX6yMbMn3yUbKIcLAlI6/SjrzDNWhnqlAt U/psa2Olew4SWGblQ4rl8RbQ+1q7P3K55JnS1kLhVVVdBDgVcCHZFKMm2VuQpZMvK+C4 I5zXH7d8KMUu5pBaOcqaf1ADOWdzYr8QaX0wpQVVJui+SaV3EgrWRXulBNBv6GL0JgDJ CX1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=hvNSWJy7WVwu3LHyThs3AZ3RARw4oAx3Htb11ObqrGQ=; b=qvcoIodFqIMuimb4Q9x+9D29gvK/sn/hxRApVD4qNZZ9Tt8X6ohLTYWMh8ofvyVxhn /9GdqveqUzKu/T+CFnY2AND9AZ4oG/POIeUQHAouxImmif10o7IGKbQYuP6QGWd5ojra Hm8VleiNP1vc306Hvrz2QiWmavEd57G+92jqikV9QV8DbeKkY6aACPH3ulwLBbVE3t7D 7bMnyKxPkWPHtcCdvz5FVuVa9uoOUJFcRAuBmn/acxjX0ipsM79CVuIvbzLeCdxA4df9 pIdHP1dzHNQKPN0jxvye4+NOoVBRDWGRVGa2Ct6Nahq/yIYNv4lQtOFZNVwJ3KXMubfe uwpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@overt.org header.s=mail header.b=jm0/ArCG; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s1si4992596wrf.447.2018.02.21.14.31.34; Wed, 21 Feb 2018 14:31:35 -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; dkim=neutral (body hash did not verify) header.i=@overt.org header.s=mail header.b=jm0/ArCG; 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 ECBC668A346; Thu, 22 Feb 2018 00:31:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it0-f99.google.com (mail-it0-f99.google.com [209.85.214.99]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2F00D68A2A5 for ; Thu, 22 Feb 2018 00:31:25 +0200 (EET) Received: by mail-it0-f99.google.com with SMTP id v186so4161414itc.5 for ; Wed, 21 Feb 2018 14:31:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=90a8HfVhqS8aWCiWZAlZPxNABJ0ahPcLvx9EXFpB7tk=; b=qI6lUZbYqJfksRhs4K+LuVB2169u6cQV29FdIKg+HqQIFgI2H6k8DI2nsANbfzAslb WbsFFLfLZEHejgO+VWuE0BvtgFG3o8PcRVXYKlns2g2CWcf4Ip77jYX4O4phgsbv2Mxi 2eX+A2nA+FpltwKHIJG0MKafgsPAe8qIdL8LbZVTkDTRfbjoigDpE9SmNeUXA8lJE784 C9i+DallzRKhn5YBqSC5OURIRVV1rspibKg3Biu7rbYAclls8Bn3It3K6NhBbAYYZ4qR rVaB7j44UeR+oKxRC0/i6YfY8zB86XavMLwpYYs2muivxs/kKEuU7gKIc9u4V1vU9TQB t47Q== X-Gm-Message-State: APf1xPAskQFssm2Dl8Ww1MWuA3oHwizn0k4ruR5aAULXCHCe7fziBgQo y2d/7aYSSPCq6PSV7p039h+V0miX6Es1Sx91WKo2JZBf5aA2ow== X-Received: by 10.36.66.195 with SMTP id i186mr5610567itb.45.1519251952478; Wed, 21 Feb 2018 14:25:52 -0800 (PST) Received: from mail.overt.org (155.208.178.107.bc.googleusercontent.com. [107.178.208.155]) by smtp-relay.gmail.com with ESMTPS id 138sm8250907itx.0.2018.02.21.14.25.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2018 14:25:52 -0800 (PST) X-Relaying-Domain: gapps.overt.org Received: from authenticated-user (mail.overt.org [107.178.208.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.overt.org (Postfix) with ESMTPSA id D53BD601BE; Wed, 21 Feb 2018 22:25:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=overt.org; s=mail; t=1519251952; bh=MkpUjVmu4IW4B1wAGBuMGJW05nW3Pos6JPVLjEOmbMA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jm0/ArCGfPmD9zb7H5JVmgyzB65kIE1/1sOYOsHtbt9qRDnLhCMpwkRi2mQymKPjd ZNrCVcNWLO+0alBVumO1Ej6FDpZFHlsE7MomlKIC3aZmXtshODoS2Z0BgneSoq+z75 Mn2I2UhTnXC3+05DNro7oftrmEkFUTA0if3WFsIx/5NKDPR6TxgSmQC4vZzLxD3iHs EIk+ILkaybveLqFQZGViRlkZiX3WYnJwBJkcGYGCtnOPUORC7Od89gth9xx2DXyx3o OtUs85RCbTUH6OECOGfNaakOtTiLrHxnlI/gByEYgX8y9guPxw69vRBf+oNMCqTKck Ei3hVjhKYsvMA== From: Philip Langdale To: ffmpeg-devel@ffmpeg.org Date: Wed, 21 Feb 2018 14:25:36 -0800 Message-Id: <20180221222538.7255-2-philipl@overt.org> In-Reply-To: <20180221222538.7255-1-philipl@overt.org> References: <20180221222538.7255-1-philipl@overt.org> Subject: [FFmpeg-devel] [PATCH 1/3] avfilter: Add support for colour range as a link parameter 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 Cc: Philip Langdale MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" As part of achieving our YUVJ-free future, it needs to be possible to pass the colour range property from a decoder context to an encoder context. In the absence of filters, this is obviously trivial, but as soon as filters are introduced, there needs to be a way to pass and preserve the property (or modify it, as some filters will do). Based on existing properties of this type, this change adds a link property and ways to set it from a buffer source and get it from a buffer sink. Signed-off-by: Philip Langdale --- doc/APIchanges | 5 +++++ libavfilter/avfilter.c | 2 ++ libavfilter/avfilter.h | 2 ++ libavfilter/buffersink.c | 1 + libavfilter/buffersink.h | 1 + libavfilter/buffersrc.c | 23 +++++++++++++++++++++-- libavfilter/buffersrc.h | 5 +++++ libavfilter/version.h | 2 +- libavfilter/video.c | 1 + 9 files changed, 39 insertions(+), 3 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index a98475366d..1c583420d1 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,11 @@ libavutil: 2017-10-21 API changes, most recent first: +2018-02-xx - xxxxxxx - lavfi 7.13.100 - avfilter.h + + Add AVFilterLink.color_range, and mechanisms to set/get it on + buffersrc and buffersink. + 2018-02-xx - xxxxxxx Change av_ripemd_update(), av_murmur3_update() and av_hash_update() length parameter type to size_t at next major bump. diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 7553f7c36a..9b93e8177e 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -338,6 +338,8 @@ int avfilter_config_links(AVFilterContext *filter) link->w = inlink->w; if (!link->h) link->h = inlink->h; + if (link->color_range == AVCOL_RANGE_UNSPECIFIED) + link->color_range = inlink->color_range; } else if (!link->w || !link->h) { av_log(link->src, AV_LOG_ERROR, "Video source filters must set their output link's " diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 2d1195eeeb..ae3287a69e 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -600,6 +600,8 @@ struct AVFilterLink { */ AVBufferRef *hw_frames_ctx; + enum AVColorRange color_range; ///< agreed upon video color range + #ifndef FF_INTERNAL_FIELDS /** diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c index 0f87b5439a..897396cac4 100644 --- a/libavfilter/buffersink.c +++ b/libavfilter/buffersink.c @@ -194,6 +194,7 @@ 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(enum AVColorRange, color_range ) MAKE_AVFILTERLINK_ACCESSOR(int , channels ) MAKE_AVFILTERLINK_ACCESSOR(uint64_t , channel_layout ) diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h index 21d6bb505b..d91e3fe448 100644 --- a/libavfilter/buffersink.h +++ b/libavfilter/buffersink.h @@ -114,6 +114,7 @@ AVRational av_buffersink_get_frame_rate (const AVFilterContext *c 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); +enum AVColorRange av_buffersink_get_color_range (const AVFilterContext *ctx); int av_buffersink_get_channels (const AVFilterContext *ctx); uint64_t av_buffersink_get_channel_layout (const AVFilterContext *ctx); diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c index cd56f8ca45..2517f10feb 100644 --- a/libavfilter/buffersrc.c +++ b/libavfilter/buffersrc.c @@ -52,6 +52,7 @@ typedef struct BufferSourceContext { int w, h; enum AVPixelFormat pix_fmt; AVRational pixel_aspect; + int color_range; char *sws_param; AVBufferRef *hw_frames_ctx; @@ -111,6 +112,8 @@ int av_buffersrc_parameters_set(AVFilterContext *ctx, AVBufferSrcParameters *par s->pixel_aspect = param->sample_aspect_ratio; if (param->frame_rate.num > 0 && param->frame_rate.den > 0) s->frame_rate = param->frame_rate; + if (param->color_range > AVCOL_RANGE_UNSPECIFIED) + s->color_range = param->color_range; if (param->hw_frames_ctx) { av_buffer_unref(&s->hw_frames_ctx); s->hw_frames_ctx = av_buffer_ref(param->hw_frames_ctx); @@ -279,13 +282,19 @@ static av_cold int init_video(AVFilterContext *ctx) return AVERROR(EINVAL); } + if (!av_color_range_name(c->color_range)) { + av_log(ctx, AV_LOG_ERROR, "Invalid color_range parameter provided.\n"); + return AVERROR(EINVAL); + } + if (!(c->fifo = av_fifo_alloc(sizeof(AVFrame*)))) return AVERROR(ENOMEM); - av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d pixfmt:%s tb:%d/%d fr:%d/%d sar:%d/%d sws_param:%s\n", + av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d pixfmt:%s tb:%d/%d fr:%d/%d sar:%d/%d sws_param:%s\n color_range:%s\n", c->w, c->h, av_get_pix_fmt_name(c->pix_fmt), c->time_base.num, c->time_base.den, c->frame_rate.num, c->frame_rate.den, - c->pixel_aspect.num, c->pixel_aspect.den, (char *)av_x_if_null(c->sws_param, "")); + c->pixel_aspect.num, c->pixel_aspect.den, (char *)av_x_if_null(c->sws_param, ""), + av_color_range_name(c->color_range)); c->warning_limit = 100; return 0; } @@ -309,6 +318,15 @@ static const AVOption buffer_options[] = { { "time_base", NULL, OFFSET(time_base), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, DBL_MAX, V }, { "frame_rate", NULL, OFFSET(frame_rate), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, DBL_MAX, V }, { "sws_param", NULL, OFFSET(sws_param), AV_OPT_TYPE_STRING, .flags = V }, + { "color_range", NULL, OFFSET(color_range), AV_OPT_TYPE_INT, { .i64 = AVCOL_RANGE_UNSPECIFIED }, 0, INT_MAX, V, "range" }, + { "unspecified", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_UNSPECIFIED}, 0, 0, V, "range"}, + { "unknown", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_UNSPECIFIED}, 0, 0, V, "range"}, + { "limited", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, V, "range"}, + { "tv", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, V, "range"}, + { "mpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_MPEG}, 0, 0, V, "range"}, + { "full", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, V, "range"}, + { "pc", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, V, "range"}, + { "jpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64=AVCOL_RANGE_JPEG}, 0, 0, V, "range"}, { NULL }, }; @@ -434,6 +452,7 @@ static int config_props(AVFilterLink *link) link->w = c->w; link->h = c->h; link->sample_aspect_ratio = c->pixel_aspect; + link->color_range = c->color_range; if (c->hw_frames_ctx) { link->hw_frames_ctx = av_buffer_ref(c->hw_frames_ctx); diff --git a/libavfilter/buffersrc.h b/libavfilter/buffersrc.h index 0652113f2b..0ea2e436b3 100644 --- a/libavfilter/buffersrc.h +++ b/libavfilter/buffersrc.h @@ -114,6 +114,11 @@ typedef struct AVBufferSrcParameters { * Audio only, the audio channel layout */ uint64_t channel_layout; + + /** + * Video only, The color range of the video. + */ + enum AVColorRange color_range; } AVBufferSrcParameters; /** diff --git a/libavfilter/version.h b/libavfilter/version.h index ca096962bb..babb4187b4 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -30,7 +30,7 @@ #include "libavutil/version.h" #define LIBAVFILTER_VERSION_MAJOR 7 -#define LIBAVFILTER_VERSION_MINOR 12 +#define LIBAVFILTER_VERSION_MINOR 13 #define LIBAVFILTER_VERSION_MICRO 100 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ diff --git a/libavfilter/video.c b/libavfilter/video.c index 7a8e587798..2cfe9c8f17 100644 --- a/libavfilter/video.c +++ b/libavfilter/video.c @@ -92,6 +92,7 @@ AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h) return NULL; frame->sample_aspect_ratio = link->sample_aspect_ratio; + frame->color_range = link->color_range; return frame; }