]> git.sesse.net Git - ffmpeg/commitdiff
avformat/librist: make packet size adjustable for writing, fix it for reading
authorMarton Balint <cus@passwd.hu>
Sat, 6 Mar 2021 21:26:13 +0000 (22:26 +0100)
committerMarton Balint <cus@passwd.hu>
Sat, 13 Mar 2021 16:36:48 +0000 (17:36 +0100)
Maximum packet size is 10000 (RIST_MAX_PACKET_SIZE, which is unfortunately
private) minus the RIST protocol overhead which is 28 bytes for the unencrypted
case, 36 for the encrypted case.

Signed-off-by: Marton Balint <cus@passwd.hu>
doc/protocols.texi
libavformat/librist.c

index 4f4a4b4a3ac4b5685aa0b5f3ff1a0932e262ff3a..11005b0849dd759d19f467953cec5d9fc09e7a04 100644 (file)
@@ -714,6 +714,9 @@ This one is default.
 @item buffer_size
 Set internal RIST buffer size for retransmission of data.
 
+@item pkt_size
+Set maximum packet size for sending data. 1316 by default.
+
 @item log_level
 Set loglevel for RIST logging messages.
 
index c4ba1192e91e7b7a3384c114c8a4d9c08b0af33a..3f74521cb47c68e178d7b1986ca369a29a4ffd8a 100644 (file)
 
 #include <librist/librist.h>
 
+// RIST_MAX_PACKET_SIZE - 28 minimum protocol overhead
+#define MAX_PAYLOAD_SIZE (10000-28)
+
 typedef struct RISTContext {
     const AVClass *class;
 
     int profile;
     int buffer_size;
+    int packet_size;
     int log_level;
     int encryption;
     char *secret;
@@ -59,6 +63,7 @@ static const AVOption librist_options[] = {
     { "main",        NULL,              0,                   AV_OPT_TYPE_CONST, {.i64=RIST_PROFILE_MAIN},     0, 0, .flags = D|E, "profile" },
     { "advanced",    NULL,              0,                   AV_OPT_TYPE_CONST, {.i64=RIST_PROFILE_ADVANCED}, 0, 0, .flags = D|E, "profile" },
     { "buffer_size", "set buffer_size", OFFSET(buffer_size), AV_OPT_TYPE_INT,   {.i64=0},                     0, INT_MAX, .flags = D|E },
+    { "pkt_size",    "set packet size", OFFSET(packet_size), AV_OPT_TYPE_INT,   {.i64=1316},                  1, MAX_PAYLOAD_SIZE,    .flags = D|E },
     { "log_level",   "set loglevel",    OFFSET(log_level),   AV_OPT_TYPE_INT,   {.i64=-1},                   -1, INT_MAX, .flags = D|E },
     { "secret", "set encryption secret",OFFSET(secret),      AV_OPT_TYPE_STRING,{.str=NULL},                  0, 0,       .flags = D|E },
     { "encryption","set encryption type",OFFSET(encryption), AV_OPT_TYPE_INT   ,{.i64=0},                     0, INT_MAX, .flags = D|E },
@@ -123,13 +128,17 @@ static int librist_open(URLContext *h, const char *uri, int flags)
     if (ret < 0)
         return risterr2ret(ret);
 
-    if (flags & AVIO_FLAG_WRITE)
+    if (flags & AVIO_FLAG_WRITE) {
+        h->max_packet_size = s->packet_size;
         ret = rist_sender_create(&s->ctx, s->profile, 0, logging_settings);
+    }
     if (ret < 0)
         goto err;
 
-    if (flags & AVIO_FLAG_READ)
+    if (flags & AVIO_FLAG_READ) {
+        h->max_packet_size = MAX_PAYLOAD_SIZE;
         ret = rist_receiver_create(&s->ctx, s->profile, logging_settings);
+    }
     if (ret < 0)
         goto err;
 
@@ -167,8 +176,6 @@ static int librist_open(URLContext *h, const char *uri, int flags)
     if (ret < 0)
         goto err;
 
-    h->max_packet_size = 9968;
-
     return 0;
 
 err:
@@ -190,7 +197,7 @@ static int librist_read(URLContext *h, uint8_t *buf, int size)
     if (ret == 0)
         return AVERROR(EAGAIN);
 
-    if (data_block->payload_len > 9968) {
+    if (data_block->payload_len > MAX_PAYLOAD_SIZE) {
         rist_receiver_data_block_free((struct rist_data_block**)&data_block);
         return AVERROR_EXTERNAL;
     }