]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/blobdiff - libavformat/rtpproto.c
Put FRSH support as a separate protocol
[frescor/ffmpeg.git] / libavformat / rtpproto.c
index 1933ab06dc7a3472bbab8ce7f2ff2ee3a0e5c9a0..727c799619801d4104b29f6151a153353d21e8b0 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * RTP network protocol
- * Copyright (c) 2002 Fabrice Bellard.
+ * Copyright (c) 2002 Fabrice Bellard
  *
  * This file is part of FFmpeg.
  *
@@ -20,7 +20,7 @@
  */
 
 /**
- * @file rtpproto.c
+ * @file libavformat/rtpproto.c
  * RTP protocol
  */
 
 #define RTP_TX_BUF_SIZE  (64 * 1024)
 #define RTP_RX_BUF_SIZE  (128 * 1024)
 
+#ifdef OMK_FOR_USER
+#include "libavformat_config.h"
+#endif
+
+#ifdef CONFIG_FFMPEG_WITH_FRSH
+#define URL_PROTO "frsh"
+#else
+#define URL_PROTO "udp"
+#endif
+
 typedef struct RTPContext {
     URLContext *rtp_hd, *rtcp_hd;
     int rtp_fd, rtcp_fd;
@@ -66,10 +76,10 @@ int rtp_set_remote_url(URLContext *h, const char *uri)
     url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port,
               path, sizeof(path), uri);
 
-    snprintf(buf, sizeof(buf), "udp://%s:%d%s", hostname, port, path);
+    snprintf(buf, sizeof(buf), URL_PROTO"://%s:%d%s", hostname, port, path);
     udp_set_remote_url(s->rtp_hd, buf);
 
-    snprintf(buf, sizeof(buf), "udp://%s:%d%s", hostname, port + 1, path);
+    snprintf(buf, sizeof(buf), URL_PROTO"://%s:%d%s", hostname, port + 1, path);
     udp_set_remote_url(s->rtcp_hd, buf);
     return 0;
 }
@@ -98,15 +108,18 @@ static void url_add_option(char *buf, int buf_size, const char *fmt, ...)
 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 max_packet_size,
+                         const char *label)
 {
-    snprintf(buf, buf_size, "udp://%s:%d", hostname, port);
+    snprintf(buf, buf_size, URL_PROTO"://%s:%d", hostname, port);
     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 (label)
+        url_add_option(buf, buf_size, "contract_label=%s", label);
 }
 
 /**
@@ -154,7 +167,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
     }
 
     build_udp_url(buf, sizeof(buf),
-                  hostname, port, local_port, ttl, max_packet_size);
+                  hostname, port, local_port, ttl, max_packet_size, "RTP");
     if (url_open(&s->rtp_hd, buf, flags) < 0)
         goto fail;
     local_port = udp_get_local_port(s->rtp_hd);
@@ -163,14 +176,14 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
     /* well, should suppress localport in path */
 
     build_udp_url(buf, sizeof(buf),
-                  hostname, port + 1, local_port + 1, ttl, max_packet_size);
+                  hostname, port + 1, local_port + 1, ttl, max_packet_size, "RTCP");
     if (url_open(&s->rtcp_hd, buf, flags) < 0)
         goto fail;
 
     /* just to ease handle access. XXX: need to suppress direct handle
        access */
-    s->rtp_fd = udp_get_file_handle(s->rtp_hd);
-    s->rtcp_fd = udp_get_file_handle(s->rtcp_hd);
+    s->rtp_fd = url_get_file_handle(s->rtp_hd);
+    s->rtcp_fd = url_get_file_handle(s->rtcp_hd);
 
     h->max_packet_size = url_get_max_packet_size(s->rtp_hd);
     h->is_streamed = 1;
@@ -296,6 +309,7 @@ int rtp_get_local_port(URLContext *h)
     return udp_get_local_port(s->rtp_hd);
 }
 
+#if (LIBAVFORMAT_VERSION_MAJOR <= 52)
 /**
  * Return the rtp and rtcp file handles for select() usage to wait for
  * several RTP streams at the same time.
@@ -309,6 +323,13 @@ void rtp_get_file_handles(URLContext *h, int *prtp_fd, int *prtcp_fd)
     *prtp_fd = s->rtp_fd;
     *prtcp_fd = s->rtcp_fd;
 }
+#endif
+
+static int rtp_get_file_handle(URLContext *h)
+{
+    RTPContext *s = h->priv_data;
+    return s->rtp_fd;
+}
 
 URLProtocol rtp_protocol = {
     "rtp",
@@ -317,4 +338,5 @@ URLProtocol rtp_protocol = {
     rtp_write,
     NULL, /* seek */
     rtp_close,
+    .url_get_file_handle = rtp_get_file_handle,
 };