comparison rtsp.c @ 5819:53c5a5d40ee7 libavformat

RTSP muxer: Create the SDP with the numerical IP of the peer instead of using the original host name
author mstorsjo
date Thu, 11 Mar 2010 08:24:18 +0000
parents 2d82e25df58c
children b56e31849e0f
comparison
equal deleted inserted replaced
5818:1a3c4f74f17d 5819:53c5a5d40ee7
1326 return AVERROR_INVALIDDATA; 1326 return AVERROR_INVALIDDATA;
1327 1327
1328 return 0; 1328 return 0;
1329 } 1329 }
1330 1330
1331 static int rtsp_setup_output_streams(AVFormatContext *s) 1331 static int rtsp_setup_output_streams(AVFormatContext *s, const char *addr)
1332 { 1332 {
1333 RTSPState *rt = s->priv_data; 1333 RTSPState *rt = s->priv_data;
1334 RTSPMessageHeader reply1, *reply = &reply1; 1334 RTSPMessageHeader reply1, *reply = &reply1;
1335 char cmd[1024]; 1335 char cmd[1024];
1336 int i; 1336 int i;
1337 char *sdp; 1337 char *sdp;
1338 AVFormatContext sdp_ctx, *ctx_array[1];
1338 1339
1339 /* Announce the stream */ 1340 /* Announce the stream */
1340 snprintf(cmd, sizeof(cmd), 1341 snprintf(cmd, sizeof(cmd),
1341 "ANNOUNCE %s RTSP/1.0\r\n" 1342 "ANNOUNCE %s RTSP/1.0\r\n"
1342 "Content-Type: application/sdp\r\n", 1343 "Content-Type: application/sdp\r\n",
1343 rt->control_uri); 1344 rt->control_uri);
1344 sdp = av_mallocz(8192); 1345 sdp = av_mallocz(8192);
1345 if (sdp == NULL) 1346 if (sdp == NULL)
1346 return AVERROR(ENOMEM); 1347 return AVERROR(ENOMEM);
1347 if (avf_sdp_create(&s, 1, sdp, 8192)) { 1348 /* We create the SDP based on the RTSP AVFormatContext where we
1349 * aren't allowed to change the filename field. (We create the SDP
1350 * based on the RTSP context since the contexts for the RTP streams
1351 * don't exist yet.) In order to specify a custom URL with the actual
1352 * peer IP instead of the originally specified hostname, we create
1353 * a temporary copy of the AVFormatContext, where the custom URL is set.
1354 *
1355 * FIXME: Create the SDP without copying the AVFormatContext.
1356 * This either requires setting up the RTP stream AVFormatContexts
1357 * already here (complicating things immensely) or getting a more
1358 * flexible SDP creation interface.
1359 */
1360 sdp_ctx = *s;
1361 ff_url_join(sdp_ctx.filename, sizeof(sdp_ctx.filename),
1362 "rtsp", NULL, addr, -1, NULL);
1363 ctx_array[0] = &sdp_ctx;
1364 if (avf_sdp_create(ctx_array, 1, sdp, 8192)) {
1348 av_free(sdp); 1365 av_free(sdp);
1349 return AVERROR_INVALIDDATA; 1366 return AVERROR_INVALIDDATA;
1350 } 1367 }
1351 av_log(s, AV_LOG_INFO, "SDP:\n%s\n", sdp); 1368 av_log(s, AV_LOG_INFO, "SDP:\n%s\n", sdp);
1352 ff_rtsp_send_cmd_with_content(s, cmd, reply, NULL, sdp, strlen(sdp)); 1369 ff_rtsp_send_cmd_with_content(s, cmd, reply, NULL, sdp, strlen(sdp));
1505 } 1522 }
1506 1523
1507 if (s->iformat) 1524 if (s->iformat)
1508 err = rtsp_setup_input_streams(s); 1525 err = rtsp_setup_input_streams(s);
1509 else 1526 else
1510 err = rtsp_setup_output_streams(s); 1527 err = rtsp_setup_output_streams(s, host);
1511 if (err) 1528 if (err)
1512 goto fail; 1529 goto fail;
1513 1530
1514 do { 1531 do {
1515 int lower_transport = ff_log2_tab[lower_transport_mask & 1532 int lower_transport = ff_log2_tab[lower_transport_mask &