]> git.sesse.net Git - vlc/blobdiff - modules/access/mms/mmstu.c
Remove useless <fcntl.h> inclusions
[vlc] / modules / access / mms / mmstu.c
index 9f24789c5162c1fe29b47a4407da64f91b28e437..12fb209a9f98c023618efb102cfd7f8cdac03b05 100644 (file)
 #ifdef HAVE_UNISTD_H
 #   include <unistd.h>
 #endif
-#ifdef HAVE_FCNTL_H
-#   include <fcntl.h>
-#endif
-#ifdef HAVE_SYS_TIME_H
-#   include <sys/time.h>
-#endif
 #ifdef HAVE_SYS_TYPES_H
 #   include <sys/types.h>
 #endif
-#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"
+#include <vlc_url.h>
 #include "asf.h"
 #include "buffer.h"
 
@@ -201,6 +192,11 @@ int  MMSTUOpen( access_t *p_access )
 
     /* Keep the connection alive when paused */
     p_sys->p_keepalive = malloc( sizeof( mmstu_keepalive_t ) );
+    if( !p_sys->p_keepalive )
+    {
+        MMSTUClose ( p_access );
+        return VLC_ENOMEM;
+    }
     p_sys->p_keepalive->p_access = p_access;
     vlc_mutex_init( &p_sys->p_keepalive->lock );
     vlc_cond_init( &p_sys->p_keepalive->wait );
@@ -253,7 +249,6 @@ static int Control( access_t *p_access, int i_query, va_list args )
     bool    b_bool;
     int64_t      *pi_64;
     int           i_int;
-    vlc_value_t  val;
 
     switch( i_query )
     {
@@ -286,7 +281,6 @@ static int Control( access_t *p_access, int i_query, va_list args )
         /* */
         case ACCESS_GET_PTS_DELAY:
             pi_64 = (int64_t*)va_arg( args, int64_t * );
-            var_Get( p_access, "mms-caching", &val );
             *pi_64 = (int64_t)var_GetInteger( p_access, "mms-caching" ) * INT64_C(1000);
             break;
 
@@ -307,11 +301,14 @@ static int Control( access_t *p_access, int i_query, va_list args )
             else
                 Seek( p_access, p_access->info.i_pos );
 
-            vlc_mutex_lock( &p_sys->p_keepalive->lock );
-            p_sys->p_keepalive->b_paused = b_bool;
-            if( b_bool )
-                vlc_cond_signal( &p_sys->p_keepalive->wait );
-            vlc_mutex_unlock( &p_sys->p_keepalive->lock );
+            if( p_sys->p_keepalive )
+            {
+                vlc_mutex_lock( &p_sys->p_keepalive->lock );
+                p_sys->p_keepalive->b_paused = b_bool;
+                if( b_bool )
+                    vlc_cond_signal( &p_sys->p_keepalive->wait );
+                vlc_mutex_unlock( &p_sys->p_keepalive->lock );
+            }
             break;
 
         case ACCESS_GET_TITLE_INFO:
@@ -364,6 +361,9 @@ static int Seek( access_t * p_access, int64_t i_pos )
         i_packet = ( i_pos - p_sys->i_header ) / p_sys->i_packet_length;
         i_offset = ( i_pos - p_sys->i_header ) % p_sys->i_packet_length;
     }
+    if( p_sys->b_seekable && i_packet >= p_sys->i_packet_count )
+        return VLC_EGENERIC;
+
     msg_Dbg( p_access, "seeking to %"PRId64 " (packet:%d)", i_pos, i_packet );
 
     MMSStop( p_access );
@@ -594,7 +594,7 @@ static int MMSOpen( access_t  *p_access, vlc_url_t *p_url, int  i_proto )
 #define GETUTF16( psz, size ) \
     { \
         int i; \
-        psz = malloc( size + 1); \
+        psz = xmalloc( size + 1); \
         for( i = 0; i < size; i++ ) \
         { \
             psz[i] = p[i]; \
@@ -731,11 +731,11 @@ static int MMSOpen( access_t  *p_access, vlc_url_t *p_url, int  i_proto )
 
     msg_Dbg( p_access,
              "answer 0x06 flags:0x%8.8"PRIx32" media_length:%"PRIu32"s "
-             "packet_length:%u packet_count:%"PRId32" max_bit_rate:%d "
+             "packet_length:%zu packet_count:%"PRIu32" max_bit_rate:%d "
              "header_size:%zu",
              p_sys->i_flags_broadcast,
              p_sys->i_media_length,
-             (unsigned)p_sys->i_packet_length,
+             p_sys->i_packet_length,
              p_sys->i_packet_count,
              p_sys->i_max_bit_rate,
              p_sys->i_header_size );
@@ -1026,6 +1026,7 @@ static int mms_CommandSend( access_t *p_access, int i_command,
     vlc_mutex_unlock( &p_sys->lock_netwrite );
     if( i_ret != buffer.i_data - ( 8 - ( i_data - i_data_old ) ) )
     {
+        var_buffer_free( &buffer );
         msg_Err( p_access, "failed to send command" );
         return VLC_EGENERIC;
     }
@@ -1175,7 +1176,7 @@ static int  mms_ParseCommand( access_t *p_access,
 
     free( p_sys->p_cmd );
     p_sys->i_cmd = i_data;
-    p_sys->p_cmd = malloc( i_data );
+    p_sys->p_cmd = xmalloc( i_data );
     memcpy( p_sys->p_cmd, p_data, i_data );
 
     *pi_used = i_data; /* by default */
@@ -1298,8 +1299,8 @@ static int  mms_ParsePacket( access_t *p_access,
     {
         if( p_sys->p_header )
         {
-            p_sys->p_header = realloc( p_sys->p_header,
-                                          p_sys->i_header + i_packet_length - 8 );
+            p_sys->p_header = xrealloc( p_sys->p_header,
+                                      p_sys->i_header + i_packet_length - 8 );
             memcpy( &p_sys->p_header[p_sys->i_header],
                     p_data + 8, i_packet_length - 8 );
             p_sys->i_header += i_packet_length - 8;
@@ -1307,7 +1308,7 @@ static int  mms_ParsePacket( access_t *p_access,
         }
         else
         {
-            uint8_t* p_packet = malloc( i_packet_length - 8 ); // don't bother with preheader
+            uint8_t* p_packet = xmalloc( i_packet_length - 8 ); // don't bother with preheader
             memcpy( p_packet, p_data + 8, i_packet_length - 8 );
             p_sys->p_header = p_packet;
             p_sys->i_header = i_packet_length - 8;
@@ -1320,7 +1321,7 @@ static int  mms_ParsePacket( access_t *p_access,
     }
     else
     {
-        uint8_t* p_packet = malloc( i_packet_length - 8 ); // don't bother with preheader
+        uint8_t* p_packet = xmalloc( i_packet_length - 8 ); // don't bother with preheader
         memcpy( p_packet, p_data + 8, i_packet_length - 8 );
         FREENULL( p_sys->p_media );
         p_sys->p_media = p_packet;