]> git.sesse.net Git - vlc/blobdiff - modules/access/mms/mms.c
* modules/*: sanitization of the modules description strings.
[vlc] / modules / access / mms / mms.c
index ae72bab6c3ec1d726ff4554314794a3c6204e5fd..e9b9983a198f038324f798a68dd55fd5b4aacfae 100644 (file)
@@ -2,7 +2,7 @@
  * mms.c: MMS access plug-in
  *****************************************************************************
  * Copyright (C) 2001, 2002 VideoLAN
- * $Id: mms.c,v 1.23 2003/03/11 18:14:27 fenrir Exp $
+ * $Id: mms.c,v 1.31 2003/03/30 18:14:35 gbazin Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
@@ -132,7 +132,7 @@ static void mms_ParseURL( url_t *p_url, char *psz_url );
     "value should be set in miliseconds units." )
 
 vlc_module_begin();
-    set_description( _("MMS access module") );
+    set_description( _("Microsoft Media Server (MMS) input") );
     set_capability( "access", 0 );
     add_category_hint( "stream", NULL, VLC_TRUE );
         add_integer( "mms-caching", 4 * DEFAULT_PTS_DELAY / 1000, NULL,
@@ -252,14 +252,6 @@ static int Open( vlc_object_t *p_this )
     /* *** finished to set some variable *** */
     vlc_mutex_lock( &p_input->stream.stream_lock );
     p_input->stream.b_pace_control = 0;
-    if( p_access->i_proto == MMS_PROTO_UDP )
-    {
-        p_input->stream.b_connected = 0;
-    }
-    else
-    {
-        p_input->stream.b_connected = 1;
-    }
     p_input->stream.p_selected_area->i_tell = 0;
     /*
      * i_flags_broadcast
@@ -329,15 +321,6 @@ static int SetProgram( input_thread_t * p_input,
  *****************************************************************************/
 static void Seek( input_thread_t * p_input, off_t i_pos )
 {
-    /*
-     * FIXME
-     * Don't work
-     * Probably some bad or missing command
-     *
-     *
-     */
-#if 1
-
     access_t    *p_access = (access_t*)p_input->p_access_data;
     uint32_t    i_packet;
     uint32_t    i_offset;
@@ -421,8 +404,6 @@ static void Seek( input_thread_t * p_input, off_t i_pos )
     p_access->i_pos = i_pos;
     p_input->stream.p_selected_area->i_tell = i_pos;
     vlc_mutex_unlock( &p_input->stream.stream_lock );
-
-#endif
 }
 
 static int  Read        ( input_thread_t * p_input, byte_t * p_buffer,
@@ -934,7 +915,7 @@ static int MMSOpen( input_thread_t  *p_input,
     }
     else
     {
-        sprintf( tmp, "\\\\127.0.0.1\\TCP\\1242"  );
+        sprintf( tmp, "\\\\192.168.0.1\\TCP\\1242"  );
     }
     var_buffer_addUTF16( &buffer, tmp );
     var_buffer_add16( &buffer, '0' );
@@ -1488,11 +1469,23 @@ static int  NetFillBuffer( input_thread_t *p_input )
     timeout.tv_usec = 500000;
 
     /* Find if some data is available */
-    i_ret = select( i_handle_max + 1,
-                    &fds,
-                    NULL, NULL, &timeout );
+    while( (i_ret = select( i_handle_max + 1, &fds,
+                            NULL, NULL, &timeout )) == 0
+           || (i_ret < 0 && errno == EINTR) )
+    {
+        FD_ZERO( &fds );
+        if( i_tcp > 0 ) FD_SET( p_access->socket_tcp.i_handle, &fds );
+        if( i_udp > 0 ) FD_SET( p_access->socket_udp.i_handle, &fds );
+        timeout.tv_sec = 0;
+        timeout.tv_usec = 500000;
+
+        if( p_input->b_die || p_input->b_error )
+        {
+            return 0;
+        }
+    }
 
-    if( i_ret == -1 && errno != EINTR )
+    if( i_ret < 0 )
     {
         msg_Err( p_input, "network select error (%s)", strerror(errno) );
         return -1;
@@ -1539,8 +1532,14 @@ static int  NetFillBuffer( input_thread_t *p_input )
                  i_tcp_read );
     }
 #endif
-    p_access->i_buffer_tcp += i_tcp_read;
-    p_access->i_buffer_udp += i_udp_read;
+    if( i_tcp_read > 0 )
+    {
+        p_access->i_buffer_tcp += i_tcp_read;
+    }
+    if( i_udp_read > 0 )
+    {
+        p_access->i_buffer_udp += i_udp_read;
+    }
 
     return( i_tcp_read + i_udp_read);
 #endif
@@ -1633,7 +1632,6 @@ static int  mms_ParsePacket( input_thread_t *p_input,
     uint8_t  *p_packet;
 
 
-//    *pi_used = i_data; /* default */
     *pi_used = i_data; /* default */
     if( i_data <= 8 )
     {
@@ -1740,7 +1738,6 @@ static int mms_ReceivePacket( input_thread_t *p_input )
             msg_Warn( p_input, "cannot fill buffer" );
             continue;
         }
-        /* TODO udp */
 
         i_packet_tcp_type = -1;
         i_packet_udp_type = -1;
@@ -1766,7 +1763,7 @@ static int mms_ReceivePacket( input_thread_t *p_input )
                                      p_access->i_buffer_tcp,
                                      &i_used );
             }
-            if( i_used < MMS_BUFFER_SIZE )
+            if( i_used > 0 && i_used < MMS_BUFFER_SIZE )
             {
                 memmove( p_access->buffer_tcp,
                          p_access->buffer_tcp + i_used,
@@ -1777,26 +1774,14 @@ static int mms_ReceivePacket( input_thread_t *p_input )
         else if( p_access->i_buffer_udp > 0 )
         {
             int i_used;
-#if 0
-            if( GetDWLE( p_access->buffer_tcp + 4 ) == 0xb00bface )
-            {
-                i_packet_tcp_type =
-                    mms_ParseCommand( p_input,
-                                      p_access->buffer_tcp,
-                                      p_access->i_buffer_tcp,
-                                      &i_used );
 
-            }
-            else
-#endif
-            {
-                i_packet_tcp_type =
-                    mms_ParsePacket( p_input,
-                                     p_access->buffer_udp,
-                                     p_access->i_buffer_udp,
-                                     &i_used );
-            }
-            if( i_used < MMS_BUFFER_SIZE )
+            i_packet_udp_type =
+                mms_ParsePacket( p_input,
+                                 p_access->buffer_udp,
+                                 p_access->i_buffer_udp,
+                                 &i_used );
+
+            if( i_used > 0 && i_used < MMS_BUFFER_SIZE )
             {
                 memmove( p_access->buffer_udp,
                          p_access->buffer_udp + i_used,
@@ -1804,10 +1789,6 @@ static int mms_ReceivePacket( input_thread_t *p_input )
             }
             p_access->i_buffer_udp -= i_used;
         }
-        else
-        {
-            i_packet_udp_type = -1;
-        }
 
         if( i_packet_tcp_type == MMS_PACKET_CMD &&
                 p_access->i_command == 0x1b )
@@ -1836,32 +1817,43 @@ static int  mms_ReceiveCommand( input_thread_t *p_input )
     {
         int i_used;
         int i_status;
-        NetFillBuffer( p_input );
 
-        i_status = mms_ParseCommand( p_input,
-                              p_access->buffer_tcp,
-                              p_access->i_buffer_tcp,
-                              &i_used );
-        if( i_used < MMS_BUFFER_SIZE )
+        if( NetFillBuffer( p_input ) < 0 )
         {
-            memmove( p_access->buffer_tcp,
-                     p_access->buffer_tcp + i_used,
-                     MMS_BUFFER_SIZE - i_used );
+            msg_Warn( p_input, "cannot fill buffer" );
+            continue;
         }
-        p_access->i_buffer_tcp -= i_used;
-
-        if( i_status < 0 )
+        if( p_access->i_buffer_tcp > 0 )
         {
-            return( -1 );
-        }
+            i_status = mms_ParseCommand( p_input,
+                                  p_access->buffer_tcp,
+                                  p_access->i_buffer_tcp,
+                                  &i_used );
+            if( i_used < MMS_BUFFER_SIZE )
+            {
+                memmove( p_access->buffer_tcp,
+                         p_access->buffer_tcp + i_used,
+                         MMS_BUFFER_SIZE - i_used );
+            }
+            p_access->i_buffer_tcp -= i_used;
 
-        if( p_access->i_command == 0x1b )
-        {
-            mms_CommandSend( p_input, 0x1b, 0, 0, NULL, 0 );
+            if( i_status < 0 )
+            {
+                return( -1 );
+            }
+
+            if( p_access->i_command == 0x1b )
+            {
+                mms_CommandSend( p_input, 0x1b, 0, 0, NULL, 0 );
+            }
+            else
+            {
+                break;
+            }
         }
         else
         {
-            break;
+            return( -1 );
         }
     }