On Sun, 22 Mar 2015, Luca Barbato wrote:

---

Martin, please triplecheck it ^^

libavformat/rtpproto.c | 102 +++++++++++++++++++++++++++++++++----------------
1 file changed, 69 insertions(+), 33 deletions(-)

diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c
index 5bff00e..f1c2e97 100644
--- a/libavformat/rtpproto.c
+++ b/libavformat/rtpproto.c
@@ -26,6 +26,7 @@

#include "libavutil/parseutils.h"
#include "libavutil/avstring.h"
+#include "libavutil/opt.h"
#include "avformat.h"
#include "avio_internal.h"
#include "rtp.h"
@@ -42,14 +43,46 @@
#endif

typedef struct RTPContext {
+    const AVClass *class;
    URLContext *rtp_hd, *rtcp_hd;
    int rtp_fd, rtcp_fd, nb_ssm_include_addrs, nb_ssm_exclude_addrs;
    struct sockaddr_storage **ssm_include_addrs, **ssm_exclude_addrs;
    int write_to_source;
    struct sockaddr_storage last_rtp_source, last_rtcp_source;
    socklen_t last_rtp_source_len, last_rtcp_source_len;
+    int ttl;
+    int buffer_size;
+    int rtcp_port, local_rtpport, local_rtcpport;
+    int connect;
+    int pkt_size;
+    char *sources;
+    char *block;
} RTPContext;

+#define OFFSET(x) offsetof(RTPContext, x)
+#define D AV_OPT_FLAG_DECODING_PARAM
+#define E AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+    { "ttl",                "Time to live (in milliseconds, multicast only)",  
                 OFFSET(ttl),             AV_OPT_TYPE_INT,    { .i64 = -1 },    -1, INT_MAX, .flags 
= D|E },
+    { "buffer_size",        "System buffer size (in bytes)",                   
                 OFFSET(buffer_size),     AV_OPT_TYPE_INT,    { .i64 = -1 },    -1, INT_MAX, .flags 
= D|E },
+    { "rtcp_port",          "Custom rtcp port",                                
                 OFFSET(rtcp_port),       AV_OPT_TYPE_INT,    { .i64 = -1 },    -1, INT_MAX, .flags 
= D|E },
+    { "local_rtpport",      "Local rtp port",                                  
                 OFFSET(local_rtpport),   AV_OPT_TYPE_INT,    { .i64 = -1 },    -1, INT_MAX, .flags 
= D|E },
+    { "local_rtcpport",     "Local rtcp port",                                 
                 OFFSET(local_rtcpport),  AV_OPT_TYPE_INT,    { .i64 = -1 },    -1, INT_MAX, .flags 
= D|E },
+    { "connect",            "Connect socket",                                  
                 OFFSET(connect),         AV_OPT_TYPE_INT,    { .i64 =  0 },     0, 1,       .flags 
= D|E },
+    { "write_to_source",    "Send packets to the source address of the latest 
received packet", OFFSET(write_to_source), AV_OPT_TYPE_INT,    { .i64 =  0 },     0, 1,       
.flags = D|E },
+    { "pkt_size",           "Maximum packet size",                             
                 OFFSET(pkt_size),        AV_OPT_TYPE_INT,    { .i64 = -1 },    -1, INT_MAX, .flags 
= D|E },
+    { "sources",            "Source list",                                     
                 OFFSET(sources),         AV_OPT_TYPE_STRING, { .str = NULL },               .flags 
= D|E },
+    { "block",              "Block list",                                      
                 OFFSET(block),           AV_OPT_TYPE_STRING, { .str = NULL },               .flags 
= D|E },
+    { NULL }
+};
+
+static const AVClass rtp_class = {
+    .class_name = "rtp",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
/**
 * If no filename is given to av_open_input_file because you want to
 * get the local port first, then you must call this function to set
@@ -188,21 +221,23 @@ static av_printf_format(3, 4) void url_add_option(char 
*buf, int buf_size, const
    va_end(ap);
}

-static void build_udp_url(char *buf, int buf_size,
-                          const char *hostname, int port,
-                          int local_port, int ttl,
-                          int max_packet_size, int connect,
+static void build_udp_url(RTPContext *s,
+                          char *buf, int buf_size,
+                          const char *hostname,
+                          int port, int local_port,
                          const char *include_sources,
                          const char *exclude_sources)
{
    ff_url_join(buf, buf_size, "udp", NULL, hostname, port, NULL);
    if (local_port >= 0)
        url_add_option(buf, buf_size, "localport=%d", local_port);
-    if (ttl >= 0)
-        url_add_option(buf, buf_size, "ttl=%d", ttl);
-    if (max_packet_size >=0)
-        url_add_option(buf, buf_size, "pkt_size=%d", max_packet_size);
-    if (connect)
+    if (s->ttl >= 0)
+        url_add_option(buf, buf_size, "ttl=%d", s->ttl);
+    if (s->buffer_size)
+        url_add_option(buf, buf_size, "buffer_size=%d", s->buffer_size);

This needs to be s->buffer_size > 0, because now we write the default value of -1 through to the udp protocol.

// Martin
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to