From patchwork Mon Oct 22 06:58:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matsuzawa Tomohiro X-Patchwork-Id: 10743 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 8C10D4496F4 for ; Mon, 22 Oct 2018 09:58:30 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DA389680503; Mon, 22 Oct 2018 09:58:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM05-BY2-obe.outbound.protection.outlook.com (mail-oln040092012031.outbound.protection.outlook.com [40.92.12.31]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 05F8A68002C for ; Mon, 22 Oct 2018 09:58:04 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WKOH5BR8Fj9PBjqeqsZW4ZPgfPLfj0BR5vzYp+3zn3Y=; b=nKrDZFlKYLrW4Qkcv1kUwwccy3allukk6GEwrLRagECoZbbxD2kNXJDVHDOKS147FsALIGAOeLr1q6r8o8k+WhBAKiGVDsfMJyV1XuRvk680HTV33rrFzjerTGIWuj3Rb8mVYKbSh4XxVFbDnnVptZJS0nijLe7w/2B3hrASxnXnEi76QqSHggH0Io0Xhskxjf/z2jYx4qNbJF4H70GGz8kPvJT3fswKDauUxfICWOcFNn6sgjv8KYvvsFPqpXzShj21G7Vfu/rR+H1QJWSywSG8DcYeJqgtj5SkJOZu0SlphKyfKrPaY44X+llrlbIzHD5GJ9+jWWG/ZPhMsw4Qtw== Received: from DM3NAM05FT051.eop-nam05.prod.protection.outlook.com (10.152.98.58) by DM3NAM05HT079.eop-nam05.prod.protection.outlook.com (10.152.99.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1273.11; Mon, 22 Oct 2018 06:58:29 +0000 Received: from CY4PR06MB3335.namprd06.prod.outlook.com (10.152.98.52) by DM3NAM05FT051.mail.protection.outlook.com (10.152.98.165) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1273.11 via Frontend Transport; Mon, 22 Oct 2018 06:58:29 +0000 Received: from CY4PR06MB3335.namprd06.prod.outlook.com ([fe80::fdad:c5d4:9ce:da61]) by CY4PR06MB3335.namprd06.prod.outlook.com ([fe80::fdad:c5d4:9ce:da61%5]) with mapi id 15.20.1228.035; Mon, 22 Oct 2018 06:58:29 +0000 From: Matsuzawa Tomohiro To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH] avformat/libsrt: add several options supported in srt 1.3.0 v2 Thread-Index: AQHUadSjDn9EGc98Zku/VjfsWd8fYw== Date: Mon, 22 Oct 2018 06:58:29 +0000 Message-ID: References: In-Reply-To: Accept-Language: ja-JP, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: TYAPR01CA0136.jpnprd01.prod.outlook.com (2603:1096:404:2d::28) To CY4PR06MB3335.namprd06.prod.outlook.com (2603:10b6:910:52::20) x-incomingtopheadermarker: OriginalChecksum:623A9EC6197B96608F041447C7F44A9AFB1FFD6BA2B4E8EA1E51B52709026092; UpperCasedChecksum:555F4EAF0230EFB9DB8E97A8CF83425A77480B30EFFB6F738994B032B28F0827; SizeAsReceived:7593; Count:50 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [UVS5lJezDrEZ3LfJZlyFGFI4d9Swv0nRiNgQZyJxCfE=] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM3NAM05HT079; 6:4KZLsMJmlNpq6Mxxn5ioYhOEhQbPV+aS5WcPsVLBdXk38BQzb03YHqTVuyj4rhoyk2hjEJM8EIpNcfESdE346mmBaJ3IfTic8OmF78+UzvEgdE8ML9UI+EbY0NpfhzRlyl93hBGX1VgJ6CX92bANRdElJfViULOS/V24YaAtOVEW9QbhOYONJdEwdcVTCNyyOds1yW3Kkv4IQsjQDNKHT5vFdqAIflf73krkvagpOw2hyb4X+8Pl803PAvAzuqE28ejkbV2duZs7x0+NKzLekJEmBWnIrLMfc5NEMq5xni3yhaShhjVYFbIcNztS5P8rac2++r5xF5X1AF+Q4UWhdoAq+KCfFHbCrq0xqcLrcgzM5RgpRYQV9WcqLnC5WwtwgX/r1u23J5rrgdsKXn6ywawU/us77obtM0i9SubrIGezXfJU6qjnx7C1mvhiIhLSB6zQD5quayydNflSiv8NtQ==; 5:NKPShb+ERyfuf6T/iUcSR7Xnq+dCcGGiM6lJynxgH4qzjVhgeuMthOzZE8qRR7WyJ9i3pk2n5PhvuByjMipZjEyFx0loXlihMa50wS3ElUBGR2aE5yhuq4dcX5a+5jWY2xVrJckuHfQONzzG+viW4gKYX2Ksgni0bohrcNDENqY=; 7:ETvv9Cqf2WEbK95dDpXdyIb33crSE0kohMjNvtgYMaCbkpy1dw4q2+YHDwRWvENsgIkzQAqm4Y+Lm2Rfu0jY4++l2x2sjeRX7UjrKtm5hk0ZFCYq6fHAAS+cmyESfxGz55us67IU59f7YBvhvL3SrQ== x-incomingheadercount: 50 x-eopattributedmessage: 0 x-ms-exchange-slblob-mailprops: q+fD6XS3/UJlxTvPGk9+bDeSfVk+IodWBngiplR5YdFJbj1GJSs9HiH4dKw2Oy35jeT+sYGUer5f1ieEs+UXDvEhsjtJPWWIXBkcnnT1Z9Iyzx73uiX20k/QtWu/ha29GstzjUYV9l0iCUoaqo76kRcRPOGnXS+n+jSygc4dZ3hVk7SL84n3UiskvyfIdCCd36iolS/V0dhAOCrxCYl2OtupP3jdYF6uW7CMyDFArDUmCk8wfkJhllTh969fTBO+WnTzVSRDy3Am8oobDvV8dMTIvquxuxYR+eCiFJi+jEkEggaezo1QzdSZjGw7FFOOnA1en+SfqO8mtp1HSHNM8ztgVTY+FNUTjDvd1+aXAHh7kkS6pl/4pkFJlZ74lS64C8P+nvkXgdJUMQYX0vU/RW4lUTtht1ANQS/LXk+XjEEyjsXP3UP1fW5M7xE6vW660aaZRZUPeSQxTXCPr4v+se3Dw+SVKdXkaYwbV1Ck57s+9s/nnEA3+vniRzWNtykCW2HDPn7JNXFw8NSLxX9QhSyxSMDLGDyDNZcmnVpIX8Uum53owveJfvYxL27rgC1ubK4SB0ijSRvsLxPnxyEUdOK6ty0lRqUIvjoTPpP2ECPY2qtH2f06Fv44V37f8a3m69VaZ7as8gv1T7N/xQLtF2tFzI56TPvWvNwn5l9xF5vgIsPHpCvFhlwo6qRKPnHlrRNTXvWxSXBuh9TV3sbOXg== x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(201702061078)(5061506573)(5061507331)(1603103135)(2017031320274)(2017031324274)(2017031323274)(201702181274)(2017031322404)(1601125500)(1603101475)(1701031045); SRVR:DM3NAM05HT079; x-ms-traffictypediagnostic: DM3NAM05HT079: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(4566010)(82015058); SRVR:DM3NAM05HT079; BCL:0; PCL:0; RULEID:; SRVR:DM3NAM05HT079; x-microsoft-antispam-message-info: FcDHvv6Uu7Ssz2jfu2yMf9PDNJFnVqmu7lAgJ6YQMGH4vSMuEwqvWyzxfIpH73lA Content-ID: <4BDFA0D9A94A0D4C99A74ACD9F492E77@namprd06.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 7181d4b0-87d6-4f4e-ba33-0d3746212cec X-MS-Exchange-CrossTenant-Network-Message-Id: 0b9b18f8-4a64-48bf-bfe3-08d637ebc49e X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 7181d4b0-87d6-4f4e-ba33-0d3746212cec X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Oct 2018 06:58:29.8760 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3NAM05HT079 Subject: [FFmpeg-devel] [PATCH] avformat/libsrt: add several options supported in srt 1.3.0 v2 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: Matsuzawa Tomohiro Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Several SRT options are missing. Since pkg_config requires libsrt v1.3.0 and above, it should be able to support options added in libsrt v1.3.0 and below. This commit adds 8 SRT options. sndbuf, rcvbuf, lossmaxttl, minversion, streamid, smoother, messageapi and transtype The keys of option are equivalent to stransmit. https://github.com/Haivision/srt/blob/v1.3.0/apps/socketoptions.hpp#L196-L223 --- doc/protocols.texi | 85 ++++++++++++++++++++++++++++++++++++++++++-- libavformat/libsrt.c | 62 ++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+), 2 deletions(-) -- 2.17.1 (Apple Git-112) diff --git a/doc/protocols.texi b/doc/protocols.texi index b34f29eebf..fb7725e058 100644 --- a/doc/protocols.texi +++ b/doc/protocols.texi @@ -1306,10 +1306,10 @@ set by the peer side. Before version 1.3.0 this option is only available as @option{latency}. @item recv_buffer_size=@var{bytes} -Set receive buffer size, expressed in bytes. +Set UDP receive buffer size, expressed in bytes. @item send_buffer_size=@var{bytes} -Set send buffer size, expressed in bytes. +Set UDP send buffer size, expressed in bytes. @item rw_timeout Set raise error timeout for read/write optations. @@ -1329,6 +1329,87 @@ have no chance of being delivered in time. It was automatically enabled in the sender if the receiver supports it. +@item sndbuf=@var{bytes} +Set send buffer size, expressed in bytes. + +@item rcvbuf=@var{bytes} +Set receive buffer size, expressed in bytes. + +Receive buffer must not be greater than @option{ffs}. + +@item lossmaxttl=@var{packets} +The value up to which the Reorder Tolerance may grow. When +Reorder Tolerance is > 0, then packet loss report is delayed +until that number of packets come in. Reorder Tolerance +increases every time a "belated" packet has come, but it +wasn't due to retransmission (that is, when UDP packets tend +to come out of order), with the difference between the latest +sequence and this packet's sequence, and not more than the +value of this option. By default it's 0, which means that this +mechanism is turned off, and the loss report is always sent +immediately upon experiencing a "gap" in sequences. + +@item minversion +The minimum SRT version that is required from the peer. A connection +to a peer that does not satisfy the minimum version requirement +will be rejected. + +The version format in hex is 0xXXYYZZ for x.y.z in human readable +form. + +@item streamid=@var{string} +A string limited to 512 characters that can be set on the socket prior +to connecting. This stream ID will be able to be retrieved by the +listener side from the socket that is returned from srt_accept and +was connected by a socket with that set stream ID. SRT does not enforce +any special interpretation of the contents of this string. +This option doesn’t make sense in Rendezvous connection; the result +might be that simply one side will override the value from the other +side and it’s the matter of luck which one would win + +@item smoother=@var{live|file} +The type of Smoother used for the transmission for that socket, which +is responsible for the transmission and congestion control. The Smoother +type must be exactly the same on both connecting parties, otherwise +the connection is rejected. + +@item messageapi=@var{1|0} +When set, this socket uses the Message API, otherwise it uses Buffer +API. Note that in live mode (see @option{transtype}) there’s only +message API available. In File mode you can chose to use one of two modes: + +Stream API (default, when this option is false). In this mode you may +send as many data as you wish with one sending instruction, or even use +dedicated functions that read directly from a file. The internal facility +will take care of any speed and congestion control. When receiving, you +can also receive as many data as desired, the data not extracted will be +waiting for the next call. There is no boundary between data portions in +the Stream mode. + +Message API. In this mode your single sending instruction passes exactly +one piece of data that has boundaries (a message). Contrary to Live mode, +this message may span across multiple UDP packets and the only size +limitation is that it shall fit as a whole in the sending buffer. The +receiver shall use as large buffer as necessary to receive the message, +otherwise the message will not be given up. When the message is not +complete (not all packets received or there was a packet loss) it will +not be given up. + +@item transtype=@var{live|file} +Sets the transmission type for the socket, in particular, setting this +option sets multiple other parameters to their default values as required +for a particular transmission type. + +live: Set options as for live transmission. In this mode, you should +send by one sending instruction only so many data that fit in one UDP packet, +and limited to the value defined first in @option{payload_size} (1316 is +default in this mode). There is no speed control in this mode, only the +bandwidth control, if configured, in order to not exceed the bandwidth with +the overhead transmission (retransmitted and control packets). + +file: Set options as for non-live transmission. See @option{messageapi} +for further explanations + @end table For more information see: @url{https://github.com/Haivision/srt}. diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c index fbfd6ace83..e7a60dbc40 100644 --- a/libavformat/libsrt.c +++ b/libavformat/libsrt.c @@ -76,6 +76,14 @@ typedef struct SRTContext { int64_t rcvlatency; int64_t peerlatency; enum SRTMode mode; + int sndbuf; + int rcvbuf; + int lossmaxttl; + int minversion; + char *streamid; + char *smoother; + int messageapi; + SRT_TRANSTYPE transtype; } SRTContext; #define D AV_OPT_FLAG_DECODING_PARAM @@ -110,6 +118,16 @@ static const AVOption libsrt_options[] = { { "caller", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = SRT_MODE_CALLER }, INT_MIN, INT_MAX, .flags = D|E, "mode" }, { "listener", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = SRT_MODE_LISTENER }, INT_MIN, INT_MAX, .flags = D|E, "mode" }, { "rendezvous", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = SRT_MODE_RENDEZVOUS }, INT_MIN, INT_MAX, .flags = D|E, "mode" }, + { "sndbuf", "Send buffer size (in bytes)", OFFSET(sndbuf), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E }, + { "rcvbuf", "Receive buffer size (in bytes)", OFFSET(rcvbuf), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E }, + { "lossmaxttl", "Maximum possible packet reorder tolerance", OFFSET(lossmaxttl), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E }, + { "minversion", "The minimum SRT version that is required from the peer", OFFSET(minversion), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E }, + { "streamid", "A string of up to 512 characters that an Initiator can pass to a Responder", OFFSET(streamid), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = D|E }, + { "smoother", "The type of Smoother used for the transmission for that socket", OFFSET(smoother), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = D|E }, + { "messageapi", "Enable message API", OFFSET(messageapi), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, .flags = D|E }, + { "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" }, { NULL } }; @@ -297,6 +315,7 @@ static int libsrt_set_options_pre(URLContext *h, int fd) int connect_timeout = s->connect_timeout; if ((s->mode == SRT_MODE_RENDEZVOUS && libsrt_setsockopt(h, fd, SRTO_RENDEZVOUS, "SRTO_RENDEZVOUS", &yes, sizeof(yes)) < 0) || + (s->transtype != SRTT_INVALID && libsrt_setsockopt(h, fd, SRTO_TRANSTYPE, "SRTO_TRANSTYPE", &s->transtype, sizeof(s->transtype)) < 0) || (s->maxbw >= 0 && libsrt_setsockopt(h, fd, SRTO_MAXBW, "SRTO_MAXBW", &s->maxbw, sizeof(s->maxbw)) < 0) || (s->pbkeylen >= 0 && libsrt_setsockopt(h, fd, SRTO_PBKEYLEN, "SRTO_PBKEYLEN", &s->pbkeylen, sizeof(s->pbkeylen)) < 0) || (s->passphrase && libsrt_setsockopt(h, fd, SRTO_PASSPHRASE, "SRTO_PASSPHRASE", s->passphrase, strlen(s->passphrase)) < 0) || @@ -310,6 +329,13 @@ static int libsrt_set_options_pre(URLContext *h, int fd) (s->tlpktdrop >= 0 && libsrt_setsockopt(h, fd, SRTO_TLPKTDROP, "SRTO_TLPKDROP", &s->tlpktdrop, sizeof(s->tlpktdrop)) < 0) || (s->nakreport >= 0 && libsrt_setsockopt(h, fd, SRTO_NAKREPORT, "SRTO_NAKREPORT", &s->nakreport, sizeof(s->nakreport)) < 0) || (connect_timeout >= 0 && libsrt_setsockopt(h, fd, SRTO_CONNTIMEO, "SRTO_CONNTIMEO", &connect_timeout, sizeof(connect_timeout)) <0 ) || + (s->sndbuf >= 0 && libsrt_setsockopt(h, fd, SRTO_SNDBUF, "SRTO_SNDBUF", &s->sndbuf, sizeof(s->sndbuf)) < 0) || + (s->rcvbuf >= 0 && libsrt_setsockopt(h, fd, SRTO_RCVBUF, "SRTO_RCVBUF", &s->rcvbuf, sizeof(s->rcvbuf)) < 0) || + (s->lossmaxttl >= 0 && libsrt_setsockopt(h, fd, SRTO_LOSSMAXTTL, "SRTO_LOSSMAXTTL", &s->lossmaxttl, sizeof(s->lossmaxttl)) < 0) || + (s->minversion >= 0 && libsrt_setsockopt(h, fd, SRTO_MINVERSION, "SRTO_MINVERSION", &s->minversion, sizeof(s->minversion)) < 0) || + (s->streamid && libsrt_setsockopt(h, fd, SRTO_STREAMID, "SRTO_STREAMID", s->streamid, strlen(s->streamid)) < 0) || + (s->smoother && libsrt_setsockopt(h, fd, SRTO_SMOOTHER, "SRTO_SMOOTHER", s->smoother, strlen(s->smoother)) < 0) || + (s->messageapi >= 0 && libsrt_setsockopt(h, fd, SRTO_MESSAGEAPI, "SRTO_MESSAGEAPI", &s->messageapi, sizeof(s->messageapi)) < 0) || (s->payload_size >= 0 && libsrt_setsockopt(h, fd, SRTO_PAYLOADSIZE, "SRTO_PAYLOADSIZE", &s->payload_size, sizeof(s->payload_size)) < 0)) { return AVERROR(EIO); } @@ -522,6 +548,42 @@ static int libsrt_open(URLContext *h, const char *uri, int flags) return AVERROR(EIO); } } + if (av_find_info_tag(buf, sizeof(buf), "sndbuf", p)) { + s->sndbuf = strtol(buf, NULL, 10); + } + if (av_find_info_tag(buf, sizeof(buf), "rcvbuf", p)) { + s->rcvbuf = strtol(buf, NULL, 10); + } + if (av_find_info_tag(buf, sizeof(buf), "lossmaxttl", p)) { + s->lossmaxttl = strtol(buf, NULL, 10); + } + if (av_find_info_tag(buf, sizeof(buf), "minversion", p)) { + s->minversion = strtol(buf, NULL, 0); + } + if (av_find_info_tag(buf, sizeof(buf), "streamid", p)) { + if (s->streamid) { + av_freep(s->streamid); + } + s->streamid = av_strdup(buf); + } + if (av_find_info_tag(buf, sizeof(buf), "smoother", p)) { + if (s->smoother) { + av_freep(s->smoother); + } + s->smoother = av_strdup(buf); + } + if (av_find_info_tag(buf, sizeof(buf), "messageapi", p)) { + s->messageapi = strtol(buf, NULL, 10); + } + if (av_find_info_tag(buf, sizeof(buf), "transtype", p)) { + if (!strcmp(buf, "live")) { + s->transtype = SRTT_LIVE; + } else if (!strcmp(buf, "file")) { + s->transtype = SRTT_FILE; + } else { + return AVERROR(EINVAL); + } + } } return libsrt_setup(h, uri, flags); }