From patchwork Sun Nov 8 19:50:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andriy Gelman X-Patchwork-Id: 23435 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 055F544AB13 for ; Sun, 8 Nov 2020 21:57:15 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DE10968BBEC; Sun, 8 Nov 2020 21:57:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A550868BBD2 for ; Sun, 8 Nov 2020 21:57:08 +0200 (EET) Received: by mail-qk1-f193.google.com with SMTP id u4so3416253qkk.10 for ; Sun, 08 Nov 2020 11:57:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bAVeY9w6+wKOH36KK4hllSUkG+vTCib4AOjVKVGpiX0=; b=vUbA6Tbbd5FU/bWNsSoIq9tspX1A4h8Va1g7QueX6IIHmzHRnXB16yXzAjH4wQdZ5k k5GGYXik3JhiK5QNMFzcKY+oZvaO8jiF1+hEVb8aLOV3L1wcI9kOoUXn6GdHplA0tYVq EP+W7Ix7MoGOtCuS0vwgJuuH4hitxpH3bpMSSiIKpR5QVLJQ6SKfJFB97dkTtcJpAGdU W4/c/xL8MuP7YKCjlpOJKdVLe/TsIkqPEaUxmW0j5by2sWQN3cNMFwJm5FyPTkrCpP5y xvuznU40dowgQE1aZozDod7oZWrmUucfItEpbG0112AYBdVgg2lMpuLevmRApzVczX67 cX/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bAVeY9w6+wKOH36KK4hllSUkG+vTCib4AOjVKVGpiX0=; b=faW9/rkdaU0hyu6LgdvuIMqMBOgaLyYGPaWLAA6A4QT0hu/O+ZBWRAjjrTNQHkqXEl D5ji14oc5Fcij3BiYbUtB67LT+hMAlsy0ECR6AJOSQ+IsSd78DxQ48+5r5x4QZ9icHNF xJ2r8H+3o9WxSB9Zfpd8RDdmaaANcAqEoH4YldS7iiTknHy8cxziNLWoahWhZb2zf9/D eU/IikCw0VSTJ9CNWJPeswlVgvB5lTukmauUcDB9gQf4iysqvC5JB6JgkPiryagRcEEf 5ugqtQyroxXA2VoZHnGcf3ikeRDGRA/1XZkuYrx2qnE3uJimB9RhsoSWxdNfkPRyYOjH 4KPg== X-Gm-Message-State: AOAM5332ZOriN4M7ZgVDBfxt39sWL8srhhhDGPUUBAwCXKtI2wVQeGFD z76TWEDxSpIHawEv0M1pUkhZ3iebjKo= X-Google-Smtp-Source: ABdhPJyNUw5EZXammNCzNQUtPHaEfCYIoeqZkQdpEfhgVr9hvukWTPb2a0SCwgYucWD6Yjf2DL0fDg== X-Received: by 2002:ac8:6c6:: with SMTP id j6mr8640819qth.123.1604865056587; Sun, 08 Nov 2020 11:50:56 -0800 (PST) Received: from localhost.localdomain (c-71-232-27-28.hsd1.ma.comcast.net. [71.232.27.28]) by smtp.gmail.com with ESMTPSA id i15sm447001qke.16.2020.11.08.11.50.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Nov 2020 11:50:56 -0800 (PST) From: Andriy Gelman X-Google-Original-From: Andriy Gelman To: ffmpeg-devel@ffmpeg.org Date: Sun, 8 Nov 2020 14:50:42 -0500 Message-Id: <20201108195043.210799-3-andriy.gelman@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201108195043.210799-1-andriy.gelman@gmail.com> References: <20201108195043.210799-1-andriy.gelman@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/4] avformat/nutenc: add option to periodically insert global headers 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: Andriy Gelman Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Andriy Gelman Signed-off-by: Andriy Gelman --- doc/muxers.texi | 6 ++++++ libavformat/nut.h | 3 ++- libavformat/nutenc.c | 10 ++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/muxers.texi b/doc/muxers.texi index 813b4678f4..ace236fca6 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -1822,6 +1822,12 @@ Change the syncpoint usage in nut: The @var{none} and @var{timestamped} flags are experimental. @item -write_index @var{bool} Write index at the end, the default is to write an index. +@item -header_period @var{value} +Sets how often global headers are re-inserted into the bytestream. +Default value is -1. This inserts headers at exponentially increasing locations +@math{2^23, 2^26, 2^29,...} etc. +Setting parameter in the range @math{[0,62]}, will insert headers periodically +after each @math{2^header_period} bytes at the next possible location. @end table @example diff --git a/libavformat/nut.h b/libavformat/nut.h index a990d3832e..c0928306c1 100644 --- a/libavformat/nut.h +++ b/libavformat/nut.h @@ -104,7 +104,8 @@ typedef struct NUTContext { int64_t last_syncpoint_pos; int64_t last_resync_pos; int header_count; // elision header count - int header_rep_count; // number of times headers written + int64_t header_rep_count; // number of times headers written + int header_period; // header insertion option AVRational *time_base; struct AVTreeNode *syncpoints; int sp_count; diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c index 0646f72af2..5a775a92fe 100644 --- a/libavformat/nutenc.c +++ b/libavformat/nutenc.c @@ -988,11 +988,20 @@ static int nut_write_packet(AVFormatContext *s, AVPacket *pkt) data_size += sm_size; } + if (nut->header_period >= 0) { + if (avio_tell(bc) >> nut->header_period > nut->header_rep_count) { + ret = write_headers(s, bc); + nut->header_rep_count = avio_tell(bc) >> nut->header_period; + if (ret < 0) + goto fail; + } + } else { if (1LL << (20 + 3 * nut->header_rep_count) <= avio_tell(bc)) { ret = write_headers(s, bc); if (ret < 0) goto fail; } + } if (key_frame && !(nus->last_flags & FLAG_KEY)) store_sp = 1; @@ -1221,6 +1230,7 @@ static const AVOption options[] = { { "none", "Disable syncpoints, low overhead and unseekable", 0, AV_OPT_TYPE_CONST, {.i64 = NUT_PIPE}, INT_MIN, INT_MAX, E, "syncpoints" }, { "timestamped", "Extend syncpoints with a wallclock timestamp", 0, AV_OPT_TYPE_CONST, {.i64 = NUT_BROADCAST}, INT_MIN, INT_MAX, E, "syncpoints" }, { "write_index", "Write index", OFFSET(write_index), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, E, }, + { "header_period", "Header insertion parameter", OFFSET(header_period), AV_OPT_TYPE_INT, {.i64 =-1}, -1, 62, E, }, { NULL }, };