From patchwork Fri Nov 12 16:32:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 31394 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp2053054iob; Fri, 12 Nov 2021 08:33:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJww7bYYXtKN5/70IOAtzYVMxjpVeB49MJW1rMWzu7vxAG53RsSU/1GYf37D7LXnb7/caL7+ X-Received: by 2002:a05:6402:40ce:: with SMTP id z14mr22519568edb.294.1636734825984; Fri, 12 Nov 2021 08:33:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636734825; cv=none; d=google.com; s=arc-20160816; b=dOQKqVElXCGCUX6GAAnuVIjgjw1bk0rskL5YTnPf9V9WJG1GVBUbFQgqmLdJftnmcv rLhn8L2+9W7P7DoAl7nrxswRNdDVcIap7qlcRIzB1peTio/oiKxlL0KsozBES/+zMUuV etqYz/UBsP4PXo1ZJMRiGFXT0F9mv5c0P8LPc7SItzN5zhcEmxcBqW5xukTOf0PjWaSV pzM4UGNDi3k71XE+ZcL1vwv2pb+oddx6XnNaXlPOy2CKo1TWqTCquTsKpjcbR2bWYzHl zKGYhkA3mBQ4ymMk/AMnIvpOiZ0ctKXUwToWErlXLdo5BksFe7Fun/fciK3x0e+33NPj 4mYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=JU/4kiviTdBpZuJSbbcREH9I8bU6BZgAGNCoTfaKWL8=; b=if8eR8qksVowXnF3peUbDa1FJHOQpd4OKkNZ8dsSnpfThHgyJs7B5Onjo8TuuMo2fe 3KCeeC135Fh5zHuL3IauMLF0k5WYhXEK6FE0oh+VqP/hOZFwH2KWhbA/8wsPSCjvbUIl vPjPzXm6H4fRq0GlW78/mZiVghhvkOCfhMrtUUfnb4AhPyzK5Z3NGtXp70tTfNCrWyTJ rxLUl4pB3qwXy4ornx0tXZQo59rYSId+wzz/j+xpAZ1ditYt/d0+BENiozbBB2CNttLZ xJcuQjaCJPSHKPW4AqonI4MtFcRzLjfMMzHETv5nRC49t7nnZGJOvEQ+MqBUylj97KrP EBoQ== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id nc35si16488977ejc.662.2021.11.12.08.33.45; Fri, 12 Nov 2021 08:33:45 -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 90CF868A778; Fri, 12 Nov 2021 18:33:09 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 16EE068A1A7 for ; Fri, 12 Nov 2021 18:33:01 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 9115A240176 for ; Fri, 12 Nov 2021 17:33:00 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 27MBuGVFC4hT for ; Fri, 12 Nov 2021 17:32:59 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 0A98F24017A for ; Fri, 12 Nov 2021 17:32:59 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 0734B3A0743; Fri, 12 Nov 2021 17:32:59 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 12 Nov 2021 17:32:53 +0100 Message-Id: <20211112163255.20522-4-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211112163255.20522-1-anton@khirnov.net> References: <20211112163255.20522-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/6] lavf: add "disposition" AVOption to AVStream AVClass X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: vkI7pDhdIn0A Use it to remove custom disposition parsing code from ffmpeg.c --- doc/APIchanges | 1 + fftools/ffmpeg.c | 40 ++++++++++++---------------------------- libavformat/utils.c | 24 ++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 53f229d41a..ad57ae29d6 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -18,6 +18,7 @@ API changes, most recent first: Add av_stream_get_class(). Schedule adding AVStream.av_class at libavformat major version 60. Add av_disposition_to_string() and av_disposition_from_string(). + Add "disposition" AVOption to AVStream's class. 2021-11-12 - xxxxxxxxxx - lavu 57.8.100 - hwcontext_vulkan.h Added AVFrame.sem_value, AVVulkanDeviceContext.queue_family_encode_index, diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 9d4f9d7a2b..b5fc1e845f 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3667,34 +3667,18 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame, // parse user provided disposition, and update stream values if (ost->disposition) { - static const AVOption opts[] = { - { "disposition" , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit = "flags" }, - { "default" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEFAULT }, .unit = "flags" }, - { "dub" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DUB }, .unit = "flags" }, - { "original" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ORIGINAL }, .unit = "flags" }, - { "comment" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_COMMENT }, .unit = "flags" }, - { "lyrics" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_LYRICS }, .unit = "flags" }, - { "karaoke" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_KARAOKE }, .unit = "flags" }, - { "forced" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_FORCED }, .unit = "flags" }, - { "hearing_impaired" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_HEARING_IMPAIRED }, .unit = "flags" }, - { "visual_impaired" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_VISUAL_IMPAIRED }, .unit = "flags" }, - { "clean_effects" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CLEAN_EFFECTS }, .unit = "flags" }, - { "attached_pic" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ATTACHED_PIC }, .unit = "flags" }, - { "captions" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CAPTIONS }, .unit = "flags" }, - { "descriptions" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DESCRIPTIONS }, .unit = "flags" }, - { "dependent" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEPENDENT }, .unit = "flags" }, - { "metadata" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_METADATA }, .unit = "flags" }, - { NULL }, - }; - static const AVClass class = { - .class_name = "", - .item_name = av_default_item_name, - .option = opts, - .version = LIBAVUTIL_VERSION_INT, - }; - const AVClass *pclass = &class; - - ret = av_opt_eval_flags(&pclass, &opts[0], ost->disposition, &ost->st->disposition); +#if LIBAVFORMAT_VERSION_MAJOR >= 60 + ret = av_opt_set(ost->st, "disposition", ost->disposition, 0); +#else + { + const AVClass *class = av_stream_get_class(); + const AVOption *o = av_opt_find(&class, "disposition", NULL, 0, AV_OPT_SEARCH_FAKE_OBJ); + + av_assert0(o); + ret = av_opt_eval_flags(&class, o, ost->disposition, &ost->st->disposition); + } +#endif + if (ret < 0) return ret; } diff --git a/libavformat/utils.c b/libavformat/utils.c index 9c38c60e81..af6805c27f 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -722,10 +722,34 @@ void avformat_free_context(AVFormatContext *s) av_free(s); } +static const AVOption stream_options[] = { + { "disposition", NULL, offsetof(AVStream, disposition), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, + .flags = AV_OPT_FLAG_ENCODING_PARAM, .unit = "disposition" }, + { "default", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEFAULT }, .unit = "disposition" }, + { "dub", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DUB }, .unit = "disposition" }, + { "original", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ORIGINAL }, .unit = "disposition" }, + { "comment", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_COMMENT }, .unit = "disposition" }, + { "lyrics", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_LYRICS }, .unit = "disposition" }, + { "karaoke", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_KARAOKE }, .unit = "disposition" }, + { "forced", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_FORCED }, .unit = "disposition" }, + { "hearing_impaired", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_HEARING_IMPAIRED }, .unit = "disposition" }, + { "visual_impaired", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_VISUAL_IMPAIRED }, .unit = "disposition" }, + { "clean_effects", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CLEAN_EFFECTS }, .unit = "disposition" }, + { "attached_pic", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ATTACHED_PIC }, .unit = "disposition" }, + { "timed_thumbnails", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_TIMED_THUMBNAILS }, .unit = "disposition" }, + { "captions", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CAPTIONS }, .unit = "disposition" }, + { "descriptions", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DESCRIPTIONS }, .unit = "disposition" }, + { "metadata", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_METADATA }, .unit = "disposition" }, + { "dependent", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEPENDENT }, .unit = "disposition" }, + { "still_image", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_STILL_IMAGE }, .unit = "disposition" }, + { NULL } +}; + static const AVClass stream_class = { .class_name = "AVStream", .item_name = av_default_item_name, .version = LIBAVUTIL_VERSION_INT, + .option = stream_options, }; const AVClass *av_stream_get_class(void)