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;
92 p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) );
96 memset( p_sys, 0, sizeof( access_sys_t ) );
97 p_sys->i_proto= MMS_PROTO_HTTP;
102 p_sys->b_proxy = VLC_FALSE;
103 memset( &p_sys->proxy, 0, sizeof(p_sys->proxy) );
106 /* TODO reuse instead http-proxy from http access ? */
107 psz_proxy = var_CreateGetString( p_access, "mmsh-proxy" );
110 char *psz_http_proxy = config_GetPsz( p_access, "http-proxy" );
111 if( psz_http_proxy && *psz_http_proxy )
114 psz_proxy = psz_http_proxy;
115 var_SetString( p_access, "mmsh-proxy", psz_proxy );
119 free( psz_http_proxy );
125 p_sys->b_proxy = VLC_TRUE;
126 vlc_UrlParse( &p_sys->proxy, psz_proxy, 0 );
131 char *psz_proxy = getenv( "http_proxy" );
132 if( psz_proxy && *psz_proxy )
134 p_sys->b_proxy = VLC_TRUE;
135 vlc_UrlParse( &p_sys->proxy, psz_proxy, 0 );
143 if( ( p_sys->proxy.psz_host == NULL ) ||
144 ( *p_sys->proxy.psz_host == '\0' ) )
146 msg_Warn( p_access, "invalid proxy host" );
147 vlc_UrlClean( &p_sys->proxy );
152 if( p_sys->proxy.i_port <= 0 )
153 p_sys->proxy.i_port = 80;
154 msg_Dbg( p_access, "Using http proxy %s:%d",
155 p_sys->proxy.psz_host, p_sys->proxy.i_port );
158 /* open a tcp connection */
159 vlc_UrlParse( &p_sys->url, p_access->psz_path, 0 );
160 if( ( p_sys->url.psz_host == NULL ) ||
161 ( *p_sys->url.psz_host == '\0' ) )
163 msg_Err( p_access, "invalid host" );
164 vlc_UrlClean( &p_sys->proxy );
165 vlc_UrlClean( &p_sys->url );
169 if( p_sys->url.i_port <= 0 )
170 p_sys->url.i_port = 80;
172 if( Describe( p_access, &psz_location ) )
174 vlc_UrlClean( &p_sys->proxy );
175 vlc_UrlClean( &p_sys->url );
179 /* Handle redirection */
180 if( psz_location && *psz_location )
182 playlist_t * p_playlist = pl_Yield( p_access );
183 msg_Dbg( p_access, "redirection to %s", psz_location );
185 /** \bug we do not autodelete here */
186 playlist_Add( p_playlist, psz_location, psz_location,
187 PLAYLIST_INSERT | PLAYLIST_GO, PLAYLIST_END, VLC_TRUE,
189 vlc_object_release( p_playlist );
191 free( psz_location );
193 p_access->pf_read = ReadRedirect;
198 if( Start( p_access, 0 ) )
200 msg_Err( p_access, "cannot start stream" );
201 free( p_sys->p_header );
202 vlc_UrlClean( &p_sys->proxy );
203 vlc_UrlClean( &p_sys->url );
208 if( !p_sys->b_broadcast )
210 p_access->info.i_size = p_sys->asfh.i_file_size;
216 /*****************************************************************************
217 * Close: free unused data structures
218 *****************************************************************************/
219 void E_( MMSHClose )( access_t *p_access )
221 access_sys_t *p_sys = p_access->p_sys;
225 if( p_sys->p_header )
226 free( p_sys->p_header );
228 vlc_UrlClean( &p_sys->proxy );
229 vlc_UrlClean( &p_sys->url );
233 /*****************************************************************************
235 *****************************************************************************/
236 static int Control( access_t *p_access, int i_query, va_list args )
238 access_sys_t *p_sys = p_access->p_sys;
247 case ACCESS_CAN_SEEK:
248 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
249 *pb_bool = !p_sys->b_broadcast;
252 case ACCESS_CAN_FASTSEEK:
253 case ACCESS_CAN_PAUSE:
254 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
255 *pb_bool = VLC_FALSE;
258 case ACCESS_CAN_CONTROL_PACE:
259 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
265 pi_int = (int*)va_arg( args, int * );
266 *pi_int = 3 * p_sys->asfh.i_min_data_packet_size;
269 case ACCESS_GET_PTS_DELAY:
270 pi_64 = (int64_t*)va_arg( args, int64_t * );
271 *pi_64 = (int64_t)var_GetInteger( p_access, "mms-caching" ) * I64C(1000);
274 case ACCESS_GET_PRIVATE_ID_STATE:
275 i_int = (int)va_arg( args, int );
276 pb_bool = (vlc_bool_t *)va_arg( args, vlc_bool_t * );
278 if( (i_int < 0) || (i_int > 127) )
280 *pb_bool = p_sys->asfh.stream[i_int].i_selected ? VLC_TRUE : VLC_FALSE;
284 case ACCESS_SET_PAUSE_STATE:
285 case ACCESS_GET_TITLE_INFO:
286 case ACCESS_SET_TITLE:
287 case ACCESS_SET_SEEKPOINT:
288 case ACCESS_SET_PRIVATE_ID_STATE:
289 case ACCESS_GET_CONTENT_TYPE:
293 msg_Warn( p_access, "unimplemented query in control" );
300 /*****************************************************************************
301 * Seek: try to go at the right place
302 *****************************************************************************/
303 static int Seek( access_t *p_access, int64_t i_pos )
305 access_sys_t *p_sys = p_access->p_sys;
310 msg_Dbg( p_access, "seeking to "I64Fd, i_pos );
312 i_packet = ( i_pos - p_sys->i_header ) / p_sys->asfh.i_min_data_packet_size;
313 i_offset = ( i_pos - p_sys->i_header ) % p_sys->asfh.i_min_data_packet_size;
316 Start( p_access, i_packet * p_sys->asfh.i_min_data_packet_size );
318 while( !p_access->b_die )
320 msg_Warn( p_access, "GetPacket 1" );
321 if( GetPacket( p_access, &ck ) )
325 if( ck.i_type != 0x4824 )
328 msg_Warn( p_access, "skipping header" );
331 p_access->info.i_pos = i_pos;
332 p_access->info.b_eof = VLC_FALSE;
333 p_sys->i_packet_used += i_offset;
338 /*****************************************************************************
340 *****************************************************************************/
341 static int ReadRedirect( access_t *p_access, uint8_t *p, int i_len )
346 /*****************************************************************************
348 *****************************************************************************/
349 static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
351 access_sys_t *p_sys = p_access->p_sys;
355 if( p_access->info.b_eof )
358 while( i_data < (size_t) i_len )
360 if( p_access->info.i_pos < (p_sys->i_start + p_sys->i_header) )
362 int i_offset = p_access->info.i_pos - p_sys->i_start;
363 i_copy = __MIN( p_sys->i_header - i_offset,
364 (int)((size_t)i_len - i_data) );
365 memcpy( &p_buffer[i_data], &p_sys->p_header[i_offset], i_copy );
368 p_access->info.i_pos += i_copy;
370 else if( p_sys->i_packet_used < p_sys->i_packet_length )
372 i_copy = __MIN( p_sys->i_packet_length - p_sys->i_packet_used,
374 memcpy( &p_buffer[i_data],
375 &p_sys->p_packet[p_sys->i_packet_used],
379 p_sys->i_packet_used += i_copy;
380 p_access->info.i_pos += i_copy;
382 else if( (p_sys->i_packet_length > 0) &&
383 ((int)p_sys->i_packet_used < p_sys->asfh.i_min_data_packet_size) )
385 i_copy = __MIN( p_sys->asfh.i_min_data_packet_size - p_sys->i_packet_used,
387 memset( &p_buffer[i_data], 0, i_copy );
390 p_sys->i_packet_used += i_copy;
391 p_access->info.i_pos += i_copy;
396 msg_Warn( p_access, "GetPacket 2" );
397 if( GetPacket( p_access, &ck ) )
400 if( p_sys->b_broadcast )
402 if( (ck.i_type == 0x4524) && (ck.i_sequence != 0) )
403 i_ret = Restart( p_access );
404 else if( ck.i_type == 0x4324 )
405 i_ret = Reset( p_access );
409 p_access->info.b_eof = VLC_TRUE;
413 if( ck.i_type != 0x4424 )
415 p_sys->i_packet_used = 0;
416 p_sys->i_packet_length = 0;
425 static int Restart( access_t *p_access )
427 access_sys_t *p_sys = p_access->p_sys;
428 char *psz_location = NULL;
430 msg_Dbg( p_access, "Restart the stream" );
431 p_sys->i_start = p_access->info.i_pos;
434 msg_Dbg( p_access, "stoping the stream" );
438 msg_Dbg( p_access, "describe the stream" );
439 if( Describe( p_access, &psz_location ) )
441 msg_Err( p_access, "describe failed" );
445 if( Start( p_access, 0 ) )
447 msg_Err( p_access, "Start failed" );
452 static int Reset( access_t *p_access )
454 access_sys_t *p_sys = p_access->p_sys;
455 asf_header_t old_asfh = p_sys->asfh;
458 msg_Dbg( p_access, "Reset the stream" );
459 p_sys->i_start = p_access->info.i_pos;
462 p_sys->i_packet_sequence = 0;
463 p_sys->i_packet_used = 0;
464 p_sys->i_packet_length = 0;
465 p_sys->p_packet = NULL;
467 /* Get the next header FIXME memory loss ? */
468 GetHeader( p_access );
469 if( p_sys->i_header <= 0 )
472 E_( asf_HeaderParse )( &p_sys->asfh,
473 p_sys->p_header, p_sys->i_header );
474 msg_Dbg( p_access, "packet count="I64Fd" packet size=%d",
475 p_sys->asfh.i_data_packets_count,
476 p_sys->asfh.i_min_data_packet_size );
478 E_( asf_StreamSelect)( &p_sys->asfh,
479 var_CreateGetInteger( p_access, "mms-maxbitrate" ),
480 var_CreateGetInteger( p_access, "mms-all" ),
481 var_CreateGetInteger( p_access, "audio" ),
482 var_CreateGetInteger( p_access, "video" ) );
484 /* Check we have comptible asfh */
485 for( i = 1; i < 128; i++ )
487 asf_stream_t *p_old = &old_asfh.stream[i];
488 asf_stream_t *p_new = &p_sys->asfh.stream[i];
490 if( p_old->i_cat != p_new->i_cat || p_old->i_selected != p_new->i_selected )
495 msg_Warn( p_access, "incompatible asf header, restart" );
496 return Restart( p_access );
500 p_sys->i_packet_used = 0;
501 p_sys->i_packet_length = 0;
505 static int OpenConnection( access_t *p_access )
507 access_sys_t *p_sys = p_access->p_sys;
508 vlc_url_t srv = p_sys->b_proxy ? p_sys->proxy : p_sys->url;
510 if( ( p_sys->fd = net_ConnectTCP( p_access,
511 srv.psz_host, srv.i_port ) ) < 0 )
513 msg_Err( p_access, "cannot connect to %s:%d",
514 srv.psz_host, srv.i_port );
520 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
521 "GET http://%s:%d%s HTTP/1.0\r\n",
522 p_sys->url.psz_host, p_sys->url.i_port,
523 ( (p_sys->url.psz_path == NULL) ||
524 (*p_sys->url.psz_path == '\0') ) ?
525 "/" : p_sys->url.psz_path );
527 /* Proxy Authentication */
528 if( p_sys->proxy.psz_username && *p_sys->proxy.psz_username )
533 asprintf( &buf, "%s:%s", p_sys->proxy.psz_username,
534 p_sys->proxy.psz_password ? p_sys->proxy.psz_password : "" );
536 b64 = vlc_b64_encode( buf );
539 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
540 "Proxy-Authorization: Basic %s\r\n", b64 );
546 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
547 "GET %s HTTP/1.0\r\n"
549 ( (p_sys->url.psz_path == NULL) ||
550 (*p_sys->url.psz_path == '\0') ) ?
551 "/" : p_sys->url.psz_path,
552 p_sys->url.psz_host, p_sys->url.i_port );
557 /*****************************************************************************
559 *****************************************************************************/
560 static int Describe( access_t *p_access, char **ppsz_location )
562 access_sys_t *p_sys = p_access->p_sys;
563 char *psz_location = NULL;
568 p_sys->b_broadcast = VLC_TRUE;
569 p_sys->i_request_context = 1;
570 p_sys->i_packet_sequence = 0;
571 p_sys->i_packet_used = 0;
572 p_sys->i_packet_length = 0;
573 p_sys->p_packet = NULL;
574 E_( GenerateGuid )( &p_sys->guid );
576 if( OpenConnection( p_access ) )
579 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
581 "User-Agent: "MMSH_USER_AGENT"\r\n"
582 "Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=0:0,request-context=%d,max-duration=0\r\n"
583 "Pragma: xClientGUID={"GUID_FMT"}\r\n"
584 "Connection: Close\r\n",
585 p_sys->i_request_context++,
586 GUID_PRINT( p_sys->guid ) );
588 if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, "\r\n" ) < 0 )
590 msg_Err( p_access, "failed to send request" );
594 /* Receive the http header */
595 if( ( psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL ) ) == NULL )
597 msg_Err( p_access, "failed to read answer" );
601 if( strncmp( psz, "HTTP/1.", 7 ) )
603 msg_Err( p_access, "invalid HTTP reply '%s'", psz );
607 i_code = atoi( &psz[9] );
610 msg_Err( p_access, "error: %s", psz );
615 msg_Dbg( p_access, "HTTP reply '%s'", psz );
619 char *psz = net_Gets( p_access, p_sys->fd, NULL );
624 msg_Err( p_access, "failed to read answer" );
634 if( ( p = strchr( psz, ':' ) ) == NULL )
636 msg_Err( p_access, "malformed header line: %s", psz );
641 while( *p == ' ' ) p++;
643 /* FIXME FIXME test Content-Type to see if it's a plain stream or an
645 if( !strcasecmp( psz, "Pragma" ) )
647 if( strstr( p, "features" ) )
649 /* FIXME, it is a bit badly done here ..... */
650 if( strstr( p, "broadcast" ) )
652 msg_Dbg( p_access, "stream type = broadcast" );
653 p_sys->b_broadcast = VLC_TRUE;
655 else if( strstr( p, "seekable" ) )
657 msg_Dbg( p_access, "stream type = seekable" );
658 p_sys->b_broadcast = VLC_FALSE;
662 msg_Warn( p_access, "unknow stream types (%s)", p );
663 p_sys->b_broadcast = VLC_FALSE;
667 else if( !strcasecmp( psz, "Location" ) )
669 psz_location = strdup( p );
675 /* Handle the redirection */
676 if( ( (i_code == 301) || (i_code == 302) ||
677 (i_code == 303) || (i_code == 307) ) &&
678 psz_location && *psz_location )
680 msg_Dbg( p_access, "redirection to %s", psz_location );
681 net_Close( p_sys->fd ); p_sys->fd = -1;
683 *ppsz_location = psz_location;
687 /* Read the asf header */
688 GetHeader( p_access );
689 if( p_sys->i_header <= 0 )
691 msg_Err( p_access, "header size == 0" );
694 /* close this connection */
695 net_Close( p_sys->fd );
698 /* *** parse header and get stream and their id *** */
699 /* get all streams properties,
701 * TODO : stream bitrates properties(optional)
702 * and bitrate mutual exclusion(optional) */
703 E_( asf_HeaderParse )( &p_sys->asfh,
704 p_sys->p_header, p_sys->i_header );
705 msg_Dbg( p_access, "packet count="I64Fd" packet size=%d",
706 p_sys->asfh.i_data_packets_count,
707 p_sys->asfh.i_min_data_packet_size );
709 E_( asf_StreamSelect)( &p_sys->asfh,
710 var_CreateGetInteger( p_access, "mms-maxbitrate" ),
711 var_CreateGetInteger( p_access, "mms-all" ),
712 var_CreateGetInteger( p_access, "audio" ),
713 var_CreateGetInteger( p_access, "video" ) );
719 net_Close( p_sys->fd );
725 static void GetHeader( access_t *p_access )
727 access_sys_t *p_sys = p_access->p_sys;
729 /* Read the asf header */
731 if( p_sys->p_header )
732 free( p_sys->p_header );
733 p_sys->p_header = NULL;
737 if( GetPacket( p_access, &ck ) || ck.i_type != 0x4824 )
742 p_sys->i_header += ck.i_data;
743 p_sys->p_header = realloc( p_sys->p_header, p_sys->i_header );
744 memcpy( &p_sys->p_header[p_sys->i_header - ck.i_data],
745 ck.p_data, ck.i_data );
748 msg_Dbg( p_access, "complete header size=%d", p_sys->i_header );
752 /*****************************************************************************
754 ****************************************************************************/
755 static int Start( access_t *p_access, off_t i_pos )
757 access_sys_t *p_sys = p_access->p_sys;
759 int i_streams_selected = 0;
763 msg_Dbg( p_access, "starting stream" );
765 for( i = 1; i < 128; i++ )
767 if( p_sys->asfh.stream[i].i_cat == ASF_STREAM_UNKNOWN )
770 if( p_sys->asfh.stream[i].i_selected )
771 i_streams_selected++;
773 if( i_streams_selected <= 0 )
775 msg_Err( p_access, "no stream selected" );
779 if( OpenConnection( p_access ) )
782 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
784 "User-Agent: "MMSH_USER_AGENT"\r\n" );
785 if( p_sys->b_broadcast )
787 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
788 "Pragma: no-cache,rate=1.000000,request-context=%d\r\n",
789 p_sys->i_request_context++ );
793 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
794 "Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=%u:%u,request-context=%d,max-duration=0\r\n",
795 (uint32_t)((i_pos >> 32)&0xffffffff),
796 (uint32_t)(i_pos&0xffffffff),
797 p_sys->i_request_context++ );
799 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
800 "Pragma: xPlayStrm=1\r\n"
801 "Pragma: xClientGUID={"GUID_FMT"}\r\n"
802 "Pragma: stream-switch-count=%d\r\n"
803 "Pragma: stream-switch-entry=",
804 GUID_PRINT( p_sys->guid ),
807 for( i = 1; i < 128; i++ )
809 if( p_sys->asfh.stream[i].i_cat != ASF_STREAM_UNKNOWN )
812 if( p_sys->asfh.stream[i].i_selected )
816 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
817 "ffff:%d:%d ", i, i_select );
820 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, "\r\n" );
822 net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
823 "Connection: Close\r\n" );
825 if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, "\r\n" ) < 0 )
827 msg_Err( p_access, "failed to send request" );
832 psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL );
835 msg_Err( p_access, "cannot read data 0" );
839 if( atoi( &psz[9] ) >= 400 )
841 msg_Err( p_access, "error: %s", psz );
845 msg_Dbg( p_access, "HTTP reply '%s'", psz );
848 /* FIXME check HTTP code */
851 char *psz = net_Gets( p_access, p_sys->fd, NULL );
854 msg_Err( p_access, "cannot read data 1" );
862 msg_Dbg( p_access, "%s", psz );
866 p_sys->i_packet_used = 0;
867 p_sys->i_packet_length = 0;
872 /*****************************************************************************
874 *****************************************************************************/
875 static void Stop( access_t *p_access )
877 access_sys_t *p_sys = p_access->p_sys;
879 msg_Dbg( p_access, "closing stream" );
882 net_Close( p_sys->fd );
887 /*****************************************************************************
889 *****************************************************************************/
890 static int GetPacket( access_t * p_access, chunk_t *p_ck )
892 access_sys_t *p_sys = p_access->p_sys;
896 memset( p_ck, 0, sizeof( chunk_t ) );
898 /* Read the chunk header */
899 /* Some headers are short, like 0x4324. Reading 12 bytes will cause us
900 * to lose synchronization with the stream. Just read to the length
901 * (4 bytes), decode and then read up to 8 additional bytes to get the
904 if( net_Read( p_access, p_sys->fd, NULL, p_sys->buffer, 4, VLC_TRUE ) < 4 )
906 msg_Err( p_access, "cannot read data 2" );
910 p_ck->i_type = GetWLE( p_sys->buffer);
911 p_ck->i_size = GetWLE( p_sys->buffer + 2);
913 restsize = p_ck->i_size;
917 if( net_Read( p_access, p_sys->fd, NULL, p_sys->buffer + 4, restsize, VLC_TRUE ) < restsize )
919 msg_Err( p_access, "cannot read data 3" );
922 p_ck->i_sequence = GetDWLE( p_sys->buffer + 4);
923 p_ck->i_unknown = GetWLE( p_sys->buffer + 8);
925 /* Set i_size2 to 8 if this header was short, since a real value won't be
926 * present in the buffer. Using 8 avoid reading additional data for the
932 p_ck->i_size2 = GetWLE( p_sys->buffer + 10);
934 p_ck->p_data = p_sys->buffer + 12;
935 p_ck->i_data = p_ck->i_size2 - 8;
937 if( p_ck->i_type == 0x4524 ) // Transfer complete
939 if( p_ck->i_sequence == 0 )
941 msg_Warn( p_access, "EOF" );
946 msg_Warn( p_access, "next stream following" );
950 else if( p_ck->i_type == 0x4324 )
952 /* 0x4324 is CHUNK_TYPE_RESET: a new stream will follow with a sequence of 0 */
953 msg_Warn( p_access, "next stream following (reset) seq=%d", p_ck->i_sequence );
956 else if( (p_ck->i_type != 0x4824) && (p_ck->i_type != 0x4424) )
958 msg_Err( p_access, "invalid chunk FATAL (0x%x)", p_ck->i_type );
962 if( (p_ck->i_data > 0) &&
963 (net_Read( p_access, p_sys->fd, NULL, &p_sys->buffer[12],
964 p_ck->i_data, VLC_TRUE ) < p_ck->i_data) )
966 msg_Err( p_access, "cannot read data 4" );
971 if( (p_sys->i_packet_sequence != 0) &&
972 (p_ck->i_sequence != p_sys->i_packet_sequence) )
974 msg_Warn( p_access, "packet lost ? (%d != %d)", p_ck->i_sequence, p_sys->i_packet_sequence );
978 p_sys->i_packet_sequence = p_ck->i_sequence + 1;
979 p_sys->i_packet_used = 0;
980 p_sys->i_packet_length = p_ck->i_data;
981 p_sys->p_packet = p_ck->p_data;