OLD | NEW |
1 /* | 1 /* |
2 * UDP prototype streaming system | 2 * UDP prototype streaming system |
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard | 3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard |
4 * | 4 * |
5 * This file is part of FFmpeg. | 5 * This file is part of FFmpeg. |
6 * | 6 * |
7 * FFmpeg is free software; you can redistribute it and/or | 7 * FFmpeg is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Lesser General Public | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2.1 of the License, or (at your option) any later version. | 10 * version 2.1 of the License, or (at your option) any later version. |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 service = sport; | 152 service = sport; |
153 } | 153 } |
154 if ((hostname) && (hostname[0] != '\0') && (hostname[0] != '?')) { | 154 if ((hostname) && (hostname[0] != '\0') && (hostname[0] != '?')) { |
155 node = hostname; | 155 node = hostname; |
156 } | 156 } |
157 memset(&hints, 0, sizeof(hints)); | 157 memset(&hints, 0, sizeof(hints)); |
158 hints.ai_socktype = type; | 158 hints.ai_socktype = type; |
159 hints.ai_family = family; | 159 hints.ai_family = family; |
160 hints.ai_flags = flags; | 160 hints.ai_flags = flags; |
161 if ((error = getaddrinfo(node, service, &hints, &res))) { | 161 if ((error = getaddrinfo(node, service, &hints, &res))) { |
| 162 res = NULL; |
162 av_log(NULL, AV_LOG_ERROR, "udp_resolve_host: %s\n", gai_strerror(error)
); | 163 av_log(NULL, AV_LOG_ERROR, "udp_resolve_host: %s\n", gai_strerror(error)
); |
163 } | 164 } |
164 | 165 |
165 return res; | 166 return res; |
166 } | 167 } |
167 | 168 |
168 static int udp_set_url(struct sockaddr_storage *addr, | 169 static int udp_set_url(struct sockaddr_storage *addr, |
169 const char *hostname, int port) | 170 const char *hostname, int port) |
170 { | 171 { |
171 struct addrinfo *res0; | 172 struct addrinfo *res0; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 * @param s1 media file context | 258 * @param s1 media file context |
258 * @param uri of the remote server | 259 * @param uri of the remote server |
259 * @return zero if no error. | 260 * @return zero if no error. |
260 */ | 261 */ |
261 int udp_set_remote_url(URLContext *h, const char *uri) | 262 int udp_set_remote_url(URLContext *h, const char *uri) |
262 { | 263 { |
263 UDPContext *s = h->priv_data; | 264 UDPContext *s = h->priv_data; |
264 char hostname[256]; | 265 char hostname[256]; |
265 int port; | 266 int port; |
266 | 267 |
267 url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri)
; | 268 ff_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, u
ri); |
268 | 269 |
269 /* set the destination address */ | 270 /* set the destination address */ |
270 s->dest_addr_len = udp_set_url(&s->dest_addr, hostname, port); | 271 s->dest_addr_len = udp_set_url(&s->dest_addr, hostname, port); |
271 if (s->dest_addr_len < 0) { | 272 if (s->dest_addr_len < 0) { |
272 return AVERROR(EIO); | 273 return AVERROR(EIO); |
273 } | 274 } |
274 s->is_multicast = is_multicast_address(&s->dest_addr); | 275 s->is_multicast = is_multicast_address(&s->dest_addr); |
275 | 276 |
276 return 0; | 277 return 0; |
277 } | 278 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 const char *p; | 313 const char *p; |
313 char buf[256]; | 314 char buf[256]; |
314 struct sockaddr_storage my_addr; | 315 struct sockaddr_storage my_addr; |
315 int len; | 316 int len; |
316 | 317 |
317 h->is_streamed = 1; | 318 h->is_streamed = 1; |
318 h->max_packet_size = 1472; | 319 h->max_packet_size = 1472; |
319 | 320 |
320 is_output = (flags & URL_WRONLY); | 321 is_output = (flags & URL_WRONLY); |
321 | 322 |
322 if(!ff_network_init()) | |
323 return AVERROR(EIO); | |
324 | |
325 s = av_mallocz(sizeof(UDPContext)); | 323 s = av_mallocz(sizeof(UDPContext)); |
326 if (!s) | 324 if (!s) |
327 return AVERROR(ENOMEM); | 325 return AVERROR(ENOMEM); |
328 | 326 |
329 h->priv_data = s; | 327 h->priv_data = s; |
330 s->ttl = 16; | 328 s->ttl = 16; |
331 s->buffer_size = is_output ? UDP_TX_BUF_SIZE : UDP_MAX_PKT_SIZE; | 329 s->buffer_size = is_output ? UDP_TX_BUF_SIZE : UDP_MAX_PKT_SIZE; |
332 | 330 |
333 p = strchr(uri, '?'); | 331 p = strchr(uri, '?'); |
334 if (p) { | 332 if (p) { |
335 s->reuse_socket = find_info_tag(buf, sizeof(buf), "reuse", p); | 333 s->reuse_socket = find_info_tag(buf, sizeof(buf), "reuse", p); |
336 if (find_info_tag(buf, sizeof(buf), "ttl", p)) { | 334 if (find_info_tag(buf, sizeof(buf), "ttl", p)) { |
337 s->ttl = strtol(buf, NULL, 10); | 335 s->ttl = strtol(buf, NULL, 10); |
338 } | 336 } |
339 if (find_info_tag(buf, sizeof(buf), "localport", p)) { | 337 if (find_info_tag(buf, sizeof(buf), "localport", p)) { |
340 s->local_port = strtol(buf, NULL, 10); | 338 s->local_port = strtol(buf, NULL, 10); |
341 } | 339 } |
342 if (find_info_tag(buf, sizeof(buf), "pkt_size", p)) { | 340 if (find_info_tag(buf, sizeof(buf), "pkt_size", p)) { |
343 h->max_packet_size = strtol(buf, NULL, 10); | 341 h->max_packet_size = strtol(buf, NULL, 10); |
344 } | 342 } |
345 if (find_info_tag(buf, sizeof(buf), "buffer_size", p)) { | 343 if (find_info_tag(buf, sizeof(buf), "buffer_size", p)) { |
346 s->buffer_size = strtol(buf, NULL, 10); | 344 s->buffer_size = strtol(buf, NULL, 10); |
347 } | 345 } |
348 } | 346 } |
349 | 347 |
350 /* fill the dest addr */ | 348 /* fill the dest addr */ |
351 url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri)
; | 349 ff_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, u
ri); |
352 | 350 |
353 /* XXX: fix url_split */ | 351 /* XXX: fix ff_url_split */ |
354 if (hostname[0] == '\0' || hostname[0] == '?') { | 352 if (hostname[0] == '\0' || hostname[0] == '?') { |
355 /* only accepts null hostname if input */ | 353 /* only accepts null hostname if input */ |
356 if (flags & URL_WRONLY) | 354 if (flags & URL_WRONLY) |
357 goto fail; | 355 goto fail; |
358 } else { | 356 } else { |
359 udp_set_remote_url(h, uri); | 357 udp_set_remote_url(h, uri); |
360 } | 358 } |
361 | 359 |
362 if (s->is_multicast && !(h->flags & URL_WRONLY)) | 360 if (s->is_multicast && !(h->flags & URL_WRONLY)) |
363 s->local_port = port; | 361 s->local_port = port; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 return size; | 472 return size; |
475 } | 473 } |
476 | 474 |
477 static int udp_close(URLContext *h) | 475 static int udp_close(URLContext *h) |
478 { | 476 { |
479 UDPContext *s = h->priv_data; | 477 UDPContext *s = h->priv_data; |
480 | 478 |
481 if (s->is_multicast && !(h->flags & URL_WRONLY)) | 479 if (s->is_multicast && !(h->flags & URL_WRONLY)) |
482 udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr); | 480 udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr); |
483 closesocket(s->udp_fd); | 481 closesocket(s->udp_fd); |
484 ff_network_close(); | |
485 av_free(s); | 482 av_free(s); |
486 return 0; | 483 return 0; |
487 } | 484 } |
488 | 485 |
489 URLProtocol udp_protocol = { | 486 URLProtocol udp_protocol = { |
490 "udp", | 487 "udp", |
491 udp_open, | 488 udp_open, |
492 udp_read, | 489 udp_read, |
493 udp_write, | 490 udp_write, |
494 NULL, /* seek */ | 491 NULL, /* seek */ |
495 udp_close, | 492 udp_close, |
496 .url_get_file_handle = udp_get_file_handle, | 493 .url_get_file_handle = udp_get_file_handle, |
497 }; | 494 }; |
OLD | NEW |