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 *****************************************************************************/
29 #include <vlc_access.h>
30 #include "vlc_playlist.h"
31 #include "vlc_strings.h"
33 #include <vlc_network.h>
45 /*****************************************************************************
47 *****************************************************************************/
48 int E_(MMSHOpen) ( access_t * );
49 void E_(MMSHClose) ( access_t * );
51 static int Read( access_t *, uint8_t *, int );
52 static int ReadRedirect( access_t *, uint8_t *, int );
53 static int Seek( access_t *, int64_t );
54 static int Control( access_t *, int, va_list );
56 static int Describe( access_t *, char **ppsz_location );
57 static int Start( access_t *, int64_t );
58 static void Stop( access_t * );
60 static int GetPacket( access_t *, chunk_t * );
61 static void GetHeader( access_t *p_access );
63 static int Restart( access_t * );
64 static int Reset( access_t * );
66 //#define MMSH_USER_AGENT "NSPlayer/4.1.0.3856"
67 #define MMSH_USER_AGENT "NSPlayer/7.10.0.3059"
69 /****************************************************************************
70 * Open: connect to ftp server and ask for file
71 ****************************************************************************/
72 int E_(MMSHOpen)( access_t *p_access )
75 char *psz_location = NULL;
81 p_access->pf_read = Read;
82 p_access->pf_block = NULL;
83 p_access->pf_control = Control;
84 p_access->pf_seek = Seek;
85 p_access->info.i_update = 0;
86 p_access->info.i_size = 0;
87 p_access->info.i_pos = 0;
88 p_access->info.b_eof = VLC_FALSE;
89 p_access->info.i_title = 0;
90 p_access->info.i_seekpoint = 0;
91 p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) );
92 memset( p_sys, 0, sizeof( access_sys_t ) );
93 p_sys->i_proto= MMS_PROTO_HTTP;
98 p_sys->b_proxy = VLC_FALSE;
99 memset( &p_sys->proxy, 0, sizeof(p_sys->proxy) );
102 /* TODO reuse instead http-proxy from http access ? */
103 psz_proxy = var_CreateGetString( p_access, "mmsh-proxy" );
106 char *psz_http_proxy = config_GetPsz( p_access, "http-proxy" );
107 if( psz_http_proxy && *psz_http_proxy )
110 psz_proxy = psz_http_proxy;
111 var_SetString( p_access, "mmsh-proxy", psz_proxy );
115 free( psz_http_proxy );
120 p_sys->b_proxy = VLC_TRUE;
121 vlc_UrlParse( &p_sys->proxy, psz_proxy, 0 );
126 char *psz_proxy = getenv( "http_proxy" );
127 if( psz_proxy && *psz_proxy )
129 p_sys->b_proxy = VLC_TRUE;
130 vlc_UrlParse( &p_sys->proxy, psz_proxy, 0 );
138 if( p_sys->proxy.psz_host == NULL || *p_sys->proxy.psz_host == '\0' )
140 msg_Warn( p_access, "invalid proxy host" );
141 vlc_UrlClean( &p_sys->proxy );
145 if( p_sys->proxy.i_port <= 0 )
146 p_sys->proxy.i_port = 80;
147 msg_Dbg( p_access, "Using http proxy %s:%d",
148 p_sys->proxy.psz_host, p_sys->proxy.i_port );
151 /* open a tcp connection */
152 vlc_UrlParse( &p_sys->url, p_access->psz_path, 0 );
153 if( p_sys->url.psz_host == NULL || *p_sys->url.psz_host == '\0' )
155 msg_Err( p_access, "invalid host" );
156 vlc_UrlClean( &p_sys->proxy );
157 vlc_UrlClean( &p_sys->url );
161 if( p_sys->url.i_port <= 0 )
162 p_sys->url.i_port = 80;
164 if( Describe( p_access, &psz_location ) )
166 vlc_UrlClean( &p_sys->proxy );
167 vlc_UrlClean( &p_sys->url );
171 /* Handle redirection */
172 if( psz_location && *psz_location )
174 playlist_t * p_playlist = pl_Yield( p_access );
175 msg_Dbg( p_access, "redirection to %s", psz_location );
177 /** \bug we do not autodelete here */
178 playlist_Add( p_playlist, psz_location, psz_location,
179 PLAYLIST_INSERT | PLAYLIST_GO, PLAYLIST_END, VLC_TRUE,
181 vlc_object_release( p_playlist );
183 free( psz_location );
185 p_access->pf_read = ReadRedirect;
190 if( Start( p_access, 0 ) )
192 msg_Err( p_access, "cannot start stream" );
193 free( p_sys->p_header );
194 vlc_UrlClean( &p_sys->proxy );
195 vlc_UrlClean( &p_sys->url );
200 if( !p_sys->b_broadcast )
202 p_access->info.i_size = p_sys->asfh.i_file_size;
208 /*****************************************************************************
209 * Close: free unused data structures
210 *****************************************************************************/
211 void E_( MMSHClose )( access_t *p_access )
213 access_sys_t *p_sys = p_access->p_sys;
217 if( p_sys->p_header )
218 free( p_sys->p_header );
220 vlc_UrlClean( &p_sys->proxy );
221 vlc_UrlClean( &p_sys->url );
225 /*****************************************************************************
227 *****************************************************************************/
228 static int Control( access_t *p_access, int i_query, va_list args )
230 access_sys_t *p_sys = p_access->p_sys;
239 case ACCESS_CAN_SEEK:
240 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
241 *pb_bool = !p_sys->b_broadcast;
244 case ACCESS_CAN_FASTSEEK:
245 case ACCESS_CAN_PAUSE:
246 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
247 *pb_bool = VLC_FALSE;
250 case ACCESS_CAN_CONTROL_PACE:
251 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
253 #if 0 /* Disable for now until we have a clock synchro algo
254 * which works with something else than MPEG over UDP */
255 *pb_bool = VLC_FALSE;
262 pi_int = (int*)va_arg( args, int * );
263 *pi_int = 3 * p_sys->asfh.i_min_data_packet_size;
266 case ACCESS_GET_PTS_DELAY:
267 pi_64 = (int64_t*)va_arg( args, int64_t * );
268 *pi_64 = (int64_t)var_GetInteger( p_access, "mms-caching" ) * I64C(1000);
271 case ACCESS_GET_PRIVATE_ID_STATE:
272 i_int = (int)va_arg( args, int );
273 pb_bool = (vlc_bool_t *)va_arg( args, vlc_bool_t * );
275 if( i_int < 0 || i_int > 127 )
277 *pb_bool = p_sys->asfh.stream[i_int].i_selected ? VLC_TRUE : VLC_FALSE;
281 case ACCESS_SET_PAUSE_STATE:
282 case ACCESS_GET_TITLE_INFO:
283 case ACCESS_SET_TITLE:
284 case ACCESS_SET_SEEKPOINT:
285 case ACCESS_SET_PRIVATE_ID_STATE:
286 case ACCESS_GET_CONTENT_TYPE:
290 msg_Warn( p_access, "unimplemented query in control" );
297 /*****************************************************************************
298 * Seek: try to go at the right place
299 *****************************************************************************/
300 static int Seek( access_t *p_access, int64_t i_pos )
302 access_sys_t *p_sys = p_access->p_sys;
307 msg_Dbg( p_access, "seeking to "I64Fd, i_pos );
309 i_packet = ( i_pos - p_sys->i_header ) / p_sys->asfh.i_min_data_packet_size;
310 i_offset = ( i_pos - p_sys->i_header ) % p_sys->asfh.i_min_data_packet_size;
313 Start( p_access, i_packet * p_sys->asfh.i_min_data_packet_size );
315 while( !p_access->b_die )
317 if( GetPacket( p_access, &ck ) )
321 if( ck.i_type != 0x4824 )
324 msg_Warn( p_access, "skipping header" );
327 p_access->info.i_pos = i_pos;
328 p_access->info.b_eof = VLC_FALSE;
329 p_sys->i_packet_used += i_offset;
334 /*****************************************************************************
336 *****************************************************************************/
337 static int ReadRedirect( access_t *p_access, uint8_t *p, int i_len )
342 /*****************************************************************************
344 *****************************************************************************/
345 static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
347 access_sys_t *p_sys = p_access->p_sys;
351 if( p_access->info.b_eof )
354 while( i_data < (size_t) i_len )
356 if( p_access->info.i_pos < p_sys->i_start + p_sys->i_header )
358 int i_offset = p_access->info.i_pos - p_sys->i_start;
359 i_copy = __MIN( p_sys->i_header - i_offset, (int)((size_t)i_len - i_data) );
360 memcpy( &p_buffer[i_data], &p_sys->p_header[i_offset], i_copy );
363 p_access->info.i_pos += i_copy;
365 else if( p_sys->i_packet_used < p_sys->i_packet_length )
367 i_copy = __MIN( p_sys->i_packet_length - p_sys->i_packet_used,
370 memcpy( &p_buffer[i_data],
371 &p_sys->p_packet[p_sys->i_packet_used],
375 p_sys->i_packet_used += i_copy;
376 p_access->info.i_pos += i_copy;
378 else if( (p_sys->i_packet_length > 0) &&
379 ((int)p_sys->i_packet_used < p_sys->asfh.i_min_data_packet_size) )
381 i_copy = __MIN( p_sys->asfh.i_min_data_packet_size - p_sys->i_packet_used,
384 memset( &p_buffer[i_data], 0, i_copy );
387 p_sys->i_packet_used += i_copy;
388 p_access->info.i_pos += i_copy;
393 if( GetPacket( p_access, &ck ) )
396 if( p_sys->b_broadcast )
398 if( ck.i_type == 0x4524 && ck.i_sequence != 0 )
399 i_ret = Restart( p_access );
400 else if( ck.i_type == 0x4324 )
401 i_ret = Reset( p_access );
405 p_access->info.b_eof = VLC_TRUE;
409 if( ck.i_type != 0x4424 )
411 p_sys->i_packet_used = 0;
412 p_sys->i_packet_length = 0;
421 static int Restart( access_t *p_access )
423 access_sys_t *p_sys = p_access->p_sys;
424 char *psz_location = NULL;
426 msg_Dbg( p_access, "Restart the stream" );
427 p_sys->i_start = p_access->info.i_pos;
430 msg_Dbg( p_access, "stoping the stream" );
434 msg_Dbg( p_access, "describe the stream" );
435 if( Describe( p_access, &psz_location ) )
437 msg_Err( p_access, "describe failed" );
441 if( Start( p_access, 0 ) )
443 msg_Err( p_access, "Start failed" );
448 static int Reset( access_t *p_access )
450 access_sys_t *p_sys = p_access->p_sys;
451 asf_header_t old_asfh = p_sys->asfh;
454 msg_Dbg( p_access, "Reset the stream" );
455 p_sys->i_start = p_access->info.i_pos;
458 p_sys->i_packet_sequence = 0;
459 p_sys->i_packet_used = 0;
460 p_sys->i_packet_length = 0;
461 p_sys->p_packet = NULL;
463 /* Get the next header FIXME memory loss ? */
464 GetHeader( p_access );
465 if( p_sys->i_header <= 0 )
468 E_( asf_HeaderParse )( &p_sys->asfh,
469 p_sys->p_header, p_sys->i_header );
470 msg_Dbg( p_access, "packet count="I64Fd" packet size=%d",
471 p_sys->asfh.i_data_packets_count,
472 p_sys->asfh.i_min_data_packet_size );
474 E_( asf_StreamSelect)( &p_sys->asfh,
475 var_CreateGetInteger( p_access, "mms-maxbitrate" ),
476 var_CreateGetInteger( p_access, "mms-all" ),
477 var_CreateGetInteger( p_access, "audio" ),
478 var_CreateGetInteger( p_access, "video" ) );
480 /* Check we have comptible asfh */
481 for( i = 1; i < 128; i++ )
483 asf_stream_t *p_old = &old_asfh.stream[i];
484 asf_stream_t *p_new = &p_sys->asfh.stream[i];
486 if( p_old->i_cat != p_new->i_cat || p_old->i_selected != p_new->i_selected )
491 msg_Warn( p_access, "incompatible asf header, restart" );
492 return Restart( p_access );
496 p_sys->i_packet_used = 0;
497 p_sys->i_packet_length = 0;
501 static int OpenConnection( access_t *p_access )
503 access_sys_t *p_sys = p_access->p_sys;
504 vlc_url_t srv = p_sys->b_proxy ? p_sys->proxy : p_sys->url;
506 if( ( p_sys->fd = net_ConnectTCP( p_access,
507 srv.psz_host, srv.i_port ) ) < 0 )
509 msg_Err( p_access, "cannot connect to %s:%d",
510 srv.psz_host, srv.i_port );
516 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
517 "GET http://%s:%d%s HTTP/1.0\r\n",
518 p_sys->url.psz_host, p_sys->url.i_port,
519 ( p_sys->url.psz_path == NULL || *p_sys->url.psz_path == '\0' ) ? "/" : p_sys->url.psz_path );
521 /* Proxy Authentication */
522 if( p_sys->proxy.psz_username && *p_sys->proxy.psz_username )
527 asprintf( &buf, "%s:%s", p_sys->proxy.psz_username,
528 p_sys->proxy.psz_password ? p_sys->proxy.psz_password : "" );
530 b64 = vlc_b64_encode( buf );
533 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
534 "Proxy-Authorization: Basic %s\r\n", b64 );
540 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
541 "GET %s HTTP/1.0\r\n"
543 ( p_sys->url.psz_path == NULL || *p_sys->url.psz_path == '\0' ) ? "/" : p_sys->url.psz_path,
544 p_sys->url.psz_host, p_sys->url.i_port );
549 /*****************************************************************************
551 *****************************************************************************/
552 static int Describe( access_t *p_access, char **ppsz_location )
554 access_sys_t *p_sys = p_access->p_sys;
555 char *psz_location = NULL;
560 p_sys->b_broadcast = VLC_TRUE;
561 p_sys->i_request_context = 1;
562 p_sys->i_packet_sequence = 0;
563 p_sys->i_packet_used = 0;
564 p_sys->i_packet_length = 0;
565 p_sys->p_packet = NULL;
566 E_( GenerateGuid )( &p_sys->guid );
568 if( OpenConnection( p_access ) )
571 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
573 "User-Agent: "MMSH_USER_AGENT"\r\n"
574 "Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=0:0,request-context=%d,max-duration=0\r\n"
575 "Pragma: xClientGUID={"GUID_FMT"}\r\n"
576 "Connection: Close\r\n",
577 p_sys->i_request_context++,
578 GUID_PRINT( p_sys->guid ) );
580 if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, "\r\n" ) < 0 )
582 msg_Err( p_access, "failed to send request" );
586 /* Receive the http header */
587 if( ( psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL ) ) == NULL )
589 msg_Err( p_access, "failed to read answer" );
592 if( strncmp( psz, "HTTP/1.", 7 ) )
594 msg_Err( p_access, "invalid HTTP reply '%s'", psz );
598 i_code = atoi( &psz[9] );
601 msg_Err( p_access, "error: %s", psz );
606 msg_Dbg( p_access, "HTTP reply '%s'", psz );
610 char *psz = net_Gets( p_access, p_sys->fd, NULL );
615 msg_Err( p_access, "failed to read answer" );
625 if( ( p = strchr( psz, ':' ) ) == NULL )
627 msg_Err( p_access, "malformed header line: %s", psz );
632 while( *p == ' ' ) p++;
634 /* FIXME FIXME test Content-Type to see if it's a plain stream or an
636 if( !strcasecmp( psz, "Pragma" ) )
638 if( strstr( p, "features" ) )
640 /* FIXME, it is a bit badly done here ..... */
641 if( strstr( p, "broadcast" ) )
643 msg_Dbg( p_access, "stream type = broadcast" );
644 p_sys->b_broadcast = VLC_TRUE;
646 else if( strstr( p, "seekable" ) )
648 msg_Dbg( p_access, "stream type = seekable" );
649 p_sys->b_broadcast = VLC_FALSE;
653 msg_Warn( p_access, "unknow stream types (%s)", p );
654 p_sys->b_broadcast = VLC_FALSE;
658 else if( !strcasecmp( psz, "Location" ) )
660 psz_location = strdup( p );
666 /* Handle the redirection */
667 if( ( i_code == 301 || i_code == 302 ||
668 i_code == 303 || i_code == 307 ) &&
669 psz_location && *psz_location )
671 msg_Dbg( p_access, "redirection to %s", psz_location );
672 net_Close( p_sys->fd ); p_sys->fd = -1;
674 *ppsz_location = psz_location;
678 /* Read the asf header */
679 GetHeader( p_access );
680 if( p_sys->i_header <= 0 )
682 msg_Err( p_access, "header size == 0" );
685 /* close this connection */
686 net_Close( p_sys->fd ); p_sys->fd = -1;
688 /* *** parse header and get stream and their id *** */
689 /* get all streams properties,
691 * TODO : stream bitrates properties(optional)
692 * and bitrate mutual exclusion(optional) */
693 E_( asf_HeaderParse )( &p_sys->asfh,
694 p_sys->p_header, p_sys->i_header );
695 msg_Dbg( p_access, "packet count="I64Fd" packet size=%d",
696 p_sys->asfh.i_data_packets_count,
697 p_sys->asfh.i_min_data_packet_size );
699 E_( asf_StreamSelect)( &p_sys->asfh,
700 var_CreateGetInteger( p_access, "mms-maxbitrate" ),
701 var_CreateGetInteger( p_access, "mms-all" ),
702 var_CreateGetInteger( p_access, "audio" ),
703 var_CreateGetInteger( p_access, "video" ) );
709 net_Close( p_sys->fd );
715 static void GetHeader( access_t *p_access )
717 access_sys_t *p_sys = p_access->p_sys;
719 /* Read the asf header */
721 if( p_sys->p_header )
722 free( p_sys->p_header );
723 p_sys->p_header = NULL;
727 if( GetPacket( p_access, &ck ) || ck.i_type != 0x4824 )
732 p_sys->i_header += ck.i_data;
733 p_sys->p_header = realloc( p_sys->p_header, p_sys->i_header );
734 memcpy( &p_sys->p_header[p_sys->i_header - ck.i_data],
735 ck.p_data, ck.i_data );
738 msg_Dbg( p_access, "complete header size=%d", p_sys->i_header );
742 /*****************************************************************************
744 *****************************************************************************/
745 static int Start( access_t *p_access, off_t i_pos )
747 access_sys_t *p_sys = p_access->p_sys;
749 int i_streams_selected = 0;
753 msg_Dbg( p_access, "starting stream" );
755 for( i = 1; i < 128; i++ )
757 if( p_sys->asfh.stream[i].i_cat == ASF_STREAM_UNKNOWN )
760 if( p_sys->asfh.stream[i].i_selected )
761 i_streams_selected++;
763 if( i_streams_selected <= 0 )
765 msg_Err( p_access, "no stream selected" );
769 if( OpenConnection( p_access ) )
772 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
774 "User-Agent: "MMSH_USER_AGENT"\r\n" );
775 if( p_sys->b_broadcast )
777 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
778 "Pragma: no-cache,rate=1.000000,request-context=%d\r\n",
779 p_sys->i_request_context++ );
783 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
784 "Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=%u:%u,request-context=%d,max-duration=0\r\n",
785 (uint32_t)((i_pos >> 32)&0xffffffff),
786 (uint32_t)(i_pos&0xffffffff),
787 p_sys->i_request_context++ );
789 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
790 "Pragma: xPlayStrm=1\r\n"
791 "Pragma: xClientGUID={"GUID_FMT"}\r\n"
792 "Pragma: stream-switch-count=%d\r\n"
793 "Pragma: stream-switch-entry=",
794 GUID_PRINT( p_sys->guid ),
797 for( i = 1; i < 128; i++ )
799 if( p_sys->asfh.stream[i].i_cat != ASF_STREAM_UNKNOWN )
802 if( p_sys->asfh.stream[i].i_selected )
807 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
808 "ffff:%d:%d ", i, i_select );
811 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, "\r\n" );
812 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
813 "Connection: Close\r\n" );
815 if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, "\r\n" ) < 0 )
817 msg_Err( p_access, "failed to send request" );
821 if( ( psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL ) ) == NULL )
823 msg_Err( p_access, "cannot read data" );
826 if( atoi( &psz[9] ) >= 400 )
828 msg_Err( p_access, "error: %s", psz );
832 msg_Dbg( p_access, "HTTP reply '%s'", psz );
835 /* FIXME check HTTP code */
838 char *psz = net_Gets( p_access, p_sys->fd, NULL );
841 msg_Err( p_access, "cannot read data" );
849 msg_Dbg( p_access, "%s", psz );
853 p_sys->i_packet_used = 0;
854 p_sys->i_packet_length = 0;
859 /*****************************************************************************
861 *****************************************************************************/
862 static void Stop( access_t *p_access )
864 access_sys_t *p_sys = p_access->p_sys;
866 msg_Dbg( p_access, "closing stream" );
869 net_Close( p_sys->fd );
874 /*****************************************************************************
876 *****************************************************************************/
877 static int GetPacket( access_t * p_access, chunk_t *p_ck )
879 access_sys_t *p_sys = p_access->p_sys;
883 memset( p_ck, 0, sizeof( chunk_t ) );
885 /* Read the chunk header */
886 /* Some headers are short, like 0x4324. Reading 12 bytes will cause us
887 * to lose synchronization with the stream. Just read to the length
888 * (4 bytes), decode and then read up to 8 additional bytes to get the
891 if( net_Read( p_access, p_sys->fd, NULL, p_sys->buffer, 4, VLC_TRUE ) < 4 )
894 p_ck->i_type = GetWLE( p_sys->buffer);
895 p_ck->i_size = GetWLE( p_sys->buffer + 2);
897 restsize = p_ck->i_size;
901 if( net_Read( p_access, p_sys->fd, NULL, p_sys->buffer + 4, restsize, VLC_TRUE ) < restsize )
903 msg_Err( p_access, "cannot read data" );
906 p_ck->i_sequence = GetDWLE( p_sys->buffer + 4);
907 p_ck->i_unknown = GetWLE( p_sys->buffer + 8);
909 /* Set i_size2 to 8 if this header was short, since a real value won't be
910 * present in the buffer. Using 8 avoid reading additional data for the
916 p_ck->i_size2 = GetWLE( p_sys->buffer + 10);
918 p_ck->p_data = p_sys->buffer + 12;
919 p_ck->i_data = p_ck->i_size2 - 8;
921 if( p_ck->i_type == 0x4524 ) // Transfer complete
923 if( p_ck->i_sequence == 0 )
925 msg_Warn( p_access, "EOF" );
930 msg_Warn( p_access, "next stream following" );
934 else if( p_ck->i_type == 0x4324 )
936 /* 0x4324 is CHUNK_TYPE_RESET: a new stream will follow with a sequence of 0 */
937 msg_Warn( p_access, "next stream following (reset) seq=%d", p_ck->i_sequence );
940 else if( (p_ck->i_type != 0x4824) && (p_ck->i_type != 0x4424) )
942 msg_Err( p_access, "invalid chunk FATAL (0x%x)", p_ck->i_type );
946 if( (p_ck->i_data > 0) &&
947 (net_Read( p_access, p_sys->fd, NULL, &p_sys->buffer[12],
948 p_ck->i_data, VLC_TRUE ) < p_ck->i_data) )
950 msg_Err( p_access, "cannot read data" );
955 if( (p_sys->i_packet_sequence != 0) &&
956 (p_ck->i_sequence != p_sys->i_packet_sequence) )
958 msg_Warn( p_access, "packet lost ? (%d != %d)", p_ck->i_sequence, p_sys->i_packet_sequence );
962 p_sys->i_packet_sequence = p_ck->i_sequence + 1;
963 p_sys->i_packet_used = 0;
964 p_sys->i_packet_length = p_ck->i_data;
965 p_sys->p_packet = p_ck->p_data;