]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/blobdiff - libavformat/udp.c
Added meaningful labels to FWP contracts
[frescor/ffmpeg.git] / libavformat / udp.c
index 91e994506af5c6af25687853640e147cadc193bc..d45288e5e27b79588924428cb21db29590bc9d22 100644 (file)
@@ -35,7 +35,9 @@
 #include <sys/time.h>
 
 #include <frsh.h>
-#include <fwp_endpoint.h>
+#include <frsh_core_types.h>
+
+long int udp_budget, udp_period;
 
 typedef struct {
     int udp_fd;
@@ -52,6 +54,7 @@ typedef struct {
        frsh_vres_id_t vres;
        frsh_send_endpoint_protocol_info_t send_pinfo;
        frsh_contract_t contract;
+       frsh_contract_label_t label;
        frsh_rel_time_t budget, period;
 } UDPContext;
 
@@ -92,9 +95,9 @@ static int is_multicast_address(struct sockaddr_in *addr)
 static int 
 udp_socket_create(UDPContext *s, struct sockaddr_in *addr, int *addr_len)
 {
-       int ret,fd;
-       unsigned int node, port;
-       fwp_endpoint_attr_t attr;
+       static long int netcont_num = 0;
+       int ret,udp_fd;
+       char netcont_name[20];
 
     addr->sin_family = AF_INET;
     addr->sin_addr.s_addr = htonl (INADDR_ANY);
@@ -102,14 +105,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, 30000, &s->budget);
-       s->period = fosa_msec_to_rel_time(1000);
+       frsh_network_bytes_to_budget(FRSH_NETPF_FWP, udp_budget, &s->budget);
+       s->period = fosa_msec_to_rel_time(udp_period);
        s->send_pinfo.body = NULL;              
        
-       if (frsh_send_endpoint_create(FRSH_NETPF_FWP, 
+       udp_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) < 0) {
+                                       &s->sepoint);
+       if (udp_fd < 0) {
                        
                        return -1;
        }
@@ -126,8 +130,10 @@ udp_socket_create(UDPContext *s, struct sockaddr_in *addr, int *addr_len)
                                             FRSH_CT_REGULAR);
        //if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_basic_params");
        if (ret) return -1;
-       ret = frsh_contract_set_resource_and_label(&s->contract,FRSH_RT_NETWORK,
-                                               FRSH_NETPF_FWP, "net_cont1");
+       snprintf(netcont_name, sizeof(netcont_name), "ffmpeg%02d", ++netcont_num);
+       ret = frsh_contract_set_resource_and_label(&s->contract,FRSH_RT_NETWORK,
+                                                  FRSH_NETPF_FWP,
+                                                  s->label[0] ? s->label : netcont_name);
        //if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_resource_and_label");
        if (ret) return -1;
 
@@ -142,7 +148,7 @@ 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 0;
+       return udp_fd;
 }
 
 static int udp_port(struct sockaddr_in *addr, int len)
@@ -252,6 +258,10 @@ static int udp_open(URLContext *h, const char *uri, int flags)
         if (find_info_tag(buf, sizeof(buf), "buffer_size", p)) {
             s->buffer_size = strtol(buf, NULL, 10);
         }
+        if (!find_info_tag(s->label, sizeof(s->label),
+                         "contract_label", p)) {
+               s->label[0]=0;
+        }
     }
 
     /* fill the dest addr */
@@ -278,6 +288,7 @@ static int udp_open(URLContext *h, const char *uri, int flags)
      * bind failed */
     /*if (bind_ret < 0 && bind(udp_fd,(struct sockaddr *)&my_addr, len) < 0)
         goto fail;*/
+#endif
 
     len = sizeof(my_addr);
     getsockname(udp_fd, (struct sockaddr *)&my_addr, &len);
@@ -300,9 +311,9 @@ static int udp_open(URLContext *h, const char *uri, int flags)
         /* make the socket non-blocking */
         ff_socket_nonblock(udp_fd, 1);
     }
-#endif
     s->udp_fd = udp_fd;
     return 0;
  fail:
     if (udp_fd >= 0)
         closesocket(udp_fd);
@@ -331,11 +342,11 @@ static int udp_write(URLContext *h, uint8_t *buf, int size)
 static int udp_close(URLContext *h)
 {
     UDPContext *s = h->priv_data;
-    int ret1, ret2;
+    int ret;
        
-       ret1 = frsh_send_endpoint_destroy(s->sepoint);
-       ret2 = frsh_receive_endpoint_destroy(s->repoint);
-       return (ret1 || ret2);
+       frsh_send_endpoint_unbind(s->sepoint);
+       ret = frsh_contract_cancel(s->vres);
+       return ret;
 }
 
 URLProtocol udp_protocol = {