]> git.sesse.net Git - vlc/blobdiff - modules/access/mms/mmstu.c
Useless test before a free()
[vlc] / modules / access / mms / mmstu.c
index f19e48b2136513c73e68d9fecbe51339ba6d28c1..3779a065ea1bded6310a28c7e11ee79b523a7b36 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <vlc/vlc.h>
 #include <vlc_access.h>
 
-#include <string.h>
 #include <errno.h>
 
 #ifdef HAVE_UNISTD_H
@@ -47,6 +49,9 @@
 #ifdef HAVE_SYS_STAT_H
 #   include <sys/stat.h>
 #endif
+#ifdef HAVE_POLL
+#   include <poll.h>
+#endif
 
 #include <vlc_network.h>
 #include "vlc_url.h"
@@ -70,7 +75,7 @@ int  E_( MMSTUOpen )  ( access_t * );
 void E_( MMSTUClose ) ( access_t * );
 
 
-static int Read( access_t *, uint8_t *, int );
+static ssize_t Read( access_t *, uint8_t *, size_t );
 static int Seek( access_t *, int64_t );
 static int Control( access_t *, int, va_list );
 
@@ -88,26 +93,6 @@ static int  mms_HeaderMediaRead( access_t *, int );
 static int  mms_ReceivePacket( access_t * );
 
 
-/*
- * XXX DON'T FREE MY MEMORY !!! XXX
- * non mais :P
- */
-/*
- * Ok, ok, j'le ferai plus...
- */
-/*
- * Merci :))
- */
-/*
- * Vous pourriez signer vos commentaires (m�e si on voit bien qui peut
- * �rire ce genre de trucs :p), et �rire en anglais, bordel de
- * merde :p.
- */
-/*
- * Alors la ouai �est fou les gens qui �rivent des commentaires sans les
- * signer. Ca m�iterait un coup de pied dans le cul � :)
- */
-
 int  E_(MMSTUOpen)( access_t *p_access )
 {
     access_sys_t   *p_sys;
@@ -134,6 +119,7 @@ int  E_(MMSTUOpen)( access_t *p_access )
     {
         msg_Err( p_access, "invalid server name" );
         vlc_UrlClean( &p_sys->url );
+        free( p_sys );
         return VLC_EGENERIC;
     }
     if( p_sys->url.i_port <= 0 )
@@ -173,6 +159,7 @@ int  E_(MMSTUOpen)( access_t *p_access )
     {
         msg_Err( p_access, "cannot connect to server" );
         vlc_UrlClean( &p_sys->url );
+        free( p_sys );
         return VLC_EGENERIC;
     }
 
@@ -203,8 +190,7 @@ int  E_(MMSTUOpen)( access_t *p_access )
     if( MMSStart( p_access, 0xffffffff ) < 0 )
     {
         msg_Err( p_access, "cannot start stream" );
-        MMSClose( p_access );
-        vlc_UrlClean( &p_sys->url );
+        E_(MMSTUClose) ( p_access );
         return VLC_EGENERIC;
     }
     return VLC_SUCCESS;
@@ -289,6 +275,7 @@ static int Control( access_t *p_access, int i_query, va_list args )
         case ACCESS_SET_TITLE:
         case ACCESS_SET_SEEKPOINT:
         case ACCESS_SET_PRIVATE_ID_STATE:
+        case ACCESS_GET_CONTENT_TYPE:
             return VLC_EGENERIC;
 
 
@@ -390,7 +377,7 @@ static int Seek( access_t * p_access, int64_t i_pos )
 /*****************************************************************************
  * Read:
  *****************************************************************************/
-static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
+static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
 {
     access_sys_t *p_sys = p_access->p_sys;
     size_t      i_data;
@@ -481,7 +468,7 @@ static int MMSOpen( access_t  *p_access, vlc_url_t *p_url, int  i_proto )
             return VLC_EGENERIC;
         }
 
-        p_sys->i_handle_udp = net_ListenUDP1( p_access, p_sys->sz_bind_addr,
+        p_sys->i_handle_udp = net_ListenUDP1( (vlc_object_t *)p_access, p_sys->sz_bind_addr,
                                               7000 );
         if( p_sys->i_handle_udp < 0 )
         {
@@ -679,10 +666,12 @@ static int MMSOpen( access_t  *p_access, vlc_url_t *p_url, int  i_proto )
         GetDWLE( p_sys->p_cmd + MMS_CMD_HEADERSIZE + 60 );
 
     msg_Dbg( p_access,
-             "answer 0x06 flags:0x%8.8x media_length:%us packet_length:%ul packet_count:%u max_bit_rate:%d header_size:%d",
+             "answer 0x06 flags:0x%8.8x media_length:%us "
+             "packet_length:%ul packet_count:%d max_bit_rate:%d "
+             "header_size:%d",
              p_sys->i_flags_broadcast,
              p_sys->i_media_length,
-             p_sys->i_packet_length,
+             (unsigned)p_sys->i_packet_length,
              p_sys->i_packet_count,
              p_sys->i_max_bit_rate,
              p_sys->i_header_size );
@@ -985,14 +974,13 @@ static int NetFillBuffer( access_t *p_access )
 
 #else
     access_sys_t    *p_sys = p_access->p_sys;
-    struct timeval  timeout;
-    fd_set          fds_r, fds_e;
     int             i_ret;
+    struct pollfd   ufd[2];
+    unsigned        timeout, nfd;
 
     /* FIXME when using udp */
     ssize_t i_tcp, i_udp;
     ssize_t i_tcp_read, i_udp_read;
-    int i_handle_max;
     int i_try = 0;
 
     i_tcp = MMS_BUFFER_SIZE/2 - p_sys->i_buffer_tcp;
@@ -1006,14 +994,7 @@ static int NetFillBuffer( access_t *p_access )
         i_udp = 0;  /* there isn't udp socket */
     }
 
-    i_handle_max = 0;
-
-    if( i_tcp > 0 )
-        i_handle_max = __MAX( i_handle_max, p_sys->i_handle_tcp );
-    if( i_udp > 0 )
-        i_handle_max = __MAX( i_handle_max, p_sys->i_handle_udp );
-
-    if( i_handle_max == 0 )
+    if( ( i_udp <= 0 ) && ( i_tcp <= 0 ) )
     {
         msg_Warn( p_access, "nothing to read %d:%d", (int)i_tcp, (int)i_udp );
         return 0;
@@ -1029,23 +1010,24 @@ static int NetFillBuffer( access_t *p_access )
         i_try++;
 
         /* Initialize file descriptor set */
-        FD_ZERO( &fds_r );
-        FD_ZERO( &fds_e );
+        memset (ufd, 0, sizeof (ufd));
+        nfd = 0;
 
         if( i_tcp > 0 )
         {
-            FD_SET( p_sys->i_handle_tcp, &fds_r );
-            FD_SET( p_sys->i_handle_tcp, &fds_e );
+            ufd[nfd].fd = p_sys->i_handle_tcp;
+            ufd[nfd].events = POLLIN;
+            nfd++;
         }
         if( i_udp > 0 )
         {
-            FD_SET( p_sys->i_handle_udp, &fds_r );
-            FD_SET( p_sys->i_handle_udp, &fds_e );
+            ufd[nfd].fd = p_sys->i_handle_tcp;
+            ufd[nfd].events = POLLIN;
+            nfd++;
         }
 
         /* We'll wait 0.5 second if nothing happens */
-        timeout.tv_sec = 0;
-        timeout.tv_usec = 500000;
+        timeout = 500;
 
         if( i_try > 3 && (p_sys->i_buffer_tcp > 0 || p_sys->i_buffer_udp > 0) )
         {
@@ -1056,18 +1038,18 @@ static int NetFillBuffer( access_t *p_access )
 
         //msg_Dbg( p_access, "NetFillBuffer: trying again (select)" );
 
-    } while( !(i_ret = select(i_handle_max +1, &fds_r, 0, &fds_e, &timeout)) ||
+    } while( !(i_ret = poll( ufd, nfd, timeout)) ||
              (i_ret < 0 && errno == EINTR) );
 
     if( i_ret < 0 )
     {
-        msg_Err( p_access, "network select error (%s)", strerror(errno) );
+        msg_Err( p_access, "network poll error (%m)" );
         return -1;
     }
 
     i_tcp_read = i_udp_read = 0;
 
-    if( i_tcp > 0 && FD_ISSET( p_sys->i_handle_tcp, &fds_r ) )
+    if( ( i_tcp > 0 ) && ufd[0].revents )
     {
         i_tcp_read =
             recv( p_sys->i_handle_tcp,
@@ -1075,7 +1057,7 @@ static int NetFillBuffer( access_t *p_access )
                   i_tcp + MMS_BUFFER_SIZE/2, 0 );
     }
 
-    if( i_udp > 0 && FD_ISSET( p_sys->i_handle_udp, &fds_r ) )
+    if( i_udp > 0 && ufd[i_tcp > 0].revents )
     {
         i_udp_read = recv( p_sys->i_handle_udp,
                            p_sys->buffer_udp + p_sys->i_buffer_udp,
@@ -1117,10 +1099,7 @@ static int  mms_ParseCommand( access_t *p_access,
     int         i_length;
     uint32_t    i_id;
 
-    if( p_sys->p_cmd )
-    {
-        free( p_sys->p_cmd );
-    }
+    free( p_sys->p_cmd );
     p_sys->i_cmd = i_data;
     p_sys->p_cmd = malloc( i_data );
     memcpy( p_sys->p_cmd, p_data, i_data );
@@ -1237,14 +1216,15 @@ static int  mms_ParsePacket( access_t *p_access,
 
     if( i_packet_seq_num != p_sys->i_packet_seq_num )
     {
+#if 0
         /* FIXME for udp could be just wrong order ? */
         msg_Warn( p_access,
                   "detected packet lost (%d != %d)",
                   i_packet_seq_num,
                   p_sys->i_packet_seq_num );
-        p_sys->i_packet_seq_num = i_packet_seq_num;
+#endif
     }
-    p_sys->i_packet_seq_num++;
+    p_sys->i_packet_seq_num = i_packet_seq_num + 1;
 
     if( i_packet_id == p_sys->i_header_packet_id_type )
     {