Browse code

Handle IPv6 in the SDP demuxer

Originally committed as revision 24924 to svn://svn.ffmpeg.org/ffmpeg/trunk

Martin Storsjö authored on 2010/08/26 00:32:00
Showing 2 changed files
... ...
@@ -204,9 +204,21 @@ static void rtsp_parse_range_npt(const char *p, int64_t *start, int64_t *end)
204 204
 //    av_log(NULL, AV_LOG_DEBUG, "Range End: %lld\n", *end);
205 205
 }
206 206
 
207
+static int get_sockaddr(const char *buf, struct sockaddr_storage *sock)
208
+{
209
+    struct addrinfo hints, *ai = NULL;
210
+    memset(&hints, 0, sizeof(hints));
211
+    hints.ai_flags = AI_NUMERICHOST;
212
+    if (getaddrinfo(buf, NULL, &hints, &ai))
213
+        return -1;
214
+    memcpy(sock, ai->ai_addr, FFMIN(sizeof(*sock), ai->ai_addrlen));
215
+    freeaddrinfo(ai);
216
+    return 0;
217
+}
218
+
207 219
 typedef struct SDPParseState {
208 220
     /* SDP only */
209
-    struct in_addr default_ip;
221
+    struct sockaddr_storage default_ip;
210 222
     int            default_ttl;
211 223
     int            skip_media;  ///< set if an unknown m= line occurs
212 224
 } SDPParseState;
... ...
@@ -221,7 +233,7 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
221 221
     int payload_type, i;
222 222
     AVStream *st;
223 223
     RTSPStream *rtsp_st;
224
-    struct in_addr sdp_ip;
224
+    struct sockaddr_storage sdp_ip;
225 225
     int ttl;
226 226
 
227 227
     dprintf(s, "sdp: %c='%s'\n", letter, buf);
... ...
@@ -235,10 +247,10 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
235 235
         if (strcmp(buf1, "IN") != 0)
236 236
             return;
237 237
         get_word(buf1, sizeof(buf1), &p);
238
-        if (strcmp(buf1, "IP4") != 0)
238
+        if (strcmp(buf1, "IP4") && strcmp(buf1, "IP6"))
239 239
             return;
240 240
         get_word_sep(buf1, sizeof(buf1), "/", &p);
241
-        if (ff_inet_aton(buf1, &sdp_ip) == 0)
241
+        if (get_sockaddr(buf1, &sdp_ip))
242 242
             return;
243 243
         ttl = 16;
244 244
         if (*p == '/') {
... ...
@@ -1171,7 +1183,7 @@ static int make_setup_request(AVFormatContext *s, const char *host, int port,
1171 1171
                 port      = reply->transports[0].port_min;
1172 1172
                 ttl       = reply->transports[0].ttl;
1173 1173
             } else {
1174
-                in        = rtsp_st->sdp_ip;
1174
+                in        = ((struct sockaddr_in*)&rtsp_st->sdp_ip)->sin_addr;
1175 1175
                 port      = rtsp_st->sdp_port;
1176 1176
                 ttl       = rtsp_st->sdp_ttl;
1177 1177
             }
... ...
@@ -1996,10 +2008,10 @@ static int sdp_probe(AVProbeData *p1)
1996 1996
 {
1997 1997
     const char *p = p1->buf, *p_end = p1->buf + p1->buf_size;
1998 1998
 
1999
-    /* we look for a line beginning "c=IN IP4" */
1999
+    /* we look for a line beginning "c=IN IP" */
2000 2000
     while (p < p_end && *p != '\0') {
2001
-        if (p + sizeof("c=IN IP4") - 1 < p_end &&
2002
-            av_strstart(p, "c=IN IP4", NULL))
2001
+        if (p + sizeof("c=IN IP") - 1 < p_end &&
2002
+            av_strstart(p, "c=IN IP", NULL))
2003 2003
             return AVPROBE_SCORE_MAX / 2;
2004 2004
 
2005 2005
         while (p < p_end - 1 && *p != '\n') p++;
... ...
@@ -2037,10 +2049,13 @@ static int sdp_read_header(AVFormatContext *s, AVFormatParameters *ap)
2037 2037
 
2038 2038
     /* open each RTP stream */
2039 2039
     for (i = 0; i < rt->nb_rtsp_streams; i++) {
2040
+        char namebuf[50];
2040 2041
         rtsp_st = rt->rtsp_streams[i];
2041 2042
 
2043
+        getnameinfo((struct sockaddr*) &rtsp_st->sdp_ip, sizeof(rtsp_st->sdp_ip),
2044
+                    namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
2042 2045
         ff_url_join(url, sizeof(url), "rtp", NULL,
2043
-                    inet_ntoa(rtsp_st->sdp_ip), rtsp_st->sdp_port,
2046
+                    namebuf, rtsp_st->sdp_port,
2044 2047
                     "?localport=%d&ttl=%d", rtsp_st->sdp_port,
2045 2048
                     rtsp_st->sdp_ttl);
2046 2049
         if (url_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) {
... ...
@@ -327,7 +327,7 @@ typedef struct RTSPStream {
327 327
     /** The following are used only in SDP, not RTSP */
328 328
     //@{
329 329
     int sdp_port;             /**< port (from SDP content) */
330
-    struct in_addr sdp_ip;    /**< IP address (from SDP content) */
330
+    struct sockaddr_storage sdp_ip; /**< IP address (from SDP content) */
331 331
     int sdp_ttl;              /**< IP Time-To-Live (from SDP content) */
332 332
     int sdp_payload_type;     /**< payload type */
333 333
     //@}