]> git.sesse.net Git - vlc/blob - modules/access/udp.c
Simplify shutdown() portability
[vlc] / modules / access / udp.c
1 /*****************************************************************************
2  * udp.c: raw UDP & RTP input module
3  *****************************************************************************
4  * Copyright (C) 2001-2005 the VideoLAN team
5  * Copyright (C) 2007 Remi Denis-Courmont
6  * $Id$
7  *
8  * Authors: Christophe Massiot <massiot@via.ecp.fr>
9  *          Tristan Leteurtre <tooney@via.ecp.fr>
10  *          Laurent Aimar <fenrir@via.ecp.fr>
11  *          Jean-Paul Saman <jpsaman #_at_# m2x dot nl>
12  *          Remi Denis-Courmont
13  *
14  * Reviewed: 23 October 2003, Jean-Paul Saman <jpsaman _at_ videolan _dot_ org>
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 2 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
29  *****************************************************************************/
30
31 /*****************************************************************************
32  * Preamble
33  *****************************************************************************/
34 #include <stdlib.h>
35
36 #include <vlc/vlc.h>
37 #include <vlc_access.h>
38 #include <vlc_network.h>
39
40 /* Big pile of stuff missing form glibc 2.5 */
41 #if defined (HAVE_NETINET_UDPLITE_H)
42 # include <netinet/udplite.h>
43 #elif defined (__linux__)
44 # define UDPLITE_SEND_CSCOV     10
45 # define UDPLITE_RECV_CSCOV     11
46 #endif
47
48 #ifndef SOCK_DCCP /* provisional API */
49 # ifdef __linux__
50 #  define SOCK_DCCP 6
51 # endif
52 #endif
53
54 #ifndef IPPROTO_DCCP
55 # define IPPROTO_DCCP 33 /* IANA */
56 #endif
57
58 #ifndef IPPROTO_UDPLITE
59 # define IPPROTO_UDPLITE 136 /* from IANA */
60 #endif
61 #ifndef SOL_UDPLITE
62 # define SOL_UDPLITE IPPROTO_UDPLITE
63 #endif
64
65
66 /*****************************************************************************
67  * Module descriptor
68  *****************************************************************************/
69 #define CACHING_TEXT N_("Caching value in ms")
70 #define CACHING_LONGTEXT N_( \
71     "Caching value for UDP streams. This " \
72     "value should be set in milliseconds." )
73
74 #define AUTO_MTU_TEXT N_("Autodetection of MTU")
75 #define AUTO_MTU_LONGTEXT N_( \
76     "Automatically detect the line's MTU. This will increase the size if" \
77     " truncated packets are found" )
78
79 #define RTP_LATE_TEXT N_("RTP reordering timeout in ms")
80 #define RTP_LATE_LONGTEXT N_( \
81     "VLC reorders RTP packets. The input will wait for late packets at most "\
82     "the time specified here (in milliseconds)." )
83
84 static int  Open ( vlc_object_t * );
85 static void Close( vlc_object_t * );
86
87 vlc_module_begin();
88     set_shortname( _("UDP/RTP" ) );
89     set_description( _("UDP/RTP input") );
90     set_category( CAT_INPUT );
91     set_subcategory( SUBCAT_INPUT_ACCESS );
92
93     add_integer( "udp-caching", DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT,
94                  CACHING_LONGTEXT, VLC_TRUE );
95     add_integer( "rtp-late", 100, NULL, RTP_LATE_TEXT, RTP_LATE_LONGTEXT, VLC_TRUE );
96
97     add_bool( "udp-auto-mtu", 1, NULL,
98               AUTO_MTU_TEXT, AUTO_MTU_LONGTEXT, VLC_TRUE );
99
100     set_capability( "access2", 0 );
101     add_shortcut( "udp" );
102     add_shortcut( "udpstream" );
103     add_shortcut( "udp4" );
104     add_shortcut( "udp6" );
105     add_shortcut( "rtp" );
106     add_shortcut( "rtp4" );
107     add_shortcut( "rtp6" );
108     add_shortcut( "udplite" );
109     add_shortcut( "rtptcp" );
110     add_shortcut( "dccp" );
111
112     set_callbacks( Open, Close );
113 vlc_module_end();
114
115 /*****************************************************************************
116  * Local prototypes
117  *****************************************************************************/
118 #define RTP_HEADER_LEN 12
119
120 static block_t *BlockUDP( access_t * );
121 static block_t *BlockTCP( access_t * );
122 static block_t *BlockRTP( access_t * );
123 static block_t *BlockChoose( access_t * );
124 static int Control( access_t *, int, va_list );
125
126 struct access_sys_t
127 {
128     int fd;
129
130     int i_mtu;
131     vlc_bool_t b_auto_mtu;
132     vlc_bool_t b_framed_rtp;
133
134     /* reorder rtp packets when out-of-sequence */
135     uint16_t i_last_seqno;
136     mtime_t i_rtp_late;
137     block_t *p_list;
138     block_t *p_end;
139     block_t *p_partial_frame; /* Partial Framed RTP packet */
140 };
141
142 /*****************************************************************************
143  * Open: open the socket
144  *****************************************************************************/
145 static int Open( vlc_object_t *p_this )
146 {
147     access_t     *p_access = (access_t*)p_this;
148     access_sys_t *p_sys;
149
150     char *psz_name = strdup( p_access->psz_path );
151     char *psz_parser;
152     const char *psz_server_addr, *psz_bind_addr = "";
153     int  i_bind_port, i_server_port = 0;
154     int fam = AF_UNSPEC, proto = IPPROTO_UDP;
155
156     if (strlen (p_access->psz_access) >= 3)
157     {
158         switch (p_access->psz_access[3])
159         {
160             case '4':
161                 fam = AF_INET;
162                 break;
163
164             case '6':
165                 fam = AF_INET6;
166                 break;
167         }
168         if (strcmp (p_access->psz_access + 3, "lite") == 0)
169             proto = IPPROTO_UDPLITE;
170         else
171         if (strcmp (p_access->psz_access + 3, "tcp") == 0)
172             proto = IPPROTO_TCP;
173         else
174         if (strcmp (p_access->psz_access, "dccp") == 0)
175             proto = IPPROTO_DCCP;
176     }
177
178     i_bind_port = var_CreateGetInteger( p_access, "server-port" );
179
180     /* Parse psz_name syntax :
181      * [serveraddr[:serverport]][@[bindaddr]:[bindport]] */
182     psz_parser = strchr( psz_name, '@' );
183     if( psz_parser != NULL )
184     {
185         /* Found bind address and/or bind port */
186         *psz_parser++ = '\0';
187         psz_bind_addr = psz_parser;
188
189         if( *psz_parser == '[' )
190             /* skips bracket'd IPv6 address */
191             psz_parser = strchr( psz_parser, ']' );
192
193         if( psz_parser != NULL )
194         {
195             psz_parser = strchr( psz_parser, ':' );
196             if( psz_parser != NULL )
197             {
198                 *psz_parser++ = '\0';
199                 i_bind_port = atoi( psz_parser );
200             }
201         }
202     }
203
204     psz_server_addr = psz_name;
205     if( *psz_server_addr == '[' )
206         /* skips bracket'd IPv6 address */
207         psz_parser = strchr( psz_name, ']' );
208
209     if( psz_parser != NULL )
210     {
211         psz_parser = strchr( psz_parser, ':' );
212         if( psz_parser != NULL )
213         {
214             *psz_parser++ = '\0';
215             i_server_port = atoi( psz_parser );
216         }
217     }
218
219     msg_Dbg( p_access, "opening server=%s:%d local=%s:%d",
220              psz_server_addr, i_server_port, psz_bind_addr, i_bind_port );
221
222     /* Set up p_access */
223     access_InitFields( p_access );
224     ACCESS_SET_CALLBACKS( NULL, BlockChoose, Control, NULL );
225     p_access->info.b_prebuffered = VLC_FALSE;
226     MALLOC_ERR( p_access->p_sys, access_sys_t ); p_sys = p_access->p_sys;
227     memset (p_sys, 0, sizeof (*p_sys));
228
229     switch (proto)
230     {
231         case IPPROTO_UDP:
232         case IPPROTO_UDPLITE:
233             p_sys->fd = net_OpenDgram( p_access, psz_bind_addr, i_bind_port,
234                                        psz_server_addr, i_server_port, fam,
235                                        proto );
236             break;
237
238         case IPPROTO_TCP:
239             p_sys = net_ConnectTCP( p_access, psz_server_addr, i_server_port );
240             p_sys->b_framed_rtp = VLC_TRUE;
241             break;
242
243         case IPPROTO_DCCP:
244 #ifdef SOCK_DCCP
245             p_sys->fd = net_Connect( p_access, psz_server_addr, i_server_port,
246                                      SOCK_DCCP, IPPROTO_DCCP );
247 #else
248             p_sys->fd = -1;
249             msg_Err( p_access, "DCCP support not compiled-in!" );
250 #endif
251             break;
252     }
253     free (psz_name);
254     if( p_sys->fd == -1 )
255     {
256         msg_Err( p_access, "cannot open socket" );
257         free( p_sys );
258         return VLC_EGENERIC;
259     }
260
261     shutdown( p_sys->fd, SHUT_WR );
262
263 #ifdef UDPLITE_RECV_CSCOV
264     if (proto == IPPROTO_UDPLITE)
265         /* UDP header: 8 bytes + RTP header: 12 bytes (or more) */
266         setsockopt (p_sys->fd, SOL_UDPLITE, UDPLITE_RECV_CSCOV,
267                     &(int){ 20 }, sizeof (int));
268 #endif
269
270     if (p_sys->b_framed_rtp)
271     {
272         /* We don't do autodetection and prebuffering in case of framing */
273         p_access->pf_block = BlockRTP;
274         p_sys->i_mtu = 65535;
275     }
276     else
277     {
278         /* FIXME */
279         p_sys->i_mtu = var_CreateGetInteger( p_access, "mtu" );
280         if( p_sys->i_mtu <= 1 )
281             p_sys->i_mtu  = 1500;   /* Avoid problem */
282
283         p_sys->b_auto_mtu = var_CreateGetBool( p_access, "udp-auto-mtu" );;
284     }
285
286     /* Update default_pts to a suitable value for udp access */
287     var_Create( p_access, "udp-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
288
289     /* RTP reordering for out-of-sequence packets */
290     p_sys->i_rtp_late = var_CreateGetInteger( p_access, "rtp-late" ) * 1000;
291     p_sys->i_last_seqno = 0;
292     p_sys->p_list = NULL;
293     p_sys->p_end = NULL;
294     return VLC_SUCCESS;
295 }
296
297 /*****************************************************************************
298  * Close: free unused data structures
299  *****************************************************************************/
300 static void Close( vlc_object_t *p_this )
301 {
302     access_t     *p_access = (access_t*)p_this;
303     access_sys_t *p_sys = p_access->p_sys;
304
305     block_ChainRelease( p_sys->p_list );
306     net_Close( p_sys->fd );
307     free( p_sys );
308 }
309
310 /*****************************************************************************
311  * Control:
312  *****************************************************************************/
313 static int Control( access_t *p_access, int i_query, va_list args )
314 {
315     access_sys_t *p_sys = p_access->p_sys;
316     vlc_bool_t   *pb_bool;
317     int          *pi_int;
318     int64_t      *pi_64;
319
320     switch( i_query )
321     {
322         /* */
323         case ACCESS_CAN_SEEK:
324         case ACCESS_CAN_FASTSEEK:
325         case ACCESS_CAN_PAUSE:
326         case ACCESS_CAN_CONTROL_PACE:
327             pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
328             *pb_bool = VLC_FALSE;
329             break;
330         /* */
331         case ACCESS_GET_MTU:
332             pi_int = (int*)va_arg( args, int * );
333             *pi_int = p_sys->i_mtu;
334             break;
335
336         case ACCESS_GET_PTS_DELAY:
337             pi_64 = (int64_t*)va_arg( args, int64_t * );
338             *pi_64 = var_GetInteger( p_access, "udp-caching" ) * 1000;
339             break;
340
341         /* */
342         case ACCESS_SET_PAUSE_STATE:
343         case ACCESS_GET_TITLE_INFO:
344         case ACCESS_SET_TITLE:
345         case ACCESS_SET_SEEKPOINT:
346         case ACCESS_SET_PRIVATE_ID_STATE:
347             return VLC_EGENERIC;
348
349         default:
350             msg_Warn( p_access, "unimplemented query in control" );
351             return VLC_EGENERIC;
352
353     }
354     return VLC_SUCCESS;
355 }
356
357 /*****************************************************************************
358  * BlockUDP:
359  *****************************************************************************/
360 static block_t *BlockUDP( access_t *p_access )
361 {
362     access_sys_t *p_sys = p_access->p_sys;
363     block_t      *p_block;
364
365     /* Read data */
366     p_block = block_New( p_access, p_sys->i_mtu );
367     p_block->i_buffer = net_Read( p_access, p_sys->fd, NULL,
368                                   p_block->p_buffer, p_sys->i_mtu,
369                                   VLC_FALSE );
370     if( p_block->i_buffer < 0 )
371     {
372         block_Release( p_block );
373         return NULL;
374     }
375
376     if( (p_block->i_buffer >= p_sys->i_mtu) && p_sys->b_auto_mtu &&
377         p_sys->i_mtu < 32767 )
378     {
379         /* Increase by 100% */
380         p_sys->i_mtu *= 2;
381         msg_Dbg( p_access, "increasing MTU to %d", p_sys->i_mtu );
382     }
383
384     return p_block;
385 }
386
387 /*****************************************************************************
388  * BlockTCP: Framed RTP/AVP packet reception for COMEDIA
389  * Still an I-D (draft-ietf-avt-rtp-framing-contrans-06) - subject to change.
390  *****************************************************************************/
391 static block_t *BlockTCP( access_t *p_access )
392 {
393     access_sys_t *p_sys = p_access->p_sys;
394     block_t      *p_block = p_sys->p_partial_frame;
395
396     if( p_access->info.b_eof )
397         return NULL;
398
399     if( p_block == NULL )
400     {
401         /* MTU should always be 65535 in this case */
402         p_sys->p_partial_frame = p_block = block_New( p_access, 65537 );
403         if (p_block == NULL)
404             return NULL;
405     }
406
407     /* Read RTP framing */
408     if (p_block->i_buffer < 2)
409     {
410         /* FIXME: not very efficient */
411         int i_read = net_Read( p_access, p_sys->fd, NULL,
412                                p_block->p_buffer + p_block->i_buffer,
413                                2 - p_block->i_buffer, VLC_FALSE );
414         if( i_read <= 0 )
415             goto error;
416
417         p_block->i_buffer += i_read;
418         if (p_block->i_buffer < 2)
419             return NULL;
420     }
421
422     uint16_t framelen = GetWLE( p_block->p_buffer );
423     /* Read RTP frame */
424     if( framelen > 0 )
425     {
426         int i_read = net_Read( p_access, p_sys->fd, NULL,
427                                p_block->p_buffer + p_block->i_buffer,
428                                2 + framelen - p_block->i_buffer, VLC_FALSE );
429         if( i_read <= 0 )
430             goto error;
431
432         p_block->i_buffer += i_read;
433     }
434
435     if( p_block->i_buffer < (2 + framelen) )
436         return NULL; // incomplete frame
437
438     /* Hide framing from RTP layer */
439     p_block->p_buffer += 2;
440     p_block->i_buffer -= 2;
441     p_sys->p_partial_frame = NULL;
442     return p_block;
443
444 error:
445     p_access->info.b_eof = VLC_TRUE;
446     block_Release( p_block );
447     p_sys->p_partial_frame = NULL;
448     return NULL;
449 }
450
451
452 /*
453  * rtp_ChainInsert - insert a p_block in the chain and
454  * look at the sequence numbers.
455  */
456 static inline vlc_bool_t rtp_ChainInsert( access_t *p_access, block_t *p_block )
457 {
458     access_sys_t *p_sys = (access_sys_t *) p_access->p_sys;
459     block_t *p_prev = NULL;
460     block_t *p = p_sys->p_end;
461     uint16_t i_new = (uint16_t) p_block->i_dts;
462     uint16_t i_tmp = 0;
463
464     if( !p_sys->p_list )
465     {
466         p_sys->p_list = p_block;
467         p_sys->p_end = p_block;
468         return VLC_TRUE;
469     }
470     /* walk through the queue from top down since the new packet is in 
471     most cases just appended to the end */
472
473     for( ;; )
474     {
475         i_tmp = i_new - (uint16_t) p->i_dts;
476
477         if( !i_tmp )   /* trash duplicate */
478             break; 
479
480         if ( i_tmp < 32768 )
481         {   /* insert after this block ( i_new > p->i_dts ) */
482             p_block->p_next = p->p_next;
483             p->p_next = p_block;
484             p_block->p_prev = p;
485             if (p_prev)
486             {
487                 p_prev->p_prev = p_block;
488                 msg_Dbg(p_access, "RTP reordering: insert after %d, new %d", 
489                     (uint16_t) p->i_dts, i_new );
490             }
491             else 
492             {
493                 p_sys->p_end = p_block;
494             }
495             return VLC_TRUE;
496         }
497         if( p == p_sys->p_list )
498         {   /* we've reached bottom of chain */
499             i_tmp = p_sys->i_last_seqno - i_new;
500             if( !p_access->info.b_prebuffered || (i_tmp > 32767) )
501             {
502                 msg_Dbg(p_access, "RTP reordering: prepend %d before %d", 
503                         i_new, (uint16_t) p->i_dts );
504                 p_block->p_next = p;
505                 p->p_prev = p_block;
506                 p_sys->p_list = p_block;
507                 return VLC_TRUE;
508             }
509
510             if( !i_tmp )   /* trash duplicate */
511                 break;
512
513             /* reordering failed - append the packet to the end of queue */
514             msg_Dbg(p_access, "RTP: sequence changed (or buffer too small) "
515                 "new: %d, buffer %d...%d", i_new, (uint16_t) p->i_dts, 
516                 (uint16_t) p_sys->p_end->i_dts);
517             p_sys->p_end->p_next = p_block;
518             p_block->p_prev = p_sys->p_end;
519             p_sys->p_end = p_block;
520             return VLC_TRUE;
521         }
522         p_prev = p;
523         p = p->p_prev;
524     }
525     block_Release( p_block );
526     return VLC_FALSE;
527 }
528
529 /*****************************************************************************
530  * BlockParseRTP/BlockRTP:
531  *****************************************************************************/
532 static block_t *BlockParseRTP( access_t *p_access, block_t *p_block )
533 {
534     int      i_rtp_version;
535     int      i_CSRC_count;
536     int      i_payload_type;
537     int      i_skip = 0;
538     int      i_extension_flag = 0;
539     int      i_extension_length = 0;
540     uint16_t i_sequence_number = 0;
541
542     if( p_block == NULL )
543         return NULL;
544
545     if( p_block->i_buffer < RTP_HEADER_LEN )
546         goto trash;
547
548     /* Parse the header and make some verifications.
549      * See RFC 3550. */
550     i_rtp_version     = ( p_block->p_buffer[0] & 0xC0 ) >> 6;
551     i_CSRC_count      = p_block->p_buffer[0] & 0x0F;
552     i_extension_flag  = p_block->p_buffer[0] & 0x10;
553     i_payload_type    = p_block->p_buffer[1] & 0x7F;
554     i_sequence_number = (p_block->p_buffer[2] << 8 ) + p_block->p_buffer[3];
555
556     if( i_rtp_version != 2 )
557         msg_Dbg( p_access, "RTP version is %u, should be 2", i_rtp_version );
558
559     if( i_payload_type == 14 || i_payload_type == 32)
560         i_skip = 4;
561     else if( i_payload_type !=  33 )
562         msg_Dbg( p_access, "unsupported RTP payload type (%u)", i_payload_type );
563     if( i_extension_flag )
564     {
565         if( p_block->i_buffer < 16 )
566             goto trash;
567         i_extension_length = 4 +
568             4 * ( (p_block->p_buffer[14] << 8) + p_block->p_buffer[15] );
569     }
570
571     /* Skip header + CSRC extension field n*(32 bits) + extension */
572     i_skip += RTP_HEADER_LEN + 4*i_CSRC_count + i_extension_length;
573
574     if( i_skip >= p_block->i_buffer )
575         goto trash;
576
577     /* Return the packet without the RTP header, remember seqno in i_dts */
578     p_block->i_buffer -= i_skip;
579     p_block->p_buffer += i_skip;
580     p_block->i_pts = mdate();
581     p_block->i_dts = (mtime_t) i_sequence_number;
582
583 #if 0
584     /* Emulate packet loss */
585     if ( (i_sequence_number % 4000) == 0)
586     {
587         msg_Warn( p_access, "Emulating packet drop" );
588         block_Release( p_block );
589         return NULL;
590     }
591 #endif
592
593     return p_block;
594
595 trash:
596     msg_Warn( p_access, "received a too short packet for RTP" );
597     block_Release( p_block );
598     return NULL;
599 }
600
601 static block_t *BlockPrebufferRTP( access_t *p_access, block_t *p_block )
602 {
603     access_sys_t *p_sys = p_access->p_sys;
604     mtime_t   i_first = mdate();
605     int       i_count = 0;
606     block_t   *p = p_block;
607
608     for( ;; )
609     {
610         mtime_t i_date = mdate();
611
612         if( p && rtp_ChainInsert( p_access, p ))
613             i_count++;
614
615         /* Require at least 2 packets in the buffer */
616         if( i_count > 2 && (i_date - i_first) > p_sys->i_rtp_late )
617             break;
618
619         p = BlockParseRTP( p_access, BlockUDP( p_access ) );
620         if( !p && (i_date - i_first) > p_sys->i_rtp_late ) 
621         {
622             msg_Err( p_access, "error in RTP prebuffering!" );
623             break;
624         }
625     }
626
627     msg_Dbg( p_access, "RTP: prebuffered %d packets", i_count - 1 );
628     p_access->info.b_prebuffered = VLC_TRUE;
629     p = p_sys->p_list;
630     p_sys->p_list = p_sys->p_list->p_next;
631     p_sys->i_last_seqno = (uint16_t) p->i_dts;
632     p->p_next = NULL;
633     return p;
634 }
635
636 static block_t *BlockRTP( access_t *p_access )
637 {
638     access_sys_t *p_sys = p_access->p_sys;
639     block_t *p;
640
641     while ( !p_sys->p_list ||
642              ( mdate() - p_sys->p_list->i_pts ) < p_sys->i_rtp_late )
643     {
644         p = BlockParseRTP( p_access,
645                            p_sys->b_framed_rtp ? BlockTCP( p_access )
646                                                : BlockUDP( p_access ) );
647         if ( !p )
648             return NULL;
649
650         rtp_ChainInsert( p_access, p );
651     }
652
653     p = p_sys->p_list;
654     p_sys->p_list = p_sys->p_list->p_next;
655     p_sys->i_last_seqno++;
656     if( p_sys->i_last_seqno != (uint16_t) p->i_dts )
657     {
658         msg_Dbg( p_access, "RTP: packet(s) lost, expected %d, got %d",
659                  p_sys->i_last_seqno, (uint16_t) p->i_dts );
660         p_sys->i_last_seqno = (uint16_t) p->i_dts;
661     }
662     p->p_next = NULL;
663     return p;
664 }
665
666 /*****************************************************************************
667  * BlockChoose: decide between RTP and UDP
668  *****************************************************************************/
669 static block_t *BlockChoose( access_t *p_access )
670 {
671     block_t *p_block;
672     int     i_rtp_version;
673     int     i_CSRC_count;
674     int     i_payload_type;
675
676     if( ( p_block = BlockUDP( p_access ) ) == NULL )
677         return NULL;
678
679     if( p_block->p_buffer[0] == 0x47 )
680     {
681         msg_Dbg( p_access, "detected TS over raw UDP" );
682         p_access->pf_block = BlockUDP;
683         p_access->info.b_prebuffered = VLC_TRUE;
684         return p_block;
685     }
686
687     if( p_block->i_buffer < RTP_HEADER_LEN )
688         return p_block;
689
690     /* Parse the header and make some verifications.
691      * See RFC 3550. */
692
693     i_rtp_version  = ( p_block->p_buffer[0] & 0xC0 ) >> 6;
694     i_CSRC_count   = ( p_block->p_buffer[0] & 0x0F );
695     i_payload_type = ( p_block->p_buffer[1] & 0x7F );
696
697     if( i_rtp_version != 2 )
698     {
699         msg_Dbg( p_access, "no supported RTP header detected" );
700         p_access->pf_block = BlockUDP;
701         p_access->info.b_prebuffered = VLC_TRUE;
702         return p_block;
703     }
704
705     switch( i_payload_type )
706     {
707         case 33:
708             msg_Dbg( p_access, "detected TS over RTP" );
709             p_access->psz_demux = strdup( "ts" );
710             break;
711
712         case 14:
713             msg_Dbg( p_access, "detected MPEG audio over RTP" );
714             p_access->psz_demux = strdup( "mpga" );
715             break;
716
717         case 32:
718             msg_Dbg( p_access, "detected MPEG video over RTP" );
719             p_access->psz_demux = strdup( "mpgv" );
720             break;
721
722         default:
723             msg_Dbg( p_access, "no RTP header detected" );
724             p_access->pf_block = BlockUDP;
725             p_access->info.b_prebuffered = VLC_TRUE;
726             return p_block;
727     }
728
729     if( !BlockParseRTP( p_access, p_block )) return NULL;
730
731     p_access->pf_block = BlockRTP;
732
733     return BlockPrebufferRTP( p_access, p_block );
734 }