]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/commitdiff
Put FRSH support as a separate protocol
authorMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 26 Nov 2009 23:57:32 +0000 (00:57 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 26 Nov 2009 23:57:32 +0000 (00:57 +0100)
This helps to overcome OMK's unability to remove objects from existing
libraries (when compiled without make clean).

If I wanted to switch between FRSH and non-FRSH version I always had to
delete the library manually.

libavformat/allformats.c
libavformat/frsh.c
libavformat/rtpproto.c

index 626b66cf2e61ed4de1b7c019a7be8b83d87d63f5..17dc7fcf4e8988d86618b960118a39d62d137a5c 100644 (file)
 #include "rtp.h"
 #include "rdt.h"
 
+#ifdef OMK_FOR_USER
+# include "libavformat_config.h"
+# ifdef CONFIG_FFMPEG_WITH_FRSH
+#  define CONFIG_FRSH_PROTOCOL 1
+# else
+#  define CONFIG_FRSH_PROTOCOL 0
+# endif
+#endif
+
+#ifndef CONFIG_FRSH_PROTOCOL
+#define CONFIG_FRSH_PROTOCOL 0
+#endif
+
+
 #define REGISTER_MUXER(X,x) { \
     extern AVOutputFormat x##_muxer; \
     if(CONFIG_##X##_MUXER) av_register_output_format(&x##_muxer); }
@@ -210,4 +224,5 @@ void av_register_all(void)
     REGISTER_PROTOCOL (RTP, rtp);
     REGISTER_PROTOCOL (TCP, tcp);
     REGISTER_PROTOCOL (UDP, udp);
+    REGISTER_PROTOCOL (FRSH, frsh);
 }
index 82c8460d0559d8b6f65bbf281ed505f1ac2c0181..5044ca26fa77df7ae5a2b4a94683017be11956c4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * UDP prototype streaming system
+ * FRSH prototype streaming system
  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
  *
  * This file is part of FFmpeg.
@@ -20,8 +20,8 @@
  */
 
 /**
- * @file libavformat/udp.c
- * UDP protocol
+ * @file libavformat/frsh.c
+ * FRSH protocol
  */
 
 #include "avformat.h"
 #include <frsh.h>
 #include <frsh_core_types.h>
 
-long int udp_budget, udp_period;
+long int avformat_frsh_budget, avformat_frsh_period;
 
 typedef struct {
-    int udp_fd;
+    int frsh_fd;
     int ttl;
     int buffer_size;
     int is_multicast;
@@ -55,27 +55,27 @@ typedef struct {
        frsh_contract_t contract;
        frsh_contract_label_t label;
        frsh_rel_time_t budget, period;
-} UDPContext;
+} FRSHContext;
 
-#define UDP_TX_BUF_SIZE 32768
-#define UDP_MAX_PKT_SIZE 65536
+#define FRSH_TX_BUF_SIZE 32768
+#define FRSH_MAX_PKT_SIZE 65536
 
-static int udp_set_multicast_ttl(int sockfd, int mcastTTL, struct sockaddr *addr) 
+static int frsh_set_multicast_ttl(int sockfd, int mcastTTL, struct sockaddr *addr) 
 {
     return 0;
 }
 
-static int udp_join_multicast_group(int sockfd, struct sockaddr *addr) 
+static int frsh_join_multicast_group(int sockfd, struct sockaddr *addr) 
 {
     return 0;
 }
 
-static int udp_leave_multicast_group(int sockfd, struct sockaddr *addr) 
+static int frsh_leave_multicast_group(int sockfd, struct sockaddr *addr) 
 {
     return 0;
 }
 
-static int udp_set_url(struct sockaddr_in *addr, const char *hostname, int port)
+static int frsh_set_url(struct sockaddr_in *addr, const char *hostname, int port)
 {
     /* set the destination address */
     if (resolve_host(&addr->sin_addr, hostname) < 0)
@@ -92,10 +92,10 @@ static int is_multicast_address(struct sockaddr_in *addr)
 }
 
 static int 
-udp_socket_create(UDPContext *s, struct sockaddr_in *addr, int *addr_len)
+frsh_socket_create(FRSHContext *s, struct sockaddr_in *addr, int *addr_len)
 {
        static long int netcont_num = 0;
-       int ret,udp_fd;
+       int ret,frsh_fd;
        char netcont_name[20];
 
     addr->sin_family = AF_INET;
@@ -104,15 +104,15 @@ udp_socket_create(UDPContext *s, struct sockaddr_in *addr, int *addr_len)
     *addr_len = sizeof(struct sockaddr_in);
 
        /* set params for contract */
-       frsh_network_bytes_to_budget(FRSH_NETPF_FWP, udp_budget, &s->budget);
-       s->period = fosa_msec_to_rel_time(udp_period);
+       frsh_network_bytes_to_budget(FRSH_NETPF_FWP, avformat_frsh_budget, &s->budget);
+       s->period = fosa_msec_to_rel_time(avformat_frsh_period);
        s->send_pinfo.body = NULL;              
        
-       udp_fd = frsh_send_endpoint_create(FRSH_NETPF_FWP, 
+       frsh_fd = frsh_send_endpoint_create(FRSH_NETPF_FWP, 
                                        s->dest_addr.sin_addr.s_addr,
                                        ntohs(s->dest_addr.sin_port), s->send_pinfo, 
                                        &s->sepoint);
-       if (udp_fd < 0) {
+       if (frsh_fd < 0) {
                        
                        return -1;
        }
@@ -147,10 +147,10 @@ udp_socket_create(UDPContext *s, struct sockaddr_in *addr, int *addr_len)
        //fwp_endpoint_get_params(s->sepoint->protocol_info.body, &node,
        //              &port, &attr, &fd);
 
-       return udp_fd;
+       return frsh_fd;
 }
 
-static int udp_port(struct sockaddr_in *addr, int len)
+static int frsh_port(struct sockaddr_in *addr, int len)
 {
     return ntohs(addr->sin_port);
 }
@@ -160,7 +160,7 @@ static int udp_port(struct sockaddr_in *addr, int len)
  * get the local port first, then you must call this function to set
  * the remote server address.
  *
- * url syntax: udp://host:port[?option=val...]
+ * url syntax: frsh://host:port[?option=val...]
  * option: 'ttl=n'       : set the ttl value (for multicast only)
  *         'localport=n' : set the local port
  *         'pkt_size=n'  : set max packet size
@@ -170,16 +170,16 @@ static int udp_port(struct sockaddr_in *addr, int len)
  * @param uri of the remote server
  * @return zero if no error.
  */
-int udp_set_remote_url(URLContext *h, const char *uri)
+int frsh_set_remote_url(URLContext *h, const char *uri)
 {
-    UDPContext *s = h->priv_data;
+    FRSHContext *s = h->priv_data;
     char hostname[256];
     int port;
 
     url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
 
     /* set the destination address */
-    s->dest_addr_len = udp_set_url(&s->dest_addr, hostname, port);
+    s->dest_addr_len = frsh_set_url(&s->dest_addr, hostname, port);
     if (s->dest_addr_len < 0) {
         return AVERROR(EIO);
     }
@@ -189,37 +189,37 @@ int udp_set_remote_url(URLContext *h, const char *uri)
 }
 
 /**
- * Return the local port used by the UDP connexion
+ * Return the local port used by the FRSH connexion
  * @param s1 media file context
  * @return the local port number
  */
-int udp_get_local_port(URLContext *h)
+int frsh_get_local_port(URLContext *h)
 {
-    UDPContext *s = h->priv_data;
+    FRSHContext *s = h->priv_data;
     return s->local_port;
 }
 
 /**
- * Return the udp file handle for select() usage to wait for several RTP
+ * Return the frsh file handle for select() usage to wait for several RTP
  * streams at the same time.
  * @param h media file context
  */
 #if (LIBAVFORMAT_VERSION_MAJOR >= 53)
 static
 #endif
-int udp_get_file_handle(URLContext *h)
+int frsh_get_file_handle(URLContext *h)
 {
-    UDPContext *s = h->priv_data;
-    return s->udp_fd;
+    FRSHContext *s = h->priv_data;
+    return s->frsh_fd;
 }
 
-/* put it in UDP context */
+/* put it in FRSH context */
 /* return non zero if error */
-static int udp_open(URLContext *h, const char *uri, int flags)
+static int frsh_open(URLContext *h, const char *uri, int flags)
 {
     char hostname[1024];
-    int port, udp_fd = -1, tmp;
-    UDPContext *s = NULL;
+    int port, frsh_fd = -1, tmp;
+    FRSHContext *s = NULL;
     int is_output;
     const char *p;
     char buf[256];
@@ -234,13 +234,13 @@ static int udp_open(URLContext *h, const char *uri, int flags)
     if(!ff_network_init())
         return AVERROR(EIO);
 
-    s = av_mallocz(sizeof(UDPContext));
+    s = av_mallocz(sizeof(FRSHContext));
     if (!s)
         return AVERROR(ENOMEM);
 
     h->priv_data = s;
     s->ttl = 16;
-    s->buffer_size = is_output ? UDP_TX_BUF_SIZE : UDP_MAX_PKT_SIZE;
+    s->buffer_size = is_output ? FRSH_TX_BUF_SIZE : FRSH_MAX_PKT_SIZE;
 
     p = strchr(uri, '?');
     if (p) {
@@ -272,75 +272,75 @@ static int udp_open(URLContext *h, const char *uri, int flags)
         if (flags & URL_WRONLY)
             goto fail;
     } else {
-        udp_set_remote_url(h, uri);
+        frsh_set_remote_url(h, uri);
     }
 
-    udp_fd = udp_socket_create(s, &my_addr, &len);
-    if (udp_fd < 0)
+    frsh_fd = frsh_socket_create(s, &my_addr, &len);
+    if (frsh_fd < 0)
         goto fail;
 #if 0
     if (s->reuse_socket)
-        if (setsockopt (udp_fd, SOL_SOCKET, SO_REUSEADDR, &(s->reuse_socket), sizeof(s->reuse_socket)) != 0)
+        if (setsockopt (frsh_fd, SOL_SOCKET, SO_REUSEADDR, &(s->reuse_socket), sizeof(s->reuse_socket)) != 0)
             goto fail;
 
     /* bind to the local address if not multicast or if the multicast
      * bind failed */
-    /*if (bind_ret < 0 && bind(udp_fd,(struct sockaddr *)&my_addr, len) < 0)
+    /*if (bind_ret < 0 && bind(frsh_fd,(struct sockaddr *)&my_addr, len) < 0)
         goto fail;*/
 #endif
 
     len = sizeof(my_addr);
-    getsockname(udp_fd, (struct sockaddr *)&my_addr, &len);
-    s->local_port = udp_port(&my_addr, len);
+    getsockname(frsh_fd, (struct sockaddr *)&my_addr, &len);
+    s->local_port = frsh_port(&my_addr, len);
 
     if (is_output) {
         /* limit the tx buf size to limit latency */
         tmp = s->buffer_size;
-        if (setsockopt(udp_fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp)) < 0) {
+        if (setsockopt(frsh_fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp)) < 0) {
             av_log(NULL, AV_LOG_ERROR, "setsockopt(SO_SNDBUF): %s\n", strerror(errno));
             goto fail;
         }
     } else {
-        /* set udp recv buffer size to the largest possible udp packet size to
+        /* set frsh recv buffer size to the largest possible frsh packet size to
          * avoid losing data on OSes that set this too low by default. */
         tmp = s->buffer_size;
-        if (setsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &tmp, sizeof(tmp)) < 0) {
+        if (setsockopt(frsh_fd, SOL_SOCKET, SO_RCVBUF, &tmp, sizeof(tmp)) < 0) {
             av_log(NULL, AV_LOG_WARNING, "setsockopt(SO_RECVBUF): %s\n", strerror(errno));
         }
         /* make the socket non-blocking */
-        ff_socket_nonblock(udp_fd, 1);
+        ff_socket_nonblock(frsh_fd, 1);
     }
-    s->udp_fd = udp_fd;
+    s->frsh_fd = frsh_fd;
     return 0;
  
  fail:
-    if (udp_fd >= 0)
-        closesocket(udp_fd);
+    if (frsh_fd >= 0)
+        closesocket(frsh_fd);
     av_free(s);
     return AVERROR(EIO);
 }
 
-static int udp_read(URLContext *h, uint8_t *buf, int size)
+static int frsh_read(URLContext *h, uint8_t *buf, int size)
 {
-    UDPContext *s = h->priv_data;
+    FRSHContext *s = h->priv_data;
     unsigned int from;
        int len;
 
     return frsh_receive_sync(s->repoint, buf, size, &len, &from);
 }
 
-static int udp_write(URLContext *h, uint8_t *buf, int size)
+static int frsh_write(URLContext *h, uint8_t *buf, int size)
 {
-    UDPContext *s = h->priv_data;
+    FRSHContext *s = h->priv_data;
     int ret;
        
        ret = frsh_send_async(s->sepoint, buf, size);
        return ret;
 }
 
-static int udp_close(URLContext *h)
+static int frsh_close(URLContext *h)
 {
-    UDPContext *s = h->priv_data;
+    FRSHContext *s = h->priv_data;
     int ret;
        
        frsh_send_endpoint_unbind(s->sepoint);
@@ -348,12 +348,12 @@ static int udp_close(URLContext *h)
        return ret;
 }
 
-URLProtocol udp_protocol = {
-    "udp",
-    udp_open,
-    udp_read,
-    udp_write,
+URLProtocol frsh_protocol = {
+    "frsh",
+    frsh_open,
+    frsh_read,
+    frsh_write,
     NULL, /* seek */
-    udp_close,
-    .url_get_file_handle = udp_get_file_handle,
+    frsh_close,
+    .url_get_file_handle = frsh_get_file_handle,
 };
index ca7af2f95f1b8222ec71b1c354e7e574a7d3a3e0..727c799619801d4104b29f6151a153353d21e8b0 100644 (file)
 #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;
 }
@@ -101,7 +111,7 @@ static void build_udp_url(char *buf, int buf_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)