From patchwork Sun Jun 18 22:02:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 4023 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.22.4 with SMTP id 4csp643813vsw; Sun, 18 Jun 2017 15:03:26 -0700 (PDT) X-Received: by 10.28.54.13 with SMTP id d13mr13864217wma.124.1497823406505; Sun, 18 Jun 2017 15:03:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497823406; cv=none; d=google.com; s=arc-20160816; b=syalNdsbBg9g4FfKATKaL+rh6SrcShUdctgH/aYIfdi/jxdWIL1niGdzRD3+OyPMYc 7KKGg0T1esygF05W6HMMddjTkkh+WMP5MELgQG0EpwOviqseOer8S7TcThFfyaGiogJZ CEp/83lHHuu1DwwQQjRA9IYvyfe3ClpyP3iCDDcylZFs/wInh/2H9S/4ZF/lH3vd+eiS wLbsSr6kq+zFkoi//yP0gEI5E6+07ctTBI+DbYMhrzH3lkOYVt/4/RyDRARD83JThx8H DTf47k8uU+36o/PxRnT48oUNGCCWnzVVNImlZDP1nVH3zkGVhWUPA5DE+/2Qgn2yE14e c9+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to:arc-authentication-results; bh=KudiDWdEeGvT52Mr8ZI+02XBozV9R6J9qwdm7PAC/8k=; b=wgFSji8zYmJtGENr0VrwKn2t5kW/on0HoSZrFU5WpV7YzrrxMHdwBmo/fiSmoBuG7o MWx55tVavEPkBOX0tHenV+K68Qh2Gs4MgQPtIemqhcDeX6YDdCscMaNruo+6Amma3Yej wz9a3m63/wmmadashbO4FvGCA224v/mHVJmdN9paAXXwXHyYCvkjhQlBp7f2VlbL7luM /3f/r5OMXr303KgA8uLSuP47Wr34bKl7bA9Wj2kSVIcutN7EoKxEOIxU28pDIuB/iK8f ffjqo1mOEeOboSywk90Ld5NEBQiw2yK0I/05QQoM3eHHfXY+a83rPtnyN5MGbSPoE+zP zofQ== 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 c65si4556630wmf.193.2017.06.18.15.03.26; Sun, 18 Jun 2017 15:03:26 -0700 (PDT) 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 888F068A322; Mon, 19 Jun 2017 01:03:07 +0300 (EEST) 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 3AF9768A2AD for ; Mon, 19 Jun 2017 01:03:01 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id A71B0103427; Mon, 19 Jun 2017 00:03:05 +0200 (CEST) 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 2+ydV6ZqU3uz; Mon, 19 Jun 2017 00:03:04 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id D827D10342A; Mon, 19 Jun 2017 00:03:03 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Mon, 19 Jun 2017 00:02:53 +0200 Message-Id: <20170618220254.21682-3-cus@passwd.hu> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20170618220254.21682-1-cus@passwd.hu> References: <20170618220254.21682-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 3/4] avformat: make flush_packets a tri-state and set it to -1 (auto) by default 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" If flushing is not disabled, then mux.c will signal the end of the packets with an AVIO_DATA_MARKER_FLUSH_POINT, and aviobuf will be able to decide to flush or not based on the preferred minimum packet size set by the used protocol. Signed-off-by: Marton Balint --- doc/formats.texi | 7 ++++--- libavformat/mux.c | 12 +++++++++--- libavformat/options_table.h | 4 ++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/doc/formats.texi b/doc/formats.texi index c51d4086db..ddd7743548 100644 --- a/doc/formats.texi +++ b/doc/formats.texi @@ -182,9 +182,10 @@ Default is 0. Correct single timestamp overflows if set to 1. Default is 1. @item flush_packets @var{integer} (@emph{output}) -Flush the underlying I/O stream after each packet. Default 1 enables it, and -has the effect of reducing the latency; 0 disables it and may slightly -increase performance in some cases. +Flush the underlying I/O stream after each packet. Default is -1 (auto), which +means that the underlying protocol will decide, 1 enables it, and has the +effect of reducing the latency, 0 disables it and may increase IO throughput in +some cases. @item output_ts_offset @var{offset} (@emph{output}) Set the output time offset. diff --git a/libavformat/mux.c b/libavformat/mux.c index e1e49a81be..7c97b77881 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -479,8 +479,10 @@ static int write_header_internal(AVFormatContext *s) s->internal->write_header_ret = ret; if (ret < 0) return ret; - if (s->flush_packets && s->pb && s->pb->error >= 0 && s->flags & AVFMT_FLAG_FLUSH_PACKETS) + if ((s->flush_packets == 1 || s->flags & AVFMT_FLAG_FLUSH_PACKETS) && s->pb && s->pb->error >= 0) avio_flush(s->pb); + if (s->flush_packets && !(s->oformat->flags & AVFMT_NOFILE) && s->pb && s->pb->error >= 0) + avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT); } s->internal->header_written = 1; if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb) @@ -772,8 +774,10 @@ FF_ENABLE_DEPRECATION_WARNINGS } if (s->pb && ret >= 0) { - if (s->flush_packets && s->flags & AVFMT_FLAG_FLUSH_PACKETS) + if (s->flush_packets == 1 || s->flags & AVFMT_FLAG_FLUSH_PACKETS) avio_flush(s->pb); + if (s->flush_packets && !(s->oformat->flags & AVFMT_NOFILE)) + avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT); if (s->pb->error < 0) ret = s->pb->error; } @@ -932,8 +936,10 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt) return ret; } ret = s->oformat->write_packet(s, NULL); - if (s->flush_packets && s->pb && s->pb->error >= 0 && s->flags & AVFMT_FLAG_FLUSH_PACKETS) + if ((s->flush_packets == 1 || s->flags & AVFMT_FLAG_FLUSH_PACKETS) && s->pb && s->pb->error >= 0) avio_flush(s->pb); + if (s->flush_packets && !(s->oformat->flags & AVFMT_NOFILE) && s->pb && s->pb->error >= 0) + avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_FLUSH_POINT); if (ret >= 0 && s->pb && s->pb->error < 0) ret = s->pb->error; return ret; diff --git a/libavformat/options_table.h b/libavformat/options_table.h index 0c1915d6d4..118086df66 100644 --- a/libavformat/options_table.h +++ b/libavformat/options_table.h @@ -39,7 +39,7 @@ static const AVOption avformat_options[] = { {"probesize", "set probing size", OFFSET(probesize), AV_OPT_TYPE_INT64, {.i64 = 5000000 }, 32, INT64_MAX, D}, {"formatprobesize", "number of bytes to probe file format", OFFSET(format_probesize), AV_OPT_TYPE_INT, {.i64 = PROBE_BUF_MAX}, 0, INT_MAX-1, D}, {"packetsize", "set packet size", OFFSET(packet_size), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX, E}, -{"fflags", NULL, OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = AVFMT_FLAG_FLUSH_PACKETS | AVFMT_FLAG_AUTO_BSF }, INT_MIN, INT_MAX, D|E, "fflags"}, +{"fflags", NULL, OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = AVFMT_FLAG_AUTO_BSF }, INT_MIN, INT_MAX, D|E, "fflags"}, {"flush_packets", "reduce the latency by flushing out packets immediately", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_FLUSH_PACKETS }, INT_MIN, INT_MAX, E, "fflags"}, {"ignidx", "ignore index", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_IGNIDX }, INT_MIN, INT_MAX, D, "fflags"}, {"genpts", "generate pts", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_GENPTS }, INT_MIN, INT_MAX, D, "fflags"}, @@ -85,7 +85,7 @@ static const AVOption avformat_options[] = { {"use_wallclock_as_timestamps", "use wallclock as timestamps", OFFSET(use_wallclock_as_timestamps), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, D}, {"skip_initial_bytes", "set number of bytes to skip before reading header and frames", OFFSET(skip_initial_bytes), AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX-1, D}, {"correct_ts_overflow", "correct single timestamp overflows", OFFSET(correct_ts_overflow), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, D}, -{"flush_packets", "enable flushing of the I/O context after each packet", OFFSET(flush_packets), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, E}, +{"flush_packets", "enable flushing of the I/O context after each packet", OFFSET(flush_packets), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, E}, {"metadata_header_padding", "set number of bytes to be written as padding in a metadata header", OFFSET(metadata_header_padding), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, E}, {"output_ts_offset", "set output timestamp offset", OFFSET(output_ts_offset), AV_OPT_TYPE_DURATION, {.i64 = 0}, -INT64_MAX, INT64_MAX, E}, {"max_interleave_delta", "maximum buffering duration for interleaving", OFFSET(max_interleave_delta), AV_OPT_TYPE_INT64, { .i64 = 10000000 }, 0, INT64_MAX, E },