From patchwork Sat Jul 15 10:45:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42690 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239003pzb; Sat, 15 Jul 2023 03:46:38 -0700 (PDT) X-Google-Smtp-Source: APBJJlHJhMDJM+XOU3QQX+Ne9wVlReWN6Nc+wC05ZM4ZDKw0h2zU4wa2JlAzUR0/fV8jFmG/3Mg+ X-Received: by 2002:a50:ec98:0:b0:51e:720:3ae7 with SMTP id e24-20020a50ec98000000b0051e07203ae7mr6596341edr.3.1689417998186; Sat, 15 Jul 2023 03:46:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689417998; cv=none; d=google.com; s=arc-20160816; b=sCVal+/iKK6p9YxEIqBrQyRgFH4/ik7LxWp2pnNpGs4/lpTdq80XEux9d0fxIlOhN/ 1p6k7Exm4/GG06tC8q5JgJvd4MqpaWMXYj+9NUUnFKWgOt/AjiDH4YZZRmq1sw2Ml7qg TqyYlu9TKIuHsqGDmRC4S2HSwhhwwT3elCECUyoKihDVWHfvhiVKeBMQRlHSmHjpsww7 BjAVpsy+tvgrzUZ4RfmC8VZP6fxcgGazBpwoeJaoNQaHCvju+fBqo/BNFtCInZ2aXami ha27IMU937I1lGqRvPvZ3P5TyH56AuQyYG6A9EwNhLKY+jBwthGQgdfhuZ2QtZSge75t +WxA== 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:message-id:date:to:from :delivered-to; bh=Ahc+PlaUOMFgyq5ZszQET1I0AcWzmb6+4tq25fC2BQ0=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=m8KM/wthewV9zI64Nj3ZmMTj5a3NiPEIAfRzDWiTBMOJG37cuLHfneCwdy4kGNAE1g F9ZFIWi6Kljwd20Pu2ob+dIbO/IUELwG8zEUHrQp8PSnTTBsHkVFzWGEWa25X7dPDwib 90LoZLV0D63H4yVqXpIM29nWbrB0GMmVqLpaS68sGv27DtFAlhM6wECQTXGwtyu1gBAe 47z8btMSjgvzga6MLpoJ4aqqmISZbuWizvQaBgkWGgwrL50UX4FAI8DjegBP1WqZVuP6 tiV4O++s18nMoQauF79qU25rfix3gxe2P5cZ7/TeNWZt3ss4Ai54n5RZaCsDfCuHK2fZ tgSw== 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 d4-20020a056402078400b0051fea43cedfsi1374119edy.384.2023.07.15.03.46.37; Sat, 15 Jul 2023 03:46:38 -0700 (PDT) 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 0EAD068C558; Sat, 15 Jul 2023 13:46:34 +0300 (EEST) 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 7CBE068C4C7 for ; Sat, 15 Jul 2023 13:46:27 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 3FBC8240D30 for ; Sat, 15 Jul 2023 12:46:27 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id rc4mWfaoZ5r7 for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) 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 7395D2404EA for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id F39E03A0153 for ; Sat, 15 Jul 2023 12:46:19 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:25 +0200 Message-Id: <20230715104611.17902-1-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/47] fftools/ffmpeg_mux_init: handle pixel format endianness 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: XAfMCZZrX5Nv When -pix_fmt designates a BE/LE pixel format, it gets translated into the native one by av_get_pix_fmt(). This may not always be the best choice, as the encoder might only support one endianness. In such a case, explicitly choose the endianness supported by the encoder. While this is currently redundant with choose_pixel_fmt() in ffmpeg_filter.c, the latter code will be deprecated in following commits. --- fftools/ffmpeg_mux_init.c | 55 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 6458414b5f..2d45fa7c7c 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -495,6 +495,54 @@ static int parse_matrix_coeffs(void *logctx, uint16_t *dest, const char *str) return 0; } +static int fmt_in_list(const int *formats, int format) +{ + for (; *formats != -1; formats++) + if (*formats == format) + return 1; + return 0; +} + +static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, const char *name) +{ + const enum AVPixelFormat *fmts = ost->enc_ctx->codec->pix_fmts; + enum AVPixelFormat fmt; + + fmt = av_get_pix_fmt(name); + if (fmt == AV_PIX_FMT_NONE) { + av_log(ost, AV_LOG_FATAL, "Unknown pixel format requested: %s.\n", name); + return AV_PIX_FMT_NONE; + } + + /* when the user specified-format is an alias for an endianness-specific + * one (e.g. rgb48 -> rgb48be/le), it gets translated into the native + * endianness by av_get_pix_fmt(); + * the following code handles the case when the native endianness is not + * supported by the encoder, but the other one is */ + if (fmts && !fmt_in_list(fmts, fmt)) { + const char *name_canonical = av_get_pix_fmt_name(fmt); + int len = strlen(name_canonical); + + if (strcmp(name, name_canonical) && + (!strcmp(name_canonical + len - 2, "le") || + !strcmp(name_canonical + len - 2, "be"))) { + char name_other[64]; + enum AVPixelFormat fmt_other; + + snprintf(name_other, sizeof(name_other), "%s%ce", + name, name_canonical[len - 2] == 'l' ? 'b' : 'l'); + fmt_other = av_get_pix_fmt(name_other); + if (fmt_other != AV_PIX_FMT_NONE && fmt_in_list(fmts, fmt_other)) { + av_log(ost, AV_LOG_VERBOSE, "Mapping pixel format %s->%s\n", + name, name_other); + fmt = fmt_other; + } + } + } + + return fmt; +} + static int new_stream_video(Muxer *mux, const OptionsContext *o, OutputStream *ost) { @@ -558,9 +606,10 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, if (!*++frame_pix_fmt) frame_pix_fmt = NULL; } - if (frame_pix_fmt && (video_enc->pix_fmt = av_get_pix_fmt(frame_pix_fmt)) == AV_PIX_FMT_NONE) { - av_log(ost, AV_LOG_FATAL, "Unknown pixel format requested: %s.\n", frame_pix_fmt); - return AVERROR(EINVAL); + if (frame_pix_fmt) { + video_enc->pix_fmt = pix_fmt_parse(ost, frame_pix_fmt); + if (video_enc->pix_fmt == AV_PIX_FMT_NONE) + return AVERROR(EINVAL); } MATCH_PER_STREAM_OPT(intra_matrices, str, intra_matrix, oc, st); From patchwork Sat Jul 15 10:45:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42692 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239110pzb; Sat, 15 Jul 2023 03:46:57 -0700 (PDT) X-Google-Smtp-Source: APBJJlGsQsNd+3BOfDStSby8HScrawQvkxIkG/1If8LduRz09L8j2IGpyQEOnBnWVidme5rDbYJh X-Received: by 2002:a17:906:151:b0:992:3ac7:a2d8 with SMTP id 17-20020a170906015100b009923ac7a2d8mr6367398ejh.37.1689418017391; Sat, 15 Jul 2023 03:46:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418017; cv=none; d=google.com; s=arc-20160816; b=k7oNd+2bi2oymP2MGoA4T0VhCfz43UW+a4G5F/rcTTk55TawvIJ4x4fJNP4YAUM0Sn oVCdt10k+Pz0507f1pPpYqbbBQCPvBbqAmhe5wQWOxc6Lq5m+Ln/JZnESJ5uaR8HLI+w 2O0HFvDzcp6pIOniO5o4+L4aCoS3P1kSnGkZZo8IfJpWJd15XtJfTs5zbKAOotyMNMyg hLSC/8Ahhh8gh5umcXopAqrvlfunIvxZumNmqhqtiR8JYChRtt/hEg6np3Yn+kCQn2r8 zjoPNvW2xrHGg2gvsMetnogpRgga1zgWWaHalI99Oj6CBs5kzhaJPt+HIxy5pA6xGMG3 U4LA== 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=khZVb8EC1IklkR6507wl6DzJfW2ERIXUbyC7anWMm4s=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=ZBejxIJQZNXX6Qm8Z1PorunSpMEZNNxdWIhjrfXrya/j8/diE9kFGM6wsgIEcD28kG 4Ep9ZiRLgaGu+koY48Ta+cYrwjufgnfb90XZ51T/L88XVAD+UDgbcG3lzKYPv0+uw2uP COO3de+5er6aWjmDVeQ5NdnOJXtyj3P2MBiku+TR4O2/4maL1tS8j+/GKFqisKYFqrgf GbYcsLLdAM6DpFt83pCvOqYO5t/pR5il2hN6REW9kQDrKToHWY43lp4ArnEaa/JapUfE pr0nJtK0XqAo2kt1/Ip1uiPi1MfGyj319tXeBTUCb89MBhWk3DgGfKw7MGey9AWHR4D4 J4Tw== 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 f8-20020a170906138800b00982bd2c070fsi2111946ejc.469.2023.07.15.03.46.56; Sat, 15 Jul 2023 03:46:57 -0700 (PDT) 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 112EE68C4FB; Sat, 15 Jul 2023 13:46:36 +0300 (EEST) 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 0BF7268C550 for ; Sat, 15 Jul 2023 13:46:29 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id B04022404F5 for ; Sat, 15 Jul 2023 12:46:28 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id wQDYR0464cG4 for ; Sat, 15 Jul 2023 12:46:28 +0200 (CEST) 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 756942404EC for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 0C6813A0F81 for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:26 +0200 Message-Id: <20230715104611.17902-2-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/47] fftools/ffmpeg_filter: move "smart" pixfmt selection to ffmpeg_mux_init 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: hCukCIrIshHD This code works on encoder information and has no interaction with filtering, so it does not belong in ffmpeg_filter. --- fftools/ffmpeg_filter.c | 36 +----------------------------------- fftools/ffmpeg_mux_init.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index de75c9970e..71595513f3 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -285,38 +285,6 @@ static const enum AVPixelFormat *get_compliance_normal_pix_fmts(const AVCodec *c } } -static enum AVPixelFormat -choose_pixel_fmt(const AVCodec *codec, enum AVPixelFormat target, - int strict_std_compliance) -{ - if (codec && codec->pix_fmts) { - const enum AVPixelFormat *p = codec->pix_fmts; - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(target); - //FIXME: This should check for AV_PIX_FMT_FLAG_ALPHA after PAL8 pixel format without alpha is implemented - int has_alpha = desc ? desc->nb_components % 2 == 0 : 0; - enum AVPixelFormat best= AV_PIX_FMT_NONE; - - if (strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) { - p = get_compliance_normal_pix_fmts(codec, p); - } - for (; *p != AV_PIX_FMT_NONE; p++) { - best = av_find_best_pix_fmt_of_2(best, *p, target, has_alpha, NULL); - if (*p == target) - break; - } - if (*p == AV_PIX_FMT_NONE) { - if (target != AV_PIX_FMT_NONE) - av_log(NULL, AV_LOG_WARNING, - "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n", - av_get_pix_fmt_name(target), - codec->name, - av_get_pix_fmt_name(best)); - return best; - } - } - return target; -} - /* May return NULL (no pixel format found), a static string or a string * backed by the bprint. Nothing has been written to the AVBPrint in case * NULL is returned. The AVBPrint provided should be clean. */ @@ -326,7 +294,6 @@ static const char *choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint) AVCodecContext *enc = ost->enc_ctx; const AVDictionaryEntry *strict_dict = av_dict_get(ost->encoder_opts, "strict", NULL, 0); if (strict_dict) - // used by choose_pixel_fmt() and below av_opt_set(ost->enc_ctx, "strict", strict_dict->value, 0); if (ost->keep_pix_fmt) { @@ -335,8 +302,7 @@ static const char *choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint) return av_get_pix_fmt_name(ost->enc_ctx->pix_fmt); } if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) { - return av_get_pix_fmt_name(choose_pixel_fmt(enc->codec, enc->pix_fmt, - ost->enc_ctx->strict_std_compliance)); + return av_get_pix_fmt_name(enc->pix_fmt); } else if (enc->codec->pix_fmts) { const enum AVPixelFormat *p; diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 2d45fa7c7c..3fe157c2e4 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -503,6 +503,32 @@ static int fmt_in_list(const int *formats, int format) return 0; } +static enum AVPixelFormat +choose_pixel_fmt(const AVCodec *codec, enum AVPixelFormat target) +{ + const enum AVPixelFormat *p = codec->pix_fmts; + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(target); + //FIXME: This should check for AV_PIX_FMT_FLAG_ALPHA after PAL8 pixel format without alpha is implemented + int has_alpha = desc ? desc->nb_components % 2 == 0 : 0; + enum AVPixelFormat best= AV_PIX_FMT_NONE; + + for (; *p != AV_PIX_FMT_NONE; p++) { + best = av_find_best_pix_fmt_of_2(best, *p, target, has_alpha, NULL); + if (*p == target) + break; + } + if (*p == AV_PIX_FMT_NONE) { + if (target != AV_PIX_FMT_NONE) + av_log(NULL, AV_LOG_WARNING, + "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n", + av_get_pix_fmt_name(target), + codec->name, + av_get_pix_fmt_name(best)); + return best; + } + return target; +} + static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, const char *name) { const enum AVPixelFormat *fmts = ost->enc_ctx->codec->pix_fmts; @@ -540,6 +566,9 @@ static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, const char *name) } } + if (fmts && !fmt_in_list(fmts, fmt)) + fmt = choose_pixel_fmt(ost->enc_ctx->codec, fmt); + return fmt; } From patchwork Sat Jul 15 10:45:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42694 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239223pzb; Sat, 15 Jul 2023 03:47:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlHZbqZ/uF220Xe/oiIpF0gpix51uGs2v3E7UjnJJTqavIhof+QEz513Q3S1k6K4L8naKJGi X-Received: by 2002:a17:906:8413:b0:96f:8439:6143 with SMTP id n19-20020a170906841300b0096f84396143mr5870151ejx.40.1689418035024; Sat, 15 Jul 2023 03:47:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418035; cv=none; d=google.com; s=arc-20160816; b=Vhg76m++7T2VQ0WxOLmIqbP1KJqyJ/lbo5sV10wZ2d0JDpdg47J7KKsw1flKLQYAXl rDhsR/ik7rSEPVOAFIyi1myu9NMwK7mfFbWATJOC4KUnZbKoBdqI6W4YNSCqsAk3kn+B x0QDr3TtStV+IzE1gF2bPW/87Guw6eln+di/yuhCx909uEwWhV2/mazH2c2Rg2QvJvyv 7YBTCXdeDk6+BaZ/gWGMYs1umPxmTfpCNAaTmMR6TdZGvBu4VirnwrF3siX4ZQwagcAz XzsVaQvBbOrZ8ubiNBwByE/fmrQsYGZ8+dhh+5wRV41/6dX8lvT9R/X5ldQVH5Ctz5pS CjqA== 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=QCFFkyyfKS40iA16YVbI/z2xM3w4sIbenA4CR1gJ/X0=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=uDD4IPonr+GAJpwK/5d/eJJoYlgLCojM2vB0yoGCGjLg/eFtNYgeaWSBrcPdA+36F+ /0EzkV6/aTZlMnvG/7UCoS+D9SPRGtuMBFVxkGHcw0Ta1hlZo+6oIpcbS8AXYFCHLYNI rDOwt+tMiWOXtkvMg5K6pv24Gl6CGcqpiXQpTvO6WU3z14HTDFwUlQtql2kpoKw5QcnG TLRH5R975m/DRNdDKglI4oyJ14ZfQx/GgrOpp8yHB5xoZaqBJ7gNTchl+SQexItVYtMC XWjhkCuXmKRbrnpW/HhgTfo9R+vl9AfxHG4+FJVk8KnFgZV9aSYeH4zY+/m7JdLbw+Or 2WTQ== 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 g4-20020a170906198400b00988a210d8a3si2117280ejd.239.2023.07.15.03.47.14; Sat, 15 Jul 2023 03:47:15 -0700 (PDT) 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 08C9C68C64E; Sat, 15 Jul 2023 13:46:38 +0300 (EEST) 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 BD30A68C530 for ; Sat, 15 Jul 2023 13:46:29 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 7550F2404F8 for ; Sat, 15 Jul 2023 12:46:29 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id wTp3-nuCea7K for ; Sat, 15 Jul 2023 12:46:28 +0200 (CEST) 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 76C802404EE for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 177673A0FE6 for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:27 +0200 Message-Id: <20230715104611.17902-3-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/47] fftools/ffmpeg_mux_init: deprecate "smart" pixel format selection 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: ALlvt4/1vI4X It may override a format explicitly requested with -pix_fmt and instead select something completely unrelated, which is a user-hostile behaviour and is inconsistent with how other options generally work. Print a warning and delay for a second to make the users aware of the deprecation. --- doc/ffmpeg.texi | 3 +-- fftools/ffmpeg.h | 1 + fftools/ffmpeg_mux_init.c | 15 +++++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 2273c39214..a6ef5590c7 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -1014,8 +1014,7 @@ Disable autoscale at your own risk. @item -pix_fmt[:@var{stream_specifier}] @var{format} (@emph{input/output,per-stream}) Set pixel format. Use @code{-pix_fmts} to show all the supported pixel formats. -If the selected pixel format can not be selected, ffmpeg will print a -warning and select the best pixel format supported by the encoder. + If @var{pix_fmt} is prefixed by a @code{+}, ffmpeg will exit with an error if the requested pixel format can not be selected, and automatic conversions inside filtergraphs are disabled. diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index f45ddf33b2..7c4f4365c6 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -57,6 +57,7 @@ #define FFMPEG_OPT_QPHIST 1 #define FFMPEG_OPT_ADRIFT_THRESHOLD 1 #define FFMPEG_OPT_ENC_TIME_BASE_NUM 1 +#define FFMPEG_OPT_SMART_PIXFMT 1 enum VideoSyncMethod { VSYNC_AUTO = -1, diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 3fe157c2e4..03d60f2a19 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -45,6 +45,7 @@ #include "libavutil/opt.h" #include "libavutil/parseutils.h" #include "libavutil/pixdesc.h" +#include "libavutil/time.h" #define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass" @@ -503,6 +504,7 @@ static int fmt_in_list(const int *formats, int format) return 0; } +#if FFMPEG_OPT_SMART_PIXFMT static enum AVPixelFormat choose_pixel_fmt(const AVCodec *codec, enum AVPixelFormat target) { @@ -518,16 +520,23 @@ choose_pixel_fmt(const AVCodec *codec, enum AVPixelFormat target) break; } if (*p == AV_PIX_FMT_NONE) { - if (target != AV_PIX_FMT_NONE) + if (target != AV_PIX_FMT_NONE) { av_log(NULL, AV_LOG_WARNING, - "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n", + "Requested pixel format '%s' is nut supported by encoder '%s', " + "auto-selecting format '%s'\n", av_get_pix_fmt_name(target), codec->name, av_get_pix_fmt_name(best)); + av_log(NULL, AV_LOG_WARNING, "This behaviour is deprecated and will " + "be removed. Use -h encoder=%s to check supported pixel " + "formats and select one of them.\n", codec->name); + av_usleep(1000000); + } return best; } return target; } +#endif static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, const char *name) { @@ -566,8 +575,10 @@ static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, const char *name) } } +#if FFMPEG_OPT_SMART_PIXFMT if (fmts && !fmt_in_list(fmts, fmt)) fmt = choose_pixel_fmt(ost->enc_ctx->codec, fmt); +#endif return fmt; } From patchwork Sat Jul 15 10:45:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42691 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239065pzb; Sat, 15 Jul 2023 03:46:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlF++B+ZUJ2UfrUkY1LZu53uMUaVwfEvDcOjoqyNqCqZEHq49RrTiyp8reGf7jyhIRu+ZHMf X-Received: by 2002:a05:6402:1241:b0:51e:65d:1f6c with SMTP id l1-20020a056402124100b0051e065d1f6cmr6605188edw.9.1689418007702; Sat, 15 Jul 2023 03:46:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418007; cv=none; d=google.com; s=arc-20160816; b=PJ00cOJofKGpZTiGYfZ/PshZVGkFXmEx+240ex1ZIBouy3/mvfvfi7uE68Q/3GOuAT i0/2HmTOVk90TdIDQBQbkr5KepvzpxNqrUTXoRjBBKcu82IuNVWJGtLTMykEP09kY/0y mGIo84xozxAfKu2Q6LjvwvJVZwT2GpZy9OGdNgKGpvjyAZLR/WovaFeZIK6WedMEkJ1z Ovi9ngUBbNsd6MTW1ioyP+EocjbeCeuHgauyEd+AO5OScf8mcu2gSfFN1pJSQFzsm3Vh Ky439pm8yVbN2RztrvqRj1AgYfNf2amh3O/zEaMFHT7kvUrIJycNSGTCcLZTl/2whudE pMKQ== 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=fzKoxPYpbj5h2TQB0vpohDVjS7hro1cyKEqapxL/UKU=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=oiTggdMeopneeAss5IIyjj6iFmEwNYlVrNxwwSjplUe961zMcgwz1B62y+cwrpNgl/ +x2yb4cqbxTNTdQKF82yJXnudGgxu9wdBDUMmjxPI9vvV2nZpJ2h9VLfTOOavIT9INBo toVX0lbErWvRXv7kH2Ycw6bvX+DYmEOWFJR4HAjawliLpX6xuxiergENYbH0eHQPSCEz AViREu195OGjISDTOoLVxMytrXKcwXr6sxvfET6p+hNGSd2ToO6Qv1iMnThmJk/3th5f unkJdNYtZ7XNicyfo34frD21T3EM1M/LmtfkJnWgv5FQ9ce/PfaJsAeA5IdGQyW0wkyM Uo4A== 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 p13-20020a056402074d00b0051dd49a94c2si10479692edy.583.2023.07.15.03.46.47; Sat, 15 Jul 2023 03:46:47 -0700 (PDT) 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 205C668C5DE; Sat, 15 Jul 2023 13:46:35 +0300 (EEST) 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 5DFAB68C4F8 for ; Sat, 15 Jul 2023 13:46:28 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 1DDE32404EA for ; Sat, 15 Jul 2023 12:46:28 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id oEkIQSx8-4-8 for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) 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 79D132404F5 for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 227703A1074 for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:28 +0200 Message-Id: <20230715104611.17902-4-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/47] tests/fate: fix mismatches between requested and actually used pixel formats 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: K2s36ZKdN1uc --- tests/fate/fits.mak | 6 +++--- tests/fate/lavf-video.mak | 2 +- tests/fate/vcodec.mak | 4 ++-- tests/ref/fate/{fitsdec-gbrap16le => fitsdec-gbrap16be} | 4 ++-- tests/ref/fate/{fitsdec-gbrp16 => fitsdec-gbrp16be} | 4 ++-- tests/ref/lavf/gif | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) rename tests/ref/fate/{fitsdec-gbrap16le => fitsdec-gbrap16be} (79%) rename tests/ref/fate/{fitsdec-gbrp16 => fitsdec-gbrp16be} (79%) diff --git a/tests/fate/fits.mak b/tests/fate/fits.mak index b9e99d97ee..d85946bc1a 100644 --- a/tests/fate/fits.mak +++ b/tests/fate/fits.mak @@ -8,8 +8,8 @@ tests/data/fits-multi.fits: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data # TODO: Use an actual 64bit input file and fix the gbrp16 test on big-endian fits-png-map-gray := gray8 fits-png-map-gbrp := rgb24 -fits-png-map-gbrp16 := rgb48 -fits-png-map-gbrap16le := rgba64 +fits-png-map-gbrp16be := rgb48 +fits-png-map-gbrap16be := rgba64 FATE_FITS_DEC-$(call FRAMECRC, FITS, FITS, SCALE_FILTER) += fate-fitsdec-ext_data_min_max fate-fitsdec-ext_data_min_max: CMD = framecrc -i $(TARGET_SAMPLES)/fits/x0cj010ct_d0h.fit -pix_fmt gray16le -vf scale @@ -30,7 +30,7 @@ fate-fitsdec-multi: CMD = framecrc -i $(TARGET_PATH)/tests/data/fits-multi.fits fate-fitsdec%: PIXFMT = $(word 3, $(subst -, ,$(@))) fate-fitsdec%: CMD = transcode image2 $(TARGET_SAMPLES)/png1/lena-$(fits-png-map-$(PIXFMT)).png fits "-vf scale -pix_fmt $(PIXFMT)" -FATE_FITS_DEC_PIXFMT = gray gbrp gbrp16 gbrap16le +FATE_FITS_DEC_PIXFMT = gray gbrp gbrp16be gbrap16be FATE_FITS_DEC-$(call TRANSCODE, FITS, FITS, IMAGE2_DEMUXER PNG_DECODER SCALE_FILTER) += $(FATE_FITS_DEC_PIXFMT:%=fate-fitsdec-%) FATE_FITS += $(FATE_FITS_DEC-yes) diff --git a/tests/fate/lavf-video.mak b/tests/fate/lavf-video.mak index e73f8f203b..da3b114bc8 100644 --- a/tests/fate/lavf-video.mak +++ b/tests/fate/lavf-video.mak @@ -27,7 +27,7 @@ fate-lavf-gbrp.fits: CMD = lavf_video "-pix_fmt gbrp" fate-lavf-gbrap.fits: CMD = lavf_video "-pix_fmt gbrap" fate-lavf-gbrp16be.fits: CMD = lavf_video "-pix_fmt gbrp16be" fate-lavf-gbrap16be.fits: CMD = lavf_video "-pix_fmt gbrap16be" -fate-lavf-gif: CMD = lavf_video "-pix_fmt rgb24" +fate-lavf-gif: CMD = lavf_video "-pix_fmt rgb8" FATE_AVCONV += $(FATE_LAVF_VIDEO) fate-lavf-video fate-lavf: $(FATE_LAVF_VIDEO) diff --git a/tests/fate/vcodec.mak b/tests/fate/vcodec.mak index 2839e54de8..e32d28c556 100644 --- a/tests/fate/vcodec.mak +++ b/tests/fate/vcodec.mak @@ -210,9 +210,9 @@ fate-vsynth%-h263p: ENCOPTS = -qscale 2 -flags +aic -umv 1 -aiv 1 - FATE_VCODEC_SCALE-$(call ENCDEC, HUFFYUV, AVI) += huffyuv huffyuvbgr24 huffyuvbgra fate-vsynth%-huffyuv: ENCOPTS = -c:v huffyuv -pix_fmt yuv422p -sws_flags neighbor fate-vsynth%-huffyuv: DECOPTS = -sws_flags neighbor -fate-vsynth%-huffyuvbgr24: ENCOPTS = -c:v huffyuv -pix_fmt bgr24 -sws_flags neighbor +fate-vsynth%-huffyuvbgr24: ENCOPTS = -c:v huffyuv -pix_fmt rgb24 -sws_flags neighbor fate-vsynth%-huffyuvbgr24: DECOPTS = -sws_flags neighbor -fate-vsynth%-huffyuvbgra: ENCOPTS = -c:v huffyuv -pix_fmt bgr32 -sws_flags neighbor +fate-vsynth%-huffyuvbgra: ENCOPTS = -c:v huffyuv -pix_fmt rgb32 -sws_flags neighbor fate-vsynth%-huffyuvbgra: DECOPTS = -sws_flags neighbor FATE_VCODEC_SCALE-$(call ENCDEC, JPEGLS, AVI) += jpegls diff --git a/tests/ref/fate/fitsdec-gbrap16le b/tests/ref/fate/fitsdec-gbrap16be similarity index 79% rename from tests/ref/fate/fitsdec-gbrap16le rename to tests/ref/fate/fitsdec-gbrap16be index 53ef980b13..1174a0f1d8 100644 --- a/tests/ref/fate/fitsdec-gbrap16le +++ b/tests/ref/fate/fitsdec-gbrap16be @@ -1,5 +1,5 @@ -64526d8da12d1fa07ceea5725647076f *tests/data/fate/fitsdec-gbrap16le.fits -135360 tests/data/fate/fitsdec-gbrap16le.fits +64526d8da12d1fa07ceea5725647076f *tests/data/fate/fitsdec-gbrap16be.fits +135360 tests/data/fate/fitsdec-gbrap16be.fits #tb 0: 1/1 #media_type 0: video #codec_id 0: rawvideo diff --git a/tests/ref/fate/fitsdec-gbrp16 b/tests/ref/fate/fitsdec-gbrp16be similarity index 79% rename from tests/ref/fate/fitsdec-gbrp16 rename to tests/ref/fate/fitsdec-gbrp16be index 9250690e9b..ff4ca9e65c 100644 --- a/tests/ref/fate/fitsdec-gbrp16 +++ b/tests/ref/fate/fitsdec-gbrp16be @@ -1,5 +1,5 @@ -2078208c93ba417d3fe150ba42bf5a30 *tests/data/fate/fitsdec-gbrp16.fits -103680 tests/data/fate/fitsdec-gbrp16.fits +2078208c93ba417d3fe150ba42bf5a30 *tests/data/fate/fitsdec-gbrp16be.fits +103680 tests/data/fate/fitsdec-gbrp16be.fits #tb 0: 1/1 #media_type 0: video #codec_id 0: rawvideo diff --git a/tests/ref/lavf/gif b/tests/ref/lavf/gif index fc94b9df3d..7f353df286 100644 --- a/tests/ref/lavf/gif +++ b/tests/ref/lavf/gif @@ -1,3 +1,3 @@ e35f5ea283bbcb249818e0078ec72664 *tests/data/lavf/lavf.gif 2011766 tests/data/lavf/lavf.gif -tests/data/lavf/lavf.gif CRC=0x2429faff +tests/data/lavf/lavf.gif CRC=0x37f4d323 From patchwork Sat Jul 15 10:45:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42693 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239168pzb; Sat, 15 Jul 2023 03:47:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlFw8J6V0sZV45MAmEQ3c6re+qOsKSQ/rqSRcKqv5zKVFbP3j/PHL8BwSjpAgi0RHe+GYxk/ X-Received: by 2002:a17:906:3f1c:b0:98d:f953:f473 with SMTP id c28-20020a1709063f1c00b0098df953f473mr6592530ejj.50.1689418025939; Sat, 15 Jul 2023 03:47:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418025; cv=none; d=google.com; s=arc-20160816; b=z5qAEqZ5ZvJPNQh7tVnpvDs7RT9ajAC1e9PZdf7sdmlpyLvLLA2MVxKRQYiRCNx9aK xJ2lsCeuvHOuyGBF9auS9HGAfRQtV4OrHNBVk4GDctoRBpaV5KSCN1QdDe9FzxZvMydg zey9kNdQK0OCLRy2B/4IzG9loAzFiT9/WJ0RXXlZib56WE1whTil4oSGsJOxqGGs7C/r yfBkMhWmHEU6Kx7UYDK2xyv+uebvRE5qEyURKnFbsPnlrP4Wkm7PAA8Wu5es9R+C3Bhp S/ClMpEmhg5ZhZDleur+V2Ch65Q1tY7gwnQfQ2fj28baWP3qn1sGvczygZv/jQj+8BP9 PDbQ== 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=T44YInkRsV3rXnT+S1gJs8gYNXnQeYWUaphaQdjMak4=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=mieSANoR5Dhi/EmBzbjmngT7aPaED4KeNEpHXThWAFfkjnWeO1YtA3/QTLAtHVVp3X nwRfUKXi4hy71YdZiHUFCW5SHgeeky09VxONBKl5TV+xszFPIByfDraZzFqnWpAgl2JG DXxxtSF2B0GJd6apx+kHsGlQUe0Fm9m/7WS5yFC0IHUP5PGDgvA7AtztO/f/Fc/aGzGM bPmhEr7aUVNgAs4+nNL0fudIvw7auWp0nwmmCrIhzkugpK7IS+TS77/k6ex6K2o/AP+t Fp6riFcpSYlDPLs/WEE5X7XgpSajSDVm/7Sqw3Tx4BcDiIxxKh72/w8Q8P0fVycVraBH 0irg== 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 v7-20020a170906564700b0098e3890e257si10211531ejr.131.2023.07.15.03.47.05; Sat, 15 Jul 2023 03:47:05 -0700 (PDT) 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 0C46568C62C; Sat, 15 Jul 2023 13:46:37 +0300 (EEST) 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 7979968C550 for ; Sat, 15 Jul 2023 13:46:29 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 3D9D02404EC for ; Sat, 15 Jul 2023 12:46:29 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id h0JFiUHpuAHK for ; Sat, 15 Jul 2023 12:46:27 +0200 (CEST) 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 7B6652404F8 for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 2DEF33A1251 for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:29 +0200 Message-Id: <20230715104611.17902-5-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/47] fftools/ffmpeg_filter: stop accessing encoder from pixfmt selection 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: LLh3YqIi30pg ffmpeg CLI pixel format selection for filtering currently special-cases MJPEG encoding, where it will restrict the supported list of pixel formats depending on the value of the -strict option. In order to get that value it will apply it from the options dict into the encoder context, which is a highly invasive action even now, and would become a race once encoding is moved to its own thread. The ugliness of this code can be much reduced by moving the special handling of MJPEG into ofilter_bind_ost(), which is called from encoder init and is thus synchronized with it. There is also no need to write anything to the encoder context, we can evaluate the option into our stack variable. There is also no need to access AVCodec at all during pixel format selection, as the pixel formats array is already stored in OutputFilterPriv. --- fftools/ffmpeg_filter.c | 64 ++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 71595513f3..e14b8f0f3c 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -270,46 +270,22 @@ static void sub2video_update(InputFilterPriv *ifp, int64_t heartbeat_pts, ifp->sub2video.initialize = 0; } -// FIXME: YUV420P etc. are actually supported with full color range, -// yet the latter information isn't available here. -static const enum AVPixelFormat *get_compliance_normal_pix_fmts(const AVCodec *codec, const enum AVPixelFormat default_formats[]) -{ - static const enum AVPixelFormat mjpeg_formats[] = - { AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P, - AV_PIX_FMT_NONE }; - - if (!strcmp(codec->name, "mjpeg")) { - return mjpeg_formats; - } else { - return default_formats; - } -} - /* May return NULL (no pixel format found), a static string or a string * backed by the bprint. Nothing has been written to the AVBPrint in case * NULL is returned. The AVBPrint provided should be clean. */ static const char *choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint) { + OutputFilterPriv *ofp = ofp_from_ofilter(ofilter); OutputStream *ost = ofilter->ost; - AVCodecContext *enc = ost->enc_ctx; - const AVDictionaryEntry *strict_dict = av_dict_get(ost->encoder_opts, "strict", NULL, 0); - if (strict_dict) - av_opt_set(ost->enc_ctx, "strict", strict_dict->value, 0); - if (ost->keep_pix_fmt) { - if (ost->enc_ctx->pix_fmt == AV_PIX_FMT_NONE) - return NULL; - return av_get_pix_fmt_name(ost->enc_ctx->pix_fmt); + if (ost->keep_pix_fmt) { + return ofp->format == AV_PIX_FMT_NONE ? NULL : + av_get_pix_fmt_name(ofp->format); } - if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) { - return av_get_pix_fmt_name(enc->pix_fmt); - } else if (enc->codec->pix_fmts) { - const enum AVPixelFormat *p; - - p = enc->codec->pix_fmts; - if (ost->enc_ctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) { - p = get_compliance_normal_pix_fmts(enc->codec, p); - } + if (ofp->format != AV_PIX_FMT_NONE) { + return av_get_pix_fmt_name(ofp->format); + } else if (ofp->formats) { + const enum AVPixelFormat *p = ofp->formats; for (; *p != AV_PIX_FMT_NONE; p++) { const char *name = av_get_pix_fmt_name(*p); @@ -668,6 +644,30 @@ void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost) ofp->format = ost->enc_ctx->pix_fmt; } else { ofp->formats = c->pix_fmts; + + // MJPEG encoder exports a full list of supported pixel formats, + // but the full-range ones are experimental-only. + // Restrict the auto-conversion list unless -strict experimental + // has been specified. + if (!strcmp(c->name, "mjpeg")) { + // FIXME: YUV420P etc. are actually supported with full color range, + // yet the latter information isn't available here. + static const enum AVPixelFormat mjpeg_formats[] = + { AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P, + AV_PIX_FMT_NONE }; + + const AVDictionaryEntry *strict = av_dict_get(ost->encoder_opts, "strict", NULL, 0); + int strict_val = ost->enc_ctx->strict_std_compliance; + + if (strict) { + const AVOption *o = av_opt_find(ost->enc_ctx, strict->key, NULL, 0, 0); + av_assert0(o); + av_opt_eval_int(ost->enc_ctx, o, strict->value, &strict_val); + } + + if (strict_val > FF_COMPLIANCE_UNOFFICIAL) + ofp->formats = mjpeg_formats; + } } fgp->disable_conversions |= ost->keep_pix_fmt; From patchwork Sat Jul 15 10:45:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42698 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239405pzb; Sat, 15 Jul 2023 03:47:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlE6EufnxmuFnFw1PRyp2DnUy79kr8F+IPTsVa2j6bPCqkSNeggDBg8o1m0U6E/F8Fi1Jze/ X-Received: by 2002:aa7:c3d8:0:b0:51d:eb90:4928 with SMTP id l24-20020aa7c3d8000000b0051deb904928mr6928806edr.30.1689418067401; Sat, 15 Jul 2023 03:47:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418067; cv=none; d=google.com; s=arc-20160816; b=RZzlBL++0l7sT5FLWZqQP+MQ6w3ZT1VXCjM6Sab0lxK8ykVjxPo9bPPnp7y0oa1kEO j4uPEhwk43ykcSQGxTywH06KwMulKOm752d/cEcbVryrxf0ajzaWMTxDQ98xvMR9qwPY YO+q+aATeISWbOZnqVKBrVKtGsFIKn0cs5kvBhixnyPqaFOpUUmMIUwAda7GFvOWQ50p 6LP6EpQCW5NgTz/a16O3GTL0z1+VRpSwupepelASryuQO4YG1Ib0Au12x30zJimuhC1m 6+ntqBekyVo0T1fPU0n7AZrnTi6trrt+NxLmq/+ZJh36ycEoy8vWBD2hYxBdixDSFJCl Nr9A== 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=MQ4ATfD6WXYHVEt96fQeF0kVVfxbu+IwUhA1qpE3bqE=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=ZjjNL7xZlsrC6ISgA+Mdf2UV7rz+2jSTqMWQE0KjwqdmAxrxp/lWl9xhxGwavt3aFN IwqHpMEwmZAHOyqE25VvBNHr1VykbmPH4CNk1OXlgfIEdgD3q0gjogxULkLzBPnT0spk Yp0k38hgC9d53L4bfv5v9v1hxGLKhzRyYcKMkMdRUJCngsWNbf5MdNumWBW1QigJOeze jljbz9kKRpEuOqX/k7Co3WH+hMYaaoeDa3/b63BsuO7Xi3OT5wL6MxZ7771DSMh3eUF3 ETMtWUkHLlgNfqRNebNReULAFNKN6JDFCF0iA8oYHDbQLf1uFNX5Z5WIkFCWk1gxTpjA 5tlA== 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 r19-20020aa7d593000000b0051e22d772a2si11298712edq.679.2023.07.15.03.47.46; Sat, 15 Jul 2023 03:47:47 -0700 (PDT) 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 C105D68C60F; Sat, 15 Jul 2023 13:46:42 +0300 (EEST) 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 B5B3768C60F for ; Sat, 15 Jul 2023 13:46:32 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id EDFA92404EE for ; Sat, 15 Jul 2023 12:46:29 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id XmcRbhdx-W6X for ; Sat, 15 Jul 2023 12:46:29 +0200 (CEST) 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 8C677240591 for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 38AA23A128F for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:30 +0200 Message-Id: <20230715104611.17902-6-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/47] fftools/ffmpeg_filter: restrict reap_filters() to a single filtergraph 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: bCgiCjzF85Bd This is more natural, as all except one of its callers require processing only one filtergraph. --- fftools/ffmpeg.c | 10 +++++++++- fftools/ffmpeg.h | 4 ++-- fftools/ffmpeg_filter.c | 33 ++++++++++++++++----------------- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index cbeddab125..27c4e7ef26 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1171,7 +1171,15 @@ static int transcode_step(OutputStream *ost) if (ret < 0) return ret == AVERROR_EOF ? 0 : ret; - return reap_filters(0); + // process_input() above might have caused output to become available + // in multiple filtergraphs, so we process all of them + for (int i = 0; i < nb_filtergraphs; i++) { + ret = reap_filters(filtergraphs[i], 0); + if (ret < 0) + return ret; + } + + return 0; } /* diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 7c4f4365c6..0189bee0f3 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -766,12 +766,12 @@ void fg_free(FilterGraph **pfg); int fg_transcode_step(FilterGraph *graph, InputStream **best_ist); /** - * Get and encode new output from any of the filtergraphs, without causing + * Get and encode new output from specified filtergraph, without causing * activity. * * @return 0 for success, <0 for severe errors */ -int reap_filters(int flush); +int reap_filters(FilterGraph *fg, int flush); int ffmpeg_parse_options(int argc, char **argv); diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index e14b8f0f3c..49e0800e6e 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1695,24 +1695,23 @@ int filtergraph_is_simple(const FilterGraph *fg) return fgp->is_simple; } -int reap_filters(int flush) +int reap_filters(FilterGraph *fg, int flush) { + FilterGraphPriv *fgp = fgp_from_fg(fg); + AVFrame *filtered_frame = fgp->frame; + + if (!fg->graph) + return 0; + /* Reap all buffers present in the buffer sinks */ - for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) { - OutputFilterPriv *ofp; - FilterGraphPriv *fgp; - AVFrame *filtered_frame; - AVFilterContext *filter; + for (int i = 0; i < fg->nb_outputs; i++) { + OutputFilter *ofilter = fg->outputs[i]; + OutputStream *ost = ofilter->ost; + OutputFilterPriv *ofp = ofp_from_ofilter(ofilter); + AVFilterContext *filter = ofp->filter; + int ret = 0; - if (!ost->filter || !ost->filter->graph->graph) - continue; - fgp = fgp_from_fg(ost->filter->graph); - ofp = ofp_from_ofilter(ost->filter); - filter = ofp->filter; - - filtered_frame = fgp->frame; - while (1) { FrameData *fd; @@ -1931,7 +1930,7 @@ int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference) return ret; } - ret = reap_filters(0); + ret = reap_filters(fg, 0); if (ret < 0 && ret != AVERROR_EOF) { av_log(fg, AV_LOG_ERROR, "Error while filtering: %s\n", av_err2str(ret)); return ret; @@ -2000,10 +1999,10 @@ int fg_transcode_step(FilterGraph *graph, InputStream **best_ist) *best_ist = NULL; ret = avfilter_graph_request_oldest(graph->graph); if (ret >= 0) - return reap_filters(0); + return reap_filters(graph, 0); if (ret == AVERROR_EOF) { - reap_filters(1); + reap_filters(graph, 1); for (int i = 0; i < graph->nb_outputs; i++) { OutputFilter *ofilter = graph->outputs[i]; OutputFilterPriv *ofp = ofp_from_ofilter(ofilter); From patchwork Sat Jul 15 10:45:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42699 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239460pzb; Sat, 15 Jul 2023 03:47:55 -0700 (PDT) X-Google-Smtp-Source: APBJJlGuMP+eF6sEit5shjgBzFh8EkKwlaXvXeZOa10lf403mW0BTAdjif/ni3QaWl0R4I/t3gkO X-Received: by 2002:a5d:670e:0:b0:314:12c:4322 with SMTP id o14-20020a5d670e000000b00314012c4322mr6737284wru.4.1689418075007; Sat, 15 Jul 2023 03:47:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418074; cv=none; d=google.com; s=arc-20160816; b=xXUnTSN2rqITrOzjHTX44YgCIUT2aRcWquQrdw+HOFe2oaNup9MMmjd5r9RcrVWdfF rtWnf12Nf9YAxX/tQleVD/ozX2MuSEi7IIU2t0DUMTN+xR4boFbHQy6nF/FFLrIIyRYF 2A4GfkfDdTs0R8Rm5ZjfEHEm6EhRT24d5JKiJa5bTIruU6o9zYvGQb/pKdZ5J+q2w7pl vVCtK1kiSaVo+e5tbHewURcGCZIzT79FCM1sCnwBLvKCIfXfUBatMY4HnyrHwjZxoyh9 1E5t8OmeEOEV2cuGBB7D5XWomW5ZpGeLLsg/uGLwktRJlJ1ku+Aa+t+ik6jfxLnzAhKp OM2Q== 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=vIU3beMfFqF1RpY/zl2fnQgfxmvB3nRQ44w2z98SZSQ=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=ydKJZOJwPQhxfXpQf8+701yajbd/1nyRxgPDiaQxjSAk8ElyrZYqWNmBmokBQ35Lfp YckTDIYS7hdgRrHEG4K40Yz7o/lDjyxCB27w+SpCtSatr6V5DcRZYu/zRJ3uNnwyv7gt iF4vCdp+tVcPNCJ/nIeSFIzcRcYNUyL5nK5TooCVC7E2ZFioJaPgmU4MGjT/fHoyRDfo HFekxFYMTGnd8Z+GggwvUe3+YdVzJcEW3SrKAwZrZ6LGor8fMUxXipuuVdfixuEvoMKa OhAFT6Igb83xmfffok6R+GHlOZ2uDk5UEjkB+L4YB/ZhfFsxldrD8E70Q2wlISjDH4eX 4yHQ== 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 n23-20020a056402515700b0051debd3e95asi10048953edd.146.2023.07.15.03.47.54; Sat, 15 Jul 2023 03:47:54 -0700 (PDT) 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 C327B68C6B5; Sat, 15 Jul 2023 13:46:43 +0300 (EEST) 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 BCFB068C64E for ; Sat, 15 Jul 2023 13:46:32 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id ACBD7240591 for ; Sat, 15 Jul 2023 12:46:30 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id xa0I87MvHvCk for ; Sat, 15 Jul 2023 12:46:30 +0200 (CEST) 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 A6C9E2405EC for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 4362C3A12C9 for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:31 +0200 Message-Id: <20230715104611.17902-7-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/47] fftools/ffmpeg_mux_init: avoid invalid memory access in set_dispositions() 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: IGarmJI06I5q This function assumes AVMEDIA_* are always positive, while in fact it can also handle AVMEDIA_TYPE_UNKNOWN, which is -1. --- fftools/ffmpeg_mux_init.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 03d60f2a19..cc5ec68040 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -2296,8 +2296,9 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o) OutputFile *of = &mux->of; AVFormatContext *ctx = mux->fc; - int nb_streams[AVMEDIA_TYPE_NB] = { 0 }; - int have_default[AVMEDIA_TYPE_NB] = { 0 }; + // indexed by type+1, because AVMEDIA_TYPE_UNKNOWN=-1 + int nb_streams[AVMEDIA_TYPE_NB + 1] = { 0 }; + int have_default[AVMEDIA_TYPE_NB + 1] = { 0 }; int have_manual = 0; int ret = 0; @@ -2311,7 +2312,7 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o) for (int i = 0; i < ctx->nb_streams; i++) { OutputStream *ost = of->streams[i]; - nb_streams[ost->type]++; + nb_streams[ost->type + 1]++; MATCH_PER_STREAM_OPT(disposition, str, dispositions[i], ctx, ost->st); @@ -2321,7 +2322,7 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o) ost->st->disposition = ost->ist->st->disposition; if (ost->st->disposition & AV_DISPOSITION_DEFAULT) - have_default[ost->type] = 1; + have_default[ost->type + 1] = 1; } } @@ -2346,12 +2347,12 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o) OutputStream *ost = of->streams[i]; enum AVMediaType type = ost->type; - if (nb_streams[type] < 2 || have_default[type] || + if (nb_streams[type + 1] < 2 || have_default[type + 1] || ost->st->disposition & AV_DISPOSITION_ATTACHED_PIC) continue; ost->st->disposition |= AV_DISPOSITION_DEFAULT; - have_default[type] = 1; + have_default[type + 1] = 1; } } From patchwork Sat Jul 15 10:45:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42702 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239564pzb; Sat, 15 Jul 2023 03:48:19 -0700 (PDT) X-Google-Smtp-Source: APBJJlHzeWYWWRfgXMZ3/4UGBzg4+o/XOdIKBEhnJbKGSQWmWdc3vE5i/OevsZmdPsVSsmYp/3Bg X-Received: by 2002:a17:907:3d9e:b0:993:eddd:6df4 with SMTP id he30-20020a1709073d9e00b00993eddd6df4mr7422675ejc.10.1689418098825; Sat, 15 Jul 2023 03:48:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418098; cv=none; d=google.com; s=arc-20160816; b=gcm7A5EWZbjnVx/smT7HSnmSrLge4qBY5zu9tSqFLWhBXZ8Re2JsT8ueYNjjMkZhtQ YqMLwpNZiILnM7lJBvTquTTDncjejVWhhqMsd4HtfYi3PwPDcY+dU6tnrMX7GRbONKuH 7/r8hANvbIdxlR0yDkpBOeIgxs7sni8jDo3lz2F8+zY5cnScbpb+L9Ff0pUnC0FBQN36 6OE98zncY5TiaunPFs2OFvk3owqBwVpBfbkcr6Gi7q/9hbMKvYAWvPdqIc46GfayL7kw /hCsyNeBVJIVRYKe6giQ8OzAjDdSN2K8Nf3ivg5hxADy7c3s+9HKebUT3jyCf6x87CkS 467Q== 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=BXBG9O/+l4X3je2LB0520Uok2TPXf4jqlPPAT59vqjU=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=g4cziV3c3hzqizV6NkhLp8tK54BeNQ5a0TwkP+waoGVH2eKM7u7o7aSyU40kIimZjF bSMXNSGdfc92SyHUiEVRHMTGEvEka9dKRy4RhOqBsBRnJPNkUIUwETzKCGOciQ7LnNf6 E2rxoDPVQD3Bqzy0vNdH/27zp8la/erfhelbpOWbed9mizQzIL/OypPTjzqg3G1jjEJ6 pSe1zAZxjL2/FLU2/Mlww5XK3H8M6WAsQ2zVzVVAgGaOiY55/YaUFXC6r6983K+k75rF 1/CnnvqZB+Ga1bV6Xfu2ugTqiOwRYN9kWLdW+EwHWs1z7tBE0bS+QvS27ol1ni6eZ05T VWNg== 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 d2-20020a170906344200b009888e599645si10392010ejb.771.2023.07.15.03.48.18; Sat, 15 Jul 2023 03:48:18 -0700 (PDT) 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 940CE68C6D6; Sat, 15 Jul 2023 13:46:46 +0300 (EEST) 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 9DAE868C657 for ; Sat, 15 Jul 2023 13:46:33 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 2E9CE2406CA for ; Sat, 15 Jul 2023 12:46:32 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id A7vGq5DtDyWL for ; Sat, 15 Jul 2023 12:46:29 +0200 (CEST) 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 9D32F2405B5 for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 4E8133A12E0 for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:32 +0200 Message-Id: <20230715104611.17902-8-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/47] fftools/ffmpeg_enc: return errors from enc_frame() instead of aborting 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: SwpzZUVaoygs --- fftools/ffmpeg.h | 2 +- fftools/ffmpeg_enc.c | 6 ++++-- fftools/ffmpeg_filter.c | 12 +++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 0189bee0f3..38f2b1ef66 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -815,7 +815,7 @@ void enc_free(Encoder **penc); int enc_open(OutputStream *ost, AVFrame *frame); int enc_subtitle(OutputFile *of, OutputStream *ost, const AVSubtitle *sub); -void enc_frame(OutputStream *ost, AVFrame *frame); +int enc_frame(OutputStream *ost, AVFrame *frame); void enc_flush(void); /* diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 1489b2f179..6130e3e221 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -1133,17 +1133,19 @@ static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame) av_frame_move_ref(e->last_frame, frame); } -void enc_frame(OutputStream *ost, AVFrame *frame) +int enc_frame(OutputStream *ost, AVFrame *frame) { OutputFile *of = output_files[ost->file_index]; int ret; ret = enc_open(ost, frame); if (ret < 0) - exit_program(1); + return ret; if (ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO) do_video_out(of, ost, frame); else do_audio_out(of, ost, frame); + + return 0; } void enc_flush(void) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 49e0800e6e..d373d8c002 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1722,8 +1722,11 @@ int reap_filters(FilterGraph *fg, int flush) av_log(fgp, AV_LOG_WARNING, "Error in av_buffersink_get_frame_flags(): %s\n", av_err2str(ret)); } else if (flush && ret == AVERROR_EOF && ofp->got_frame && - av_buffersink_get_type(filter) == AVMEDIA_TYPE_VIDEO) - enc_frame(ost, NULL); + av_buffersink_get_type(filter) == AVMEDIA_TYPE_VIDEO) { + ret = enc_frame(ost, NULL); + if (ret < 0) + return ret; + } break; } @@ -1759,8 +1762,11 @@ int reap_filters(FilterGraph *fg, int flush) if (ost->type == AVMEDIA_TYPE_VIDEO) fd->frame_rate_filter = av_buffersink_get_frame_rate(filter); - enc_frame(ost, filtered_frame); + ret = enc_frame(ost, filtered_frame); av_frame_unref(filtered_frame); + if (ret < 0) + return ret; + ofp->got_frame = 1; } } From patchwork Sat Jul 15 10:45:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42715 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4240042pzb; Sat, 15 Jul 2023 03:49:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlFq/11Bkc3EP53dZ8WTv025PBdbawRhpDCu8CN60/1S+a8mtU0Z3o6B8WLmiOcKe7ZPu2ri X-Received: by 2002:a17:907:3c0e:b0:992:ef60:aae0 with SMTP id gh14-20020a1709073c0e00b00992ef60aae0mr6367636ejc.54.1689418188412; Sat, 15 Jul 2023 03:49:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418188; cv=none; d=google.com; s=arc-20160816; b=GMjJy6VdWLS86FdaiZgHNCCKVAoGLOsLryV0xuOohW712L2HY4XOQekTLQjRBlyv6c 8pv1s+ZdorcGSe6EoWjvgvnoPiwWd38hlTULnOJ8Xu4dqDDt3Df7NjtMfh8a9j8GD77Z Uu0Ml/tXYanbDZmeNuN2edxoEzaNc4jVlIejMebZlLK5fEthWQcabGj1r9hDKubwKUqo IZaKyUqeNOxVrTuanxGBo2o3ibWKYXtmWkYc2/VcaI1nsYxvUY5+ilpf9/7nkw3T1S6u 0JD5q7IOhAVibUWNb1Gueft2gjQq/oa+p5fIPvJgq1ZgPjIog76/HOXZszzMRyMLmxYj UcKQ== 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=8FWkkPoin67hHgbJSYr3Au1y4CxOiLzcMIFYmkCQn2k=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=h/G6F0xNGmXJWvS6ZIDECcKaFDnmHF+pkBcjwIAZr+/M/QRnZEhCvlEcq8c7rV/2DW hY3aJh+IKyC4Jt7V3vVBlNAouHWrCN15howqS1akGpVCkKbz54RhMcnnZvTBkYurQRxd j8SokL1uZ85KBryEaNOtv7bQ/gy17qS86Hv2VdA+1MZopfCSGARh+uhjEk0RO2cBHEw2 EJKNpxKfbk1bvidAQf0V41bOsbvkirEajEZY/vfxurRS0H5VS5SEAWxfG+TW3FkjHsKC //itfi8tNycLJ+xLf4kMv3xORuj9m5BFBluR/+leptbW5mD57wvBXIoV/iPvJxHC9KTo +vpg== 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 ss2-20020a170907038200b00992f654b2d7si9954396ejb.723.2023.07.15.03.49.48; Sat, 15 Jul 2023 03:49:48 -0700 (PDT) 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 0F44568C71A; Sat, 15 Jul 2023 13:46:58 +0300 (EEST) 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 2874A68C6A3 for ; Sat, 15 Jul 2023 13:46:36 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id E61D62404F5 for ; Sat, 15 Jul 2023 12:46:35 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id GUZq6yuWHFE8 for ; Sat, 15 Jul 2023 12:46:34 +0200 (CEST) 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 DBE2D240705 for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 5A28E3A12EC for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:33 +0200 Message-Id: <20230715104611.17902-9-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/47] fftools/ffmpeg_enc: return errors from enc_open() instead of aborting 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: D8itacryntyW --- fftools/ffmpeg_enc.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 6130e3e221..f84641b1c4 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -165,19 +165,19 @@ static int hw_device_setup_for_encode(OutputStream *ost, AVBufferRef *frames_ref return 0; } -static void set_encoder_id(OutputFile *of, OutputStream *ost) +static int set_encoder_id(OutputFile *of, OutputStream *ost) { const char *cname = ost->enc_ctx->codec->name; uint8_t *encoder_string; int encoder_string_len; if (av_dict_get(ost->st->metadata, "encoder", NULL, 0)) - return; + return 0; encoder_string_len = sizeof(LIBAVCODEC_IDENT) + strlen(cname) + 2; encoder_string = av_mallocz(encoder_string_len); if (!encoder_string) - report_and_exit(AVERROR(ENOMEM)); + return AVERROR(ENOMEM); if (!of->bitexact && !ost->bitexact) av_strlcpy(encoder_string, LIBAVCODEC_IDENT " ", encoder_string_len); @@ -186,6 +186,8 @@ static void set_encoder_id(OutputFile *of, OutputStream *ost) av_strlcat(encoder_string, cname, encoder_string_len); av_dict_set(&ost->st->metadata, "encoder", encoder_string, AV_DICT_DONT_STRDUP_VAL | AV_DICT_DONT_OVERWRITE); + + return 0; } int enc_open(OutputStream *ost, AVFrame *frame) @@ -211,7 +213,9 @@ int enc_open(OutputStream *ost, AVFrame *frame) return AVERROR(ENOMEM); } - set_encoder_id(output_files[ost->file_index], ost); + ret = set_encoder_id(output_files[ost->file_index], ost); + if (ret < 0) + return ret; if (ist) { dec_ctx = ist->dec_ctx; @@ -417,7 +421,7 @@ int enc_open(OutputStream *ost, AVFrame *frame) if (ret < 0) { av_log(ost, AV_LOG_FATAL, "Error initializing the output stream codec context.\n"); - exit_program(1); + return ret; } if (ost->enc_ctx->nb_coded_side_data) { From patchwork Sat Jul 15 10:45:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42705 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239680pzb; Sat, 15 Jul 2023 03:48:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlH7rAAfv0Q/uYFlkboEOjKh2RITgn+QC1YvvgoKkFfHIpr5UnkAICu/7U4RA5YCznygPKzn X-Received: by 2002:a17:906:fad4:b0:993:d8a2:380 with SMTP id lu20-20020a170906fad400b00993d8a20380mr6269769ejb.21.1689418122651; Sat, 15 Jul 2023 03:48:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418122; cv=none; d=google.com; s=arc-20160816; b=NmR+/SmYXAm310NLDzWbgvF4QQEecT4p5OpXrwJhsF1TuIFTGMsk1HiPHvyF97rz8u +fmItg2GtILqouZLefOksig9opPO2huwB4ziStnZhcHVWCS/2VsWD91ImJBstBMjD7P2 lkDU54A8AA3RdnOFZEAzTD0UiLJEM3nHouQELPs3wjEPY9jlE2ItDtT1T7V4edoRlwKy Ws0aImgd9AUpdtzSzmjaxnmBU/NXcOTcq8bJa+dAXNmPNYSY3mvA1QQ6YKUrFuGcZnVz PxLuQ8hoWc52qJLYugv2dKbtruWsjQSeNTv1+p1ijwi8/oaqnMSDTNYdlac2TvRSC0N8 PU8Q== 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=/9iREn0APvQG4VQveYa2gLYDLIQZrRAk7fceUO/97+Q=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=s3j1PcDe7JMEj+HEhS5x8Ouvmc0XX5gNE6i56rF7KKohc0p7RcJFzLiM9wJngY6dv4 HEWYH7MoF4vjKMdC/GMLgo/OwMxMWcKj1eAmyxh1rf8DZbuCQrXjxV/HaxwxCr3BaLbU H6NbPNjQarAiFlCzKET0so4YZEO1vhnQLlLdIeE7ZSxXffDMQvK2jMFuMstC49hqN0U0 5BzRibijELNTFX8Ypac5zvcIuftkuPsK/qYodPqVaFztxca7rwtzpaSdJKSdfIyqliub qrg7qH5ecbip+cJ1RytPGCyh+dUjHDTA3jz9MAXEV2BgUJ2oOmVWAqAvisGGEY5z6Nsb cY0Q== 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 x24-20020a170906b09800b009885e680300si9834718ejy.266.2023.07.15.03.48.42; Sat, 15 Jul 2023 03:48:42 -0700 (PDT) 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 6FCEE68C6FF; Sat, 15 Jul 2023 13:46:49 +0300 (EEST) 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 4AC9268C66A for ; Sat, 15 Jul 2023 13:46:34 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 449D62406CB for ; Sat, 15 Jul 2023 12:46:33 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Yz0B7w37aEnK for ; Sat, 15 Jul 2023 12:46:31 +0200 (CEST) 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 A6FA22405F9 for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 65C003A142E for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:34 +0200 Message-Id: <20230715104611.17902-10-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/47] fftools/ffmpeg_enc: return errors from do_*_out() instead of aborting 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: yRRjAvsjleD3 --- fftools/ffmpeg_enc.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index f84641b1c4..72ba56a03d 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -839,8 +839,8 @@ static int submit_encode_frame(OutputFile *of, OutputStream *ost, } } -static void do_audio_out(OutputFile *of, OutputStream *ost, - AVFrame *frame) +static int do_audio_out(OutputFile *of, OutputStream *ost, + AVFrame *frame) { Encoder *e = ost->enc; AVCodecContext *enc = ost->enc_ctx; @@ -850,7 +850,7 @@ static void do_audio_out(OutputFile *of, OutputStream *ost, enc->ch_layout.nb_channels != frame->ch_layout.nb_channels) { av_log(ost, AV_LOG_ERROR, "Audio channel count changed and encoder does not support parameter changes\n"); - return; + return 0; } if (frame->pts == AV_NOPTS_VALUE) @@ -866,13 +866,12 @@ static void do_audio_out(OutputFile *of, OutputStream *ost, enc->time_base); if (!check_recording_time(ost, frame->pts, frame->time_base)) - return; + return 0; e->next_pts = frame->pts + frame->nb_samples; ret = submit_encode_frame(of, ost, frame); - if (ret < 0 && ret != AVERROR_EOF) - exit_program(1); + return (ret < 0 && ret != AVERROR_EOF) ? ret : 0; } static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost, @@ -1059,7 +1058,7 @@ force_keyframe: } /* May modify/reset frame */ -static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame) +static int do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame) { int ret; Encoder *e = ost->enc; @@ -1090,7 +1089,7 @@ static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame) if (nb_frames > dts_error_threshold * 30) { av_log(ost, AV_LOG_ERROR, "%"PRId64" frame duplication too large, skipping\n", nb_frames - 1); ost->nb_frames_drop++; - return; + return 0; } ost->nb_frames_dup += nb_frames - (nb_frames_prev && ost->last_dropped) - (nb_frames > nb_frames_prev); av_log(ost, AV_LOG_VERBOSE, "*** %"PRId64" dup!\n", nb_frames - 1); @@ -1112,12 +1111,12 @@ static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame) in_picture = frame; if (!in_picture) - return; + return 0; in_picture->pts = e->next_pts; if (!check_recording_time(ost, in_picture->pts, ost->enc_ctx->time_base)) - return; + return 0; in_picture->quality = enc->global_quality; in_picture->pict_type = forced_kf_apply(ost, &ost->kf, enc->time_base, in_picture, i); @@ -1126,7 +1125,7 @@ static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame) if (ret == AVERROR_EOF) break; else if (ret < 0) - exit_program(1); + return ret; e->next_pts++; e->vsync_frame_number++; @@ -1135,6 +1134,8 @@ static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame) av_frame_unref(e->last_frame); if (frame) av_frame_move_ref(e->last_frame, frame); + + return 0; } int enc_frame(OutputStream *ost, AVFrame *frame) @@ -1146,10 +1147,8 @@ int enc_frame(OutputStream *ost, AVFrame *frame) if (ret < 0) return ret; - if (ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO) do_video_out(of, ost, frame); - else do_audio_out(of, ost, frame); - - return 0; + return ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO ? + do_video_out(of, ost, frame) : do_audio_out(of, ost, frame); } void enc_flush(void) From patchwork Sat Jul 15 10:45:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42700 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239491pzb; Sat, 15 Jul 2023 03:48:03 -0700 (PDT) X-Google-Smtp-Source: APBJJlE8H2XoNXV/bv8UetMRjFrNge+GvY6NT5hmyz8qdukqyJqw1kyoEtdxAyDAvicKoRZDMzrU X-Received: by 2002:a05:6402:3451:b0:51e:1af0:3a90 with SMTP id l17-20020a056402345100b0051e1af03a90mr6170053edc.37.1689418082950; Sat, 15 Jul 2023 03:48:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418082; cv=none; d=google.com; s=arc-20160816; b=e208gHM4CuPPTMeHtrEIkaHZwGk1FSUQJU4KNqaoRXd16Kd7Jb8t8sMAzQcC7mHorY PUTnelTjAqSTKbppIViqOv/m3ESq29Osg7UMPdieAaRFKNz0Gubhx5ybhXfN01KvtslG bFdfbu7K/LYQb4ct0YzIQ/idrY6HqoVqjcBgSFwiza0K6BVa7o1h6vBGAihqnCznaI4K gPgDYfa5+qoZHTw5L4Eqb2CfeXRpthnT2pUq6SCnnvzSfCgT74oUuHPSN/nRL9E/bN+n 0RL2p4TvoQZlUqwfoXv8n+9ad1AJRWuzvGs0Y179cY46vqR9TtByjQV7PeN0MzlYHbzF hFKQ== 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=jjK9ueX0i0G4LyxHiuKrFFPqeP/d6w4p6NS+PkTbY8E=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=cUdrT7LxtRzX8/i26trJXDsTcLhUb1+ftu7tStqOyhY8SngPqr+0tAO0zaZ2SOBP6C b2t4iX+KWwPHDpL4/a7Tofj7qUyRGqGq4+HPcx296rrs+agbFleSeitWdpRrtEbjrCm/ yIGPUER9Mqs8OVUhFntEYHoYpiZhnRZi+e3t5wJOJRhXUDYWLYqQU4OEOFwy3Pt0C+pO NBFgjZKfJslJYm1oA9K5Mwp9AVQiNH0eDvaxUJXD7TPCWmKYKkqF5ziS4fZYzz3yT6aq m9++aInSc3f0NYRETUu0JEswSZSDxnfdq7KMbGoapQ5dWHnVi5fRatSpI0yILvcmkFBo 1krA== 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 l24-20020aa7d958000000b0051de00fc4f2si10612711eds.179.2023.07.15.03.48.02; Sat, 15 Jul 2023 03:48:02 -0700 (PDT) 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 B56DC68C6C9; Sat, 15 Jul 2023 13:46:44 +0300 (EEST) 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 947C668C654 for ; Sat, 15 Jul 2023 13:46:33 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 5C5612405EC for ; Sat, 15 Jul 2023 12:46:31 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id vF9E0sBCe1QD for ; Sat, 15 Jul 2023 12:46:30 +0200 (CEST) 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 A73C02406CA for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 716E33A1531 for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:35 +0200 Message-Id: <20230715104611.17902-11-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/47] fftools/ffmpeg_enc: return errors from enc_flush() instead of aborting 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: PDz8p+MEi3Wu --- fftools/ffmpeg.c | 2 +- fftools/ffmpeg.h | 2 +- fftools/ffmpeg_enc.c | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 27c4e7ef26..926fdea23a 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1250,7 +1250,7 @@ static int transcode(int *err_rate_exceeded) } else if (err_rate) av_log(ist, AV_LOG_VERBOSE, "Decode error rate %g\n", err_rate); } - enc_flush(); + ret = err_merge(ret, enc_flush()); term_exit(); diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 38f2b1ef66..7329df6607 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -816,7 +816,7 @@ void enc_free(Encoder **penc); int enc_open(OutputStream *ost, AVFrame *frame); int enc_subtitle(OutputFile *of, OutputStream *ost, const AVSubtitle *sub); int enc_frame(OutputStream *ost, AVFrame *frame); -void enc_flush(void); +int enc_flush(void); /* * Initialize muxing state for the given stream, should be called diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 72ba56a03d..728c09dcad 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -1151,7 +1151,7 @@ int enc_frame(OutputStream *ost, AVFrame *frame) do_video_out(of, ost, frame) : do_audio_out(of, ost, frame); } -void enc_flush(void) +int enc_flush(void) { int ret; @@ -1172,6 +1172,8 @@ void enc_flush(void) ret = submit_encode_frame(of, ost, NULL); if (ret != AVERROR_EOF) - exit_program(1); + return ret; } + + return 0; } From patchwork Sat Jul 15 10:45:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42704 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239634pzb; Sat, 15 Jul 2023 03:48:34 -0700 (PDT) X-Google-Smtp-Source: APBJJlGXWzGu6Vcw0ebXQ2/mli2MLRtnsJ2tCMgLXgi9i5f6dfLOBPDT9naiI2qlVHATNEsbjhHj X-Received: by 2002:a17:906:224a:b0:993:d700:8a46 with SMTP id 10-20020a170906224a00b00993d7008a46mr7265810ejr.16.1689418114561; Sat, 15 Jul 2023 03:48:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418114; cv=none; d=google.com; s=arc-20160816; b=Yo/of5q9wImO21BAbbKoQF0DvtdHyBrew+IcCTOG5GJ9uJAtiHq7YY5PEK8oesthhE lD2nFLAyFIdmm5VdR3LifgI/Ym/rs/CTwLeKB96/aGGlLVRy+LRndmLF4KBUmB3qDID4 WxbKJMXFi2VVejaeC/W9g987d93zI7x9hvczJjqk1hNtoTbI2rHoDeXS1x/Pe5Chb3NT 9aJX1HE7UNODabNw1RjfdMD5httk+mn1//3yOnjfRk6e9eAiq29QISay0PGHrqtq1v/Q qhXOmJCTWPiEvSa/3OBKAQhY8EblLyhNtCn6eWkWkihS0buVbpt/Hg1TiuywhVAu+z24 Qq4A== 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=vHpr5nXU6p0fCIWpDK65C2N6a3PmXrylplWcNgoZEf0=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=Khn5qZnSdbCLFcSmjMuZREleA4na5XitRMEgtRwZIUCnQHiB5BHz4kd2ZGjyW6X/bJ W5YAp/lhv8YDv/WVJQ1w82B2SV18ZVMBNYeAfWwzEJNxjhk9bc7HiACGufBlVW22PW18 atgPsip1WofvV58GBXsTB4Y1nnmS7b7toE00H3DjebT2uKmMZZqrGIxjWvb/pBghqOxw SfJlT+fzQkZexkylBq/GFs3SjC27OBPw6ETm3NKZnVgBHIniJuMdytNP7wzcTB9wd1vn rlaRSY4SBt+y3HMyFfXPNp3MvjkwYRf9/qrRyvocgobiHoT62gJ4TIoFaIhu/+kh04zL vLZQ== 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 p7-20020a056402074700b0051dd1c4b760si11066656edy.630.2023.07.15.03.48.34; Sat, 15 Jul 2023 03:48:34 -0700 (PDT) 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 94DC868C6E4; Sat, 15 Jul 2023 13:46:48 +0300 (EEST) 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 484E168C665 for ; Sat, 15 Jul 2023 13:46:34 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id E2A732405B5 for ; Sat, 15 Jul 2023 12:46:32 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id NOHbyd0sN-32 for ; Sat, 15 Jul 2023 12:46:32 +0200 (CEST) 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 ADFFB2406CB for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 7D2D43A15A9 for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:36 +0200 Message-Id: <20230715104611.17902-12-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/47] fftools/ffmpeg_enc: return errors from encode_frame() instead of aborting 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: kRbPQEn3nzh6 --- fftools/ffmpeg_enc.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 728c09dcad..9ca3940b93 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -641,7 +641,7 @@ static inline double psnr(double d) return -10.0 * log10(d); } -static void update_video_stats(OutputStream *ost, const AVPacket *pkt, int write_vstats) +static int update_video_stats(OutputStream *ost, const AVPacket *pkt, int write_vstats) { Encoder *e = ost->enc; const uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS, @@ -663,14 +663,14 @@ static void update_video_stats(OutputStream *ost, const AVPacket *pkt, int write } if (!write_vstats) - return; + return 0; /* this is executed just the first time update_video_stats is called */ if (!vstats_file) { vstats_file = fopen(vstats_filename, "w"); if (!vstats_file) { perror("fopen"); - exit_program(1); + return AVERROR(errno); } } @@ -697,6 +697,8 @@ static void update_video_stats(OutputStream *ost, const AVPacket *pkt, int write fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ", (double)e->data_size / 1024, ti1, bitrate, avg_bitrate); fprintf(vstats_file, "type= %c\n", av_get_picture_type_char(pict_type)); + + return 0; } static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) @@ -738,6 +740,8 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) } while (1) { + av_packet_unref(pkt); + ret = avcodec_receive_packet(enc, pkt); update_benchmark("%s_%s %d.%d", action, type_desc, ost->file_index, ost->index); @@ -759,8 +763,12 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) return ret; } - if (enc->codec_type == AVMEDIA_TYPE_VIDEO) - update_video_stats(ost, pkt, !!vstats_filename); + if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { + ret = update_video_stats(ost, pkt, !!vstats_filename); + if (ret < 0) + return ret; + } + if (ost->enc_stats_post.io) enc_stats_write(ost, &ost->enc_stats_post, NULL, pkt, e->packets_encoded); @@ -779,7 +787,7 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) av_log(NULL, AV_LOG_ERROR, "Subtitle heartbeat logic failed in %s! (%s)\n", __func__, av_err2str(ret)); - exit_program(1); + return ret; } e->data_size += pkt->size; From patchwork Sat Jul 15 10:45:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42714 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239991pzb; Sat, 15 Jul 2023 03:49:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlESW1J+fxiE8vpGCnVFfwYLOshmi2FtMHjdiLFZaWTUWqHzmvVMQXjxVuHsIbx7/Auw3Fdq X-Received: by 2002:a17:906:50e:b0:993:b8b5:489 with SMTP id j14-20020a170906050e00b00993b8b50489mr5438666eja.47.1689418180430; Sat, 15 Jul 2023 03:49:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418180; cv=none; d=google.com; s=arc-20160816; b=ZShKeWkummifl/0wvaU1DqzfDuZJJdF1TeT5n7lw0TvbB8PJz5GhB/sLvSP5Xsot0t dX4D6UvtDfSdZZBeZmH9CEWbMY+DdVEP1401nvIgNrcTbc7zWOKK2WjR7uzx2nH8Z5Rb SbPuHdsAGfyKWFvwtonGWsxyyFzS6+RaAmhBoROG9NWo9Fgx63j6PqECQwR1D8UOPx5o 0FTacaH7Ny7/CwU2lDIJXH4MW1lRIkAUIH56TGfXPteF2raePcEBy3V46A4YWMpraJrv NAuFCyrVoNkYf3yPqrg5Vft3x8tqKWWURvSbmNazBxO17LQ0MptJt1AN394jxoZu/UEh zWPg== 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=WNT6vI+rDbWl761g0qQQcDm/Z0uXb+s5pIHAOKv72gk=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=v8ZuCrKgAD5+7b3sHcelct19kEsDA1tDoDtDqPeULQsVws9p6j9zc5IOh8h8EOsLP1 ggmqFJU58sEUozaQS9MgZFMkQLc8ocx9Je7INct702eFixaNQ1xGFPwNYgqtKhZHnaXJ vS0jDaZk3t8IzLcA+xUu3Gk+ZPVk9zJMthViHSNZa17qOMW57M/fb2Q9DHSKqz9R00SS Y6Lsai8cxZtDKGlQLXi3rQpeCVLNTZUxNUUgoQUC7IFSccs4MF2pSUIZbBK9xOlnAKmN wp+nquhCZxTLvoBzljIWsEfdk2+6O11wqpr1Cr5oRCa+PAhiRnO2Mlg26jKowwCvoCLH Yakg== 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 i13-20020aa7dd0d000000b0051e19aae8d1si10346102edv.378.2023.07.15.03.49.40; Sat, 15 Jul 2023 03:49:40 -0700 (PDT) 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 12D0368C6D5; Sat, 15 Jul 2023 13:46:57 +0300 (EEST) 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 B524968C655 for ; Sat, 15 Jul 2023 13:46:40 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 7C5532404EA for ; Sat, 15 Jul 2023 12:46:40 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id IuolQEIVipy4 for ; Sat, 15 Jul 2023 12:46:39 +0200 (CEST) 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 F1834240D1B for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 88EB23A15FA for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:37 +0200 Message-Id: <20230715104611.17902-13-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/47] fftools/ffmpeg_mux: return errors from of_output_packet() instead of aborting 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: vEC0P5vp31+d --- fftools/ffmpeg.c | 4 +++- fftools/ffmpeg.h | 2 +- fftools/ffmpeg_enc.c | 12 ++++++++---- fftools/ffmpeg_mux.c | 20 +++++++++----------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 926fdea23a..ddb011741a 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1120,7 +1120,9 @@ static int process_input(int file_index) OutputStream *ost = ist->outputs[oidx]; OutputFile *of = output_files[ost->file_index]; close_output_stream(ost); - of_output_packet(of, ost, NULL); + ret = of_output_packet(of, ost, NULL); + if (ret < 0) + return ret; } } diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 7329df6607..62b56a8cd8 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -831,7 +831,7 @@ void of_close(OutputFile **pof); void of_enc_stats_close(void); -void of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt); +int of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt); /** * @param dts predicted packet dts in AV_TIME_BASE_Q diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 9ca3940b93..01e1b0656c 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -563,7 +563,9 @@ int enc_subtitle(OutputFile *of, OutputStream *ost, const AVSubtitle *sub) } pkt->dts = pkt->pts; - of_output_packet(of, ost, pkt); + ret = of_output_packet(of, ost, pkt); + if (ret < 0) + return ret; } return 0; @@ -756,8 +758,8 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) av_assert0(frame); // should never happen during flushing return 0; } else if (ret == AVERROR_EOF) { - of_output_packet(of, ost, NULL); - return ret; + ret = of_output_packet(of, ost, NULL); + return ret < 0 ? ret : AVERROR_EOF; } else if (ret < 0) { av_log(ost, AV_LOG_ERROR, "%s encoding failed\n", type_desc); return ret; @@ -794,7 +796,9 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) e->packets_encoded++; - of_output_packet(of, ost, pkt); + ret = of_output_packet(of, ost, pkt); + if (ret < 0) + return ret; } av_assert0(0); diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index a6cc824496..24cdf00469 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -330,7 +330,7 @@ static int submit_packet(Muxer *mux, AVPacket *pkt, OutputStream *ost) return 0; } -void of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt) +int of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt) { Muxer *mux = mux_from_of(of); MuxStream *ms = ms_from_ost(ost); @@ -359,7 +359,7 @@ void of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt) while (!bsf_eof) { ret = av_bsf_receive_packet(ms->bsf_ctx, ms->bsf_pkt); if (ret == AVERROR(EAGAIN)) - return; + return 0; else if (ret == AVERROR_EOF) bsf_eof = 1; else if (ret < 0) { @@ -377,16 +377,14 @@ void of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt) goto mux_fail; } - return; + return 0; mux_fail: err_msg = "submitting a packet to the muxer"; fail: av_log(ost, AV_LOG_ERROR, "Error %s\n", err_msg); - if (exit_on_error) - exit_program(1); - + return exit_on_error ? ret : 0; } int of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts) @@ -405,10 +403,8 @@ int of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts) pkt = NULL; // EOF: flush output bitstream filters. - if (!pkt) { - of_output_packet(of, ost, NULL); - return 0; - } + if (!pkt) + return of_output_packet(of, ost, NULL); if (!ms->streamcopy_started && !(pkt->flags & AV_PKT_FLAG_KEY) && !ms->copy_initial_nonkeyframes) @@ -461,7 +457,9 @@ int of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts) } } - of_output_packet(of, ost, opkt); + ret = of_output_packet(of, ost, opkt); + if (ret < 0) + return ret; ms->streamcopy_started = 1; From patchwork Sat Jul 15 10:45:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42703 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239595pzb; Sat, 15 Jul 2023 03:48:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlHaVpt8N/WQHFJsg54OMhu5muJeFz9TZ4mwyE/U5fpefRP+g0kSMa2wHKso8IGEbqD6DRB7 X-Received: by 2002:a17:907:4c5:b0:988:d6ca:ea72 with SMTP id vz5-20020a17090704c500b00988d6caea72mr5915415ejb.71.1689418106496; Sat, 15 Jul 2023 03:48:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418106; cv=none; d=google.com; s=arc-20160816; b=r75T2/s4QriSu8+ulU3vdLUpxUaiIXqNWXHF6NrxncOi02Uj4JDTHT3ZCD8wKy1XQy LzyGM4OCfScwPGVeFZQYIt3ff+Fko2/R7kgcl6rTaDXdaniIIaxveDXwtVj5kza5ZxgA toExPILss8QPF5CGArQcnfVpbD3JI2ghtw3/fqjWPy/6CxzsjA6VxT/GhGIG4mmVgtCX 7FIA9nirhOWAmyyyT5PZB8pGaPAbg21AfB80H25FUG1co+0IZCV1LzJjjcN4GwPPW/2w dtp8fXZUNdyOco3Vsy1RalFFRERsqU8mWyyLrVZrqsVLA2qAdo+gnoDJMUkE69WoD+wg arOg== 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=iaAFp+qbFtMiyTIsrSLAb4D7bBkiP2/AXm1RTf3bnI4=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=QVx+i9uB9DBvf9PrcPDJrSInHYPKEmNFYlQ7f68BJO1DrMvW4ogszrrNFjA8z467Uf W8IZJ/xiCg6GtADUwVn+D53LtkoL0pPIvKwL0JaWipBcesCoBPIc+q2wkkuyEStF377D k0mKYKAWo8ITKMpCKmwhynJobqjbN473NbhJhlXtlph/Vja14GXRi0F6U4RdCll0aRxp 8qR+whlt4mvwEu9cxZBXn//BPU0hw7TOjk/7z/sI3iBltssdqfatIFFJpCBqgS5gTQbB nAEVhh+OOo+Hp+67e52Ry3ugJxVugJQuQwgaOFin4rNF6MgbgAPVfWnJnHaHHwWKijWj L+JQ== 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 m23-20020a170906235700b0099381745ba0si10461254eja.156.2023.07.15.03.48.26; Sat, 15 Jul 2023 03:48:26 -0700 (PDT) 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 87A8A68C6DB; Sat, 15 Jul 2023 13:46:47 +0300 (EEST) 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 3CC0168C637 for ; Sat, 15 Jul 2023 13:46:39 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id E2DAB2404EE for ; Sat, 15 Jul 2023 12:46:38 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Uh4VfNCOcW-r for ; Sat, 15 Jul 2023 12:46:38 +0200 (CEST) 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 F19BB240D1C for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 94CC13A1627 for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:38 +0200 Message-Id: <20230715104611.17902-14-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/47] fftools/ffmpeg_dec: return error codes from dec_packet() instead of aborting 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: F91NWpBvMUQa --- fftools/ffmpeg.c | 5 ++++- fftools/ffmpeg_dec.c | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index ddb011741a..b4ea52ac1d 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -814,8 +814,11 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo int eof_reached = 0; int duration_exceeded; - if (ist->decoding_needed) + if (ist->decoding_needed) { ret = dec_packet(ist, pkt, no_eof); + if (ret < 0 && ret != AVERROR_EOF) + return ret; + } if (ret == AVERROR_EOF || (!pkt && !ist->decoding_needed)) eof_reached = 1; diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index 5c1b8888e9..f5f764b6fa 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -816,7 +816,7 @@ finish: } // non-EOF errors here are all fatal if (ret < 0 && ret != AVERROR_EOF) - report_and_exit(ret); + return ret; // signal EOF to our downstreams if (ist->dec->type == AVMEDIA_TYPE_SUBTITLE) @@ -825,7 +825,7 @@ finish: ret = send_filter_eof(ist); if (ret < 0) { av_log(NULL, AV_LOG_FATAL, "Error marking filters as finished\n"); - exit_program(1); + return ret; } } From patchwork Sat Jul 15 10:45:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42710 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239901pzb; Sat, 15 Jul 2023 03:49:25 -0700 (PDT) X-Google-Smtp-Source: APBJJlF6TrCWAfm3fdSRWjNcEJbPihYUg53Pye+xIQiwdstXrp8Gx9zHpXsfQ5f5RzDTr8hLL1X8 X-Received: by 2002:a17:906:104e:b0:988:fb2f:274e with SMTP id j14-20020a170906104e00b00988fb2f274emr6849471ejj.27.1689418165566; Sat, 15 Jul 2023 03:49:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418165; cv=none; d=google.com; s=arc-20160816; b=NNLCvZhEaOP2o9Y58o51p0+4x0fhxgQrHr5uuUqczJYMftjzGMZUTdB3hQAjUSmxuZ nO50n7jkGat4hsjWPlZAwmosch2Iw152HGc8bSvClfwPKO8/7QZvP2yBixRzK5LNcuTK TOJF09KNgJlHKAm+cT5VFR3l7yXNaiUACMh9zSij0R3WTYrxN3m6I44Zohd6X+y5o5Oc UNywdSqw0U9YboFb0/E5Wz/7hOmysoOliwIukzg+YZsEJJ6ecAxAmqqu8+gY5viSno4P vyGoONlk0cdfvqkkhJSprhSfJViBz9rhflrQW/XvtXZzH2zzFNKqjZjpRwT4kAlg+BEa 35Ug== 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=OeZI8lXKkaI3kUJvJn7W+2VQDhAp7aoUnfprE5rcIgg=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=hZM4k9yO8XSt4vDnKL+H+AVrV+dBIu2YE1RiPJXQBRlnEw1mXEjclw0JCRJvA1TDgh R1bRnfgXHXb3BchwlgvD1RQb6zVu+BrCd9KqcdTH/kchomqjA3y6hxc5V3xPxwWm9u9x elwRe5i9VDi6EIjsRhRKoPiYktPlDseqfBZsfJeZqYT9cbJHkKbgTSBVCEgN1U2+rteF cQ8bNqjytGSi/m/J6Ao7hePZSIrmpfwDaF3jiEy0OjP0CZGHQHZ5r0kSEmev8D6P6jbs zP05jxpsJQ3Pltgc+faYYYibqZzfP4PWTzcfzPB3eFQCVnGROTJRV/L12H4/Y6ohPBsN 1Mjg== 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 a6-20020a1709062b0600b0098885a739f2si2224253ejg.657.2023.07.15.03.49.24; Sat, 15 Jul 2023 03:49:25 -0700 (PDT) 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 CBA4268C70F; Sat, 15 Jul 2023 13:46:54 +0300 (EEST) 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 1347768C67A for ; Sat, 15 Jul 2023 13:46:40 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id BE7072404EA for ; Sat, 15 Jul 2023 12:46:39 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id vyLsXfpPtGEy for ; Sat, 15 Jul 2023 12:46:39 +0200 (CEST) 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 01864240D1E for ; Sat, 15 Jul 2023 12:46:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A045A3A1711 for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:39 +0200 Message-Id: <20230715104611.17902-15-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/47] fftools/ffmpeg_dec: drop redundant handling of AVERROR_EXPERIMENTAL 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: 7s/Yd2pVf47Z Normal error handling does the job just as well. --- fftools/ffmpeg_dec.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index f5f764b6fa..62c1baf287 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -1115,9 +1115,6 @@ int dec_open(InputStream *ist) } if ((ret = avcodec_open2(ist->dec_ctx, codec, &ist->decoder_opts)) < 0) { - if (ret == AVERROR_EXPERIMENTAL) - exit_program(1); - av_log(ist, AV_LOG_ERROR, "Error while opening decoder: %s\n", av_err2str(ret)); return ret; From patchwork Sat Jul 15 10:45:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42696 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239305pzb; Sat, 15 Jul 2023 03:47:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlEEylGHF99I+iUVmFeOkI9fiZu3CWwGRadu0hbzZlku3q4K+cWOGITxGd0GttSRjpikyPU7 X-Received: by 2002:a17:906:7a0b:b0:994:522f:3f4a with SMTP id d11-20020a1709067a0b00b00994522f3f4amr3692314ejo.29.1689418050918; Sat, 15 Jul 2023 03:47:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418050; cv=none; d=google.com; s=arc-20160816; b=UqmfwJY/KhbSOLRVKL/9U5Hqd0Wdgs5nVcF53AWSEDLthQ86Vb+2m+akjYyUjtpUCk 1RRwP2SZm+Tc/SRYLuIHiglL+6LsS+8X4MPMt247uz1ZV1CPBfYTEe4Fkb/pbgT5HGaT iYmGkXmjN7WiYu/sKv7QQI6tzihtNuX9CZfQa2SQW2AZ61ymw/ZR9MUbafFEDlp9W/oF jD4HJoskDAPNmUsK54HKCNtz80K7b6diL0lVP5dNOvYN6RPLzFswfYVONZ0HFeJMko2Y I9ObWsao+0eDfuISfILvxgZFR9qAwf5KUF6QUo7vb8IO/G64B4PBAGmeDDxzu0ICA5X0 zOiA== 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=Tk47l0j/g5e6EGokj4EM0wk56rUCK/SUoJNNg3Ij1Ns=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=U0Qj0Efkvse6z5FivpdajsIrDK1xbBDyq7tMlP8vJizDmsuepjwrl6GfBQVMKOAfbg pJTAxK9j95YQSkqqiEJ16v8SNZM16Jl3x0LnICRVVNCda1BS+fdgV7FTeiny2BBQKdpW IGaVSYcOgoHKezLMCk47Kfduj3GCDRvdO0fAIlLdZzq/S1mjcUP7y+J7nUTf/MNOH55u NSvttOGRSr84TkbxMKIj++poJZ+niv27mWY3fj+CIaN2lQrXma5ve4dqisH+AEsPVvbt enPmSStu3KgiHf738hb0LOx+0F/JUqBHM88T1VwS0kQAhSbOeryKuwEczyPNAscrA2WB Xj6A== 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 h2-20020a1709067cc200b00987b0a5f325si9888717ejp.1043.2023.07.15.03.47.30; Sat, 15 Jul 2023 03:47:30 -0700 (PDT) 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 78F5D68C665; Sat, 15 Jul 2023 13:46:40 +0300 (EEST) 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 1DB2B68C5DC for ; Sat, 15 Jul 2023 13:46:35 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id A93072406CC for ; Sat, 15 Jul 2023 12:46:34 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id QHRSghmGZRL0 for ; Sat, 15 Jul 2023 12:46:33 +0200 (CEST) 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 CD4552406CE for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id AC0763A1829 for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:40 +0200 Message-Id: <20230715104611.17902-16-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/47] fftools/ffmpeg_filter: return error codes from ofilter_bind_ost() instead of aborting 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: NO/QLTkahYsG --- fftools/ffmpeg.h | 2 +- fftools/ffmpeg_filter.c | 12 ++++++++---- fftools/ffmpeg_mux_init.c | 4 +++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 62b56a8cd8..d7e16d034f 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -744,7 +744,7 @@ void ifilter_sub2video_heartbeat(InputFilter *ifilter, int64_t pts, AVRational t */ int ifilter_parameters_from_dec(InputFilter *ifilter, const AVCodecContext *dec); -void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost); +int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost); /** * Create a new filtergraph in the global filtergraph list. diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index d373d8c002..cdf5610620 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -624,7 +624,7 @@ static void set_channel_layout(OutputFilterPriv *f, OutputStream *ost) av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels); } -void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost) +int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost) { OutputFilterPriv *ofp = ofp_from_ofilter(ofilter); FilterGraph *fg = ofilter->graph; @@ -699,15 +699,17 @@ void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost) for (int i = 0; i < fg->nb_outputs; i++) if (!fg->outputs[i]->ost) - return; + return 0; ret = configure_filtergraph(fg); if (ret < 0) { av_log(fg, AV_LOG_ERROR, "Error configuring filter graph: %s\n", av_err2str(ret)); - exit_program(1); + return ret; } } + + return 0; } static InputFilter *ifilter_alloc(FilterGraph *fg) @@ -899,7 +901,9 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost, if (ret < 0) return ret; - ofilter_bind_ost(fg->outputs[0], ost); + ret = ofilter_bind_ost(fg->outputs[0], ost); + if (ret < 0) + return ret; return 0; } diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index cc5ec68040..359a5149d4 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1393,7 +1393,9 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) { if (ofilter) { ost->filter = ofilter; - ofilter_bind_ost(ofilter, ost); + ret = ofilter_bind_ost(ofilter, ost); + if (ret < 0) + return ret; } else { ret = init_simple_filtergraph(ost->ist, ost, filters); if (ret < 0) { From patchwork Sat Jul 15 10:45:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42709 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239843pzb; Sat, 15 Jul 2023 03:49:16 -0700 (PDT) X-Google-Smtp-Source: APBJJlHidMh6BbNLIJZJeigRUdKCg8pwg6wVaV/zEvweTh4GFpado8eD1JU3JMnEgULsd86LoITx X-Received: by 2002:aa7:d74f:0:b0:51e:5603:5073 with SMTP id a15-20020aa7d74f000000b0051e56035073mr8184610eds.3.1689418156039; Sat, 15 Jul 2023 03:49:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418156; cv=none; d=google.com; s=arc-20160816; b=Pb34cLKfoRC8K+So7GEiGDQxJMrAj6vcuGFnP8HvD58hjIeH4ahI2VabWyL0MJ3tyU 8X9n6mrKSux60Gyh5ysfXVTzIaoCbtrlRnIoIidGMihOaD9Q9uuxChG42XyVmA7LqRV9 4T/cO+1XGk4+LwTMZPqV4ZWh97A/w69vlScW+eIvNgTAiGx08hJb+Kcn39ZfNULuD8u8 PNF2TFxgvBEhGIxAHw4oeBWFwreutBrOR0TA51b5KJiuF2eFkozewoUx3PQJJ6t/hLwN gQTCvujMY0CPrEtqr54z25OxnfCofl2aH04Uah+pcewyV/CIyUR1ZR/lAanrb4c8laWU fIUQ== 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=KofBYicpFAobtdbKTX/g56Ag/ioPCdjkpIXts9lLye0=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=mR+nH6rpLwq1axe5JBl6X3X1yb+eOypJJDAzuGFRhoVsB4T9+FolTSDQ3pDtDtKCpt XpJ/eG2ub0x5SaURbOSYblx7U1ozkExkO8c5i4OJLUB7rQTz228JXl0eKwyslueQtLCd +TPuEoJl/b5CuFB09w3MtR27FqVK4zefxyKSa/s4ww6z4Ca1NEdJ6CLi0+LFBZTmQJBU ZENOa3baSwh5j09R8dENZIcvtVybLwISezrqOa16Y+kfYBrcpV/bBjK80hlcd2GN6BrI 7nqFAkzrwEQGF6Bp7eqVkAiR5cF1HGMHCa8mKc7BhTtJl8Bei11GnThoBQN9g2kwbIkV OnYQ== 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 j1-20020a50ed01000000b005217bbd1afesi165426eds.381.2023.07.15.03.49.15; Sat, 15 Jul 2023 03:49:16 -0700 (PDT) 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 DC01668C70A; Sat, 15 Jul 2023 13:46:53 +0300 (EEST) 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 C1E8468C67A for ; Sat, 15 Jul 2023 13:46:39 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 84C282404EE for ; Sat, 15 Jul 2023 12:46:39 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id X34I4Oiec1qd for ; Sat, 15 Jul 2023 12:46:38 +0200 (CEST) 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 01742240D1D for ; Sat, 15 Jul 2023 12:46:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B7C563A1889 for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:41 +0200 Message-Id: <20230715104611.17902-17-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/47] fftools/ffmpeg_filter: return error codes from init_input_filter() instead of aborting 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: DNyUVNSzY+VJ --- fftools/ffmpeg_filter.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index cdf5610620..79e034d248 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -908,7 +908,7 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost, return 0; } -static void init_input_filter(FilterGraph *fg, InputFilter *ifilter) +static int init_input_filter(FilterGraph *fg, InputFilter *ifilter) { FilterGraphPriv *fgp = fgp_from_fg(fg); InputFilterPriv *ifp = ifp_from_ifilter(ifilter); @@ -920,7 +920,7 @@ static void init_input_filter(FilterGraph *fg, InputFilter *ifilter) if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO) { av_log(fg, AV_LOG_FATAL, "Only video and audio filters supported " "currently.\n"); - exit_program(1); + return AVERROR(ENOSYS); } if (ifp->linklabel) { @@ -932,7 +932,7 @@ static void init_input_filter(FilterGraph *fg, InputFilter *ifilter) if (file_idx < 0 || file_idx >= nb_input_files) { av_log(fg, AV_LOG_FATAL, "Invalid file index %d in filtergraph description %s.\n", file_idx, fgp->graph_desc); - exit_program(1); + return AVERROR(EINVAL); } s = input_files[file_idx]->ctx; @@ -950,7 +950,7 @@ static void init_input_filter(FilterGraph *fg, InputFilter *ifilter) if (!st) { av_log(fg, AV_LOG_FATAL, "Stream specifier '%s' in filtergraph description %s " "matches no streams.\n", p, fgp->graph_desc); - exit_program(1); + return AVERROR(EINVAL); } ist = input_files[file_idx]->streams[st->index]; } else { @@ -958,7 +958,7 @@ static void init_input_filter(FilterGraph *fg, InputFilter *ifilter) if (!ist) { av_log(fg, AV_LOG_FATAL, "Cannot find a matching stream for " "unlabeled input pad %s\n", ifilter->name); - exit_program(1); + return AVERROR(EINVAL); } } av_assert0(ist); @@ -968,15 +968,20 @@ static void init_input_filter(FilterGraph *fg, InputFilter *ifilter) av_log(fg, AV_LOG_ERROR, "Error binding an input stream to complex filtergraph input %s.\n", ifilter->name); - exit_program(1); + return ret; } + + return 0; } int init_complex_filtergraph(FilterGraph *fg) { // bind filtergraph inputs to input streams - for (int i = 0; i < fg->nb_inputs; i++) - init_input_filter(fg, fg->inputs[i]); + for (int i = 0; i < fg->nb_inputs; i++) { + int ret = init_input_filter(fg, fg->inputs[i]); + if (ret < 0) + return ret; + } return 0; } From patchwork Sat Jul 15 10:45:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42707 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239764pzb; Sat, 15 Jul 2023 03:48:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlGXMGtcJFHozJBaY9FFOsqQq1E/xzcKFzbE+jU4HD/vmcAOmmf0bwZNy3jNBEwY7ykikMAF X-Received: by 2002:a17:906:39d2:b0:989:3e0d:89fb with SMTP id i18-20020a17090639d200b009893e0d89fbmr5496119eje.45.1689418139488; Sat, 15 Jul 2023 03:48:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418139; cv=none; d=google.com; s=arc-20160816; b=x+V0rImTkOrMjN3wa5qNZT5UkFhIC1X7AmF4yThO6747fopTOOAYV0FQ7mKOim9Av3 Wv0Z2hOatdLEdSgsCid4YHa1qpvM61GfNuuiZTkOns7DkkhZLB5mUfv8MsCfUtF3PNkY NC+Pda60wugraLmFn5CjygmLDqEjmvtBIb9aDXtffhLHuF+KlH4MoOvFNCsUZrjRof2V WNN0DCz53mu5ByxhRaJq6E/p3ZS6G2J0idkhXR1PCkVhhdnkAd5dvzDntWmPNwN3ryob 11mUEdwFQdcnVwfMoOTme92o35lvCt8rkdb5unaFf3Au/Z/Ryf47h2dLMHN8KOvqVE/T APdw== 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=p24SysbxRegoJA2giiQiulqvDL6nKOgGjBVLYF3+uxI=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=Vnqp6vzoGfK0ZvxRYvQ6JtbiC9LHa+/RLEh4LLd7cIUgoBTujSOSKbrtwYMHLA66Oy I1x67aAEBMCqTm/B9XoCMS64RJsdjhjaIxb64o1I3c8byPoQPSQmu9RNoI62GOt1oeQu CWpxL+fzXpiqv8gAlzBAvndCh2nWbmMHZKVTtlz8a96BG5xx8spM2EG/tPv5iWvBYmrN 2Xlf00LE6wEiPYvbY5fOemo2v9eO6nREWxryPy0o9QSLebD+D/HXMZLCrLdj5DW74Osf 2yj7d0pMQBIe4+aaD7+3tPveiQEHWXUNx5fTPeLom2TDj5AILTbbmtA/tuJklodoGrk3 vcPg== 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 va25-20020a17090711d900b009662960f217si2158366ejb.303.2023.07.15.03.48.58; Sat, 15 Jul 2023 03:48:59 -0700 (PDT) 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 6593768C708; Sat, 15 Jul 2023 13:46:51 +0300 (EEST) 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 B0B1768C675 for ; Sat, 15 Jul 2023 13:46:34 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 9F1322404EA for ; Sat, 15 Jul 2023 12:46:33 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 1YLKgGWzqdGX for ; Sat, 15 Jul 2023 12:46:32 +0200 (CEST) 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 C70062406CC for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id C37C23A188A for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:42 +0200 Message-Id: <20230715104611.17902-18-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 18/47] fftools/ffmpeg_filter: replace remaining exit_program() with error codes 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: /gkPZep8M4xm --- fftools/ffmpeg.h | 2 +- fftools/ffmpeg_filter.c | 15 ++++++++++----- fftools/ffmpeg_opt.c | 4 +++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index d7e16d034f..043eb5e6ec 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -717,7 +717,7 @@ const AVCodec *find_codec_or_die(void *logctx, const char *name, enum AVMediaType type, int encoder); int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global); -void check_filter_outputs(void); +int check_filter_outputs(void); int filtergraph_is_simple(const FilterGraph *fg); int init_simple_filtergraph(InputStream *ist, OutputStream *ost, char *graph_desc); diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 79e034d248..ed0df9f320 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1246,7 +1246,7 @@ static int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, { if (!ofilter->ost) { av_log(fg, AV_LOG_FATAL, "Filter %s has an unconnected output\n", ofilter->name); - exit_program(1); + return AVERROR(EINVAL); } switch (avfilter_pad_get_type(out->filter_ctx->output_pads, out->pad_idx)) { @@ -1256,7 +1256,7 @@ static int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, } } -void check_filter_outputs(void) +int check_filter_outputs(void) { int i; for (i = 0; i < nb_filtergraphs; i++) { @@ -1266,10 +1266,12 @@ void check_filter_outputs(void) if (!output->ost) { av_log(filtergraphs[i], AV_LOG_FATAL, "Filter %s has an unconnected output\n", output->name); - exit_program(1); + return AVERROR(EINVAL); } } } + + return 0; } static void sub2video_prepare(InputFilterPriv *ifp) @@ -1570,8 +1572,11 @@ static int configure_filtergraph(FilterGraph *fg) } avfilter_inout_free(&inputs); - for (cur = outputs, i = 0; cur; cur = cur->next, i++) - configure_output_filter(fg, fg->outputs[i], cur); + for (cur = outputs, i = 0; cur; cur = cur->next, i++) { + ret = configure_output_filter(fg, fg->outputs[i], cur); + if (ret < 0) + return ret; + } avfilter_inout_free(&outputs); if (fgp->disable_conversions) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 300f042660..44bf263621 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1301,7 +1301,9 @@ int ffmpeg_parse_options(int argc, char **argv) apply_sync_offsets(); - check_filter_outputs(); + ret = check_filter_outputs(); + if (ret < 0) + goto fail; fail: uninit_parse_context(&octx); From patchwork Sat Jul 15 10:45:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42708 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239795pzb; Sat, 15 Jul 2023 03:49:08 -0700 (PDT) X-Google-Smtp-Source: APBJJlFFq0bJX/FbVeNt1KTKInIfc1MpsD0EPA7tEY1TEgSrOE3ZomnDdX+I6FvB6T3YH2ak8Cwn X-Received: by 2002:a05:6402:524e:b0:51d:cf7b:c9f0 with SMTP id t14-20020a056402524e00b0051dcf7bc9f0mr7145628edd.12.1689418147847; Sat, 15 Jul 2023 03:49:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418147; cv=none; d=google.com; s=arc-20160816; b=hsFR5ilo63hTGdbHzgxRTrIZ4yXpFabYXAc9XlZcUfr3TeRxxywc1zYbDbcOgfwhHL oxTPRa6J7+jkhXjErOHUd6PjXrHDNsMg/dLtfEH0vpd87J8lU9MbgkKfZp9w3DyRYEFV eGYuCQV+cbOxZ31uNnTCLTbfqoGgBgvYEHudA1rak/tC8Km4g/TEU9gtACaU6Y2DcLPv jy1tKSaR5pa+G0xKksVzQWZv3rIileacprLsVRg6LxV7ZdzQkTRUypJdGddupzgG2rRS eQamL+uCadCTNg63bvSAMxJlUF94dmEmw58en5ZQagM6own2kXFp8VRU+WPsoBCNI98j RuCw== 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=dorSthKkU6n3Q6EyhZKXnmCm6zMkCxnI7WvMXndEKbM=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=g3svzbUQdLNFU7uD7LbUkbT23Bifs6M34JnBEl97IRzHGkERAEyl64aMQaIcGKUfjO kjs2TDZsf4HYDFzJhjgdqw+qd5mS3joxVPbDC8pu0PbsS4FqzeCAW/dK52n2e8bhw73F 6rBqxicEc+KdmJdGgPMyLbxjdgRaPfiVbg1gfMbrtnb5W72u5R4T5FZmbRbu72UncDXN Fzlo9TwkWCbv3VLDg9LL0gMWg++BYUHYLhFJN8lyAm/IoOhNKfRLF9ASDk1OP/OgXyn9 TiYSPItqu2Kza2E2zLHsYGP7FUq99LbHOdUQYtA6EzVc3yQT8wcH8o2MI8tmYMqUu8Qy oVUw== 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 q18-20020aa7da92000000b0051e57e864b2si10342364eds.339.2023.07.15.03.49.07; Sat, 15 Jul 2023 03:49:07 -0700 (PDT) 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 B84A168C6EB; Sat, 15 Jul 2023 13:46:52 +0300 (EEST) 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 B5FE768C677 for ; Sat, 15 Jul 2023 13:46:34 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id E25702405F9 for ; Sat, 15 Jul 2023 12:46:33 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id ml-v9YsjGoLR for ; Sat, 15 Jul 2023 12:46:33 +0200 (CEST) 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 C72C72406CD for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id CF6683A1929 for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:43 +0200 Message-Id: <20230715104611.17902-19-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 19/47] fftools/ffmpeg_filter: return error codes from choose_pix_fmts() instead of aborting 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: gSXzKqAiKuX8 --- fftools/ffmpeg_filter.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index ed0df9f320..2a3204121a 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -270,20 +270,20 @@ static void sub2video_update(InputFilterPriv *ifp, int64_t heartbeat_pts, ifp->sub2video.initialize = 0; } -/* May return NULL (no pixel format found), a static string or a string - * backed by the bprint. Nothing has been written to the AVBPrint in case +/* *dst may return be set to NULL (no pixel format found), a static string or a + * string backed by the bprint. Nothing has been written to the AVBPrint in case * NULL is returned. The AVBPrint provided should be clean. */ -static const char *choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint) +static int choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint, + const char **dst) { OutputFilterPriv *ofp = ofp_from_ofilter(ofilter); OutputStream *ost = ofilter->ost; - if (ost->keep_pix_fmt) { - return ofp->format == AV_PIX_FMT_NONE ? NULL : + *dst = NULL; + + if (ost->keep_pix_fmt || ofp->format != AV_PIX_FMT_NONE) { + *dst = ofp->format == AV_PIX_FMT_NONE ? NULL : av_get_pix_fmt_name(ofp->format); - } - if (ofp->format != AV_PIX_FMT_NONE) { - return av_get_pix_fmt_name(ofp->format); } else if (ofp->formats) { const enum AVPixelFormat *p = ofp->formats; @@ -292,10 +292,12 @@ static const char *choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint) av_bprintf(bprint, "%s%c", name, p[1] == AV_PIX_FMT_NONE ? '\0' : '|'); } if (!av_bprint_is_complete(bprint)) - report_and_exit(AVERROR(ENOMEM)); - return bprint->str; - } else - return NULL; + return AVERROR(ENOMEM); + + *dst = bprint->str; + } + + return 0; } /* Define a function for appending a list of allowed formats @@ -1103,7 +1105,11 @@ static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, } av_bprint_init(&bprint, 0, AV_BPRINT_SIZE_UNLIMITED); - if ((pix_fmts = choose_pix_fmts(ofilter, &bprint))) { + ret = choose_pix_fmts(ofilter, &bprint, &pix_fmts); + if (ret < 0) + return ret; + + if (pix_fmts) { AVFilterContext *filter; ret = avfilter_graph_create_filter(&filter, From patchwork Sat Jul 15 10:45:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42723 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4240486pzb; Sat, 15 Jul 2023 03:50:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlGv70H1yR8GLtcRiioa+wkZl78jbRxa+3mirlxOG/tB53+kbYIgwT6z8hPkax3+BP9tkD4X X-Received: by 2002:a17:907:2347:b0:978:8937:19ba with SMTP id we7-20020a170907234700b00978893719bamr6224008ejb.44.1689418258827; Sat, 15 Jul 2023 03:50:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418258; cv=none; d=google.com; s=arc-20160816; b=HuarGDTsAp/lCsUjm4nHWz3fGL4zTXMzxSrvwA481gxb8QU4eGjKUosKlHAojaqXTo SDBaS1zfvb1MxsLk20jOGKr7ctBaU2D5HERHvdBv+PxJQ+cVYAS+4vg84T+enssy+tUD lo7fWENptC1a9YnRRD9sJjmkx1QzAJeomMQP0h381X04resGsfYAXCrgOL5kq+tbyaRZ XUjxBUk9sn1AmhKGSBM4dJ1ZhtW+8BcVaFaBRxSDGC/q8S9vo6Xufj4LupmV0IOdJCb1 OP2uQBBjUAtxvFeyLwsYbv9jpvsZb8b9VkBlXYuRWSgAIikXatDS4XDdw+QPaLAeav7J tO3Q== 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=4YQOckn+M9hPqlo6bIsgXuBZ+fkiMnnrdD8N5QYUFnc=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=UZrydBw2vcAdrXmGVEj+KNRY2F42k2XJ8xPszHwZIhzPEq3Ifu+c413IlZd7zVJOL0 usk6ba53Bkbv2uJYgqxWdm8PGcRDDHf83BoJJ8Acs72oPptEX2ExpxKlHgL4EC1yzNJN Y1uFUl5+vFPoXEguuaYWPTWp5TzYJHJCKIGtV8lx8B97MxWh2V72nA3Qflhrus0mCjdc BW1IM3FvqimJe69AoFnTkGrmClrVy9sS+gOTWzrdP5RucDyX5CZbIA6FaQDDDXn2uTKm Q347Wfh27y3uV5puhZd+JMGD65SOgqFcouAJIVWHEugXisDw7aiqvyHEyWHb9NmDzD5V K1JA== 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 y15-20020a170906448f00b00992e23f0e6asi10761244ejo.822.2023.07.15.03.50.58; Sat, 15 Jul 2023 03:50:58 -0700 (PDT) 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 CF50868C768; Sat, 15 Jul 2023 13:47:08 +0300 (EEST) 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 B532468C6D2 for ; Sat, 15 Jul 2023 13:46:45 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 68AB82404EE for ; Sat, 15 Jul 2023 12:46:45 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id opNmEs_rGBFC for ; Sat, 15 Jul 2023 12:46:44 +0200 (CEST) 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 048B1240D1F for ; Sat, 15 Jul 2023 12:46:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id DAFD33A1A05 for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:44 +0200 Message-Id: <20230715104611.17902-20-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 20/47] fftools/ffmpeg_filter: return error codes from fg_create() instead of aborting 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: wjB3EO4SXyYW --- fftools/ffmpeg.h | 2 +- fftools/ffmpeg_filter.c | 38 ++++++++++++++++++++++---------------- fftools/ffmpeg_opt.c | 8 ++------ 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 043eb5e6ec..ba73dcffdc 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -752,7 +752,7 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost); * @param graph_desc Graph description; an av_malloc()ed string, filtergraph * takes ownership of it. */ -FilterGraph *fg_create(char *graph_desc); +int fg_create(FilterGraph **pfg, char *graph_desc); void fg_free(FilterGraph **pfg); diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 2a3204121a..485154a448 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -538,16 +538,11 @@ static char *describe_filter_link(FilterGraph *fg, AVFilterInOut *inout, int in) AVFilterContext *ctx = inout->filter_ctx; AVFilterPad *pads = in ? ctx->input_pads : ctx->output_pads; int nb_pads = in ? ctx->nb_inputs : ctx->nb_outputs; - char *res; if (nb_pads > 1) - res = av_strdup(ctx->filter->name); - else - res = av_asprintf("%s:%s", ctx->filter->name, - avfilter_pad_get_name(pads, inout->pad_idx)); - if (!res) - report_and_exit(AVERROR(ENOMEM)); - return res; + return av_strdup(ctx->filter->name); + return av_asprintf("%s:%s", ctx->filter->name, + avfilter_pad_get_name(pads, inout->pad_idx)); } static OutputFilter *ofilter_alloc(FilterGraph *fg) @@ -799,7 +794,7 @@ static const AVClass fg_class = { .category = AV_CLASS_CATEGORY_FILTER, }; -FilterGraph *fg_create(char *graph_desc) +int fg_create(FilterGraph **pfg, char *graph_desc) { FilterGraphPriv *fgp = allocate_array_elem(&filtergraphs, sizeof(*fgp), &nb_filtergraphs); FilterGraph *fg = &fgp->fg; @@ -808,6 +803,9 @@ FilterGraph *fg_create(char *graph_desc) AVFilterGraph *graph; int ret = 0; + if (pfg) + *pfg = fg; + fg->class = &fg_class; fg->index = nb_filtergraphs - 1; fgp->graph_desc = graph_desc; @@ -817,13 +815,13 @@ FilterGraph *fg_create(char *graph_desc) fgp->frame = av_frame_alloc(); if (!fgp->frame) - report_and_exit(AVERROR(ENOMEM)); + return AVERROR(ENOMEM); /* this graph is only used for determining the kinds of inputs * and outputs we have, and is discarded on exit from this function */ graph = avfilter_graph_alloc(); if (!graph) - report_and_exit(AVERROR(ENOMEM)); + return AVERROR(ENOMEM);; graph->nb_threads = 1; ret = graph_parse(graph, fgp->graph_desc, &inputs, &outputs, NULL); @@ -840,6 +838,10 @@ FilterGraph *fg_create(char *graph_desc) ifp->type = avfilter_pad_get_type(cur->filter_ctx->input_pads, cur->pad_idx); ifilter->name = describe_filter_link(fg, cur, 1); + if (!ifilter->name) { + ret = AVERROR(ENOMEM); + goto fail; + } } for (AVFilterInOut *cur = outputs; cur; cur = cur->next) { @@ -851,6 +853,10 @@ FilterGraph *fg_create(char *graph_desc) ofilter->type = avfilter_pad_get_type(cur->filter_ctx->output_pads, cur->pad_idx); ofilter->name = describe_filter_link(fg, cur, 0); + if (!ofilter->name) { + ret = AVERROR(ENOMEM); + goto fail; + } } if (!fg->nb_outputs) { @@ -865,9 +871,9 @@ fail: avfilter_graph_free(&graph); if (ret < 0) - report_and_exit(ret); + return ret; - return fg; + return 0; } int init_simple_filtergraph(InputStream *ist, OutputStream *ost, @@ -877,9 +883,9 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost, FilterGraphPriv *fgp; int ret; - fg = fg_create(graph_desc); - if (!fg) - report_and_exit(AVERROR(ENOMEM)); + ret = fg_create(&fg, graph_desc); + if (ret < 0) + return ret; fgp = fgp_from_fg(fg); fgp->is_simple = 1; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 44bf263621..25a1083366 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1112,9 +1112,7 @@ static int opt_filter_complex(void *optctx, const char *opt, const char *arg) if (!graph_desc) return AVERROR(ENOMEM); - fg_create(graph_desc); - - return 0; + return fg_create(NULL, graph_desc); } static int opt_filter_complex_script(void *optctx, const char *opt, const char *arg) @@ -1123,9 +1121,7 @@ static int opt_filter_complex_script(void *optctx, const char *opt, const char * if (!graph_desc) return AVERROR(EINVAL); - fg_create(graph_desc); - - return 0; + return fg_create(NULL, graph_desc); } void show_help_default(const char *opt, const char *arg) From patchwork Sat Jul 15 10:45:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42717 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4240146pzb; Sat, 15 Jul 2023 03:50:04 -0700 (PDT) X-Google-Smtp-Source: APBJJlGSq7C2Ei0BRCJCt1+fpT0+MbXWuIE6QsmAcF+TqdZH/TOvvBwwN25mPtX2X9lcww5NyWKK X-Received: by 2002:a05:6402:164d:b0:51d:e2c4:f94a with SMTP id s13-20020a056402164d00b0051de2c4f94amr6330857edx.20.1689418204229; Sat, 15 Jul 2023 03:50:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418204; cv=none; d=google.com; s=arc-20160816; b=KI4VQr5xn2hjcKYZivOrGM+/11WVwxLeFvM8pRLztcIT+or13Eg86lu2ze0UACfRb+ n8LuldU1WnYSl8N8ALkKIVZrRpRqdEWYosXWRFqb6fckr5im520V3IxxgIm8EG1X2xG1 tF9zBapd51VPGcmrZkO2PIJpcMb2mCazvpQUtY5XryZPuoyusqbGBs0TfT6gbyir5Veh iyyelpLH5z+wFO2hj5O6vLYEdtYNIHSxGSNaX+pl9v90J7ss5alBQTy9/aZyIoN2s6Qk +YK2Qxd2kIteuCyCyURtBI2guvULZIhyqxIW8yUjgRVouQ2oA9K1Tn3Y/oBWMp5cjYWr q4pA== 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=4m3fhR9f8ajJfVBfgR3IbkCBu/EJS7UsiwXDNnIzT08=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=gtV6BAxu6PQe7gI7HarCH10Hs6U4Q7n3T2xL/2VoX+aEh8RdUjMOY85+j1qgwJMz3C ZUKuhp2YzihAN+cIG7e4kqdh3u3GH9OApO1r5Mdoy59Aun+zyM6C9WP7y9a4OEOfP7Yq k9c+uj3IzFgwrS0T5uYEsMMyuBoYXatmgXvQUAViQgVyfbEQ340gLn4hgQvkHbRYZ0qh dkya+9Wm+H7vnHQzeH4LPl7gQQkMgpfoXXp2orrvoZX4UbtL0SjnsANtWw5i2dGQv3aq YyHsIYMe+xVKj2veDka5gtBguyFKnLI+kaVYDd3i0z3Iz1ZRULQuGqQC7mO4NYPkjWhs hiAQ== 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 d15-20020aa7ce0f000000b0051db82d2c02si3663952edv.170.2023.07.15.03.50.03; Sat, 15 Jul 2023 03:50:04 -0700 (PDT) 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 6EF8768C737; Sat, 15 Jul 2023 13:47:01 +0300 (EEST) 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 77F2268C6A6 for ; Sat, 15 Jul 2023 13:46:36 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 3E9492404F8 for ; Sat, 15 Jul 2023 12:46:36 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Z9Estk94icrj for ; Sat, 15 Jul 2023 12:46:35 +0200 (CEST) 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 E33CA240706 for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id E6E0C3A1AF1 for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:45 +0200 Message-Id: <20230715104611.17902-21-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 21/47] fftools/ffmpeg_filter: return error codes from set_channel_layout() instead of aborting 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: nU5N3xpXyl8t --- fftools/ffmpeg_filter.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 485154a448..470d7b1f02 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -583,7 +583,7 @@ static int ifilter_bind_ist(InputFilter *ifilter, InputStream *ist) return 0; } -static void set_channel_layout(OutputFilterPriv *f, OutputStream *ost) +static int set_channel_layout(OutputFilterPriv *f, OutputStream *ost) { const AVCodec *c = ost->enc_ctx->codec; int i, err; @@ -592,8 +592,8 @@ static void set_channel_layout(OutputFilterPriv *f, OutputStream *ost) /* Pass the layout through for all orders but UNSPEC */ err = av_channel_layout_copy(&f->ch_layout, &ost->enc_ctx->ch_layout); if (err < 0) - report_and_exit(AVERROR(ENOMEM)); - return; + return err; + return 0; } /* Requested layout is of order UNSPEC */ @@ -601,7 +601,7 @@ static void set_channel_layout(OutputFilterPriv *f, OutputStream *ost) /* Use the default native layout for the requested amount of channels when the encoder doesn't have a list of supported layouts */ av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels); - return; + return 0; } /* Encoder has a list of supported layouts. Pick the first layout in it with the same amount of channels as the requested layout */ @@ -613,12 +613,14 @@ static void set_channel_layout(OutputFilterPriv *f, OutputStream *ost) /* Use it if one is found */ err = av_channel_layout_copy(&f->ch_layout, &c->ch_layouts[i]); if (err < 0) - report_and_exit(AVERROR(ENOMEM)); - return; + return err; + return 0; } /* If no layout for the amount of channels requested was found, use the default native layout for it. */ av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels); + + return 0; } int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost) @@ -682,7 +684,9 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost) ofp->sample_rates = c->supported_samplerates; } if (ost->enc_ctx->ch_layout.nb_channels) { - set_channel_layout(ofp, ost); + int ret = set_channel_layout(ofp, ost); + if (ret < 0) + return ret; } else if (c->ch_layouts) { ofp->ch_layouts = c->ch_layouts; } From patchwork Sat Jul 15 10:45:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42695 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239269pzb; Sat, 15 Jul 2023 03:47:23 -0700 (PDT) X-Google-Smtp-Source: APBJJlErYfAjo6eFpSSsH13sVULNRlYvFw0EsWHZKLhK49nPAsQUHycMsaH4ljqTV2maLdqCvgkE X-Received: by 2002:a17:906:c06:b0:98e:3cef:68ff with SMTP id s6-20020a1709060c0600b0098e3cef68ffmr5572196ejf.43.1689418043217; Sat, 15 Jul 2023 03:47:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418043; cv=none; d=google.com; s=arc-20160816; b=r92DrGGjBzAr4cCzyYCkNQMKJxl99Ry81vEGTuRNIsioGJ7Lcy255pZ8o1Ep2W4bYZ NY0fplGmJ+U3PWGRSgyAyh02Fiwq2T63VI7p4En1UQXowUu3kQXg7ADXIxlZEKbhg5mn ZY1L2F19aT0boZDzdD8gaad545Geuq8kFwtcBIZQXoWVZywd8GEYutg+HLXGLiYuNkhM FxMtOvdtM9Y7seilBjgIKIiAuurvcntdDE5HgvWVuG+R9fqZ9YTbLDVaTI8T0otEf1H2 27aqZq4hAsasHSzA+pdi7E9z0ta5kZzZ/B7SOESJBpehGTHHREwlyXICRqZ65aup/dJc xubA== 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=453rznb5xeGo39IKto7xRUDwIn73y7Ik15qelzV0+D4=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=iD6F2Al2CvlTZ3LDurFkQ9TxaKebe/dx3+WDd+PbYEBgqOYdshLH2UffC2CEIRQl/C mLKbetFPoMfrgQrttTM8QT56mA3NXly4e6wxMlSjKNKa1ULZwC5aSltSAQ0M6a5/CAdZ 2v1TAafBtr6nlxbbn3bhW32MCf7u9JUWIm/8EKE1be6XlPg1TmWIB7/SGmrd4/TLehRA e5Akz9nctqXSM6xTtUIZkHVrWgxFr421Xk5J3I0xNNJXfvYBJYbasod9uv20E0TccFjt FUeQOW3WHpK1/jY2NdFkCppoGLORRgKNslsQCyzy4XViVEXXNg0bo/+8D15v1QQk7ZWQ /uDg== 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 op10-20020a170906bcea00b0098cf69d9447si9908314ejb.820.2023.07.15.03.47.22; Sat, 15 Jul 2023 03:47:23 -0700 (PDT) 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 3E77068C647; Sat, 15 Jul 2023 13:46:39 +0300 (EEST) 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 1B39468C530 for ; Sat, 15 Jul 2023 13:46:35 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 394412404F5 for ; Sat, 15 Jul 2023 12:46:34 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id AZPLqxu_4cDu for ; Sat, 15 Jul 2023 12:46:33 +0200 (CEST) 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 D594A2406D0 for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id F2B8A3A1B0D for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:46 +0200 Message-Id: <20230715104611.17902-22-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 22/47] fftools/ffmpeg_filter: replace remaining report_and_exit() with error codes 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: Plnu2uXlZqSz --- fftools/ffmpeg_filter.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 470d7b1f02..26aff9c328 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -723,14 +723,14 @@ static InputFilter *ifilter_alloc(FilterGraph *fg) ifp->frame = av_frame_alloc(); if (!ifp->frame) - report_and_exit(AVERROR(ENOMEM)); + return NULL; ifp->format = -1; ifp->fallback.format = -1; ifp->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW); if (!ifp->frame_queue) - report_and_exit(AVERROR(ENOMEM)); + return NULL; return ifilter; } @@ -1781,7 +1781,7 @@ int reap_filters(FilterGraph *fg, int flush) fd = frame_data(filtered_frame); if (!fd) { av_frame_unref(filtered_frame); - report_and_exit(AVERROR(ENOMEM)); + return AVERROR(ENOMEM); } // only use bits_per_raw_sample passed through from the decoder From patchwork Sat Jul 15 10:45:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42720 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4240304pzb; Sat, 15 Jul 2023 03:50:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlHZnNw934jUzyeJoOPJtFs2+f9NEcMl4oZG7isEv2qCPWVsBF265b5bTuWBd/lKjuUiCrIK X-Received: by 2002:a17:906:2d6:b0:993:e752:1a72 with SMTP id 22-20020a17090602d600b00993e7521a72mr7142878ejk.7.1689418227461; Sat, 15 Jul 2023 03:50:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418227; cv=none; d=google.com; s=arc-20160816; b=UhlxCI4crBAIoSyNzQ4L8VNB6dlFRPEq9AbvDsYRM2fakcM/D8k2yBkjJo9yD8Q32T 0ytZIWoYr2JPVRxSI/Sp/+f63eQZ4oYqpIlJSBw2UIbvHDXEaEELP9PG9TeDXsv4pJuv OKHBboRAcAHyY0KNp8/ew00GYQRP/xrlAljh5x5+pAbdyhuofQn/Kzi0nwCiZMTS8UJP a5gPThm9eeySmPkjUNcEIhrhiDTfpksMvr6pukTzyAwexQ+ogtDZJ3jHvj3gO3DFjJf7 xtYGGJSR1ywlxyk0D/hFz0L8aLuwsp/8Po3x2S/o2fLwXNhcGLCy2FzMzQdlg5bMDmOF A2SQ== 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=Zn4PMd+haDoT8K9Xj03+3/Mwm7Ndh+0MlNjT11oXXBc=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=WGkO0b5FW9ccWXiVmMmP8J31FNj34v7Ap6SXxFoLq+/h5Rud29G/S9DNwMUO4fZ5YD O58YOGbQCeWnW0B4UiQwQ9h0wwnOhNS44M/gMYBwRyeP0f61B0mj2XmgysBV81TQ7BGL zQ3GdCrH4xlmzdhjk2PSLLESgPZ9u125lCbN+nNfqaZxJO7/oqRsiQVEnD3GbHprj+Aa XMwqB3hcrSI8Frc3HWuIn48x3gdN4WC9yjUQxTljZcNYx8w4hPTgDWp8LB4LdVRyKQU0 4ELV2g4CJamcNVeJFAIbS/O6tECt/Qa3P62GLk3xmsHoesOHC7ww/lk5aJn7Xr6YJ8Xk Cjhg== 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 j12-20020a170906094c00b00992d347dc94si10390825ejd.927.2023.07.15.03.50.27; Sat, 15 Jul 2023 03:50:27 -0700 (PDT) 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 761CA68C74E; Sat, 15 Jul 2023 13:47:04 +0300 (EEST) 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 D5E2668C6A5 for ; Sat, 15 Jul 2023 13:46:42 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 9CA562404EA for ; Sat, 15 Jul 2023 12:46:42 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 2b3Myd6F-5s0 for ; Sat, 15 Jul 2023 12:46:40 +0200 (CEST) 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 11779240D22 for ; Sat, 15 Jul 2023 12:46:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 0A32C3A1E19 for ; Sat, 15 Jul 2023 12:46:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:47 +0200 Message-Id: <20230715104611.17902-23-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 23/47] fftools/cmdutils: return error codes from setup_find_stream_info_opts() instead of aborting 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: h2pI0iuHdTGx --- fftools/cmdutils.c | 30 +++++++++++++++++++++--------- fftools/cmdutils.h | 8 +++----- fftools/ffmpeg_demux.c | 6 +++++- fftools/ffplay.c | 6 +++++- fftools/ffprobe.c | 6 +++++- 5 files changed, 39 insertions(+), 17 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 9ec00add30..e2fa08c116 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -645,8 +645,8 @@ static void add_opt(OptionParseContext *octx, const OptionDef *opt, g->opts[g->nb_opts - 1].val = val; } -static void init_parse_context(OptionParseContext *octx, - const OptionGroupDef *groups, int nb_groups) +static int init_parse_context(OptionParseContext *octx, + const OptionGroupDef *groups, int nb_groups) { static const OptionGroupDef global_group = { "global" }; int i; @@ -656,13 +656,15 @@ static void init_parse_context(OptionParseContext *octx, octx->nb_groups = nb_groups; octx->groups = av_calloc(octx->nb_groups, sizeof(*octx->groups)); if (!octx->groups) - report_and_exit(AVERROR(ENOMEM)); + return AVERROR(ENOMEM); for (i = 0; i < octx->nb_groups; i++) octx->groups[i].group_def = &groups[i]; octx->global_opts.group_def = &global_group; octx->global_opts.arg = ""; + + return 0; } void uninit_parse_context(OptionParseContext *octx) @@ -694,13 +696,17 @@ int split_commandline(OptionParseContext *octx, int argc, char *argv[], const OptionDef *options, const OptionGroupDef *groups, int nb_groups) { + int ret; int optindex = 1; int dashdash = -2; /* perform system-dependent conversions for arguments list */ prepare_app_arguments(&argc, &argv); - init_parse_context(octx, groups, nb_groups); + ret = init_parse_context(octx, groups, nb_groups); + if (ret < 0) + return ret; + av_log(NULL, AV_LOG_DEBUG, "Splitting the commandline.\n"); while (optindex < argc) { @@ -950,21 +956,27 @@ AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, return ret; } -AVDictionary **setup_find_stream_info_opts(AVFormatContext *s, - AVDictionary *codec_opts) +int setup_find_stream_info_opts(AVFormatContext *s, + AVDictionary *codec_opts, + AVDictionary ***dst) { int i; AVDictionary **opts; + *dst = NULL; + if (!s->nb_streams) - return NULL; + return 0; + opts = av_calloc(s->nb_streams, sizeof(*opts)); if (!opts) - report_and_exit(AVERROR(ENOMEM)); + return AVERROR(ENOMEM); + for (i = 0; i < s->nb_streams; i++) opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id, s, s->streams[i], NULL); - return opts; + *dst = opts; + return 0; } void *grow_array(void *array, int elem_size, int *size, int new_size) diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index 0115940225..f54f3322ef 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -364,12 +364,10 @@ AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, * contained in s. * Each dictionary will contain the options from codec_opts which can * be applied to the corresponding stream codec context. - * - * @return pointer to the created array of dictionaries. - * Calls exit() on failure. */ -AVDictionary **setup_find_stream_info_opts(AVFormatContext *s, - AVDictionary *codec_opts); +int setup_find_stream_info_opts(AVFormatContext *s, + AVDictionary *codec_opts, + AVDictionary ***dst); /** * Print an error message to stderr, indicating filename and a human diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 9e7f13a2b4..a43c39b843 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -1482,9 +1482,13 @@ int ifile_open(const OptionsContext *o, const char *filename) choose_decoder(o, ic, ic->streams[i], HWACCEL_NONE, AV_HWDEVICE_TYPE_NONE); if (o->find_stream_info) { - AVDictionary **opts = setup_find_stream_info_opts(ic, o->g->codec_opts); + AVDictionary **opts; int orig_nb_streams = ic->nb_streams; + ret = setup_find_stream_info_opts(ic, o->g->codec_opts, &opts); + if (ret < 0) + return ret; + /* If not enough info to get the stream parameters, we decode the first frames to get it. (used in mpeg case for example) */ ret = avformat_find_stream_info(ic, opts); diff --git a/fftools/ffplay.c b/fftools/ffplay.c index 51cde0d208..99700dc6f2 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -2773,9 +2773,13 @@ static int read_thread(void *arg) av_format_inject_global_side_data(ic); if (find_stream_info) { - AVDictionary **opts = setup_find_stream_info_opts(ic, codec_opts); + AVDictionary **opts; int orig_nb_streams = ic->nb_streams; + err = setup_find_stream_info_opts(ic, codec_opts, &opts); + if (err < 0) + report_and_exit(err); + err = avformat_find_stream_info(ic, opts); for (i = 0; i < orig_nb_streams; i++) diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index 1ff76ce809..91a3be660b 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -3372,9 +3372,13 @@ static int open_input_file(InputFile *ifile, const char *filename, av_log(NULL, AV_LOG_WARNING, "Option %s skipped - not known to demuxer.\n", t->key); if (find_stream_info) { - AVDictionary **opts = setup_find_stream_info_opts(fmt_ctx, codec_opts); + AVDictionary **opts; int orig_nb_streams = fmt_ctx->nb_streams; + err = setup_find_stream_info_opts(fmt_ctx, codec_opts, &opts); + if (err < 0) + report_and_exit(err); + err = avformat_find_stream_info(fmt_ctx, opts); for (i = 0; i < orig_nb_streams; i++) From patchwork Sat Jul 15 10:45:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42697 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239361pzb; Sat, 15 Jul 2023 03:47:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlHcOBl/+IqYY1Um83x6ZPlgS56jm4aylMU10fxSpFMjmjEMsjhPls0HL3OaprSgeQNVfODN X-Received: by 2002:a17:906:1695:b0:97e:32e:c1e with SMTP id s21-20020a170906169500b0097e032e0c1emr5772334ejd.55.1689418059070; Sat, 15 Jul 2023 03:47:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418059; cv=none; d=google.com; s=arc-20160816; b=Y3+QO6ygy4Cv4KcIS9P/RWMv2pWKNhjO6QnUIqjGVmPWNjjGrkfbDuFZMZ/Y0vU5Br rrfsh1xAyjSmteAlPOQUK7d+MgwbAlBGtkNoPstFV3WBX55+po9hp7mynUHw06Qc4bfF bek0IezLSDxiPuje0fWXc/UScqPK/RJyQIQWzq71tmVgsr+UEuAUbASvskAoSUPt1tp0 mZozfheVBfh242gBt0G3fMTkZMc8EigUujniWj95BbCXDVsXObLEPE92oP5ZKPS3RM/K JQGA6G50NeTPKly0sTH+jO+57hFuGlOSmf7LIhuRQka+kK3mNEqHH6QCDJHkwExA+wvS w6HA== 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=MqUETsol7fvz6UZbQ2XuoM9lmvi7y5ZRkI84FDqwOuI=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=injiUAXN/4dMkIhCX3DKRGk6UCQpd9mei5D+gOGUAiRbhw+zXmrEAGfnT1nx48xNjH 92Eyhxy4PVlgMGfNhj00OseClNaEJ4fr+/62At8UXAlnbFTEMNJH5nVA5DhCxIjkDgh/ wTuIARaVVZ1fHWi9bV60wx2X3Ely9okDlvN7L7BAIKqx6jikj89+TB6S6JiIxU6hcI4g c/FiGfPd2jGfRDZcvABag0JCnpRfYtnpvaZp2NIaTaQTFJAaJIgI2OVCkNAq+JtdnrJv yANskWa2F8gTO0TLi3hbdltH/SlsLurZlLsBDh4zvoguAyaKcshXXIcFg2YryMhcYmkU VEVA== 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 t7-20020a1709064f0700b009924806cd02si10080254eju.392.2023.07.15.03.47.38; Sat, 15 Jul 2023 03:47:39 -0700 (PDT) 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 8E76E68C6B2; Sat, 15 Jul 2023 13:46:41 +0300 (EEST) 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 C40BB68C589 for ; Sat, 15 Jul 2023 13:46:35 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 845732404F5 for ; Sat, 15 Jul 2023 12:46:35 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id izeb_H0RxNOn for ; Sat, 15 Jul 2023 12:46:34 +0200 (CEST) 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 D13BF2406CF for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 15AEA3A1E4B for ; Sat, 15 Jul 2023 12:46:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:48 +0200 Message-Id: <20230715104611.17902-24-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 24/47] fftools/ffmpeg_opt: reimplement -streamid using a dictionary 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: 8QlKQaRHL70C This does not require an arbitrary limit on the number of streams. Also, return error codes from opt_streamid() instead of aborting. --- fftools/ffmpeg.h | 7 ++----- fftools/ffmpeg_mux_init.c | 18 +++++++++++++++--- fftools/ffmpeg_opt.c | 12 +++++------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index ba73dcffdc..8a94cd7861 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -73,8 +73,6 @@ enum EncTimeBase { ENC_TIME_BASE_FILTER = -2, }; -#define MAX_STREAMS 1024 /* arbitrary sanity check value */ - enum HWAccelID { HWACCEL_NONE = 0, HWACCEL_AUTO, @@ -184,9 +182,8 @@ typedef struct OptionsContext { int subtitle_disable; int data_disable; - /* indexed by output file stream index */ - int *streamid_map; - int nb_streamid_map; + // keys are stream indices + AVDictionary *streamid; SpecifierOpt *metadata; int nb_metadata; diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 359a5149d4..ac4ef328a6 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1111,12 +1111,24 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, if (!st) return AVERROR(ENOMEM); - if (oc->nb_streams - 1 < o->nb_streamid_map) - st->id = o->streamid_map[oc->nb_streams - 1]; - ms = mux_stream_alloc(mux, type); ost = &ms->ost; + if (o->streamid) { + AVDictionaryEntry *e; + char idx[16], *p; + snprintf(idx, sizeof(idx), "%d", ost->index); + + e = av_dict_get(o->streamid, idx, NULL, 0); + if (e) { + st->id = strtol(e->value, &p, 0); + if (!e->value[0] || *p) { + av_log(ost, AV_LOG_FATAL, "Invalid stream id: %s\n", e->value); + return AVERROR(EINVAL); + } + } + } + ost->par_in = avcodec_parameters_alloc(); if (!ost->par_in) return AVERROR(ENOMEM); diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 25a1083366..7002986369 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -128,8 +128,9 @@ static void uninit_options(OptionsContext *o) #if FFMPEG_OPT_MAP_CHANNEL av_freep(&o->audio_channel_maps); #endif - av_freep(&o->streamid_map); av_freep(&o->attachments); + + av_dict_free(&o->streamid); } static void init_options(OptionsContext *o) @@ -727,7 +728,6 @@ char *file_read(const char *filename) static int opt_streamid(void *optctx, const char *opt, const char *arg) { OptionsContext *o = optctx; - int idx; char *p; char idx_str[16]; @@ -737,13 +737,11 @@ static int opt_streamid(void *optctx, const char *opt, const char *arg) av_log(NULL, AV_LOG_FATAL, "Invalid value '%s' for option '%s', required syntax is 'index:value'\n", arg, opt); - exit_program(1); + return AVERROR(EINVAL); } *p++ = '\0'; - idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, MAX_STREAMS-1); - o->streamid_map = grow_array(o->streamid_map, sizeof(*o->streamid_map), &o->nb_streamid_map, idx+1); - o->streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX); - return 0; + + return av_dict_set(&o->streamid, idx_str, p, 0); } static int init_complex_filters(void) From patchwork Sat Jul 15 10:45:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42722 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4240433pzb; Sat, 15 Jul 2023 03:50:51 -0700 (PDT) X-Google-Smtp-Source: APBJJlHv5BlEnT2g8a6eQRKuKoZC0SRbyP04hIZaRH2hoMbkPZyrmpR7TcSzVzYvBP5A9Mq7gFOt X-Received: by 2002:adf:f988:0:b0:313:f505:8211 with SMTP id f8-20020adff988000000b00313f5058211mr7169492wrr.46.1689418250975; Sat, 15 Jul 2023 03:50:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418250; cv=none; d=google.com; s=arc-20160816; b=EOazXQ6NW6PSzpXGhOGx8M+qta90hMYHN29zg/xxnqpshC1MYrP1y5sF+fj+21oL2b Zdo6HWzkgLg3NJYM9bAEMPnSExNhdTOMXD8DsKchCqvtX1k/c7To/mGa6N6Xgvlmx5lb WqzxphxtER7Rm4RMwTb87+qqtcOQ/HFsFb9JO13VKaXM049LiRcW3hrAg0lNgzfZuvEc iRCQIP6c+Io4vXLZmJCOdgeYHHlsO5j1ue4+WyOGnmG4Uljp+rLmRDvlcOhdtVTt8F8A si6M9Qax7MbSAExWvhSf2EAmVC/9WxzdXJCEVUpkJicYeSVK/QbGtvz951K/aE5TakzJ KOgg== 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=ZTjbRFEJXbsxVioT/weO4/6oQ72Z5CAoornRAKQNipA=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=GizZs7ozCM7hDgPVLVWPF5PLcDI4tAMgOXZbfhOERcewObuNFtbXIXhGaEeUSlpwiK s1SE1doKyiyVi9L7rcUCIzn+ZpvejfMPQUeFPyjRBNET0PnSa2U/JrQ1A8AiW/ohZG8F 1H2NFr4IMWsAIgJ/KF0JxY7GZcfQk4WMQ+5zmqV1u755JFnJo6rf5viqMsmITyCw/Nzn TscRTPP73loU9ipTwI24itrUG+SJ9sugGstjcOWaCfv5sKySFsjBga4rme67y6KswWo6 8PyuoVdmIsS7R2QLn/svVK0JQLSK/ZoaDkhuOZALoBHIQ8EvH3ocJS8o+uhCzIWng3kJ 7V9w== 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 r4-20020aa7cb84000000b0051dff4f3c97si10593637edt.132.2023.07.15.03.50.50; Sat, 15 Jul 2023 03:50:50 -0700 (PDT) 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 D3F8768C762; Sat, 15 Jul 2023 13:47:07 +0300 (EEST) 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 B920E68C6CA for ; Sat, 15 Jul 2023 13:46:44 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 7D4562404EE for ; Sat, 15 Jul 2023 12:46:44 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id KFqQYJVCK_uE for ; Sat, 15 Jul 2023 12:46:42 +0200 (CEST) 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 0DBAB240D20 for ; Sat, 15 Jul 2023 12:46:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 215F93A1ED2 for ; Sat, 15 Jul 2023 12:46:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:49 +0200 Message-Id: <20230715104611.17902-25-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 25/47] fftools/cmdutils: drop unused ALLOC_ARRAY_ELEM() 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: tvB/GEzFS0no --- fftools/cmdutils.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index f54f3322ef..decd23040f 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -443,9 +443,6 @@ void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems); #define GROW_ARRAY(array, nb_elems)\ array = grow_array(array, sizeof(*array), &nb_elems, nb_elems + 1) -#define ALLOC_ARRAY_ELEM(array, nb_elems)\ - allocate_array_elem(&array, sizeof(*array[0]), &nb_elems) - #define GET_PIX_FMT_NAME(pix_fmt)\ const char *name = av_get_pix_fmt_name(pix_fmt); From patchwork Sat Jul 15 10:45:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42701 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239517pzb; Sat, 15 Jul 2023 03:48:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlGYDHt/INFgTrqLX+jT/nw/y5an9kp2wOUURzuKSgoVQS+VHIhYVreQbYLcdIeDrUNXbWi4 X-Received: by 2002:a05:6402:2037:b0:51d:9ddf:f0f3 with SMTP id ay23-20020a056402203700b0051d9ddff0f3mr6078358edb.31.1689418091058; Sat, 15 Jul 2023 03:48:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418091; cv=none; d=google.com; s=arc-20160816; b=SArwFfN6jfYxqDp8Dqx37U2wbXo+4nOxP+a4EH03h8lyaJCK+cPliJtvId7gACoqPl uSkvuqJwMSiKNdTYGAMgDbhvbBt1FoLoZgV/7T7o0X6Qa5vqR7DuRvVF5sgdnp/d+ikY xOSo0rCSQbZxxQuE5lPA1zbO1SV/no+mYP6iHQSdT26aQ/+lSW2Kb+UNGq0VCmqJS4JJ i//SnoNZLb2pA3sNcY1JX3/OAO5LpM4v/InpBx+g+fKVyZrvSbyyoThTQWZdJmcRhsjP RH0E/SZ6PIlbPnZO2GWmA5LLLp4EVskTapsWzb8b2wI+ysOelvDZWYBlJ/rqyCOQ2pCf GN3w== 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=Tb8bYR2o532dud7M2uaTcsrHSvGdPLGh75xld/htkq8=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=YGIOK0ASkFBxPxlzD+PLPqkigELSoYqUYvt/mthr0iEjwueBu/o8c+7M8RTgc9uDML vMgRH3hY1qN1PLaNlnOh25NPOBVsvwUBRmWr+ziXzcyUfqy0RlC+i9YBY9bInGsyBQUu 3i1k7rp21qvfEKsJiv/cF7/1AyYGyzmQ/x9SDrCSHMoP82/Qi9XRULDAKUpJnhIDNMev +y8ycKj/C0vtd/29UwyC1UwfHceEhaIj9RHe1hRYivC10m7bAlBULQjIJFRxzWVyfySa 8jdAExk5RmZHXjNyNxT9fyPWBXxIJUAqkGqPJ5XAx/hy+7Hs+eti4+0L+MUVyukz5QOF HxoQ== 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 b21-20020aa7c6d5000000b0051e04e2dbd9si10248767eds.258.2023.07.15.03.48.10; Sat, 15 Jul 2023 03:48:11 -0700 (PDT) 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 96FBD68C6C6; Sat, 15 Jul 2023 13:46:45 +0300 (EEST) 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 960EB68C655 for ; Sat, 15 Jul 2023 13:46:38 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 460F52404EE for ; Sat, 15 Jul 2023 12:46:38 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 1rnS5zzQLxj1 for ; Sat, 15 Jul 2023 12:46:35 +0200 (CEST) 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 E6499240D03 for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 2D2B83A20DF for ; Sat, 15 Jul 2023 12:46:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:50 +0200 Message-Id: <20230715104611.17902-26-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 26/47] fftools/cmdutils: add error handling to allocate_array_elem() 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: l4f/g91cCvKJ --- fftools/cmdutils.c | 2 +- fftools/cmdutils.h | 3 +-- fftools/ffmpeg_demux.c | 16 ++++++++++++++-- fftools/ffmpeg_filter.c | 28 +++++++++++++++++++++------- fftools/ffmpeg_mux_init.c | 16 ++++++++++++++-- 5 files changed, 51 insertions(+), 14 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index e2fa08c116..6c627ee815 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -1002,7 +1002,7 @@ void *allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems) if (!(new_elem = av_mallocz(elem_size)) || av_dynarray_add_nofree(ptr, nb_elems, new_elem) < 0) - report_and_exit(AVERROR(ENOMEM)); + return NULL; return new_elem; } diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index decd23040f..6b9d7f80ae 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -430,13 +430,12 @@ void *grow_array(void *array, int elem_size, int *size, int new_size); * Atomically add a new element to an array of pointers, i.e. allocate * a new entry, reallocate the array of pointers and make the new last * member of this array point to the newly allocated buffer. - * Calls exit() on failure. * * @param array array of pointers to reallocate * @param elem_size size of the new element to allocate * @param nb_elems pointer to the number of elements of the array array; * *nb_elems will be incremented by one by this function. - * @return pointer to the newly allocated entry + * @return pointer to the newly allocated entry or NULL on failure */ void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems); diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index a43c39b843..72b94ea44f 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -1018,8 +1018,11 @@ static DemuxStream *demux_stream_alloc(Demuxer *d, AVStream *st) { const char *type_str = av_get_media_type_string(st->codecpar->codec_type); InputFile *f = &d->f; - DemuxStream *ds = allocate_array_elem(&f->streams, sizeof(*ds), - &f->nb_streams); + DemuxStream *ds; + + ds = allocate_array_elem(&f->streams, sizeof(*ds), &f->nb_streams); + if (!ds) + return NULL; ds->ist.st = st; ds->ist.file_index = f->index; @@ -1051,6 +1054,9 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st) int ret; ds = demux_stream_alloc(d, st); + if (!ds) + return AVERROR(ENOMEM); + ist = &ds->ist; ist->discard = 1; @@ -1328,6 +1334,9 @@ static Demuxer *demux_alloc(void) { Demuxer *d = allocate_array_elem(&input_files, sizeof(*d), &nb_input_files); + if (!d) + return NULL; + d->f.class = &input_file_class; d->f.index = nb_input_files - 1; @@ -1358,6 +1367,9 @@ int ifile_open(const OptionsContext *o, const char *filename) int64_t recording_time = o->recording_time; d = demux_alloc(); + if (!d) + return AVERROR(ENOMEM); + f = &d->f; if (stop_time != INT64_MAX && recording_time != INT64_MAX) { diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 26aff9c328..880d883064 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -550,8 +550,10 @@ static OutputFilter *ofilter_alloc(FilterGraph *fg) OutputFilterPriv *ofp; OutputFilter *ofilter; - ofp = allocate_array_elem(&fg->outputs, sizeof(*ofp), - &fg->nb_outputs); + ofp = allocate_array_elem(&fg->outputs, sizeof(*ofp), &fg->nb_outputs); + if (!ofp) + return NULL; + ofilter = &ofp->ofilter; ofilter->graph = fg; ofp->format = -1; @@ -715,10 +717,14 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost) static InputFilter *ifilter_alloc(FilterGraph *fg) { - InputFilterPriv *ifp = allocate_array_elem(&fg->inputs, sizeof(*ifp), - &fg->nb_inputs); - InputFilter *ifilter = &ifp->ifilter; + InputFilterPriv *ifp; + InputFilter *ifilter; + ifp = allocate_array_elem(&fg->inputs, sizeof(*ifp), &fg->nb_inputs); + if (!ifp) + return NULL; + + ifilter = &ifp->ifilter; ifilter->graph = fg; ifp->frame = av_frame_alloc(); @@ -800,13 +806,18 @@ static const AVClass fg_class = { int fg_create(FilterGraph **pfg, char *graph_desc) { - FilterGraphPriv *fgp = allocate_array_elem(&filtergraphs, sizeof(*fgp), &nb_filtergraphs); - FilterGraph *fg = &fgp->fg; + FilterGraphPriv *fgp; + FilterGraph *fg; AVFilterInOut *inputs, *outputs; AVFilterGraph *graph; int ret = 0; + fgp = allocate_array_elem(&filtergraphs, sizeof(*fgp), &nb_filtergraphs); + if (!fgp) + return AVERROR(ENOMEM); + fg = &fgp->fg; + if (pfg) *pfg = fg; @@ -851,6 +862,9 @@ int fg_create(FilterGraph **pfg, char *graph_desc) for (AVFilterInOut *cur = outputs; cur; cur = cur->next) { OutputFilter *const ofilter = ofilter_alloc(fg); + if (!ofilter) + goto fail; + ofilter->linklabel = cur->name; cur->name = NULL; diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index ac4ef328a6..e714d6cc70 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -414,8 +414,11 @@ static const AVClass output_stream_class = { static MuxStream *mux_stream_alloc(Muxer *mux, enum AVMediaType type) { const char *type_str = av_get_media_type_string(type); - MuxStream *ms = allocate_array_elem(&mux->of.streams, sizeof(*ms), - &mux->of.nb_streams); + MuxStream *ms; + + ms = allocate_array_elem(&mux->of.streams, sizeof(*ms), &mux->of.nb_streams); + if (!ms) + return NULL; ms->ost.file_index = mux->of.index; ms->ost.index = mux->of.nb_streams - 1; @@ -1112,6 +1115,9 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, return AVERROR(ENOMEM); ms = mux_stream_alloc(mux, type); + if (!ms) + return AVERROR(ENOMEM); + ost = &ms->ost; if (o->streamid) { @@ -2568,6 +2574,9 @@ static Muxer *mux_alloc(void) { Muxer *mux = allocate_array_elem(&output_files, sizeof(*mux), &nb_output_files); + if (!mux) + return NULL; + mux->of.class = &output_file_class; mux->of.index = nb_output_files - 1; @@ -2587,6 +2596,9 @@ int of_open(const OptionsContext *o, const char *filename) int64_t stop_time = o->stop_time; mux = mux_alloc(); + if (!mux) + return AVERROR(ENOMEM); + of = &mux->of; if (stop_time != INT64_MAX && recording_time != INT64_MAX) { From patchwork Sat Jul 15 10:45:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42724 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4240542pzb; Sat, 15 Jul 2023 03:51:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlGJ6gBksWuYlgx10CcCIgypZ8f5DX8GnfgmPQBrzxZEZNpf1KugSK1MOyj6OueYD8oYqnA2 X-Received: by 2002:a17:906:a094:b0:98e:419b:4cbc with SMTP id q20-20020a170906a09400b0098e419b4cbcmr5748030ejy.12.1689418266496; Sat, 15 Jul 2023 03:51:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418266; cv=none; d=google.com; s=arc-20160816; b=EhA1frDLomICcG+63rn8ysQU9LSo4HuFSYCioqpMXypK3pf67YBCa1B//DyHULu/Ud ayQRBmLX6QBr9hiFiVRrwppXsujdQi0POwwdraWQCjHqzd1jJzo7cK3CWj28zNEC0EjY myIyplHzgjWmrlINIqhayJMEr03EsbX09V9Xlk6UdP0ishjJZ1eLxLoMcMPCaTlO4Nky 89JgWFBh18xczvuIqpiGn7Zak3MwY8QStFWVQ8cRMerVx/aoVYM9GjW7CqcdkHr811lZ b7en7owKmon0f6DmfwxcetgSMk1Q9JIXTPC/r7FNNzfIc4mLE5zb9o4ryXBQTuAFXTY2 /isg== 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=CEtfk+hgAeZXRzxaqfzMNMkWhvCwoB+NTdriz/Cm/No=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=Jv5FPBhpXEU4GcyBauTTfHLebayZzHeDgB8+Tu8Mvdb/+jzisDg1TlCIHQio5gD1Y1 IcNXDbNlsIHwrvimCk3Pm4sVDoTJrTW9UPDkINTf714Gj8mQkZg92WeqaxpoW4oI+2EB zK13KlL1crYkU4CWS/XvDgZ380URbtusDnken523e62x1zG+6izi+lwFbXql5wIes2/R YycfnZCaNrCW0K/AdyZuk9WHfBQVpD1WlRoCml2zKyXgERENvLlLHlvqUWVTb/99R9BL 5eg+co4tSiTV4jVo22nyui1AhL30L41vzSM7DbWgQ2eX06ng0nVjF5xbg0O6MzgLPi72 WVWQ== 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 ov6-20020a170906fc0600b009938d70d887si9821293ejb.382.2023.07.15.03.51.06; Sat, 15 Jul 2023 03:51:06 -0700 (PDT) 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 B321968C76D; Sat, 15 Jul 2023 13:47:09 +0300 (EEST) 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 81FE668C4F8 for ; Sat, 15 Jul 2023 13:46:46 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 380E52404EE for ; Sat, 15 Jul 2023 12:46:46 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id tYL1-mU1QfA1 for ; Sat, 15 Jul 2023 12:46:45 +0200 (CEST) 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 1B50F240D2A for ; Sat, 15 Jul 2023 12:46:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 38C373A2125 for ; Sat, 15 Jul 2023 12:46:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:51 +0200 Message-Id: <20230715104611.17902-27-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 27/47] fftools/cmdutils: add error handling to grow_array() 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: b8yV1LEgwmA7 --- fftools/cmdutils.c | 19 ++++++++++++------- fftools/cmdutils.h | 14 +++++++++----- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 6c627ee815..63b29c7a3a 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -262,6 +262,7 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt, void *dst = po->flags & (OPT_OFFSET | OPT_SPEC) ? (uint8_t *)optctx + po->u.off : po->u.dst_ptr; int *dstcount; + int ret; if (po->flags & OPT_SPEC) { SpecifierOpt **so = dst; @@ -269,7 +270,10 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt, char *str; dstcount = (int *)(so + 1); - *so = grow_array(*so, sizeof(**so), dstcount, *dstcount + 1); + ret = grow_array((void**)so, sizeof(**so), dstcount, *dstcount + 1); + if (ret < 0) + return ret; + str = av_strdup(p ? p + 1 : ""); if (!str) return AVERROR(ENOMEM); @@ -979,21 +983,22 @@ int setup_find_stream_info_opts(AVFormatContext *s, return 0; } -void *grow_array(void *array, int elem_size, int *size, int new_size) +int grow_array(void **array, int elem_size, int *size, int new_size) { if (new_size >= INT_MAX / elem_size) { av_log(NULL, AV_LOG_ERROR, "Array too big.\n"); - exit_program(1); + return AVERROR(ERANGE); } if (*size < new_size) { - uint8_t *tmp = av_realloc_array(array, new_size, elem_size); + uint8_t *tmp = av_realloc_array(*array, new_size, elem_size); if (!tmp) - report_and_exit(AVERROR(ENOMEM)); + return AVERROR(ENOMEM); memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size); *size = new_size; - return tmp; + *array = tmp; + return 0; } - return array; + return 0; } void *allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems) diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index 6b9d7f80ae..0dfe8b313c 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -416,15 +416,15 @@ FILE *get_preset_file(char *filename, size_t filename_size, /** * Realloc array to hold new_size elements of elem_size. - * Calls exit() on failure. * - * @param array array to reallocate + * @param array pointer to the array to reallocate, will be updated + * with a new pointer on success * @param elem_size size in bytes of each element * @param size new element count will be written here * @param new_size number of elements to place in reallocated array - * @return reallocated array + * @return a non-negative number on success, a negative error code on failure */ -void *grow_array(void *array, int elem_size, int *size, int new_size); +int grow_array(void **array, int elem_size, int *size, int new_size); /** * Atomically add a new element to an array of pointers, i.e. allocate @@ -440,7 +440,11 @@ void *grow_array(void *array, int elem_size, int *size, int new_size); void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems); #define GROW_ARRAY(array, nb_elems)\ - array = grow_array(array, sizeof(*array), &nb_elems, nb_elems + 1) +do { \ + int _ret = grow_array((void**)&array, sizeof(*array), &nb_elems, nb_elems + 1); \ + if (_ret < 0) \ + report_and_exit(_ret); \ +} while (0) #define GET_PIX_FMT_NAME(pix_fmt)\ const char *name = av_get_pix_fmt_name(pix_fmt); From patchwork Sat Jul 15 10:45:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42719 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4240260pzb; Sat, 15 Jul 2023 03:50:19 -0700 (PDT) X-Google-Smtp-Source: APBJJlG7vc5ltRUsUic2eOfwbe9CoYXTjE2BXL//SToiPN6qJeO1AGjVq7x0DwpKBg1XTw9/60x4 X-Received: by 2002:a17:906:eb8a:b0:993:d617:bdc2 with SMTP id mh10-20020a170906eb8a00b00993d617bdc2mr6115102ejb.75.1689418219472; Sat, 15 Jul 2023 03:50:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418219; cv=none; d=google.com; s=arc-20160816; b=Nb7NFSswnHPYpGKgTq+QJiu0Uh8D3vAnJ5oVTGRzM4elIyR8VcHkRVVwZMWolFRzgP jfLFUhEkv1MHU3eH9QMBcmtD1CgV97A0mnzXXjL8V1aW03mNWkhp4RUy5OD7ttIOq5fC ohzTzsdeqDr06OE3tRJCdchEUPoPTDpLpAQoe4Qv7uNOi2dEuhQzYTbLYlxv05/uajXg 7nmyWI1E7RKC0RuH6C2HfF2OpVq1ViXU8U3dij5FKsnqGoYR5TzM5c+avwB0vEQiw5m+ S0TG6r13oXpqTgfUcMKba8kjKnPFoRMlpXe3AEOBg7JRBXYtaaj4Bw3cJoMHWGNyY7+L 55LQ== 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=kQknFiIVW7CkKUGfJVwP3+eCzX6OGwfCM9C7IL0ZqYY=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=V2XrePInD8r8/6DUrxhlkFXBUNPJXnhe5enROwE9EdA90l8slLUzPyo8D/Dwr0IXVP o/ut77F5txq6iXHWbJTk38ca70T0cs0n2j4+sSguGNcnPqjvYS+yR/lELX6oZPjZP+E7 1kwUzXTiZOpNqbPGqMwXTduZEwnqcFDMPheG65JXnF/weYu3yHDiO4uar4bUVkJ0WSwU HV1i6PRRTaGZR0zMs5H86P6yE4XR06QFSLUF2bwxsjt5QxyXMRUzia8u1mIQsIOlU3uQ pZwTPIYZjixCM+hN+/FVoxhy/EZID7Qm0nfN8PfVvF3ySbddWkVuxMGh2MbbwIUV5fB5 xNgQ== 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 w10-20020a1709060a0a00b0098e38b3b7e3si972107ejf.793.2023.07.15.03.50.19; Sat, 15 Jul 2023 03:50:19 -0700 (PDT) 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 6A9E568C747; Sat, 15 Jul 2023 13:47:03 +0300 (EEST) 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 8883B68C6B5 for ; Sat, 15 Jul 2023 13:46:37 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 4C3D42406CC for ; Sat, 15 Jul 2023 12:46:37 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id MEPf8c3zkiiV for ; Sat, 15 Jul 2023 12:46:36 +0200 (CEST) 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 EB251240D0E for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 447333A2169 for ; Sat, 15 Jul 2023 12:46:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:52 +0200 Message-Id: <20230715104611.17902-28-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 28/47] fftools/cmdutils: add error handling to GROW_ARRAY() 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: KKzjdTtmnAwJ --- fftools/cmdutils.c | 44 ++++++++++++++++++++++++++++++--------- fftools/cmdutils.h | 6 +----- fftools/ffmpeg_demux.c | 10 +++++++-- fftools/ffmpeg_mux_init.c | 15 ++++++++++--- fftools/ffmpeg_opt.c | 24 ++++++++++++++++----- fftools/ffplay.c | 5 ++++- 6 files changed, 78 insertions(+), 26 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 63b29c7a3a..fb35245f0a 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -609,13 +609,17 @@ static int match_group_separator(const OptionGroupDef *groups, int nb_groups, * @param group_idx which group definition should this group belong to * @param arg argument of the group delimiting option */ -static void finish_group(OptionParseContext *octx, int group_idx, - const char *arg) +static int finish_group(OptionParseContext *octx, int group_idx, + const char *arg) { OptionGroupList *l = &octx->groups[group_idx]; OptionGroup *g; + int ret; + + ret = GROW_ARRAY(l->groups, l->nb_groups); + if (ret < 0) + return ret; - GROW_ARRAY(l->groups, l->nb_groups); g = &l->groups[l->nb_groups - 1]; *g = octx->cur_group; @@ -632,21 +636,29 @@ static void finish_group(OptionParseContext *octx, int group_idx, swr_opts = NULL; memset(&octx->cur_group, 0, sizeof(octx->cur_group)); + + return ret; } /* * Add an option instance to currently parsed group. */ -static void add_opt(OptionParseContext *octx, const OptionDef *opt, - const char *key, const char *val) +static int add_opt(OptionParseContext *octx, const OptionDef *opt, + const char *key, const char *val) { int global = !(opt->flags & (OPT_PERFILE | OPT_SPEC | OPT_OFFSET)); OptionGroup *g = global ? &octx->global_opts : &octx->cur_group; + int ret; + + ret = GROW_ARRAY(g->opts, g->nb_opts); + if (ret < 0) + return ret; - GROW_ARRAY(g->opts, g->nb_opts); g->opts[g->nb_opts - 1].opt = opt; g->opts[g->nb_opts - 1].key = key; g->opts[g->nb_opts - 1].val = val; + + return 0; } static int init_parse_context(OptionParseContext *octx, @@ -726,7 +738,10 @@ int split_commandline(OptionParseContext *octx, int argc, char *argv[], } /* unnamed group separators, e.g. output filename */ if (opt[0] != '-' || !opt[1] || dashdash+1 == optindex) { - finish_group(octx, 0, opt); + ret = finish_group(octx, 0, opt); + if (ret < 0) + return ret; + av_log(NULL, AV_LOG_DEBUG, " matched as %s.\n", groups[0].name); continue; } @@ -744,7 +759,10 @@ do { \ /* named group separators, e.g. -i */ if ((ret = match_group_separator(groups, nb_groups, opt)) >= 0) { GET_ARG(arg); - finish_group(octx, ret, arg); + ret = finish_group(octx, ret, arg); + if (ret < 0) + return ret; + av_log(NULL, AV_LOG_DEBUG, " matched as %s with argument '%s'.\n", groups[ret].name, arg); continue; @@ -762,7 +780,10 @@ do { \ arg = "1"; } - add_opt(octx, po, opt, arg); + ret = add_opt(octx, po, opt, arg); + if (ret < 0) + return ret; + av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with " "argument '%s'.\n", po->name, po->help, arg); continue; @@ -787,7 +808,10 @@ do { \ if (opt[0] == 'n' && opt[1] == 'o' && (po = find_option(options, opt + 2)) && po->name && po->flags & OPT_BOOL) { - add_opt(octx, po, opt, "0"); + ret = add_opt(octx, po, opt, "0"); + if (ret < 0) + return ret; + av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with " "argument 0.\n", po->name, po->help); continue; diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index 0dfe8b313c..69c2123804 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -440,11 +440,7 @@ int grow_array(void **array, int elem_size, int *size, int new_size); void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems); #define GROW_ARRAY(array, nb_elems)\ -do { \ - int _ret = grow_array((void**)&array, sizeof(*array), &nb_elems, nb_elems + 1); \ - if (_ret < 0) \ - report_and_exit(_ret); \ -} while (0) + grow_array((void**)&array, sizeof(*array), &nb_elems, nb_elems + 1) #define GET_PIX_FMT_NAME(pix_fmt)\ const char *name = av_get_pix_fmt_name(pix_fmt); diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 72b94ea44f..5a41db9b21 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -880,7 +880,10 @@ int ist_output_add(InputStream *ist, OutputStream *ost) if (ret < 0) return ret; - GROW_ARRAY(ist->outputs, ist->nb_outputs); + ret = GROW_ARRAY(ist->outputs, ist->nb_outputs); + if (ret < 0) + return ret; + ist->outputs[ist->nb_outputs - 1] = ost; return 0; @@ -894,7 +897,10 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple) if (ret < 0) return ret; - GROW_ARRAY(ist->filters, ist->nb_filters); + ret = GROW_ARRAY(ist->filters, ist->nb_filters); + if (ret < 0) + return ret; + ist->filters[ist->nb_filters - 1] = ifilter; // initialize fallback parameters for filtering diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index e714d6cc70..cb943ac408 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -209,7 +209,9 @@ static int enc_stats_get_file(AVIOContext **io, const char *path) return 0; } - GROW_ARRAY(enc_stats_files, nb_enc_stats_files); + ret = GROW_ARRAY(enc_stats_files, nb_enc_stats_files); + if (ret < 0) + return ret; esf = &enc_stats_files[nb_enc_stats_files - 1]; @@ -321,7 +323,11 @@ static int enc_stats_init(OutputStream *ost, EncStats *es, int pre, return ret; if (val) { - GROW_ARRAY(es->components, es->nb_components); + ret = GROW_ARRAY(es->components, es->nb_components); + if (ret < 0) { + av_freep(&val); + return ret; + } c = &es->components[es->nb_components - 1]; c->type = ENC_STATS_LITERAL; @@ -352,7 +358,10 @@ static int enc_stats_init(OutputStream *ost, EncStats *es, int pre, } next++; - GROW_ARRAY(es->components, es->nb_components); + ret = GROW_ARRAY(es->components, es->nb_components); + if (ret < 0) + return ret; + c = &es->components[es->nb_components - 1]; for (size_t i = 0; i < FF_ARRAY_ELEMS(fmt_specs); i++) { diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 7002986369..eef6d5e749 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -361,6 +361,7 @@ static int opt_map(void *optctx, const char *opt, const char *arg) OptionsContext *o = optctx; StreamMap *m = NULL; int i, negative = 0, file_idx, disabled = 0; + int ret; #if FFMPEG_OPT_MAP_SYNC char *sync; #endif @@ -387,7 +388,11 @@ static int opt_map(void *optctx, const char *opt, const char *arg) if (map[0] == '[') { /* this mapping refers to lavfi output */ const char *c = map + 1; - GROW_ARRAY(o->stream_maps, o->nb_stream_maps); + + ret = GROW_ARRAY(o->stream_maps, o->nb_stream_maps); + if (ret < 0) + return ret; + m = &o->stream_maps[o->nb_stream_maps - 1]; m->linklabel = av_get_token(&c, "]"); if (!m->linklabel) { @@ -421,7 +426,10 @@ static int opt_map(void *optctx, const char *opt, const char *arg) disabled = 1; continue; } - GROW_ARRAY(o->stream_maps, o->nb_stream_maps); + ret = GROW_ARRAY(o->stream_maps, o->nb_stream_maps); + if (ret < 0) + return ret; + m = &o->stream_maps[o->nb_stream_maps - 1]; m->file_index = file_idx; @@ -450,7 +458,10 @@ static int opt_map(void *optctx, const char *opt, const char *arg) static int opt_attach(void *optctx, const char *opt, const char *arg) { OptionsContext *o = optctx; - GROW_ARRAY(o->attachments, o->nb_attachments); + int ret = GROW_ARRAY(o->attachments, o->nb_attachments); + if (ret < 0) + return ret; + o->attachments[o->nb_attachments - 1] = arg; return 0; } @@ -459,7 +470,7 @@ static int opt_attach(void *optctx, const char *opt, const char *arg) static int opt_map_channel(void *optctx, const char *opt, const char *arg) { OptionsContext *o = optctx; - int n; + int n, ret; AVStream *st; AudioChannelMap *m; char *allow_unused; @@ -474,7 +485,10 @@ static int opt_map_channel(void *optctx, const char *opt, const char *arg) if (!mapchan) return AVERROR(ENOMEM); - GROW_ARRAY(o->audio_channel_maps, o->nb_audio_channel_maps); + ret = GROW_ARRAY(o->audio_channel_maps, o->nb_audio_channel_maps); + if (ret < 0) + return ret; + m = &o->audio_channel_maps[o->nb_audio_channel_maps - 1]; /* muted channel syntax */ diff --git a/fftools/ffplay.c b/fftools/ffplay.c index 99700dc6f2..1f9757d607 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -388,7 +388,10 @@ static const struct TextureFormatEntry { static int opt_add_vfilter(void *optctx, const char *opt, const char *arg) { - GROW_ARRAY(vfilters_list, nb_vfilters); + int ret = GROW_ARRAY(vfilters_list, nb_vfilters); + if (ret < 0) + return ret; + vfilters_list[nb_vfilters - 1] = arg; return 0; } From patchwork Sat Jul 15 10:45:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42706 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239734pzb; Sat, 15 Jul 2023 03:48:51 -0700 (PDT) X-Google-Smtp-Source: APBJJlGijRVoNHEPDsUAiP7YXeIFefrloSoCQ5udYZPrxq774xrFpetL3u0AmJz3ITyREQRlKXVH X-Received: by 2002:a05:6402:b1a:b0:51d:8953:1c89 with SMTP id bm26-20020a0564020b1a00b0051d89531c89mr6784141edb.8.1689418130855; Sat, 15 Jul 2023 03:48:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418130; cv=none; d=google.com; s=arc-20160816; b=ywxx1qqQypGNu9q2Lvq9gycltA3j8lF6UvZFCHoy1KI3LxVrV4fB1Adx2XQO0Q4u9k gG2OjwOoclxCcJ8ofEDyiJ5/WW2n2ACP2IKhhuJWJXa+EPKpizXOaGAPub9JVWX3L94h QZZ4fssdZJTRl5T9tdJpofzbv6gw44B6DT9bPliW7cTJEQSk5+tTHQltD8e2lEALPTMm CpQs8LiyVpC6YsG2FGiifa64L9gzLsFZuCe3fpYzmijGYXtVpFuy1i22DhnTPCxVMqzZ wjuhDVPGn0y/YPADmfjYt/CrlyHsWU4So8ymuPmtdTGwVos3HpTwYwvGtaqNFLUSd9CY thrg== 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=/wpYPhdTFXaxkPy/v1teCLTuBV9RGVekOtbw3h/OZlM=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=z7TpiRUBLArtXmgpBVRy7iKE9hlw9pfbA59U3/fXQysviBpn9vqw81AgXrSxLoSrxi ckPyH+wpS+gNarGRxo/xvUY9QjVFL+rdhEq/oJFhY1mkoMJ65A+kiANJWEY64gg+AA0r dNlZbCQ6EdSzGCQ/77LfyjdsArAs6U8nmyXFMmTT43ga7Z9mLNFHzYWg00cjqHXn6mJb laEt+7TMQMfl3x3q/s/0ANfun/MhviJy+EnFEOhmV29ofF/xPPnZDX4RMDkQY8Z0SEbT BT9EiPJudRxo8tYjhs4g4XmShPJ3F0dDarE9IYE87VxrA4Jc7K3sIjOqEM70ZXBjH9DJ SVPw== 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 j10-20020aa7c40a000000b0051e5c4351absi10131088edq.82.2023.07.15.03.48.50; Sat, 15 Jul 2023 03:48:50 -0700 (PDT) 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 666CA68C701; Sat, 15 Jul 2023 13:46:50 +0300 (EEST) 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 7494868C645 for ; Sat, 15 Jul 2023 13:46:39 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 3A6CC240591 for ; Sat, 15 Jul 2023 12:46:39 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id poYr4Iv-ID8a for ; Sat, 15 Jul 2023 12:46:37 +0200 (CEST) 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 EB99C240D1A for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 4F9143A216F for ; Sat, 15 Jul 2023 12:46:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:53 +0200 Message-Id: <20230715104611.17902-29-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 29/47] fftools/ffmpeg: return errors from find_codec_or_die() instead of aborting 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: 3n5B+jOsT/MY Rename the function to just find_codec(). --- fftools/ffmpeg.h | 4 +-- fftools/ffmpeg_demux.c | 54 +++++++++++++++++++++++++++------------ fftools/ffmpeg_mux_init.c | 4 ++- fftools/ffmpeg_opt.c | 13 ++++++---- 4 files changed, 50 insertions(+), 25 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 8a94cd7861..60dff87436 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -710,8 +710,8 @@ void assert_avoptions(AVDictionary *m); int assert_file_overwrite(const char *filename); char *file_read(const char *filename); AVDictionary *strip_specifiers(const AVDictionary *dict); -const AVCodec *find_codec_or_die(void *logctx, const char *name, - enum AVMediaType type, int encoder); +int find_codec(void *logctx, const char *name, + enum AVMediaType type, int encoder, const AVCodec **codec); int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global); int check_filter_outputs(void); diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 5a41db9b21..a41b59ceb8 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -911,19 +911,22 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple) return 0; } -static const AVCodec *choose_decoder(const OptionsContext *o, AVFormatContext *s, AVStream *st, - enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type) +static int choose_decoder(const OptionsContext *o, AVFormatContext *s, AVStream *st, + enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type, + const AVCodec **pcodec) { char *codec_name = NULL; MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st); if (codec_name) { - const AVCodec *codec = find_codec_or_die(NULL, codec_name, st->codecpar->codec_type, 0); - st->codecpar->codec_id = codec->id; - if (recast_media && st->codecpar->codec_type != codec->type) - st->codecpar->codec_type = codec->type; - return codec; + int ret = find_codec(NULL, codec_name, st->codecpar->codec_type, 0, pcodec); + if (ret < 0) + return ret; + st->codecpar->codec_id = (*pcodec)->id; + if (recast_media && st->codecpar->codec_type != (*pcodec)->type) + st->codecpar->codec_type = (*pcodec)->type; + return 0; } else { if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && hwaccel_id == HWACCEL_GENERIC && @@ -942,13 +945,15 @@ static const AVCodec *choose_decoder(const OptionsContext *o, AVFormatContext *s if (config->device_type == hwaccel_device_type) { av_log(NULL, AV_LOG_VERBOSE, "Selecting decoder '%s' because of requested hwaccel method %s\n", c->name, av_hwdevice_get_type_name(hwaccel_device_type)); - return c; + *pcodec = c; + return 0; } } } } - return avcodec_find_decoder(st->codecpar->codec_id); + *pcodec = avcodec_find_decoder(st->codecpar->codec_id); + return 0; } } @@ -1166,7 +1171,11 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st) } } - ist->dec = choose_decoder(o, ic, st, ist->hwaccel_id, ist->hwaccel_device_type); + ret = choose_decoder(o, ic, st, ist->hwaccel_id, ist->hwaccel_device_type, + &ist->dec); + if (ret < 0) + return ret; + ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id, ic, st, ist->dec); ist->reinit_filters = -1; @@ -1357,7 +1366,7 @@ int ifile_open(const OptionsContext *o, const char *filename) InputFile *f; AVFormatContext *ic; const AVInputFormat *file_iformat = NULL; - int err, i, ret; + int err, i, ret = 0; int64_t timestamp; AVDictionary *unused_opts = NULL; const AVDictionaryEntry *e = NULL; @@ -1455,13 +1464,19 @@ int ifile_open(const OptionsContext *o, const char *filename) MATCH_PER_TYPE_OPT(codec_names, str, data_codec_name, ic, "d"); if (video_codec_name) - ic->video_codec = find_codec_or_die(NULL, video_codec_name , AVMEDIA_TYPE_VIDEO , 0); + ret = err_merge(ret, find_codec(NULL, video_codec_name , AVMEDIA_TYPE_VIDEO , 0, + &ic->video_codec)); if (audio_codec_name) - ic->audio_codec = find_codec_or_die(NULL, audio_codec_name , AVMEDIA_TYPE_AUDIO , 0); + ret = err_merge(ret, find_codec(NULL, audio_codec_name , AVMEDIA_TYPE_AUDIO , 0, + &ic->audio_codec)); if (subtitle_codec_name) - ic->subtitle_codec = find_codec_or_die(NULL, subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0); + ret = err_merge(ret, find_codec(NULL, subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0, + &ic->subtitle_codec)); if (data_codec_name) - ic->data_codec = find_codec_or_die(NULL, data_codec_name , AVMEDIA_TYPE_DATA , 0); + ret = err_merge(ret, find_codec(NULL, data_codec_name , AVMEDIA_TYPE_DATA, 0, + &ic->data_codec)); + if (ret < 0) + return ret; ic->video_codec_id = video_codec_name ? ic->video_codec->id : AV_CODEC_ID_NONE; ic->audio_codec_id = audio_codec_name ? ic->audio_codec->id : AV_CODEC_ID_NONE; @@ -1496,8 +1511,13 @@ int ifile_open(const OptionsContext *o, const char *filename) assert_avoptions(o->g->format_opts); /* apply forced codec ids */ - for (i = 0; i < ic->nb_streams; i++) - choose_decoder(o, ic, ic->streams[i], HWACCEL_NONE, AV_HWDEVICE_TYPE_NONE); + for (i = 0; i < ic->nb_streams; i++) { + const AVCodec *dummy; + ret = choose_decoder(o, ic, ic->streams[i], HWACCEL_NONE, AV_HWDEVICE_TYPE_NONE, + &dummy); + if (ret < 0) + return ret; + } if (o->find_stream_info) { AVDictionary **opts; diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index cb943ac408..aebec0c573 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -140,7 +140,9 @@ static int choose_encoder(const OptionsContext *o, AVFormatContext *s, return AVERROR_ENCODER_NOT_FOUND; } } else if (strcmp(codec_name, "copy")) { - *enc = find_codec_or_die(ost, codec_name, ost->type, 1); + int ret = find_codec(ost, codec_name, ost->type, 1, enc); + if (ret < 0) + return ret; ost->par_in->codec_id = (*enc)->id; } diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index eef6d5e749..5a5a26d0a5 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -637,8 +637,8 @@ static int opt_recording_timestamp(void *optctx, const char *opt, const char *ar return 0; } -const AVCodec *find_codec_or_die(void *logctx, const char *name, - enum AVMediaType type, int encoder) +int find_codec(void *logctx, const char *name, + enum AVMediaType type, int encoder, const AVCodec **pcodec) { const AVCodecDescriptor *desc; const char *codec_string = encoder ? "encoder" : "decoder"; @@ -658,13 +658,16 @@ const AVCodec *find_codec_or_die(void *logctx, const char *name, if (!codec) { av_log(logctx, AV_LOG_FATAL, "Unknown %s '%s'\n", codec_string, name); - exit_program(1); + return encoder ? AVERROR_ENCODER_NOT_FOUND : + AVERROR_DECODER_NOT_FOUND; } if (codec->type != type && !recast_media) { av_log(logctx, AV_LOG_FATAL, "Invalid %s type '%s'\n", codec_string, name); - exit_program(1); + return AVERROR(EINVAL); } - return codec; + + *pcodec = codec; + return 0;; } int assert_file_overwrite(const char *filename) From patchwork Sat Jul 15 10:45:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42735 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4241649pzb; Sat, 15 Jul 2023 03:54:20 -0700 (PDT) X-Google-Smtp-Source: APBJJlGngz8IujADrVutnhWFIdWLkgtzHALRlzeq0jFnxB+xqgv719kHTfV/RIZ4/+ac0G5Hn/1Z X-Received: by 2002:a05:6402:542:b0:51e:3427:63ea with SMTP id i2-20020a056402054200b0051e342763eamr6225966edx.8.1689418460536; Sat, 15 Jul 2023 03:54:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418460; cv=none; d=google.com; s=arc-20160816; b=Sscg/BCzYonwCe/Xoh3uRMus0MHTmaU7q1c+jTEKL4G1rKY2bUnHVrBy33FTTqUdl+ +HqIfOqtVyeQGWRjVIRRaBJmtAJ7MDzBNOZxlAUr+VFg38EuygCV61EA6YgZyMoua8gL hrotEkSxiY9NOrPxDPCyTlutI5M230sL4tzBTdp7qxA7UOGN3UcHGZeOza8M9tnYMTO1 nOMCgPkQV1gAlVNX3rzS3lZX4iLNSmLs9jd19puGANpp9/Ah1kPnYMvPzqkZKSFOlCqf icUFCyVi54y9UbN4ILYBiLZHaEFmQ4HetmUazVHq5nm+T8HWaZNRT6YSevVWx9M8g4Pl Nlog== 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=KHMBbpSH2OjyuossMdF3zLffwXZIYJoiFqECbHhF1z8=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=wCtQX6wXa7L8flqQBShiWJxPcUzhKic/upz05Cq/RHJLFtfeoPlvforOQ490JGhXPr 5X+0XxmTd0QJJTFpzXcAzZNEhHAAagkjyQbW/TvHP2cPmQrjQxrVFOc9infVVQKtRt+0 y59qERBqq0LHSr3NMJ9+UH0A329r13b2sQplx2qjy28ayLamN1qEdTWWZYcIVZoSDgX5 oWMnXmhV23fEjHESp9Cf+c9TvDG0c55L48IRAN3cJViuJ3A1Uxu9d++LhHioi9Hj5LUW DBwR1LIAYiyLyjZKjPo74AjUS7NCpLUOn14qcf9pYhoRhhA69YyBHtttKQ1TItJfgIe/ v8JQ== 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 b3-20020aa7c6c3000000b0051e2936779fsi4586676eds.380.2023.07.15.03.54.20; Sat, 15 Jul 2023 03:54:20 -0700 (PDT) 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 A06A368C782; Sat, 15 Jul 2023 13:53:45 +0300 (EEST) 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 CDD2068C75C for ; Sat, 15 Jul 2023 13:53:38 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 83C5A2404EA for ; Sat, 15 Jul 2023 12:53:37 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id cBRZvzsWuNtc for ; Sat, 15 Jul 2023 12:53:36 +0200 (CEST) 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 EC8952405B5 for ; Sat, 15 Jul 2023 12:53:32 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 5B4563A21C7 for ; Sat, 15 Jul 2023 12:46:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:54 +0200 Message-Id: <20230715104611.17902-30-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 30/47] fftools/ffmpeg_opt: replace exit_program() with returning error codes 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: iD9mmyaWXd2U --- fftools/ffmpeg_opt.c | 49 ++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 5a5a26d0a5..293397a8b7 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -190,7 +190,7 @@ int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_id else if (!is_global && !av_strcasecmp(arg, "auto")) *vsync_var = VSYNC_AUTO; else if (!is_global) { av_log(NULL, AV_LOG_FATAL, "Invalid value %s specified for fps_mode of #%d:%d.\n", arg, file_idx, st_idx); - exit_program(1); + return AVERROR(EINVAL); } if (is_global && *vsync_var == VSYNC_AUTO) { @@ -250,12 +250,12 @@ static int apply_sync_offsets(void) if (self->input_sync_ref == -1 || self->input_sync_ref == i) continue; if (self->input_sync_ref >= nb_input_files || self->input_sync_ref < -1) { av_log(NULL, AV_LOG_FATAL, "-isync for input %d references non-existent input %d.\n", i, self->input_sync_ref); - exit_program(1); + return AVERROR(EINVAL); } if (copy_ts && !start_at_zero) { av_log(NULL, AV_LOG_FATAL, "Use of -isync requires that start_at_zero be set if copyts is set.\n"); - exit_program(1); + return AVERROR(EINVAL); } ref = input_files[self->input_sync_ref]; @@ -397,7 +397,7 @@ static int opt_map(void *optctx, const char *opt, const char *arg) m->linklabel = av_get_token(&c, "]"); if (!m->linklabel) { av_log(NULL, AV_LOG_ERROR, "Invalid output link label: %s.\n", map); - exit_program(1); + return AVERROR(EINVAL); } } else { if (allow_unused = strchr(map, '?')) @@ -405,7 +405,7 @@ static int opt_map(void *optctx, const char *opt, const char *arg) file_idx = strtol(map, &p, 0); if (file_idx >= nb_input_files || file_idx < 0) { av_log(NULL, AV_LOG_FATAL, "Invalid input file index: %d.\n", file_idx); - exit_program(1); + return AVERROR(EINVAL); } if (negative) /* disable some already defined maps */ @@ -443,11 +443,11 @@ static int opt_map(void *optctx, const char *opt, const char *arg) } else if (disabled) { av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches disabled streams.\n" "To ignore this, add a trailing '?' to the map.\n", arg); - exit_program(1); + return AVERROR(EINVAL); } else { av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches no streams.\n" "To ignore this, add a trailing '?' to the map.\n", arg); - exit_program(1); + return AVERROR(EINVAL); } } @@ -509,7 +509,7 @@ static int opt_map_channel(void *optctx, const char *opt, const char *arg) if (n != 3 && n != 5) { av_log(NULL, AV_LOG_FATAL, "Syntax error, mapchan usage: " "[file.stream.channel|-1][:syncfile:syncstream]\n"); - exit_program(1); + goto fail; } if (n != 5) // only file.stream.channel specified @@ -519,19 +519,19 @@ static int opt_map_channel(void *optctx, const char *opt, const char *arg) if (m->file_idx < 0 || m->file_idx >= nb_input_files) { av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file index: %d\n", m->file_idx); - exit_program(1); + goto fail; } if (m->stream_idx < 0 || m->stream_idx >= input_files[m->file_idx]->nb_streams) { av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file stream index #%d.%d\n", m->file_idx, m->stream_idx); - exit_program(1); + goto fail; } st = input_files[m->file_idx]->ctx->streams[m->stream_idx]; if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) { av_log(NULL, AV_LOG_FATAL, "mapchan: stream #%d.%d is not an audio stream.\n", m->file_idx, m->stream_idx); - exit_program(1); + goto fail; } /* allow trailing ? to map_channel */ if (allow_unused = strchr(mapchan, '?')) @@ -545,12 +545,15 @@ static int opt_map_channel(void *optctx, const char *opt, const char *arg) av_log(NULL, AV_LOG_FATAL, "mapchan: invalid audio channel #%d.%d.%d\n" "To ignore this, add a trailing '?' to the map_channel.\n", m->file_idx, m->stream_idx, m->channel_idx); - exit_program(1); + goto fail; } } av_free(mapchan); return 0; +fail: + av_free(mapchan); + return AVERROR(EINVAL); } #endif @@ -602,7 +605,7 @@ static int opt_init_hw_device(void *optctx, const char *opt, const char *arg) AV_HWDEVICE_TYPE_NONE) printf("%s\n", av_hwdevice_get_type_name(type)); printf("\n"); - exit_program(0); + return AVERROR_EXIT; } else { return hw_device_init_from_string(arg, NULL); } @@ -819,7 +822,7 @@ static int opt_target(void *optctx, const char *opt, const char *arg) av_log(NULL, AV_LOG_FATAL, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n"); av_log(NULL, AV_LOG_FATAL, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n"); av_log(NULL, AV_LOG_FATAL, "or set a framerate with \"-r xxx\".\n"); - exit_program(1); + return AVERROR(EINVAL); } if (!strcmp(arg, "vcd")) { @@ -931,7 +934,7 @@ static int opt_vstats(void *optctx, const char *opt, const char *arg) if (!today) { // maybe tomorrow av_log(NULL, AV_LOG_FATAL, "Unable to get current time: %s\n", strerror(errno)); - exit_program(1); + return AVERROR(errno); } snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min, @@ -983,6 +986,7 @@ static int opt_preset(void *optctx, const char *opt, const char *arg) FILE *f=NULL; char filename[1000], line[1000], tmp_line[1000]; const char *codec_name = NULL; + int ret = 0; tmp_line[0] = *opt; tmp_line[1] = 0; @@ -993,7 +997,7 @@ static int opt_preset(void *optctx, const char *opt, const char *arg) av_log(NULL, AV_LOG_FATAL, "Please use -preset -qp 0\n"); }else av_log(NULL, AV_LOG_FATAL, "File for preset '%s' not found\n", arg); - exit_program(1); + return AVERROR(ENOENT); } while (fgets(line, sizeof(line), f)) { @@ -1005,7 +1009,8 @@ static int opt_preset(void *optctx, const char *opt, const char *arg) if (!av_strtok(key, "=", &value) || !av_strtok(value, "\r\n", &endptr)) { av_log(NULL, AV_LOG_FATAL, "%s: Invalid syntax: '%s'\n", filename, line); - exit_program(1); + ret = AVERROR(EINVAL); + goto fail; } av_log(NULL, AV_LOG_DEBUG, "ffpreset[%s]: set '%s' = '%s'\n", filename, key, value); @@ -1016,13 +1021,15 @@ static int opt_preset(void *optctx, const char *opt, const char *arg) else if (opt_default_new(o, key, value) < 0) { av_log(NULL, AV_LOG_FATAL, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n", filename, line, key, value); - exit_program(1); + ret = AVERROR(EINVAL); + goto fail; } } +fail: fclose(f); - return 0; + return ret; } static int opt_old2new(void *optctx, const char *opt, const char *arg) @@ -1310,7 +1317,9 @@ int ffmpeg_parse_options(int argc, char **argv) correct_input_start_times(); - apply_sync_offsets(); + ret = apply_sync_offsets(); + if (ret < 0) + goto fail; ret = check_filter_outputs(); if (ret < 0) From patchwork Sat Jul 15 10:45:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42733 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4241578pzb; Sat, 15 Jul 2023 03:54:05 -0700 (PDT) X-Google-Smtp-Source: APBJJlHYz/ULxxFOv7Bxal+kYykP7ni2mrGsNiHRRlkSdwuo0Ojof4xf+nkjhMNAB9JwJOqyA2F7 X-Received: by 2002:a17:907:6e0d:b0:992:4c42:581c with SMTP id sd13-20020a1709076e0d00b009924c42581cmr6691782ejc.62.1689418445157; Sat, 15 Jul 2023 03:54:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418445; cv=none; d=google.com; s=arc-20160816; b=O29VYWAXUiIh5VW6+mFEOveNUacnnQipuO6/tmLTr3cINbiTN1bKVeL3r2ibwm4Zyf 3r+ffhzoVwVzoazgGXfXNGMtBFBZadKcDWmCaj3g3wqqxov3+oc+WBpkcDsGN+IbgCOn tlPRfaKdnvfMf5LokbwHqpsJD4Qb8Pi9951+gcRTDYGMpnBKL24Csou1VtCY0PA4kTfJ Pkzpf7tHhCwEtlUQkipHrAwAr3j/ccYRPZSGEMVPzJPuQweYKA+u/IFEKZVy5Gq71zGh P1USXn/SWN/kIk9mldLDrvwESZqFLrKxmnKyAtZuYUpIgPI+3/mPzDQEk4kYJ0Q2I1BB MYrg== 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=AJpGjFmFaXHGPltQtU6JMG/i6jD6uPMkUIhcZVBbaQg=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=x3xBZt229FT3/3djlGypIGXXnOe9XcYBE/6bnDhKtqP40xoAa4cWlPTKbX5qWU/eSa Yh7h6XZ+/MC2L/3H+9NvyhNNB/lJeIqPXyEReVGKJSQSHfWXFUAEeuIYUnmdlV+3tjsg IeFMCKrxU6QlT64X+K13SvjYVlYhsaWc0CM/k2O2XVDcMfmSXYXCmCXrzNdUPqcu/E5d hO1pt0METCLyjzWM1R2FSavv1jc3aj4Ek3LdOdMbU2BTGv1fAo+brpaFdp5Xax4evyi5 90u9ul29zCkkaWXI+0c17Zrn20KIGU3GbuctBEGftOM1ai1V8k//bqFnxl1K+OjAjXiz b9Hg== 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 s16-20020a170906bc5000b0098e2edf7479si10707350ejv.858.2023.07.15.03.54.04; Sat, 15 Jul 2023 03:54:05 -0700 (PDT) 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 95FAE68C753; Sat, 15 Jul 2023 13:53:43 +0300 (EEST) 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 26C0A68C737 for ; Sat, 15 Jul 2023 13:53:36 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id D6EFC2404EE for ; Sat, 15 Jul 2023 12:53:35 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id hzHFuY67596F for ; Sat, 15 Jul 2023 12:53:35 +0200 (CEST) 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 BCCD62404F8 for ; Sat, 15 Jul 2023 12:53:32 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 66B1B3A220F for ; Sat, 15 Jul 2023 12:46:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:55 +0200 Message-Id: <20230715104611.17902-31-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 31/47] fftools/opt_common: replace exit_program() with returning error codes 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: QO0Ih23LOQF7 --- fftools/opt_common.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fftools/opt_common.c b/fftools/opt_common.c index f6fe9815e1..39258bb46c 100644 --- a/fftools/opt_common.c +++ b/fftools/opt_common.c @@ -1159,7 +1159,9 @@ int init_report(const char *env, FILE **file) report_file_level = strtol(val, &tail, 10); if (*tail) { av_log(NULL, AV_LOG_FATAL, "Invalid report file level\n"); - exit_program(1); + av_free(key); + av_free(val); + return AVERROR(EINVAL); } envlevel = 1; } else { @@ -1219,7 +1221,7 @@ int opt_max_alloc(void *optctx, const char *opt, const char *arg) max = strtol(arg, &tail, 10); if (*tail) { av_log(NULL, AV_LOG_FATAL, "Invalid max_alloc \"%s\".\n", arg); - exit_program(1); + return AVERROR(EINVAL); } av_max_alloc(max); return 0; @@ -1293,7 +1295,7 @@ int opt_loglevel(void *optctx, const char *opt, const char *arg) "Possible levels are numbers or:\n", arg); for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) av_log(NULL, AV_LOG_FATAL, "\"%s\"\n", log_levels[i].name); - exit_program(1); + return AVERROR(EINVAL); } end: From patchwork Sat Jul 15 10:45:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42711 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4240349pzb; Sat, 15 Jul 2023 03:50:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlGYN36Cd7n0NRZ1tWOwFJOAdeuSahfDcRRgkMt+YVv/fR1ZMApVRIlypOZlBlYjvocqJI1/ X-Received: by 2002:a5d:40ce:0:b0:313:f61c:42ab with SMTP id b14-20020a5d40ce000000b00313f61c42abmr6323958wrq.56.1689418235487; Sat, 15 Jul 2023 03:50:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418235; cv=none; d=google.com; s=arc-20160816; b=h01SOmkLes0JA8qRv/eSFg3qc81XLFXrh0gzdwVujxQuacq4+wO4uv/2+SVHPLmujt oK5ubtsuIae/wUIyS4UGf05aU5dO3VgA7E9ec1Bynzh1xM418qpswCqNTAlpChZZImtf C8I/phmuHFr4+as8T6xQSNBFdIm0wOGKpw4tiqOon6QItx44LaqjvWybrzu/oivcwf9i UoaSa6pwlhkKEBSdMCzAyraLpZFKo0VYBQ6O7uZJuEw4ZH87wLTTjhNa4UgtIP5QS29M 1d21WwcE3o1fDQVq1HD/r5bdV3RA2dVPNyl+Li+N/4uPxqhhREkdjCN2Rp3yk2Ae7N1z rBxQ== 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=HEzwHbC/EiodIuxGirMHaZUwmcL+ojTXQaMHGxdVl5o=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=EkLNnlOFzXG5iYIdQ0luToTwBdM97GU619aSNKUU3ieTQaR1dOdlZ0fjyjqnXZwVVs alS/DRDSuOtfom6VK5xBnz+BY5xe2S01YNggIVNqUNbhkIAUMA784t3u9o9Md6TVjZYq nTnRu4b4WB2kPJOnxq/O053tHEjmjqKttytHDMNX37TcdKEtjY9IW5kD+TORzrB1tchT x34+szcuXHOCG9h/7SnlS4dTyAep4JFTJG1HI/0GR6I9/Gj7heG3vSq1m9cb2GNxq8fn 9EsY7ysQsWQqbev5Tc+b6oeSfNJ5xzJuKChFPFqCq/Enh6UDNE9mDCEai4QChtj9SGWJ pQ5A== 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 w9-20020aa7da49000000b0051e367e4653si2499253eds.282.2023.07.15.03.50.35; Sat, 15 Jul 2023 03:50:35 -0700 (PDT) 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 80C0768C752; Sat, 15 Jul 2023 13:47:05 +0300 (EEST) 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 433BD68C65B for ; Sat, 15 Jul 2023 13:46:43 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id EADC12404EA for ; Sat, 15 Jul 2023 12:46:42 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id wTAe1CEmsz8q for ; Sat, 15 Jul 2023 12:46:42 +0200 (CEST) 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 13B16240D25 for ; Sat, 15 Jul 2023 12:46:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 728693A222F for ; Sat, 15 Jul 2023 12:46:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:56 +0200 Message-Id: <20230715104611.17902-32-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 32/47] fftools: return errors from parse_number_or_die() instead of aborting 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: u+F4pie8I9fq Rename the function to just parse_number(). --- fftools/cmdutils.c | 39 +++++++++++++++++++++++++++++---------- fftools/cmdutils.h | 6 ++---- fftools/ffmpeg_mux_init.c | 7 +++++-- fftools/ffmpeg_opt.c | 23 ++++++++++++++++++----- fftools/ffplay.c | 25 +++++++++++++++++++++---- fftools/ffprobe.c | 10 ++++++++-- 6 files changed, 83 insertions(+), 27 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index fb35245f0a..48a81ca201 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -104,8 +104,8 @@ void exit_program(int ret) exit(ret); } -double parse_number_or_die(const char *context, const char *numstr, int type, - double min, double max) +int parse_number(const char *context, const char *numstr, int type, + double min, double max, double *dst) { char *tail; const char *error; @@ -118,11 +118,13 @@ double parse_number_or_die(const char *context, const char *numstr, int type, error = "Expected int64 for %s but found %s\n"; else if (type == OPT_INT && (int)d != d) error = "Expected int for %s but found %s\n"; - else - return d; + else { + *dst = d; + return 0; + } + av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max); - exit_program(1); - return 0; + return AVERROR(EINVAL); } int64_t parse_time_or_die(const char *context, const char *timestr, @@ -262,6 +264,7 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt, void *dst = po->flags & (OPT_OFFSET | OPT_SPEC) ? (uint8_t *)optctx + po->u.off : po->u.dst_ptr; int *dstcount; + double num; int ret; if (po->flags & OPT_SPEC) { @@ -289,15 +292,31 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt, return AVERROR(ENOMEM); *(char **)dst = str; } else if (po->flags & OPT_BOOL || po->flags & OPT_INT) { - *(int *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX); + ret = parse_number(opt, arg, OPT_INT64, INT_MIN, INT_MAX, &num); + if (ret < 0) + return ret; + + *(int *)dst = num; } else if (po->flags & OPT_INT64) { - *(int64_t *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX); + ret = parse_number(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX, &num); + if (ret < 0) + return ret; + + *(int64_t *)dst = num; } else if (po->flags & OPT_TIME) { *(int64_t *)dst = parse_time_or_die(opt, arg, 1); } else if (po->flags & OPT_FLOAT) { - *(float *)dst = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY); + ret = parse_number(opt, arg, OPT_FLOAT, -INFINITY, INFINITY, &num); + if (ret < 0) + return ret; + + *(float *)dst = num; } else if (po->flags & OPT_DOUBLE) { - *(double *)dst = parse_number_or_die(opt, arg, OPT_DOUBLE, -INFINITY, INFINITY); + ret = parse_number(opt, arg, OPT_DOUBLE, -INFINITY, INFINITY, &num); + if (ret < 0) + return ret; + + *(double *)dst = num; } else if (po->u.func_arg) { int ret = po->u.func_arg(optctx, opt, arg); if (ret < 0) { diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index 69c2123804..68de0bcb7f 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -100,8 +100,6 @@ int opt_timelimit(void *optctx, const char *opt, const char *arg); /** * Parse a string and return its corresponding value as a double. - * Exit from the application if the string cannot be correctly - * parsed or the corresponding value is invalid. * * @param context the context of the value to be set (e.g. the * corresponding command line option name) @@ -111,8 +109,8 @@ int opt_timelimit(void *optctx, const char *opt, const char *arg); * @param min the minimum valid accepted value * @param max the maximum valid accepted value */ -double parse_number_or_die(const char *context, const char *numstr, int type, - double min, double max); +int parse_number(const char *context, const char *numstr, int type, + double min, double max, double *dst); /** * Parse a string specifying a time and return its corresponding diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index aebec0c573..02d71588ad 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -795,8 +795,11 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, ost->vsync_method = video_sync_method; MATCH_PER_STREAM_OPT(fps_mode, str, fps_mode, oc, st); - if (fps_mode) - parse_and_set_vsync(fps_mode, &ost->vsync_method, ost->file_index, ost->index, 0); + if (fps_mode) { + ret = parse_and_set_vsync(fps_mode, &ost->vsync_method, ost->file_index, ost->index, 0); + if (ret < 0) + return ret; + } if ((ost->frame_rate.num || ost->max_frame_rate.num) && !(ost->vsync_method == VSYNC_AUTO || diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 293397a8b7..e1696cdd59 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -194,7 +194,14 @@ int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_id } if (is_global && *vsync_var == VSYNC_AUTO) { - video_sync_method = parse_number_or_die("vsync", arg, OPT_INT, VSYNC_AUTO, VSYNC_VFR); + int ret; + double num; + + ret = parse_number("vsync", arg, OPT_INT, VSYNC_AUTO, VSYNC_VFR, &num); + if (ret < 0) + return ret; + + video_sync_method = num; av_log(NULL, AV_LOG_WARNING, "Passing a number to -vsync is deprecated," " use a string argument as described in the manual.\n"); } @@ -1104,8 +1111,7 @@ static int opt_audio_filters(void *optctx, const char *opt, const char *arg) static int opt_vsync(void *optctx, const char *opt, const char *arg) { av_log(NULL, AV_LOG_WARNING, "-vsync is deprecated. Use -fps_mode\n"); - parse_and_set_vsync(arg, &video_sync_method, -1, -1, 1); - return 0; + return parse_and_set_vsync(arg, &video_sync_method, -1, -1, 1); } static int opt_timecode(void *optctx, const char *opt, const char *arg) @@ -1353,8 +1359,15 @@ static int opt_progress(void *optctx, const char *opt, const char *arg) int opt_timelimit(void *optctx, const char *opt, const char *arg) { #if HAVE_SETRLIMIT - int lim = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX); - struct rlimit rl = { lim, lim + 1 }; + int ret; + double lim; + struct rlimit rl; + + ret = parse_number(opt, arg, OPT_INT64, 0, INT_MAX, &lim); + if (ret < 0) + return ret; + + rl = (struct rlimit){ lim, lim + 1 }; if (setrlimit(RLIMIT_CPU, &rl)) perror("setrlimit"); #else diff --git a/fftools/ffplay.c b/fftools/ffplay.c index 1f9757d607..6ca1ad98bf 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -3440,13 +3440,23 @@ static void event_loop(VideoState *cur_stream) static int opt_width(void *optctx, const char *opt, const char *arg) { - screen_width = parse_number_or_die(opt, arg, OPT_INT64, 1, INT_MAX); + double num; + int ret = parse_number(opt, arg, OPT_INT64, 1, INT_MAX, &num); + if (ret < 0) + return ret; + + screen_width = num; return 0; } static int opt_height(void *optctx, const char *opt, const char *arg) { - screen_height = parse_number_or_die(opt, arg, OPT_INT64, 1, INT_MAX); + double num; + int ret = parse_number(opt, arg, OPT_INT64, 1, INT_MAX, &num); + if (ret < 0) + return ret; + + screen_height = num; return 0; } @@ -3491,8 +3501,15 @@ static int opt_show_mode(void *optctx, const char *opt, const char *arg) { show_mode = !strcmp(arg, "video") ? SHOW_MODE_VIDEO : !strcmp(arg, "waves") ? SHOW_MODE_WAVES : - !strcmp(arg, "rdft" ) ? SHOW_MODE_RDFT : - parse_number_or_die(opt, arg, OPT_INT, 0, SHOW_MODE_NB-1); + !strcmp(arg, "rdft" ) ? SHOW_MODE_RDFT : SHOW_MODE_NONE; + + if (show_mode == SHOW_MODE_NONE) { + double num; + int ret = parse_number(opt, arg, OPT_INT, 0, SHOW_MODE_NB-1, &num); + if (ret < 0) + return ret; + show_mode = num; + } return 0; } diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index 91a3be660b..e6fd33492d 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -3665,8 +3665,14 @@ static int opt_show_optional_fields(void *optctx, const char *opt, const char *a else if (!av_strcasecmp(arg, "never")) show_optional_fields = SHOW_OPTIONAL_FIELDS_NEVER; else if (!av_strcasecmp(arg, "auto")) show_optional_fields = SHOW_OPTIONAL_FIELDS_AUTO; - if (show_optional_fields == SHOW_OPTIONAL_FIELDS_AUTO && av_strcasecmp(arg, "auto")) - show_optional_fields = parse_number_or_die("show_optional_fields", arg, OPT_INT, SHOW_OPTIONAL_FIELDS_AUTO, SHOW_OPTIONAL_FIELDS_ALWAYS); + if (show_optional_fields == SHOW_OPTIONAL_FIELDS_AUTO && av_strcasecmp(arg, "auto")) { + double num; + int ret = parse_number("show_optional_fields", arg, OPT_INT, + SHOW_OPTIONAL_FIELDS_AUTO, SHOW_OPTIONAL_FIELDS_ALWAYS, &num); + if (ret < 0) + return ret; + show_optional_fields = num; + } return 0; } From patchwork Sat Jul 15 10:45:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42716 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4240085pzb; Sat, 15 Jul 2023 03:49:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlEEA0D+7kCwY+RTIChbRotQjfHYcYJTnM0ksj7lIkV0eZ60p0Ga29p5UANVa5Ofdb2ekpsM X-Received: by 2002:aa7:dd0f:0:b0:51a:3159:53c7 with SMTP id i15-20020aa7dd0f000000b0051a315953c7mr6447788edv.30.1689418196336; Sat, 15 Jul 2023 03:49:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418196; cv=none; d=google.com; s=arc-20160816; b=L/a7rSO90QdFIZL5XEPhNxHucSMnjPEn1wG9SsvPG7Lv1aYAmmrbE5xuLQyCeQLcrp JyQUPFdMcOiXRsWZmVsrMRYLElWE+J2enks1wkvZU+I0e74ammWImQiuiUIsFw+dXXDR PYcNKwQIp54rv/n5hLFxDECPNfC4kpu8Og1lenc7b0ITHyIRMDJ5DubZaO+ykdU9C3lU h72AV7gs1+/sgn3zTJrG2xq8Mo/090IsdGcuN/Cq1aaRImxkaIJf2dtG0MfPZwTrKtDw 8qMeKn29iorxdW9WMoeyxfNeT6dKXlyzMskA675vBEcYY/BdtOuaoc163clkaHRkiVyV qCzA== 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=NyDWixS5E/I1L7mGrgSNM3GOZv6WpM+lI9h2wwKX/Pw=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=ZqGthAg6I9iHuLTWEa3Tq/1sevnEWZe0YfreRBOkFRVCi3L/xENYnDaxpG8lYo9IIi WAoqmKHDSwW1aHtjtv8LEND7sPCr+CqvZLfF8tyCvT23RxgYThdMefMSDU6TLUZwOWGq bwRgYtOGz7xJRZTTkdKaTMsWZqyCNlNR/3T+zTN3WVeWnmoptP+v9kQIWIZ0oaBJscuh DnI2mbKbvia5lJZU/GR9zlxj0ZvVjYPtuHEnWntNG1+oj2FoJa2jE7sQAqUA6TsT18kF w7/WAWndjWonHhVQJiprSi96LH7D1d2QgdRprSRtbbXUmbO8XZa+gKO0/CaW4X7F/QBm oqWQ== 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 bf10-20020a0564021a4a00b0051de49abbd2si2503897edb.483.2023.07.15.03.49.56; Sat, 15 Jul 2023 03:49:56 -0700 (PDT) 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 A708D68C727; Sat, 15 Jul 2023 13:46:59 +0300 (EEST) 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 6F30B68C6A5 for ; Sat, 15 Jul 2023 13:46:41 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 2370B2404EA for ; Sat, 15 Jul 2023 12:46:41 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Q7tOhdaXpd7L for ; Sat, 15 Jul 2023 12:46:40 +0200 (CEST) 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 0DCA7240D21 for ; Sat, 15 Jul 2023 12:46:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 7E43B3A2278 for ; Sat, 15 Jul 2023 12:46:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:57 +0200 Message-Id: <20230715104611.17902-33-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 33/47] fftools: remove parse_time_or_die() 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: h87HifPBOEze Replace it with calling av_parse_time() directly, which provides graceful error handling and more accurate error messages. --- fftools/cmdutils.c | 19 ++++++------------- fftools/cmdutils.h | 17 ----------------- fftools/ffmpeg_mux_init.c | 30 ++++++++++++++++++++++++------ fftools/ffmpeg_opt.c | 17 ++++++++++++++--- fftools/ffplay.c | 16 ++-------------- 5 files changed, 46 insertions(+), 53 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 48a81ca201..b401b8fb89 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -127,18 +127,6 @@ int parse_number(const char *context, const char *numstr, int type, return AVERROR(EINVAL); } -int64_t parse_time_or_die(const char *context, const char *timestr, - int is_duration) -{ - int64_t us; - if (av_parse_time(&us, timestr, is_duration) < 0) { - av_log(NULL, AV_LOG_FATAL, "Invalid %s specification for %s: %s\n", - is_duration ? "duration" : "date", context, timestr); - exit_program(1); - } - return us; -} - void show_help_options(const OptionDef *options, const char *msg, int req_flags, int rej_flags, int alt_flags) { @@ -304,7 +292,12 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt, *(int64_t *)dst = num; } else if (po->flags & OPT_TIME) { - *(int64_t *)dst = parse_time_or_die(opt, arg, 1); + ret = av_parse_time(dst, arg, 1); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "Invalid duration for option %s: %s\n", + opt, arg); + return ret; + } } else if (po->flags & OPT_FLOAT) { ret = parse_number(opt, arg, OPT_FLOAT, -INFINITY, INFINITY, &num); if (ret < 0) diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index 68de0bcb7f..dc041d9fa2 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -112,23 +112,6 @@ int opt_timelimit(void *optctx, const char *opt, const char *arg); int parse_number(const char *context, const char *numstr, int type, double min, double max, double *dst); -/** - * Parse a string specifying a time and return its corresponding - * value as a number of microseconds. Exit from the application if - * the string cannot be correctly parsed. - * - * @param context the context of the value to be set (e.g. the - * corresponding command line option name) - * @param timestr the string to be parsed - * @param is_duration a flag which tells how to interpret timestr, if - * not zero timestr is interpreted as a duration, otherwise as a - * date - * - * @see av_parse_time() - */ -int64_t parse_time_or_die(const char *context, const char *timestr, - int is_duration); - typedef struct SpecifierOpt { char *specifier; /**< stream/chapter/program/... specifier */ union { diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 02d71588ad..92d62c7b89 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -2410,11 +2410,11 @@ static int compare_int64(const void *a, const void *b) return FFDIFFSIGN(*(const int64_t *)a, *(const int64_t *)b); } -static int parse_forced_key_frames(KeyframeForceCtx *kf, const Muxer *mux, - const char *spec) +static int parse_forced_key_frames(void *log, KeyframeForceCtx *kf, + const Muxer *mux, const char *spec) { const char *p; - int n = 1, i, size, index = 0; + int n = 1, i, ret, size, index = 0; int64_t t, *pts; for (p = spec; *p; p++) @@ -2441,7 +2441,16 @@ static int parse_forced_key_frames(KeyframeForceCtx *kf, const Muxer *mux, !(pts = av_realloc_f(pts, size += nb_ch - 1, sizeof(*pts)))) return AVERROR(ENOMEM); - t = p[8] ? parse_time_or_die("force_key_frames", p + 8, 1) : 0; + + if (p[8]) { + ret = av_parse_time(&t, p + 8, 1); + if (ret < 0) { + av_log(log, AV_LOG_ERROR, + "Invalid chapter time offset: %s\n", p + 8); + goto fail; + } + } else + t = 0; for (j = 0; j < nb_ch; j++) { const AVChapter *c = ch[j]; @@ -2452,7 +2461,13 @@ static int parse_forced_key_frames(KeyframeForceCtx *kf, const Muxer *mux, } else { av_assert1(index < size); - pts[index++] = parse_time_or_die("force_key_frames", p, 1); + ret = av_parse_time(&t, p, 1); + if (ret < 0) { + av_log(log, AV_LOG_ERROR, "Invalid keyframe time: %s\n", p); + goto fail; + } + + pts[index++] = t; } p = next; @@ -2464,6 +2479,9 @@ static int parse_forced_key_frames(KeyframeForceCtx *kf, const Muxer *mux, kf->pts = pts; return 0; +fail: + av_freep(&pts); + return ret; } static int process_forced_keyframes(Muxer *mux, const OptionsContext *o) @@ -2498,7 +2516,7 @@ static int process_forced_keyframes(Muxer *mux, const OptionsContext *o) } else if (!strcmp(forced_keyframes, "source_no_drop")) { ost->kf.type = KF_FORCE_SOURCE_NO_DROP; } else { - int ret = parse_forced_key_frames(&ost->kf, mux, forced_keyframes); + int ret = parse_forced_key_frames(ost, &ost->kf, mux, forced_keyframes); if (ret < 0) return ret; } diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index e1696cdd59..44a6b49ed7 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -326,7 +326,10 @@ static int opt_abort_on(void *optctx, const char *opt, const char *arg) static int opt_stats_period(void *optctx, const char *opt, const char *arg) { - int64_t user_stats_period = parse_time_or_die(opt, arg, 1); + int64_t user_stats_period; + int ret = av_parse_time(&user_stats_period, arg, 1); + if (ret < 0) + return ret; if (user_stats_period <= 0) { av_log(NULL, AV_LOG_ERROR, "stats_period %s must be positive.\n", arg); @@ -636,8 +639,16 @@ static int opt_recording_timestamp(void *optctx, const char *opt, const char *ar { OptionsContext *o = optctx; char buf[128]; - int64_t recording_timestamp = parse_time_or_die(opt, arg, 0) / 1E6; - struct tm time = *gmtime((time_t*)&recording_timestamp); + int64_t recording_timestamp; + int ret; + struct tm time; + + ret = av_parse_time(&recording_timestamp, arg, 0); + if (ret < 0) + return ret; + + recording_timestamp /= 1e6; + time = *gmtime((time_t*)&recording_timestamp); if (!strftime(buf, sizeof(buf), "creation_time=%Y-%m-%dT%H:%M:%S%z", &time)) return -1; parse_option(o, "metadata", buf, options); diff --git a/fftools/ffplay.c b/fftools/ffplay.c index 6ca1ad98bf..89cea4d876 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -3485,18 +3485,6 @@ static int opt_sync(void *optctx, const char *opt, const char *arg) return 0; } -static int opt_seek(void *optctx, const char *opt, const char *arg) -{ - start_time = parse_time_or_die(opt, arg, 1); - return 0; -} - -static int opt_duration(void *optctx, const char *opt, const char *arg) -{ - duration = parse_time_or_die(opt, arg, 1); - return 0; -} - static int opt_show_mode(void *optctx, const char *opt, const char *arg) { show_mode = !strcmp(arg, "video") ? SHOW_MODE_VIDEO : @@ -3561,8 +3549,8 @@ static const OptionDef options[] = { { "ast", OPT_STRING | HAS_ARG | OPT_EXPERT, { &wanted_stream_spec[AVMEDIA_TYPE_AUDIO] }, "select desired audio stream", "stream_specifier" }, { "vst", OPT_STRING | HAS_ARG | OPT_EXPERT, { &wanted_stream_spec[AVMEDIA_TYPE_VIDEO] }, "select desired video stream", "stream_specifier" }, { "sst", OPT_STRING | HAS_ARG | OPT_EXPERT, { &wanted_stream_spec[AVMEDIA_TYPE_SUBTITLE] }, "select desired subtitle stream", "stream_specifier" }, - { "ss", HAS_ARG, { .func_arg = opt_seek }, "seek to a given position in seconds", "pos" }, - { "t", HAS_ARG, { .func_arg = opt_duration }, "play \"duration\" seconds of audio/video", "duration" }, + { "ss", HAS_ARG | OPT_TIME, { &start_time }, "seek to a given position in seconds", "pos" }, + { "t", HAS_ARG | OPT_TIME, { &duration }, "play \"duration\" seconds of audio/video", "duration" }, { "bytes", OPT_INT | HAS_ARG, { &seek_by_bytes }, "seek by bytes 0=off 1=on -1=auto", "val" }, { "seek_interval", OPT_FLOAT | HAS_ARG, { &seek_interval }, "set seek interval for left/right keys, in seconds", "seconds" }, { "nodisp", OPT_BOOL, { &display_disable }, "disable graphical display" }, From patchwork Sat Jul 15 10:45:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42718 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4240220pzb; Sat, 15 Jul 2023 03:50:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlEII3fuxGcNZSRRdp0g+pG4DYCSCB15lUQhZXWn0+llp2NGM0yWUmjftFiNLSL1xgqwUFIF X-Received: by 2002:a50:ef0e:0:b0:521:6ed7:aab1 with SMTP id m14-20020a50ef0e000000b005216ed7aab1mr2510551eds.7.1689418212267; Sat, 15 Jul 2023 03:50:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418212; cv=none; d=google.com; s=arc-20160816; b=0rrcfUqwG1IM9t6uBTT3yDITxPWoFZTtvnMlx4iDMvIcQMnNmpAATqIGcNd05yKEqY rQSxWWusMHwNPSNMNKAmZmtdbP+673BlQYVrkXpXh/lUGOE59WLNEgB/VF/oZ3mPFpMo /kLv+oMvXJDEydbXIYOMP0JIp1rRliRtHYGN6TSXGI4NWryDmKWjkOXy4tUg2zGltL+8 terp/QTUsk113w7kMFJ+WYs49BeZGtlVMpB2cVZEF4YCgCwA2PQxnhExmz8owMDrt8CZ BDg4muHrqSNn8y6Z8lhPeY2jH88+4eeifRjEWEYNtyKaE3nde7d/vt5Agcy3VYE/VxYw bHRg== 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=4WD0FAgnWKdww0k+p6pM41t03emo/9rfiqnaXkG8C7s=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=xnYOopVdZfq6UBloXKxUNXrVQLRdw/JqphHgFlRb7ymxOsmrJqUbwFoxY+poe/Gdys k3OaRfbNXbTbaeiVIVyDPb+ie4KNxBOi+u8y4V81OWLresUbJ4gmtkkdoAdC6PXs3dzM f+9rCum+gLE2hItMm7aZt/61LLUg9kDzt2gF2s0C6aQf4aQSvsI0EHY3Jja5SqofWo2E kzDsEyUNdi+ws6qd86OjsvI6msVNksjE7mzdT48ac+ogfEGOSEQmIib9l8pdrnMU3rkU XWmMRN73hfxkvDeWpDdHXp4ft7ntFjUBQeP0V5pxZ4/H+F3J6ygjARvihpeSRCtk/XzV d4Fg== 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 e8-20020a056402088800b0051e196bf9ddsi10796067edy.375.2023.07.15.03.50.11; Sat, 15 Jul 2023 03:50:12 -0700 (PDT) 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 68FE168C73C; Sat, 15 Jul 2023 13:47:02 +0300 (EEST) 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 4707468C69D for ; Sat, 15 Jul 2023 13:46:42 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id EEA002404EA for ; Sat, 15 Jul 2023 12:46:41 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id NHw9VibbOXAP for ; Sat, 15 Jul 2023 12:46:41 +0200 (CEST) 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 12CD7240D23 for ; Sat, 15 Jul 2023 12:46:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 89C323A2307 for ; Sat, 15 Jul 2023 12:46:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:58 +0200 Message-Id: <20230715104611.17902-34-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 34/47] fftools: handle errors in parse_options() 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: PUE2Pvwso7kv --- fftools/cmdutils.c | 15 ++++++++++----- fftools/cmdutils.h | 4 ++-- fftools/ffplay.c | 12 ++++++++---- fftools/ffprobe.c | 10 +++++++--- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index b401b8fb89..330b9c2aba 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -364,8 +364,8 @@ int parse_option(void *optctx, const char *opt, const char *arg, return !!(po->flags & HAS_ARG); } -void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, - void (*parse_arg_function)(void *, const char*)) +int parse_options(void *optctx, int argc, char **argv, const OptionDef *options, + int (*parse_arg_function)(void *, const char*)) { const char *opt; int optindex, handleoptions = 1, ret; @@ -386,13 +386,18 @@ void parse_options(void *optctx, int argc, char **argv, const OptionDef *options opt++; if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0) - exit_program(1); + return ret; optindex += ret; } else { - if (parse_arg_function) - parse_arg_function(optctx, opt); + if (parse_arg_function) { + ret = parse_arg_function(optctx, opt); + if (ret < 0) + return ret; + } } } + + return 0; } int parse_optgroup(void *optctx, OptionGroup *g) diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index dc041d9fa2..210d52e998 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -194,8 +194,8 @@ void show_help_default(const char *opt, const char *arg); * argument without a leading option name flag. NULL if such arguments do * not have to be processed. */ -void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, - void (* parse_arg_function)(void *optctx, const char*)); +int parse_options(void *optctx, int argc, char **argv, const OptionDef *options, + int (* parse_arg_function)(void *optctx, const char*)); /** * Parse one given option. diff --git a/fftools/ffplay.c b/fftools/ffplay.c index 89cea4d876..4e26b3309d 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -3501,17 +3501,19 @@ static int opt_show_mode(void *optctx, const char *opt, const char *arg) return 0; } -static void opt_input_file(void *optctx, const char *filename) +static int opt_input_file(void *optctx, const char *filename) { if (input_filename) { av_log(NULL, AV_LOG_FATAL, "Argument '%s' provided as input filename, but '%s' was already specified.\n", filename, input_filename); - exit(1); + return AVERROR(EINVAL); } if (!strcmp(filename, "-")) filename = "fd:"; input_filename = filename; + + return 0; } static int opt_codec(void *optctx, const char *opt, const char *arg) @@ -3630,7 +3632,7 @@ void show_help_default(const char *opt, const char *arg) /* Called from the main */ int main(int argc, char **argv) { - int flags; + int flags, ret; VideoState *is; init_dynload(); @@ -3649,7 +3651,9 @@ int main(int argc, char **argv) show_banner(argc, argv, options); - parse_options(NULL, argc, argv, options, opt_input_file); + ret = parse_options(NULL, argc, argv, options, opt_input_file); + if (ret < 0) + exit(1); if (!input_filename) { show_usage(); diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index e6fd33492d..ba55437760 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -3770,17 +3770,19 @@ static int opt_show_entries(void *optctx, const char *opt, const char *arg) return ret; } -static void opt_input_file(void *optctx, const char *arg) +static int opt_input_file(void *optctx, const char *arg) { if (input_filename) { av_log(NULL, AV_LOG_ERROR, "Argument '%s' provided as input filename, but '%s' was already specified.\n", arg, input_filename); - exit_program(1); + return AVERROR(EINVAL); } if (!strcmp(arg, "-")) arg = "fd:"; input_filename = arg; + + return 0; } static int opt_input_file_i(void *optctx, const char *opt, const char *arg) @@ -4121,7 +4123,9 @@ int main(int argc, char **argv) #endif show_banner(argc, argv, options); - parse_options(NULL, argc, argv, options, opt_input_file); + ret = parse_options(NULL, argc, argv, options, opt_input_file); + if (ret < 0) + exit_program(1); if (do_show_log) av_log_set_callback(log_callback); From patchwork Sat Jul 15 10:45:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42731 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4241487pzb; Sat, 15 Jul 2023 03:53:50 -0700 (PDT) X-Google-Smtp-Source: APBJJlF/2WBzZ/CQtdlYgI/cQ7LLLRyVf5l7nu7UydlcXr/HX6ETDtMu15sOVA/jOkkeZHQaVFmA X-Received: by 2002:a17:907:d0d:b0:988:9b29:5653 with SMTP id gn13-20020a1709070d0d00b009889b295653mr6760191ejc.77.1689418430536; Sat, 15 Jul 2023 03:53:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418430; cv=none; d=google.com; s=arc-20160816; b=o6/uFMP7gHgj5v0NQaYqHyRzrr2TXXzx/w180E6g1TDL2kPWV0hUuZev7MENCjPsko Jc7dO3pHb+sX+X1H+hxWCQSVdVXJJaeYTiI3P96sVX1Le20nvKHyJmBkMxc1wgnPLcxh 3SxG9RLhU03EyISKF91hyaRvOwi7iu5NM5rA13SbALGzZPAH9Pel0BYwUExzlhaRRpFq wds0209xSnndLyHy/xVD0dAvlqjY+mWP2czLj2uuwuEzUVyu1uPz9s3cXxWiBQOGlWMZ 4KQYAsen79SdyIEfF4TT1eAe1rSMdf1XIgOimGvhnuWlTku9PF9AOTUhMHO05kJuS6vF tSow== 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=HZnJULcwMgfDzKoaOpaIcd2E1wF28wSaxO5O34ieAeM=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=JnaNsj7t6H9DceY5xVSNJ+FHRu316KXIf7b3PkeBtdX2QVHba+JWYNgrRrinjo0Bnz QQIpvWVJO1EyDtfBnGs7XcehgN00Kp8G5XQYiEi3oUNLQa5r6T7iCYSS4b+whkQS1gLl sdbWk+Ot5PCDomV25E3+uIbtpqWsTRC5+4NjE08Y4k+yoaBG798UlsvzSkQ2NzxRlSlB piQ+is9JQiyrs+e2jzlQwwc6dfxVCp0Uj1dtD6Is1iGGlaXj6M5c6vAZufq/s5/+ueQZ EfivatBe2gP90rFXDY8uT2P1UmksXTW3oW6AFo/xLdYNIF67t391ifc0/+CaFjN7+gHB Hc7g== 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 q27-20020a170906361b00b00991ce8f1e19si10554560ejb.301.2023.07.15.03.53.50; Sat, 15 Jul 2023 03:53:50 -0700 (PDT) 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 97B6468C743; Sat, 15 Jul 2023 13:53:41 +0300 (EEST) 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 6601868C3F2 for ; Sat, 15 Jul 2023 13:53:34 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 26F262404EC for ; Sat, 15 Jul 2023 12:53:34 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id KJA3j-eJ1QNI for ; Sat, 15 Jul 2023 12:53:33 +0200 (CEST) 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 B77E92404F5 for ; Sat, 15 Jul 2023 12:53:32 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 948BC3A2683 for ; Sat, 15 Jul 2023 12:46:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:59 +0200 Message-Id: <20230715104611.17902-35-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 35/47] fftools/cmdutils: constify the first parameter of filter_codec_opts() 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: zaSD2pLSEw9r --- fftools/cmdutils.c | 2 +- fftools/cmdutils.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 330b9c2aba..137e69f2c3 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -943,7 +943,7 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec) return ret; } -AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, +AVDictionary *filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, const AVCodec *codec) { AVDictionary *ret = NULL; diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index 210d52e998..7e7fb700b7 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -335,7 +335,7 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec); * If null, the default one is looked up according to the codec id. * @return a pointer to the created dictionary */ -AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, +AVDictionary *filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, const AVCodec *codec); /** From patchwork Sat Jul 15 10:46:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42734 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4241619pzb; Sat, 15 Jul 2023 03:54:13 -0700 (PDT) X-Google-Smtp-Source: APBJJlGZu0pfCnD4FXxew6KYOrP24cumde8+fIOC9qQttWjlhutbVUhRnMwzTo+d8SOlOfuzMT23 X-Received: by 2002:a17:906:314c:b0:957:1df0:9cbf with SMTP id e12-20020a170906314c00b009571df09cbfmr5049423eje.19.1689418452731; Sat, 15 Jul 2023 03:54:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418452; cv=none; d=google.com; s=arc-20160816; b=tVPq3pW1Usa2z0h5hYY4Yri2xt9CKkUgDwx26tL/mngFiwPs/ZjJjSO0UeVfoweWdh /r09cTMuVc7SATppJ4Pm/TCQCblH33SuDBHHptnKhgUaJTi01+ytXEmuzBOWyz7a+5vo k23ODHMqNjKeGZiIrcOSWa7u4HbMofOH5E5mbFtHMiFlovmHczCnAbGigl+Zkp+zYOV5 xLF55/AItG0DWI7VtmIVy6hjzywnX+KNsXNgqh96uxHiX+h5dn+fFREva3HOuNHILXTD uae6w13rsenhxjTnz3LzqrYOv04e6m8MqFBBuFcgXLlPjxjUMYQfKF462576uDF5IYP1 RNwQ== 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=PpA3eohRlzZHVZaKUdgjXW+GcsfVjSaITt2hMUzQV1c=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=oCJ144FUfitPCUmHgd4NLQXRDWrtMeuT2wDTbSV6DtBfbwQdeDziGadRrroANzfErA mjD5GGNB76hfgnj19+HYoc8MdZqgRSxvw2kLHaUOxoBGOLNZQSnIP4rw9w5aNpyBObbW G9GTXMlGskIIWqfGvYnvndDSO+kKeWfGZgVpSUJ6z7ZgCiT8a65AMxCuyxV3jLH3mU5r WrFu0EiyaS7Vn2c7Oy8vV9yw6AYoaq8Gk+vWi7jzLvNBEk6XIkjw2ejR2BizqoRqkia9 l4spgUJDUxtTBfMYG5N3lxws6xlPZfdBULJkymbI6CyBebFsSt1UMR2cpZSGauwCaA7u EjJw== 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 k22-20020a170906a39600b0099279b2cdd5si10503849ejz.825.2023.07.15.03.54.12; Sat, 15 Jul 2023 03:54:12 -0700 (PDT) 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 963B268C773; Sat, 15 Jul 2023 13:53:44 +0300 (EEST) 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 B43C968C744 for ; Sat, 15 Jul 2023 13:53:36 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 727A92404F8 for ; Sat, 15 Jul 2023 12:53:36 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id X12wcy57B6G6 for ; Sat, 15 Jul 2023 12:53:34 +0200 (CEST) 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 A93A32404EA for ; Sat, 15 Jul 2023 12:53:32 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9F7053A26F1 for ; Sat, 15 Jul 2023 12:46:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:46:00 +0200 Message-Id: <20230715104611.17902-36-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 36/47] fftools/cmdutils: add error handling to filter_codec_opts() 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: OTxFRtX/Mqu+ --- fftools/cmdutils.c | 41 ++++++++++++++++++++++++++------------- fftools/cmdutils.h | 8 +++++--- fftools/ffmpeg_demux.c | 5 ++++- fftools/ffmpeg_mux_init.c | 11 ++++++++--- fftools/ffplay.c | 6 +++++- fftools/ffprobe.c | 8 ++++++-- 6 files changed, 56 insertions(+), 23 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 137e69f2c3..9d9d8d44a6 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -943,8 +943,9 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec) return ret; } -AVDictionary *filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id, - AVFormatContext *s, AVStream *st, const AVCodec *codec) +int filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id, + AVFormatContext *s, AVStream *st, const AVCodec *codec, + AVDictionary **dst) { AVDictionary *ret = NULL; const AVDictionaryEntry *t = NULL; @@ -977,12 +978,16 @@ AVDictionary *filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_i char *p = strchr(t->key, ':'); /* check stream specification in opt name */ - if (p) - switch (check_stream_specifier(s, st, p + 1)) { - case 1: *p = 0; break; - case 0: continue; - default: exit_program(1); - } + if (p) { + int err = check_stream_specifier(s, st, p + 1); + if (err < 0) { + av_dict_free(&ret); + return err; + } else if (!err) + continue; + + *p = 0; + } if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) || !codec || @@ -998,14 +1003,16 @@ AVDictionary *filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_i if (p) *p = ':'; } - return ret; + + *dst = ret; + return 0; } int setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts, AVDictionary ***dst) { - int i; + int ret; AVDictionary **opts; *dst = NULL; @@ -1017,11 +1024,19 @@ int setup_find_stream_info_opts(AVFormatContext *s, if (!opts) return AVERROR(ENOMEM); - for (i = 0; i < s->nb_streams; i++) - opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id, - s, s->streams[i], NULL); + for (int i = 0; i < s->nb_streams; i++) { + ret = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id, + s, s->streams[i], NULL, &opts[i]); + if (ret < 0) + goto fail; + } *dst = opts; return 0; +fail: + for (int i = 0; i < s->nb_streams; i++) + av_dict_free(&opts[i]); + av_freep(&opts); + return ret; } int grow_array(void **array, int elem_size, int *size, int new_size) diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index 7e7fb700b7..97e49850c5 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -333,10 +333,12 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec); * @param st A stream from s for which the options should be filtered. * @param codec The particular codec for which the options should be filtered. * If null, the default one is looked up according to the codec id. - * @return a pointer to the created dictionary + * @param dst a pointer to the created dictionary + * @return a non-negative number on success, a negative error code on failure */ -AVDictionary *filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id, - AVFormatContext *s, AVStream *st, const AVCodec *codec); +int filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id, + AVFormatContext *s, AVStream *st, const AVCodec *codec, + AVDictionary **dst); /** * Setup AVCodecContext options for avformat_find_stream_info(). diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index a41b59ceb8..d612c5f434 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -1176,7 +1176,10 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st) if (ret < 0) return ret; - ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id, ic, st, ist->dec); + ret = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id, + ic, st, ist->dec, &ist->decoder_opts); + if (ret < 0) + return ret; ist->reinit_filters = -1; MATCH_PER_STREAM_OPT(reinit_filters, i, ist->reinit_filters, ic, st); diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 92d62c7b89..63d86209ff 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1217,8 +1217,10 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, const char *enc_stats_pre = NULL, *enc_stats_post = NULL, *mux_stats = NULL; const char *enc_time_base = NULL; - ost->encoder_opts = filter_codec_opts(o->g->codec_opts, enc->codec_id, - oc, st, enc->codec); + ret = filter_codec_opts(o->g->codec_opts, enc->codec_id, + oc, st, enc->codec, &ost->encoder_opts); + if (ret < 0) + return ret; MATCH_PER_STREAM_OPT(presets, str, preset, oc, st); ost->autoscale = 1; @@ -1316,7 +1318,10 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, ost->enc_timebase = q; } } else { - ost->encoder_opts = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st, NULL); + ret = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st, + NULL, &ost->encoder_opts); + if (ret < 0) + return ret; } diff --git a/fftools/ffplay.c b/fftools/ffplay.c index 4e26b3309d..df20c6a29d 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -2584,7 +2584,11 @@ static int stream_component_open(VideoState *is, int stream_index) if (fast) avctx->flags2 |= AV_CODEC_FLAG2_FAST; - opts = filter_codec_opts(codec_opts, avctx->codec_id, ic, ic->streams[stream_index], codec); + ret = filter_codec_opts(codec_opts, avctx->codec_id, ic, + ic->streams[stream_index], codec, &opts); + if (ret < 0) + goto fail; + if (!av_dict_get(opts, "threads", NULL, 0)) av_dict_set(&opts, "threads", "auto", 0); if (stream_lowres) diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index ba55437760..da8fc89830 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -3421,8 +3421,12 @@ static int open_input_file(InputFile *ifile, const char *filename, continue; } { - AVDictionary *opts = filter_codec_opts(codec_opts, stream->codecpar->codec_id, - fmt_ctx, stream, codec); + AVDictionary *opts; + + err = filter_codec_opts(codec_opts, stream->codecpar->codec_id, + fmt_ctx, stream, codec, &opts); + if (err < 0) + exit(1); ist->dec_ctx = avcodec_alloc_context3(codec); if (!ist->dec_ctx) From patchwork Sat Jul 15 10:46:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42713 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239956pzb; Sat, 15 Jul 2023 03:49:32 -0700 (PDT) X-Google-Smtp-Source: APBJJlGL4yCO1V5GoWQjlHPgAVucy8dfRFCzPNELiQg/V2bzz7bLTnkDTHBOeKVE95e1/rS8tCHl X-Received: by 2002:a17:906:3f5c:b0:98e:b48:24fc with SMTP id f28-20020a1709063f5c00b0098e0b4824fcmr6065042ejj.51.1689418172646; Sat, 15 Jul 2023 03:49:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418172; cv=none; d=google.com; s=arc-20160816; b=Up2/25I4iZDx7szbo9wMv3vti7/5iXv0RVok12uj5FtjgK/0i+Nvbetisvsl7cBGVJ vtO7DCOsWDkhsb4w7qpYM7zUsoGA6DNhaCa8PFqBXx0P4VSo85xtqlSLGJHCA1TSyQ1b J9h2/M/WA9SbWjaBu02KidaR7+YOV3oUo0g2mT11OGNBqrE6WEm0Af+Xdxr9uPAKRvzj IUGOil2t261CqZNZyzxTmHOMquvTmjLqueyDRD/e4FDP6DCXZ3r6vvgEFNthPoOdzxqv 4N3I1vEWEkobc4yRf0bIUDl6bzlD0VM+jO4Buu1Wi78KJCRlefo6Sy/YzOzQdPmdCSKg 0Fbw== 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=1opk777aiQ1IgF0c1iWjkjsYmZafEqJsH3+p7TrhVd0=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=SkQViInwXSU5v/BoK96DtK2xpFPUYm5WMz3Q09u+3YRkpVYp/I8Rlq/JQjdOgmxJ8G G5oDQIjGjqSc4smncENoOFc8zc1ycA02T/yzjMDwhRzlcjgyNAmQrKqpJJvKNPerAnBi L9hB6XFNV1j9ionkNwDx5LwfsmWqk5K+whhPwQSriqA6RQXo+3De0mR0PZ0fBr3Bhv1u +5yt7bX5p9Q1jMU8knz6bTB6mI76q1Iiv4HpPSgSyRdJ3pRPtNEzOCeVJZpRoHVP/QnR 7IkTWSw5LncBpB8Aw/q3J3D0dw7D0JN7scoCRjJ2DubgtIDzDnJZtS7XwNDanuAglIZL JivQ== 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 us12-20020a170906bfcc00b00992ee70a0afsi9985292ejb.12.2023.07.15.03.49.32; Sat, 15 Jul 2023 03:49:32 -0700 (PDT) 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 F2B8468C713; Sat, 15 Jul 2023 13:46:55 +0300 (EEST) 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 5871168C680 for ; Sat, 15 Jul 2023 13:46:40 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 231BA2404EA for ; Sat, 15 Jul 2023 12:46:40 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 3MTLqBxZ6XCb for ; Sat, 15 Jul 2023 12:46:39 +0200 (CEST) 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 1490E240D27 for ; Sat, 15 Jul 2023 12:46:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id AB0CA3A2788 for ; Sat, 15 Jul 2023 12:46:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:46:01 +0200 Message-Id: <20230715104611.17902-37-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 37/47] fftools/ffmpeg_opt: consolidate printing errors in ffmpeg_parse_options() 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: zBfiQObPZLWK --- fftools/ffmpeg_opt.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 44a6b49ed7..14b292f202 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1289,6 +1289,7 @@ static int open_files(OptionGroupList *l, const char *inout, int ffmpeg_parse_options(int argc, char **argv) { OptionParseContext octx; + const char *errmsg = NULL; int ret; memset(&octx, 0, sizeof(octx)); @@ -1297,14 +1298,14 @@ int ffmpeg_parse_options(int argc, char **argv) ret = split_commandline(&octx, argc, argv, options, groups, FF_ARRAY_ELEMS(groups)); if (ret < 0) { - av_log(NULL, AV_LOG_FATAL, "Error splitting the argument list: "); + errmsg = "splitting the argument list"; goto fail; } /* apply global options */ ret = parse_optgroup(NULL, &octx.global_opts); if (ret < 0) { - av_log(NULL, AV_LOG_FATAL, "Error parsing global options: "); + errmsg = "parsing global options"; goto fail; } @@ -1314,21 +1315,21 @@ int ffmpeg_parse_options(int argc, char **argv) /* open input files */ ret = open_files(&octx.groups[GROUP_INFILE], "input", ifile_open); if (ret < 0) { - av_log(NULL, AV_LOG_FATAL, "Error opening input files: "); + errmsg = "opening input files"; goto fail; } /* create the complex filtergraphs */ ret = init_complex_filters(); if (ret < 0) { - av_log(NULL, AV_LOG_FATAL, "Error initializing complex filters.\n"); + errmsg = "initializing complex filters"; goto fail; } /* open output files */ ret = open_files(&octx.groups[GROUP_OUTFILE], "output", of_open); if (ret < 0) { - av_log(NULL, AV_LOG_FATAL, "Error opening output files: "); + errmsg = "opening output files"; goto fail; } @@ -1345,7 +1346,8 @@ int ffmpeg_parse_options(int argc, char **argv) fail: uninit_parse_context(&octx); if (ret < 0) { - av_log(NULL, AV_LOG_FATAL, "%s\n", av_err2str(ret)); + av_log(NULL, AV_LOG_FATAL, "Error %s: %s\n", + errmsg ? errmsg : "", av_err2str(ret)); } return ret; } From patchwork Sat Jul 15 10:46:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42728 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4240792pzb; Sat, 15 Jul 2023 03:51:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlFulHTE7uH51vYyK9Q7xDBojM440Ha9FIZplnfdLKOLypIXrzJx9Ial0h4r4NvxnZZlmRDa X-Received: by 2002:aa7:c9d6:0:b0:51e:4fa:14e9 with SMTP id i22-20020aa7c9d6000000b0051e04fa14e9mr6003280edt.29.1689418305282; Sat, 15 Jul 2023 03:51:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418305; cv=none; d=google.com; s=arc-20160816; b=ybSL0GlCapewenDMj49AmQdzKEUdLHCYp0Jy8ptyKL+I0EHbOqlLJoen6H9w3krlXj 3Sly/ueywYhQcvM13zwkt/i2K9hEOrT4VErBJSqOBbHfSvKqT1PGt+AultC++1iIz3oh Bhkyba7KWfX/3SGW6e7l512aGaQtMpKhNF7EkOonn5tBwBd9fLnkTEWhRaG/XK+Id+83 00duujGrrdLkIf1DgQ4qwY5EG3LEX276u/WcNnH16zAVdCZA/Cietmq6fhJfgpX2cYAR eJ76rHHvNCiebEe6luqTsxMlQTWbd3NBaRhIq7A1PMniK4Y0d5wVJpXqgOVnvGnO1UAZ EgZQ== 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=44pArjn+8noHB8a+1MJhbGojDttIaRsjefb5E4Y5uk8=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=LP9KWjhVzrqUeyX+e0oAga21N/RJ8tpyUVlAacP/6/yVcsXtlQBWU/kp6sTxIznHcl I3hzoUP5S3kgs01oSIBSU4VGfqXdF626snV5MdWKoIhm3XXe6PaoTasD1MSeUdeVSf++ lgxiTuGxBX5eCqc5aDVKC7d6oBJUNdaOyOTLs69tUG/QtKbL2f7mVB4/PLsbKDoNggKS tYuTG4pU19LhFmdplwDekFD9LNd3u9txVkL32gFqlCLs7wlpy/VgNoqlFatKO6jJ0CHW L0ryw/gUI/+4X2R0PpTOSIXgZKGHnn6sqHQjxkj0yLfD8m5puwmFyy7fRbEaht3BAVSM 24Tw== 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 l10-20020a056402344a00b0051ff079876fsi4804434edc.621.2023.07.15.03.51.44; Sat, 15 Jul 2023 03:51:45 -0700 (PDT) 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 AA7F068C78B; Sat, 15 Jul 2023 13:47:14 +0300 (EEST) 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 ADC4368C6D5 for ; Sat, 15 Jul 2023 13:46:49 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 72A412404EE for ; Sat, 15 Jul 2023 12:46:49 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id BmELu7B-Zgsd for ; Sat, 15 Jul 2023 12:46:43 +0200 (CEST) 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 1A0D2240D29 for ; Sat, 15 Jul 2023 12:46:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B6D533A27D9 for ; Sat, 15 Jul 2023 12:46:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:46:02 +0200 Message-Id: <20230715104611.17902-38-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 38/47] fftools/ffmpeg: consolidate exiting from main() on error 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: 1ZJ3at1JIZLB --- fftools/ffmpeg.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index b4ea52ac1d..0c5e553c72 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1339,17 +1339,19 @@ int main(int argc, char **argv) /* parse options and open all input/output files */ ret = ffmpeg_parse_options(argc, argv); if (ret < 0) - exit_program(1); + goto finish; if (nb_output_files <= 0 && nb_input_files == 0) { show_usage(); av_log(NULL, AV_LOG_WARNING, "Use -h to get full help or, even better, run 'man %s'\n", program_name); - exit_program(1); + ret = 1; + goto finish; } if (nb_output_files <= 0) { av_log(NULL, AV_LOG_FATAL, "At least one output file must be specified\n"); - exit_program(1); + ret = 1; + goto finish; } current_time = ti = get_benchmark_time_stamps(); @@ -1368,6 +1370,7 @@ int main(int argc, char **argv) ret = received_nb_signals ? 255 : err_rate_exceeded ? 69 : ret; +finish: exit_program(ret); return ret; } From patchwork Sat Jul 15 10:46:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42721 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4240389pzb; Sat, 15 Jul 2023 03:50:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlHdv1cXMPBdF0rg3TZ6t+/s+ZqIw9m60ObNvv12hUpOxElxH5guI07BI5i0J0x8i82Xa2Y5 X-Received: by 2002:a17:906:64d6:b0:993:d5e7:80f6 with SMTP id p22-20020a17090664d600b00993d5e780f6mr1613729ejn.5.1689418243348; Sat, 15 Jul 2023 03:50:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418243; cv=none; d=google.com; s=arc-20160816; b=XnxtC9dPZWLk6DAl9cD0RCOwPTjrDLAonK5IsrOrI3fvWfAzfvGynn12EQwP1743l/ UpykynL23IlhoCAdTrQpw2/5JXip/f/UfiAmjmPAGUkmP08c9DwdMRCUCnvSJYKtRdMA ttGgs1PEkfEYie4ZK7KTHb+UsrjwDt27+sBVR3b3Ku9GRx6UYNlF6JOoOxtJHv2Oy7Mo NNqy0pR4KxsOSB+UCS10XGTu1cXYZ8efws0wBwAW+xT6d7rB+dDfGgb7itJgx763luvA sk1ER8OWeyLp7m/c1ul/IOeZvCp6lsmT1Rt0y8Z8w7W8hgQWuHmKwNLnqLxWDNyJg+zG Ax2w== 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=yS+mHh/TPZNq8MgmjWouE7W8fJlZi4djcptNmNsIGTY=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=BGe+oYT6Gz8vp3q8PqPBjMRvexDTkBLaHZFSW8TxH3LafVq4OwC+ZOPl4MBG7nVJk2 0HZSElh0R50mnPCrj7k4UGVYiKpmY2nUt534OKnVvMSAbCy0A2ZR1GjAzClVSgXJ0bxq 6WxTXkOC0X2qeigADm4PO1d4Va/InMzIzsphlz0rRqDc8jLK7k0dj5WrVs8g8f1WziBH bJKClXfnJhfoeBLPZ1n3bA7VbWuK5YecEg1Agh1q0EvbDK6SEyPcG41jXbw22sU0UOkf Agz+IccWf4Xb9FwJ8TfKoySY6phXKX9o9VWmSeTNoPKhTD4/kH9YfOXUQJUTHvVwRrDV Mj4A== 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 g10-20020a17090613ca00b00992dce29d4csi10779952ejc.874.2023.07.15.03.50.42; Sat, 15 Jul 2023 03:50:43 -0700 (PDT) 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 CFDC568C75C; Sat, 15 Jul 2023 13:47:06 +0300 (EEST) 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 1FE9B68C6A6 for ; Sat, 15 Jul 2023 13:46:44 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id C9DFD2404EE for ; Sat, 15 Jul 2023 12:46:43 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id och-RHO0V2ef for ; Sat, 15 Jul 2023 12:46:43 +0200 (CEST) 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 156D7240D28 for ; Sat, 15 Jul 2023 12:46:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id C28A93A27F9 for ; Sat, 15 Jul 2023 12:46:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:46:03 +0200 Message-Id: <20230715104611.17902-39-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 39/47] fftools/cmdutils: return AVERROR_EXIT for OPT_EXIT options instead of aborting() 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: 5tp4dzhArePN --- fftools/cmdutils.c | 2 +- fftools/ffmpeg.c | 3 +++ fftools/ffmpeg_opt.c | 2 +- fftools/ffplay.c | 2 +- fftools/ffprobe.c | 2 +- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 9d9d8d44a6..f37b7d44d6 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -320,7 +320,7 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt, } } if (po->flags & OPT_EXIT) - exit_program(0); + return AVERROR_EXIT; return 0; } diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 0c5e553c72..50d6658472 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1371,6 +1371,9 @@ int main(int argc, char **argv) err_rate_exceeded ? 69 : ret; finish: + if (ret == AVERROR_EXIT) + ret = 0; + exit_program(ret); return ret; } diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 14b292f202..700db706a1 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1345,7 +1345,7 @@ int ffmpeg_parse_options(int argc, char **argv) fail: uninit_parse_context(&octx); - if (ret < 0) { + if (ret < 0 && ret != AVERROR_EXIT) { av_log(NULL, AV_LOG_FATAL, "Error %s: %s\n", errmsg ? errmsg : "", av_err2str(ret)); } diff --git a/fftools/ffplay.c b/fftools/ffplay.c index df20c6a29d..a491fdd9e3 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -3657,7 +3657,7 @@ int main(int argc, char **argv) ret = parse_options(NULL, argc, argv, options, opt_input_file); if (ret < 0) - exit(1); + exit(ret == AVERROR_EXIT ? 0 : 1); if (!input_filename) { show_usage(); diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index da8fc89830..c83d20995e 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -4129,7 +4129,7 @@ int main(int argc, char **argv) show_banner(argc, argv, options); ret = parse_options(NULL, argc, argv, options, opt_input_file); if (ret < 0) - exit_program(1); + exit_program(ret == AVERROR_EXIT ? 0 : 1); if (do_show_log) av_log_set_callback(log_callback); From patchwork Sat Jul 15 10:46:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42732 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4241532pzb; Sat, 15 Jul 2023 03:53:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlGMBLePxe4Rnun1CrXQeH57trkUm+CORb4QvmnSUm7rytEXu/kKqs/pFQP7r0iMJvUK2HQV X-Received: by 2002:a17:907:8a11:b0:993:e691:6dd5 with SMTP id sc17-20020a1709078a1100b00993e6916dd5mr7855900ejc.7.1689418437800; Sat, 15 Jul 2023 03:53:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418437; cv=none; d=google.com; s=arc-20160816; b=I0TIShc3ytKYoalgsvjgW1w1hQ+rpYSo47nhG7rn8789V59AqszWC1sYmw089ygy9+ /KvReVv4WpSeobga8NPac+4tuNSepkSrcr1Hjact7sn3Zr5ktvA7xZfdv2Lu71gXmkzD 10uwtAwvX3Hxpj/F1uBAckAD3fYwS575ztlhga0jOlDOUA9UWgu2+KyCZcdG0NFiUUNy lyzTbhPdGBOLXF6ZvzA5aNKkJ31C4pBBqN9gy7LRGTMphFwud3Efpnv5QZ7auni4A0Ir s2E5YZb6CH1Yaiw6UFmPMKvXr0i1SI25DIa/JwO1McfE7HWqAR7+XUZjgFxC/eIUr5zJ 1VUQ== 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=+JlccYz7PlMzgij+d2xbxPmOqBjPwp3cAp6n7T+pH7k=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=HqAGQJq3HljvIQx7B1m/VncCNSSEql82VYOJhJjjHo2AbzrDtMBp6XjTafMtmkJZR5 QUeZCMYP/XWjJXBAkIfYchFALU95TojIlLmFs3hakHPDkQAfUTm64Ml5gSACaoGRF/03 N8RKjuEssRwTlJRN0kHwu0yP9KJzYAuFcDg3bnXpg0nW51FsmQ0hAxyJaNPzjpFggEPK uHEh9+Z9OGgA53XjvBvvsat2kfxSdSRBG4Y3SJt5if8JZqIkIpxnAtMr1UdGS8lRW5fq XPRegaBYWAhNQs311bbeY7UzmV6xM03uJaE1dZCmlyCDEZMlFUjeOAEbUF8k/tZPgebZ gZXQ== 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 h8-20020a1709063c0800b009655fcff588si10877511ejg.835.2023.07.15.03.53.57; Sat, 15 Jul 2023 03:53:57 -0700 (PDT) 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 8A63568C751; Sat, 15 Jul 2023 13:53:42 +0300 (EEST) 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 752F968C716 for ; Sat, 15 Jul 2023 13:53:35 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 041BC2404F5 for ; Sat, 15 Jul 2023 12:53:35 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id RqiZD9xCiA7f for ; Sat, 15 Jul 2023 12:53:32 +0200 (CEST) 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 B67FB2404EE for ; Sat, 15 Jul 2023 12:53:32 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id CE6503A2812 for ; Sat, 15 Jul 2023 12:46:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:46:04 +0200 Message-Id: <20230715104611.17902-40-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 40/47] fftools/ffmpeg: return an error from assert_avoptions() instead of aborting 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: G/K0OMlTyRdD Rename it to check_avoptions(). --- fftools/ffmpeg.c | 6 ++++-- fftools/ffmpeg.h | 2 +- fftools/ffmpeg_dec.c | 5 ++++- fftools/ffmpeg_demux.c | 5 ++++- fftools/ffmpeg_enc.c | 5 ++++- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 50d6658472..ecb3f89f85 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -457,13 +457,15 @@ void remove_avoptions(AVDictionary **a, AVDictionary *b) } } -void assert_avoptions(AVDictionary *m) +int check_avoptions(AVDictionary *m) { const AVDictionaryEntry *t; if ((t = av_dict_get(m, "", NULL, AV_DICT_IGNORE_SUFFIX))) { av_log(NULL, AV_LOG_FATAL, "Option %s not found.\n", t->key); - exit_program(1); + return AVERROR_OPTION_NOT_FOUND; } + + return 0; } void update_benchmark(const char *fmt, ...) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 60dff87436..73baad238c 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -705,7 +705,7 @@ void term_exit(void); void show_usage(void); void remove_avoptions(AVDictionary **a, AVDictionary *b); -void assert_avoptions(AVDictionary *m); +int check_avoptions(AVDictionary *m); int assert_file_overwrite(const char *filename); char *file_read(const char *filename); diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index 62c1baf287..8a3b52fd7e 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -1119,7 +1119,10 @@ int dec_open(InputStream *ist) av_err2str(ret)); return ret; } - assert_avoptions(ist->decoder_opts); + + ret = check_avoptions(ist->decoder_opts); + if (ret < 0) + return ret; ret = dec_thread_start(ist); if (ret < 0) { diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index d612c5f434..48edbd7f6b 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -1511,7 +1511,10 @@ int ifile_open(const OptionsContext *o, const char *filename) if (scan_all_pmts_set) av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE); remove_avoptions(&o->g->format_opts, o->g->codec_opts); - assert_avoptions(o->g->format_opts); + + ret = check_avoptions(o->g->format_opts); + if (ret < 0) + return ret; /* apply forced codec ids */ for (i = 0; i < ic->nb_streams; i++) { diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 01e1b0656c..dde239657f 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -411,7 +411,10 @@ int enc_open(OutputStream *ost, AVFrame *frame) ost->sq_idx_encode, ost->enc_ctx->frame_size); } - assert_avoptions(ost->encoder_opts); + ret = check_avoptions(ost->encoder_opts); + if (ret < 0) + return ret; + if (ost->enc_ctx->bit_rate && ost->enc_ctx->bit_rate < 1000 && ost->enc_ctx->codec_id != AV_CODEC_ID_CODEC2 /* don't complain about 700 bit/s modes */) av_log(ost, AV_LOG_WARNING, "The bitrate parameter is set too low." From patchwork Sat Jul 15 10:46:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42729 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4240834pzb; Sat, 15 Jul 2023 03:51:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlGE69kIQ/aWe4oQtIP7JAvG4A7wTplfMts1gmlSKfPkMOAF6kZUuUC2SLGmVZO3xaUHgL3S X-Received: by 2002:a17:906:e17:b0:993:ffcb:ad4e with SMTP id l23-20020a1709060e1700b00993ffcbad4emr5368679eji.13.1689418313104; Sat, 15 Jul 2023 03:51:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418313; cv=none; d=google.com; s=arc-20160816; b=eYUPlekGQGUKJ900Z4M7TxjE1i293iRwCSOTany6qYBJZt5P4uZDFaziFxo3eEOHdH 0KGNRPyFlmZooh/VnqnTmijFmUqBI0A8D5PuTRVXo94G0mCEtPKciEOUWMFrYsOZ/SaF E2x79VxX3eVsx2LdU4MECp/uTQTfNXyu5RyNDcBRHsAk5DTCdEoB+TUR3rKHzzaJD4qt y5mowsxhFIPARz0dv1XVWznlC07wuI8+VvdWUUKcuIto6O0090iBfgdqic5UEN1DGeuF oED80opiwCjZXZ+NMI9HMX80vg5l/SPXbKVNucEVpUEkjWtysvlEDf4Jq3YI+tM5+m7s W+uw== 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=U9sI9RBzfjs6FHeEaPTJDUeX1XAh12rM8+HxTL3OLAI=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=hG2tR7TlbPv9JG84bU/0BtXoJTxSIOo9MM/lqOAmDz8FftzjjTXXmgdzpFok7lHk7P 0y3yyJML2tuBpjF0AmBNXCDLSQS8YoPd+CUviHeXRIDYmJajHdq10ZS5NRshwme3c3gK QbJNj3NErS6fU/13A3z9edBBTrF1TIkrslo4H06nkNuk0xDNMjyjpBdIx+QuXWJTcc4W rcxxyWyInU35WAUind4+/QrQsMk+KmAPSQcuH4qn3eseE2DXodajR0ONaL7K5bFrdfjS PhBvAUAF7pSFIia0uBt45yjKqf8boS1PmYsZQJBGKBLChY8is+f7FmSO0W5TS3SdaWZh dMrw== 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 br20-20020a170906d15400b009889d31227fsi10762690ejb.588.2023.07.15.03.51.52; Sat, 15 Jul 2023 03:51:53 -0700 (PDT) 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 4BE9668C794; Sat, 15 Jul 2023 13:47:16 +0300 (EEST) 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 ED00968C4C7 for ; Sat, 15 Jul 2023 13:46:49 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id AED842404F5 for ; Sat, 15 Jul 2023 12:46:49 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id muCD0XI_3bBV for ; Sat, 15 Jul 2023 12:46:49 +0200 (CEST) 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 34908240D2D for ; Sat, 15 Jul 2023 12:46:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id D9F253A281A for ; Sat, 15 Jul 2023 12:46:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:46:05 +0200 Message-Id: <20230715104611.17902-41-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 41/47] fftools/ffmpeg: return an error from MATCH_PER_STREAM_OPT() instead of aborting 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: KAzsAbpDtAGF --- fftools/ffmpeg.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 73baad238c..5c93b3aa29 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -912,7 +912,7 @@ static inline int err_merge(int err0, int err1) so = &o->name[_i];\ _matches++;\ } else if (_ret < 0)\ - exit_program(1);\ + return _ret;\ }\ if (_matches > 1)\ WARN_MULTIPLE_OPT_USAGE(name, type, so, st);\ From patchwork Sat Jul 15 10:46:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42726 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4240661pzb; Sat, 15 Jul 2023 03:51:21 -0700 (PDT) X-Google-Smtp-Source: APBJJlH3QDEIeOw4wBQFkXZyS/duhNdj2QPR1wjWhzai92TdBEyK1pyqvU7hFn/NEZ/jwtUuw/AV X-Received: by 2002:a17:906:5a45:b0:977:95f4:5cca with SMTP id my5-20020a1709065a4500b0097795f45ccamr6443451ejc.54.1689418281645; Sat, 15 Jul 2023 03:51:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418281; cv=none; d=google.com; s=arc-20160816; b=wvi4098I3Vi5ibFVMeLBOE4T3+WA88q0KJPaNVe8Tep5O1hPBGpuuRPtHxUHGeiAZP N9WT4S/qamSYL4mXrPYhP7q1hwCV8IwJVnLyaFR1WpGinmSSarN81GkHJlEK8jk6Vo0G 2WM9TJvWc6R/sSi6Cql5CoWoOelcOPLIue9+Dk1hCCI3CntcvlFbXu8r+2r6YOH1vMm1 +lYBkfbXk60XtdD2sGGGyg2g2spmXRnkfsm1pcUQZZ62E76xuMUs8uS+zUSEs6Oigl37 MidhRBWH+sC0IjrOSKIoDG/VZIAMT3R7K7lYzfsmbj8bR8Yr55GzUElu3S7Jn6V71bAK rEkA== 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=EW2Q0gtJgIWxdLG3CBUU5jT9sQnV2cyg9gnIO5EXagw=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=0ms+5VqPItr4XajCzuPfEw4a2vGM8UqJ+qMff4TBBnhkOJ3a/HJAJJmItgJT3H7waZ 3jV+mEPtNSbxAEtx3tYiFgGnOmmgJATevUkhOKXJpuOrv7a5ea5vELxy3ziGq9MTVoOC 4MbsdJgbqUnGQzhmfUGUIhs2ZHZutuOyn4CbsVUyMNGBJanxkgY7LV4dRTs1EvwUHGR5 Hxo7mVkDCebM8YYXPdGaCophaVxFonK1MMrBqwBsAcZeHIKZDbfOGXox36jGkyZdxPXC iRNSzVUeruP2DjLs9K+lg1Xww4OSVs0M7IVSFMdrxcIlFiPC7KJ6+1RlJpcQ7F4U3tkY XF6w== 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 b21-20020a1709062b5500b009924806cd01si9922709ejg.386.2023.07.15.03.51.21; Sat, 15 Jul 2023 03:51:21 -0700 (PDT) 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 A424868C77A; Sat, 15 Jul 2023 13:47:11 +0300 (EEST) 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 CB7F868C39F for ; Sat, 15 Jul 2023 13:46:47 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 8F1172404EE for ; Sat, 15 Jul 2023 12:46:47 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id AAh-ssdGVDZ4 for ; Sat, 15 Jul 2023 12:46:47 +0200 (CEST) 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 291E3240D2B for ; Sat, 15 Jul 2023 12:46:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id E57EF3A2832 for ; Sat, 15 Jul 2023 12:46:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:46:06 +0200 Message-Id: <20230715104611.17902-42-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 42/47] fftools/ffprobe: replace report_and_exit() with returning error codes 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: B+mY6UauZiKC --- fftools/ffprobe.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index c83d20995e..6180a5c952 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -3350,7 +3350,7 @@ static int open_input_file(InputFile *ifile, const char *filename, fmt_ctx = avformat_alloc_context(); if (!fmt_ctx) - report_and_exit(AVERROR(ENOMEM)); + return AVERROR(ENOMEM); if (!av_dict_get(format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) { av_dict_set(&format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE); @@ -3377,7 +3377,7 @@ static int open_input_file(InputFile *ifile, const char *filename, err = setup_find_stream_info_opts(fmt_ctx, codec_opts, &opts); if (err < 0) - report_and_exit(err); + return err; err = avformat_find_stream_info(fmt_ctx, opts); From patchwork Sat Jul 15 10:46:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42725 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4240600pzb; Sat, 15 Jul 2023 03:51:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlG+oWZ3JpT5YdM0JmJLFDFREb6Mcty+3bkg7Wr9RFCDVV9GMocxA50cSnht6G5K4iU2a+zk X-Received: by 2002:a17:906:7397:b0:994:18c4:3303 with SMTP id f23-20020a170906739700b0099418c43303mr6900078ejl.18.1689418274054; Sat, 15 Jul 2023 03:51:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418274; cv=none; d=google.com; s=arc-20160816; b=gcpCHP5K65YZSHlJSxfsn+dm6MaGVsUOKp1Z76WgQxbo63HJHojACKJFOE5L1RdZBW w9T3jSPtig9531ZUD1El2xDcFwnuTIFFJPVa+Ys/eZxdMkJ+1De9br9pHqsBr1C0OCS3 sGxrGIobizJJl4yh5oBwBV0m7YjMJl1XQiZUaE0lUn7mzFaR1bjk3/2IqAQgGXb5ozlY nKJpC6M/wD9kuGXT04lpCb2haahC49RoDztWZ2oniHhdfQMxtnbTD1wzlX+bvsVbQ1C+ rBFeLTbQxjFzEWcnX9oN66hEsttUQpQGOeNRtB/Je4IpOUXO14/4Chz02C4CQ/gBHwqG GJiA== 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=inkl//CimXe+vEr6A5prS2n/pZNdfIRD8UxxWkqROmg=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=NOAUfCvkTgNfbhOPgeNDKlvzdAJP6yqTCnjh7MA+KSXzJ2qgUbVdSh/9mjZDX3oaMt YPBqYNDKsTjG/sZQAn4qA+oVCq8yUBDAP71rc/eTc63H0sAbb1+QWUTvKXOP1v20chG3 K+Gji/4sifYNGSOa1Dtgpbz1IUEShNZnAbTv3Cf5n78eyZYB6594WsmJ4L3cSKK2e/aC dtr49fevJq0vppbPddTOh0uNiAG76lqpteXXzeItY17u4FaqoRPMZLGmuplZBvp8zjtD IRDt7MFm8Bdwn7Tpmofah3/aX3WvnmnIFKKPOgY1bpYDimAVdusVbhF4/BGX/2Z7fA5e GEIg== 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 r21-20020aa7d155000000b0051a53f2684fsi9554578edo.576.2023.07.15.03.51.13; Sat, 15 Jul 2023 03:51:14 -0700 (PDT) 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 B868068C773; Sat, 15 Jul 2023 13:47:10 +0300 (EEST) 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 51AC268C6D5 for ; Sat, 15 Jul 2023 13:46:47 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 050942404EE for ; Sat, 15 Jul 2023 12:46:47 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id ybc8HmtfxvU8 for ; Sat, 15 Jul 2023 12:46:46 +0200 (CEST) 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 2972A240D2C for ; Sat, 15 Jul 2023 12:46:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id F06333A283F for ; Sat, 15 Jul 2023 12:46:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:46:07 +0200 Message-Id: <20230715104611.17902-43-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 43/47] fftools/ffplay: replace report_and_exit() with returning an error code 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: TiNilOy3qVEg --- fftools/ffplay.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fftools/ffplay.c b/fftools/ffplay.c index a491fdd9e3..5212ad053e 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -2784,8 +2784,12 @@ static int read_thread(void *arg) int orig_nb_streams = ic->nb_streams; err = setup_find_stream_info_opts(ic, codec_opts, &opts); - if (err < 0) - report_and_exit(err); + if (err < 0) { + av_log(NULL, AV_LOG_ERROR, + "Error setting up avformat_find_stream_info() options\n"); + ret = err; + goto fail; + } err = avformat_find_stream_info(ic, opts); From patchwork Sat Jul 15 10:46:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42736 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4241694pzb; Sat, 15 Jul 2023 03:54:28 -0700 (PDT) X-Google-Smtp-Source: APBJJlHke1mhdk2Rln0TquGwUxmL0fLV25jWEE0wrcPl0oQQr8s6MBRlBaRr6tLz5gVXSW7AJMLi X-Received: by 2002:a17:907:724f:b0:974:183a:54b6 with SMTP id ds15-20020a170907724f00b00974183a54b6mr7949245ejc.33.1689418468461; Sat, 15 Jul 2023 03:54:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418468; cv=none; d=google.com; s=arc-20160816; b=EMwnoIM+8sjv25XkXCT3vKitDhLvUgoZaPNHTFDR3bm4MgUz7GTJEyAV32gdJKHasL diNM5jhcml0AvAL9otBzJ1chj1kZOCXYKkdkqAHZtOos9rNMDngSdEoTNP5OWddDdK+h 3hupprjkzFoO8/tGY7iXi4Eb6GMKBNny6nzZvWDdP12w6CkKacINsDo/AeTh8dScgWqb HaotnImaY1eTdxMB5WolWCNpxMh46Iyvw094heA6OEx9frNvHP2Fo33ZRUOdzHdMPLJv gWsqAP7FXxT/MlkF0hbMJZgo6+1UsWwsL8iHGNAd1f/W2SQvJfzfiLp9/bCKteoTTlqM oyYA== 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=Z49Aq2fdYVC+HRjaD+CdDOgUhTUsR8Ja/l8fM/j7eqc=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=P4S++B8PzWLhGgXLe2rqGJVgEdSnOaVZIvcBftan00uB2kq374uLlmxOA0Kw0/62kH cTTcsVnoHZ4h+15t3S2kiA79ykTh7zWaMNtYeE1eoNW99wBDpERe3s2CqSXeGVB5vn+z mBVV4fA/bsIWepoV8SMTKyrlX05iZpekwhbuviMsjT2eBn36/povmOAme+MCQ7JUt23C qfmgD5NhmR+zTGnS2FgdWjjdZSIWLc5dCI1cCUokzQVts1IVDEDrW4P6qWNjgpN0tahE fS/LRRoinXs/AyigOogwZB5OfSlSXcFCyZtKr+5BRQVJe5GlGkiyt0q3BpNikOB59hBE 2yRw== 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 j16-20020aa7c0d0000000b0051e2486c1ecsi10440312edp.252.2023.07.15.03.54.27; Sat, 15 Jul 2023 03:54:28 -0700 (PDT) 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 78ED068C78B; Sat, 15 Jul 2023 13:53:46 +0300 (EEST) 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 D4E3168C765 for ; Sat, 15 Jul 2023 13:53:38 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 58A602405B5 for ; Sat, 15 Jul 2023 12:53:38 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id ufbfeB8yV5Or for ; Sat, 15 Jul 2023 12:53:35 +0200 (CEST) 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 D1394240591 for ; Sat, 15 Jul 2023 12:53:32 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 0834E3A2848 for ; Sat, 15 Jul 2023 12:46:22 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:46:08 +0200 Message-Id: <20230715104611.17902-44-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 44/47] fftools/opt_common: replace report_and_exit() with returning an error code 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: 6rgBzzfy1yzP Remove report_and_exit(), as it has no more users. --- fftools/cmdutils.c | 6 ------ fftools/cmdutils.h | 11 ----------- fftools/opt_common.c | 10 +++++++--- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index f37b7d44d6..bceb778ff0 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -90,12 +90,6 @@ void register_exit(void (*cb)(int ret)) program_exit = cb; } -void report_and_exit(int ret) -{ - av_log(NULL, AV_LOG_FATAL, "%s\n", av_err2str(ret)); - exit_program(AVUNERROR(ret)); -} - void exit_program(int ret) { if (program_exit) diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index 97e49850c5..cc2180f768 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -54,17 +54,6 @@ extern int hide_banner; */ void register_exit(void (*cb)(int ret)); -/** - * Reports an error corresponding to the provided - * AVERROR code and calls exit_program() with the - * corresponding POSIX error code. - * @note ret must be an AVERROR-value of a POSIX error code - * (i.e. AVERROR(EFOO) and not AVERROR_FOO). - * library functions can return both, so call this only - * with AVERROR(EFOO) of your own. - */ -void report_and_exit(int ret) av_noreturn; - /** * Wraps exit with a program-specific cleanup routine. */ diff --git a/fftools/opt_common.c b/fftools/opt_common.c index 39258bb46c..913932c914 100644 --- a/fftools/opt_common.c +++ b/fftools/opt_common.c @@ -632,7 +632,7 @@ static int compare_codec_desc(const void *a, const void *b) strcmp((*da)->name, (*db)->name); } -static unsigned get_codecs_sorted(const AVCodecDescriptor ***rcodecs) +static int get_codecs_sorted(const AVCodecDescriptor ***rcodecs) { const AVCodecDescriptor *desc = NULL; const AVCodecDescriptor **codecs; @@ -641,7 +641,7 @@ static unsigned get_codecs_sorted(const AVCodecDescriptor ***rcodecs) while ((desc = avcodec_descriptor_next(desc))) nb_codecs++; if (!(codecs = av_calloc(nb_codecs, sizeof(*codecs)))) - report_and_exit(AVERROR(ENOMEM)); + return AVERROR(ENOMEM); desc = NULL; while ((desc = avcodec_descriptor_next(desc))) codecs[i++] = desc; @@ -666,7 +666,11 @@ static char get_media_type_char(enum AVMediaType type) int show_codecs(void *optctx, const char *opt, const char *arg) { const AVCodecDescriptor **codecs; - unsigned i, nb_codecs = get_codecs_sorted(&codecs); + unsigned i; + int nb_codecs = get_codecs_sorted(&codecs); + + if (nb_codecs < 0) + return nb_codecs; printf("Codecs:\n" " D..... = Decoding supported\n" From patchwork Sat Jul 15 10:46:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42730 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4241438pzb; Sat, 15 Jul 2023 03:53:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlG08DmiOVA9pNgNLuckpZ7jiCpOi9fja8dZQ7FrAeMBiActDXSeFb8zPMGmA5fpc2tNR9Vj X-Received: by 2002:a17:906:3f54:b0:988:f2ad:73e9 with SMTP id f20-20020a1709063f5400b00988f2ad73e9mr6396025ejj.52.1689418423366; Sat, 15 Jul 2023 03:53:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418423; cv=none; d=google.com; s=arc-20160816; b=noPwjesUvIXSreOMkXATFB6oBmYPwdLWriWAVLqtArkZ3bEgAsAmVeXvZl910dPaQt A2tZ7JxKvPsuFEjsge2Hm4H6y2/ESqMv+FfEgD0d/WmWNQhnIaaTVstqzvsf7euucDwO z+g801QFf0XdCL5Q8DiHwTfckyJq0ritai9gf+56ccOr54EwGaM18CLECiujCXe49Xc0 xk2/syv7RPZAkNFvk1xLZNF/2bbv1TYTEO88fhC1PN/jLRX2wyRMYiMTtJSyHErOl2KA 2DEOhgSkcYgL3pQbLNSvrkcWkZGM9UBqRub8grIJRJKTXgKzNWhWlVSZR11yIL1yrUrm QN8w== 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=LouBSy+BaVY9ciIU2FqmHj7ZbBnQv0de64PlzfRf3QE=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=uGTvagHIXsKL1Il//yDWXNu9P1LsJAVCgFHDQrOVdv5Ga/Nkii6Cx6n8zP8XjGat0I UwSfdb515n4QIwmZ0P/oM/78pl40s2iaZv63SuGzLz/Lydq1FOPWUVgwwAsV60t4VZv7 6VVVBT/dPbxJbtUIDFlSwZCdI9dRL8sdYf2G+LiB8YHsXhlj3Ohnx/rvvPhLKS7YeuMn yRjxAjVgU2fhTNf1upTUs4Y1voqhVRBCaC0qMv71wYdvdAmKEupCbylhqHDHTjfGOwPj laVAYz+RfsC8BBhQ6NbYTpCik2bVkM/rThLDPUCRaUPzIBAvUivrK5dE0uECOuhLh7od p+iQ== 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 z11-20020a170906814b00b0098cf3eaee4esi11124077ejw.57.2023.07.15.03.53.42; Sat, 15 Jul 2023 03:53:43 -0700 (PDT) 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 C55F968C6F7; Sat, 15 Jul 2023 13:53:40 +0300 (EEST) 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 9458068C3F2 for ; Sat, 15 Jul 2023 13:53:33 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 5231F2405EC for ; Sat, 15 Jul 2023 12:53:33 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id yd_4U_l8JNwP for ; Sat, 15 Jul 2023 12:53:32 +0200 (CEST) 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 B26802404EC for ; Sat, 15 Jul 2023 12:53:32 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 13B0C3A2858 for ; Sat, 15 Jul 2023 12:46:22 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:46:09 +0200 Message-Id: <20230715104611.17902-45-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 45/47] fftools/ffprobe: inline opt_output_file() into its only caller 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: Zx6hiET3xnRu There is no reason to keep them separate. Also, replace exit_program() with returning an error code. --- fftools/ffprobe.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index 6180a5c952..e234c92904 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -3795,22 +3795,18 @@ static int opt_input_file_i(void *optctx, const char *opt, const char *arg) return 0; } -static void opt_output_file(void *optctx, const char *arg) +static int opt_output_file_o(void *optctx, const char *opt, const char *arg) { if (output_filename) { av_log(NULL, AV_LOG_ERROR, "Argument '%s' provided as output filename, but '%s' was already specified.\n", arg, output_filename); - exit_program(1); + return AVERROR(EINVAL); } if (!strcmp(arg, "-")) arg = "fd:"; output_filename = arg; -} -static int opt_output_file_o(void *optctx, const char *opt, const char *arg) -{ - opt_output_file(optctx, arg); return 0; } From patchwork Sat Jul 15 10:46:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42727 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4240709pzb; Sat, 15 Jul 2023 03:51:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlG/jEXW5OWCnxQbA3q+b6Ojdb5K131tmgxhQJN2dhfPwV9FTjS4c8rP33xFLSrVUlOASIqy X-Received: by 2002:a17:906:257:b0:994:62ee:7531 with SMTP id 23-20020a170906025700b0099462ee7531mr1760729ejl.58.1689418289604; Sat, 15 Jul 2023 03:51:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418289; cv=none; d=google.com; s=arc-20160816; b=hOfiXRRIQWYAZATLGaWUQmLIvr6ocw7Fm2IMjJCXy01GYqxwh4LvQJBPca7HHe4cmW 0J61Bw8qp94c2RnGnEBWX2COF+aTA1IaA8mVTJtiFehXuaSaxCLHsHif4GzjIGpxiGLO Ykn2aizSfepateNO6VBY3Sv5SsQN8z9kOLujw24yhuce2dHOUHpg35U8Byx0BgtLipK5 wIeMBR+n9kPcqzdIz4WtGwJ707kEIK5aJdqOb/KJDv3Ek76FN7MHsWK51iJLyTpcZW1E Vmpa4ZFchjC3puMqdNxzZSnvyjWijDnR2F96tTS0rI95iitcjlXFiuHRfakgu4pR6p7p 7Ymg== 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=gGB9fG+INVBJQKveoViwsNKiyi4jobZygVVOIKOgXuU=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=Q2iM5khOpTHiYtfQnwSrGjiv+I7yQBH5OYVjzHAsjLQ/JiBGKZK4jHiZx0z+KuAbVK uh6furqXP3cF8vxj90GmAEnZxGJoJNt4DCZrI5SZk8ML0sbamkdRkknP9cvRmsviuAWf tbPD/FfSzGnrXULmSTE7DxZLCVAjfO9FjSfC61HldqRLynPelpV9+sNg35RR4S/4LO0z 1Hy2fw+gEWEGe4lCoqcN8HOf2DQx79XIRorF+MC5ThviX5T/43W5JiVcXZCfgXBSW7fu XI8HlngdFRQpW6MGiUVn/XGUjY7wNQxYs/IsI3H5Ui0MUu5zNckn1pxP+OgLztKs34Kx rkWA== 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 a23-20020a17090640d700b00988e89079fesi9993735ejk.167.2023.07.15.03.51.29; Sat, 15 Jul 2023 03:51:29 -0700 (PDT) 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 A695168C774; Sat, 15 Jul 2023 13:47:12 +0300 (EEST) 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 9BACF68C6C3 for ; Sat, 15 Jul 2023 13:46:48 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 50B7C2404EE for ; Sat, 15 Jul 2023 12:46:48 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 6ORR0NZI_UlZ for ; Sat, 15 Jul 2023 12:46:47 +0200 (CEST) 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 3A52F240D2F for ; Sat, 15 Jul 2023 12:46:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 1F3763A285C for ; Sat, 15 Jul 2023 12:46:22 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:46:10 +0200 Message-Id: <20230715104611.17902-46-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 46/47] fftools/ffprobe: stop calling exit_program() 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: ALDk9jZCTNha Inline the relevant part of ffprobe_cleanup() into main() and drop the rest. --- fftools/ffprobe.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index e234c92904..a39185f6fe 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -381,17 +381,6 @@ static void log_callback(void *ptr, int level, const char *fmt, va_list vl) #endif } -static void ffprobe_cleanup(int ret) -{ - int i; - for (i = 0; i < FF_ARRAY_ELEMS(sections); i++) - av_dict_free(&(sections[i].entries_to_show)); - -#if HAVE_THREADS - pthread_mutex_destroy(&log_mutex); -#endif -} - struct unit_value { union { double d; long long int i; } val; const char *unit; @@ -4113,7 +4102,6 @@ int main(int argc, char **argv) } #endif av_log_set_flags(AV_LOG_SKIP_REPEATED); - register_exit(ffprobe_cleanup); options = real_options; parse_loglevel(argc, argv, options); @@ -4124,8 +4112,10 @@ int main(int argc, char **argv) show_banner(argc, argv, options); ret = parse_options(NULL, argc, argv, options, opt_input_file); - if (ret < 0) - exit_program(ret == AVERROR_EXIT ? 0 : 1); + if (ret < 0) { + ret = AVERROR_EXIT ? 0 : ret; + goto end; + } if (do_show_log) av_log_set_callback(log_callback); @@ -4249,5 +4239,9 @@ end: avformat_network_deinit(); +#if HAVE_THREADS + pthread_mutex_destroy(&log_mutex); +#endif + return ret < 0; } From patchwork Sat Jul 15 10:46:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42712 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4240744pzb; Sat, 15 Jul 2023 03:51:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlEQPbcEBf9SqxdIKicJMskfIpYSKaQ7DxkX24WDCmQdCj0GfkpjsOq3uB1xiWsiAq6iBRAQ X-Received: by 2002:a05:6402:149a:b0:51a:5ebe:4ab9 with SMTP id e26-20020a056402149a00b0051a5ebe4ab9mr6065003edv.14.1689418297152; Sat, 15 Jul 2023 03:51:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418297; cv=none; d=google.com; s=arc-20160816; b=BaZNMBpCSKq7ZOU/hqXCxQIC25SNhy68pF5I/IL1GqnDin+tbPMo+sKtAM85xPR7HJ 4Bg4BPN9nh3Ussn3Udy3sVhEei3gsgDCgkf0dUDyX/zW3y8A8Vifu1deV2TsLzCQoRET D+/BL40uZbSMciKzX3O/RvBks13wEZVSQG6FkJ5QUnwA4JNRtY05xY0gJ5+Ft6yrK8Jt ulnEt1VorJwgZzFsRAqNlTLhMtxPwSSMNTJvfLhnmoA9ozHWRXUS/LbFKR3czUBeH35z P0E/fsz31Nk16OVaPfh2QzdxgHX0XDA1KBjT1OikxZW5E17UGkxbjZU7KdlP2SpAHESB AZPw== 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=2keHEIl7wGcoXRmu0P9I58ai+pzYhoEHHR1HTtOvzGk=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=CZw+vzJxSO/BGV7putO9bTQDmT+n1oLg1BY9iTHSstyH/+lIPfDwuxtSh3e7UeqeEW eY36A+HaEu/DBTKLGwcr1W0M3CIP/E3QEBDqP1AFK43MXOqYPql+n3XJBZLpYa6pmWDO 31g3KfXigNFW6Fi3O7OnuJFfExckzN/pxZvVof4JFR3toeezgn6uF2gjhk4oJBkVHuyO Qq+LPDiEBNoM18+A/JrOJZBCfXVW2EZOpJpaZ6ZdH3WAayO5WnVEn6GPiPicqK/nxp7l kabYJFIsKt8U92L8tZmvsJgSHEar08cukLAz9s408wE3lTueiLrChf/QwkQhZA3PV0dW NU4w== 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 be1-20020a0564021a2100b005203311fd98si3343579edb.131.2023.07.15.03.51.36; Sat, 15 Jul 2023 03:51:37 -0700 (PDT) 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 ACF2768C786; Sat, 15 Jul 2023 13:47:13 +0300 (EEST) 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 5E33468C6FD for ; Sat, 15 Jul 2023 13:46:49 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 1323F2404EE for ; Sat, 15 Jul 2023 12:46:49 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id biPTzPCnl5yL for ; Sat, 15 Jul 2023 12:46:48 +0200 (CEST) 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 3A2DB240D2E for ; Sat, 15 Jul 2023 12:46:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 2A31E3A2874 for ; Sat, 15 Jul 2023 12:46:22 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:46:11 +0200 Message-Id: <20230715104611.17902-47-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 47/47] fftools/ffmpeg: stop calling exit_program() 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: itmSzRxJcxJx Remove exit_program() and register_exit(), as they are no longer used. --- fftools/cmdutils.c | 15 --------------- fftools/cmdutils.h | 10 ---------- fftools/ffmpeg.c | 4 +--- 3 files changed, 1 insertion(+), 28 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index bceb778ff0..8a3b4bd285 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -83,21 +83,6 @@ void init_dynload(void) #endif } -static void (*program_exit)(int ret); - -void register_exit(void (*cb)(int ret)) -{ - program_exit = cb; -} - -void exit_program(int ret) -{ - if (program_exit) - program_exit(ret); - - exit(ret); -} - int parse_number(const char *context, const char *numstr, int type, double min, double max, double *dst) { diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index cc2180f768..4779b280fd 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -49,16 +49,6 @@ extern AVDictionary *swr_opts; extern AVDictionary *format_opts, *codec_opts; extern int hide_banner; -/** - * Register a program-specific cleanup routine. - */ -void register_exit(void (*cb)(int ret)); - -/** - * Wraps exit with a program-specific cleanup routine. - */ -void exit_program(int ret) av_noreturn; - /** * Initialize dynamic library loading */ diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index ecb3f89f85..6130fd06fc 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1324,8 +1324,6 @@ int main(int argc, char **argv) init_dynload(); - register_exit(ffmpeg_cleanup); - setvbuf(stderr,NULL,_IONBF,0); /* win32 runtime needs this */ av_log_set_flags(AV_LOG_SKIP_REPEATED); @@ -1376,6 +1374,6 @@ finish: if (ret == AVERROR_EXIT) ret = 0; - exit_program(ret); + ffmpeg_cleanup(ret); return ret; }