From patchwork Sun Sep 13 10:26:19 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: 22334 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 E48AA4495BC for ; Sun, 13 Sep 2020 13:49:43 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C61FF68BBEF; Sun, 13 Sep 2020 13:49:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2337168BA8F for ; Sun, 13 Sep 2020 13:49:38 +0300 (EEST) Received: by mail-ed1-f47.google.com with SMTP id a12so14734093eds.13 for ; Sun, 13 Sep 2020 03:49:38 -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=pVfqi3YS4Dl9pCkEP57Ebq/zQ5Dl8ExllEFoY9agfu2E44VVauv/8+G14ihumQlbKI uUjuxDq8hh3mmSkhVzhW1FMpZcVp5SAWUHvbElrG9JKQdCZDUFditGhywI3aYSlOuH4h 7WralKjbJLYvjtXP76u71hl/6RMePM/sI+aaPKvEgqYOEpqu8Le7Xzucc/orIQRE5ij+ 2POxsw8VlvKFrswUiXnkJ8IYgykBIxp3+kXsL3ZiYiBHlTtvvb4LZxRleTP5oLD2uHLX mqQjrKCDqiDIdM+prktdWhrncjisoigQbc5lebdZAb9IU6l87SdOsPOoJizM0dJoJsbI oKrQ== 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=pA50tOVn1Qj7+wbM/Fa0K0M/9RN4rxkWEyEiXlm+YP1428QS23m7zfKLBnQ1b8GOO+ fD6Mogx2S37tYtkpwJmM3uANVa8ZHxKFI1eRdzZ0NCJIOiJ/BMPCA+HEdyGeJjlJlmoz oMDDK0pya2gNeLUE/04jQ1Zry3sME1ZdIoNG6rEq9xcuuyDdRAjJn3g+2XbfVNsKZpm8 BGa6/OU+JOD1J/piVqzpqYZOitcnT20hi/VC4Udx+8CrueSBa+8LK6kAem/mmVwrGZae 4xFx3fZR5+cAcfQws29s9U9UAy4eKQy4/eVuSRLQZPjHWLaq/KrxrqErMK8jTCYnJxTs GqpA== X-Gm-Message-State: AOAM533JX8IMbPbo1agREIGBGBTvYLgqzeoEdFtPH1lq0yCu9dcyyMDW vhAdGdcs4ihh+ejhPPo0JBqIqPZH/nk= X-Google-Smtp-Source: ABdhPJzVxnyhNZVsQo0YcAs5WxMLp4byOoaCFmwtMad2XDrREUYtbxBKGo8luM4uc8TY0m+JiyddXg== X-Received: by 2002:a05:651c:484:: with SMTP id s4mr3630703ljc.391.1599992785702; Sun, 13 Sep 2020 03:26:25 -0700 (PDT) Received: from localhost.localdomain (91-159-194-103.elisa-laajakaista.fi. [91.159.194.103]) by smtp.gmail.com with ESMTPSA id n3sm2674790ljj.59.2020.09.13.03.26.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Sep 2020 03:26:25 -0700 (PDT) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Sun, 13 Sep 2020 13:26:19 +0300 Message-Id: <20200913102622.168011-2-jeebjp@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200913102622.168011-1-jeebjp@gmail.com> References: <20200913102622.168011-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4] 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)