]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/udp.c
remove useless &0xFF
[ffmpeg] / libavformat / udp.c
index 0c42945eb1670b4c98ae972e0309b42d092ce9ee..d0aadcefc8ad57097b61306d613470eb6caedc72 100644 (file)
@@ -43,6 +43,7 @@ typedef struct {
 } UDPContext;
 
 #define UDP_TX_BUF_SIZE 32768
+#define UDP_MAX_PKT_SIZE 65536
 
 #ifdef CONFIG_IPV6
 
@@ -321,6 +322,9 @@ static int udp_open(URLContext *h, const char *uri, int flags)
         udp_set_remote_url(h, uri);
     }
 
+    if(!ff_network_init())
+        return AVERROR(EIO);
+
 #ifndef CONFIG_IPV6
     udp_fd = socket(AF_INET, SOCK_DGRAM, 0);
     if (udp_fd < 0)
@@ -393,6 +397,11 @@ static int udp_open(URLContext *h, const char *uri, int flags)
             perror("setsockopt sndbuf");
             goto fail;
         }
+    } else {
+        /* set udp recv buffer size to the largest possible udp packet size to
+         * avoid losing data on OSes that set this too low by default. */
+        tmp = UDP_MAX_PKT_SIZE;
+        setsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &tmp, sizeof(tmp));
     }
 
     s->udp_fd = udp_fd;
@@ -472,6 +481,7 @@ static int udp_close(URLContext *h)
         udp_ipv6_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr);
 #endif
     closesocket(s->udp_fd);
+    ff_network_close();
     av_free(s);
     return 0;
 }