From patchwork Wed Jan 8 00:23:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 17244 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 1300144917A for ; Wed, 8 Jan 2020 02:27:17 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CF32168AD3D; Wed, 8 Jan 2020 02:27:16 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4DE796899EB for ; Wed, 8 Jan 2020 02:27:10 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 32CC4E3BD9; Wed, 8 Jan 2020 01:27:10 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id N7_n5gUpROMo; Wed, 8 Jan 2020 01:27:08 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 28A2CE1D3E; Wed, 8 Jan 2020 01:27:08 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Wed, 8 Jan 2020 01:23:39 +0100 Message-Id: <20200108002340.24949-1-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 Subject: [FFmpeg-devel] [PATCH 1/2] avformat/avio: fix ff_rename to respect used protocol 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: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Also simplify it, move it to avio.c and make it always log the error. This fixes for example the image2 muxer when used with an URL which also contains the protocol: ffmpeg -f lavfi -i testsrc -vframes 10 -atomic_writing 1 file:out%d.png Signed-off-by: Marton Balint --- libavformat/avio.c | 9 +++++++++ libavformat/internal.h | 20 ++++---------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/libavformat/avio.c b/libavformat/avio.c index 2dd2312296..65cfc0f4bb 100644 --- a/libavformat/avio.c +++ b/libavformat/avio.c @@ -26,6 +26,7 @@ #include "libavutil/avassert.h" #include "os_support.h" #include "avformat.h" +#include "internal.h" #if CONFIG_NETWORK #include "network.h" #endif @@ -665,3 +666,11 @@ int ff_check_interrupt(AVIOInterruptCB *cb) return cb->callback(cb->opaque); return 0; } + +int ff_rename(const char *url_src, const char *url_dst, void *logctx) +{ + int ret = avpriv_io_move(url_src, url_dst); + if (ret < 0) + av_log(logctx, AV_LOG_ERROR, "failed to rename file %s to %s: %s\n", url_src, url_dst, av_err2str(ret)); + return ret; +} diff --git a/libavformat/internal.h b/libavformat/internal.h index ec9a29907a..332477a532 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -580,25 +580,13 @@ int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *a int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src); /** - * Wrap errno on rename() error. + * Wrap avpriv_io_move and log if error happens. * - * @param oldpath source path - * @param newpath destination path + * @param url_src source path + * @param url_dst destination path * @return 0 or AVERROR on failure */ -static inline int ff_rename(const char *oldpath, const char *newpath, void *logctx) -{ - int ret = 0; - if (rename(oldpath, newpath) == -1) { - ret = AVERROR(errno); - if (logctx) { - char err[AV_ERROR_MAX_STRING_SIZE] = {0}; - av_make_error_string(err, AV_ERROR_MAX_STRING_SIZE, ret); - av_log(logctx, AV_LOG_ERROR, "failed to rename file %s to %s: %s\n", oldpath, newpath, err); - } - } - return ret; -} +int ff_rename(const char *url_src, const char *url_dst, void *logctx); /** * Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end From patchwork Wed Jan 8 00:23:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 17245 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 24FE244917A for ; Wed, 8 Jan 2020 02:27:19 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0ACAF68ADCD; Wed, 8 Jan 2020 02:27:19 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3F22C68AD08 for ; Wed, 8 Jan 2020 02:27:13 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id A84D7E3B1F; Wed, 8 Jan 2020 01:27:12 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KDj8mEMNdFyP; Wed, 8 Jan 2020 01:27:10 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id B8603E1D3E; Wed, 8 Jan 2020 01:27:10 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Wed, 8 Jan 2020 01:23:40 +0100 Message-Id: <20200108002340.24949-2-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200108002340.24949-1-cus@passwd.hu> References: <20200108002340.24949-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 2/2] avformat/dashenc: use ff_rename instead of avpriv_io_move 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: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" ff_rename always logs the error message. Signed-off-by: Marton Balint --- libavformat/dashenc.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index b84736881f..6b82ca9450 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -540,9 +540,7 @@ static void write_hls_media_playlist(OutputStream *os, AVFormatContext *s, dashenc_io_close(s, &c->m3u8_out, temp_filename_hls); if (use_rename) - if (avpriv_io_move(temp_filename_hls, filename_hls) < 0) { - av_log(os->ctx, AV_LOG_WARNING, "renaming file %s to %s failed\n\n", temp_filename_hls, filename_hls); - } + ff_rename(temp_filename_hls, filename_hls, os->ctx); } static int flush_init_segment(AVFormatContext *s, OutputStream *os) @@ -1037,7 +1035,7 @@ static int write_manifest(AVFormatContext *s, int final) dashenc_io_close(s, &c->mpd_out, temp_filename); if (use_rename) { - if ((ret = avpriv_io_move(temp_filename, s->url)) < 0) + if ((ret = ff_rename(temp_filename, s->url, s)) < 0) return ret; } @@ -1119,7 +1117,7 @@ static int write_manifest(AVFormatContext *s, int final) } dashenc_io_close(s, &c->m3u8_out, temp_filename); if (use_rename) - if ((ret = avpriv_io_move(temp_filename, filename_hls)) < 0) + if ((ret = ff_rename(temp_filename, filename_hls, s)) < 0) return ret; c->master_playlist_created = 1; } @@ -1619,7 +1617,7 @@ static int dash_flush(AVFormatContext *s, int final, int stream) dashenc_io_close(s, &os->out, os->temp_path); if (use_rename) { - ret = avpriv_io_move(os->temp_path, os->full_path); + ret = ff_rename(os->temp_path, os->full_path, os->ctx); if (ret < 0) break; }