From patchwork Sun Jan 5 13:14:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 17201 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 5F3F444B762 for ; Sun, 5 Jan 2020 15:14:41 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4B25A68AE72; Sun, 5 Jan 2020 15:14:41 +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 D5CA268ADD9 for ; Sun, 5 Jan 2020 15:14:34 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id B0A7CE314D; Sun, 5 Jan 2020 14:14:34 +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 0td2BJVjkxpU; Sun, 5 Jan 2020 14:14:32 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 3C9B0E377B; Sun, 5 Jan 2020 14:14:32 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 5 Jan 2020 14:14:13 +0100 Message-Id: <20200105131413.22707-6-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200105131413.22707-1-cus@passwd.hu> References: <20200105131413.22707-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 6/6] avformat: convert some avio_flush() calls to avio_write_marker(AVIO_DATA_MARKER_FLUSH_POINT) 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" Converting explicit avio_flush() calls helps us to buffer more data and avoid flushing the IO context too often which causes reduced IO throughput for non-streamed file output. The user can control FLUSH_POINT flushing behaviour using the -flush_packets option, the default typically means to flush unless a non-streamed file output is used, so this change should have no adverse effect on streaming even if it is assumed that after an avio_flush() the output buffer is clean so small seekbacks within the output buffer will work even when the IO context is not seekable. Signed-off-by: Marton Balint --- libavformat/asfenc.c | 3 ++- libavformat/matroskaenc.c | 2 +- libavformat/movenc.c | 8 ++++---- libavformat/mpegenc.c | 4 ++-- libavformat/mxfenc.c | 2 +- libavformat/oggenc.c | 2 +- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/libavformat/asfenc.c b/libavformat/asfenc.c index 8eaa9d40ce..73afb13200 100644 --- a/libavformat/asfenc.c +++ b/libavformat/asfenc.c @@ -892,7 +892,8 @@ static void flush_packet(AVFormatContext *s) avio_write(s->pb, asf->packet_buf, s->packet_size - packet_hdr_size); - avio_flush(s->pb); + avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT); + asf->nb_packets++; asf->packet_nb_payloads = 0; asf->packet_timestamp_start = -1; diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 4b6d14b435..71c9afb15c 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2235,7 +2235,7 @@ static void mkv_end_cluster(AVFormatContext *s) end_ebml_master_crc32(s->pb, &mkv->cluster_bc, mkv); mkv->cluster_pos = -1; - avio_flush(s->pb); + avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT); } static int mkv_check_new_extra_data(AVFormatContext *s, AVPacket *pkt) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index e20eea7571..1d9497283f 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -5152,7 +5152,7 @@ static int mov_flush_fragment(AVFormatContext *s, int force) if (mov->flags & FF_MOV_FLAG_DELAY_MOOV) { if (mov->flags & FF_MOV_FLAG_GLOBAL_SIDX) mov->reserved_header_pos = avio_tell(s->pb); - avio_flush(s->pb); + avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT); mov->moov_written = 1; return 0; } @@ -5176,7 +5176,7 @@ static int mov_flush_fragment(AVFormatContext *s, int force) mov->tracks[i].entry = 0; mov->tracks[i].end_reliable = 0; } - avio_flush(s->pb); + avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT); return 0; } @@ -5241,7 +5241,7 @@ static int mov_flush_fragment(AVFormatContext *s, int force) } if (write_moof) { - avio_flush(s->pb); + avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT); mov_write_moof_tag(s->pb, mov, moof_tracks, mdat_size); mov->fragments++; @@ -5273,7 +5273,7 @@ static int mov_flush_fragment(AVFormatContext *s, int force) mov->mdat_size = 0; - avio_flush(s->pb); + avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT); return 0; } diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c index f8039a42c0..669ff9d152 100644 --- a/libavformat/mpegenc.c +++ b/libavformat/mpegenc.c @@ -928,7 +928,7 @@ static int flush_packet(AVFormatContext *ctx, int stream_index, for (i = 0; i < zero_trail_bytes; i++) avio_w8(ctx->pb, 0x00); - avio_flush(ctx->pb); + avio_write_marker(ctx->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT); s->packet_number++; @@ -957,7 +957,7 @@ static void put_vcd_padding_sector(AVFormatContext *ctx) s->vcd_padding_bytes_written += s->packet_size; - avio_flush(ctx->pb); + avio_write_marker(ctx->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT); /* increasing the packet number is correct. The SCR of the following packs * is calculated from the packet_number and it has to include the padding diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index 396768d51f..374a83d069 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -1936,7 +1936,7 @@ static int mxf_write_partition(AVFormatContext *s, int bodysid, } if(key) - avio_flush(pb); + avio_write_marker(pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT); return 0; } diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c index 04f7813083..fe89f23e36 100644 --- a/libavformat/oggenc.c +++ b/libavformat/oggenc.c @@ -139,7 +139,7 @@ static int ogg_write_page(AVFormatContext *s, OGGPage *page, int extra_flags) return size; avio_write(s->pb, buf, size); - avio_flush(s->pb); + avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT); av_free(buf); oggstream->page_count--; return 0;