Changeset 5c8acc49f87cb734a2d072cf1b3f5c0f067b5ade
- Timestamp:
- 27/07/05 18:30:19 (3 years ago)
- git-parent:
- Files:
-
- include/stream_output.h (modified) (2 diffs)
- include/vlc_symbols.h (modified) (1 diff)
- modules/stream_out/standard.c (modified) (1 diff)
- src/stream_output/announce.c (modified) (2 diffs)
- src/stream_output/sap.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
include/stream_output.h
rc4a2920 r5c8acc4 258 258 { 259 259 int i_type; 260 261 /* For SAP */262 char *psz_address; /* If we use a custom address */263 260 }; 264 261 … … 292 289 int i_current_session; 293 290 294 int (*pf_add) ( sap_handler_t*, session_descriptor_t * ,announce_method_t*);291 int (*pf_add) ( sap_handler_t*, session_descriptor_t *); 295 292 int (*pf_del) ( sap_handler_t*, session_descriptor_t *); 296 293 include/vlc_symbols.h
rc4a2920 r5c8acc4 93 93 int * (*__net_ListenTCP_inner) (vlc_object_t *, const char *, int); 94 94 int (*__net_Accept_inner) (vlc_object_t *, int *, mtime_t); 95 int (*__net_OpenUDP_inner) (vlc_object_t *p_this, c har *psz_bind, int i_bind,char *psz_server, int i_server);95 int (*__net_OpenUDP_inner) (vlc_object_t *p_this, const char *psz_bind, int i_bind, const char *psz_server, int i_server); 96 96 void (*net_Close_inner) (int fd); 97 97 int (*__net_Read_inner) (vlc_object_t *p_this, int fd, v_socket_t *, uint8_t *p_data, int i_data, vlc_bool_t b_retry); modules/stream_out/standard.c
r3220fe6 r5c8acc4 362 362 vlc_UrlClean( &url ); 363 363 364 /* FIXME: Free p_method */365 if( p_method->psz_address) free( p_method->psz_address );366 364 free( p_method ); 367 365 } src/stream_output/announce.c
rc4a2920 r5c8acc4 200 200 201 201 p_method = (announce_method_t *)malloc( sizeof(announce_method_t) ); 202 203 if( p_method ) 204 { 205 p_method->i_type = i_type; 206 if( i_type == METHOD_TYPE_SAP ) 207 /* Default value */ 208 p_method->psz_address = NULL; 209 } 202 if( p_method == NULL ) 203 return NULL; 204 205 p_method->i_type = i_type; 210 206 return p_method; 211 207 } … … 287 283 /* this will set p_session->p_sap for later deletion */ 288 284 msg_Dbg( p_announce, "adding SAP session"); 289 p_announce->p_sap->pf_add( p_announce->p_sap, p_session , p_method);285 p_announce->p_sap->pf_add( p_announce->p_sap, p_session ); 290 286 } 291 287 else if( p_method->i_type == METHOD_TYPE_SLP ) src/stream_output/sap.c
rd20e734 r5c8acc4 66 66 { 67 67 char *psz_address; 68 char psz_machine[NI_MAXNUMERICHOST]; 68 69 int i_port; 69 70 int i_rfd; /* Read socket */ … … 84 85 static void RunThread( vlc_object_t *p_this); 85 86 static int CalculateRate( sap_handler_t *p_sap, sap_address_t *p_address ); 86 static int SDPGenerate( sap_handler_t *p_sap, session_descriptor_t *p_session ); 87 static char *SDPGenerate( sap_handler_t *p_sap, 88 const session_descriptor_t *p_session, 89 const sap_address_t *p_addr ); 87 90 88 91 static int announce_SendSAPAnnounce( sap_handler_t *p_sap, … … 91 94 92 95 static int announce_SAPAnnounceAdd( sap_handler_t *p_sap, 93 session_descriptor_t *p_session, 94 announce_method_t *p_method ); 96 session_descriptor_t *p_session ); 95 97 96 98 static int announce_SAPAnnounceDel( sap_handler_t *p_sap, … … 126 128 free( psz_charset ); 127 129 if( p_sap->iconvHandle == (vlc_iconv_t)(-1) ) 128 {129 130 msg_Warn( p_sap, "Unable to do requested conversion" ); 130 }131 131 132 132 p_sap->pf_add = announce_SAPAnnounceAdd; … … 253 253 /* Add a SAP announce */ 254 254 static int announce_SAPAnnounceAdd( sap_handler_t *p_sap, 255 session_descriptor_t *p_session, 256 announce_method_t *p_method ) 255 session_descriptor_t *p_session ) 257 256 { 258 257 int i; 259 c har *psz_type = "application/sdp";258 const char *psz_type = "application/sdp"; 260 259 int i_header_size; 261 260 char *psz_head; 262 vlc_bool_t b_ found = VLC_FALSE, b_ipv6 = VLC_FALSE;261 vlc_bool_t b_ipv6 = VLC_FALSE; 263 262 sap_session_t *p_sap_session; 264 263 mtime_t i_hash; 264 char psz_buf[NI_MAXNUMERICHOST], *ptr; 265 const char *psz_addr; 266 struct addrinfo hints, *res; 267 265 268 266 269 vlc_mutex_lock( &p_sap->object_lock ); 267 270 268 /* If needed, build the SDP */ 269 if( !p_session->psz_sdp ) 270 { 271 if ( SDPGenerate( p_sap, p_session ) != VLC_SUCCESS ) 272 { 273 vlc_mutex_unlock( &p_sap->object_lock ); 274 return VLC_EGENERIC; 275 } 276 } 277 278 if( p_method->psz_address == NULL ) 279 { 280 /* Determine SAP multicast address automatically */ 281 char psz_buf[NI_MAXNUMERICHOST], *ptr; 282 const char *psz_addr; 283 struct addrinfo hints, *res; 284 285 if( p_session->psz_uri == NULL ) 286 { 287 msg_Err( p_sap, "*FIXME* Unexpected NULL URI for SAP announce" ); 288 msg_Err( p_sap, "This should not happen. VLC needs fixing." ); 289 vlc_mutex_unlock( &p_sap->object_lock ); 290 return VLC_EGENERIC; 291 } 292 293 /* Canonicalize IP address (e.g. 224.00.010.1 => 224.0.10.1) */ 294 memset( &hints, 0, sizeof( hints ) ); 295 hints.ai_socktype = SOCK_DGRAM; 296 hints.ai_flags = AI_NUMERICHOST; 297 298 i = vlc_getaddrinfo( (vlc_object_t *)p_sap, p_session->psz_uri, 0, 299 &hints, &res ); 300 if( i == 0 ) 301 { 302 i = vlc_getnameinfo( res->ai_addr, res->ai_addrlen, psz_buf, 303 sizeof( psz_buf ), NULL, NI_NUMERICHOST ); 304 vlc_freeaddrinfo( res ); 305 } 306 307 if( i ) 308 { 309 msg_Err( p_sap, "Invalid URI for SAP announce : %s : %s", 310 p_session->psz_uri, vlc_gai_strerror( i ) ); 311 vlc_mutex_unlock( &p_sap->object_lock ); 312 return VLC_EGENERIC; 313 } 314 315 /* Remove interface specification if present */ 316 ptr = strchr( psz_buf, '%' ); 317 if( ptr != NULL ) 318 *ptr = '\0'; 319 320 if( strchr( psz_buf, ':' ) != NULL ) 321 { 322 b_ipv6 = VLC_TRUE; 323 324 /* See RFC3513 for list of valid IPv6 scopes */ 325 if( ( tolower( psz_buf[0] ) == 'f' ) 326 && ( tolower( psz_buf[1] ) == 'f' ) 327 && isxdigit( psz_buf[2] ) && isxdigit( psz_buf[3] ) ) 328 { 329 /* Multicast IPv6 */ 330 psz_buf[2] = '0'; /* force flags to zero */ 331 /* keep scope in psz_addr[3] */ 332 memcpy( &psz_buf[4], "::2:7ffe", sizeof( "::2:7ffe" ) ); 333 psz_addr = psz_buf; 334 } 335 else 336 /* Unicast IPv6 - assume global scope */ 337 psz_addr = "ff0e::2:7ffe"; 271 if( p_session->psz_uri == NULL ) 272 { 273 msg_Err( p_sap, "*FIXME* Unexpected NULL URI for SAP announce" ); 274 msg_Err( p_sap, "This should not happen. VLC needs fixing." ); 275 vlc_mutex_unlock( &p_sap->object_lock ); 276 return VLC_EGENERIC; 277 } 278 279 /* Determine SAP multicast address automatically (FIXME: gruik) */ 280 /* Canonicalize IP address (e.g. 224.00.010.1 => 224.0.10.1) */ 281 memset( &hints, 0, sizeof( hints ) ); 282 hints.ai_socktype = SOCK_DGRAM; 283 hints.ai_flags = AI_NUMERICHOST; 284 285 i = vlc_getaddrinfo( (vlc_object_t *)p_sap, p_session->psz_uri, 0, 286 &hints, &res ); 287 if( i == 0 ) 288 { 289 i = vlc_getnameinfo( res->ai_addr, res->ai_addrlen, psz_buf, 290 sizeof( psz_buf ), NULL, NI_NUMERICHOST ); 291 vlc_freeaddrinfo( res ); 292 } 293 294 if( i ) 295 { 296 msg_Err( p_sap, "Invalid URI for SAP announce : %s : %s", 297 p_session->psz_uri, vlc_gai_strerror( i ) ); 298 vlc_mutex_unlock( &p_sap->object_lock ); 299 return VLC_EGENERIC; 300 } 301 302 /* Remove interface specification if present */ 303 ptr = strchr( psz_buf, '%' ); 304 if( ptr != NULL ) 305 *ptr = '\0'; 306 307 if( strchr( psz_buf, ':' ) != NULL ) 308 { 309 b_ipv6 = VLC_TRUE; 310 311 /* See RFC3513 for list of valid IPv6 scopes */ 312 if( ( tolower( psz_buf[0] ) == 'f' ) 313 && ( tolower( psz_buf[1] ) == 'f' ) 314 && isxdigit( psz_buf[2] ) && isxdigit( psz_buf[3] ) ) 315 { 316 /* Multicast IPv6 */ 317 psz_buf[2] = '0'; /* force flags to zero */ 318 /* keep scope in psz_addr[3] */ 319 memcpy( &psz_buf[4], "::2:7ffe", sizeof( "::2:7ffe" ) ); 320 psz_addr = psz_buf; 338 321 } 339 322 else 340 { 341 /* See RFC2365 for IPv4 scopes */ 342 if( memcmp( psz_buf, "224.0.0.", 8 ) == 0 ) 343 psz_addr = "224.0.0.255"; 344 else 345 if( memcmp( psz_buf, "239.255.", 8 ) == 0 ) 346 psz_addr = "239.255.255.255"; 347 else 348 if( ( memcmp( psz_buf, "239.19", 6 ) == 0 ) 349 && ( ( psz_buf[6] >= '2' ) && ( psz_buf[6] <= '5' ) ) ) 350 psz_addr = "239.195.255.255"; 351 else 352 /* assume global scope */ 353 psz_addr = "224.2.127.254"; 354 } 355 356 p_method->psz_address = strdup( psz_addr ); 323 /* Unicast IPv6 - assume global scope */ 324 psz_addr = "ff0e::2:7ffe"; 357 325 } 358 326 else 359 b_ipv6 = (strchr( p_method->psz_address, ':' ) != NULL); 360 361 msg_Dbg( p_sap, "using SAP address: %s", p_method->psz_address); 327 { 328 /* See RFC2365 for IPv4 scopes */ 329 if( memcmp( psz_buf, "224.0.0.", 8 ) == 0 ) 330 psz_addr = "224.0.0.255"; 331 else 332 if( memcmp( psz_buf, "239.255.", 8 ) == 0 ) 333 psz_addr = "239.255.255.255"; 334 else 335 if( ( memcmp( psz_buf, "239.19", 6 ) == 0 ) 336 && ( ( psz_buf[6] >= '2' ) && ( psz_buf[6] <= '5' ) ) ) 337 psz_addr = "239.195.255.255"; 338 else 339 /* assume global scope */ 340 psz_addr = "224.2.127.254"; 341 } 342 343 msg_Dbg( p_sap, "using SAP address: %s", psz_addr); 362 344 363 345 /* XXX: Check for dupes */ 364 346 p_sap_session = (sap_session_t*)malloc(sizeof(sap_session_t)); 365 366 p_sap_session->psz_sdp = strdup( p_session->psz_sdp ); 367 p_sap_session->i_last = 0; 347 p_sap_session->p_address = NULL; 368 348 369 349 /* Add the address to the buffer */ 370 for( i = 0; i< p_sap->i_addresses; i++) 371 { 372 if( !strcmp( p_method->psz_address, 373 p_sap->pp_addresses[i]->psz_address ) ) 350 for( i = 0; i < p_sap->i_addresses; i++) 351 { 352 if( !strcmp( psz_addr, p_sap->pp_addresses[i]->psz_address ) ) 374 353 { 375 354 p_sap_session->p_address = p_sap->pp_addresses[i]; 376 b_found = VLC_TRUE;377 355 break; 378 356 } 379 357 } 380 if( b_found == VLC_FALSE ) 358 359 if( p_sap_session->p_address == NULL ) 381 360 { 382 361 sap_address_t *p_address = (sap_address_t *) … … 387 366 return VLC_ENOMEM; 388 367 } 389 p_address->psz_address = strdup( p _method->psz_address);368 p_address->psz_address = strdup( psz_addr ); 390 369 p_address->i_port = 9875; 391 p_address->i_wfd = net_OpenUDP( p_sap, "", 0, 392 p_address->psz_address, 370 p_address->i_wfd = net_OpenUDP( p_sap, "", 0, psz_addr, 393 371 p_address->i_port ); 394 372 if( p_address->i_wfd != -1 ) 373 { 395 374 net_StopRecv( p_address->i_wfd ); 375 net_GetSockAddress( p_sap, p_address->i_wfd, 376 p_address->psz_machine, NULL ); 377 } 396 378 397 379 if( p_sap->b_control == VLC_TRUE ) 398 380 { 399 p_address->i_rfd = net_OpenUDP( p_sap, p_method->psz_address, 400 p_address->i_port, 401 "", 0 ); 381 p_address->i_rfd = net_OpenUDP( p_sap, psz_addr, 382 p_address->i_port, "", 0 ); 402 383 if( p_address->i_rfd != -1 ) 403 384 net_StopSend( p_address->i_rfd ); … … 430 411 } 431 412 413 432 414 /* Build the SAP Headers */ 433 415 i_header_size = ( b_ipv6 ? 20 : 8 ) + strlen( psz_type ) + 1; 434 416 psz_head = (char *) malloc( i_header_size * sizeof( char ) ); 435 if( ! psz_head)417 if( psz_head == NULL ) 436 418 { 437 419 msg_Err( p_sap, "out of memory" ); … … 484 466 strncpy( psz_head + 8, psz_type, 15 ); 485 467 } 468 469 /* If needed, build the SDP */ 470 if( p_session->psz_sdp == NULL ) 471 { 472 p_session->psz_sdp = SDPGenerate( p_sap, p_session, 473 p_sap_session->p_address ); 474 if( p_session->psz_sdp == NULL ) 475 { 476 vlc_mutex_unlock( &p_sap->object_lock ); 477 return VLC_ENOMEM; 478 } 479 } 480 481 p_sap_session->psz_sdp = strdup( p_session->psz_sdp ); 482 p_sap_session->i_last = 0; 486 483 487 484 psz_head[ i_header_size-1 ] = '\0'; … … 571 568 p_session->psz_data, 572 569 p_session->i_length ); 573 if( i_ret != p_session->i_length )570 if( i_ret != (int)p_session->i_length ) 574 571 { 575 572 msg_Warn( p_sap, "SAP send failed on address %s (%i %i)", … … 588 585 } 589 586 590 static int SDPGenerate( sap_handler_t *p_sap, session_descriptor_t *p_session ) 587 static char *SDPGenerate( sap_handler_t *p_sap, 588 const session_descriptor_t *p_session, 589 const sap_address_t *p_addr ) 591 590 { 592 591 int64_t i_sdp_id = mdate(); 593 592 int i_sdp_version = 1 + p_sap->i_sessions + (rand()&0xfff); 594 char *psz_group, *psz_name, psz_uribuf[NI_MAXNUMERICHOST], *psz_uri; 593 char *psz_group, *psz_name, psz_uribuf[NI_MAXNUMERICHOST], *psz_uri, 594 *psz_sdp; 595 595 char ipv; 596 596 597 597 psz_group = convert_to_utf8( p_sap, p_session->psz_group ); 598 598 psz_name = convert_to_utf8( p_sap, p_session->psz_name ); 599 if( psz_name == NULL ) 600 { 601 FREE( psz_group ); 602 return NULL; 603 } 599 604 600 605 /* FIXME: really check that psz_uri is a real IP address … … 619 624 620 625 /* see the lists in modules/stream_out/rtp.c for compliance stuff */ 621 p_session->psz_sdp = (char *)malloc( 622 sizeof("v=0\r\n" 623 "o=- 45383436098 45398 IN IP4 127.0.0.1\r\n" /* FIXME */ 624 "s=\r\n" 625 "t=0 0\r\n" 626 "c=IN IP4 /\r\n" 627 "m=video udp\r\n" 628 "a=tool:"PACKAGE_STRING"\r\n" 629 "a=type:broadcast\r\n") 630 + strlen( psz_name ) 631 + strlen( psz_uri ) + 300 632 + ( psz_group ? strlen( psz_group ) : 0 ) ); 633 634 if( p_session->psz_sdp == NULL || psz_name == NULL ) 635 { 636 msg_Err( p_sap, "out of memory" ); 637 FREE( psz_name ); 638 FREE( psz_group ); 639 return VLC_ENOMEM; 640 } 641 642 sprintf( p_session->psz_sdp, 626 if( asprintf( &psz_sdp, 643 627 "v=0\r\n" 644 "o=- "I64Fd" %d IN IP 4 127.0.0.1\r\n"628 "o=- "I64Fd" %d IN IP%c %s\r\n" 645 629 "s=%s\r\n" 646 630 "t=0 0\r\n" … … 650 634 "a=type:broadcast\r\n", 651 635 i_sdp_id, i_sdp_version, 636 ipv, p_addr->psz_machine, 652 637 psz_name, ipv, 653 638 psz_uri, p_session->i_ttl, 654 p_session->i_port, p_session->i_payload ); 639 p_session->i_port, p_session->i_payload ) == -1 ) 640 { 641 free( psz_name ); 642 FREE( psz_group ); 643 return NULL; 644 } 645 655 646 free( psz_name ); 656 647 657 648 if( psz_group ) 658 649 { 659 sprintf( p_session->psz_sdp, "%sa=x-plgroup:%s\r\n",660 p_session->psz_sdp, psz_group );650 /* FIXME: this is illegal use of sprintf */ 651 sprintf( psz_sdp, "%sa=x-plgroup:%s\r\n", psz_sdp, psz_group ); 661 652 free( psz_group ); 662 653 } 663 654 664 msg_Dbg( p_sap, "Generated SDP (%i bytes):\n%s", strlen(p _session->psz_sdp),665 p_session->psz_sdp );666 return VLC_SUCCESS;655 msg_Dbg( p_sap, "Generated SDP (%i bytes):\n%s", strlen(psz_sdp), 656 psz_sdp ); 657 return psz_sdp; 667 658 } 668 659
