From patchwork Sun May 17 23:13:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19726 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 9F2F54489FD for ; Mon, 18 May 2020 02:14:00 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8B03A689F22; Mon, 18 May 2020 02:14:00 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 176F5689AD2 for ; Mon, 18 May 2020 02:13:54 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id j5so9735440wrq.2 for ; Sun, 17 May 2020 16:13:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=u5FyWnGHixXub6SEMrFQZzqZKl81tTikPRrpSbGSxEI=; b=ADhkHYGPuVBaRIRhsjCdrfKzbBLClcfjFIQpdXevSdLWEwPKa9HicdfyiylbWjOUNE zLTBeiikMCs+gq9worPWRCHvVOu7yGrRffzKCp9ih5y98Fk9TdFfkUzlxHoFdJHRQYyC tF0pd6ei65VmVNiKIl++zv7wSjBfQDLEOTUL3WvRAhEzagEWZG488pB/w64wNstk/aQg gGwPhu2QPocuDm6KzLKSNA8WW6QFgcYd+2grg69LoQe/IwOu3fRiOc8K1lPP08u6UDZF yQcS/v88niWn9M0oeA7t5js1q6oKJK9D8fqZj528I0lZW/q6fUSTXFEZvV+grQ9n1EXW Ak8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=u5FyWnGHixXub6SEMrFQZzqZKl81tTikPRrpSbGSxEI=; b=D6//UVSQY7gUnqnfmCLmJUpbCbmx+RFu/dl7TpOvXSmEn6eD3rjNX3vYpXupMlyyuH RWRTSXLqKZ3QIO0UQ9WLi/yc3WoOs7vMC9XaRugmoIwwiVfAwaHQ6FJr5fRznz8zDwXn hhpGUiJ+KZHvx+p0zawqns4Qtz5/v6ek15jsAtxJfXISeDK1lBy19Qh9fyhfs1/DuRax zdo5YT6MJWl/XpN57msK9LMh0oyhm7QFq+2bz/iZEmAPXLKyN0YP1GAUnOnBN4Y/gmRs yesA4KJu36IMQNW1s88THv10gqlXHI2ipwDlGja/vpNJbvG7UKXF9WlXFZYI/jRYda57 Xurg== X-Gm-Message-State: AOAM531ljIl3D2QuFWEtehqh94TQ1kb8DcSrs7d392KIfNxauHY1W0Yf jMlQPRuq7SJH3FF93k/gGYwvP6pg X-Google-Smtp-Source: ABdhPJzQ5YccBsANE0WiPnIYBgUWnmpMsFnz+/3rdpP3+HKF10gyblSAv3p/kBWMDH5wE7q9WmJcuA== X-Received: by 2002:adf:a285:: with SMTP id s5mr18046460wra.60.1589757233024; Sun, 17 May 2020 16:13:53 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id q144sm14700203wme.0.2020.05.17.16.13.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 May 2020 16:13:52 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 18 May 2020 01:13:19 +0200 Message-Id: <20200517231319.13067-6-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200517231319.13067-1-andreas.rheinhardt@gmail.com> References: <20200517231319.13067-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/6] avformat/webm_chunk: Open AVIOContext before initializing sub-muxer 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The description of AVOutputFormat.init contains the statement that "this method must not write output". Due to this, the webm_chunk muxer defers opening the AVIOContext for the child muxer until avformat_write_header(), i.e. there is no AVIOContext when the sub-muxer's avformat_init_output() is called. But this violates the documentation of said function which requires the AVFormatContext to have an already opened AVIOContext. This commit fixes this. Signed-off-by: Andreas Rheinhardt --- libavformat/webm_chunk.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/libavformat/webm_chunk.c b/libavformat/webm_chunk.c index 1749509975..f1bee5fa9f 100644 --- a/libavformat/webm_chunk.c +++ b/libavformat/webm_chunk.c @@ -44,6 +44,7 @@ typedef struct WebMChunkContext { uint64_t duration_written; int64_t prev_pts; AVFormatContext *avf; + int header_written; } WebMChunkContext; static int webm_chunk_init(AVFormatContext *s) @@ -101,6 +102,15 @@ static int webm_chunk_init(AVFormatContext *s) avpriv_set_pts_info(st, ost->pts_wrap_bits, ost->time_base.num, ost->time_base.den); + if (wc->http_method) + if ((ret = av_dict_set(&dict, "method", wc->http_method, 0)) < 0) + return ret; + ret = s->io_open(s, &oc->pb, oc->url, AVIO_FLAG_WRITE, &dict); + av_dict_free(&dict); + if (ret < 0) + return ret; + oc->pb->seekable = 0; + if ((ret = av_dict_set_int(&dict, "dash", 1, 0)) < 0 || (ret = av_dict_set_int(&dict, "cluster_time_limit", wc->chunk_duration, 0)) < 0 || @@ -147,19 +157,10 @@ static int webm_chunk_write_header(AVFormatContext *s) WebMChunkContext *wc = s->priv_data; AVFormatContext *oc = wc->avf; int ret; - AVDictionary *options = NULL; - if (wc->http_method) - if ((ret = av_dict_set(&options, "method", wc->http_method, 0)) < 0) - return ret; - ret = s->io_open(s, &oc->pb, oc->url, AVIO_FLAG_WRITE, &options); - av_dict_free(&options); - if (ret < 0) - return ret; - - oc->pb->seekable = 0; ret = avformat_write_header(oc, NULL); ff_format_io_close(s, &oc->pb); + wc->header_written = 1; if (ret < 0) return ret; return 0; @@ -270,7 +271,10 @@ static void webm_chunk_deinit(AVFormatContext *s) if (!wc->avf) return; - ffio_free_dyn_buf(&wc->avf->pb); + if (wc->header_written) + ffio_free_dyn_buf(&wc->avf->pb); + else + ff_format_io_close(s, &wc->avf->pb); avformat_free_context(wc->avf); wc->avf = NULL; }