]> 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 cf762d5ed4309450e614d10561538cf710afd809..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.
  *
  * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
+
+/**
+ * @file libavformat/rtpproto.c
+ * RTP protocol
+ */
+
+#include "libavutil/avstring.h"
 #include "avformat.h"
-#include "avstring.h"
 
 #include <unistd.h>
 #include <stdarg.h>
 #include "network.h"
 #include "os_support.h"
 #include <fcntl.h>
+#if HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
 
 #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;
@@ -44,6 +63,7 @@ typedef struct RTPContext {
  * @param uri of the remote server
  * @return zero if no error.
  */
+
 int rtp_set_remote_url(URLContext *h, const char *uri)
 {
     RTPContext *s = h->priv_data;
@@ -56,17 +76,20 @@ 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;
 }
 
 
-/* add option to url of the form:
-   "http://host:port/path?option1=val1&option2=val2... */
+/**
+ * add option to url of the form:
+ * "http://host:port/path?option1=val1&option2=val2...
+ */
+
 static void url_add_option(char *buf, int buf_size, const char *fmt, ...)
 {
     char buf1[1024];
@@ -84,25 +107,33 @@ 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 local_port, int ttl,
+                          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);
 }
 
-/*
+/**
  * url syntax: rtp://host:port[?option=val...]
  * option: 'ttl=n'       : set the ttl value (for multicast only)
  *         'localport=n' : set the local port to n
+ *         'pkt_size=n'  : set max packet size
  *
  */
+
 static int rtp_open(URLContext *h, const char *uri, int flags)
 {
     RTPContext *s;
-    int port, is_output, ttl, local_port;
+    int port, is_output, ttl, local_port, max_packet_size;
     char hostname[256];
     char buf[1024];
     char path[1024];
@@ -120,6 +151,8 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
     /* extract parameters */
     ttl = -1;
     local_port = -1;
+    max_packet_size = -1;
+
     p = strchr(uri, '?');
     if (p) {
         if (find_info_tag(buf, sizeof(buf), "ttl", p)) {
@@ -128,10 +161,13 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
         if (find_info_tag(buf, sizeof(buf), "localport", p)) {
             local_port = strtol(buf, NULL, 10);
         }
+        if (find_info_tag(buf, sizeof(buf), "pkt_size", p)) {
+            max_packet_size = strtol(buf, NULL, 10);
+        }
     }
 
     build_udp_url(buf, sizeof(buf),
-                  hostname, port, local_port, ttl);
+                  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);
@@ -140,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);
+                  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;
@@ -266,17 +302,20 @@ static int rtp_close(URLContext *h)
  * @param s1 media file context
  * @return the local port number
  */
+
 int rtp_get_local_port(URLContext *h)
 {
     RTPContext *s = h->priv_data;
     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.
+ * Return the rtp and rtcp file handles for select() usage to wait for
+ * several RTP streams at the same time.
  * @param h media file context
  */
+
 void rtp_get_file_handles(URLContext *h, int *prtp_fd, int *prtcp_fd)
 {
     RTPContext *s = h->priv_data;
@@ -284,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",
@@ -292,4 +338,5 @@ URLProtocol rtp_protocol = {
     rtp_write,
     NULL, /* seek */
     rtp_close,
+    .url_get_file_handle = rtp_get_file_handle,
 };