Changeset 5deafc168b81ecbd650b150bfc8a1bb86cf24eab
- Timestamp:
- 21/01/04 17:56:16 (5 years ago)
- git-parent:
- Files:
-
- modules/access/mms/mms.c (modified) (4 diffs)
- modules/access/mms/mmsh.c (modified) (20 diffs)
- modules/access/mms/mmsh.h (modified) (5 diffs)
- modules/access/mms/mmstu.c (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
modules/access/mms/mms.c
rd5791c9 r5deafc1 3 3 ***************************************************************************** 4 4 * Copyright (C) 2001, 2002 VideoLAN 5 * $Id: mms.c,v 1.3 4 2003/05/15 22:27:36 massiotExp $5 * $Id: mms.c,v 1.35 2004/01/21 16:56:16 fenrir Exp $ 6 6 * 7 7 * Authors: Laurent Aimar <fenrir@via.ecp.fr> … … 70 70 "force selection of all streams", 71 71 "force selection of all streams", VLC_TRUE ); 72 #if 073 add_string( "mms-stream", NULL, NULL,74 "streams selection",75 "force this stream selection", VLC_TRUE );76 #endif77 72 add_integer( "mms-maxbitrate", 0, NULL, 78 73 "max bitrate", … … 90 85 input_thread_t *p_input = (input_thread_t*)p_this; 91 86 92 int i_err; 93 94 87 /* First set ipv4/ipv6 */ 88 var_Create( p_input, "ipv4", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); 89 var_Create( p_input, "ipv6", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); 90 91 /* mms-caching */ 92 var_Create( p_input, "mms-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); 93 94 /* use specified method */ 95 95 if( *p_input->psz_access ) 96 96 { … … 109 109 } 110 110 111 112 i_err = E_( MMSTUOpen )( p_input ); 113 114 if( i_err ) 115 { 116 i_err = E_( MMSHOpen )( p_input ); 117 } 118 119 return i_err; 111 if( E_( MMSTUOpen )( p_input ) ) 112 { 113 /* try mmsh if mmstu failed */ 114 return E_( MMSHOpen )( p_input ); 115 } 116 return VLC_SUCCESS; 120 117 } 121 118 modules/access/mms/mmsh.c
r217c4d9 r5deafc1 3 3 ***************************************************************************** 4 4 * Copyright (C) 2001, 2002 VideoLAN 5 * $Id: mmsh.c,v 1. 6 2003/08/26 00:51:19fenrir Exp $5 * $Id: mmsh.c,v 1.7 2004/01/21 16:56:16 fenrir Exp $ 6 6 * 7 7 * Authors: Laurent Aimar <fenrir@via.ecp.fr> … … 36 36 #include <vlc/input.h> 37 37 38 #ifdef HAVE_ERRNO_H39 # include <errno.h>40 #endif41 #ifdef HAVE_FCNTL_H42 # include <fcntl.h>43 #endif44 #ifdef HAVE_SYS_TIME_H45 # include <sys/time.h>46 #endif47 48 #ifdef HAVE_UNISTD_H49 # include <unistd.h>50 #endif51 52 #if defined( UNDER_CE )53 # include <winsock.h>54 #elif defined( WIN32 )55 # include <winsock2.h>56 # include <ws2tcpip.h>57 # ifndef IN_MULTICAST58 # define IN_MULTICAST(a) IN_CLASSD(a)59 # endif60 #else61 # include <sys/socket.h>62 #endif63 64 38 #include "network.h" 65 39 #include "asf.h" … … 72 46 * Local prototypes 73 47 *****************************************************************************/ 74 int E_( MMSHOpen ) ( input_thread_t * ); 75 void E_( MMSHClose ) ( input_thread_t * ); 76 77 static ssize_t Read ( input_thread_t * p_input, byte_t * p_buffer, 78 size_t i_len ); 79 static void Seek ( input_thread_t *, off_t ); 80 81 /**************************************************************************** 82 **************************************************************************** 83 ******************* ******************* 84 ******************* Main functions ******************* 85 ******************* ******************* 86 **************************************************************************** 87 ****************************************************************************/ 48 int E_(MMSHOpen) ( input_thread_t * ); 49 void E_(MMSHClose) ( input_thread_t * ); 50 static ssize_t Read( input_thread_t *, byte_t *, size_t ); 51 static void Seek( input_thread_t *, off_t ); 52 53 static ssize_t NetFill( input_thread_t *, access_sys_t *, int ); 54 55 static int mmsh_start ( input_thread_t *, off_t ); 56 static void mmsh_stop ( input_thread_t * ); 57 static int mmsh_get_packet( input_thread_t *, chunk_t * ); 58 59 static http_answer_t *http_answer_parse( uint8_t *, int ); 60 static void http_answer_free ( http_answer_t * ); 61 static http_field_t *http_field_find ( http_field_t *, char * ); 62 63 static int chunk_parse( chunk_t *, uint8_t *, int ); 88 64 89 65 /**************************************************************************** … … 99 75 chunk_t ck; 100 76 77 vlc_value_t val; 78 101 79 /* init p_sys */ 102 80 p_input->p_access_data = p_sys = malloc( sizeof( access_sys_t ) ); 103 81 p_sys->i_proto = MMS_PROTO_HTTP; 104 82 105 p_sys-> p_socket = NULL;83 p_sys->fd = -1; 106 84 p_sys->i_request_context = 1; 107 85 p_sys->i_buffer = 0; … … 129 107 } 130 108 131 if( ( p_sys->p_socket = NetOpenTCP( p_input, p_sys->p_url ) ) == NULL ) 109 if( ( p_sys->fd = net_OpenTCP( p_input, p_sys->p_url->psz_host, 110 p_sys->p_url->i_port ) ) < 0 ) 132 111 { 133 112 msg_Err( p_input, "cannot connect" ); … … 147 126 GUID_PRINT( p_sys->guid ) ); 148 127 p += sprintf( p, "Connection: Close\r\n\r\n" ); 149 NetWrite( p_input, p_sys->p_socket, p_sys->buffer, p - p_sys->buffer ); 150 128 129 net_Write( p_input, p_sys->fd, p_sys->buffer, p - p_sys->buffer ); 151 130 152 131 if( NetFill ( p_input, p_sys, BUFFER_SIZE ) <= 0 ) … … 155 134 goto exit_error; 156 135 } 157 NetClose( p_input, p_sys->p_socket ); 158 p_sys->p_socket = NULL; 136 net_Close( p_sys->fd ); p_sys->fd = -1; 159 137 160 138 p_ans = http_answer_parse( p_sys->buffer, p_sys->i_buffer ); … … 301 279 vlc_mutex_unlock( &p_input->stream.stream_lock ); 302 280 303 /* Update default_pts to a suitable value for ftpaccess */304 p_input->i_pts_delay = config_GetInt( p_input, "mms-caching" ) * 1000;305 306 307 return ( VLC_SUCCESS );281 /* Update default_pts to a suitable value for mms access */ 282 var_Get( p_input, "mms-caching", &val ); 283 p_input->i_pts_delay = val.i_int * 1000; 284 285 return VLC_SUCCESS; 308 286 309 287 exit_error: 310 288 E_( url_free )( p_sys->p_url ); 311 289 312 if( p_sys-> p_socket)313 { 314 NetClose( p_input, p_sys->p_socket);290 if( p_sys->fd > 0 ) 291 { 292 net_Close( p_sys->fd ); 315 293 } 316 294 free( p_sys ); 317 return ( VLC_EGENERIC );295 return VLC_EGENERIC; 318 296 } 319 297 … … 331 309 free( p_sys ); 332 310 } 333 334 static int mmsh_get_packet( input_thread_t * p_input,335 chunk_t *p_ck )336 {337 access_sys_t *p_sys = p_input->p_access_data;338 339 int i_mov = p_sys->i_buffer - p_sys->i_buffer_pos;340 341 if( p_sys->i_buffer_pos > BUFFER_SIZE / 2 )342 {343 if( i_mov > 0 )344 {345 memmove( &p_sys->buffer[0],346 &p_sys->buffer[p_sys->i_buffer_pos],347 i_mov );348 }349 350 p_sys->i_buffer = i_mov;351 p_sys->i_buffer_pos = 0;352 }353 354 if( NetFill( p_input, p_sys, 12 ) < 12 )355 {356 msg_Warn( p_input, "cannot fill buffer" );357 return VLC_EGENERIC;358 }359 360 chunk_parse( p_ck, &p_sys->buffer[p_sys->i_buffer_pos],361 p_sys->i_buffer - p_sys->i_buffer_pos );362 363 if( p_ck->i_type == 0x4524 ) // Transfer complete364 {365 msg_Warn( p_input, "EOF" );366 return VLC_EGENERIC;367 }368 else if( p_ck->i_type != 0x4824 && p_ck->i_type != 0x4424 )369 {370 msg_Err( p_input, "invalid chunk FATAL" );371 return VLC_EGENERIC;372 }373 374 if( p_ck->i_data < p_ck->i_size2 - 8 )375 {376 if( NetFill( p_input, p_sys, p_ck->i_size2 - 8 - p_ck->i_data ) <= 0 )377 {378 msg_Warn( p_input, "cannot fill buffer" );379 return VLC_EGENERIC;380 }381 chunk_parse( p_ck, &p_sys->buffer[p_sys->i_buffer_pos],382 p_sys->i_buffer - p_sys->i_buffer_pos );383 }384 385 if( p_sys->i_packet_sequence != 0 &&386 p_ck->i_sequence != p_sys->i_packet_sequence )387 {388 msg_Warn( p_input, "packet lost ?" );389 }390 391 p_sys->i_packet_sequence = p_ck->i_sequence + 1;392 p_sys->i_packet_used = 0;393 p_sys->i_packet_length = p_ck->i_data;394 p_sys->p_packet = p_ck->p_data;395 396 p_sys->i_buffer_pos += 12 + p_ck->i_data;397 398 return VLC_SUCCESS;399 }400 401 311 402 312 /***************************************************************************** … … 438 348 p_sys->i_packet_used += i_offset; 439 349 440 441 350 p_input->stream.p_selected_area->i_tell = i_pos; 442 351 vlc_mutex_unlock( &p_input->stream.stream_lock ); 443 444 352 } 445 353 … … 499 407 } 500 408 501 502 /****************************************************************************/ 503 /****************************************************************************/ 504 /****************************************************************************/ 505 /****************************************************************************/ 506 /****************************************************************************/ 507 508 static int mmsh_start( input_thread_t *p_input, 509 off_t i_pos ) 409 /***************************************************************************** 410 * NetFill: 411 *****************************************************************************/ 412 static ssize_t NetFill( input_thread_t *p_input, access_sys_t *p_sys, int i_size ) 413 { 414 int i_try = 0; 415 int i_total = 0; 416 417 i_size = __MIN( i_size, BUFFER_SIZE - p_sys->i_buffer ); 418 if( i_size <= 0 ) 419 { 420 return 0; 421 } 422 423 for( ;; ) 424 { 425 int i_read; 426 427 i_read = net_Read( p_input, p_sys->fd, 428 &p_sys->buffer[p_sys->i_buffer], i_size, VLC_FALSE ); 429 430 if( i_read == 0 ) 431 { 432 if( i_try++ > 2 ) 433 { 434 break; 435 } 436 msg_Dbg( p_input, "another try %d/2", i_try ); 437 continue; 438 } 439 440 if( i_read < 0 || p_input->b_die || p_input->b_error ) 441 { 442 break; 443 } 444 i_total += i_read; 445 446 p_sys->i_buffer += i_read; 447 if( i_total >= i_size ) 448 { 449 break; 450 } 451 } 452 453 p_sys->buffer[p_sys->i_buffer] = '\0'; 454 455 return i_total; 456 } 457 458 459 /***************************************************************************** 460 * 461 *****************************************************************************/ 462 static int mmsh_start( input_thread_t *p_input, off_t i_pos ) 510 463 { 511 464 access_sys_t *p_sys = p_input->p_access_data; … … 517 470 msg_Dbg( p_input, "starting stream" ); 518 471 519 if( ( p_sys->p_socket = NetOpenTCP( p_input, p_sys->p_url ) ) == NULL ) 472 if( ( p_sys->fd = net_OpenTCP( p_input, p_sys->p_url->psz_host, 473 p_sys->p_url->i_port ) ) < 0 ) 520 474 { 521 475 /* should not occur */ … … 575 529 p += sprintf( p, "Connection: Close\r\n\r\n" ); 576 530 577 578 NetWrite( p_input, p_sys->p_socket, p_sys->buffer, p - p_sys->buffer ); 531 net_Write( p_input, p_sys->fd, p_sys->buffer, p - p_sys->buffer ); 579 532 580 533 msg_Dbg( p_input, "filling buffer" ); … … 589 542 590 543 p = &p_sys->buffer[p_sys->i_buffer]; 591 i_read = 592 NetRead( p_input, p_sys->p_socket, 593 &p_sys->buffer[p_sys->i_buffer], 594 1024 ); 544 i_read = net_Read( p_input, p_sys->fd, &p_sys->buffer[p_sys->i_buffer], 1024, VLC_FALSE ); 595 545 596 546 if( i_read == 0 ) … … 652 602 } 653 603 604 /***************************************************************************** 605 * 606 *****************************************************************************/ 654 607 static void mmsh_stop( input_thread_t *p_input ) 655 608 { … … 657 610 658 611 msg_Dbg( p_input, "closing stream" ); 659 NetClose( p_input, p_sys->p_socket ); 660 p_sys->p_socket = NULL; 661 } 662 663 static ssize_t NetFill( input_thread_t *p_input, 664 access_sys_t *p_sys, int i_size ) 665 { 666 int i_try = 0; 667 int i_total = 0; 668 669 i_size = __MIN( i_size, BUFFER_SIZE - p_sys->i_buffer ); 670 if( i_size <= 0 ) 671 { 672 return 0; 673 } 674 675 for( ;; ) 676 { 677 int i_read; 678 679 i_read = NetRead( p_input, p_sys->p_socket, 680 &p_sys->buffer[p_sys->i_buffer], i_size ); 681 682 if( i_read == 0 ) 683 { 684 if( i_try++ > 2 ) 685 { 686 break; 687 } 688 msg_Dbg( p_input, "another try %d/2", i_try ); 689 continue; 690 } 691 692 if( i_read < 0 || p_input->b_die || p_input->b_error ) 693 { 694 break; 695 } 696 i_total += i_read; 697 698 p_sys->i_buffer += i_read; 699 if( i_total >= i_size ) 700 { 701 break; 702 } 703 } 704 705 p_sys->buffer[p_sys->i_buffer] = '\0'; 706 707 return i_total; 708 } 709 710 /**************************************************************************** 711 * NetOpenTCP: 712 ****************************************************************************/ 713 static input_socket_t * NetOpenTCP( input_thread_t *p_input, url_t *p_url ) 714 { 715 input_socket_t *p_socket; 716 char *psz_network; 717 module_t *p_network; 718 network_socket_t socket_desc; 719 720 721 p_socket = malloc( sizeof( input_socket_t ) ); 722 memset( p_socket, 0, sizeof( input_socket_t ) ); 723 724 psz_network = ""; 725 if( config_GetInt( p_input, "ipv4" ) ) 726 { 727 psz_network = "ipv4"; 728 } 729 else if( config_GetInt( p_input, "ipv6" ) ) 730 { 731 psz_network = "ipv6"; 732 } 733 734 msg_Dbg( p_input, "waiting for connection..." ); 735 736 socket_desc.i_type = NETWORK_TCP; 737 socket_desc.psz_server_addr = p_url->psz_host; 738 socket_desc.i_server_port = p_url->i_port; 739 socket_desc.psz_bind_addr = ""; 740 socket_desc.i_bind_port = 0; 741 socket_desc.i_ttl = 0; 742 p_input->p_private = (void*)&socket_desc; 743 if( !( p_network = module_Need( p_input, "network", psz_network ) ) ) 744 { 745 msg_Err( p_input, "failed to connect with server" ); 746 return NULL; 747 } 748 module_Unneed( p_input, p_network ); 749 p_socket->i_handle = socket_desc.i_handle; 750 p_input->i_mtu = socket_desc.i_mtu; 751 752 msg_Dbg( p_input, 753 "connection with \"%s:%d\" successful", 754 p_url->psz_host, 755 p_url->i_port ); 756 757 return p_socket; 758 } 759 760 /***************************************************************************** 761 * Read: read on a file descriptor, checking b_die periodically 762 *****************************************************************************/ 763 static ssize_t NetRead( input_thread_t *p_input, 764 input_socket_t *p_socket, 765 byte_t *p_buffer, size_t i_len ) 766 { 767 struct timeval timeout; 768 fd_set fds; 769 ssize_t i_recv; 770 int i_ret; 771 772 /* Initialize file descriptor set */ 773 FD_ZERO( &fds ); 774 FD_SET( p_socket->i_handle, &fds ); 775 776 /* We'll wait 1 second if nothing happens */ 777 timeout.tv_sec = 1; 778 timeout.tv_usec = 0; 779 780 /* Find if some data is available */ 781 while( ( i_ret = select( p_socket->i_handle + 1, &fds, 782 NULL, NULL, &timeout )) == 0 || 783 #ifdef HAVE_ERRNO_H 784 ( i_ret < 0 && errno == EINTR ) 785 #endif 786 ) 787 { 788 FD_ZERO( &fds ); 789 FD_SET( p_socket->i_handle, &fds ); 790 timeout.tv_sec = 1; 791 timeout.tv_usec = 0; 792 793 if( p_input->b_die || p_input->b_error ) 794 { 795 return 0; 796 } 797 } 798 799 if( i_ret < 0 ) 800 { 801 msg_Err( p_input, "network select error (%s)", strerror(errno) ); 802 return -1; 803 } 804 805 i_recv = recv( p_socket->i_handle, p_buffer, i_len, 0 ); 806 807 if( i_recv < 0 ) 808 { 809 msg_Err( p_input, "recv failed (%s)", strerror(errno) ); 810 } 811 812 return i_recv; 813 } 814 815 static ssize_t NetWrite( input_thread_t *p_input, 816 input_socket_t *p_socket, 817 byte_t *p_buffer, size_t i_len ) 818 { 819 struct timeval timeout; 820 fd_set fds; 821 ssize_t i_send; 822 int i_ret; 823 824 /* Initialize file descriptor set */ 825 FD_ZERO( &fds ); 826 FD_SET( p_socket->i_handle, &fds ); 827 828 /* We'll wait 1 second if nothing happens */ 829 timeout.tv_sec = 1; 830 timeout.tv_usec = 0; 831 832 /* Find if some data is available */ 833 while( ( i_ret = select( p_socket->i_handle + 1, NULL, &fds, NULL, &timeout ) ) == 0 || 834 #ifdef HAVE_ERRNO_H 835 ( i_ret < 0 && errno == EINTR ) 836 #endif 837 ) 838 { 839 FD_ZERO( &fds ); 840 FD_SET( p_socket->i_handle, &fds ); 841 timeout.tv_sec = 1; 842 timeout.tv_usec = 0; 843 844 if( p_input->b_die || p_input->b_error ) 845 { 846 return 0; 847 } 848 } 849 850 if( i_ret < 0 ) 851 { 852 msg_Err( p_input, "network select error (%s)", strerror(errno) ); 853 return -1; 854 } 855 856 i_send = send( p_socket->i_handle, p_buffer, i_len, 0 ); 857 858 if( i_send < 0 ) 859 { 860 msg_Err( p_input, "send failed (%s)", strerror(errno) ); 861 } 862 863 return i_send; 864 } 865 866 static void NetClose( input_thread_t *p_input, input_socket_t *p_socket ) 867 { 868 #if defined( WIN32 ) || defined( UNDER_CE ) 869 closesocket( p_socket->i_handle ); 870 #else 871 close( p_socket->i_handle ); 872 #endif 873 874 free( p_socket ); 875 } 876 612 net_Close( p_sys->fd ); p_sys->fd = -1; 613 } 614 615 /***************************************************************************** 616 * 617 *****************************************************************************/ 618 static int mmsh_get_packet( input_thread_t * p_input, chunk_t *p_ck ) 619 { 620 access_sys_t *p_sys = p_input->p_access_data; 621 622 int i_mov = p_sys->i_buffer - p_sys->i_buffer_pos; 623 624 if( p_sys->i_buffer_pos > BUFFER_SIZE / 2 ) 625 { 626 if( i_mov > 0 ) 627 { 628 memmove( &p_sys->buffer[0], 629 &p_sys->buffer[p_sys->i_buffer_pos], 630 i_mov ); 631 } 632 633 p_sys->i_buffer = i_mov; 634 p_sys->i_buffer_pos = 0; 635 } 636 637 if( NetFill( p_input, p_sys, 12 ) < 12 ) 638 { 639 msg_Warn( p_input, "cannot fill buffer" ); 640 return VLC_EGENERIC; 641 } 642 643 chunk_parse( p_ck, &p_sys->buffer[p_sys->i_buffer_pos], 644 p_sys->i_buffer - p_sys->i_buffer_pos ); 645 646 if( p_ck->i_type == 0x4524 ) // Transfer complete 647 { 648 msg_Warn( p_input, "EOF" ); 649 return VLC_EGENERIC; 650 } 651 else if( p_ck->i_type != 0x4824 && p_ck->i_type != 0x4424 ) 652 { 653 msg_Err( p_input, "invalid chunk FATAL" ); 654 return VLC_EGENERIC; 655 } 656 657 if( p_ck->i_data < p_ck->i_size2 - 8 ) 658 { 659 if( NetFill( p_input, p_sys, p_ck->i_size2 - 8 - p_ck->i_data ) <= 0 ) 660 { 661 msg_Warn( p_input, "cannot fill buffer" ); 662 return VLC_EGENERIC; 663 } 664 chunk_parse( p_ck, &p_sys->buffer[p_sys->i_buffer_pos], 665 p_sys->i_buffer - p_sys->i_buffer_pos ); 666 } 667 668 if( p_sys->i_packet_sequence != 0 && 669 p_ck->i_sequence != p_sys->i_packet_sequence ) 670 { 671 msg_Warn( p_input, "packet lost ?" ); 672 } 673 674 p_sys->i_packet_sequence = p_ck->i_sequence + 1; 675 p_sys->i_packet_used = 0; 676 p_sys->i_packet_length = p_ck->i_data; 677 p_sys->p_packet = p_ck->p_data; 678 679 p_sys->i_buffer_pos += 12 + p_ck->i_data; 680 681 return VLC_SUCCESS; 682 } 683 684 /***************************************************************************** 685 * 686 *****************************************************************************/ 877 687 static int http_next_line( uint8_t **pp_data, int *pi_data ) 878 688 { … … 899 709 } 900 710 711 /***************************************************************************** 712 * 713 *****************************************************************************/ 901 714 static http_answer_t *http_answer_parse( uint8_t *p_data, int i_data ) 902 715 { … … 982 795 } 983 796 797 /***************************************************************************** 798 * 799 *****************************************************************************/ 984 800 static void http_answer_free( http_answer_t *ans ) 985 801 { … … 1002 818 } 1003 819 820 /***************************************************************************** 821 * 822 *****************************************************************************/ 1004 823 static http_field_t *http_field_find( http_field_t *p_field, char *psz_name ) 1005 824 { … … 1018 837 } 1019 838 839 /***************************************************************************** 840 * 841 *****************************************************************************/ 1020 842 static int chunk_parse( chunk_t *ck, uint8_t *p_data, int i_data ) 1021 843 { modules/access/mms/mmsh.h
r217c4d9 r5deafc1 3 3 ***************************************************************************** 4 4 * Copyright (C) 2001, 2002 VideoLAN 5 * $Id: mmsh.h,v 1. 4 2003/08/26 00:51:19fenrir Exp $5 * $Id: mmsh.h,v 1.5 2004/01/21 16:56:16 fenrir Exp $ 6 6 * 7 7 * Authors: Laurent Aimar <fenrir@via.ecp.fr> … … 37 37 } chunk_t; 38 38 39 static int chunk_parse( chunk_t *, uint8_t *, int );40 41 39 #define BUFFER_SIZE 150000 42 40 struct access_sys_t … … 44 42 int i_proto; 45 43 46 in put_socket_t *p_socket;44 int fd; 47 45 url_t *p_url; 48 46 … … 69 67 }; 70 68 71 static input_socket_t * NetOpenTCP ( input_thread_t *, url_t * );72 static ssize_t NetRead ( input_thread_t *, input_socket_t *, byte_t *, size_t );73 static ssize_t NetWrite ( input_thread_t *, input_socket_t *, byte_t *, size_t );74 static void NetClose ( input_thread_t *, input_socket_t * );75 76 77 static ssize_t NetFill( input_thread_t *, access_sys_t *, int );78 79 69 typedef struct http_field_s 80 70 { … … 99 89 } http_answer_t; 100 90 101 static http_answer_t *http_answer_parse ( uint8_t *, int );102 static void http_answer_free ( http_answer_t * );103 /* static char *http_field_get_value ( http_answer_t *, char * ); */104 static http_field_t *http_field_find ( http_field_t *, char * );105 91 106 static int mmsh_start( input_thread_t *, off_t );107 static void mmsh_stop ( input_thread_t * );modules/access/mms/mmstu.c
r0d39f13 r5deafc1 3 3 ***************************************************************************** 4 4 * Copyright (C) 2001, 2002 VideoLAN 5 * $Id: mmstu.c,v 1. 6 2003/07/31 23:44:49fenrir Exp $5 * $Id: mmstu.c,v 1.7 2004/01/21 16:56:16 fenrir Exp $ 6 6 * 7 7 * Authors: Laurent Aimar <fenrir@via.ecp.fr> … … 82 82 static void Seek ( input_thread_t *, off_t ); 83 83 84 static int MMSOpen( input_thread_t *, url_t *, int , char *);84 static int MMSOpen( input_thread_t *, url_t *, int ); 85 85 86 86 static int MMSStart ( input_thread_t *, uint32_t ); … … 96 96 97 97 static int mms_ReceivePacket( input_thread_t * ); 98 99 //static void mms_ParseURL( url_t *p_url, char *psz_url );100 101 98 102 99 … … 120 117 int E_( MMSTUOpen ) ( input_thread_t *p_input ) 121 118 { 122 access_sys_t *p_sys;123 int i_proto;124 char *psz_network;125 int i_status;119 access_sys_t *p_sys; 120 int i_proto; 121 int i_status; 122 vlc_value_t val; 126 123 127 124 /* *** allocate p_sys_data *** */ … … 131 128 132 129 /* *** Parse URL and get server addr/port and path *** */ 133 //mms_ParseURL( &p_sys->url, p_input->psz_name );134 130 p_sys->p_url = E_( url_new )( p_input->psz_name ); 135 131 … … 138 134 E_( url_free )( p_sys->p_url ); 139 135 msg_Err( p_input, "invalid server name" ); 140 return ( -1 );136 return VLC_EGENERIC; 141 137 } 142 138 if( p_sys->p_url->i_port <= 0 ) … … 144 140 p_sys->p_url->i_port = 1755; 145 141 } 146 #if 0147 if( p_sys->url.i_bind_port == 0 )148 {149 p_sys->url.i_bind_port = 7000; /* default port */150 }151 #endif152 142 153 143 /* *** connect to this server *** */ 154 /* 1:look at requested protocol (udp/tcp) */144 /* look at requested protocol (udp/tcp) */ 155 145 i_proto = MMS_PROTO_AUTO; 156 146 if( *p_input->psz_access ) … … 165 155 } 166 156 } 167 /* 2: look at ip version ipv4/ipv6 */ 168 psz_network = ""; 169 if( config_GetInt( p_input, "ipv4" ) ) 170 { 171 psz_network = "ipv4"; 172 } 173 else if( config_GetInt( p_input, "ipv6" ) ) 174 { 175 psz_network = "ipv6"; 176 } 177 /* 3: connect */ 157 158 /* connect */ 178 159 if( i_proto == MMS_PROTO_AUTO ) 179 160 { /* first try with TCP */ 180 i_status = 181 MMSOpen( p_input, p_sys->p_url, MMS_PROTO_TCP, psz_network ); 182 if( i_status < 0 ) 161 if( ( i_status = MMSOpen( p_input, p_sys->p_url, MMS_PROTO_TCP ) ) ) 183 162 { /* then with UDP */ 184 i_status = 185 MMSOpen( p_input, p_sys->p_url, MMS_PROTO_UDP, psz_network ); 163 i_status = MMSOpen( p_input, p_sys->p_url, MMS_PROTO_UDP ); 186 164 } 187 165 } 188 166 else 189 167 { 190 191 i_status = 192 MMSOpen( p_input, p_sys->p_url, i_proto, psz_network ); 193 } 194 195 if( i_status < 0 ) 168 i_status = MMSOpen( p_input, p_sys->p_url, i_proto ); 169 } 170 171 if( i_status ) 196 172 { 197 173 msg_Err( p_input, "cannot connect to server" ); 198 174 E_( url_free )( p_sys->p_url ); 199 return( -1 ); 200 } 175 return VLC_EGENERIC; 176 } 177 201 178 msg_Dbg( p_input, "connected to %s:%d", p_sys->p_url->psz_host, p_sys->p_url->i_port ); 202 203 179 204 180 /* *** set exported functions *** */ … … 242 218 MMSClose( p_input ); 243 219 E_( url_free )( p_sys->p_url ); 244 return ( -1 );220 return VLC_EGENERIC; 245 221 } 246 222 247 223 /* Update default_pts to a suitable value for mms access */ 248 p_input->i_pts_delay = config_GetInt( p_input, "mms-caching" ) * 1000; 249 250 return( 0 ); 224 var_Get( p_input, "mms-caching", &val ); 225 p_input->i_pts_delay = val.i_int * 1000; 226 227 return VLC_SUCCESS; 251 228 } 252 229 … … 420 397 * MMSOpen : Open a connection with the server over mmst or mmsu 421 398 ****************************************************************************/ 422 static int MMSOpen( input_thread_t *p_input, 423 url_t *p_url, 424 int i_proto, 425 char *psz_network ) /* "", "ipv4", "ipv6" */ 399 static int MMSOpen( input_thread_t *p_input, url_t *p_url, int i_proto ) 426 400 { 427 module_t *p_network;428 401 access_sys_t *p_sys = p_input->p_access_data; 429 430 network_socket_t socket_desc; 431 int b_udp = ( i_proto == MMS_PROTO_UDP ) ? 1 : 0; 402 int b_udp = ( i_proto == MMS_PROTO_UDP ) ? 1 : 0; 432 403 433 404 var_buffer_t buffer; … … 445 416 /* *** Open a TCP connection with server *** */ 446 417 msg_Dbg( p_input, "waiting for connection..." ); 447 socket_desc.i_type = NETWORK_TCP; 448 socket_desc.psz_server_addr = p_url->psz_host; 449 socket_desc.i_server_port = p_url->i_port; 450 socket_desc.psz_bind_addr = ""; 451 socket_desc.i_bind_port = 0; 452 socket_desc.i_ttl = 0; 453 p_input->p_private = (void*)&socket_desc; 454 if( !( p_network = module_Need( p_input, "network", psz_network ) ) ) 418 p_sys->socket_tcp.i_handle = net_OpenTCP( p_input, p_url->psz_host, p_url->i_port ); 419 if( p_sys->socket_tcp.i_handle < 0 ) 455 420 { 456 421 msg_Err( p_input, "failed to open a connection (tcp)" ); 457 return( -1 ); 458 } 459 module_Unneed( p_input, p_network ); 460 p_sys->socket_tcp.i_handle = socket_desc.i_handle; 461 p_input->i_mtu = 0; /*socket_desc.i_mtu;*/ 422 return VLC_EGENERIC; 423 } 424 p_input->i_mtu = 0; 462 425 msg_Dbg( p_input, 463 426 "connection(tcp) with \"%s:%d\" successful", … … 476 439 477 440 msg_Err( p_input, "for udp you have to provide bind address (mms://<server_addr>@<bind_addr/<path> (FIXME)" ); 478 #if defined( UNDER_CE ) 479 CloseHandle( (HANDLE)p_sys->socket_tcp.i_handle ); 480 #elif defined( WIN32 ) 481 closesocket( p_sys->socket_tcp.i_handle ); 482 #else 483 close( p_sys->socket_tcp.i_handle ); 484 #endif 485 return( -1 ); 441 net_Close( p_sys->socket_tcp.i_handle ); 442 return VLC_EGENERIC; 486 443 } 487 444 p_sys->psz_bind_addr = inet_ntoa( name.sin_addr ); 488 445 489 socket_desc.i_type = NETWORK_UDP; 490 socket_desc.psz_server_addr = ""; 491 socket_desc.i_server_port = 0; 492 socket_desc.psz_bind_addr = p_sys->psz_bind_addr; 493 socket_desc.i_bind_port = 7000; //p_url->i_bind_port; FIXME 494 socket_desc.i_ttl = 0; 495 p_input->p_private = (void*)&socket_desc; 496 if( !( p_network = module_Need( p_input, "network", psz_network ) ) ) 446 p_sys->socket_udp.i_handle = net_OpenUDP( p_input, p_sys->psz_bind_addr, 7000, "", 0 ); 447 if( p_sys->socket_udp.i_handle < 0 ) 497 448 { 498 449 msg_Err( p_input, "failed to open a connection (udp)" ); 499 #if defined( UNDER_CE ) 500 CloseHandle( (HANDLE)p_sys->socket_tcp.i_handle ); 501 #elif defined( WIN32 ) 502 closesocket( p_sys->socket_tcp.i_handle ); 503 #else 504 close( p_sys->socket_tcp.i_handle ); 505 #endif 506 return( -1 ); 507 } 508 module_Unneed( p_input, p_network ); 509 p_sys->socket_udp.i_handle = socket_desc.i_handle; 510 p_input->i_mtu = 0;/*socket_desc.i_mtu; FIXME */ 511 450 net_Close( p_sys->socket_tcp.i_handle ); 451 return VLC_EGENERIC; 452 } 512 453 msg_Dbg( p_input, 513 454 "connection(udp) at \"%s:%d\" successful", 514 p_sys->psz_bind_addr, 515 7000 ); 455 p_sys->psz_bind_addr, 7000 ); 516 456 } 517 457 else … … 565 505 var_buffer_free( &buffer ); 566 506 MMSClose( p_input ); 567 return ( -1 );507 return VLC_EGENERIC; 568 508 } 569 509 … … 632 572 var_buffer_free( &buffer ); 633 573 MMSClose( p_input ); 634 return ( -1 );574 return VLC_EGENERIC; 635 575 } 636 576 else if( p_sys->i_command != 0x02 ) … … 661 601 var_buffer_free( &buffer ); 662 602 MMSClose( p_input ); 663 return ( -1 );603 return VLC_EGENERIC; 664 604 } 665 605 if( p_sys->i_command != 0x06 ) … … 688 628 var_buffer_free( &buffer ); 689 629 MMSClose( p_input ); 690 return ( -1 );630 return VLC_EGENERIC; 691 631 } 692 632 … … 757 697 var_buffer_free( &buffer ); 758 698 MMSClose( p_input ); 759 return ( -1 );699 return VLC_EGENERIC; 760 700 } 761 701 if( p_sys->i_header >= p_sys->i_header_size ) … … 835 775 var_buffer_free( &buffer ); 836 776 MMSClose( p_input ); 837 return ( -1 );777 return VLC_EGENERIC; 838 778 } 839 779 mms_CommandSend( p_input, 0x33, … … 850 790 var_buffer_free( &buffer ); 851 791 MMSClose( p_input ); 852 return ( -1 );792 return VLC_EGENERIC; 853 793 } 854 794 … … 858 798 msg_Info( p_input, "connection sucessful" ); 859 799 860 return ( 0 );800 return VLC_SUCCESS; 861 801 } 862 802 … … 934 874 0x00000001, 935 875 NULL, 0 ); 876 936 877 /* *** close sockets *** */ 937 #if defined( UNDER_CE ) 938 CloseHandle( (HANDLE)p_sys->socket_tcp.i_handle ); 939 #elif defined( WIN32 ) 940 closesocket( p_sys->socket_tcp.i_handle ); 941 #else 942 close( p_sys-&
