From patchwork Sat Dec 4 17:41:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 31966 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp2275853iog; Sat, 4 Dec 2021 09:42:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzgQwo1rs2V1z7gBt94mDLNnOMGY4WaqC/Crdv1m0r0GKWZaKzlFdURNSuSUoUWPUpr+ZRB X-Received: by 2002:aa7:c9ce:: with SMTP id i14mr36409891edt.300.1638639749840; Sat, 04 Dec 2021 09:42:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638639749; cv=none; d=google.com; s=arc-20160816; b=v0G0gFZa50daoI+zRH8ZKnpqLXxkVnU6pvyx1zETM/RG4zfpajVja0Jqc/nEuKemdJ WfoledhnkesEAPGnH9PekJANU2iSDLBQ87XJWj2Di6KnHcGL4rrj7a+6S2fXp6c4FYod Gn8xp7tTrMfyow4m3cpDT1SzTVzQpPgov0J16w66HpM/U4i5p1ahLOn47CA1oINNv6SC hgDKn1FBqGK4e1jr6SPQqc52VyfuGStkXZ6CKlwLhqJcL3lAWCS5pU19/2Wbt8wxLfH9 i0SpUZR47D3E8I/YzL0CG4Fg1GRA38+wJlKstgCKJqm5SztcnL1tOg4nwl3FI2bmaEFs UYLw== 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=m464DtZLf97V1gcU4nwJEittsZBNqfpY1ZZuzjQc81U=; b=lIAMeTJ23aDX4dwo2carMdHfXO6flhbb33yaJ47vym0Fnc4XuPA8DyBdR+cFEiczsU b8Pfi2TFmCK5h/+rknXN+wqBNxihIBuBbed6rxMhevIGjb8bGrh5IB8VG6JM6YCc3mQL 6k8lVivHS3WeTLaJfPqPCMkfFuCXC1Qetr4IRLBG+F2PmzREHQakcrt3geMpiQmd41mj AqxKNqkCIPphQMbv3udLTICg9qiwKAvW3f0WbcNJzLMuBYxweYQX5XhXwm+uinJ+nbu7 pbJFamsj5UUDnTMd1Krsk6xj8VRxpxHI/Zh7BT889MfmrtGysk5vlR5lD3mpFEqLZZ0U BMkQ== 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 hv17si11333875ejc.37.2021.12.04.09.42.29; Sat, 04 Dec 2021 09:42:29 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D12A868AE87; Sat, 4 Dec 2021 19:41:52 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B8D8C68A807 for ; Sat, 4 Dec 2021 19:41:44 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 3909D24017E for ; Sat, 4 Dec 2021 18:41:44 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id FUX19EJ9Yx1x for ; Sat, 4 Dec 2021 18:41:43 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 63E6E240506 for ; Sat, 4 Dec 2021 18:41:41 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 395253A0769; Sat, 4 Dec 2021 18:41:41 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 4 Dec 2021 18:41:18 +0100 Message-Id: <20211204174118.19085-6-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211204174118.19085-1-anton@khirnov.net> References: <20211204174118.19085-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/6] ffmpeg: handle errors in print_sdp() 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: SX9m2CK4s1bk Do not continue as if nothing happened. --- fftools/ffmpeg.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 1936367463..11cdf69af0 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2764,17 +2764,17 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo return !eof_reached; } -static void print_sdp(void) +static int print_sdp(void) { char sdp[16384]; int i; - int j; + int j, ret; AVIOContext *sdp_pb; AVFormatContext **avc; for (i = 0; i < nb_output_files; i++) { if (!output_files[i]->header_written) - return; + return 0; } avc = av_malloc_array(nb_output_files, sizeof(*avc)); @@ -2787,26 +2787,34 @@ static void print_sdp(void) } } - if (!j) + if (!j) { + av_log(NULL, AV_LOG_ERROR, "No output streams in the SDP.\n"); + ret = AVERROR(EINVAL); goto fail; + } - av_sdp_create(avc, j, sdp, sizeof(sdp)); + ret = av_sdp_create(avc, j, sdp, sizeof(sdp)); + if (ret < 0) + goto fail; if (!sdp_filename) { printf("SDP:\n%s\n", sdp); fflush(stdout); } else { - if (avio_open2(&sdp_pb, sdp_filename, AVIO_FLAG_WRITE, &int_cb, NULL) < 0) { + ret = avio_open2(&sdp_pb, sdp_filename, AVIO_FLAG_WRITE, &int_cb, NULL); + if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Failed to open sdp file '%s'\n", sdp_filename); - } else { - avio_print(sdp_pb, sdp); - avio_closep(&sdp_pb); - av_freep(&sdp_filename); + goto fail; } + + avio_print(sdp_pb, sdp); + avio_closep(&sdp_pb); + av_freep(&sdp_filename); } fail: av_freep(&avc); + return ret; } static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat *pix_fmts) @@ -2962,8 +2970,13 @@ static int check_init_output_file(OutputFile *of, int file_index) av_dump_format(of->ctx, file_index, of->ctx->url, 1); nb_output_dumped++; - if (sdp_filename || want_sdp) - print_sdp(); + if (sdp_filename || want_sdp) { + ret = print_sdp(); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "Error writing the SDP.\n"); + return ret; + } + } /* flush the muxing queues */ for (i = 0; i < of->ctx->nb_streams; i++) {