annotate udp.c @ 1383:97bd1648eb9a libavformat

Add a note about illegal codec IDs.
author diego
date Fri, 13 Oct 2006 00:02:33 +0000
parents 0899bfe4105c
children 7316227e64eb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
2 * UDP prototype streaming system
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1332
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 885
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 #include "avformat.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 #include <unistd.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23 #include <sys/types.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 #include <sys/socket.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25 #include <netinet/in.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26 #ifndef __BEOS__
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 # include <arpa/inet.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29 # include "barpainet.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31 #include <netdb.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32
834
2ad855f5a156 FreeBSD ipv6 multicast patch from ports tree
alex
parents: 825
diff changeset
33 #ifndef IPV6_ADD_MEMBERSHIP
2ad855f5a156 FreeBSD ipv6 multicast patch from ports tree
alex
parents: 825
diff changeset
34 #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
2ad855f5a156 FreeBSD ipv6 multicast patch from ports tree
alex
parents: 825
diff changeset
35 #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
2ad855f5a156 FreeBSD ipv6 multicast patch from ports tree
alex
parents: 825
diff changeset
36 #endif
2ad855f5a156 FreeBSD ipv6 multicast patch from ports tree
alex
parents: 825
diff changeset
37
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 typedef struct {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 int udp_fd;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 int ttl;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 int is_multicast;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 int local_port;
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
43 #ifndef CONFIG_IPV6
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 struct ip_mreq mreq;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 struct sockaddr_in dest_addr;
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
46 #else
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
47 struct sockaddr_storage dest_addr;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
48 size_t dest_addr_len;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
49 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 } UDPContext;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 #define UDP_TX_BUF_SIZE 32768
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
54 #ifdef CONFIG_IPV6
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
55
1124
d3aff2c607f9 Add const to (mostly) char* and make some functions static, which aren't used
diego
parents: 896
diff changeset
56 static int udp_ipv6_is_multicast_address(const struct sockaddr *addr) {
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
57 if (addr->sa_family == AF_INET)
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 834
diff changeset
58 return IN_MULTICAST(ntohl(((struct sockaddr_in *)addr)->sin_addr.s_addr));
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
59 if (addr->sa_family == AF_INET6)
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 834
diff changeset
60 return IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *)addr)->sin6_addr);
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
61 return -1;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
62 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
63
1124
d3aff2c607f9 Add const to (mostly) char* and make some functions static, which aren't used
diego
parents: 896
diff changeset
64 static int udp_ipv6_set_multicast_ttl(int sockfd, int mcastTTL, struct sockaddr *addr) {
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
65 if (addr->sa_family == AF_INET) {
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
66 if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &mcastTTL, sizeof(mcastTTL)) < 0) {
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
67 perror("setsockopt(IP_MULTICAST_TTL)");
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
68 return -1;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
69 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
70 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
71 if (addr->sa_family == AF_INET6) {
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
72 if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &mcastTTL, sizeof(mcastTTL)) < 0) {
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
73 perror("setsockopt(IPV6_MULTICAST_HOPS)");
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
74 return -1;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
75 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
76 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
77 return 0;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
78 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
79
1124
d3aff2c607f9 Add const to (mostly) char* and make some functions static, which aren't used
diego
parents: 896
diff changeset
80 static int udp_ipv6_join_multicast_group(int sockfd, struct sockaddr *addr) {
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
81 struct ip_mreq mreq;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 834
diff changeset
82 struct ipv6_mreq mreq6;
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
83 if (addr->sa_family == AF_INET) {
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
84 mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
85 mreq.imr_interface.s_addr= INADDR_ANY;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
86 if (setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const void *)&mreq, sizeof(mreq)) < 0) {
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
87 perror("setsockopt(IP_ADD_MEMBERSHIP)");
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
88 return -1;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
89 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
90 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
91 if (addr->sa_family == AF_INET6) {
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
92 memcpy(&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6 *)addr)->sin6_addr), sizeof(struct in6_addr));
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
93 mreq6.ipv6mr_interface= 0;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
94 if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) {
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
95 perror("setsockopt(IPV6_ADD_MEMBERSHIP)");
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
96 return -1;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
97 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
98 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
99 return 0;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
100 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
101
1124
d3aff2c607f9 Add const to (mostly) char* and make some functions static, which aren't used
diego
parents: 896
diff changeset
102 static int udp_ipv6_leave_multicast_group(int sockfd, struct sockaddr *addr) {
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
103 struct ip_mreq mreq;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 834
diff changeset
104 struct ipv6_mreq mreq6;
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
105 if (addr->sa_family == AF_INET) {
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
106 mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
107 mreq.imr_interface.s_addr= INADDR_ANY;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
108 if (setsockopt(sockfd, IPPROTO_IP, IP_DROP_MEMBERSHIP, (const void *)&mreq, sizeof(mreq)) < 0) {
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
109 perror("setsockopt(IP_DROP_MEMBERSHIP)");
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
110 return -1;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
111 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
112 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
113 if (addr->sa_family == AF_INET6) {
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
114 memcpy(&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6 *)addr)->sin6_addr), sizeof(struct in6_addr));
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
115 mreq6.ipv6mr_interface= 0;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
116 if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) {
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
117 perror("setsockopt(IPV6_DROP_MEMBERSHIP)");
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
118 return -1;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
119 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
120 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
121 return 0;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
122 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
123
1124
d3aff2c607f9 Add const to (mostly) char* and make some functions static, which aren't used
diego
parents: 896
diff changeset
124 static struct addrinfo* udp_ipv6_resolve_host(const char *hostname, int port, int type, int family, int flags) {
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
125 struct addrinfo hints, *res = 0;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
126 int error;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
127 char sport[16];
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
128 const char *node = 0, *service = 0;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
129
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
130 if (port > 0) {
644
1bbcf7b444ae dissallow sprintf
michael
parents: 579
diff changeset
131 snprintf(sport, sizeof(sport), "%d", port);
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
132 service = sport;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
133 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
134 if ((hostname) && (hostname[0] != '\0') && (hostname[0] != '?')) {
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
135 node = hostname;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
136 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
137 if ((node) || (service)) {
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
138 memset(&hints, 0, sizeof(hints));
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
139 hints.ai_socktype = type;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
140 hints.ai_family = family;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 834
diff changeset
141 hints.ai_flags = flags;
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
142 if ((error = getaddrinfo(node, service, &hints, &res))) {
815
5f9e330500d9 printf-> av_log patch by (Benjamin Larsson, banan: student ltu se)
michael
parents: 683
diff changeset
143 av_log(NULL, AV_LOG_ERROR, "udp_ipv6_resolve_host: %s\n", gai_strerror(error));
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
144 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
145 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
146 return res;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
147 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
148
1124
d3aff2c607f9 Add const to (mostly) char* and make some functions static, which aren't used
diego
parents: 896
diff changeset
149 static int udp_ipv6_set_remote_url(URLContext *h, const char *uri) {
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
150 UDPContext *s = h->priv_data;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
151 char hostname[256];
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
152 int port;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
153 struct addrinfo *res0;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
154 url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
155 res0 = udp_ipv6_resolve_host(hostname, port, SOCK_DGRAM, AF_UNSPEC, 0);
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
156 if (res0 == 0) return AVERROR_IO;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
157 memcpy(&s->dest_addr, res0->ai_addr, res0->ai_addrlen);
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
158 s->dest_addr_len = res0->ai_addrlen;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
159 freeaddrinfo(res0);
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
160 return 0;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
161 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
162
1124
d3aff2c607f9 Add const to (mostly) char* and make some functions static, which aren't used
diego
parents: 896
diff changeset
163 static int udp_ipv6_set_local(URLContext *h) {
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
164 UDPContext *s = h->priv_data;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
165 int udp_fd = -1;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
166 struct sockaddr_storage clientaddr;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
167 socklen_t addrlen;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
168 char sbuf[NI_MAXSERV];
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
169 char hbuf[NI_MAXHOST];
825
c8d4a65729c5 udp ipv6 localhost resolving patch by ("Hans Zandbelt": Hans Zandbelt, telin nl)
michael
parents: 815
diff changeset
170 struct addrinfo *res0 = NULL, *res = NULL;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 834
diff changeset
171
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 834
diff changeset
172 if (s->local_port != 0) {
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
173 res0 = udp_ipv6_resolve_host(0, s->local_port, SOCK_DGRAM, AF_UNSPEC, AI_PASSIVE);
683
095009fc2f35 kill warnings patch by (M«©ns Rullg«©rd <mru inprovide com>)
michael
parents: 644
diff changeset
174 if (res0 == 0)
095009fc2f35 kill warnings patch by (M«©ns Rullg«©rd <mru inprovide com>)
michael
parents: 644
diff changeset
175 goto fail;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 834
diff changeset
176 for (res = res0; res; res=res->ai_next) {
825
c8d4a65729c5 udp ipv6 localhost resolving patch by ("Hans Zandbelt": Hans Zandbelt, telin nl)
michael
parents: 815
diff changeset
177 udp_fd = socket(res->ai_family, SOCK_DGRAM, 0);
c8d4a65729c5 udp ipv6 localhost resolving patch by ("Hans Zandbelt": Hans Zandbelt, telin nl)
michael
parents: 815
diff changeset
178 if (udp_fd > 0) break;
c8d4a65729c5 udp ipv6 localhost resolving patch by ("Hans Zandbelt": Hans Zandbelt, telin nl)
michael
parents: 815
diff changeset
179 perror("socket");
c8d4a65729c5 udp ipv6 localhost resolving patch by ("Hans Zandbelt": Hans Zandbelt, telin nl)
michael
parents: 815
diff changeset
180 }
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
181 } else {
825
c8d4a65729c5 udp ipv6 localhost resolving patch by ("Hans Zandbelt": Hans Zandbelt, telin nl)
michael
parents: 815
diff changeset
182 udp_fd = socket(s->dest_addr.ss_family, SOCK_DGRAM, 0);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 834
diff changeset
183 if (udp_fd < 0)
825
c8d4a65729c5 udp ipv6 localhost resolving patch by ("Hans Zandbelt": Hans Zandbelt, telin nl)
michael
parents: 815
diff changeset
184 perror("socket");
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
185 }
825
c8d4a65729c5 udp ipv6 localhost resolving patch by ("Hans Zandbelt": Hans Zandbelt, telin nl)
michael
parents: 815
diff changeset
186
c8d4a65729c5 udp ipv6 localhost resolving patch by ("Hans Zandbelt": Hans Zandbelt, telin nl)
michael
parents: 815
diff changeset
187 if (udp_fd < 0)
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
188 goto fail;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 834
diff changeset
189
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
190 if (s->local_port != 0) {
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
191 if (bind(udp_fd, res0->ai_addr, res0->ai_addrlen) < 0) {
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
192 perror("bind");
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
193 goto fail;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
194 }
683
095009fc2f35 kill warnings patch by (M«©ns Rullg«©rd <mru inprovide com>)
michael
parents: 644
diff changeset
195 freeaddrinfo(res0);
095009fc2f35 kill warnings patch by (M«©ns Rullg«©rd <mru inprovide com>)
michael
parents: 644
diff changeset
196 res0 = NULL;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 834
diff changeset
197 }
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
198
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
199 addrlen = sizeof(clientaddr);
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
200 if (getsockname(udp_fd, (struct sockaddr *)&clientaddr, &addrlen) < 0) {
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
201 perror("getsockname");
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
202 goto fail;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
203 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
204
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
205 if (getnameinfo((struct sockaddr *)&clientaddr, addrlen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV) != 0) {
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
206 perror("getnameinfo");
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
207 goto fail;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
208 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
209
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
210 s->local_port = strtol(sbuf, NULL, 10);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 834
diff changeset
211
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
212 return udp_fd;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 834
diff changeset
213
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
214 fail:
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
215 if (udp_fd >= 0)
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
216 #ifdef CONFIG_BEOS_NETSERVER
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
217 closesocket(udp_fd);
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
218 #else
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
219 close(udp_fd);
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
220 #endif
683
095009fc2f35 kill warnings patch by (M«©ns Rullg«©rd <mru inprovide com>)
michael
parents: 644
diff changeset
221 if(res0)
095009fc2f35 kill warnings patch by (M«©ns Rullg«©rd <mru inprovide com>)
michael
parents: 644
diff changeset
222 freeaddrinfo(res0);
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
223 return -1;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
224 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
225
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
226 #endif
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
227
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
228
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230 * If no filename is given to av_open_input_file because you want to
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231 * get the local port first, then you must call this function to set
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
232 * the remote server address.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
233 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
234 * url syntax: udp://host:port[?option=val...]
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 834
diff changeset
235 * option: 'multicast=1' : enable multicast
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 * 'ttl=n' : set the ttl value (for multicast only)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237 * 'localport=n' : set the local port
62
56a6676125b4 variable UDP packet size patch by Max Krasnyansky
bellard
parents: 0
diff changeset
238 * 'pkt_size=n' : set max packet size
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240 * @param s1 media file context
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
241 * @param uri of the remote server
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242 * @return zero if no error.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
244 int udp_set_remote_url(URLContext *h, const char *uri)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245 {
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
246 #ifdef CONFIG_IPV6
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
247 return udp_ipv6_set_remote_url(h, uri);
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
248 #else
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 UDPContext *s = h->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250 char hostname[256];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251 int port;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 834
diff changeset
252
511
056991ab9f10 HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents: 482
diff changeset
253 url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
255 /* set the destination address */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
256 if (resolve_host(&s->dest_addr.sin_addr, hostname) < 0)
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 161
diff changeset
257 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 s->dest_addr.sin_family = AF_INET;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259 s->dest_addr.sin_port = htons(port);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
260 return 0;
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
261 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
263
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
264 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
265 * Return the local port used by the UDP connexion
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
266 * @param s1 media file context
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
267 * @return the local port number
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
268 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
269 int udp_get_local_port(URLContext *h)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
270 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
271 UDPContext *s = h->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
272 return s->local_port;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
273 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
274
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
275 /**
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
276 * Return the udp file handle for select() usage to wait for several RTP
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
277 * streams at the same time.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
278 * @param h media file context
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
279 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
280 int udp_get_file_handle(URLContext *h)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
281 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
282 UDPContext *s = h->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
283 return s->udp_fd;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
284 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
285
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
286 /* put it in UDP context */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
287 /* return non zero if error */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
288 static int udp_open(URLContext *h, const char *uri, int flags)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
289 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
290 char hostname[1024];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
291 int port, udp_fd = -1, tmp;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
292 UDPContext *s = NULL;
683
095009fc2f35 kill warnings patch by (M«©ns Rullg«©rd <mru inprovide com>)
michael
parents: 644
diff changeset
293 int is_output;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
294 const char *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
295 char buf[256];
683
095009fc2f35 kill warnings patch by (M«©ns Rullg«©rd <mru inprovide com>)
michael
parents: 644
diff changeset
296 #ifndef CONFIG_IPV6
095009fc2f35 kill warnings patch by (M«©ns Rullg«©rd <mru inprovide com>)
michael
parents: 644
diff changeset
297 struct sockaddr_in my_addr, my_addr1;
095009fc2f35 kill warnings patch by (M«©ns Rullg«©rd <mru inprovide com>)
michael
parents: 644
diff changeset
298 int len;
095009fc2f35 kill warnings patch by (M«©ns Rullg«©rd <mru inprovide com>)
michael
parents: 644
diff changeset
299 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
300
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
301 h->is_streamed = 1;
62
56a6676125b4 variable UDP packet size patch by Max Krasnyansky
bellard
parents: 0
diff changeset
302 h->max_packet_size = 1472;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
303
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
304 is_output = (flags & URL_WRONLY);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 834
diff changeset
305
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
306 s = av_malloc(sizeof(UDPContext));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
307 if (!s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
308 return -ENOMEM;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
309
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
310 h->priv_data = s;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
311 s->ttl = 16;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
312 s->is_multicast = 0;
161
e01949598794 undefined local_port fix by (Giancarlo Formicuccia <ilsensine at inwind dot it>)
michaelni
parents: 65
diff changeset
313 s->local_port = 0;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
314 p = strchr(uri, '?');
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
315 if (p) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
316 s->is_multicast = find_info_tag(buf, sizeof(buf), "multicast", p);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
317 if (find_info_tag(buf, sizeof(buf), "ttl", p)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
318 s->ttl = strtol(buf, NULL, 10);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
319 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
320 if (find_info_tag(buf, sizeof(buf), "localport", p)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
321 s->local_port = strtol(buf, NULL, 10);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
322 }
62
56a6676125b4 variable UDP packet size patch by Max Krasnyansky
bellard
parents: 0
diff changeset
323 if (find_info_tag(buf, sizeof(buf), "pkt_size", p)) {
56a6676125b4 variable UDP packet size patch by Max Krasnyansky
bellard
parents: 0
diff changeset
324 h->max_packet_size = strtol(buf, NULL, 10);
56a6676125b4 variable UDP packet size patch by Max Krasnyansky
bellard
parents: 0
diff changeset
325 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
326 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
327
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
328 /* fill the dest addr */
511
056991ab9f10 HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents: 482
diff changeset
329 url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 834
diff changeset
330
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
331 /* XXX: fix url_split */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
332 if (hostname[0] == '\0' || hostname[0] == '?') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
333 /* only accepts null hostname if input */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
334 if (s->is_multicast || (flags & URL_WRONLY))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
335 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
336 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
337 udp_set_remote_url(h, uri);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
338 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
339
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
340 #ifndef CONFIG_IPV6
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
341 udp_fd = socket(PF_INET, SOCK_DGRAM, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
342 if (udp_fd < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
343 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
344
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
345 my_addr.sin_family = AF_INET;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
346 my_addr.sin_addr.s_addr = htonl (INADDR_ANY);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
347 if (s->is_multicast && !(h->flags & URL_WRONLY)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
348 /* special case: the bind must be done on the multicast address port */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
349 my_addr.sin_port = s->dest_addr.sin_port;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
350 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
351 my_addr.sin_port = htons(s->local_port);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
352 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
353
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
354 /* the bind is needed to give a port to the socket now */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 834
diff changeset
355 if (bind(udp_fd,(struct sockaddr *)&my_addr, sizeof(my_addr)) < 0)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
356 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
357
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
358 len = sizeof(my_addr1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
359 getsockname(udp_fd, (struct sockaddr *)&my_addr1, &len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
360 s->local_port = ntohs(my_addr1.sin_port);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
361
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
362 #ifndef CONFIG_BEOS_NETSERVER
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
363 if (s->is_multicast) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
364 if (h->flags & URL_WRONLY) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
365 /* output */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 834
diff changeset
366 if (setsockopt(udp_fd, IPPROTO_IP, IP_MULTICAST_TTL,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
367 &s->ttl, sizeof(s->ttl)) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
368 perror("IP_MULTICAST_TTL");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
369 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
370 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
371 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
372 /* input */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
373 memset(&s->mreq, 0, sizeof(s->mreq));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
374 s->mreq.imr_multiaddr = s->dest_addr.sin_addr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
375 s->mreq.imr_interface.s_addr = htonl (INADDR_ANY);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 834
diff changeset
376 if (setsockopt(udp_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
377 &s->mreq, sizeof(s->mreq)) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
378 perror("rtp: IP_ADD_MEMBERSHIP");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
379 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
380 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
381 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
382 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
383 #endif
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
384 #else
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
385 if (s->is_multicast && !(h->flags & URL_WRONLY))
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
386 s->local_port = port;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
387 udp_fd = udp_ipv6_set_local(h);
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
388 if (udp_fd < 0)
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
389 goto fail;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
390 #ifndef CONFIG_BEOS_NETSERVER
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
391 if (s->is_multicast) {
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
392 if (h->flags & URL_WRONLY) {
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
393 if (udp_ipv6_set_multicast_ttl(udp_fd, s->ttl, (struct sockaddr *)&s->dest_addr) < 0)
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
394 goto fail;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
395 } else {
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
396 if (udp_ipv6_join_multicast_group(udp_fd, (struct sockaddr *)&s->dest_addr) < 0)
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
397 goto fail;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
398 }
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
399 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 834
diff changeset
400 #endif
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
401 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
402
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
403 if (is_output) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
404 /* limit the tx buf size to limit latency */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
405 tmp = UDP_TX_BUF_SIZE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
406 if (setsockopt(udp_fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp)) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
407 perror("setsockopt sndbuf");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
408 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
409 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
410 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
411
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
412 s->udp_fd = udp_fd;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
413 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
414 fail:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
415 if (udp_fd >= 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
416 #ifdef CONFIG_BEOS_NETSERVER
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
417 closesocket(udp_fd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
418 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
419 close(udp_fd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
420 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
421 av_free(s);
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 161
diff changeset
422 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
423 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
424
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 62
diff changeset
425 static int udp_read(URLContext *h, uint8_t *buf, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
426 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
427 UDPContext *s = h->priv_data;
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
428 #ifndef CONFIG_IPV6
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
429 struct sockaddr_in from;
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
430 #else
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
431 struct sockaddr_storage from;
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
432 #endif
1332
7474cc6383d4 fix some signedness warnings
mru
parents: 1124
diff changeset
433 socklen_t from_len;
7474cc6383d4 fix some signedness warnings
mru
parents: 1124
diff changeset
434 int len;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
435
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
436 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
437 from_len = sizeof(from);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
438 len = recvfrom (s->udp_fd, buf, size, 0,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
439 (struct sockaddr *)&from, &from_len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
440 if (len < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
441 if (errno != EAGAIN && errno != EINTR)
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 161
diff changeset
442 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
443 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
444 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
445 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
446 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
447 return len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
448 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
449
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 62
diff changeset
450 static int udp_write(URLContext *h, uint8_t *buf, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
451 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
452 UDPContext *s = h->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
453 int ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
454
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
455 for(;;) {
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 834
diff changeset
456 ret = sendto (s->udp_fd, buf, size, 0,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
457 (struct sockaddr *) &s->dest_addr,
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
458 #ifndef CONFIG_IPV6
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
459 sizeof (s->dest_addr));
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
460 #else
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
461 s->dest_addr_len);
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
462 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
463 if (ret < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
464 if (errno != EINTR && errno != EAGAIN)
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 161
diff changeset
465 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
466 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
467 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
468 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
469 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
470 return size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
471 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
472
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
473 static int udp_close(URLContext *h)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
474 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
475 UDPContext *s = h->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
476
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
477 #ifndef CONFIG_BEOS_NETSERVER
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
478 #ifndef CONFIG_IPV6
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
479 if (s->is_multicast && !(h->flags & URL_WRONLY)) {
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 834
diff changeset
480 if (setsockopt(s->udp_fd, IPPROTO_IP, IP_DROP_MEMBERSHIP,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
481 &s->mreq, sizeof(s->mreq)) < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
482 perror("IP_DROP_MEMBERSHIP");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
483 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
484 }
579
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
485 #else
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
486 if (s->is_multicast && !(h->flags & URL_WRONLY))
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
487 udp_ipv6_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr);
117ece7c24a6 IPv6 support patch by ("Hans Zandbelt" <Hans.Zandbelt <at> telin {dot} nl>)
michael
parents: 511
diff changeset
488 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
489 close(s->udp_fd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
490 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
491 closesocket(s->udp_fd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
492 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
493 av_free(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
494 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
495 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
496
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
497 URLProtocol udp_protocol = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
498 "udp",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
499 udp_open,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
500 udp_read,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
501 udp_write,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
502 NULL, /* seek */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
503 udp_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
504 };