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 );
113 const char *http_proxy = getenv( "http_proxy" );
116 p_sys->b_proxy = true;
117 vlc_UrlParse( &p_sys->proxy, http_proxy );
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 );
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 = p_access->p_input;
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 );
172 free( psz_location );
174 p_access->pf_block = NULL;
175 p_access->pf_read = ReadRedirect;
178 free( psz_location );
181 if( Start( p_access, 0 ) )
183 msg_Err( p_access, "cannot start stream" );
184 free( p_sys->p_header );
191 vlc_UrlClean( &p_sys->proxy );
192 vlc_UrlClean( &p_sys->url );
197 /*****************************************************************************
198 * Close: free unused data structures
199 *****************************************************************************/
200 void MMSHClose ( access_t *p_access )
202 access_sys_t *p_sys = p_access->p_sys;
206 free( p_sys->p_header );
208 vlc_UrlClean( &p_sys->proxy );
209 vlc_UrlClean( &p_sys->url );
213 /*****************************************************************************
215 *****************************************************************************/
216 static int Control( access_t *p_access, int i_query, va_list args )
218 access_sys_t *p_sys = p_access->p_sys;
226 case ACCESS_CAN_SEEK:
227 pb_bool = (bool*)va_arg( args, bool* );
228 *pb_bool = !p_sys->b_broadcast;
231 case ACCESS_CAN_FASTSEEK:
232 pb_bool = (bool*)va_arg( args, bool* );
236 case ACCESS_CAN_PAUSE:
237 case ACCESS_CAN_CONTROL_PACE:
238 pb_bool = (bool*)va_arg( args, bool* );
242 case ACCESS_GET_SIZE:
244 uint64_t *s = va_arg( args, uint64_t * );
245 if (p_sys->b_broadcast)
247 *s = p_sys->asfh.i_file_size;
251 case ACCESS_GET_PTS_DELAY:
252 pi_64 = (int64_t*)va_arg( args, int64_t * );
253 *pi_64 = INT64_C(1000)
254 * var_InheritInteger( p_access, "network-caching" );
257 case ACCESS_GET_PRIVATE_ID_STATE:
258 i_int = (int)va_arg( args, int );
259 pb_bool = (bool *)va_arg( args, bool * );
261 if( (i_int < 0) || (i_int > 127) )
263 *pb_bool = p_sys->asfh.stream[i_int].i_selected ? true : false;
266 case ACCESS_SET_PRIVATE_ID_STATE:
268 i_int = (int)va_arg( args, int );
269 b_bool = (bool)va_arg( args, int );
273 else if ( i_int < 0 )
275 /* Deselecting all ES in this category */
278 if ( i_cat > ES_CATEGORY_COUNT )
283 /* Chose another ES */
285 i_cat = p_sys->asfh.stream[i_int].i_cat;
288 for ( int i=0; i< 128; i++ )
290 /* First unselect all streams from the same cat */
291 if ( i_cat == p_sys->asfh.stream[i].i_cat )
292 p_sys->asfh.stream[i].i_selected = false;
296 p_sys->asfh.stream[i_int].i_selected = true;
299 Seek( p_access, p_access->info.i_pos );
303 case ACCESS_SET_PAUSE_STATE:
304 b_bool = (bool)va_arg( args, int );
308 Seek( p_access, p_access->info.i_pos );
317 /*****************************************************************************
318 * Seek: try to go at the right place
319 *****************************************************************************/
320 static int Seek( access_t *p_access, uint64_t i_pos )
322 access_sys_t *p_sys = p_access->p_sys;
327 msg_Dbg( p_access, "seeking to %"PRId64, i_pos );
329 i_packet = ( i_pos - p_sys->i_header ) / p_sys->asfh.i_min_data_packet_size;
330 i_offset = ( i_pos - p_sys->i_header ) % p_sys->asfh.i_min_data_packet_size;
333 Start( p_access, i_packet * p_sys->asfh.i_min_data_packet_size );
337 if( GetPacket( p_access, &ck ) )
341 if( ck.i_type != 0x4824 )
344 msg_Warn( p_access, "skipping header" );
347 p_access->info.i_pos = i_pos;
348 p_access->info.b_eof = false;
349 p_sys->i_packet_used += i_offset;
354 /*****************************************************************************
356 *****************************************************************************/
357 static ssize_t ReadRedirect( access_t *p_access, uint8_t *p, size_t i_len )
359 VLC_UNUSED(p_access); VLC_UNUSED(p); VLC_UNUSED(i_len);
363 /*****************************************************************************
365 *****************************************************************************/
366 static block_t *Block( access_t *p_access )
368 access_sys_t *p_sys = p_access->p_sys;
369 const unsigned i_packet_min = p_sys->asfh.i_min_data_packet_size;
371 if( p_access->info.i_pos < p_sys->i_start + p_sys->i_header )
373 const size_t i_offset = p_access->info.i_pos - p_sys->i_start;
374 const size_t i_copy = p_sys->i_header - i_offset;
376 block_t *p_block = block_Alloc( i_copy );
380 memcpy( p_block->p_buffer, &p_sys->p_header[i_offset], i_copy );
381 p_access->info.i_pos += i_copy;
384 else if( p_sys->i_packet_length > 0 &&
385 p_sys->i_packet_used < __MAX( p_sys->i_packet_length, i_packet_min ) )
388 size_t i_padding = 0;
390 if( p_sys->i_packet_used < p_sys->i_packet_length )
391 i_copy = p_sys->i_packet_length - p_sys->i_packet_used;
392 if( __MAX( p_sys->i_packet_used, p_sys->i_packet_length ) < i_packet_min )
393 i_padding = i_packet_min - __MAX( p_sys->i_packet_used, p_sys->i_packet_length );
395 block_t *p_block = block_Alloc( i_copy + i_padding );
400 memcpy( &p_block->p_buffer[0], &p_sys->p_packet[p_sys->i_packet_used], i_copy );
402 memset( &p_block->p_buffer[i_copy], 0, i_padding );
404 p_sys->i_packet_used += i_copy + i_padding;
405 p_access->info.i_pos += i_copy + i_padding;
411 if( GetPacket( p_access, &ck ) )
414 if( p_sys->b_broadcast )
416 if( (ck.i_type == 0x4524) && (ck.i_sequence != 0) )
417 i_ret = Restart( p_access );
418 else if( ck.i_type == 0x4324 )
419 i_ret = Reset( p_access );
423 p_access->info.b_eof = true;
427 if( ck.i_type != 0x4424 )
429 p_sys->i_packet_used = 0;
430 p_sys->i_packet_length = 0;
437 static int Restart( access_t *p_access )
439 access_sys_t *p_sys = p_access->p_sys;
440 char *psz_location = NULL;
442 msg_Dbg( p_access, "Restart the stream" );
443 p_sys->i_start = p_access->info.i_pos;
446 msg_Dbg( p_access, "stoping the stream" );
450 msg_Dbg( p_access, "describe the stream" );
451 if( Describe( p_access, &psz_location ) )
453 msg_Err( p_access, "describe failed" );
456 free( psz_location );
459 if( Start( p_access, 0 ) )
461 msg_Err( p_access, "Start failed" );
466 static int Reset( access_t *p_access )
468 access_sys_t *p_sys = p_access->p_sys;
469 asf_header_t old_asfh = p_sys->asfh;
472 msg_Dbg( p_access, "Reset the stream" );
473 p_sys->i_start = p_access->info.i_pos;
476 p_sys->i_packet_sequence = 0;
477 p_sys->i_packet_used = 0;
478 p_sys->i_packet_length = 0;
479 p_sys->p_packet = NULL;
481 /* Get the next header FIXME memory loss ? */
482 GetHeader( p_access, -1 );
483 if( p_sys->i_header <= 0 )
486 asf_HeaderParse ( &p_sys->asfh,
487 p_sys->p_header, p_sys->i_header );
488 msg_Dbg( p_access, "packet count=%"PRId64" packet size=%d",
489 p_sys->asfh.i_data_packets_count,
490 p_sys->asfh.i_min_data_packet_size );
492 asf_StreamSelect( &p_sys->asfh,
493 var_InheritInteger( p_access, "mms-maxbitrate" ),
494 var_InheritBool( p_access, "mms-all" ),
495 var_InheritBool( p_access, "audio" ),
496 var_InheritBool( p_access, "video" ) );
498 /* Check we have comptible asfh */
499 for( i = 1; i < 128; i++ )
501 asf_stream_t *p_old = &old_asfh.stream[i];
502 asf_stream_t *p_new = &p_sys->asfh.stream[i];
504 if( p_old->i_cat != p_new->i_cat || p_old->i_selected != p_new->i_selected )
509 msg_Warn( p_access, "incompatible asf header, restart" );
510 return Restart( p_access );
514 p_sys->i_packet_used = 0;
515 p_sys->i_packet_length = 0;
519 static int OpenConnection( access_t *p_access )
521 access_sys_t *p_sys = p_access->p_sys;
522 vlc_url_t srv = p_sys->b_proxy ? p_sys->proxy : p_sys->url;
524 if( ( p_sys->fd = net_ConnectTCP( p_access,
525 srv.psz_host, srv.i_port ) ) < 0 )
527 msg_Err( p_access, "cannot connect to %s:%d",
528 srv.psz_host, srv.i_port );
534 net_Printf( p_access, p_sys->fd, "GET http://%s:%d%s%s%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,
539 p_sys->url.psz_option ? "?" : "",
540 p_sys->url.psz_option ? p_sys->url.psz_option : "" );
542 /* Proxy Authentication */
543 if( p_sys->proxy.psz_username && *p_sys->proxy.psz_username )
548 if( asprintf( &buf, "%s:%s", p_sys->proxy.psz_username,
549 p_sys->proxy.psz_password ? p_sys->proxy.psz_password : "" ) == -1 )
552 b64 = vlc_b64_encode( buf );
555 net_Printf( p_access, p_sys->fd,
556 "Proxy-Authorization: Basic %s\r\n", b64 );
562 net_Printf( p_access, p_sys->fd, "GET %s%s%s HTTP/1.0\r\n"
564 ( (p_sys->url.psz_path == NULL) ||
565 (*p_sys->url.psz_path == '\0') ) ?
566 "/" : p_sys->url.psz_path,
567 p_sys->url.psz_option ? "?" : "",
568 p_sys->url.psz_option ? p_sys->url.psz_option : "",
569 p_sys->url.psz_host, p_sys->url.i_port );
574 /*****************************************************************************
576 *****************************************************************************/
577 static int Describe( access_t *p_access, char **ppsz_location )
579 access_sys_t *p_sys = p_access->p_sys;
580 char *psz_location = NULL;
581 int i_content_length = -1;
582 bool b_keepalive = false;
587 p_sys->b_broadcast = true;
588 p_sys->i_request_context = 1;
589 p_sys->i_packet_sequence = 0;
590 p_sys->i_packet_used = 0;
591 p_sys->i_packet_length = 0;
592 p_sys->p_packet = NULL;
594 GenerateGuid ( &p_sys->guid );
596 if( OpenConnection( p_access ) )
599 net_Printf( p_access, p_sys->fd,
601 "User-Agent: "MMSH_USER_AGENT"\r\n"
602 "Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=0:0,request-context=%d,max-duration=0\r\n"
603 "Pragma: xClientGUID={"GUID_FMT"}\r\n"
604 "Connection: Close\r\n",
605 p_sys->i_request_context++,
606 GUID_PRINT( p_sys->guid ) );
608 if( net_Printf( p_access, p_sys->fd, "\r\n" ) < 0 )
610 msg_Err( p_access, "failed to send request" );
614 /* Receive the http header */
615 if( ( psz = net_Gets( p_access, p_sys->fd ) ) == NULL )
617 msg_Err( p_access, "failed to read answer" );
621 if( strncmp( psz, "HTTP/1.", 7 ) )
623 msg_Err( p_access, "invalid HTTP reply '%s'", psz );
627 i_code = atoi( &psz[9] );
630 msg_Err( p_access, "error: %s", psz );
635 msg_Dbg( p_access, "HTTP reply '%s'", psz );
639 char *psz = net_Gets( p_access, p_sys->fd );
644 msg_Err( p_access, "failed to read answer" );
645 free( psz_location );
655 if( ( p = strchr( psz, ':' ) ) == NULL )
657 msg_Err( p_access, "malformed header line: %s", psz );
659 free( psz_location );
663 while( *p == ' ' ) p++;
665 /* FIXME FIXME test Content-Type to see if it's a plain stream or an
667 if( !strcasecmp( psz, "Pragma" ) )
669 if( strstr( p, "features" ) )
671 /* FIXME, it is a bit badly done here ..... */
672 if( strstr( p, "broadcast" ) )
674 msg_Dbg( p_access, "stream type = broadcast" );
675 p_sys->b_broadcast = true;
677 else if( strstr( p, "seekable" ) )
679 msg_Dbg( p_access, "stream type = seekable" );
680 p_sys->b_broadcast = false;
684 msg_Warn( p_access, "unknow stream types (%s)", p );
685 p_sys->b_broadcast = false;
689 else if( !strcasecmp( psz, "Location" ) )
691 free( psz_location );
692 psz_location = strdup( p );
694 else if( !strcasecmp( psz, "Content-Length" ) )
696 i_content_length = atoi( p );
697 msg_Dbg( p_access, "content-length = %d", i_content_length );
699 else if( !strcasecmp( psz, "Connection" ) )
701 if( strcasestr( p, "Keep-Alive" ) )
703 msg_Dbg( p_access, "Keep-Alive header found" );
712 /* Handle the redirection */
713 if( ( (i_code == 301) || (i_code == 302) ||
714 (i_code == 303) || (i_code == 307) ) &&
715 psz_location && *psz_location )
717 msg_Dbg( p_access, "redirection to %s", psz_location );
718 net_Close( p_sys->fd ); p_sys->fd = -1;
720 *ppsz_location = psz_location;
723 free( psz_location );
725 /* Read the asf header */
726 GetHeader( p_access, b_keepalive ? i_content_length : -1);
727 if( p_sys->i_header <= 0 )
729 msg_Err( p_access, "header size == 0" );
732 /* close this connection */
733 net_Close( p_sys->fd );
736 /* *** parse header and get stream and their id *** */
737 /* get all streams properties,
739 * TODO : stream bitrates properties(optional)
740 * and bitrate mutual exclusion(optional) */
741 asf_HeaderParse ( &p_sys->asfh,
742 p_sys->p_header, p_sys->i_header );
743 msg_Dbg( p_access, "packet count=%"PRId64" packet size=%d",
744 p_sys->asfh.i_data_packets_count,
745 p_sys->asfh.i_min_data_packet_size );
747 if( p_sys->asfh.i_min_data_packet_size <= 0 )
750 asf_StreamSelect( &p_sys->asfh,
751 var_InheritInteger( p_access, "mms-maxbitrate" ),
752 var_InheritBool( p_access, "mms-all" ),
753 var_InheritBool( p_access, "audio" ),
754 var_InheritBool( p_access, "video" ) );
760 net_Close( p_sys->fd );
766 static void GetHeader( access_t *p_access, int i_content_length )
768 access_sys_t *p_sys = p_access->p_sys;
769 int i_read_content = 0;
771 /* Read the asf header */
773 free( p_sys->p_header );
774 p_sys->p_header = NULL;
778 if( (i_content_length >= 0 && i_read_content >= i_content_length) || GetPacket( p_access, &ck ) || ck.i_type != 0x4824 )
781 i_read_content += (4+ck.i_size);
785 p_sys->i_header += ck.i_data;
786 p_sys->p_header = xrealloc( p_sys->p_header, p_sys->i_header );
787 memcpy( &p_sys->p_header[p_sys->i_header - ck.i_data],
788 ck.p_data, ck.i_data );
791 msg_Dbg( p_access, "complete header size=%d", p_sys->i_header );
795 /*****************************************************************************
797 ****************************************************************************/
798 static int Start( access_t *p_access, uint64_t i_pos )
800 access_sys_t *p_sys = p_access->p_sys;
802 int i_streams_selected = 0;
806 msg_Dbg( p_access, "starting stream" );
808 for( i = 1; i < 128; i++ )
810 if( p_sys->asfh.stream[i].i_cat == ASF_CODEC_TYPE_UNKNOWN )
813 if( p_sys->asfh.stream[i].i_selected )
814 i_streams_selected++;
816 if( i_streams_selected <= 0 )
818 msg_Err( p_access, "no stream selected" );
822 if( OpenConnection( p_access ) )
825 net_Printf( p_access, p_sys->fd,
827 "User-Agent: "MMSH_USER_AGENT"\r\n" );
828 if( p_sys->b_broadcast )
830 net_Printf( p_access, p_sys->fd,
831 "Pragma: no-cache,rate=1.000000,request-context=%d\r\n",
832 p_sys->i_request_context++ );
836 net_Printf( p_access, p_sys->fd,
837 "Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=%u:%u,request-context=%d,max-duration=0\r\n",
838 (uint32_t)((i_pos >> 32)&0xffffffff),
839 (uint32_t)(i_pos&0xffffffff),
840 p_sys->i_request_context++ );
842 net_Printf( p_access, p_sys->fd,
843 "Pragma: xPlayStrm=1\r\n"
844 "Pragma: xClientGUID={"GUID_FMT"}\r\n"
845 "Pragma: stream-switch-count=%d\r\n"
846 "Pragma: stream-switch-entry=",
847 GUID_PRINT( p_sys->guid ),
850 for( i = 1; i < 128; i++ )
852 if( p_sys->asfh.stream[i].i_cat != ASF_CODEC_TYPE_UNKNOWN )
855 if( p_sys->asfh.stream[i].i_selected )
859 net_Printf( p_access, p_sys->fd, "ffff:%x:%d ", i, i_select );
862 net_Printf( p_access, p_sys->fd, "\r\n" );
863 net_Printf( p_access, p_sys->fd, "Connection: Close\r\n" );
865 if( net_Printf( p_access, p_sys->fd, "\r\n" ) < 0 )
867 msg_Err( p_access, "failed to send request" );
871 psz = net_Gets( p_access, p_sys->fd );
874 msg_Err( p_access, "cannot read data 0" );
878 if( atoi( &psz[9] ) >= 400 )
880 msg_Err( p_access, "error: %s", psz );
884 msg_Dbg( p_access, "HTTP reply '%s'", psz );
887 /* FIXME check HTTP code */
890 char *psz = net_Gets( p_access, p_sys->fd );
893 msg_Err( p_access, "cannot read data 1" );
901 msg_Dbg( p_access, "%s", psz );
905 p_sys->i_packet_used = 0;
906 p_sys->i_packet_length = 0;
911 /*****************************************************************************
913 *****************************************************************************/
914 static void Stop( access_t *p_access )
916 access_sys_t *p_sys = p_access->p_sys;
918 msg_Dbg( p_access, "closing stream" );
921 net_Close( p_sys->fd );
926 /*****************************************************************************
928 *****************************************************************************/
929 static int GetPacket( access_t * p_access, chunk_t *p_ck )
931 access_sys_t *p_sys = p_access->p_sys;
935 memset( p_ck, 0, sizeof( chunk_t ) );
937 /* Read the chunk header */
938 /* Some headers are short, like 0x4324. Reading 12 bytes will cause us
939 * to lose synchronization with the stream. Just read to the length
940 * (4 bytes), decode and then read up to 8 additional bytes to get the
943 if( net_Read( p_access, p_sys->fd, p_sys->buffer, 4 ) < 4 )
945 msg_Err( p_access, "cannot read data 2" );
949 p_ck->i_type = GetWLE( p_sys->buffer);
950 p_ck->i_size = GetWLE( p_sys->buffer + 2);
952 restsize = p_ck->i_size;
956 if( net_Read( p_access, p_sys->fd, p_sys->buffer + 4, restsize ) < restsize )
958 msg_Err( p_access, "cannot read data 3" );
961 p_ck->i_sequence = GetDWLE( p_sys->buffer + 4);
962 p_ck->i_unknown = GetWLE( p_sys->buffer + 8);
964 /* Set i_size2 to 8 if this header was short, since a real value won't be
965 * present in the buffer. Using 8 avoid reading additional data for the
971 p_ck->i_size2 = GetWLE( p_sys->buffer + 10);
973 p_ck->p_data = p_sys->buffer + 12;
974 p_ck->i_data = p_ck->i_size2 - 8;
976 if( p_ck->i_type == 0x4524 ) // $E (End-of-Stream Notification) Packet
978 if( p_ck->i_sequence == 0 )
980 msg_Warn( p_access, "EOF" );
985 msg_Warn( p_access, "next stream following" );
989 else if( p_ck->i_type == 0x4324 ) // $C (Stream Change Notification) Packet
991 /* 0x4324 is CHUNK_TYPE_RESET: a new stream will follow with a sequence of 0 */
992 msg_Warn( p_access, "next stream following (reset) seq=%d", p_ck->i_sequence );
995 else if( (p_ck->i_type != 0x4824) && (p_ck->i_type != 0x4424) )
997 /* Unsupported so far:
998 * $M (Metadata) Packet 0x4D24
999 * $P (Packet-Pair) Packet 0x5024
1000 * $T (Test Data Notification) Packet 0x5424
1002 msg_Err( p_access, "unrecognized chunk FATAL (0x%x)", p_ck->i_type );
1003 return VLC_EGENERIC;
1006 if( (p_ck->i_data > 0) &&
1007 (net_Read( p_access, p_sys->fd, &p_sys->buffer[12],
1008 p_ck->i_data ) < p_ck->i_data) )
1010 msg_Err( p_access, "cannot read data 4" );
1011 return VLC_EGENERIC;
1015 if( (p_sys->i_packet_sequence != 0) &&
1016 (p_ck->i_sequence != p_sys->i_packet_sequence) )
1018 msg_Warn( p_access, "packet lost ? (%d != %d)", p_ck->i_sequence, p_sys->i_packet_sequence );
1022 p_sys->i_packet_sequence = p_ck->i_sequence + 1;
1023 p_sys->i_packet_used = 0;
1024 p_sys->i_packet_length = p_ck->i_data;
1025 p_sys->p_packet = p_ck->p_data;