1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 VLC authors and VideoLAN
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_access.h>
34 #include <vlc_strings.h>
35 #include <vlc_input.h>
37 #include <vlc_network.h>
50 /*****************************************************************************
52 *****************************************************************************/
53 int MMSHOpen ( access_t * );
54 void MMSHClose ( access_t * );
56 static block_t *Block( access_t *p_access );
57 static ssize_t ReadRedirect( access_t *, uint8_t *, size_t );
58 static int Seek( access_t *, uint64_t );
59 static int Control( access_t *, int, va_list );
61 static int Describe( access_t *, char **ppsz_location );
62 static int Start( access_t *, uint64_t );
63 static void Stop( access_t * );
65 static int GetPacket( access_t *, chunk_t * );
66 static void GetHeader( access_t *p_access, int i_content_length );
68 static int Restart( access_t * );
69 static int Reset( access_t * );
71 //#define MMSH_USER_AGENT "NSPlayer/4.1.0.3856"
72 #define MMSH_USER_AGENT "NSPlayer/7.10.0.3059"
74 /****************************************************************************
75 * Open: connect to ftp server and ask for file
76 ****************************************************************************/
77 int MMSHOpen( access_t *p_access )
80 char *psz_location = NULL;
83 STANDARD_BLOCK_ACCESS_INIT
85 p_sys->i_proto= MMS_PROTO_HTTP;
89 p_sys->b_proxy = false;
90 memset( &p_sys->proxy, 0, sizeof(p_sys->proxy) );
93 /* TODO reuse instead http-proxy from http access ? */
94 psz_proxy = var_CreateGetNonEmptyString( p_access, "mmsh-proxy" );
97 char *psz_http_proxy = var_InheritString( p_access, "http-proxy" );
100 psz_proxy = psz_http_proxy;
101 var_SetString( p_access, "mmsh-proxy", psz_proxy );
107 p_sys->b_proxy = true;
108 vlc_UrlParse( &p_sys->proxy, psz_proxy, 0 );
113 const char *http_proxy = getenv( "http_proxy" );
116 p_sys->b_proxy = true;
117 vlc_UrlParse( &p_sys->proxy, http_proxy, 0 );
123 if( ( p_sys->proxy.psz_host == NULL ) ||
124 ( *p_sys->proxy.psz_host == '\0' ) )
126 msg_Warn( p_access, "invalid proxy host" );
127 vlc_UrlClean( &p_sys->proxy );
132 if( p_sys->proxy.i_port <= 0 )
133 p_sys->proxy.i_port = 80;
134 msg_Dbg( p_access, "Using http proxy %s:%d",
135 p_sys->proxy.psz_host, p_sys->proxy.i_port );
138 /* open a tcp connection */
139 vlc_UrlParse( &p_sys->url, p_access->psz_location, 0 );
140 if( ( p_sys->url.psz_host == NULL ) ||
141 ( *p_sys->url.psz_host == '\0' ) )
143 msg_Err( p_access, "invalid host" );
146 if( p_sys->url.i_port <= 0 )
147 p_sys->url.i_port = 80;
149 if( Describe( p_access, &psz_location ) )
152 /* Handle redirection */
153 if( psz_location && *psz_location )
155 msg_Dbg( p_access, "redirection to %s", psz_location );
157 input_thread_t * p_input = access_GetParentInput( p_access );
158 input_item_t * p_new_loc;
162 free( psz_location );
165 /** \bug we do not autodelete here */
166 p_new_loc = input_item_New( psz_location, psz_location );
167 input_item_t *p_item = input_GetItem( p_input );
168 input_item_PostSubItem( p_item, p_new_loc );
170 vlc_gc_decref( p_new_loc );
171 vlc_object_release( p_input );
173 free( psz_location );
175 p_access->pf_block = NULL;
176 p_access->pf_read = ReadRedirect;
179 free( psz_location );
182 if( Start( p_access, 0 ) )
184 msg_Err( p_access, "cannot start stream" );
185 free( p_sys->p_header );
192 vlc_UrlClean( &p_sys->proxy );
193 vlc_UrlClean( &p_sys->url );
198 /*****************************************************************************
199 * Close: free unused data structures
200 *****************************************************************************/
201 void MMSHClose ( access_t *p_access )
203 access_sys_t *p_sys = p_access->p_sys;
207 free( p_sys->p_header );
209 vlc_UrlClean( &p_sys->proxy );
210 vlc_UrlClean( &p_sys->url );
214 /*****************************************************************************
216 *****************************************************************************/
217 static int Control( access_t *p_access, int i_query, va_list args )
219 access_sys_t *p_sys = p_access->p_sys;
227 case ACCESS_CAN_SEEK:
228 pb_bool = (bool*)va_arg( args, bool* );
229 *pb_bool = !p_sys->b_broadcast;
232 case ACCESS_CAN_FASTSEEK:
233 pb_bool = (bool*)va_arg( args, bool* );
237 case ACCESS_CAN_PAUSE:
238 case ACCESS_CAN_CONTROL_PACE:
239 pb_bool = (bool*)va_arg( args, bool* );
243 case ACCESS_GET_SIZE:
245 uint64_t *s = va_arg( args, uint64_t * );
246 *s = p_sys->b_broadcast ? 0 : p_sys->asfh.i_file_size;
250 case ACCESS_GET_PTS_DELAY:
251 pi_64 = (int64_t*)va_arg( args, int64_t * );
252 *pi_64 = INT64_C(1000)
253 * var_InheritInteger( p_access, "network-caching" );
256 case ACCESS_GET_PRIVATE_ID_STATE:
257 i_int = (int)va_arg( args, int );
258 pb_bool = (bool *)va_arg( args, bool * );
260 if( (i_int < 0) || (i_int > 127) )
262 *pb_bool = p_sys->asfh.stream[i_int].i_selected ? true : false;
265 case ACCESS_SET_PRIVATE_ID_STATE:
267 i_int = (int)va_arg( args, int );
268 b_bool = (bool)va_arg( args, int );
272 else if ( i_int < 0 )
274 /* Deselecting all ES in this category */
277 if ( i_cat > ES_CATEGORY_COUNT )
282 /* Chose another ES */
284 i_cat = p_sys->asfh.stream[i_int].i_cat;
287 for ( int i=0; i< 128; i++ )
289 /* First unselect all streams from the same cat */
290 if ( i_cat == p_sys->asfh.stream[i].i_cat )
291 p_sys->asfh.stream[i].i_selected = false;
295 p_sys->asfh.stream[i_int].i_selected = true;
298 Seek( p_access, p_access->info.i_pos );
302 case ACCESS_SET_PAUSE_STATE:
303 b_bool = (bool)va_arg( args, int );
307 Seek( p_access, p_access->info.i_pos );
316 /*****************************************************************************
317 * Seek: try to go at the right place
318 *****************************************************************************/
319 static int Seek( access_t *p_access, uint64_t i_pos )
321 access_sys_t *p_sys = p_access->p_sys;
326 msg_Dbg( p_access, "seeking to %"PRId64, i_pos );
328 i_packet = ( i_pos - p_sys->i_header ) / p_sys->asfh.i_min_data_packet_size;
329 i_offset = ( i_pos - p_sys->i_header ) % p_sys->asfh.i_min_data_packet_size;
332 Start( p_access, i_packet * p_sys->asfh.i_min_data_packet_size );
334 while( vlc_object_alive (p_access) )
336 if( GetPacket( p_access, &ck ) )
340 if( ck.i_type != 0x4824 )
343 msg_Warn( p_access, "skipping header" );
346 p_access->info.i_pos = i_pos;
347 p_access->info.b_eof = false;
348 p_sys->i_packet_used += i_offset;
353 /*****************************************************************************
355 *****************************************************************************/
356 static ssize_t ReadRedirect( access_t *p_access, uint8_t *p, size_t i_len )
358 VLC_UNUSED(p_access); VLC_UNUSED(p); VLC_UNUSED(i_len);
362 /*****************************************************************************
364 *****************************************************************************/
365 static block_t *Block( access_t *p_access )
367 access_sys_t *p_sys = p_access->p_sys;
368 const unsigned i_packet_min = p_sys->asfh.i_min_data_packet_size;
370 if( p_access->info.i_pos < p_sys->i_start + p_sys->i_header )
372 const size_t i_offset = p_access->info.i_pos - p_sys->i_start;
373 const size_t i_copy = p_sys->i_header - i_offset;
375 block_t *p_block = block_Alloc( i_copy );
379 memcpy( p_block->p_buffer, &p_sys->p_header[i_offset], i_copy );
380 p_access->info.i_pos += i_copy;
383 else if( p_sys->i_packet_length > 0 &&
384 p_sys->i_packet_used < __MAX( p_sys->i_packet_length, i_packet_min ) )
387 size_t i_padding = 0;
389 if( p_sys->i_packet_used < p_sys->i_packet_length )
390 i_copy = p_sys->i_packet_length - p_sys->i_packet_used;
391 if( __MAX( p_sys->i_packet_used, p_sys->i_packet_length ) < i_packet_min )
392 i_padding = i_packet_min - __MAX( p_sys->i_packet_used, p_sys->i_packet_length );
394 block_t *p_block = block_Alloc( i_copy + i_padding );
399 memcpy( &p_block->p_buffer[0], &p_sys->p_packet[p_sys->i_packet_used], i_copy );
401 memset( &p_block->p_buffer[i_copy], 0, i_padding );
403 p_sys->i_packet_used += i_copy + i_padding;
404 p_access->info.i_pos += i_copy + i_padding;
410 if( GetPacket( p_access, &ck ) )
413 if( p_sys->b_broadcast )
415 if( (ck.i_type == 0x4524) && (ck.i_sequence != 0) )
416 i_ret = Restart( p_access );
417 else if( ck.i_type == 0x4324 )
418 i_ret = Reset( p_access );
422 p_access->info.b_eof = true;
426 if( ck.i_type != 0x4424 )
428 p_sys->i_packet_used = 0;
429 p_sys->i_packet_length = 0;
436 static int Restart( access_t *p_access )
438 access_sys_t *p_sys = p_access->p_sys;
439 char *psz_location = NULL;
441 msg_Dbg( p_access, "Restart the stream" );
442 p_sys->i_start = p_access->info.i_pos;
445 msg_Dbg( p_access, "stoping the stream" );
449 msg_Dbg( p_access, "describe the stream" );
450 if( Describe( p_access, &psz_location ) )
452 msg_Err( p_access, "describe failed" );
455 free( psz_location );
458 if( Start( p_access, 0 ) )
460 msg_Err( p_access, "Start failed" );
465 static int Reset( access_t *p_access )
467 access_sys_t *p_sys = p_access->p_sys;
468 asf_header_t old_asfh = p_sys->asfh;
471 msg_Dbg( p_access, "Reset the stream" );
472 p_sys->i_start = p_access->info.i_pos;
475 p_sys->i_packet_sequence = 0;
476 p_sys->i_packet_used = 0;
477 p_sys->i_packet_length = 0;
478 p_sys->p_packet = NULL;
480 /* Get the next header FIXME memory loss ? */
481 GetHeader( p_access, -1 );
482 if( p_sys->i_header <= 0 )
485 asf_HeaderParse ( &p_sys->asfh,
486 p_sys->p_header, p_sys->i_header );
487 msg_Dbg( p_access, "packet count=%"PRId64" packet size=%d",
488 p_sys->asfh.i_data_packets_count,
489 p_sys->asfh.i_min_data_packet_size );
491 asf_StreamSelect( &p_sys->asfh,
492 var_InheritInteger( p_access, "mms-maxbitrate" ),
493 var_InheritBool( p_access, "mms-all" ),
494 var_InheritBool( p_access, "audio" ),
495 var_InheritBool( p_access, "video" ) );
497 /* Check we have comptible asfh */
498 for( i = 1; i < 128; i++ )
500 asf_stream_t *p_old = &old_asfh.stream[i];
501 asf_stream_t *p_new = &p_sys->asfh.stream[i];
503 if( p_old->i_cat != p_new->i_cat || p_old->i_selected != p_new->i_selected )
508 msg_Warn( p_access, "incompatible asf header, restart" );
509 return Restart( p_access );
513 p_sys->i_packet_used = 0;
514 p_sys->i_packet_length = 0;
518 static int OpenConnection( access_t *p_access )
520 access_sys_t *p_sys = p_access->p_sys;
521 vlc_url_t srv = p_sys->b_proxy ? p_sys->proxy : p_sys->url;
523 if( ( p_sys->fd = net_ConnectTCP( p_access,
524 srv.psz_host, srv.i_port ) ) < 0 )
526 msg_Err( p_access, "cannot connect to %s:%d",
527 srv.psz_host, srv.i_port );
533 net_Printf( p_access, p_sys->fd, NULL,
534 "GET http://%s:%d%s HTTP/1.0\r\n",
535 p_sys->url.psz_host, p_sys->url.i_port,
536 ( (p_sys->url.psz_path == NULL) ||
537 (*p_sys->url.psz_path == '\0') ) ?
538 "/" : p_sys->url.psz_path );
540 /* Proxy Authentication */
541 if( p_sys->proxy.psz_username && *p_sys->proxy.psz_username )
546 if( asprintf( &buf, "%s:%s", p_sys->proxy.psz_username,
547 p_sys->proxy.psz_password ? p_sys->proxy.psz_password : "" ) == -1 )
550 b64 = vlc_b64_encode( buf );
553 net_Printf( p_access, p_sys->fd, NULL,
554 "Proxy-Authorization: Basic %s\r\n", b64 );
560 net_Printf( p_access, p_sys->fd, NULL,
561 "GET %s HTTP/1.0\r\n"
563 ( (p_sys->url.psz_path == NULL) ||
564 (*p_sys->url.psz_path == '\0') ) ?
565 "/" : p_sys->url.psz_path,
566 p_sys->url.psz_host, p_sys->url.i_port );
571 /*****************************************************************************
573 *****************************************************************************/
574 static int Describe( access_t *p_access, char **ppsz_location )
576 access_sys_t *p_sys = p_access->p_sys;
577 char *psz_location = NULL;
578 int i_content_length = -1;
579 bool b_keepalive = false;
584 p_sys->b_broadcast = true;
585 p_sys->i_request_context = 1;
586 p_sys->i_packet_sequence = 0;
587 p_sys->i_packet_used = 0;
588 p_sys->i_packet_length = 0;
589 p_sys->p_packet = NULL;
591 GenerateGuid ( &p_sys->guid );
593 if( OpenConnection( p_access ) )
596 net_Printf( p_access, p_sys->fd, NULL,
598 "User-Agent: "MMSH_USER_AGENT"\r\n"
599 "Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=0:0,request-context=%d,max-duration=0\r\n"
600 "Pragma: xClientGUID={"GUID_FMT"}\r\n"
601 "Connection: Close\r\n",
602 p_sys->i_request_context++,
603 GUID_PRINT( p_sys->guid ) );
605 if( net_Printf( p_access, p_sys->fd, NULL, "\r\n" ) < 0 )
607 msg_Err( p_access, "failed to send request" );
611 /* Receive the http header */
612 if( ( psz = net_Gets( p_access, p_sys->fd, NULL ) ) == NULL )
614 msg_Err( p_access, "failed to read answer" );
618 if( strncmp( psz, "HTTP/1.", 7 ) )
620 msg_Err( p_access, "invalid HTTP reply '%s'", psz );
624 i_code = atoi( &psz[9] );
627 msg_Err( p_access, "error: %s", psz );
632 msg_Dbg( p_access, "HTTP reply '%s'", psz );
636 char *psz = net_Gets( p_access, p_sys->fd, NULL );
641 msg_Err( p_access, "failed to read answer" );
651 if( ( p = strchr( psz, ':' ) ) == NULL )
653 msg_Err( p_access, "malformed header line: %s", psz );
658 while( *p == ' ' ) p++;
660 /* FIXME FIXME test Content-Type to see if it's a plain stream or an
662 if( !strcasecmp( psz, "Pragma" ) )
664 if( strstr( p, "features" ) )
666 /* FIXME, it is a bit badly done here ..... */
667 if( strstr( p, "broadcast" ) )
669 msg_Dbg( p_access, "stream type = broadcast" );
670 p_sys->b_broadcast = true;
672 else if( strstr( p, "seekable" ) )
674 msg_Dbg( p_access, "stream type = seekable" );
675 p_sys->b_broadcast = false;
679 msg_Warn( p_access, "unknow stream types (%s)", p );
680 p_sys->b_broadcast = false;
684 else if( !strcasecmp( psz, "Location" ) )
686 psz_location = strdup( p );
688 else if( !strcasecmp( psz, "Content-Length" ) )
690 i_content_length = atoi( p );
691 msg_Dbg( p_access, "content-length = %d", i_content_length );
693 else if( !strcasecmp( psz, "Connection" ) )
695 if( strcasestr( p, "Keep-Alive" ) )
697 msg_Dbg( p_access, "Keep-Alive header found" );
706 /* Handle the redirection */
707 if( ( (i_code == 301) || (i_code == 302) ||
708 (i_code == 303) || (i_code == 307) ) &&
709 psz_location && *psz_location )
711 msg_Dbg( p_access, "redirection to %s", psz_location );
712 net_Close( p_sys->fd ); p_sys->fd = -1;
714 *ppsz_location = psz_location;
717 free( psz_location );
719 /* Read the asf header */
720 GetHeader( p_access, b_keepalive ? i_content_length : -1);
721 if( p_sys->i_header <= 0 )
723 msg_Err( p_access, "header size == 0" );
726 /* close this connection */
727 net_Close( p_sys->fd );
730 /* *** parse header and get stream and their id *** */
731 /* get all streams properties,
733 * TODO : stream bitrates properties(optional)
734 * and bitrate mutual exclusion(optional) */
735 asf_HeaderParse ( &p_sys->asfh,
736 p_sys->p_header, p_sys->i_header );
737 msg_Dbg( p_access, "packet count=%"PRId64" packet size=%d",
738 p_sys->asfh.i_data_packets_count,
739 p_sys->asfh.i_min_data_packet_size );
741 if( p_sys->asfh.i_min_data_packet_size <= 0 )
744 asf_StreamSelect( &p_sys->asfh,
745 var_InheritInteger( p_access, "mms-maxbitrate" ),
746 var_InheritBool( p_access, "mms-all" ),
747 var_InheritBool( p_access, "audio" ),
748 var_InheritBool( p_access, "video" ) );
754 net_Close( p_sys->fd );
760 static void GetHeader( access_t *p_access, int i_content_length )
762 access_sys_t *p_sys = p_access->p_sys;
763 int i_read_content = 0;
765 /* Read the asf header */
767 free( p_sys->p_header );
768 p_sys->p_header = NULL;
772 if( (i_content_length >= 0 && i_read_content >= i_content_length) || GetPacket( p_access, &ck ) || ck.i_type != 0x4824 )
775 i_read_content += (4+ck.i_size);
779 p_sys->i_header += ck.i_data;
780 p_sys->p_header = xrealloc( p_sys->p_header, p_sys->i_header );
781 memcpy( &p_sys->p_header[p_sys->i_header - ck.i_data],
782 ck.p_data, ck.i_data );
785 msg_Dbg( p_access, "complete header size=%d", p_sys->i_header );
789 /*****************************************************************************
791 ****************************************************************************/
792 static int Start( access_t *p_access, uint64_t i_pos )
794 access_sys_t *p_sys = p_access->p_sys;
796 int i_streams_selected = 0;
800 msg_Dbg( p_access, "starting stream" );
802 for( i = 1; i < 128; i++ )
804 if( p_sys->asfh.stream[i].i_cat == ASF_CODEC_TYPE_UNKNOWN )
807 if( p_sys->asfh.stream[i].i_selected )
808 i_streams_selected++;
810 if( i_streams_selected <= 0 )
812 msg_Err( p_access, "no stream selected" );
816 if( OpenConnection( p_access ) )
819 net_Printf( p_access, p_sys->fd, NULL,
821 "User-Agent: "MMSH_USER_AGENT"\r\n" );
822 if( p_sys->b_broadcast )
824 net_Printf( p_access, p_sys->fd, NULL,
825 "Pragma: no-cache,rate=1.000000,request-context=%d\r\n",
826 p_sys->i_request_context++ );
830 net_Printf( p_access, p_sys->fd, NULL,
831 "Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=%u:%u,request-context=%d,max-duration=0\r\n",
832 (uint32_t)((i_pos >> 32)&0xffffffff),
833 (uint32_t)(i_pos&0xffffffff),
834 p_sys->i_request_context++ );
836 net_Printf( p_access, p_sys->fd, NULL,
837 "Pragma: xPlayStrm=1\r\n"
838 "Pragma: xClientGUID={"GUID_FMT"}\r\n"
839 "Pragma: stream-switch-count=%d\r\n"
840 "Pragma: stream-switch-entry=",
841 GUID_PRINT( p_sys->guid ),
844 for( i = 1; i < 128; i++ )
846 if( p_sys->asfh.stream[i].i_cat != ASF_CODEC_TYPE_UNKNOWN )
849 if( p_sys->asfh.stream[i].i_selected )
853 net_Printf( p_access, p_sys->fd, NULL,
854 "ffff:%x:%d ", i, i_select );
857 net_Printf( p_access, p_sys->fd, NULL, "\r\n" );
858 net_Printf( p_access, p_sys->fd, NULL,
859 "Connection: Close\r\n" );
861 if( net_Printf( p_access, p_sys->fd, NULL, "\r\n" ) < 0 )
863 msg_Err( p_access, "failed to send request" );
867 psz = net_Gets( p_access, p_sys->fd, NULL );
870 msg_Err( p_access, "cannot read data 0" );
874 if( atoi( &psz[9] ) >= 400 )
876 msg_Err( p_access, "error: %s", psz );
880 msg_Dbg( p_access, "HTTP reply '%s'", psz );
883 /* FIXME check HTTP code */
886 char *psz = net_Gets( p_access, p_sys->fd, NULL );
889 msg_Err( p_access, "cannot read data 1" );
897 msg_Dbg( p_access, "%s", psz );
901 p_sys->i_packet_used = 0;
902 p_sys->i_packet_length = 0;
907 /*****************************************************************************
909 *****************************************************************************/
910 static void Stop( access_t *p_access )
912 access_sys_t *p_sys = p_access->p_sys;
914 msg_Dbg( p_access, "closing stream" );
917 net_Close( p_sys->fd );
922 /*****************************************************************************
924 *****************************************************************************/
925 static int GetPacket( access_t * p_access, chunk_t *p_ck )
927 access_sys_t *p_sys = p_access->p_sys;
931 memset( p_ck, 0, sizeof( chunk_t ) );
933 /* Read the chunk header */
934 /* Some headers are short, like 0x4324. Reading 12 bytes will cause us
935 * to lose synchronization with the stream. Just read to the length
936 * (4 bytes), decode and then read up to 8 additional bytes to get the
939 if( net_Read( p_access, p_sys->fd, NULL, p_sys->buffer, 4, true ) < 4 )
941 msg_Err( p_access, "cannot read data 2" );
945 p_ck->i_type = GetWLE( p_sys->buffer);
946 p_ck->i_size = GetWLE( p_sys->buffer + 2);
948 restsize = p_ck->i_size;
952 if( net_Read( p_access, p_sys->fd, NULL, p_sys->buffer + 4, restsize, true ) < restsize )
954 msg_Err( p_access, "cannot read data 3" );
957 p_ck->i_sequence = GetDWLE( p_sys->buffer + 4);
958 p_ck->i_unknown = GetWLE( p_sys->buffer + 8);
960 /* Set i_size2 to 8 if this header was short, since a real value won't be
961 * present in the buffer. Using 8 avoid reading additional data for the
967 p_ck->i_size2 = GetWLE( p_sys->buffer + 10);
969 p_ck->p_data = p_sys->buffer + 12;
970 p_ck->i_data = p_ck->i_size2 - 8;
972 if( p_ck->i_type == 0x4524 ) // $E (End-of-Stream Notification) Packet
974 if( p_ck->i_sequence == 0 )
976 msg_Warn( p_access, "EOF" );
981 msg_Warn( p_access, "next stream following" );
985 else if( p_ck->i_type == 0x4324 ) // $C (Stream Change Notification) Packet
987 /* 0x4324 is CHUNK_TYPE_RESET: a new stream will follow with a sequence of 0 */
988 msg_Warn( p_access, "next stream following (reset) seq=%d", p_ck->i_sequence );
991 else if( (p_ck->i_type != 0x4824) && (p_ck->i_type != 0x4424) )
993 /* Unsupported so far:
994 * $M (Metadata) Packet 0x4D24
995 * $P (Packet-Pair) Packet 0x5024
996 * $T (Test Data Notification) Packet 0x5424
998 msg_Err( p_access, "unrecognized chunk FATAL (0x%x)", p_ck->i_type );
1002 if( (p_ck->i_data > 0) &&
1003 (net_Read( p_access, p_sys->fd, NULL, &p_sys->buffer[12],
1004 p_ck->i_data, true ) < p_ck->i_data) )
1006 msg_Err( p_access, "cannot read data 4" );
1007 return VLC_EGENERIC;
1011 if( (p_sys->i_packet_sequence != 0) &&
1012 (p_ck->i_sequence != p_sys->i_packet_sequence) )
1014 msg_Warn( p_access, "packet lost ? (%d != %d)", p_ck->i_sequence, p_sys->i_packet_sequence );
1018 p_sys->i_packet_sequence = p_ck->i_sequence + 1;
1019 p_sys->i_packet_used = 0;
1020 p_sys->i_packet_length = p_ck->i_data;
1021 p_sys->p_packet = p_ck->p_data;