]> git.sesse.net Git - vlc/blob - modules/access/mms/mmsh.c
445f582d115799656edb0c7accd4d42d4c24d8a4
[vlc] / modules / access / mms / mmsh.c
1 /*****************************************************************************
2  * mmsh.c:
3  *****************************************************************************
4  * Copyright (C) 2001, 2002 VideoLAN
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *
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.
13  *
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.
18  *
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>
28
29 #include <vlc/vlc.h>
30 #include <vlc/input.h>
31
32 #include "vlc_playlist.h"
33
34 #include "network.h"
35 #include "asf.h"
36 #include "buffer.h"
37
38 #include "mms.h"
39 #include "mmsh.h"
40
41 /* TODO:
42  *  - http_proxy
43  *  - authentication
44  */
45
46 /*****************************************************************************
47  * Local prototypes
48  *****************************************************************************/
49 int  E_(MMSHOpen)  ( access_t * );
50 void E_(MMSHClose) ( access_t * );
51
52 static int  Read( access_t *, uint8_t *, int );
53 static int  ReadRedirect( access_t *, uint8_t *, int );
54 static int  Seek( access_t *, int64_t );
55 static int  Control( access_t *, int, va_list );
56
57 static int  Describe( access_t  *, char **ppsz_location );
58 static int  Start( access_t *, int64_t );
59 static void Stop( access_t * );
60 static int  GetPacket( access_t *, chunk_t * );
61
62 /****************************************************************************
63  * Open: connect to ftp server and ask for file
64  ****************************************************************************/
65 int E_(MMSHOpen)( access_t *p_access )
66 {
67     access_sys_t    *p_sys;
68     char            *psz_location = NULL;
69
70     /* init p_sys */
71
72     /* Set up p_access */
73     p_access->pf_read = Read;
74     p_access->pf_block = NULL;
75     p_access->pf_control = Control;
76     p_access->pf_seek = Seek;
77     p_access->info.i_update = 0;
78     p_access->info.i_size = 0;
79     p_access->info.i_pos = 0;
80     p_access->info.b_eof = VLC_FALSE;
81     p_access->info.i_title = 0;
82     p_access->info.i_seekpoint = 0;
83     p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) );
84     memset( p_sys, 0, sizeof( access_sys_t ) );
85     p_sys->i_proto= MMS_PROTO_HTTP;
86     p_sys->fd     = -1;
87     p_sys->i_start= 0;
88
89     /* open a tcp connection */
90     vlc_UrlParse( &p_sys->url, p_access->psz_path, 0 );
91     if( p_sys->url.psz_host == NULL || *p_sys->url.psz_host == '\0' )
92     {
93         msg_Err( p_access, "invalid host" );
94         vlc_UrlClean( &p_sys->url );
95         free( p_sys );
96         return VLC_EGENERIC;
97     }
98     if( p_sys->url.i_port <= 0 )
99         p_sys->url.i_port = 80;
100
101     if( Describe( p_access, &psz_location ) )
102     {
103         vlc_UrlClean( &p_sys->url );
104         free( p_sys );
105         return VLC_EGENERIC;
106     }
107     /* Handle redirection */
108     if( psz_location && *psz_location )
109     {
110         playlist_t * p_playlist = vlc_object_find( p_access, VLC_OBJECT_PLAYLIST, FIND_PARENT );
111
112         msg_Dbg( p_access, "redirection to %s", psz_location );
113
114         if( !p_playlist )
115         {
116             msg_Err( p_access, "redirection failed: can't find playlist" );
117             free( psz_location );
118             return VLC_EGENERIC;
119         }
120         p_playlist->pp_items[p_playlist->i_index]->b_autodeletion = VLC_TRUE;
121         playlist_Add( p_playlist, psz_location, psz_location,
122                       PLAYLIST_INSERT | PLAYLIST_GO,
123                       p_playlist->i_index + 1 );
124         vlc_object_release( p_playlist );
125
126         free( psz_location );
127
128         p_access->pf_read = ReadRedirect;
129         return VLC_SUCCESS;
130     }
131
132     /* Start playing */
133     if( Start( p_access, 0 ) )
134     {
135         msg_Err( p_access, "cannot start stream" );
136         free( p_sys->p_header );
137         vlc_UrlClean( &p_sys->url );
138         free( p_sys );
139         return VLC_EGENERIC;
140     }
141
142     if( !p_sys->b_broadcast )
143     {
144         p_access->info.i_size = p_sys->asfh.i_file_size;
145     }
146
147     return VLC_SUCCESS;
148 }
149
150 /*****************************************************************************
151  * Close: free unused data structures
152  *****************************************************************************/
153 void E_( MMSHClose )( access_t *p_access )
154 {
155     access_sys_t *p_sys = p_access->p_sys;
156
157     Stop( p_access );
158     free( p_sys );
159 }
160
161 /*****************************************************************************
162  * Control:
163  *****************************************************************************/
164 static int Control( access_t *p_access, int i_query, va_list args )
165 {
166     access_sys_t *p_sys = p_access->p_sys;
167     vlc_bool_t   *pb_bool;
168     int          *pi_int;
169     int64_t      *pi_64;
170
171     switch( i_query )
172     {
173         /* */
174         case ACCESS_CAN_SEEK:
175             pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
176             *pb_bool = !p_sys->b_broadcast;
177             break;
178         case ACCESS_CAN_FASTSEEK:
179         case ACCESS_CAN_PAUSE:
180         case ACCESS_CAN_CONTROL_PACE:
181             pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
182             *pb_bool = VLC_FALSE;
183             break;
184
185         /* */
186         case ACCESS_GET_MTU:
187             pi_int = (int*)va_arg( args, int * );
188             *pi_int = 3 * p_sys->asfh.i_min_data_packet_size;
189             break;
190
191         case ACCESS_GET_PTS_DELAY:
192             pi_64 = (int64_t*)va_arg( args, int64_t * );
193             *pi_64 = (int64_t)var_GetInteger( p_access, "mms-caching" ) * I64C(1000);
194             break;
195
196         /* */
197         case ACCESS_SET_PAUSE_STATE:
198         case ACCESS_GET_TITLE_INFO:
199         case ACCESS_SET_TITLE:
200         case ACCESS_SET_SEEKPOINT:
201             return VLC_EGENERIC;
202
203         default:
204             msg_Err( p_access, "unimplemented query in control" );
205             return VLC_EGENERIC;
206
207     }
208     return VLC_SUCCESS;
209 }
210
211 /*****************************************************************************
212  * Seek: try to go at the right place
213  *****************************************************************************/
214 static int Seek( access_t *p_access, int64_t i_pos )
215 {
216     access_sys_t *p_sys = p_access->p_sys;
217     chunk_t      ck;
218     off_t        i_offset;
219     off_t        i_packet;
220
221     msg_Dbg( p_access, "seeking to "I64Fd, i_pos );
222
223     i_packet = ( i_pos - p_sys->i_header ) / p_sys->asfh.i_min_data_packet_size;
224     i_offset = ( i_pos - p_sys->i_header ) % p_sys->asfh.i_min_data_packet_size;
225
226     Stop( p_access );
227     Start( p_access, i_packet * p_sys->asfh.i_min_data_packet_size );
228
229     while( !p_access->b_die )
230     {
231         if( GetPacket( p_access, &ck ) )
232             break;
233
234         /* skip headers */
235         if( ck.i_type != 0x4824 )
236             break;
237
238         msg_Warn( p_access, "skipping header" );
239     }
240
241     p_access->info.i_pos = i_pos;
242     p_access->info.b_eof = VLC_FALSE;
243     p_sys->i_packet_used += i_offset;
244
245     return VLC_SUCCESS;
246 }
247
248 /*****************************************************************************
249  * Read:
250  *****************************************************************************/
251 static int ReadRedirect( access_t *p_access, uint8_t *p, int i_len )
252 {
253     return 0;
254 }
255
256 /*****************************************************************************
257  * Read:
258  *****************************************************************************/
259 static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
260 {
261     access_sys_t *p_sys = p_access->p_sys;
262     size_t       i_copy;
263     size_t       i_data = 0;
264
265     if( p_access->info.b_eof )
266         return 0;
267
268     while( i_data < i_len )
269     {
270         if( p_access->info.i_pos < p_sys->i_start + p_sys->i_header )
271         {
272             int i_offset = p_access->info.i_pos - p_sys->i_start;
273             i_copy = __MIN( p_sys->i_header - i_offset, i_len - i_data );
274             memcpy( &p_buffer[i_data], &p_sys->p_header[i_offset], i_copy );
275
276             i_data += i_copy;
277             p_access->info.i_pos += i_copy;
278         }
279         else if( p_sys->i_packet_used < p_sys->i_packet_length )
280         {
281             i_copy = __MIN( p_sys->i_packet_length - p_sys->i_packet_used,
282                             i_len - i_data );
283
284             memcpy( &p_buffer[i_data],
285                     &p_sys->p_packet[p_sys->i_packet_used],
286                     i_copy );
287
288             i_data += i_copy;
289             p_sys->i_packet_used += i_copy;
290             p_access->info.i_pos += i_copy;
291         }
292         else if( p_sys->i_packet_length > 0 &&
293                  (int)p_sys->i_packet_used < p_sys->asfh.i_min_data_packet_size )
294         {
295             i_copy = __MIN( p_sys->asfh.i_min_data_packet_size - p_sys->i_packet_used,
296                             i_len - i_data );
297
298             memset( &p_buffer[i_data], 0, i_copy );
299
300             i_data += i_copy;
301             p_sys->i_packet_used += i_copy;
302             p_access->info.i_pos += i_copy;
303         }
304         else
305         {
306             chunk_t ck;
307             if( GetPacket( p_access, &ck ) )
308             {
309                 if( ck.i_type == 0x4524 && ck.i_sequence != 0 && p_sys->b_broadcast )
310                 {
311                     char *psz_location = NULL;
312
313                     p_sys->i_start = p_access->info.i_pos;
314
315                     msg_Dbg( p_access, "stoping the stream" );
316                     Stop( p_access );
317
318                     msg_Dbg( p_access, "describe the stream" );
319                     if( Describe( p_access, &psz_location ) )
320                     {
321                         msg_Err( p_access, "describe failed" );
322                         p_access->info.b_eof = VLC_TRUE;
323                         return 0;
324                     }
325                     if( Start( p_access, 0 ) )
326                     {
327                         msg_Err( p_access, "Start failed" );
328                         p_access->info.b_eof = VLC_TRUE;
329                         return 0;
330                     }
331                 }
332                 else
333                 {
334                     p_access->info.b_eof = VLC_TRUE;
335                     return 0;
336                 }
337             }
338             if( ck.i_type != 0x4424 )
339             {
340                 p_sys->i_packet_used = 0;
341                 p_sys->i_packet_length = 0;
342             }
343         }
344     }
345
346     return( i_data );
347 }
348
349 /*****************************************************************************
350  * Describe:
351  *****************************************************************************/
352 static int Describe( access_t  *p_access, char **ppsz_location )
353 {
354     access_sys_t *p_sys = p_access->p_sys;
355     char         *psz_location = NULL;
356     char         *psz;
357     int          i_code;
358
359     /* Reinit context */
360     p_sys->b_broadcast = VLC_TRUE;
361     p_sys->i_request_context = 1;
362     p_sys->i_packet_sequence = 0;
363     p_sys->i_packet_used = 0;
364     p_sys->i_packet_length = 0;
365     p_sys->p_packet = NULL;
366     E_( GenerateGuid )( &p_sys->guid );
367
368     if( ( p_sys->fd = net_OpenTCP( p_access, p_sys->url.psz_host,
369                                             p_sys->url.i_port ) ) < 0 )
370     {
371         msg_Err( p_access, "cannot connect to%s:%d", p_sys->url.psz_host, p_sys->url.i_port );
372         goto error;
373     }
374
375     /* send first request */
376     net_Printf( VLC_OBJECT(p_access), p_sys->fd,
377                 "GET %s HTTP/1.0\r\n"
378                 "Accept: */*\r\n"
379                 "User-Agent: NSPlayer/4.1.0.3856\r\n"
380                 "Host: %s:%d\r\n"
381                 "Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=0:0,request-context=%d,max-duration=0\r\n"
382                 "Pragma: xClientGUID={"GUID_FMT"}\r\n"
383                 "Connection: Close\r\n",
384                 ( p_sys->url.psz_path == NULL || *p_sys->url.psz_path == '\0' ) ? "/" : p_sys->url.psz_path,
385                 p_sys->url.psz_host, p_sys->url.i_port,
386                 p_sys->i_request_context++,
387                 GUID_PRINT( p_sys->guid ) );
388
389     if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, "\r\n" ) < 0 )
390     {
391         msg_Err( p_access, "failed to send request" );
392         goto error;
393     }
394
395     /* Receive the http header */
396     if( ( psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd ) ) == NULL )
397     {
398         msg_Err( p_access, "failed to read answer" );
399         goto error;
400     }
401     if( strncmp( psz, "HTTP/1.", 7 ) )
402     {
403         msg_Err( p_access, "invalid HTTP reply '%s'", psz );
404         free( psz );
405         goto error;
406     }
407     i_code = atoi( &psz[9] );
408     if( i_code >= 400 )
409     {
410         msg_Err( p_access, "error: %s", psz );
411         free( psz );
412         goto error;
413     }
414
415     msg_Dbg( p_access, "HTTP reply '%s'", psz );
416     free( psz );
417     for( ;; )
418     {
419         char *psz = net_Gets( p_access, p_sys->fd );
420         char *p;
421
422         if( psz == NULL )
423         {
424             msg_Err( p_access, "failed to read answer" );
425             goto error;
426         }
427
428         if( *psz == '\0' )
429         {
430             free( psz );
431             break;
432         }
433
434         if( ( p = strchr( psz, ':' ) ) == NULL )
435         {
436             msg_Err( p_access, "malformed header line: %s", psz );
437             free( psz );
438             goto error;
439         }
440         *p++ = '\0';
441         while( *p == ' ' ) p++;
442
443         /* FIXME FIXME test Content-Type to see if it's a plain stream or an
444          * asx FIXME */
445         if( !strcasecmp( psz, "Pragma" ) )
446         {
447             if( strstr( p, "features" ) )
448             {
449                 /* FIXME, it is a bit badly done here ..... */
450                 if( strstr( p, "broadcast" ) )
451                 {
452                     msg_Dbg( p_access, "stream type = broadcast" );
453                     p_sys->b_broadcast = VLC_TRUE;
454                 }
455                 else if( strstr( p, "seekable" ) )
456                 {
457                     msg_Dbg( p_access, "stream type = seekable" );
458                     p_sys->b_broadcast = VLC_FALSE;
459                 }
460                 else
461                 {
462                     msg_Warn( p_access, "unknow stream types (%s)", p );
463                     p_sys->b_broadcast = VLC_FALSE;
464                 }
465             }
466         }
467         else if( !strcasecmp( psz, "Location" ) )
468         {
469             psz_location = strdup( p );
470         }
471
472         free( psz );
473     }
474
475     /* Handle the redirection */
476     if( ( i_code == 301 || i_code == 302 ||
477           i_code == 303 || i_code == 307 ) &&
478         psz_location && *psz_location )
479     {
480         msg_Dbg( p_access, "redirection to %s", psz_location );
481         net_Close( p_sys->fd ); p_sys->fd = -1;
482
483         *ppsz_location = psz_location;
484         return VLC_SUCCESS;
485     }
486
487     /* Read the asf header */
488     p_sys->i_header = 0;
489     p_sys->p_header = NULL;
490     for( ;; )
491     {
492         chunk_t ck;
493         if( GetPacket( p_access, &ck ) ||
494             ck.i_type != 0x4824 )
495         {
496             break;
497         }
498
499         if( ck.i_data > 0 )
500         {
501             p_sys->i_header += ck.i_data;
502             p_sys->p_header = realloc( p_sys->p_header, p_sys->i_header );
503             memcpy( &p_sys->p_header[p_sys->i_header - ck.i_data],
504                     ck.p_data, ck.i_data );
505         }
506     }
507     msg_Dbg( p_access, "complete header size=%d", p_sys->i_header );
508     if( p_sys->i_header <= 0 )
509     {
510         msg_Err( p_access, "header size == 0" );
511         goto error;
512     }
513     /* close this connection */
514     net_Close( p_sys->fd ); p_sys->fd = -1;
515
516     /* *** parse header and get stream and their id *** */
517     /* get all streams properties,
518      *
519      * TODO : stream bitrates properties(optional)
520      *        and bitrate mutual exclusion(optional) */
521     E_( asf_HeaderParse )( &p_sys->asfh,
522                            p_sys->p_header, p_sys->i_header );
523     msg_Dbg( p_access, "packet count=%lld packet size=%d",
524              p_sys->asfh.i_data_packets_count,
525              p_sys->asfh.i_min_data_packet_size );
526
527     E_( asf_StreamSelect)( &p_sys->asfh,
528                            var_CreateGetInteger( p_access, "mms-maxbitrate" ),
529                            var_CreateGetInteger( p_access, "mms-all" ),
530                            var_CreateGetInteger( p_access, "audio" ),
531                            var_CreateGetInteger( p_access, "video" ) );
532
533     return VLC_SUCCESS;
534
535 error:
536     if( p_sys->fd > 0 )
537     {
538         net_Close( p_sys->fd  );
539         p_sys->fd = -1;
540     }
541     return VLC_EGENERIC;
542 }
543
544 /*****************************************************************************
545  *
546  *****************************************************************************/
547 static int Start( access_t *p_access, off_t i_pos )
548 {
549     access_sys_t *p_sys = p_access->p_sys;
550     int  i_streams = 0;
551     int  i;
552     char *psz;
553
554     msg_Dbg( p_access, "starting stream" );
555
556     if( ( p_sys->fd = net_OpenTCP( p_access, p_sys->url.psz_host,
557                                             p_sys->url.i_port ) ) < 0 )
558     {
559         /* should not occur */
560         msg_Err( p_access, "cannot connect to the server" );
561         return VLC_EGENERIC;
562     }
563
564     for( i = 1; i < 128; i++ )
565     {
566         if( p_sys->asfh.stream[i].i_selected )
567         {
568             i_streams++;
569         }
570     }
571
572     if( i_streams <= 0 )
573     {
574         msg_Err( p_access, "no stream selected" );
575         return VLC_EGENERIC;
576     }
577     net_Printf( VLC_OBJECT(p_access), p_sys->fd,
578                 "GET %s HTTP/1.0\r\n"
579                 "Accept: */*\r\n"
580                 "User-Agent: NSPlayer/4.1.0.3856\r\n"
581                 "Host: %s:%d\r\n",
582                 ( p_sys->url.psz_path == NULL || *p_sys->url.psz_path == '\0' ) ? "/" : p_sys->url.psz_path,
583                 p_sys->url.psz_host, p_sys->url.i_port );
584     if( p_sys->b_broadcast )
585     {
586         net_Printf( VLC_OBJECT(p_access), p_sys->fd,
587                     "Pragma: no-cache,rate=1.000000,request-context=%d\r\n",
588                     p_sys->i_request_context++ );
589     }
590     else
591     {
592         net_Printf( VLC_OBJECT(p_access), p_sys->fd,
593                     "Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=%u:%u,request-context=%d,max-duration=0\r\n",
594                     (uint32_t)((i_pos >> 32)&0xffffffff),
595                     (uint32_t)(i_pos&0xffffffff),
596                     p_sys->i_request_context++ );
597     }
598     net_Printf( VLC_OBJECT(p_access), p_sys->fd,
599                 "Pragma: xPlayStrm=1\r\n"
600                 "Pragma: xClientGUID={"GUID_FMT"}\r\n"
601                 "Pragma: stream-switch-count=%d\r\n"
602                 "Pragma: stream-switch-entry=",
603                 GUID_PRINT( p_sys->guid ),
604                 i_streams);
605
606     for( i = 1; i < 128; i++ )
607     {
608         if( p_sys->asfh.stream[i].i_cat != ASF_STREAM_UNKNOWN )
609         {
610             int i_select = 2;
611             if( p_sys->asfh.stream[i].i_selected )
612             {
613                 i_select = 0;
614             }
615
616             net_Printf( VLC_OBJECT(p_access), p_sys->fd,
617                         "ffff:%d:%d ", i, i_select );
618         }
619     }
620     net_Printf( VLC_OBJECT(p_access), p_sys->fd, "\r\n" );
621     net_Printf( VLC_OBJECT(p_access), p_sys->fd, "Connection: Close\r\n" );
622
623     if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, "\r\n" ) < 0 )
624     {
625         msg_Err( p_access, "failed to send request" );
626         return VLC_EGENERIC;
627     }
628
629     if( ( psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd ) ) == NULL )
630     {
631         msg_Err( p_access, "cannot read data" );
632         return VLC_EGENERIC;
633     }
634     if( atoi( &psz[9] ) >= 400 )
635     {
636         msg_Err( p_access, "error: %s", psz );
637         free( psz );
638         return VLC_EGENERIC;
639     }
640     msg_Dbg( p_access, "HTTP reply '%s'", psz );
641     free( psz );
642
643     /* FIXME check HTTP code */
644     for( ;; )
645     {
646         char *psz = net_Gets( p_access, p_sys->fd );
647         if( psz == NULL )
648         {
649             msg_Err( p_access, "cannot read data" );
650             return VLC_EGENERIC;
651         }
652         if( *psz == '\0' )
653         {
654             free( psz );
655             break;
656         }
657         msg_Dbg( p_access, "%s", psz );
658         free( psz );
659     }
660
661     p_sys->i_packet_used   = 0;
662     p_sys->i_packet_length = 0;
663
664     return VLC_SUCCESS;
665 }
666
667 /*****************************************************************************
668  *
669  *****************************************************************************/
670 static void Stop( access_t *p_access )
671 {
672     access_sys_t *p_sys = p_access->p_sys;
673
674     msg_Dbg( p_access, "closing stream" );
675     if( p_sys->fd > 0 )
676     {
677         net_Close( p_sys->fd );
678         p_sys->fd = -1;
679     }
680 }
681
682 /*****************************************************************************
683  *
684  *****************************************************************************/
685 static int GetPacket( access_t * p_access, chunk_t *p_ck )
686 {
687     access_sys_t *p_sys = p_access->p_sys;
688
689     /* chunk_t */
690     memset( p_ck, 0, sizeof( chunk_t ) );
691
692     /* Read the chunk header */
693     if( net_Read( p_access, p_sys->fd, p_sys->buffer, 12, VLC_TRUE ) < 12 )
694     {
695         /* msg_Err( p_access, "cannot read data" ); */
696         return VLC_EGENERIC;
697     }
698
699     p_ck->i_type      = GetWLE( p_sys->buffer);
700     p_ck->i_size      = GetWLE( p_sys->buffer + 2);
701     p_ck->i_sequence  = GetDWLE( p_sys->buffer + 4);
702     p_ck->i_unknown   = GetWLE( p_sys->buffer + 8);
703     p_ck->i_size2     = GetWLE( p_sys->buffer + 10);
704     p_ck->p_data      = p_sys->buffer + 12;
705     p_ck->i_data      = p_ck->i_size2 - 8;
706
707     if( p_ck->i_type == 0x4524 )   // Transfer complete
708     {
709         if( p_ck->i_sequence == 0 )
710         {
711             msg_Warn( p_access, "EOF" );
712             return VLC_EGENERIC;
713         }
714         else
715         {
716             msg_Warn( p_access, "Next stream follow but not supported" );
717             return VLC_EGENERIC;
718         }
719     }
720     else if( p_ck->i_type != 0x4824 && p_ck->i_type != 0x4424 )
721     {
722         msg_Err( p_access, "invalid chunk FATAL (0x%x)", p_ck->i_type );
723         return VLC_EGENERIC;
724     }
725
726     if( p_ck->i_data > 0 &&
727         net_Read( p_access, p_sys->fd, &p_sys->buffer[12], p_ck->i_data, VLC_TRUE ) < p_ck->i_data )
728     {
729         msg_Err( p_access, "cannot read data" );
730         return VLC_EGENERIC;
731     }
732
733     if( p_sys->i_packet_sequence != 0 &&
734         p_ck->i_sequence != p_sys->i_packet_sequence )
735     {
736         msg_Warn( p_access, "packet lost ? (%d != %d)", p_ck->i_sequence, p_sys->i_packet_sequence );
737     }
738
739     p_sys->i_packet_sequence = p_ck->i_sequence + 1;
740     p_sys->i_packet_used   = 0;
741     p_sys->i_packet_length = p_ck->i_data;
742     p_sys->p_packet        = p_ck->p_data;
743
744     return VLC_SUCCESS;
745 }