From patchwork Wed Dec 4 14:12:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Zhao X-Patchwork-Id: 16592 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 215E144AC24 for ; Wed, 4 Dec 2019 16:12:42 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0B75F68B1CB; Wed, 4 Dec 2019 16:12:42 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0DBC568ABC9 for ; Wed, 4 Dec 2019 16:12:36 +0200 (EET) Received: by mail-pj1-f65.google.com with SMTP id ca19so3048019pjb.8 for ; Wed, 04 Dec 2019 06:12:35 -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; bh=UBcUCfLdCgAyhmuN+P6m5RGQINhJd8BLmsb6dcG/YJQ=; b=jM83HPKkXlfZGJ6JCeFih2dkGcfBWvLWihBkaFdqBsIq2TjQCFAFWMxMrUGl/e77qg 9Ex92DOw3vaZu1NY0ONKvzQMfzRLb3jvJyRkvqXT5JW8u8P8KozoeZfgHJC6Rc1pFh1O 6vKO1QhiwChzyNeKdqi9iQ9+2jCBQ7c+TF4/wCsrhxM2FHoErzfwJPYH+vnyoqvxLgTD 6yrJD2fzbhByT4EY6JBEEOwo0cwvA1NhN7UBVyOJRiP9JKDTF49oTQoscFgROA/SUmuD qzxJFeEjq4qW9aaDXw/N9aH1NZmgI1RnoB7rwX4Q0Phq8JIUSfUk4kv6W8I+QEIfqlU0 EwSQ== 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; bh=UBcUCfLdCgAyhmuN+P6m5RGQINhJd8BLmsb6dcG/YJQ=; b=iE1wecvun08823FVid7QUtIBijkG8P4gxsGpR8VdQ/6K92CLdKQfLagUxLr6SZnDcW 99pxQShsmPhNyPIhBO9PueIei6P4BO/soHxbVMyDjO7c1kCkPWJy/EJ8rshRS/HJp368 g9ms5hGDZzpOz3qmjeRZbLZWhejC2POcj863daJkNfLa2qsPJr4gRb4FFiGLU6P+SaaX aSFS8Du4IY/eNpsrjiVBTEUom67NbXVeT+q94vhjy7dPa62GLgD++JX05lVh/edrkqEh O0Sz++Sfu1Ts9Q5FTPjlUGhbCB4tmk8PcVi2JftemzQ7av2Qbmdb3v5MWdRgh11KiF3X HNyQ== X-Gm-Message-State: APjAAAUbnZ73khAhB9g5re8sAD0I/Y0sYt6yuTuQXYJ+zjKk+1oPY0fP DEUP8U9pzPgNJTfnaJl7khs2+3cl X-Google-Smtp-Source: APXvYqz7Sdr+6im97sD5A1BYwArjCaA7gGg7wM/Pc4/lyNzB9BcbxM3enU1A5ooDsH3Q0P4oxmbJmg== X-Received: by 2002:a17:90a:d985:: with SMTP id d5mr1479338pjv.73.1575468754453; Wed, 04 Dec 2019 06:12:34 -0800 (PST) Received: from localhost.localdomain ([47.90.47.25]) by smtp.gmail.com with ESMTPSA id e1sm8799556pfl.98.2019.12.04.06.12.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Dec 2019 06:12:34 -0800 (PST) From: Jun Zhao To: ffmpeg-devel@ffmpeg.org Date: Wed, 4 Dec 2019 22:12:25 +0800 Message-Id: <1575468746-24718-2-git-send-email-mypopydev@gmail.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1575468746-24718-1-git-send-email-mypopydev@gmail.com> References: <1575468746-24718-1-git-send-email-mypopydev@gmail.com> Subject: [FFmpeg-devel] [PATCH V4 1/2] lavf/libsrt: add linger parameter to libsrt 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: Jun Zhao MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Jun Zhao add linger parameter to libsrt, it's setting the number of seconds that the socket waits for unsent data when closing. Reviewed-by: Andriy Gelman Signed-off-by: Jun Zhao --- doc/protocols.texi | 6 ++++++ libavformat/libsrt.c | 13 +++++++++++++ 2 files changed, 19 insertions(+), 0 deletions(-) diff --git a/doc/protocols.texi b/doc/protocols.texi index 0e18a49..886c3b8 100644 --- a/doc/protocols.texi +++ b/doc/protocols.texi @@ -1426,6 +1426,12 @@ the overhead transmission (retransmitted and control packets). file: Set options as for non-live transmission. See @option{messageapi} for further explanations +@item linger=@var{seconds} +The number of seconds that the socket waits for unsent data when closing. +Default is -1. -1 means auto (off with 0 seconds in live mode, on with 180 +seconds in file mode). The range for this option is integers in the +0 - @code{INT_MAX}. + @end table For more information see: @url{https://github.com/Haivision/srt}. diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c index 1c34ec5..0a748a1 100644 --- a/libavformat/libsrt.c +++ b/libavformat/libsrt.c @@ -84,6 +84,7 @@ typedef struct SRTContext { char *smoother; int messageapi; SRT_TRANSTYPE transtype; + int linger; } SRTContext; #define D AV_OPT_FLAG_DECODING_PARAM @@ -128,6 +129,7 @@ static const AVOption libsrt_options[] = { { "transtype", "The transmission type for the socket", OFFSET(transtype), AV_OPT_TYPE_INT, { .i64 = SRTT_INVALID }, SRTT_LIVE, SRTT_INVALID, .flags = D|E, "transtype" }, { "live", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = SRTT_LIVE }, INT_MIN, INT_MAX, .flags = D|E, "transtype" }, { "file", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = SRTT_FILE }, INT_MIN, INT_MAX, .flags = D|E, "transtype" }, + { "linger", "Number of seconds that the socket waits for unsent data when closing", OFFSET(linger), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E }, { NULL } }; @@ -340,6 +342,14 @@ static int libsrt_set_options_pre(URLContext *h, int fd) ((h->flags & AVIO_FLAG_WRITE) && libsrt_setsockopt(h, fd, SRTO_SENDER, "SRTO_SENDER", &yes, sizeof(yes)) < 0)) { return AVERROR(EIO); } + + if (s->linger >= 0) { + struct linger lin; + lin.l_linger = s->linger; + lin.l_onoff = lin.l_linger > 0 ? 1 : 0; + if (libsrt_setsockopt(h, fd, SRTO_LINGER, "SRTO_LINGER", &lin, sizeof(lin)) < 0) + return AVERROR(EIO); + } return 0; } @@ -591,6 +601,9 @@ static int libsrt_open(URLContext *h, const char *uri, int flags) goto err; } } + if (av_find_info_tag(buf, sizeof(buf), "linger", p)) { + s->linger = strtol(buf, NULL, 10); + } } return libsrt_setup(h, uri, flags); err: