From patchwork Fri Oct 16 13:16:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 23013 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 1D0DC44A855 for ; Fri, 16 Oct 2020 16:22:57 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 020A068BA1D; Fri, 16 Oct 2020 16:22:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 185A068BA16 for ; Fri, 16 Oct 2020 16:22:50 +0300 (EEST) Received: by mail-ej1-f50.google.com with SMTP id dt13so3092937ejb.12 for ; Fri, 16 Oct 2020 06:22:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ApqY2GFm7cLyGPwYdGkrLON6omuMlw0vrZ9e2pLJyGM=; b=iogkdwcm6bEkDZKBFnOMt82+CYu/8ZpALgJc4rJiZF847kqkF4TmhZI7C3+lFsJ4vf ig36j4AP0hAn52njlOF5aEorIvavdgnN72AxoxVCjbQ+ovkQMeSsTouXFvrGNl2f2dDY HDvVhPVneg+5eCvIeWSeLYGJ0v5b0fypFksoMdTnQl0GfTUzj1QT7J7DPq4shg4sg0PF 05wTxQyANZ20eCUB6m5oRHsJTsEQ1Y+FTPbmzN9bSL87xXBzEaB9GwM1T0S4+reu15Hj oxVW0Yy8pm1XktFBxN4+w44f4uKPh8yK1Wx9Q3YJ722Z1z6LwMy7bjqlK3gLknNZaYJm pJpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ApqY2GFm7cLyGPwYdGkrLON6omuMlw0vrZ9e2pLJyGM=; b=CweYxohWnzH8pOrF1c8ALdXA/eoy0TE61aSTUWW08ryGrrG5Z400YOUuf/jgfNs6+6 CPaAa3FU5tO03dUyXQpQ1szmtoo2R8kL+AU2NtirshIqW4WISehDJXfPv3sfXFtcOsV6 1W+nwRUr+KeMou9qTL77lBTNSc01UmFIk6wUwhFOVBS+D46txWMAnfXE1ypp8kLs/lGH D8jMsurzj2VmFSwHBaa3KIDK8XLkCDn1xIC+JW79LmS+UzRvNKDreGVlATXMRf8+s9iI nE1Zz3T9BrYcqDx93GofeHH73+nOeNMNqVgPuaHoLE7UJArQH5tBW9rzTAx8Os+y68wU h7rQ== X-Gm-Message-State: AOAM533yyIlJszAvfdMknhyFlrfjxkA/GPN5K489blMBHsXkHIQ/9+JT 2AS2rp2Qcy3dsY4UoYLZJcVpa49l9Uk= X-Google-Smtp-Source: ABdhPJy6JV4/cUzos7nN449g1XxRfO/FGf1riNm5iClWYvSbTcywxIG7JsSvLwXTs2Xs9ImKM+oxRQ== X-Received: by 2002:a19:e015:: with SMTP id x21mr1471016lfg.586.1602854215916; Fri, 16 Oct 2020 06:16:55 -0700 (PDT) Received: from localhost.localdomain (n89ridqjqdjpsztph-2.v6.elisa-mobile.fi. [2001:999:11:8336:994:7f72:f89e:9125]) by smtp.gmail.com with ESMTPSA id x13sm280594lfe.101.2020.10.16.06.16.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Oct 2020 06:16:55 -0700 (PDT) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Fri, 16 Oct 2020 16:16:44 +0300 Message-Id: <20201016131649.4361-2-jeebjp@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201016131649.4361-1-jeebjp@gmail.com> References: <20201016131649.4361-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 1/6] ffmpeg: deduplicate init_output_stream usage logic X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Adds a wrapper function, which handles any errors depending on how fatal a failure would be. --- fftools/ffmpeg.c | 51 ++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 84306818a2..cb7644de6a 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1392,6 +1392,26 @@ static void do_video_stats(OutputStream *ost, int frame_size) static int init_output_stream(OutputStream *ost, char *error, int error_len); +static int init_output_stream_wrapper(OutputStream *ost, unsigned int fatal) +{ + int ret = AVERROR_BUG; + char error[1024] = {0}; + + if (ost->initialized) + return 0; + + ret = init_output_stream(ost, error, sizeof(error)); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "Error initializing output stream %d:%d -- %s\n", + ost->file_index, ost->index, error); + + if (fatal) + exit_program(1); + } + + return ret; +} + static void finish_output_stream(OutputStream *ost) { OutputFile *of = output_files[ost->file_index]; @@ -1428,15 +1448,7 @@ static int reap_filters(int flush) continue; filter = ost->filter->filter; - if (!ost->initialized) { - char error[1024] = ""; - ret = init_output_stream(ost, error, sizeof(error)); - if (ret < 0) { - av_log(NULL, AV_LOG_ERROR, "Error initializing output stream %d:%d -- %s\n", - ost->file_index, ost->index, error); - exit_program(1); - } - } + init_output_stream_wrapper(ost, 1); if (!ost->filtered_frame && !(ost->filtered_frame = av_frame_alloc())) { return AVERROR(ENOMEM); @@ -1860,7 +1872,6 @@ static void flush_encoders(void) // Maybe we should just let encoding fail instead. if (!ost->initialized) { FilterGraph *fg = ost->filter->graph; - char error[1024] = ""; av_log(NULL, AV_LOG_WARNING, "Finishing stream %d:%d without any data written to it.\n", @@ -1886,12 +1897,7 @@ static void flush_encoders(void) finish_output_stream(ost); } - ret = init_output_stream(ost, error, sizeof(error)); - if (ret < 0) { - av_log(NULL, AV_LOG_ERROR, "Error initializing output stream %d:%d -- %s\n", - ost->file_index, ost->index, error); - exit_program(1); - } + init_output_stream_wrapper(ost, 1); } if (enc->codec_type != AVMEDIA_TYPE_VIDEO && enc->codec_type != AVMEDIA_TYPE_AUDIO) @@ -3669,7 +3675,7 @@ static int transcode_init(void) if (output_streams[i]->filter) continue; - ret = init_output_stream(output_streams[i], error, sizeof(error)); + ret = init_output_stream_wrapper(output_streams[i], 0); if (ret < 0) goto dump_format; } @@ -4580,15 +4586,8 @@ static int transcode_step(void) } if (ost->filter && ost->filter->graph->graph) { - if (!ost->initialized) { - char error[1024] = {0}; - ret = init_output_stream(ost, error, sizeof(error)); - if (ret < 0) { - av_log(NULL, AV_LOG_ERROR, "Error initializing output stream %d:%d -- %s\n", - ost->file_index, ost->index, error); - exit_program(1); - } - } + init_output_stream_wrapper(ost, 1); + if ((ret = transcode_from_filter(ost->filter->graph, &ist)) < 0) return ret; if (!ist)