From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 275544430E for ; Mon, 5 Sep 2022 21:17:17 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5D43668B9BD; Tue, 6 Sep 2022 00:17:05 +0300 (EEST) Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C763368B6D3 for ; Tue, 6 Sep 2022 00:16:58 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1662412618; bh=B2c36yrJlkmngHZKn8wTcAbKfriFuaj1RVY8Wg8kdKk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=EXdYuiyvXXpoRS8wTi7jjhzb6kVDK4ydv2Mc1kyhkuLcNyntFIYIYVcdj/FSdJNsU 5jUIe0LDcTNOyfRIYC0iZmEtYE1uq6MPmm599e+G30W8UgR9pkX9IAiErof9nPk+8u 2RHbWC40rwkpLr0C4O230jVjZYTTDIbOJauwvZI8= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([94.134.107.163]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MNt0C-1okfWU0VBo-00OGx7; Mon, 05 Sep 2022 23:16:58 +0200 From: Lukas Fellechner To: ffmpeg-devel@ffmpeg.org Date: Mon, 5 Sep 2022 23:16:33 +0200 Message-Id: <20220905211634.1460-4-lukas.fellechner@gmx.net> X-Mailer: git-send-email 2.31.1.windows.1 In-Reply-To: <20220905211634.1460-1-lukas.fellechner@gmx.net> References: <20220905211634.1460-1-lukas.fellechner@gmx.net> MIME-Version: 1.0 X-Provags-ID: V03:K1:gzju6hxiR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NKgOEv69t9nefLfCIdq2VvF15DSYkDGzxr gV1VA+33sfJjbapwcFM3ZD+aUD5uigYAUJEwXgCpq5Y7xzgSjaLZqVC+ee9aS0SeBdiZs7VNG EJPuVwww3Rmw417S2wMPXgKF1QFG8TRhlQ2f9mX//LM9vAiYzTrmzgQPBIIHUWWCRkbxuqGev 8ZtgeXDNQw6U/aIxgZwT3rCkljYlVZa39xgQNM0akocO1kqwWycyKOFMVYsTKUAc7Powb21p+ hDo32n+SYzY/IAHe2OzSCgiAx/bEV2f5TulrNY4inVc9KES8vt/6A/gwbBHcPAG7b1Rk6ppH3 +2cAqoAntjm+y/Z7h2J1bFpdpuPvf2aeqBEpYYhN/5n96AMuDrW67VrGPPaJZLlNnaZ+oNa2H iB4e5ryc8dCTP7iqK7NaChxRb/ Subject: [FFmpeg-devel] [PATCH v4 3/4] lavf/dashdec: Prevent cross-thread avio_opts modification 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 Cc: Lukas Fellechner Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: open_url modifies the shared avio_opts dict (update cookies). This can cause problems during multithreaded initialization. To prevent this, I take a copy of avio_opts, use that in open_url, and copy the updated dict back afterwards. --- libavformat/dashdec.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 0532e2c918..19e657d836 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -156,6 +156,11 @@ typedef struct DASHContext { int init_threads; +#if HAVE_THREADS + /* Set during parallel initialization, to allow locking of avio_opts */ + pthread_mutex_t *init_mutex; +#endif + /* Flags for init section*/ int is_init_section_common_video; int is_init_section_common_audio; @@ -1699,7 +1704,32 @@ static int open_input(DASHContext *c, struct representation *pls, struct fragmen ff_make_absolute_url(url, c->max_url_size, c->base_url, seg->url); av_log(pls->parent, AV_LOG_VERBOSE, "DASH request for url '%s', offset %"PRId64"\n", url, seg->url_offset); - ret = open_url(pls->parent, &pls->input, url, &c->avio_opts, opts, NULL); + + AVDictionary *avio_opts = c->avio_opts; + +#if HAVE_THREADS + // If we are doing parallel initialization, take a snapshot of the avio_opts, + // and copy the modified dictionary ("cookies" updated) back, after the url is opened. + if (c->init_mutex) { + pthread_mutex_lock(c->init_mutex); + avio_opts = NULL; + ret = av_dict_copy(&avio_opts, c->avio_opts, 0); + pthread_mutex_unlock(c->init_mutex); + if (ret < 0) + goto cleanup; + } +#endif + + ret = open_url(pls->parent, &pls->input, url, &avio_opts, opts, NULL); + +#if HAVE_THREADS + if (c->init_mutex) { + pthread_mutex_lock(c->init_mutex); + av_dict_free(&c->avio_opts); + c->avio_opts = avio_opts; + pthread_mutex_unlock(c->init_mutex); + } +#endif cleanup: av_free(url); @@ -2192,7 +2222,7 @@ static int init_streams_multithreaded(AVFormatContext *s, int nstreams, int thre if (!avpriv_slicethread_create(&slice_thread, (void*)work_pool, &thread_worker, NULL, threads)) { av_free(work_pool); return AVERROR(ENOMEM); -} + } // alloc mutex and conditions c->init_mutex = create_mutex(); -- 2.28.0.windows.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".