From patchwork Sun Nov 26 20:51:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 6367 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp881000jah; Sun, 26 Nov 2017 12:51:49 -0800 (PST) X-Google-Smtp-Source: AGs4zMZD9gtZUJEOUXW/JoDBIayf2pD9cR7cZmCUQ8cUKLDcwkWaJmD1rNrXOl70FTIaYLMk4MqQ X-Received: by 10.28.30.213 with SMTP id e204mr12182334wme.40.1511729508968; Sun, 26 Nov 2017 12:51:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511729508; cv=none; d=google.com; s=arc-20160816; b=Rlgh+EOfmXVp3pEzvn4muWZDp64WLP+P1O2eaawVf4nbjK66GaBVWVaIHhuT40bdV4 NBts0tmED3klism1b2GX9EgNU/6o2VWDyYRKFklxIIJJ+m+pnuyj/Tr1C2sq6hYIgpje nYKOxCh8w81DkQj9dYeiX92l9XFPwoRqsPXdyBwBCIt2RW8nKLVspJo2BEV79/Fxv0qs WHHvbgegDQbOsUnKVOHzLGLa/oo50ujOOBrQGkIhP6XMVCeGR5l6sPAxK7qcHHq/V2X8 exIqa1OPlKtny9U0pB3fbuq7rOE4NHGpguT0xVXgz5NphPKTFL7+4F6HmXdOTg14W3WP VZiQ== 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: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:dkim-signature:delivered-to:arc-authentication-results; bh=5kkd6GySX5uTLqx30Th9Cdj0VT/TJ7sTlzWIIdb8fTg=; b=MLAw5QTpX1W+3aWbQtk0+BJ7B8cqYkmGb+8sOVc9nBHhbnLUycCcZ+gSHjNeRTs39d 6o7DjfkIqBaNBD0yTH+YMLjebr726YacoI/coN3DsEPV4CrI9384exZbahTKk1zaNi5Q ud2aiJ7V3kuzzCNhIW7+k0S4DvfgKsxgZEthOmZzL4n1wqK+lPVz+jHJ8ZvH/lsWDC83 xkS2/ULRNWXiFjVloaMchgFaQdTYMyE/QLA9u6cFl6NS22FZAik19Uxu6AwqEx0IuH3v ASaBW57zEfkWvFprDjcBvsiYuFeimY5+vyxeqTuuzq8M+m/89Abg6f4AaESPtW37qlNs 9CiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=h9M9rzhg; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id n3si19998008wra.206.2017.11.26.12.51.48; Sun, 26 Nov 2017 12:51:48 -0800 (PST) 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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=h9M9rzhg; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7CE3268A23C; Sun, 26 Nov 2017 22:51:41 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk0-f195.google.com (mail-qk0-f195.google.com [209.85.220.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 697CD6804BC for ; Sun, 26 Nov 2017 22:51:33 +0200 (EET) Received: by mail-qk0-f195.google.com with SMTP id d125so30087375qkc.12 for ; Sun, 26 Nov 2017 12:51:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=i6urSpO65GLRyCmEVAkxuZ6eAkMsUKVVxD8gi6/n8fE=; b=h9M9rzhgDaT43GjLxjILds9ItSk483ERvY1pRJa3rIVSU1qY4kwg04bPq7i8a7ZdTP 1fc2B5IW8prgqdWnGOaZWp8csPTL7XqMF/IseBFSEPpOL3n38LMxzo6MKbgjurgaOsVq C1C0BgwdDr41bVLwhIZixXsE1yh6FTI/Vu9LeWEur9c05J/HStsanNb4YQkDVu9Q0Uya 9Sh6XUVr/Qsk8rVTegppRvgTI04vyoNTBKXKpMtq1/U18o52jWwNEG0MbHr6QaeUQEFk 6DxFpT+qJkRqtqoitd4PbvLEaZ6Tj98TSHkSyItLN4HbP77GmOJMF3kw1tXb0gSpxsv0 q/wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=i6urSpO65GLRyCmEVAkxuZ6eAkMsUKVVxD8gi6/n8fE=; b=nsNvz//l31VUXtrXDzAAFVEjJSiZHN5/EWLIYOOjkQfYiTmGeuUhcu2crdK4nJ079E A/eg3648t2k8M4KznFa4HDD4ShH/H4k/+YPAJyXu4z/SLoQ5lJlJL28Hu6/KU1MI95YR Mh8iTFn+Phj2SlC0KpjUKz2Uqge0Tdhy4sjLmhUm5DYk1l7WtIxEFtT6Eq6/yDsJtuaE G6ACTuMODjmAQc/a3JGBjdOrWj8SAJqWxjwP9CD1utj5x2N2y1yJlfJmDY5iDdXbMWVJ TyE52Mdxi6kredT99ybued0ZHjEsYJ3GYNdkypCtSPjIBfcOJd+1W4E18iQjR6v+3ql1 b+Qw== X-Gm-Message-State: AJaThX5g7nAsxiGZd19HOASBt+spwloFQoAqlKcT6kh8XxMISn+HXI+1 hqi9xbNzuYzH3tuu097MoWXmKw== X-Received: by 10.55.92.65 with SMTP id q62mr14875045qkb.154.1511729494130; Sun, 26 Nov 2017 12:51:34 -0800 (PST) Received: from localhost.localdomain ([181.231.59.220]) by smtp.gmail.com with ESMTPSA id g35sm15425640qtk.88.2017.11.26.12.51.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 26 Nov 2017 12:51:33 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Nov 2017 17:51:03 -0300 Message-Id: <20171126205104.1064-2-jamrial@gmail.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171126205104.1064-1-jamrial@gmail.com> References: <20171126205104.1064-1-jamrial@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/3] avformat/mux: stop delaying writing the header 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Every bitstream filter behaves as intended now, so there's no need to wait for the first packet of every stream. Signed-off-by: James Almer --- libavformat/avformat.h | 2 +- libavformat/internal.h | 6 ----- libavformat/mux.c | 52 ++++++++---------------------------------- libavformat/options_table.h | 2 +- libavformat/tests/fifo_muxer.c | 52 ------------------------------------------ tests/ref/fate/fifo-muxer-tst | 1 - 6 files changed, 12 insertions(+), 103 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 322210fae0..4f2798a871 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1449,7 +1449,7 @@ typedef struct AVFormatContext { #endif #define AVFMT_FLAG_FAST_SEEK 0x80000 ///< Enable fast, but inaccurate seeks for some formats #define AVFMT_FLAG_SHORTEST 0x100000 ///< Stop muxing when the shortest stream stops. -#define AVFMT_FLAG_AUTO_BSF 0x200000 ///< Wait for packet data before writing a header, and add bitstream filters as requested by the muxer +#define AVFMT_FLAG_AUTO_BSF 0x200000 ///< Add bitstream filters as requested by the muxer /** * Maximum size of the data read from input for determining diff --git a/libavformat/internal.h b/libavformat/internal.h index fcd47840a5..36a57214ce 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -120,12 +120,6 @@ struct AVFormatInternal { int avoid_negative_ts_use_pts; - /** - * Whether or not a header has already been written - */ - int header_written; - int write_header_ret; - /** * Timestamp of the end of the shortest stream. */ diff --git a/libavformat/mux.c b/libavformat/mux.c index b1244c67f3..ebb9102f11 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -458,25 +458,6 @@ static void flush_if_needed(AVFormatContext *s) } } -static int write_header_internal(AVFormatContext *s) -{ - if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb) - avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_HEADER); - if (s->oformat->write_header) { - int ret = s->oformat->write_header(s); - if (ret >= 0 && s->pb && s->pb->error < 0) - ret = s->pb->error; - s->internal->write_header_ret = ret; - if (ret < 0) - return ret; - flush_if_needed(s); - } - s->internal->header_written = 1; - if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb) - avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_UNKNOWN); - return 0; -} - int avformat_init_output(AVFormatContext *s, AVDictionary **options) { int ret = 0; @@ -515,11 +496,18 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options) if ((ret = avformat_init_output(s, options)) < 0) return ret; - if (!(s->oformat->check_bitstream && s->flags & AVFMT_FLAG_AUTO_BSF)) { - ret = write_header_internal(s); + if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb) + avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_HEADER); + if (s->oformat->write_header) { + int ret = s->oformat->write_header(s); + if (ret >= 0 && s->pb && s->pb->error < 0) + ret = s->pb->error; if (ret < 0) goto fail; + flush_if_needed(s); } + if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb) + avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_UNKNOWN); if (!s->internal->streams_initialized) { if ((ret = init_pts(s)) < 0) @@ -739,12 +727,6 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) } } - if (!s->internal->header_written) { - ret = s->internal->write_header_ret ? s->internal->write_header_ret : write_header_internal(s); - if (ret < 0) - goto fail; - } - if ((pkt->flags & AV_PKT_FLAG_UNCODED_FRAME)) { AVFrame *frame = (AVFrame *)pkt->data; av_assert0(pkt->size == UNCODED_FRAME_PACKET_SIZE); @@ -760,8 +742,6 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) ret = s->pb->error; } -fail: - if (ret < 0) { pkt->pts = pts_backup; pkt->dts = dts_backup; @@ -894,11 +874,6 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt) if (!pkt) { if (s->oformat->flags & AVFMT_ALLOW_FLUSH) { - if (!s->internal->header_written) { - ret = s->internal->write_header_ret ? s->internal->write_header_ret : write_header_internal(s); - if (ret < 0) - return ret; - } ret = s->oformat->write_packet(s, NULL); flush_if_needed(s); if (ret >= 0 && s->pb && s->pb->error < 0) @@ -1282,14 +1257,8 @@ int av_write_trailer(AVFormatContext *s) goto fail; } - if (!s->internal->header_written) { - ret = s->internal->write_header_ret ? s->internal->write_header_ret : write_header_internal(s); - if (ret < 0) - goto fail; - } - fail: - if (s->internal->header_written && s->oformat->write_trailer) { + if (s->oformat->write_trailer) { if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb) avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_TRAILER); if (ret >= 0) { @@ -1302,7 +1271,6 @@ fail: if (s->oformat->deinit) s->oformat->deinit(s); - s->internal->header_written = s->internal->initialized = s->internal->streams_initialized = 0; diff --git a/libavformat/options_table.h b/libavformat/options_table.h index b60d031f67..b8fa47c6fd 100644 --- a/libavformat/options_table.h +++ b/libavformat/options_table.h @@ -57,7 +57,7 @@ static const AVOption avformat_options[] = { {"seek2any", "allow seeking to non-keyframes on demuxer level when supported", OFFSET(seek2any), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, D}, {"bitexact", "do not write random/volatile data", 0, AV_OPT_TYPE_CONST, { .i64 = AVFMT_FLAG_BITEXACT }, 0, 0, E, "fflags" }, {"shortest", "stop muxing with the shortest stream", 0, AV_OPT_TYPE_CONST, { .i64 = AVFMT_FLAG_SHORTEST }, 0, 0, E, "fflags" }, -{"autobsf", "add needed bsfs automatically (delays header until each stream's first packet is written)", 0, AV_OPT_TYPE_CONST, { .i64 = AVFMT_FLAG_AUTO_BSF }, 0, 0, E, "fflags" }, +{"autobsf", "add needed bsfs automatically", 0, AV_OPT_TYPE_CONST, { .i64 = AVFMT_FLAG_AUTO_BSF }, 0, 0, E, "fflags" }, {"analyzeduration", "specify how many microseconds are analyzed to probe the input", OFFSET(max_analyze_duration), AV_OPT_TYPE_INT64, {.i64 = 0 }, 0, INT64_MAX, D}, {"cryptokey", "decryption key", OFFSET(key), AV_OPT_TYPE_BINARY, {.dbl = 0}, 0, 0, D}, {"indexmem", "max memory used for timestamp index (per stream)", OFFSET(max_index_size), AV_OPT_TYPE_INT, {.i64 = 1<<20 }, 0, INT_MAX, D}, diff --git a/libavformat/tests/fifo_muxer.c b/libavformat/tests/fifo_muxer.c index e20bd6e7b2..4b63df085e 100644 --- a/libavformat/tests/fifo_muxer.c +++ b/libavformat/tests/fifo_muxer.c @@ -238,54 +238,6 @@ fail: return ret; } -static int fifo_write_header_err_tst(AVFormatContext *oc, AVDictionary **opts, - const FailingMuxerPacketData *pkt_data) -{ - int ret = 0, i; - AVPacket pkt; - - av_init_packet(&pkt); - - ret = avformat_write_header(oc, opts); - if (ret) { - fprintf(stderr, "Unexpected write_header failure: %s\n", - av_err2str(ret)); - goto fail; - } - - for (i = 0; i < MAX_TST_PACKETS; i++ ) { - ret = prepare_packet(&pkt, pkt_data, i); - if (ret < 0) { - fprintf(stderr, "Failed to prepare test packet: %s\n", - av_err2str(ret)); - goto write_trailer_and_fail; - } - ret = av_write_frame(oc, &pkt); - av_packet_unref(&pkt); - if (ret < 0) { - break; - } - } - - if (!ret) { - fprintf(stderr, "write_packet not failed when supposed to.\n"); - goto fail; - } else if (ret != -1) { - fprintf(stderr, "Unexpected write_packet error: %s\n", av_err2str(ret)); - goto fail; - } - - ret = av_write_trailer(oc); - if (ret < 0) - fprintf(stderr, "Unexpected write_trailer error: %s\n", av_err2str(ret)); - - return ret; -write_trailer_and_fail: - av_write_trailer(oc); -fail: - return ret; -} - static int fifo_overflow_drop_test(AVFormatContext *oc, AVDictionary **opts, const FailingMuxerPacketData *data) { @@ -403,10 +355,6 @@ const TestCase tests[] = { * exactly what was on input */ {fifo_basic_test, "nonfail test", NULL,1, 0, 0, {0, 0, 0}}, - /* Test that we receive delayed write_header error from one of the write_packet - * calls. */ - {fifo_write_header_err_tst, "write header error test", NULL, 0, -1, 0, {0, 0, 0}}, - /* Each write_packet will fail 3 times before operation is successful. If recovery * Since recovery is on, fifo muxer should not return any errors. */ {fifo_basic_test, "recovery test", "attempt_recovery=1:recovery_wait_time=0", diff --git a/tests/ref/fate/fifo-muxer-tst b/tests/ref/fate/fifo-muxer-tst index ca7e294860..e1139ee0a8 100644 --- a/tests/ref/fate/fifo-muxer-tst +++ b/tests/ref/fate/fifo-muxer-tst @@ -2,7 +2,6 @@ flush count: 1 pts seen nr: 15 pts seen: 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14 nonfail test: ok -write header error test: ok recovery test: ok flush count: 1 pts seen nr: 15