1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
33 #include <vlc_access.h>
34 #include "vlc_playlist.h"
35 #include "vlc_strings.h"
37 #include <vlc_network.h>
49 /*****************************************************************************
51 *****************************************************************************/
52 int E_(MMSHOpen) ( access_t * );
53 void E_(MMSHClose) ( access_t * );
55 static ssize_t Read( access_t *, uint8_t *, size_t );
56 static ssize_t ReadRedirect( access_t *, uint8_t *, size_t );
57 static int Seek( access_t *, int64_t );
58 static int Control( access_t *, int, va_list );
60 static int Describe( access_t *, char **ppsz_location );
61 static int Start( access_t *, int64_t );
62 static void Stop( access_t * );
64 static int GetPacket( access_t *, chunk_t * );
65 static void GetHeader( access_t *p_access );
67 static int Restart( access_t * );
68 static int Reset( access_t * );
70 //#define MMSH_USER_AGENT "NSPlayer/4.1.0.3856"
71 #define MMSH_USER_AGENT "NSPlayer/7.10.0.3059"
73 /****************************************************************************
74 * Open: connect to ftp server and ask for file
75 ****************************************************************************/
76 int E_(MMSHOpen)( access_t *p_access )
79 char *psz_location = NULL;
85 p_access->pf_read = Read;
86 p_access->pf_block = NULL;
87 p_access->pf_control = Control;
88 p_access->pf_seek = Seek;
89 p_access->info.i_update = 0;
90 p_access->info.i_size = 0;
91 p_access->info.i_pos = 0;
92 p_access->info.b_eof = VLC_FALSE;
93 p_access->info.i_title = 0;
94 p_access->info.i_seekpoint = 0;
96 p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) );
100 memset( p_sys, 0, sizeof( access_sys_t ) );
101 p_sys->i_proto= MMS_PROTO_HTTP;
106 p_sys->b_proxy = VLC_FALSE;
107 memset( &p_sys->proxy, 0, sizeof(p_sys->proxy) );
110 /* TODO reuse instead http-proxy from http access ? */
111 psz_proxy = var_CreateGetString( p_access, "mmsh-proxy" );
114 char *psz_http_proxy = config_GetPsz( p_access, "http-proxy" );
115 if( psz_http_proxy && *psz_http_proxy )
118 psz_proxy = psz_http_proxy;
119 var_SetString( p_access, "mmsh-proxy", psz_proxy );
123 free( psz_http_proxy );
129 p_sys->b_proxy = VLC_TRUE;
130 vlc_UrlParse( &p_sys->proxy, psz_proxy, 0 );
135 char *psz_proxy = getenv( "http_proxy" );
136 if( psz_proxy && *psz_proxy )
138 p_sys->b_proxy = VLC_TRUE;
139 vlc_UrlParse( &p_sys->proxy, psz_proxy, 0 );
147 if( ( p_sys->proxy.psz_host == NULL ) ||
148 ( *p_sys->proxy.psz_host == '\0' ) )
150 msg_Warn( p_access, "invalid proxy host" );
151 vlc_UrlClean( &p_sys->proxy );
156 if( p_sys->proxy.i_port <= 0 )
157 p_sys->proxy.i_port = 80;
158 msg_Dbg( p_access, "Using http proxy %s:%d",
159 p_sys->proxy.psz_host, p_sys->proxy.i_port );
162 /* open a tcp connection */
163 vlc_UrlParse( &p_sys->url, p_access->psz_path, 0 );
164 if( ( p_sys->url.psz_host == NULL ) ||
165 ( *p_sys->url.psz_host == '\0' ) )
167 msg_Err( p_access, "invalid host" );
168 vlc_UrlClean( &p_sys->proxy );
169 vlc_UrlClean( &p_sys->url );
173 if( p_sys->url.i_port <= 0 )
174 p_sys->url.i_port = 80;
176 if( Describe( p_access, &psz_location ) )
178 vlc_UrlClean( &p_sys->proxy );
179 vlc_UrlClean( &p_sys->url );
183 /* Handle redirection */
184 if( psz_location && *psz_location )
186 playlist_t * p_playlist = pl_Yield( p_access );
187 msg_Dbg( p_access, "redirection to %s", psz_location );
189 /** \bug we do not autodelete here */
190 playlist_Add( p_playlist, psz_location, psz_location,
191 PLAYLIST_INSERT | PLAYLIST_GO, PLAYLIST_END, VLC_TRUE,
193 vlc_object_release( p_playlist );
195 free( psz_location );
197 p_access->pf_read = ReadRedirect;
202 if( Start( p_access, 0 ) )
204 msg_Err( p_access, "cannot start stream" );
205 free( p_sys->p_header );
206 vlc_UrlClean( &p_sys->proxy );
207 vlc_UrlClean( &p_sys->url );
212 if( !p_sys->b_broadcast )
214 p_access->info.i_size = p_sys->asfh.i_file_size;
220 /*****************************************************************************
221 * Close: free unused data structures
222 *****************************************************************************/
223 void E_( MMSHClose )( access_t *p_access )
225 access_sys_t *p_sys = p_access->p_sys;
229 if( p_sys->p_header )
230 free( p_sys->p_header );
232 vlc_UrlClean( &p_sys->proxy );
233 vlc_UrlClean( &p_sys->url );
237 /*****************************************************************************
239 *****************************************************************************/
240 static int Control( access_t *p_access, int i_query, va_list args )
242 access_sys_t *p_sys = p_access->p_sys;
251 case ACCESS_CAN_SEEK:
252 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
253 *pb_bool = !p_sys->b_broadcast;
256 case ACCESS_CAN_FASTSEEK:
257 case ACCESS_CAN_PAUSE:
258 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
259 *pb_bool = VLC_FALSE;
262 case ACCESS_CAN_CONTROL_PACE:
263 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
269 pi_int = (int*)va_arg( args, int * );
270 *pi_int = 3 * p_sys->asfh.i_min_data_packet_size;
273 case ACCESS_GET_PTS_DELAY:
274 pi_64 = (int64_t*)va_arg( args, int64_t * );
275 *pi_64 = (int64_t)var_GetInteger( p_access, "mms-caching" ) * I64C(1000);
278 case ACCESS_GET_PRIVATE_ID_STATE:
279 i_int = (int)va_arg( args, int );
280 pb_bool = (vlc_bool_t *)va_arg( args, vlc_bool_t * );
282 if( (i_int < 0) || (i_int > 127) )
284 *pb_bool = p_sys->asfh.stream[i_int].i_selected ? VLC_TRUE : VLC_FALSE;
288 case ACCESS_SET_PAUSE_STATE:
289 case ACCESS_GET_TITLE_INFO:
290 case ACCESS_SET_TITLE:
291 case ACCESS_SET_SEEKPOINT:
292 case ACCESS_SET_PRIVATE_ID_STATE:
293 case ACCESS_GET_CONTENT_TYPE:
297 msg_Warn( p_access, "unimplemented query in control" );
304 /*****************************************************************************
305 * Seek: try to go at the right place
306 *****************************************************************************/
307 static int Seek( access_t *p_access, int64_t i_pos )
309 access_sys_t *p_sys = p_access->p_sys;
314 msg_Dbg( p_access, "seeking to "I64Fd, i_pos );
316 i_packet = ( i_pos - p_sys->i_header ) / p_sys->asfh.i_min_data_packet_size;
317 i_offset = ( i_pos - p_sys->i_header ) % p_sys->asfh.i_min_data_packet_size;
320 Start( p_access, i_packet * p_sys->asfh.i_min_data_packet_size );
322 while( !p_access->b_die )
324 msg_Warn( p_access, "GetPacket 1" );
325 if( GetPacket( p_access, &ck ) )
329 if( ck.i_type != 0x4824 )
332 msg_Warn( p_access, "skipping header" );
335 p_access->info.i_pos = i_pos;
336 p_access->info.b_eof = VLC_FALSE;
337 p_sys->i_packet_used += i_offset;
342 /*****************************************************************************
344 *****************************************************************************/
345 static ssize_t ReadRedirect( access_t *p_access, uint8_t *p, size_t i_len )
350 /*****************************************************************************
352 *****************************************************************************/
353 static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
355 access_sys_t *p_sys = p_access->p_sys;
359 if( p_access->info.b_eof )
362 while( i_data < (size_t) i_len )
364 if( p_access->info.i_pos < (p_sys->i_start + p_sys->i_header) )
366 int i_offset = p_access->info.i_pos - p_sys->i_start;
367 i_copy = __MIN( p_sys->i_header - i_offset,
368 (int)((size_t)i_len - i_data) );
369 memcpy( &p_buffer[i_data], &p_sys->p_header[i_offset], i_copy );
372 p_access->info.i_pos += i_copy;
374 else if( p_sys->i_packet_used < p_sys->i_packet_length )
376 i_copy = __MIN( p_sys->i_packet_length - p_sys->i_packet_used,
378 memcpy( &p_buffer[i_data],
379 &p_sys->p_packet[p_sys->i_packet_used],
383 p_sys->i_packet_used += i_copy;
384 p_access->info.i_pos += i_copy;
386 else if( (p_sys->i_packet_length > 0) &&
387 ((int)p_sys->i_packet_used < p_sys->asfh.i_min_data_packet_size) )
389 i_copy = __MIN( p_sys->asfh.i_min_data_packet_size - p_sys->i_packet_used,
391 memset( &p_buffer[i_data], 0, i_copy );
394 p_sys->i_packet_used += i_copy;
395 p_access->info.i_pos += i_copy;
400 msg_Warn( p_access, "GetPacket 2" );
401 if( GetPacket( p_access, &ck ) )
404 if( p_sys->b_broadcast )
406 if( (ck.i_type == 0x4524) && (ck.i_sequence != 0) )
407 i_ret = Restart( p_access );
408 else if( ck.i_type == 0x4324 )
409 i_ret = Reset( p_access );
413 p_access->info.b_eof = VLC_TRUE;
417 if( ck.i_type != 0x4424 )
419 p_sys->i_packet_used = 0;
420 p_sys->i_packet_length = 0;
429 static int Restart( access_t *p_access )
431 access_sys_t *p_sys = p_access->p_sys;
432 char *psz_location = NULL;
434 msg_Dbg( p_access, "Restart the stream" );
435 p_sys->i_start = p_access->info.i_pos;
438 msg_Dbg( p_access, "stoping the stream" );
442 msg_Dbg( p_access, "describe the stream" );
443 if( Describe( p_access, &psz_location ) )
445 msg_Err( p_access, "describe failed" );
449 if( Start( p_access, 0 ) )
451 msg_Err( p_access, "Start failed" );
456 static int Reset( access_t *p_access )
458 access_sys_t *p_sys = p_access->p_sys;
459 asf_header_t old_asfh = p_sys->asfh;
462 msg_Dbg( p_access, "Reset the stream" );
463 p_sys->i_start = p_access->info.i_pos;
466 p_sys->i_packet_sequence = 0;
467 p_sys->i_packet_used = 0;
468 p_sys->i_packet_length = 0;
469 p_sys->p_packet = NULL;
471 /* Get the next header FIXME memory loss ? */
472 GetHeader( p_access );
473 if( p_sys->i_header <= 0 )
476 E_( asf_HeaderParse )( &p_sys->asfh,
477 p_sys->p_header, p_sys->i_header );
478 msg_Dbg( p_access, "packet count="I64Fd" packet size=%d",
479 p_sys->asfh.i_data_packets_count,
480 p_sys->asfh.i_min_data_packet_size );
482 E_( asf_StreamSelect)( &p_sys->asfh,
483 var_CreateGetInteger( p_access, "mms-maxbitrate" ),
484 var_CreateGetInteger( p_access, "mms-all" ),
485 var_CreateGetInteger( p_access, "audio" ),
486 var_CreateGetInteger( p_access, "video" ) );
488 /* Check we have comptible asfh */
489 for( i = 1; i < 128; i++ )
491 asf_stream_t *p_old = &old_asfh.stream[i];
492 asf_stream_t *p_new = &p_sys->asfh.stream[i];
494 if( p_old->i_cat != p_new->i_cat || p_old->i_selected != p_new->i_selected )
499 msg_Warn( p_access, "incompatible asf header, restart" );
500 return Restart( p_access );
504 p_sys->i_packet_used = 0;
505 p_sys->i_packet_length = 0;
509 static int OpenConnection( access_t *p_access )
511 access_sys_t *p_sys = p_access->p_sys;
512 vlc_url_t srv = p_sys->b_proxy ? p_sys->proxy : p_sys->url;
514 if( ( p_sys->fd = net_ConnectTCP( p_access,
515 srv.psz_host, srv.i_port ) ) < 0 )
517 msg_Err( p_access, "cannot connect to %s:%d",
518 srv.psz_host, srv.i_port );
524 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
525 "GET http://%s:%d%s HTTP/1.0\r\n",
526 p_sys->url.psz_host, p_sys->url.i_port,
527 ( (p_sys->url.psz_path == NULL) ||
528 (*p_sys->url.psz_path == '\0') ) ?
529 "/" : p_sys->url.psz_path );
531 /* Proxy Authentication */
532 if( p_sys->proxy.psz_username && *p_sys->proxy.psz_username )
537 asprintf( &buf, "%s:%s", p_sys->proxy.psz_username,
538 p_sys->proxy.psz_password ? p_sys->proxy.psz_password : "" );
540 b64 = vlc_b64_encode( buf );
543 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
544 "Proxy-Authorization: Basic %s\r\n", b64 );
550 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
551 "GET %s HTTP/1.0\r\n"
553 ( (p_sys->url.psz_path == NULL) ||
554 (*p_sys->url.psz_path == '\0') ) ?
555 "/" : p_sys->url.psz_path,
556 p_sys->url.psz_host, p_sys->url.i_port );
561 /*****************************************************************************
563 *****************************************************************************/
564 static int Describe( access_t *p_access, char **ppsz_location )
566 access_sys_t *p_sys = p_access->p_sys;
567 char *psz_location = NULL;
572 p_sys->b_broadcast = VLC_TRUE;
573 p_sys->i_request_context = 1;
574 p_sys->i_packet_sequence = 0;
575 p_sys->i_packet_used = 0;
576 p_sys->i_packet_length = 0;
577 p_sys->p_packet = NULL;
578 E_( GenerateGuid )( &p_sys->guid );
580 if( OpenConnection( p_access ) )
583 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
585 "User-Agent: "MMSH_USER_AGENT"\r\n"
586 "Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=0:0,request-context=%d,max-duration=0\r\n"
587 "Pragma: xClientGUID={"GUID_FMT"}\r\n"
588 "Connection: Close\r\n",
589 p_sys->i_request_context++,
590 GUID_PRINT( p_sys->guid ) );
592 if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, "\r\n" ) < 0 )
594 msg_Err( p_access, "failed to send request" );
598 /* Receive the http header */
599 if( ( psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL ) ) == NULL )
601 msg_Err( p_access, "failed to read answer" );
605 if( strncmp( psz, "HTTP/1.", 7 ) )
607 msg_Err( p_access, "invalid HTTP reply '%s'", psz );
611 i_code = atoi( &psz[9] );
614 msg_Err( p_access, "error: %s", psz );
619 msg_Dbg( p_access, "HTTP reply '%s'", psz );
623 char *psz = net_Gets( p_access, p_sys->fd, NULL );
628 msg_Err( p_access, "failed to read answer" );
638 if( ( p = strchr( psz, ':' ) ) == NULL )
640 msg_Err( p_access, "malformed header line: %s", psz );
645 while( *p == ' ' ) p++;
647 /* FIXME FIXME test Content-Type to see if it's a plain stream or an
649 if( !strcasecmp( psz, "Pragma" ) )
651 if( strstr( p, "features" ) )
653 /* FIXME, it is a bit badly done here ..... */
654 if( strstr( p, "broadcast" ) )
656 msg_Dbg( p_access, "stream type = broadcast" );
657 p_sys->b_broadcast = VLC_TRUE;
659 else if( strstr( p, "seekable" ) )
661 msg_Dbg( p_access, "stream type = seekable" );
662 p_sys->b_broadcast = VLC_FALSE;
666 msg_Warn( p_access, "unknow stream types (%s)", p );
667 p_sys->b_broadcast = VLC_FALSE;
671 else if( !strcasecmp( psz, "Location" ) )
673 psz_location = strdup( p );
679 /* Handle the redirection */
680 if( ( (i_code == 301) || (i_code == 302) ||
681 (i_code == 303) || (i_code == 307) ) &&
682 psz_location && *psz_location )
684 msg_Dbg( p_access, "redirection to %s", psz_location );
685 net_Close( p_sys->fd ); p_sys->fd = -1;
687 *ppsz_location = psz_location;
691 /* Read the asf header */
692 GetHeader( p_access );
693 if( p_sys->i_header <= 0 )
695 msg_Err( p_access, "header size == 0" );
698 /* close this connection */
699 net_Close( p_sys->fd );
702 /* *** parse header and get stream and their id *** */
703 /* get all streams properties,
705 * TODO : stream bitrates properties(optional)
706 * and bitrate mutual exclusion(optional) */
707 E_( asf_HeaderParse )( &p_sys->asfh,
708 p_sys->p_header, p_sys->i_header );
709 msg_Dbg( p_access, "packet count="I64Fd" packet size=%d",
710 p_sys->asfh.i_data_packets_count,
711 p_sys->asfh.i_min_data_packet_size );
713 E_( asf_StreamSelect)( &p_sys->asfh,
714 var_CreateGetInteger( p_access, "mms-maxbitrate" ),
715 var_CreateGetInteger( p_access, "mms-all" ),
716 var_CreateGetInteger( p_access, "audio" ),
717 var_CreateGetInteger( p_access, "video" ) );
723 net_Close( p_sys->fd );
729 static void GetHeader( access_t *p_access )
731 access_sys_t *p_sys = p_access->p_sys;
733 /* Read the asf header */
735 if( p_sys->p_header )
736 free( p_sys->p_header );
737 p_sys->p_header = NULL;
741 if( GetPacket( p_access, &ck ) || ck.i_type != 0x4824 )
746 p_sys->i_header += ck.i_data;
747 p_sys->p_header = realloc( p_sys->p_header, p_sys->i_header );
748 memcpy( &p_sys->p_header[p_sys->i_header - ck.i_data],
749 ck.p_data, ck.i_data );
752 msg_Dbg( p_access, "complete header size=%d", p_sys->i_header );
756 /*****************************************************************************
758 ****************************************************************************/
759 static int Start( access_t *p_access, int64_t i_pos )
761 access_sys_t *p_sys = p_access->p_sys;
763 int i_streams_selected = 0;
767 msg_Dbg( p_access, "starting stream" );
769 for( i = 1; i < 128; i++ )
771 if( p_sys->asfh.stream[i].i_cat == ASF_STREAM_UNKNOWN )
774 if( p_sys->asfh.stream[i].i_selected )
775 i_streams_selected++;
777 if( i_streams_selected <= 0 )
779 msg_Err( p_access, "no stream selected" );
783 if( OpenConnection( p_access ) )
786 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
788 "User-Agent: "MMSH_USER_AGENT"\r\n" );
789 if( p_sys->b_broadcast )
791 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
792 "Pragma: no-cache,rate=1.000000,request-context=%d\r\n",
793 p_sys->i_request_context++ );
797 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
798 "Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=%u:%u,request-context=%d,max-duration=0\r\n",
799 (uint32_t)((i_pos >> 32)&0xffffffff),
800 (uint32_t)(i_pos&0xffffffff),
801 p_sys->i_request_context++ );
803 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
804 "Pragma: xPlayStrm=1\r\n"
805 "Pragma: xClientGUID={"GUID_FMT"}\r\n"
806 "Pragma: stream-switch-count=%d\r\n"
807 "Pragma: stream-switch-entry=",
808 GUID_PRINT( p_sys->guid ),
811 for( i = 1; i < 128; i++ )
813 if( p_sys->asfh.stream[i].i_cat != ASF_STREAM_UNKNOWN )
816 if( p_sys->asfh.stream[i].i_selected )
820 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
821 "ffff:%d:%d ", i, i_select );
824 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, "\r\n" );
825 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
826 "Connection: Close\r\n" );
828 if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, "\r\n" ) < 0 )
830 msg_Err( p_access, "failed to send request" );
834 psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL );
837 msg_Err( p_access, "cannot read data 0" );
841 if( atoi( &psz[9] ) >= 400 )
843 msg_Err( p_access, "error: %s", psz );
847 msg_Dbg( p_access, "HTTP reply '%s'", psz );
850 /* FIXME check HTTP code */
853 char *psz = net_Gets( p_access, p_sys->fd, NULL );
856 msg_Err( p_access, "cannot read data 1" );
864 msg_Dbg( p_access, "%s", psz );
868 p_sys->i_packet_used = 0;
869 p_sys->i_packet_length = 0;
874 /*****************************************************************************
876 *****************************************************************************/
877 static void Stop( access_t *p_access )
879 access_sys_t *p_sys = p_access->p_sys;
881 msg_Dbg( p_access, "closing stream" );
884 net_Close( p_sys->fd );
889 /*****************************************************************************
891 *****************************************************************************/
892 static int GetPacket( access_t * p_access, chunk_t *p_ck )
894 access_sys_t *p_sys = p_access->p_sys;
898 memset( p_ck, 0, sizeof( chunk_t ) );
900 /* Read the chunk header */
901 /* Some headers are short, like 0x4324. Reading 12 bytes will cause us
902 * to lose synchronization with the stream. Just read to the length
903 * (4 bytes), decode and then read up to 8 additional bytes to get the
906 if( net_Read( p_access, p_sys->fd, NULL, p_sys->buffer, 4, VLC_TRUE ) < 4 )
908 msg_Err( p_access, "cannot read data 2" );
912 p_ck->i_type = GetWLE( p_sys->buffer);
913 p_ck->i_size = GetWLE( p_sys->buffer + 2);
915 restsize = p_ck->i_size;
919 if( net_Read( p_access, p_sys->fd, NULL, p_sys->buffer + 4, restsize, VLC_TRUE ) < restsize )
921 msg_Err( p_access, "cannot read data 3" );
924 p_ck->i_sequence = GetDWLE( p_sys->buffer + 4);
925 p_ck->i_unknown = GetWLE( p_sys->buffer + 8);
927 /* Set i_size2 to 8 if this header was short, since a real value won't be
928 * present in the buffer. Using 8 avoid reading additional data for the
934 p_ck->i_size2 = GetWLE( p_sys->buffer + 10);
936 p_ck->p_data = p_sys->buffer + 12;
937 p_ck->i_data = p_ck->i_size2 - 8;
939 if( p_ck->i_type == 0x4524 ) // Transfer complete
941 if( p_ck->i_sequence == 0 )
943 msg_Warn( p_access, "EOF" );
948 msg_Warn( p_access, "next stream following" );
952 else if( p_ck->i_type == 0x4324 )
954 /* 0x4324 is CHUNK_TYPE_RESET: a new stream will follow with a sequence of 0 */
955 msg_Warn( p_access, "next stream following (reset) seq=%d", p_ck->i_sequence );
958 else if( (p_ck->i_type != 0x4824) && (p_ck->i_type != 0x4424) )
960 msg_Err( p_access, "invalid chunk FATAL (0x%x)", p_ck->i_type );
964 if( (p_ck->i_data > 0) &&
965 (net_Read( p_access, p_sys->fd, NULL, &p_sys->buffer[12],
966 p_ck->i_data, VLC_TRUE ) < p_ck->i_data) )
968 msg_Err( p_access, "cannot read data 4" );
973 if( (p_sys->i_packet_sequence != 0) &&
974 (p_ck->i_sequence != p_sys->i_packet_sequence) )
976 msg_Warn( p_access, "packet lost ? (%d != %d)", p_ck->i_sequence, p_sys->i_packet_sequence );
980 p_sys->i_packet_sequence = p_ck->i_sequence + 1;
981 p_sys->i_packet_used = 0;
982 p_sys->i_packet_length = p_ck->i_data;
983 p_sys->p_packet = p_ck->p_data;