1 /*****************************************************************************
2 * mms.c: MMS access plug-in
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 VideoLAN
5 * $Id: mms.c,v 1.28 2003/03/24 17:15:29 gbazin Exp $
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
27 * - clean code, break huge code block
29 * - begin udp support...
32 /*****************************************************************************
34 *****************************************************************************/
37 #include <sys/types.h>
44 #include <vlc/input.h>
51 # include <winsock2.h>
52 # include <ws2tcpip.h>
54 # define IN_MULTICAST(a) IN_CLASSD(a)
57 # include <sys/socket.h>
58 # include <netinet/in.h>
60 # include <arpa/inet.h>
61 # elif defined( SYS_BEOS )
62 # include <net/netdb.h>
73 /****************************************************************************
75 * MMSProtocole documentation found at http://get.to/sdp
76 ****************************************************************************/
78 /*****************************************************************************
80 *****************************************************************************/
81 static int Open ( vlc_object_t * );
82 static void Close ( vlc_object_t * );
84 static int Read ( input_thread_t * p_input, byte_t * p_buffer,
86 static void Seek ( input_thread_t *, off_t );
87 static int SetProgram ( input_thread_t *, pgrm_descriptor_t * );
90 static int MMSOpen( input_thread_t *, url_t *, int, char * );
92 static int MMSStart ( input_thread_t *, uint32_t );
93 static int MMSStop ( input_thread_t *p_input );
95 static int MMSClose ( input_thread_t * );
98 static int mms_CommandRead( input_thread_t *p_input, int i_command1, int i_command2 );
99 static int mms_CommandSend( input_thread_t *, int, uint32_t, uint32_t, uint8_t *, int );
101 static int mms_HeaderMediaRead( input_thread_t *, int );
103 static int mms_ReceivePacket( input_thread_t * );
105 static void mms_ParseURL( url_t *p_url, char *psz_url );
110 * XXX DON'T FREE MY MEMORY !!! XXX
115 * Ok, ok, j'le ferai plus...
121 * Vous pourriez signer vos commentaires (même si on voit bien qui peut
122 * écrire ce genre de trucs :p), et écrire en anglais, bordel de
126 /*****************************************************************************
128 *****************************************************************************/
129 #define CACHING_TEXT N_("caching value in ms")
130 #define CACHING_LONGTEXT N_( \
131 "Allows you to modify the default caching value for mms streams. This " \
132 "value should be set in miliseconds units." )
135 set_description( _("MMS access module") );
136 set_capability( "access", 0 );
137 add_category_hint( "stream", NULL, VLC_TRUE );
138 add_integer( "mms-caching", 4 * DEFAULT_PTS_DELAY / 1000, NULL,
139 CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
141 add_bool( "mms-all", 0, NULL,
142 "force selection of all streams",
143 "force selection of all streams", VLC_TRUE );
145 add_string( "mms-stream", NULL, NULL,
147 "force this stream selection", VLC_TRUE );
148 add_integer( "mms-maxbitrate", 0, NULL,
150 "set max bitrate for auto streams selections", VLC_FALSE );
151 add_shortcut( "mms" );
152 add_shortcut( "mmsu" );
153 add_shortcut( "mmst" );
154 set_callbacks( Open, Close );
157 #define BUF_SIZE 200000
159 static int Open( vlc_object_t *p_this )
166 input_thread_t *p_input = (input_thread_t*)p_this;
168 /* *** allocate p_access_data *** */
169 p_input->p_access_data =
170 (void*)p_access = malloc( sizeof( access_t ) );
171 memset( p_access, 0, sizeof( access_t ) );
174 /* *** Parse URL and get server addr/port and path *** */
175 mms_ParseURL( &p_access->url, p_input->psz_name );
176 if( p_access->url.psz_server_addr == NULL ||
177 !( *p_access->url.psz_server_addr ) )
179 FREE( p_access->url.psz_private );
180 msg_Err( p_input, "invalid server name" );
183 if( p_access->url.i_server_port == 0 )
185 p_access->url.i_server_port = 1755; /* default port */
187 if( p_access->url.i_bind_port == 0 )
189 p_access->url.i_bind_port = 7000; /* default port */
193 /* *** connect to this server *** */
194 /* 1: look at requested protocol (udp/tcp) */
195 i_proto = MMS_PROTO_AUTO;
196 if( *p_input->psz_access )
198 if( !strncmp( p_input->psz_access, "mmsu", 4 ) )
200 i_proto = MMS_PROTO_UDP;
202 else if( !strncmp( p_input->psz_access, "mmst", 4 ) )
204 i_proto = MMS_PROTO_TCP;
207 /* 2: look at ip version ipv4/ipv6 */
209 if( config_GetInt( p_input, "ipv4" ) )
211 psz_network = "ipv4";
213 else if( config_GetInt( p_input, "ipv6" ) )
215 psz_network = "ipv6";
218 if( i_proto == MMS_PROTO_AUTO )
219 { /* first try with TCP */
221 MMSOpen( p_input, &p_access->url, MMS_PROTO_TCP, psz_network );
223 { /* then with UDP */
225 MMSOpen( p_input, &p_access->url, MMS_PROTO_UDP, psz_network );
232 MMSOpen( p_input, &p_access->url, i_proto, psz_network );
237 msg_Err( p_input, "cannot connect to server" );
238 FREE( p_access->url.psz_private );
241 msg_Dbg( p_input, "connected to %s", p_access->url.psz_server_addr );
244 /* *** set exported functions *** */
245 p_input->pf_read = Read;
246 p_input->pf_seek = Seek;
247 p_input->pf_set_program = SetProgram;
248 p_input->pf_set_area = NULL;
250 p_input->p_private = NULL;
252 /* *** finished to set some variable *** */
253 vlc_mutex_lock( &p_input->stream.stream_lock );
254 p_input->stream.b_pace_control = 0;
255 p_input->stream.p_selected_area->i_tell = 0;
259 * broadcast yy=0x02, xx= 0x00
260 * pre-recorded yy=0x01, xx= 0x80 if video, 0x00 no video
262 if( p_access->i_packet_count <= 0 || ( p_access->i_flags_broadcast >> 24 ) == 0x02 )
264 p_input->stream.b_seekable = 0;
265 p_input->stream.p_selected_area->i_size = 0;
269 p_input->stream.b_seekable = 1;
270 p_input->stream.p_selected_area->i_size =
272 p_access->i_packet_count * p_access->i_packet_length;
275 p_input->stream.i_method = INPUT_METHOD_NETWORK;
276 vlc_mutex_unlock( &p_input->stream.stream_lock );
278 /* *** Start stream *** */
279 if( MMSStart( p_input, 0xffffffff ) < 0 )
281 msg_Err( p_input, "cannot start stream" );
283 FREE( p_access->url.psz_private );
287 /* Update default_pts to a suitable value for mms access */
288 p_input->i_pts_delay = config_GetInt( p_input, "mms-caching" ) * 1000;
293 /*****************************************************************************
294 * Close: free unused data structures
295 *****************************************************************************/
296 static void Close( vlc_object_t *p_this )
298 input_thread_t * p_input = (input_thread_t *)p_this;
299 access_t *p_access = (access_t*)p_input->p_access_data;
301 /* close connection with server */
305 FREE( p_access->url.psz_private );
307 FREE( p_input->p_access_data );
310 /*****************************************************************************
311 * SetProgram: do nothing
312 *****************************************************************************/
313 static int SetProgram( input_thread_t * p_input,
314 pgrm_descriptor_t * p_program )
319 /*****************************************************************************
320 * Seek: try to go at the right place
321 *****************************************************************************/
322 static void Seek( input_thread_t * p_input, off_t i_pos )
324 access_t *p_access = (access_t*)p_input->p_access_data;
334 vlc_mutex_lock( &p_input->stream.stream_lock );
336 if( i_pos < p_access->i_header)
339 if( p_access->i_pos < p_access->i_header )
341 /* no need to restart stream, it was already one
342 * or no stream was yet read */
343 p_access->i_pos = i_pos;
348 i_packet = 0xffffffff;
354 i_packet = ( i_pos - p_access->i_header ) / p_access->i_packet_length;
355 i_offset = ( i_pos - p_access->i_header ) % p_access->i_packet_length;
357 msg_Dbg( p_input, "seeking to "I64Fd " (packet:%d)", i_pos, i_packet );
360 msg_Dbg( p_input, "stream stopped (seek)" );
362 /* *** restart stream *** */
363 var_buffer_initwrite( &buffer, 0 );
364 var_buffer_add64( &buffer, 0 ); /* seek point in second */
365 var_buffer_add32( &buffer, 0xffffffff );
366 var_buffer_add32( &buffer, i_packet ); // begin from start
367 var_buffer_add8( &buffer, 0xff ); // stream time limit
368 var_buffer_add8( &buffer, 0xff ); // on 3bytes ...
369 var_buffer_add8( &buffer, 0xff ); //
370 var_buffer_add8( &buffer, 0x00 ); // don't use limit
371 var_buffer_add32( &buffer, p_access->i_media_packet_id_type );
373 mms_CommandSend( p_input, 0x07, p_access->i_command_level, 0x0001ffff,
374 buffer.p_data, buffer.i_data );
376 var_buffer_free( &buffer );
381 mms_HeaderMediaRead( p_input, MMS_PACKET_CMD );
382 if( p_access->i_command == 0x1e )
384 msg_Dbg( p_input, "received 0x1e (seek)" );
391 mms_HeaderMediaRead( p_input, MMS_PACKET_CMD );
392 if( p_access->i_command == 0x05 )
394 msg_Dbg( p_input, "received 0x05 (seek)" );
400 mms_HeaderMediaRead( p_input, MMS_PACKET_MEDIA );
401 msg_Dbg( p_input, "Streaming restarted" );
403 p_access->i_media_used += i_offset;
404 p_access->i_pos = i_pos;
405 p_input->stream.p_selected_area->i_tell = i_pos;
406 vlc_mutex_unlock( &p_input->stream.stream_lock );
409 static int Read ( input_thread_t * p_input, byte_t * p_buffer,
412 access_t *p_access = (access_t*)p_input->p_access_data;
418 /* *** send header if needed ** */
419 if( p_access->i_pos < p_access->i_header )
421 i_copy = __MIN( i_len, p_access->i_header - p_access->i_pos );
425 p_access->p_header + p_access->i_pos,
431 /* *** now send data if needed *** */
432 while( i_data < i_len )
434 if( p_access->i_media_used < p_access->i_media )
436 i_copy = __MIN( i_len - i_data ,
437 p_access->i_media - p_access->i_media_used );
438 memcpy( p_buffer + i_data,
439 p_access->p_media + p_access->i_media_used,
442 p_access->i_media_used += i_copy;
444 else if( p_access->p_media != NULL &&
445 p_access->i_media_used < p_access->i_packet_length )
447 i_copy = __MIN( i_len - i_data,
448 p_access->i_packet_length - p_access->i_media_used);
449 memset( p_buffer + i_data, 0, i_copy );
452 p_access->i_media_used += i_copy;
457 || mms_HeaderMediaRead( p_input, MMS_PACKET_MEDIA ) < 0 )
459 p_access->i_pos += i_data;
465 p_access->i_pos += i_data;
469 static void asf_HeaderParse( mms_stream_t stream[128],
470 uint8_t *p_header, int i_header )
477 for( i = 0; i < 128; i++ )
479 stream[i].i_cat = MMS_STREAM_UNKNOWN;
482 //fprintf( stderr, " ---------------------header:%d\n", i_header );
483 var_buffer_initread( &buffer, p_header, i_header );
485 var_buffer_getguid( &buffer, &guid );
487 if( !CmpGuid( &guid, &asf_object_header_guid ) )
490 // fprintf( stderr, " ---------------------ERROR------\n" );
492 var_buffer_getmemory( &buffer, NULL, 30 - 16 );
496 //fprintf( stderr, " ---------------------data:%d\n", buffer.i_data );
498 var_buffer_getguid( &buffer, &guid );
499 i_size = var_buffer_get64( &buffer );
501 //fprintf( stderr, " guid=0x%8.8x-0x%4.4x-0x%4.4x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x size=%lld\n",
502 // guid.v1,guid.v2, guid.v3,
503 // guid.v4[0],guid.v4[1],guid.v4[2],guid.v4[3],
504 // guid.v4[4],guid.v4[5],guid.v4[6],guid.v4[7],
507 if( CmpGuid( &guid, &asf_object_stream_properties_guid ) )
511 //msg_Dbg( p_input, "found stream_properties" );
513 var_buffer_getguid( &buffer, &stream_type );
514 var_buffer_getmemory( &buffer, NULL, 32 );
515 i_stream_id = var_buffer_get8( &buffer ) & 0x7f;
517 //fprintf( stderr, " 1---------------------skip:%lld\n", i_size - 24 - 32 - 16 - 1 );
518 var_buffer_getmemory( &buffer, NULL, i_size - 24 - 32 - 16 - 1);
520 if( CmpGuid( &stream_type, &asf_object_stream_type_video ) )
522 //fprintf( stderr, "\nvideo stream[%d] found\n", i_stream_id );
523 //msg_Dbg( p_input, "video stream[%d] found", i_stream_id );
524 stream[i_stream_id].i_cat = MMS_STREAM_VIDEO;
526 else if( CmpGuid( &stream_type, &asf_object_stream_type_audio ) )
528 //fprintf( stderr, "\naudio stream[%d] found\n", i_stream_id );
529 //msg_Dbg( p_input, "audio stream[%d] found", i_stream_id );
530 stream[i_stream_id].i_cat = MMS_STREAM_AUDIO;
534 // msg_Dbg( p_input, "unknown stream[%d] found", i_stream_id );
535 stream[i_stream_id].i_cat = MMS_STREAM_UNKNOWN;
538 else if ( CmpGuid( &guid, &asf_object_bitrate_properties_guid ) )
543 i_count = var_buffer_get16( &buffer );
547 i_stream_id = var_buffer_get16( &buffer )&0x7f;
548 stream[i_stream_id].i_bitrate = var_buffer_get32( &buffer );
552 //fprintf( stderr, " 2---------------------skip:%lld\n", i_size - 24);
553 var_buffer_getmemory( &buffer, NULL, i_size - 24 );
557 //fprintf( stderr, " 3---------------------skip:%lld\n", i_size - 24);
559 var_buffer_getmemory( &buffer, NULL, i_size - 24 );
562 if( var_buffer_readempty( &buffer ) )
569 static void mms_StreamSelect( input_thread_t * p_input,
570 mms_stream_t stream[128] )
572 /* XXX FIXME use mututal eclusion information */
574 int i_audio, i_video;
575 int b_audio, b_video;
583 i_bitrate_max = config_GetInt( p_input, "mms-maxbitrate" );
584 b_audio = config_GetInt( p_input, "audio" );
585 b_video = config_GetInt( p_input, "video" );
586 if( config_GetInt( p_input, "mms-all" ) )
588 /* select all valid stream */
589 for( i = 1; i < 128; i++ )
591 if( stream[i].i_cat != MMS_STREAM_UNKNOWN )
593 stream[i].i_selected = 1;
600 for( i = 0; i < 128; i++ )
602 stream[i].i_selected = 0; /* by default, not selected */
605 psz_stream = config_GetPsz( p_input, "mms-stream" );
607 if( psz_stream && *psz_stream )
609 char *psz_tmp = psz_stream;
612 if( *psz_tmp == ',' )
619 i_stream = atoi( psz_tmp );
620 while( *psz_tmp != '\0' && *psz_tmp != ',' )
625 if( i_stream > 0 && i_stream < 128 &&
626 stream[i_stream].i_cat != MMS_STREAM_UNKNOWN )
628 stream[i_stream].i_selected = 1;
639 * - no audio nor video stream
641 * - if i_bitrate_max not set keep the highest bitrate
642 * - if i_bitrate_max is set, keep stream that make we used best
643 * quality regarding i_bitrate_max
646 * - it doesn't use mutual exclusion info..
647 * - when selecting a better stream we could select
648 * something that make i_bitrate_total> i_bitrate_max
650 for( i = 1; i < 128; i++ )
652 if( stream[i].i_cat == MMS_STREAM_UNKNOWN )
656 else if( stream[i].i_cat == MMS_STREAM_AUDIO && b_audio &&
658 ( ( ( stream[i].i_bitrate > stream[i_audio].i_bitrate &&
659 ( i_bitrate_total + stream[i].i_bitrate - stream[i_audio].i_bitrate
660 < i_bitrate_max || !i_bitrate_max) ) ||
661 ( stream[i].i_bitrate < stream[i_audio].i_bitrate &&
662 i_bitrate_max != 0 && i_bitrate_total > i_bitrate_max )
665 /* unselect old stream */
668 stream[i_audio].i_selected = 0;
669 if( stream[i_audio].i_bitrate> 0 )
671 i_bitrate_total -= stream[i_audio].i_bitrate;
675 stream[i].i_selected = 1;
676 if( stream[i].i_bitrate> 0 )
678 i_bitrate_total += stream[i].i_bitrate;
682 else if( stream[i].i_cat == MMS_STREAM_VIDEO && b_video &&
685 ( ( stream[i].i_bitrate > stream[i_video].i_bitrate &&
686 ( i_bitrate_total + stream[i].i_bitrate - stream[i_video].i_bitrate
687 < i_bitrate_max || !i_bitrate_max) ) ||
688 ( stream[i].i_bitrate < stream[i_video].i_bitrate &&
689 i_bitrate_max != 0 && i_bitrate_total > i_bitrate_max )
692 /* unselect old stream */
694 stream[i_video].i_selected = 0;
695 if( stream[i_video].i_bitrate> 0 )
697 i_bitrate_total -= stream[i_video].i_bitrate;
700 stream[i].i_selected = 1;
701 if( stream[i].i_bitrate> 0 )
703 i_bitrate_total += stream[i].i_bitrate;
709 if( i_bitrate_max > 0 )
712 "requested bitrate:%d real bitrate:%d",
713 i_bitrate_max, i_bitrate_total );
723 /****************************************************************************
724 * MMSOpen : Open a connection with the server over mmst or mmsu(not yet)
725 ****************************************************************************/
726 static int MMSOpen( input_thread_t *p_input,
729 char *psz_network ) /* "", "ipv4", "ipv6" */
732 access_t *p_access = (access_t*)p_input->p_access_data;
734 network_socket_t socket_desc;
735 int b_udp = ( i_proto == MMS_PROTO_UDP ) ? 1 : 0;
740 int i_server_version;
742 int i_update_player_url;
743 int i_encryption_type;
749 /* *** Open a TCP connection with server *** */
750 msg_Dbg( p_input, "waiting for connection..." );
751 socket_desc.i_type = NETWORK_TCP;
752 socket_desc.psz_server_addr = p_url->psz_server_addr;
753 socket_desc.i_server_port = p_url->i_server_port;
754 socket_desc.psz_bind_addr = "";
755 socket_desc.i_bind_port = 0;
756 p_input->p_private = (void*)&socket_desc;
757 if( !( p_network = module_Need( p_input, "network", psz_network ) ) )
759 msg_Err( p_input, "failed to open a connection (tcp)" );
762 module_Unneed( p_input, p_network );
763 p_access->socket_tcp.i_handle = socket_desc.i_handle;
764 p_input->i_mtu = 0; /*socket_desc.i_mtu;*/
766 "connection(tcp) with \"%s:%d\" successful",
767 p_url->psz_server_addr,
768 p_url->i_server_port );
770 /* *** Bind port if UDP protocol is selected *** */
773 if( !p_url->psz_bind_addr || !*p_url->psz_bind_addr )
775 struct sockaddr_in name;
776 socklen_t i_namelen = sizeof( struct sockaddr_in );
778 if( getsockname( p_access->socket_tcp.i_handle,
779 (struct sockaddr*)&name, &i_namelen ) < 0 )
782 msg_Err( p_input, "for udp you have to provide bind address (mms://<server_addr>@<bind_addr/<path> (FIXME)" );
783 #if defined( UNDER_CE )
784 CloseHandle( (HANDLE)p_access->socket_tcp.i_handle );
785 #elif defined( WIN32 )
786 closesocket( p_access->socket_tcp.i_handle );
788 close( p_access->socket_tcp.i_handle );
792 p_access->psz_bind_addr = inet_ntoa( name.sin_addr );
796 p_access->psz_bind_addr = strdup( p_url->psz_bind_addr );
798 socket_desc.i_type = NETWORK_UDP;
799 socket_desc.psz_server_addr = "";
800 socket_desc.i_server_port = 0;
801 socket_desc.psz_bind_addr = p_access->psz_bind_addr;
802 socket_desc.i_bind_port = p_url->i_bind_port;
803 p_input->p_private = (void*)&socket_desc;
804 if( !( p_network = module_Need( p_input, "network", psz_network ) ) )
806 msg_Err( p_input, "failed to open a connection (udp)" );
807 #if defined( UNDER_CE )
808 CloseHandle( (HANDLE)p_access->socket_tcp.i_handle );
809 #elif defined( WIN32 )
810 closesocket( p_access->socket_tcp.i_handle );
812 close( p_access->socket_tcp.i_handle );
816 module_Unneed( p_input, p_network );
817 p_access->socket_udp.i_handle = socket_desc.i_handle;
818 p_input->i_mtu = 0;/*socket_desc.i_mtu; FIXME */
823 p_access->psz_bind_addr = NULL;
826 /* *** Init context for mms prototcol *** */
827 GenerateGuid( &p_access->guid ); /* used to identify client by server */
829 "generated guid: "GUID_FMT,
830 GUID_PRINT( p_access->guid ) );
831 p_access->i_command_level = 1; /* updated after 0x1A command */
832 p_access->i_seq_num = 0;
833 p_access->i_media_packet_id_type = 0x04;
834 p_access->i_header_packet_id_type = 0x02;
835 p_access->i_proto = i_proto;
836 p_access->i_packet_seq_num = 0;
837 p_access->p_header = NULL;
838 p_access->i_header = 0;
839 p_access->p_media = NULL;
840 p_access->i_media = 0;
841 p_access->i_media_used = 0;
844 p_access->i_buffer_tcp = 0;
845 p_access->i_buffer_udp = 0;
846 p_access->p_cmd = NULL;
850 /* *** send command 1 : connection request *** */
851 var_buffer_initwrite( &buffer, 0 );
852 var_buffer_add16( &buffer, 0x001c );
853 var_buffer_add16( &buffer, 0x0003 );
855 "NSPlayer/7.0.0.1956; {"GUID_FMT"}; Host: %s",
856 GUID_PRINT( p_access->guid ),
857 p_url->psz_server_addr );
858 var_buffer_addUTF16( &buffer, tmp );
860 mms_CommandSend( p_input,
861 0x01, /* connexion request */
862 0x00000000, /* flags, FIXME */
863 0x0004000b, /* ???? */
867 if( mms_CommandRead( p_input, 0x01, 0 ) < 0 )
869 var_buffer_free( &buffer );
874 i_server_version = GetDWLE( p_access->p_cmd + MMS_CMD_HEADERSIZE + 32 );
875 i_tool_version = GetDWLE( p_access->p_cmd + MMS_CMD_HEADERSIZE + 36 );
876 i_update_player_url = GetDWLE( p_access->p_cmd + MMS_CMD_HEADERSIZE + 40 );
877 i_encryption_type = GetDWLE( p_access->p_cmd + MMS_CMD_HEADERSIZE + 44 );
878 p = (uint16_t*)( p_access->p_cmd + MMS_CMD_HEADERSIZE + 48 );
879 #define GETUTF16( psz, size ) \
882 psz = malloc( size + 1); \
883 for( i = 0; i < size; i++ ) \
890 GETUTF16( p_access->psz_server_version, i_server_version );
891 GETUTF16( p_access->psz_tool_version, i_tool_version );
892 GETUTF16( p_access->psz_update_player_url, i_update_player_url );
893 GETUTF16( p_access->psz_encryption_type, i_encryption_type );
896 "0x01 --> server_version:\"%s\" tool_version:\"%s\" update_player_url:\"%s\" encryption_type:\"%s\"",
897 p_access->psz_server_version,
898 p_access->psz_tool_version,
899 p_access->psz_update_player_url,
900 p_access->psz_encryption_type );
902 /* *** should make an 18 command to make data timing *** */
904 /* *** send command 2 : transport protocol selection *** */
905 var_buffer_reinitwrite( &buffer, 0 );
906 var_buffer_add32( &buffer, 0x00000000 );
907 var_buffer_add32( &buffer, 0x000a0000 );
908 var_buffer_add32( &buffer, 0x00000002 );
913 p_access->psz_bind_addr,
914 p_url->i_bind_port );
918 sprintf( tmp, "\\\\192.168.0.1\\TCP\\1242" );
920 var_buffer_addUTF16( &buffer, tmp );
921 var_buffer_add16( &buffer, '0' );
923 mms_CommandSend( p_input,
924 0x02, /* connexion request */
925 0x00000000, /* flags, FIXME */
926 0xffffffff, /* ???? */
930 /* *** response from server, should be 0x02 or 0x03 *** */
931 mms_CommandRead( p_input, 0x02, 0x03 );
932 if( p_access->i_command == 0x03 )
935 "%s protocol selection failed", b_udp ? "UDP" : "TCP" );
936 var_buffer_free( &buffer );
940 else if( p_access->i_command != 0x02 )
942 msg_Warn( p_input, "received command isn't 0x02 in reponse to 0x02" );
945 /* *** send command 5 : media file name/path requested *** */
946 var_buffer_reinitwrite( &buffer, 0 );
947 var_buffer_add64( &buffer, 0 );
948 var_buffer_addUTF16( &buffer, p_url->psz_path );
950 mms_CommandSend( p_input,
952 p_access->i_command_level,
957 /* *** wait for reponse *** */
958 mms_CommandRead( p_input, 0x1a, 0x06 );
960 /* test if server send 0x1A answer */
961 if( p_access->i_command == 0x1A )
963 msg_Err( p_input, "id/password requested (not yet supported)" );
965 var_buffer_free( &buffer );
969 if( p_access->i_command != 0x06 )
972 "unknown answer (0x%x instead of 0x06)",
973 p_access->i_command );
974 var_buffer_free( &buffer );
979 /* 1 for file ok, 2 for authen ok */
980 switch( GetDWLE( p_access->p_cmd + MMS_CMD_HEADERSIZE ) )
983 msg_Dbg( p_input, "Media file name/path accepted" );
986 msg_Dbg( p_input, "Authentication accepted" );
990 msg_Err( p_input, "error while asking for file %d",
991 GetDWLE( p_access->p_cmd + MMS_CMD_HEADERSIZE ) );
992 var_buffer_free( &buffer );
997 p_access->i_flags_broadcast =
998 GetDWLE( p_access->p_cmd + MMS_CMD_HEADERSIZE + 12 );
999 p_access->i_media_length =
1000 GetDWLE( p_access->p_cmd + MMS_CMD_HEADERSIZE + 24 );
1001 p_access->i_packet_length =
1002 GetDWLE( p_access->p_cmd + MMS_CMD_HEADERSIZE + 44 );
1003 p_access->i_packet_count =
1004 GetDWLE( p_access->p_cmd + MMS_CMD_HEADERSIZE + 48 );
1005 p_access->i_max_bit_rate =
1006 GetDWLE( p_access->p_cmd + MMS_CMD_HEADERSIZE + 56 );
1007 p_access->i_header_size =
1008 GetDWLE( p_access->p_cmd + MMS_CMD_HEADERSIZE + 60 );
1011 "answer 0x06 flags:0x%8.8x media_length:%ds packet_length:%d packet_count:%d max_bit_rate:%d header_size:%d",
1012 p_access->i_flags_broadcast,
1013 p_access->i_media_length,
1014 p_access->i_packet_length,
1015 p_access->i_packet_count,
1016 p_access->i_max_bit_rate,
1017 p_access->i_header_size );
1019 /* XXX XXX dirty hack XXX XXX */
1020 p_input->i_mtu = 3 * p_access->i_packet_length;
1022 /* *** send command 15 *** */
1024 var_buffer_reinitwrite( &buffer, 0 );
1025 var_buffer_add32( &buffer, 0 );
1026 var_buffer_add32( &buffer, 0x8000 );
1027 var_buffer_add32( &buffer, 0xffffffff );
1028 var_buffer_add32( &buffer, 0x00 );
1029 var_buffer_add32( &buffer, 0x00 );
1030 var_buffer_add32( &buffer, 0x00 );
1031 var_buffer_add64( &buffer, 0x40ac200000000000 );
1032 var_buffer_add32( &buffer, p_access->i_header_packet_id_type );
1033 mms_CommandSend( p_input, 0x15, p_access->i_command_level, 0x00,
1034 buffer.p_data, buffer.i_data );
1036 /* *** wait for reponse *** */
1037 mms_CommandRead( p_input, 0x11, 0 );
1039 if( p_access->i_command != 0x11 )
1042 "unknown answer (0x%x instead of 0x11)",
1043 p_access->i_command );
1044 var_buffer_free( &buffer );
1045 MMSClose( p_input );
1048 /* *** now read header packet *** */
1049 /* XXX could be split over multiples packets */
1052 if( mms_HeaderMediaRead( p_input, MMS_PACKET_HEADER ) < 0 )
1054 msg_Err( p_input, "cannot receive header" );
1055 var_buffer_free( &buffer );
1056 MMSClose( p_input );
1059 if( p_access->i_header >= p_access->i_header_size )
1062 "header complete(%d)",
1063 p_access->i_header );
1067 "header incomplete (%d/%d), reading more",
1069 p_access->i_header_size );
1072 /* *** parse header and get stream and their id *** */
1073 /* get all streams properties,
1075 * TODO : stream bitrates properties(optional)
1076 * and bitrate mutual exclusion(optional) */
1077 asf_HeaderParse( p_access->stream,
1078 p_access->p_header, p_access->i_header );
1079 mms_StreamSelect( p_input, p_access->stream );
1080 /* *** now select stream we want to receive *** */
1081 /* TODO take care of stream bitrate TODO */
1084 var_buffer_reinitwrite( &buffer, 0 );
1085 /* for now, select first audio and video stream */
1086 for( i = 1; i < 128; i++ )
1089 if( p_access->stream[i].i_cat != MMS_STREAM_UNKNOWN )
1094 var_buffer_add16( &buffer, 0xffff );
1095 var_buffer_add16( &buffer, i );
1101 if( p_access->stream[i].i_selected )
1103 var_buffer_add16( &buffer, 0x0000 );
1105 "selecting stream[0x%x] %s (%d kb/s)",
1107 ( p_access->stream[i].i_cat == MMS_STREAM_AUDIO ) ?
1109 p_access->stream[i].i_bitrate / 1024);
1113 var_buffer_add16( &buffer, 0x0002 );
1115 "ignoring stream[0x%x] %s (%d kb/s)",
1117 ( p_access->stream[i].i_cat == MMS_STREAM_AUDIO ) ?
1119 p_access->stream[i].i_bitrate / 1024);
1125 if( i_streams == 0 )
1127 msg_Err( p_input, "cannot find any stream" );
1128 var_buffer_free( &buffer );
1129 MMSClose( p_input );
1132 mms_CommandSend( p_input, 0x33,
1134 0xffff | ( i_first << 16 ),
1135 buffer.p_data, buffer.i_data );
1137 mms_CommandRead( p_input, 0x21, 0 );
1138 if( p_access->i_command != 0x21 )
1141 "unknown answer (0x%x instead of 0x21)",
1142 p_access->i_command );
1143 var_buffer_free( &buffer );
1144 MMSClose( p_input );
1149 var_buffer_free( &buffer );
1151 msg_Info( p_input, "connection sucessful" );
1156 /****************************************************************************
1157 * MMSStart : Start streaming
1158 ****************************************************************************/
1159 static int MMSStart ( input_thread_t *p_input, uint32_t i_packet )
1161 access_t *p_access = (access_t*)p_input->p_access_data;
1162 var_buffer_t buffer;
1164 /* *** start stream from packet 0 *** */
1165 var_buffer_initwrite( &buffer, 0 );
1166 var_buffer_add64( &buffer, 0 ); /* seek point in second */
1167 var_buffer_add32( &buffer, 0xffffffff );
1168 var_buffer_add32( &buffer, i_packet ); // begin from start
1169 var_buffer_add8( &buffer, 0xff ); // stream time limit
1170 var_buffer_add8( &buffer, 0xff ); // on 3bytes ...
1171 var_buffer_add8( &buffer, 0xff ); //
1172 var_buffer_add8( &buffer, 0x00 ); // don't use limit
1173 var_buffer_add32( &buffer, p_access->i_media_packet_id_type );
1175 mms_CommandSend( p_input, 0x07, p_access->i_command_level, 0x0001ffff,
1176 buffer.p_data, buffer.i_data );
1178 var_buffer_free( &buffer );
1180 mms_CommandRead( p_input, 0x05, 0 );
1182 if( p_access->i_command != 0x05 )
1185 "unknown answer (0x%x instead of 0x05)",
1186 p_access->i_command );
1192 mms_HeaderMediaRead( p_input, MMS_PACKET_MEDIA );
1193 msg_Dbg( p_input, "Streaming started" );
1198 /****************************************************************************
1199 * MMSStop : Stop streaming
1200 ****************************************************************************/
1201 static int MMSStop ( input_thread_t *p_input )
1203 access_t *p_access = (access_t*)p_input->p_access_data;
1205 /* *** stop stream but keep connection alive *** */
1206 mms_CommandSend( p_input,
1208 p_access->i_command_level,
1214 /****************************************************************************
1215 * MMSClose : Close streaming and connection
1216 ****************************************************************************/
1217 static int MMSClose ( input_thread_t *p_input )
1219 access_t *p_access = (access_t*)p_input->p_access_data;
1221 msg_Dbg( p_input, "Connection closed" );
1223 /* *** tell server that we will disconnect *** */
1224 mms_CommandSend( p_input,
1226 p_access->i_command_level,
1229 /* *** close sockets *** */
1230 #if defined( UNDER_CE )
1231 CloseHandle( (HANDLE)p_access->socket_tcp.i_handle );
1232 #elif defined( WIN32 )
1233 closesocket( p_access->socket_tcp.i_handle );
1235 close( p_access->socket_tcp.i_handle );
1238 if( p_access->i_proto == MMS_PROTO_UDP )
1240 #if defined( UNDER_CE )
1241 CloseHandle( (HANDLE)p_access->socket_udp.i_handle );
1242 #elif defined( WIN32 )
1243 closesocket( p_access->socket_udp.i_handle );
1245 close( p_access->socket_udp.i_handle );
1249 FREE( p_access->p_cmd );
1250 FREE( p_access->p_media );
1251 FREE( p_access->p_header );
1253 FREE( p_access->psz_server_version );
1254 FREE( p_access->psz_tool_version );
1255 FREE( p_access->psz_update_player_url );
1256 FREE( p_access->psz_encryption_type );
1261 /*****************************************************************************
1262 * mms_ParseURL : parse an url string and fill an url_t
1263 *****************************************************************************/
1264 static void mms_ParseURL( url_t *p_url, char *psz_url )
1267 char *psz_server_port;
1269 p_url->psz_private = strdup( psz_url );
1271 psz_parser = p_url->psz_private;
1273 while( *psz_parser == '/' )
1277 p_url->psz_server_addr = psz_parser;
1279 while( *psz_parser &&
1280 *psz_parser != ':' && *psz_parser != '/' && *psz_parser != '@' )
1285 if( *psz_parser == ':' )
1289 psz_server_port = psz_parser;
1291 while( *psz_parser && *psz_parser != '/' )
1298 psz_server_port = "";
1301 if( *psz_parser == '@' )
1303 char *psz_bind_port;
1308 p_url->psz_bind_addr = psz_parser;
1310 while( *psz_parser && *psz_parser != ':' && *psz_parser != '/' )
1315 if( *psz_parser == ':' )
1319 psz_bind_port = psz_parser;
1321 while( *psz_parser && *psz_parser != '/' )
1330 if( *psz_bind_port )
1332 p_url->i_bind_port = strtol( psz_bind_port, &psz_parser, 10 );
1336 p_url->i_bind_port = 0;
1341 p_url->psz_bind_addr = "";
1342 p_url->i_bind_port = 0;
1345 if( *psz_parser == '/' )
1349 p_url->psz_path = psz_parser;
1352 if( *psz_server_port )
1354 p_url->i_server_port = strtol( psz_server_port, &psz_parser, 10 );
1358 p_url->i_server_port = 0;
1362 /****************************************************************************
1364 * MMS specific functions
1366 ****************************************************************************/
1368 static int mms_CommandSend( input_thread_t *p_input,
1370 uint32_t i_prefix1, uint32_t i_prefix2,
1371 uint8_t *p_data, int i_data )
1373 var_buffer_t buffer;
1375 access_t *p_access = (access_t*)p_input->p_access_data;
1378 i_data_by8 = ( i_data + 7 ) / 8;
1380 /* first init uffer */
1381 var_buffer_initwrite( &buffer, 0 );
1383 var_buffer_add32( &buffer, 0x00000001 ); /* start sequence */
1384 var_buffer_add32( &buffer, 0xB00BFACE );
1385 /* size after protocol type */
1386 var_buffer_add32( &buffer, i_data + MMS_CMD_HEADERSIZE - 16 );
1387 var_buffer_add32( &buffer, 0x20534d4d ); /* protocol "MMS " */
1388 var_buffer_add32( &buffer, i_data_by8 + 4 );
1389 var_buffer_add32( &buffer, p_access->i_seq_num ); p_access->i_seq_num++;
1390 var_buffer_add64( &buffer, 0 );
1391 var_buffer_add32( &buffer, i_data_by8 + 2 );
1392 var_buffer_add32( &buffer, 0x00030000 | i_command ); /* dir | command */
1393 var_buffer_add32( &buffer, i_prefix1 ); /* command specific */
1394 var_buffer_add32( &buffer, i_prefix2 ); /* command specific */
1396 /* specific command data */
1397 if( p_data && i_data > 0 )
1399 var_buffer_addmemory( &buffer, p_data, i_data );
1403 if( send( p_access->socket_tcp.i_handle,
1408 msg_Err( p_input, "failed to send command" );
1412 var_buffer_free( &buffer );
1416 static int NetFillBuffer( input_thread_t *p_input )
1421 access_t *p_access = (access_t*)p_input->p_access_data;
1422 struct timeval timeout;
1426 /* FIXME when using udp */
1427 ssize_t i_tcp, i_udp;
1428 ssize_t i_tcp_read, i_udp_read;
1431 /* Initialize file descriptor set */
1434 i_tcp = MMS_BUFFER_SIZE/2 - p_access->i_buffer_tcp;
1436 if( p_access->i_proto == MMS_PROTO_UDP )
1438 i_udp = MMS_BUFFER_SIZE/2 - p_access->i_buffer_udp;
1442 i_udp = 0; /* there isn't udp socket */
1448 FD_SET( p_access->socket_tcp.i_handle, &fds );
1449 i_handle_max = __MAX( i_handle_max, p_access->socket_tcp.i_handle );
1453 FD_SET( p_access->socket_udp.i_handle, &fds );
1454 i_handle_max = __MAX( i_handle_max, p_access->socket_udp.i_handle );
1457 if( i_handle_max == 0 )
1459 msg_Warn( p_input, "nothing to read %d:%d", i_tcp, i_udp );
1464 // msg_Warn( p_input, "ask for tcp:%d udp:%d", i_tcp, i_udp );
1467 /* We'll wait 0.5 second if nothing happens */
1469 timeout.tv_usec = 500000;
1471 /* Find if some data is available */
1472 while( (i_ret = select( i_handle_max + 1, &fds,
1473 NULL, NULL, &timeout )) == 0
1474 || (i_ret < 0 && errno == EINTR) )
1476 if( p_input->b_die || p_input->b_error )
1484 msg_Err( p_input, "network select error (%s)", strerror(errno) );
1488 if( i_tcp > 0 && FD_ISSET( p_access->socket_tcp.i_handle, &fds ) )
1491 recv( p_access->socket_tcp.i_handle,
1492 p_access->buffer_tcp + p_access->i_buffer_tcp,
1493 i_tcp + MMS_BUFFER_SIZE/2, 0 );
1500 if( i_udp > 0 && FD_ISSET( p_access->socket_udp.i_handle, &fds ) )
1502 i_udp_read = recv( p_access->socket_udp.i_handle,
1503 p_access->buffer_udp + p_access->i_buffer_udp,
1504 i_udp + MMS_BUFFER_SIZE/2, 0 );
1512 if( p_access->i_proto == MMS_PROTO_UDP )
1515 "filling buffer TCP:%d+%d UDP:%d+%d",
1516 p_access->i_buffer_tcp,
1518 p_access->i_buffer_udp,
1524 "filling buffer TCP:%d+%d",
1525 p_access->i_buffer_tcp,
1529 if( i_tcp_read > 0 )
1531 p_access->i_buffer_tcp += i_tcp_read;
1533 if( i_udp_read > 0 )
1535 p_access->i_buffer_udp += i_udp_read;
1538 return( i_tcp_read + i_udp_read);
1542 static int mms_ParseCommand( input_thread_t *p_input,
1547 #define GET32( i_pos ) \
1548 ( p_access->p_cmd[i_pos] + ( p_access->p_cmd[i_pos +1] << 8 ) + \
1549 ( p_access->p_cmd[i_pos + 2] << 16 ) + \
1550 ( p_access->p_cmd[i_pos + 3] << 24 ) )
1552 access_t *p_access = (access_t*)p_input->p_access_data;
1556 if( p_access->p_cmd )
1558 free( p_access->p_cmd );
1560 p_access->i_cmd = i_data;
1561 p_access->p_cmd = malloc( i_data );
1562 memcpy( p_access->p_cmd, p_data, i_data );
1564 *pi_used = i_data; /* by default */
1566 if( i_data < MMS_CMD_HEADERSIZE )
1568 msg_Warn( p_input, "truncated command (header incomplete)" );
1569 p_access->i_command = 0;
1572 i_id = GetDWLE( p_data + 4 );
1573 i_length = GetDWLE( p_data + 8 ) + 16;
1575 if( i_id != 0xb00bface )
1578 "incorrect command header (0x%x)", i_id );
1579 p_access->i_command = 0;
1583 if( i_length > p_access->i_cmd )
1586 "truncated command (missing %d bytes)",
1587 i_length - i_data );
1588 p_access->i_command = 0;
1591 else if( i_length < p_access->i_cmd )
1593 p_access->i_cmd = i_length;
1594 *pi_used = i_length;
1598 "recv command start_sequence:0x%8.8x command_id:0x%8.8x length:%d len8:%d sequence 0x%8.8x len8_II:%d dir_comm:0x%8.8x",
1602 /* 12: protocol type "MMS " */
1605 /* 24: unknown (0) */
1606 /* 28: unknown (0) */
1612 p_access->i_command = GET32( 36 ) & 0xffff;
1614 return( MMS_PACKET_CMD );
1617 static int mms_ParsePacket( input_thread_t *p_input,
1618 uint8_t *p_data, size_t i_data,
1621 access_t *p_access = (access_t*)p_input->p_access_data;
1622 int i_packet_seq_num;
1623 size_t i_packet_length;
1624 uint32_t i_packet_id;
1629 *pi_used = i_data; /* default */
1632 msg_Warn( p_input, "truncated packet (header incomplete)" );
1636 i_packet_id = p_data[4];
1637 i_packet_seq_num = GetDWLE( p_data );
1638 i_packet_length = GetWLE( p_data + 6 );
1640 //msg_Warn( p_input, "------->i_packet_length=%d, i_data=%d", i_packet_length, i_data );
1642 if( i_packet_length > i_data || i_packet_length <= 8)
1645 "truncated packet (missing %d bytes)",
1646 i_packet_length - i_data );
1650 else if( i_packet_length < i_data )
1652 *pi_used = i_packet_length;
1655 if( i_packet_id == 0xff )
1658 "receive MMS UDP pair timing" );
1659 return( MMS_PACKET_UDP_TIMING );
1662 if( i_packet_id != p_access->i_header_packet_id_type &&
1663 i_packet_id != p_access->i_media_packet_id_type )
1665 msg_Warn( p_input, "incorrect Packet Id Type (0x%x)", i_packet_id );
1669 /* we now have a media or a header packet */
1670 p_packet = malloc( i_packet_length - 8 ); // don't bother with preheader
1671 memcpy( p_packet, p_data + 8, i_packet_length - 8 );
1673 if( i_packet_seq_num != p_access->i_packet_seq_num )
1675 /* FIXME for udp could be just wrong order ? */
1677 "detected packet lost (%d != %d)",
1679 p_access->i_packet_seq_num );
1680 p_access->i_packet_seq_num = i_packet_seq_num;
1682 p_access->i_packet_seq_num++;
1684 if( i_packet_id == p_access->i_header_packet_id_type )
1686 if( p_access->p_header )
1688 p_access->p_header = realloc( p_access->p_header,
1689 p_access->i_header + i_packet_length - 8 );
1690 memcpy( &p_access->p_header[p_access->i_header],
1692 i_packet_length - 8 );
1693 p_access->i_header += i_packet_length - 8;
1699 p_access->p_header = p_packet;
1700 p_access->i_header = i_packet_length - 8;
1702 /* msg_Dbg( p_input,
1703 "receive header packet (%d bytes)",
1704 i_packet_length - 8 ); */
1706 return( MMS_PACKET_HEADER );
1710 FREE( p_access->p_media );
1711 p_access->p_media = p_packet;
1712 p_access->i_media = i_packet_length - 8;
1713 p_access->i_media_used = 0;
1714 /* msg_Dbg( p_input,
1715 "receive media packet (%d bytes)",
1716 i_packet_length - 8 ); */
1718 return( MMS_PACKET_MEDIA );
1722 static int mms_ReceivePacket( input_thread_t *p_input )
1724 access_t *p_access = (access_t*)p_input->p_access_data;
1725 int i_packet_tcp_type;
1726 int i_packet_udp_type;
1730 if( NetFillBuffer( p_input ) < 0 )
1732 msg_Warn( p_input, "cannot fill buffer" );
1736 i_packet_tcp_type = -1;
1737 i_packet_udp_type = -1;
1739 if( p_access->i_buffer_tcp > 0 )
1743 if( GetDWLE( p_access->buffer_tcp + 4 ) == 0xb00bface )
1746 mms_ParseCommand( p_input,
1747 p_access->buffer_tcp,
1748 p_access->i_buffer_tcp,
1755 mms_ParsePacket( p_input,
1756 p_access->buffer_tcp,
1757 p_access->i_buffer_tcp,
1760 if( i_used > 0 && i_used < MMS_BUFFER_SIZE )
1762 memmove( p_access->buffer_tcp,
1763 p_access->buffer_tcp + i_used,
1764 MMS_BUFFER_SIZE - i_used );
1766 p_access->i_buffer_tcp -= i_used;
1768 else if( p_access->i_buffer_udp > 0 )
1773 mms_ParsePacket( p_input,
1774 p_access->buffer_udp,
1775 p_access->i_buffer_udp,
1778 if( i_used > 0 && i_used < MMS_BUFFER_SIZE )
1780 memmove( p_access->buffer_udp,
1781 p_access->buffer_udp + i_used,
1782 MMS_BUFFER_SIZE - i_used );
1784 p_access->i_buffer_udp -= i_used;
1787 if( i_packet_tcp_type == MMS_PACKET_CMD &&
1788 p_access->i_command == 0x1b )
1790 mms_CommandSend( p_input, 0x1b, 0, 0, NULL, 0 );
1791 i_packet_tcp_type = -1;
1794 if( i_packet_tcp_type != -1 )
1796 return( i_packet_tcp_type );
1798 else if( i_packet_udp_type != -1 )
1800 return( i_packet_udp_type );
1806 static int mms_ReceiveCommand( input_thread_t *p_input )
1808 access_t *p_access = (access_t*)p_input->p_access_data;
1815 if( NetFillBuffer( p_input ) < 0 )
1817 msg_Warn( p_input, "cannot fill buffer" );
1820 if( p_access->i_buffer_tcp > 0 )
1822 i_status = mms_ParseCommand( p_input,
1823 p_access->buffer_tcp,
1824 p_access->i_buffer_tcp,
1826 if( i_used < MMS_BUFFER_SIZE )
1828 memmove( p_access->buffer_tcp,
1829 p_access->buffer_tcp + i_used,
1830 MMS_BUFFER_SIZE - i_used );
1832 p_access->i_buffer_tcp -= i_used;
1839 if( p_access->i_command == 0x1b )
1841 mms_CommandSend( p_input, 0x1b, 0, 0, NULL, 0 );
1857 #define MMS_RETRY_MAX 10
1858 #define MMS_RETRY_SLEEP 50000
1860 static int mms_CommandRead( input_thread_t *p_input, int i_command1, int i_command2 )
1862 access_t *p_access = (access_t*)p_input->p_access_data;
1866 for( i_count = 0; i_count < MMS_RETRY_MAX; )
1869 i_status = mms_ReceiveCommand( p_input );
1870 if( i_status < 0 || p_access->i_command == 0 )
1873 msleep( MMS_RETRY_SLEEP );
1875 else if( i_command1 == 0 && i_command2 == 0)
1879 else if( p_access->i_command == i_command1 || p_access->i_command == i_command2 )
1885 switch( p_access->i_command )
1888 msg_Warn( p_input, "socket closed by server" );
1889 p_access->i_eos = 1;
1892 msg_Warn( p_input, "end of media stream" );
1893 p_access->i_eos = 1;
1900 msg_Warn( p_input, "failed to receive command (abording)" );
1906 static int mms_HeaderMediaRead( input_thread_t *p_input, int i_type )
1908 access_t *p_access = (access_t*)p_input->p_access_data;
1911 for( i_count = 0; i_count < MMS_RETRY_MAX; )
1915 i_status = mms_ReceivePacket( p_input );
1920 "cannot receive header (%d/%d)", i_count, MMS_RETRY_MAX );
1921 msleep( MMS_RETRY_SLEEP );
1923 else if( i_status == i_type || i_type == MMS_PACKET_ANY )
1927 else if( i_status == MMS_PACKET_CMD )
1929 switch( p_access->i_command )
1932 msg_Warn( p_input, "socket closed by server" );
1933 p_access->i_eos = 1;
1936 msg_Warn( p_input, "end of media stream" );
1937 p_access->i_eos = 1;
1940 /* XXX not too dificult to be done EXCEPT that we
1941 * need to restart demuxer... and I don't see how we
1942 * could do that :p */
1944 "reinitialization needed --> unsupported" );
1945 p_access->i_eos = 1;
1953 "cannot receive %s (abording)",
1954 ( i_type == MMS_PACKET_HEADER ) ? "header" : "media data" );