]> git.sesse.net Git - vlc/blob - modules/access/mms/mmsh.c
net_* API update for encryption (recv / send virtualization)
[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         case ACCESS_SET_PRIVATE_ID_STATE:
202             return VLC_EGENERIC;
203
204         default:
205             msg_Warn( p_access, "unimplemented query in control" );
206             return VLC_EGENERIC;
207
208     }
209     return VLC_SUCCESS;
210 }
211
212 /*****************************************************************************
213  * Seek: try to go at the right place
214  *****************************************************************************/
215 static int Seek( access_t *p_access, int64_t i_pos )
216 {
217     access_sys_t *p_sys = p_access->p_sys;
218     chunk_t      ck;
219     off_t        i_offset;
220     off_t        i_packet;
221
222     msg_Dbg( p_access, "seeking to "I64Fd, i_pos );
223
224     i_packet = ( i_pos - p_sys->i_header ) / p_sys->asfh.i_min_data_packet_size;
225     i_offset = ( i_pos - p_sys->i_header ) % p_sys->asfh.i_min_data_packet_size;
226
227     Stop( p_access );
228     Start( p_access, i_packet * p_sys->asfh.i_min_data_packet_size );
229
230     while( !p_access->b_die )
231     {
232         if( GetPacket( p_access, &ck ) )
233             break;
234
235         /* skip headers */
236         if( ck.i_type != 0x4824 )
237             break;
238
239         msg_Warn( p_access, "skipping header" );
240     }
241
242     p_access->info.i_pos = i_pos;
243     p_access->info.b_eof = VLC_FALSE;
244     p_sys->i_packet_used += i_offset;
245
246     return VLC_SUCCESS;
247 }
248
249 /*****************************************************************************
250  * Read:
251  *****************************************************************************/
252 static int ReadRedirect( access_t *p_access, uint8_t *p, int i_len )
253 {
254     return 0;
255 }
256
257 /*****************************************************************************
258  * Read:
259  *****************************************************************************/
260 static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
261 {
262     access_sys_t *p_sys = p_access->p_sys;
263     size_t       i_copy;
264     size_t       i_data = 0;
265
266     if( p_access->info.b_eof )
267         return 0;
268
269     while( i_data < i_len )
270     {
271         if( p_access->info.i_pos < p_sys->i_start + p_sys->i_header )
272         {
273             int i_offset = p_access->info.i_pos - p_sys->i_start;
274             i_copy = __MIN( p_sys->i_header - i_offset, i_len - i_data );
275             memcpy( &p_buffer[i_data], &p_sys->p_header[i_offset], i_copy );
276
277             i_data += i_copy;
278             p_access->info.i_pos += i_copy;
279         }
280         else if( p_sys->i_packet_used < p_sys->i_packet_length )
281         {
282             i_copy = __MIN( p_sys->i_packet_length - p_sys->i_packet_used,
283                             i_len - i_data );
284
285             memcpy( &p_buffer[i_data],
286                     &p_sys->p_packet[p_sys->i_packet_used],
287                     i_copy );
288
289             i_data += i_copy;
290             p_sys->i_packet_used += i_copy;
291             p_access->info.i_pos += i_copy;
292         }
293         else if( p_sys->i_packet_length > 0 &&
294                  (int)p_sys->i_packet_used < p_sys->asfh.i_min_data_packet_size )
295         {
296             i_copy = __MIN( p_sys->asfh.i_min_data_packet_size - p_sys->i_packet_used,
297                             i_len - i_data );
298
299             memset( &p_buffer[i_data], 0, i_copy );
300
301             i_data += i_copy;
302             p_sys->i_packet_used += i_copy;
303             p_access->info.i_pos += i_copy;
304         }
305         else
306         {
307             chunk_t ck;
308             if( GetPacket( p_access, &ck ) )
309             {
310                 if( ck.i_type == 0x4524 && ck.i_sequence != 0 && p_sys->b_broadcast )
311                 {
312                     char *psz_location = NULL;
313
314                     p_sys->i_start = p_access->info.i_pos;
315
316                     msg_Dbg( p_access, "stoping the stream" );
317                     Stop( p_access );
318
319                     msg_Dbg( p_access, "describe the stream" );
320                     if( Describe( p_access, &psz_location ) )
321                     {
322                         msg_Err( p_access, "describe failed" );
323                         p_access->info.b_eof = VLC_TRUE;
324                         return 0;
325                     }
326                     if( Start( p_access, 0 ) )
327                     {
328                         msg_Err( p_access, "Start failed" );
329                         p_access->info.b_eof = VLC_TRUE;
330                         return 0;
331                     }
332                 }
333                 else
334                 {
335                     p_access->info.b_eof = VLC_TRUE;
336                     return 0;
337                 }
338             }
339             if( ck.i_type != 0x4424 )
340             {
341                 p_sys->i_packet_used = 0;
342                 p_sys->i_packet_length = 0;
343             }
344         }
345     }
346
347     return( i_data );
348 }
349
350 /*****************************************************************************
351  * Describe:
352  *****************************************************************************/
353 static int Describe( access_t  *p_access, char **ppsz_location )
354 {
355     access_sys_t *p_sys = p_access->p_sys;
356     char         *psz_location = NULL;
357     char         *psz;
358     int          i_code;
359
360     /* Reinit context */
361     p_sys->b_broadcast = VLC_TRUE;
362     p_sys->i_request_context = 1;
363     p_sys->i_packet_sequence = 0;
364     p_sys->i_packet_used = 0;
365     p_sys->i_packet_length = 0;
366     p_sys->p_packet = NULL;
367     E_( GenerateGuid )( &p_sys->guid );
368
369     if( ( p_sys->fd = net_OpenTCP( p_access, p_sys->url.psz_host,
370                                             p_sys->url.i_port ) ) < 0 )
371     {
372         msg_Err( p_access, "cannot connect to %s:%d", p_sys->url.psz_host, p_sys->url.i_port );
373         goto error;
374     }
375
376     /* send first request */
377     net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
378                 "GET %s HTTP/1.0\r\n"
379                 "Accept: */*\r\n"
380                 "User-Agent: NSPlayer/4.1.0.3856\r\n"
381                 "Host: %s:%d\r\n"
382                 "Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=0:0,request-context=%d,max-duration=0\r\n"
383                 "Pragma: xClientGUID={"GUID_FMT"}\r\n"
384                 "Connection: Close\r\n",
385                 ( p_sys->url.psz_path == NULL || *p_sys->url.psz_path == '\0' ) ? "/" : p_sys->url.psz_path,
386                 p_sys->url.psz_host, p_sys->url.i_port,
387                 p_sys->i_request_context++,
388                 GUID_PRINT( p_sys->guid ) );
389
390     if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, "\r\n" ) < 0 )
391     {
392         msg_Err( p_access, "failed to send request" );
393         goto error;
394     }
395
396     /* Receive the http header */
397     if( ( psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL ) ) == NULL )
398     {
399         msg_Err( p_access, "failed to read answer" );
400         goto error;
401     }
402     if( strncmp( psz, "HTTP/1.", 7 ) )
403     {
404         msg_Err( p_access, "invalid HTTP reply '%s'", psz );
405         free( psz );
406         goto error;
407     }
408     i_code = atoi( &psz[9] );
409     if( i_code >= 400 )
410     {
411         msg_Err( p_access, "error: %s", psz );
412         free( psz );
413         goto error;
414     }
415
416     msg_Dbg( p_access, "HTTP reply '%s'", psz );
417     free( psz );
418     for( ;; )
419     {
420         char *psz = net_Gets( p_access, p_sys->fd, NULL );
421         char *p;
422
423         if( psz == NULL )
424         {
425             msg_Err( p_access, "failed to read answer" );
426             goto error;
427         }
428
429         if( *psz == '\0' )
430         {
431             free( psz );
432             break;
433         }
434
435         if( ( p = strchr( psz, ':' ) ) == NULL )
436         {
437             msg_Err( p_access, "malformed header line: %s", psz );
438             free( psz );
439             goto error;
440         }
441         *p++ = '\0';
442         while( *p == ' ' ) p++;
443
444         /* FIXME FIXME test Content-Type to see if it's a plain stream or an
445          * asx FIXME */
446         if( !strcasecmp( psz, "Pragma" ) )
447         {
448             if( strstr( p, "features" ) )
449             {
450                 /* FIXME, it is a bit badly done here ..... */
451                 if( strstr( p, "broadcast" ) )
452                 {
453                     msg_Dbg( p_access, "stream type = broadcast" );
454                     p_sys->b_broadcast = VLC_TRUE;
455                 }
456                 else if( strstr( p, "seekable" ) )
457                 {
458                     msg_Dbg( p_access, "stream type = seekable" );
459                     p_sys->b_broadcast = VLC_FALSE;
460                 }
461                 else
462                 {
463                     msg_Warn( p_access, "unknow stream types (%s)", p );
464                     p_sys->b_broadcast = VLC_FALSE;
465                 }
466             }
467         }
468         else if( !strcasecmp( psz, "Location" ) )
469         {
470             psz_location = strdup( p );
471         }
472
473         free( psz );
474     }
475
476     /* Handle the redirection */
477     if( ( i_code == 301 || i_code == 302 ||
478           i_code == 303 || i_code == 307 ) &&
479         psz_location && *psz_location )
480     {
481         msg_Dbg( p_access, "redirection to %s", psz_location );
482         net_Close( p_sys->fd ); p_sys->fd = -1;
483
484         *ppsz_location = psz_location;
485         return VLC_SUCCESS;
486     }
487
488     /* Read the asf header */
489     p_sys->i_header = 0;
490     p_sys->p_header = NULL;
491     for( ;; )
492     {
493         chunk_t ck;
494         if( GetPacket( p_access, &ck ) ||
495             ck.i_type != 0x4824 )
496         {
497             break;
498         }
499
500         if( ck.i_data > 0 )
501         {
502             p_sys->i_header += ck.i_data;
503             p_sys->p_header = realloc( p_sys->p_header, p_sys->i_header );
504             memcpy( &p_sys->p_header[p_sys->i_header - ck.i_data],
505                     ck.p_data, ck.i_data );
506         }
507     }
508     msg_Dbg( p_access, "complete header size=%d", p_sys->i_header );
509     if( p_sys->i_header <= 0 )
510     {
511         msg_Err( p_access, "header size == 0" );
512         goto error;
513     }
514     /* close this connection */
515     net_Close( p_sys->fd ); p_sys->fd = -1;
516
517     /* *** parse header and get stream and their id *** */
518     /* get all streams properties,
519      *
520      * TODO : stream bitrates properties(optional)
521      *        and bitrate mutual exclusion(optional) */
522     E_( asf_HeaderParse )( &p_sys->asfh,
523                            p_sys->p_header, p_sys->i_header );
524     msg_Dbg( p_access, "packet count=%lld packet size=%d",
525              p_sys->asfh.i_data_packets_count,
526              p_sys->asfh.i_min_data_packet_size );
527
528     E_( asf_StreamSelect)( &p_sys->asfh,
529                            var_CreateGetInteger( p_access, "mms-maxbitrate" ),
530                            var_CreateGetInteger( p_access, "mms-all" ),
531                            var_CreateGetInteger( p_access, "audio" ),
532                            var_CreateGetInteger( p_access, "video" ) );
533
534     return VLC_SUCCESS;
535
536 error:
537     if( p_sys->fd > 0 )
538     {
539         net_Close( p_sys->fd  );
540         p_sys->fd = -1;
541     }
542     return VLC_EGENERIC;
543 }
544
545 /*****************************************************************************
546  *
547  *****************************************************************************/
548 static int Start( access_t *p_access, off_t i_pos )
549 {
550     access_sys_t *p_sys = p_access->p_sys;
551     int  i_streams = 0;
552     int  i;
553     char *psz;
554
555     msg_Dbg( p_access, "starting stream" );
556
557     if( ( p_sys->fd = net_OpenTCP( p_access, p_sys->url.psz_host,
558                                             p_sys->url.i_port ) ) < 0 )
559     {
560         /* should not occur */
561         msg_Err( p_access, "cannot connect to the server" );
562         return VLC_EGENERIC;
563     }
564
565     for( i = 1; i < 128; i++ )
566     {
567         if( p_sys->asfh.stream[i].i_selected )
568         {
569             i_streams++;
570         }
571     }
572
573     if( i_streams <= 0 )
574     {
575         msg_Err( p_access, "no stream selected" );
576         return VLC_EGENERIC;
577     }
578     net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
579                 "GET %s HTTP/1.0\r\n"
580                 "Accept: */*\r\n"
581                 "User-Agent: NSPlayer/4.1.0.3856\r\n"
582                 "Host: %s:%d\r\n",
583                 ( p_sys->url.psz_path == NULL || *p_sys->url.psz_path == '\0' ) ? "/" : p_sys->url.psz_path,
584                 p_sys->url.psz_host, p_sys->url.i_port );
585     if( p_sys->b_broadcast )
586     {
587         net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
588                     "Pragma: no-cache,rate=1.000000,request-context=%d\r\n",
589                     p_sys->i_request_context++ );
590     }
591     else
592     {
593         net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
594                     "Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=%u:%u,request-context=%d,max-duration=0\r\n",
595                     (uint32_t)((i_pos >> 32)&0xffffffff),
596                     (uint32_t)(i_pos&0xffffffff),
597                     p_sys->i_request_context++ );
598     }
599     net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
600                 "Pragma: xPlayStrm=1\r\n"
601                 "Pragma: xClientGUID={"GUID_FMT"}\r\n"
602                 "Pragma: stream-switch-count=%d\r\n"
603                 "Pragma: stream-switch-entry=",
604                 GUID_PRINT( p_sys->guid ),
605                 i_streams);
606
607     for( i = 1; i < 128; i++ )
608     {
609         if( p_sys->asfh.stream[i].i_cat != ASF_STREAM_UNKNOWN )
610         {
611             int i_select = 2;
612             if( p_sys->asfh.stream[i].i_selected )
613             {
614                 i_select = 0;
615             }
616
617             net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
618                         "ffff:%d:%d ", i, i_select );
619         }
620     }
621     net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, "\r\n" );
622     net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
623                 "Connection: Close\r\n" );
624
625     if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL, "\r\n" ) < 0 )
626     {
627         msg_Err( p_access, "failed to send request" );
628         return VLC_EGENERIC;
629     }
630
631     if( ( psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL ) ) == NULL )
632     {
633         msg_Err( p_access, "cannot read data" );
634         return VLC_EGENERIC;
635     }
636     if( atoi( &psz[9] ) >= 400 )
637     {
638         msg_Err( p_access, "error: %s", psz );
639         free( psz );
640         return VLC_EGENERIC;
641     }
642     msg_Dbg( p_access, "HTTP reply '%s'", psz );
643     free( psz );
644
645     /* FIXME check HTTP code */
646     for( ;; )
647     {
648         char *psz = net_Gets( p_access, p_sys->fd, NULL );
649         if( psz == NULL )
650         {
651             msg_Err( p_access, "cannot read data" );
652             return VLC_EGENERIC;
653         }
654         if( *psz == '\0' )
655         {
656             free( psz );
657             break;
658         }
659         msg_Dbg( p_access, "%s", psz );
660         free( psz );
661     }
662
663     p_sys->i_packet_used   = 0;
664     p_sys->i_packet_length = 0;
665
666     return VLC_SUCCESS;
667 }
668
669 /*****************************************************************************
670  *
671  *****************************************************************************/
672 static void Stop( access_t *p_access )
673 {
674     access_sys_t *p_sys = p_access->p_sys;
675
676     msg_Dbg( p_access, "closing stream" );
677     if( p_sys->fd > 0 )
678     {
679         net_Close( p_sys->fd );
680         p_sys->fd = -1;
681     }
682 }
683
684 /*****************************************************************************
685  *
686  *****************************************************************************/
687 static int GetPacket( access_t * p_access, chunk_t *p_ck )
688 {
689     access_sys_t *p_sys = p_access->p_sys;
690
691     /* chunk_t */
692     memset( p_ck, 0, sizeof( chunk_t ) );
693
694     /* Read the chunk header */
695     if( net_Read( p_access, p_sys->fd, NULL, p_sys->buffer, 12, VLC_TRUE ) < 12 )
696     {
697         /* msg_Err( p_access, "cannot read data" ); */
698         return VLC_EGENERIC;
699     }
700
701     p_ck->i_type      = GetWLE( p_sys->buffer);
702     p_ck->i_size      = GetWLE( p_sys->buffer + 2);
703     p_ck->i_sequence  = GetDWLE( p_sys->buffer + 4);
704     p_ck->i_unknown   = GetWLE( p_sys->buffer + 8);
705     p_ck->i_size2     = GetWLE( p_sys->buffer + 10);
706     p_ck->p_data      = p_sys->buffer + 12;
707     p_ck->i_data      = p_ck->i_size2 - 8;
708
709     if( p_ck->i_type == 0x4524 )   // Transfer complete
710     {
711         if( p_ck->i_sequence == 0 )
712         {
713             msg_Warn( p_access, "EOF" );
714             return VLC_EGENERIC;
715         }
716         else
717         {
718             msg_Warn( p_access, "Next stream follow but not supported" );
719             return VLC_EGENERIC;
720         }
721     }
722     else if( p_ck->i_type != 0x4824 && p_ck->i_type != 0x4424 )
723     {
724         msg_Err( p_access, "invalid chunk FATAL (0x%x)", p_ck->i_type );
725         return VLC_EGENERIC;
726     }
727
728     if( p_ck->i_data > 0 &&
729         net_Read( p_access, p_sys->fd, NULL, &p_sys->buffer[12], p_ck->i_data, VLC_TRUE ) < p_ck->i_data )
730     {
731         msg_Err( p_access, "cannot read data" );
732         return VLC_EGENERIC;
733     }
734
735     if( p_sys->i_packet_sequence != 0 &&
736         p_ck->i_sequence != p_sys->i_packet_sequence )
737     {
738         msg_Warn( p_access, "packet lost ? (%d != %d)", p_ck->i_sequence, p_sys->i_packet_sequence );
739     }
740
741     p_sys->i_packet_sequence = p_ck->i_sequence + 1;
742     p_sys->i_packet_used   = 0;
743     p_sys->i_packet_length = p_ck->i_data;
744     p_sys->p_packet        = p_ck->p_data;
745
746     return VLC_SUCCESS;
747 }