Mercurial > libavformat.hg
comparison sdp.c @ 5525:f484a964bed1 libavformat
Make sure the destination address is written as an IP address in the SDP
Patch by Martin Storsjo (martin AT martin DOT st)
author | lucabe |
---|---|
date | Tue, 12 Jan 2010 10:56:43 +0000 |
parents | 89259491d541 |
children | 7a123cc24a81 |
comparison
equal
deleted
inserted
replaced
5524:043b36cefe89 | 5525:f484a964bed1 |
---|---|
23 #include "libavutil/base64.h" | 23 #include "libavutil/base64.h" |
24 #include "avformat.h" | 24 #include "avformat.h" |
25 #include "internal.h" | 25 #include "internal.h" |
26 #include "avc.h" | 26 #include "avc.h" |
27 #include "rtp.h" | 27 #include "rtp.h" |
28 #if CONFIG_NETWORK | |
29 #include "network.h" | |
30 #endif | |
28 | 31 |
29 #if CONFIG_RTP_MUXER | 32 #if CONFIG_RTP_MUXER |
30 #define MAX_EXTRADATA_SIZE ((INT_MAX - 10) / 2) | 33 #define MAX_EXTRADATA_SIZE ((INT_MAX - 10) / 2) |
31 | 34 |
32 struct sdp_session_level { | 35 struct sdp_session_level { |
67 av_strlcatf(buff, size, "t=%d %d\r\n" | 70 av_strlcatf(buff, size, "t=%d %d\r\n" |
68 "a=tool:libavformat " AV_STRINGIFY(LIBAVFORMAT_VERSION) "\r\n", | 71 "a=tool:libavformat " AV_STRINGIFY(LIBAVFORMAT_VERSION) "\r\n", |
69 s->start_time, s->end_time); | 72 s->start_time, s->end_time); |
70 } | 73 } |
71 | 74 |
75 #if CONFIG_NETWORK | |
76 static void resolve_destination(char *dest_addr, int size) | |
77 { | |
78 struct addrinfo hints, *ai, *cur; | |
79 | |
80 if (!dest_addr[0]) | |
81 return; | |
82 | |
83 /* Resolve the destination, since it must be written | |
84 * as a numeric IP address in the SDP. */ | |
85 | |
86 memset(&hints, 0, sizeof(hints)); | |
87 /* We only support IPv4 addresses in the SDP at the moment. */ | |
88 hints.ai_family = AF_INET; | |
89 if (getaddrinfo(dest_addr, NULL, &hints, &ai)) | |
90 return; | |
91 for (cur = ai; cur; cur = cur->ai_next) { | |
92 if (cur->ai_family == AF_INET) { | |
93 getnameinfo(cur->ai_addr, cur->ai_addrlen, dest_addr, size, | |
94 NULL, 0, NI_NUMERICHOST); | |
95 break; | |
96 } | |
97 } | |
98 freeaddrinfo(ai); | |
99 } | |
100 #else | |
101 static void resolve_destination(char *dest_addr, int size) | |
102 { | |
103 } | |
104 #endif | |
105 | |
72 static int sdp_get_address(char *dest_addr, int size, int *ttl, const char *url) | 106 static int sdp_get_address(char *dest_addr, int size, int *ttl, const char *url) |
73 { | 107 { |
74 int port; | 108 int port; |
75 const char *p; | 109 const char *p; |
76 char proto[32]; | 110 char proto[32]; |
301 | 335 |
302 port = 0; | 336 port = 0; |
303 ttl = 0; | 337 ttl = 0; |
304 if (n_files == 1) { | 338 if (n_files == 1) { |
305 port = sdp_get_address(dst, sizeof(dst), &ttl, ac[0]->filename); | 339 port = sdp_get_address(dst, sizeof(dst), &ttl, ac[0]->filename); |
340 resolve_destination(dst, sizeof(dst)); | |
306 if (dst[0]) { | 341 if (dst[0]) { |
307 s.dst_addr = dst; | 342 s.dst_addr = dst; |
308 s.ttl = ttl; | 343 s.ttl = ttl; |
309 } | 344 } |
310 } | 345 } |
312 | 347 |
313 dst[0] = 0; | 348 dst[0] = 0; |
314 for (i = 0; i < n_files; i++) { | 349 for (i = 0; i < n_files; i++) { |
315 if (n_files != 1) { | 350 if (n_files != 1) { |
316 port = sdp_get_address(dst, sizeof(dst), &ttl, ac[i]->filename); | 351 port = sdp_get_address(dst, sizeof(dst), &ttl, ac[i]->filename); |
352 resolve_destination(dst, sizeof(dst)); | |
317 } | 353 } |
318 for (j = 0; j < ac[i]->nb_streams; j++) { | 354 for (j = 0; j < ac[i]->nb_streams; j++) { |
319 sdp_write_media(buff, size, | 355 sdp_write_media(buff, size, |
320 ac[i]->streams[j]->codec, dst[0] ? dst : NULL, | 356 ac[i]->streams[j]->codec, dst[0] ? dst : NULL, |
321 (port > 0) ? port + j * 2 : 0, ttl); | 357 (port > 0) ? port + j * 2 : 0, ttl); |