From patchwork Fri Sep 11 16:11:04 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: 22289 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 99DCA44924E for ; Fri, 11 Sep 2020 19:18:51 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7714068BAE7; Fri, 11 Sep 2020 19:18:51 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 897C86806A5 for ; Fri, 11 Sep 2020 19:18:44 +0300 (EEST) Received: by mail-ed1-f48.google.com with SMTP id l63so10570026edl.9 for ; Fri, 11 Sep 2020 09:18:44 -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=Wy94XHh43QdRpAMlMz9vvWPTolHPAdoixD/kPsyTpJ972EIxi635bASr6Ts1wwN6MS Rdbwj/XHwHuKWrFcalUXczglKIuWmGpEgkNQn22hQGb5BPnaWUgn+JUtWkNS3vxslMJE lDvNHff0sl2Yaaw0UHn4kL+kYakbAi65SzNTRvRbBjzVl9FgFNS8NZjBVYFgywwbZg/n 0seYYF9H6idAfKCX7SfDDntiQUUzl2VaKGYTJK/44WKs195xiXqOs0pZ/nDLwjUD3brl 7WYgEnbod92QbbxfSI09u8YGr2Xy59s28ds01pQpBhpobZpJ/mqGpwCmjiWf6GY3B7NF oozg== 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=EqN0graiPV4pDcj7MyJApakh8a1hjOuD89w3b8Nn/zTmYtFMm+HM3nwBAnSy5wH0zn +TuKsPAdtI5XF4wqZ2YJfHQNxayx+zVrsFCGK6gTR/LwBJ91oRfASuMJNbyb1TWC/YVw nVqU9PxWa61tUg9YbH+a8n28hSPzxqHUMYSCHh+B5WhxvN15PfuovNUkNiPlJWUOS1L+ Ed1sQjO5Xc9yvZRV7PxFwd7hO00axMhJIJRJC7faqXTaEUqh/lqE/+lxZ8MM32uZIZ6K C/jwfEgi1BG8uSEpt/0k2j8nzigNV5nEvwQmQmMpObbZDXc9/XPytY45euG3hbqcBxBu 3Jkw== X-Gm-Message-State: AOAM5326USMc4zUaeptGifkJ1775DdcIeSP5g00RH857V9HEaHwS1Fh3 +3Z29Zkg4TCXjT63OLKn4UmK8j58qOM= X-Google-Smtp-Source: ABdhPJziMpXQpzdciStEVQ23KCBExKQfrwnLgrY/kAyk+erOn4pyQF17FAs7kxu/d/FFBCI+2+n/EQ== X-Received: by 2002:ac2:4311:: with SMTP id l17mr566991lfh.457.1599840669602; Fri, 11 Sep 2020 09:11:09 -0700 (PDT) Received: from localhost.localdomain (91-159-194-103.elisa-laajakaista.fi. [91.159.194.103]) by smtp.gmail.com with ESMTPSA id 193sm134285lfb.212.2020.09.11.09.11.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2020 09:11:09 -0700 (PDT) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Sep 2020 19:11:04 +0300 Message-Id: <20200911161107.24870-2-jeebjp@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200911161107.24870-1-jeebjp@gmail.com> References: <20200911161107.24870-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)