]> git.sesse.net Git - vlc/blobdiff - modules/access/mms/mmstu.c
Mark unreachable code on GCC even if NDEBUG
[vlc] / modules / access / mms / mmstu.c
index b74be96571b62d6d9b8adae96533400f17b2a8b4..4c0a8c21240dcfa8955ba1b2544f905129ed79bd 100644 (file)
@@ -1,24 +1,24 @@
 /*****************************************************************************
  * mmstu.c: MMS access plug-in
  *****************************************************************************
- * Copyright (C) 2001, 2002 the VideoLAN team
+ * Copyright (C) 2001, 2002 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Laurent Aimar <fenrir@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
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 
 #include <errno.h>
 #include <assert.h>
 
-#ifdef HAVE_UNISTD_H
-#   include <unistd.h>
-#endif
 #include <sys/types.h>
+#include <unistd.h>
 #ifdef HAVE_POLL
 #   include <poll.h>
 #endif
@@ -140,7 +138,7 @@ int  MMSTUOpen( access_t *p_access )
     {   /* first try with TCP and then UDP*/
         if( ( i_status = MMSOpen( p_access, &p_sys->url, MMS_PROTO_TCP ) ) )
         {
-            if( !p_access->b_die )
+            if( vlc_object_alive(p_access) )
                 i_status = MMSOpen( p_access, &p_sys->url, MMS_PROTO_UDP );
         }
     }
@@ -176,7 +174,7 @@ int  MMSTUOpen( access_t *p_access )
     else
     {
         p_sys->b_seekable = true;
-        p_access->info.i_size =
+        p_sys->i_size =
             (uint64_t)p_sys->i_header +
             (uint64_t)p_sys->i_packet_count * (uint64_t)p_sys->i_packet_length;
     }
@@ -224,7 +222,6 @@ static int Control( access_t *p_access, int i_query, va_list args )
 
     switch( i_query )
     {
-        /* */
         case ACCESS_CAN_SEEK:
             pb_bool = (bool*)va_arg( args, bool* );
             *pb_bool = p_sys->b_seekable;
@@ -250,7 +247,10 @@ static int Control( access_t *p_access, int i_query, va_list args )
             *pb_bool = true;
             break;
 
-        /* */
+        case ACCESS_GET_SIZE:
+            *va_arg( args, uint64_t * ) = p_sys->i_size;
+            break;
+
         case ACCESS_GET_PTS_DELAY:
             pi_64 = (int64_t*)va_arg( args, int64_t * );
             *pi_64 = INT64_C(1000)
@@ -266,7 +266,6 @@ static int Control( access_t *p_access, int i_query, va_list args )
             *pb_bool =  p_sys->asfh.stream[i_int].i_selected ? true : false;
             break;
 
-        /* */
         case ACCESS_SET_PAUSE_STATE:
             b_bool = (bool)va_arg( args, int );
             if( b_bool )
@@ -281,18 +280,8 @@ static int Control( access_t *p_access, int i_query, va_list args )
             }
             break;
 
-        case ACCESS_GET_TITLE_INFO:
-        case ACCESS_SET_TITLE:
-        case ACCESS_SET_SEEKPOINT:
-        case ACCESS_SET_PRIVATE_ID_STATE:
-        case ACCESS_GET_CONTENT_TYPE:
-            return VLC_EGENERIC;
-
-
         default:
-            msg_Warn( p_access, "unimplemented query in control" );
             return VLC_EGENERIC;
-
     }
     return VLC_SUCCESS;
 }
@@ -411,7 +400,7 @@ static block_t *Block( access_t *p_access )
     {
         const size_t i_copy = p_sys->i_header - p_access->info.i_pos;
 
-        block_t *p_block = block_New( p_access, i_copy );
+        block_t *p_block = block_Alloc( i_copy );
         if( !p_block )
             return NULL;
 
@@ -429,7 +418,7 @@ static block_t *Block( access_t *p_access )
         if( __MAX( p_sys->i_media, p_sys->i_media_used ) < p_sys->i_packet_length )
             i_padding = p_sys->i_packet_length - __MAX( p_sys->i_media, p_sys->i_media_used );
 
-        block_t *p_block = block_New( p_access, i_copy + i_padding );
+        block_t *p_block = block_Alloc( i_copy + i_padding );
         if( !p_block )
             return NULL;
 
@@ -456,7 +445,7 @@ static int MMSOpen( access_t  *p_access, vlc_url_t *p_url, int  i_proto )
     int           b_udp = ( i_proto == MMS_PROTO_UDP ) ? 1 : 0;
 
     var_buffer_t buffer;
-    char         tmp[4096];
+    char         *tmp;
     uint16_t     *p;
     int          i_server_version;
     int          i_tool_version;
@@ -532,11 +521,18 @@ static int MMSOpen( access_t  *p_access, vlc_url_t *p_url, int  i_proto )
     var_buffer_initwrite( &buffer, 0 );
     var_buffer_add16( &buffer, 0x001c );
     var_buffer_add16( &buffer, 0x0003 );
-    sprintf( tmp,
+    if( asprintf( &tmp,
              "NSPlayer/7.0.0.1956; {"GUID_FMT"}; Host: %s",
              GUID_PRINT( p_sys->guid ),
-             p_url->psz_host );
-    var_buffer_addUTF16( &buffer, tmp );
+             p_url->psz_host ) < 0 )
+    {
+        var_buffer_free( &buffer );
+        net_Close( p_sys->i_handle_tcp );
+        return VLC_ENOMEM;
+    }
+
+    var_buffer_addUTF16( p_access, &buffer, tmp );
+    free( tmp );
 
     mms_CommandSend( p_access,
                      0x01,          /* connexion request */
@@ -589,17 +585,28 @@ static int MMSOpen( access_t  *p_access, vlc_url_t *p_url, int  i_proto )
     var_buffer_add32( &buffer, 0x00000002 );
     if( b_udp )
     {
-        sprintf( tmp,
-                 "\\\\%s\\UDP\\%d",
-                 p_sys->sz_bind_addr,
-                 7000 ); // FIXME
+        if( asprintf( &tmp,
+                    "\\\\%s\\UDP\\%d",
+                    p_sys->sz_bind_addr,
+                    7000 ) < 0) // FIXME
+        {
+            var_buffer_free( &buffer );
+            MMSClose( p_access );
+            return VLC_EGENERIC;
+        }
     }
     else
     {
-        sprintf( tmp, "\\\\192.168.0.1\\TCP\\1242"  );
+        if( asprintf( &tmp, "\\\\192.168.0.1\\TCP\\1242" ) < 0 )
+        {
+            var_buffer_free( &buffer );
+            MMSClose( p_access );
+            return VLC_EGENERIC;
+        }
     }
-    var_buffer_addUTF16( &buffer, tmp );
+    var_buffer_addUTF16( p_access, &buffer, tmp );
     var_buffer_add16( &buffer, '0' );
+    free( tmp );
 
     mms_CommandSend( p_access,
                      0x02,          /* connexion request */
@@ -633,7 +640,7 @@ static int MMSOpen( access_t  *p_access, vlc_url_t *p_url, int  i_proto )
     {
         mediapath++;
     }
-    var_buffer_addUTF16( &buffer, mediapath );
+    var_buffer_addUTF16( p_access, &buffer, mediapath );
 
     mms_CommandSend( p_access,
                      0x05,
@@ -784,7 +791,7 @@ static int MMSOpen( access_t  *p_access, vlc_url_t *p_url, int  i_proto )
     for( i = 1; i < 128; i++ )
     {
 
-        if( p_sys->asfh.stream[i].i_cat != ASF_STREAM_UNKNOWN )
+        if( p_sys->asfh.stream[i].i_cat != ASF_CODEC_TYPE_UNKNOWN )
         {
             i_streams++;
             if( i_first != -1 )
@@ -802,7 +809,7 @@ static int MMSOpen( access_t  *p_access, vlc_url_t *p_url, int  i_proto )
                 msg_Info( p_access,
                           "selecting stream[0x%x] %s (%d Kib/s)",
                           i,
-                          ( p_sys->asfh.stream[i].i_cat == ASF_STREAM_AUDIO  ) ?
+                          ( p_sys->asfh.stream[i].i_cat == ASF_CODEC_TYPE_AUDIO  ) ?
                                                   "audio" : "video" ,
                           p_sys->asfh.stream[i].i_bitrate / 1024);
             }
@@ -812,7 +819,7 @@ static int MMSOpen( access_t  *p_access, vlc_url_t *p_url, int  i_proto )
                 msg_Info( p_access,
                           "ignoring stream[0x%x] %s (%d Kib/s)",
                           i,
-                          ( p_sys->asfh.stream[i].i_cat == ASF_STREAM_AUDIO  ) ?
+                          ( p_sys->asfh.stream[i].i_cat == ASF_CODEC_TYPE_AUDIO  ) ?
                                     "audio" : "video" ,
                           p_sys->asfh.stream[i].i_bitrate / 1024);
 
@@ -1004,10 +1011,6 @@ static int mms_CommandSend( access_t *p_access, int i_command,
 
 static int NetFillBuffer( access_t *p_access )
 {
-#ifdef UNDER_CE
-    return -1;
-
-#else
     access_sys_t    *p_sys = p_access->p_sys;
     int             i_ret;
     struct pollfd   ufd[2];
@@ -1085,7 +1088,7 @@ static int NetFillBuffer( access_t *p_access )
 
     if( i_ret < 0 )
     {
-        msg_Err( p_access, "network poll error (%m)" );
+        msg_Err( p_access, "network poll error: %s", vlc_strerror_c(errno) );
         return -1;
     }
 
@@ -1124,7 +1127,6 @@ static int NetFillBuffer( access_t *p_access )
     if( i_udp_read > 0 ) p_sys->i_buffer_udp += i_udp_read;
 
     return i_tcp_read + i_udp_read;
-#endif
 }
 
 static int  mms_ParseCommand( access_t *p_access,
@@ -1571,7 +1573,7 @@ static void *KeepAliveThread( void *p_data )
 
         msleep( 10 * CLOCK_FREQ );
     }
-    assert(0);
+    vlc_assert_unreachable();
 }
 
 static void KeepAliveStart( access_t *p_access )