]> git.sesse.net Git - vlc/commitdiff
Fixed miscellaneous problems with the RTP plug-in.
authorChristophe Massiot <massiot@videolan.org>
Thu, 3 Oct 2002 21:45:16 +0000 (21:45 +0000)
committerChristophe Massiot <massiot@videolan.org>
Thu, 3 Oct 2002 21:45:16 +0000 (21:45 +0000)
modules/access/rtp.c
modules/demux/mpeg/system.c

index b1f0613502a1ab7f159f1321a1282fe20d138399..4626fe43dc6ee195821cfc29a6c0ef8e5925e9cd 100644 (file)
@@ -2,9 +2,9 @@
  * rtp.c: RTP access plug-in
  *****************************************************************************
  * Copyright (C) 2001, 2002 VideoLAN
- * $Id: rtp.c,v 1.3 2002/10/03 20:49:31 jpsaman Exp $
+ * $Id: rtp.c,v 1.4 2002/10/03 21:45:16 massiot Exp $
  *
- * Authors: Christophe Massiot <massiot@via.ecp.fr>
+ * Authors: Tristan Leteurtre <tooney@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #   include <io.h>
 #endif
 
+#ifdef HAVE_ALLOCA_H
+#   include <alloca.h>
+#endif
+
 #include "network.h"
 
 #define RTP_HEADER_LEN 12
+
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
 static int  Open       ( vlc_object_t * );
-static int  RTPNetworkRead( input_thread_t *, byte_t *, size_t );
+static ssize_t RTPNetworkRead( input_thread_t *, byte_t *, size_t );
+
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
@@ -259,25 +265,24 @@ static int Open( vlc_object_t *p_this )
 /*****************************************************************************
  * RTPNetworkRead : Read for the network, and parses the RTP header
  *****************************************************************************/
-static int RTPNetworkRead( input_thread_t * p_input, byte_t * p_buffer,
+static ssize_t RTPNetworkRead( input_thread_t * p_input, byte_t * p_buffer,
                           size_t i_len )
 {
     int         i_rtp_version;
     int         i_CSRC_count;
     int         i_payload_type;
-    int         i;
-    
-    byte_t     p_tmp_buffer[1500];
-    
-    // Get the Raw data from the socket
-    // We first assume that RTP header size is the classic RTP_HEADER_LEN
-    ssize_t i_ret = input_FDNetworkRead(p_input, p_tmp_buffer,
-                                       i_len + RTP_HEADER_LEN);
     
+    byte_t *    p_tmp_buffer = alloca( p_input->i_mtu );
+
+    /* Get the raw data from the socket.
+     * We first assume that RTP header size is the classic RTP_HEADER_LEN. */
+    ssize_t i_ret = input_FDNetworkRead( p_input, p_tmp_buffer,
+                                        p_input->i_mtu );
+
     if (!i_ret) return 0;
-            
-    // Parse the header and make some verifications
-    // See RFC 1889 & RFC 2250
+     
+    /* Parse the header and make some verifications.
+     * See RFC 1889 & RFC 2250. */
   
     i_rtp_version  = ( p_tmp_buffer[0] & 0xC0 ) >> 6;
     i_CSRC_count   = ( p_tmp_buffer[0] & 0x0F );
@@ -287,45 +292,22 @@ static int RTPNetworkRead( input_thread_t * p_input, byte_t * p_buffer,
         msg_Dbg( p_input, "RTP version is %u, should be 2", i_rtp_version );
   
     if ( i_payload_type != 33 )
-        msg_Dbg( p_input, "RTP payload type is %u, only 33 (Mpeg2-TS) \
-is supported", i_payload_type );
+        msg_Dbg( p_input, "RTP payload type is %u, only 33 (Mpeg2-TS) \
+                 "is supported", i_payload_type );
  
-    // If both bytes are wrong, maybe a synchro error occurred...
-    if (( i_rtp_version != 2 ) && ( i_payload_type != 33 ))
-    {
-         msg_Dbg( p_input, "Too many RTP errors, trying to re-synchronize" );
-        //Trying to re-synchronize
-       for ( i=0 ; (i<i_len) ||
-                    ((( p_tmp_buffer[0] & 0xC0 ) >> 6 == 2 )
-                     && ( p_tmp_buffer[1] & 0x7F ) == 33 ) ; i++);
-
-       if (i!=i_len)
-       {
-          input_FDNetworkRead(p_input, p_tmp_buffer,i);
-          return 0;
-       }
-               
-    }
+    /* Return the packet without the RTP header. */
+    i_ret -= ( RTP_HEADER_LEN + 4 * i_CSRC_count );
 
-/*    
-    // if i_CSRC_count != 0, the header is in fact longer than RTP_HEADER_LEN
-    // so we have to read some extra bytes 
-    // This case is supposed to be very rare (vls does not handle that),
-    //  so in practical this second input_FDNetworkRead is never done...
-    if (i_CSRC_count)
-    {    i_ret += input_FDNetworkRead(p_input,
-                                      p_tmp_buffer + i_len + RTP_HEADER_LEN,
-                                      4 * i_CSRC_count ); 
+    if ( i_ret > i_len )
+    {
+        /* This should NOT happen. */
+        msg_Warn( p_input, "RTP input trashing %d bytes", i_ret - i_len );
+        i_ret = i_len;
     }
-*/
-    
-    // Return the packet without the RTP header
-    i_ret -= ( RTP_HEADER_LEN + 4 * i_CSRC_count );
 
     p_input->p_vlc->pf_memcpy( p_buffer, 
                        p_tmp_buffer + RTP_HEADER_LEN + 4 * i_CSRC_count,
                        i_ret );
     
-    return (i_ret);
+    return i_ret;
 }
index aff957b0aab292ec148fbc551d46d58764e38fe2..107094b15eeab09e4bbb7adb63a248db1718e456 100644 (file)
@@ -2,7 +2,7 @@
  * system.c: helper module for TS, PS and PES management
  *****************************************************************************
  * Copyright (C) 1998-2002 VideoLAN
- * $Id: system.c,v 1.4 2002/10/01 21:47:25 massiot Exp $
+ * $Id: system.c,v 1.5 2002/10/03 21:45:16 massiot Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *          Michel Lespinasse <walken@via.ecp.fr>
@@ -1291,7 +1291,8 @@ static void DemuxTS( input_thread_t * p_input, data_packet_t * p_data,
             {
                 /* Duplicate packet: mark it as being to be trashed. */
                 msg_Warn( p_input,
-                          "duplicate packet received by TS demux" );
+                          "duplicate packet received by TS demux (%d)",
+                          i_dummy );
                 b_trash = 1;
             }
             else if( p_es_demux->i_continuity_counter == 0xFF )