]> git.sesse.net Git - vlc/blobdiff - modules/access/mtp.c
Qt: Make fullscreen bar thinner in one line interface profile.
[vlc] / modules / access / mtp.c
index 91cd8848ce56fa0a1894c95b9eb3224fa3fc07da..baf90c57a44cee5d13d6faf6f60b24732b1f84f1 100644 (file)
@@ -1,26 +1,26 @@
 /*****************************************************************************
  * mtp.c: mtp input (mtp: access plug-in)
  *****************************************************************************
- * Copyright (C) 2001-2006 the VideoLAN team
+ * Copyright (C) 2001-2006 VLC authors and VideoLAN
  * Copyright © 2006-2008 Rémi Denis-Courmont
  *
  * Authors: Fabio Ritrovato <exsephiroth87@gmail.com>
  * Original file.c: Christophe Massiot <massiot@via.ecp.fr>
  *                  Rémi Denis-Courmont <rem # videolan # org>
  *
- * 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 "config.h"
 #endif
 
+#include <assert.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_input.h>
 #include <vlc_access.h>
 #include <vlc_dialog.h>
-
-#include <assert.h>
-#include <errno.h>
-#ifdef HAVE_SYS_TYPES_H
-#   include <sys/types.h>
-#endif
-#ifdef HAVE_SYS_STAT_H
-#   include <sys/stat.h>
-#endif
-#ifdef HAVE_FCNTL_H
-#   include <fcntl.h>
-#endif
-
-#include <unistd.h>
-#include <poll.h>
-
-#include <vlc_charset.h>
+#include <vlc_fs.h>
 
 #include "libmtp.h"
 
 static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
 
-#define CACHING_TEXT N_("Caching value in ms")
-#define CACHING_LONGTEXT N_( \
-    "Caching value for files. This " \
-    "value should be set in milliseconds." )
-
 vlc_module_begin()
     set_description( N_("MTP input") )
     set_shortname( N_("MTP") )
@@ -81,7 +67,7 @@ vlc_module_end()
  * Exported prototypes
  *****************************************************************************/
 
-static int  Seek( access_t *, int64_t );
+static int  Seek( access_t *, uint64_t );
 static ssize_t Read( access_t *, uint8_t *, size_t );
 static int  Control( access_t *, int, va_list );
 
@@ -109,11 +95,8 @@ static int Open( vlc_object_t *p_this )
     int i_numrawdevices;
     int i_ret;
 
-    /* Update default_pts to a suitable value for file access */
-    var_Create( p_access, "file-caching", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
-
-    if( sscanf( p_access->psz_path, "%"SCNu32":%"SCNu8":%"SCNu16":%d", &i_bus,
-                &i_dev, &i_product_id, &i_track_id ) != 4 )
+    if( sscanf( p_access->psz_location, "%"SCNu32":%"SCNu8":%"SCNu16":%d",
+                &i_bus, &i_dev, &i_product_id, &i_track_id ) != 4 )
         return VLC_EGENERIC;
     i_ret = LIBMTP_Detect_Raw_Devices( &p_rawdevices, &i_numrawdevices );
     if( i_ret != 0 || i_numrawdevices <= 0 || !p_rawdevices )
@@ -128,8 +111,10 @@ static int Open( vlc_object_t *p_this )
             if( ( p_device = LIBMTP_Open_Raw_Device( &p_rawdevices[i] )
                 ) != NULL )
             {
-                free( p_access->psz_path );
-                if( ( p_access->psz_path = tempnam( NULL, "vlc" ) ) == NULL )
+                free( p_access->psz_filepath );
+#warning Oooh no! Not tempnam()!
+                p_access->psz_filepath = tempnam( NULL, "vlc" );
+                if( p_access->psz_filepath == NULL )
                 {
                     LIBMTP_Release_Device( p_device );
                     free( p_rawdevices );
@@ -137,9 +122,11 @@ static int Open( vlc_object_t *p_this )
                 }
                 else
                 {
-                    msg_Dbg( p_access, "About to write %s", p_access->psz_path );
+                    msg_Dbg( p_access, "About to write %s",
+                             p_access->psz_filepath );
                     LIBMTP_Get_File_To_File( p_device, i_track_id,
-                                             p_access->psz_path, NULL, NULL );
+                                             p_access->psz_filepath, NULL,
+                                             NULL );
                     LIBMTP_Release_Device( p_device );
                     i = i_numrawdevices;
                 }
@@ -158,8 +145,8 @@ static int Open( vlc_object_t *p_this )
     int fd = p_sys->fd = -1;
 
     /* Open file */
-    msg_Dbg( p_access, "opening file `%s'", p_access->psz_path );
-    fd = open_file( p_access, p_access->psz_path );
+    msg_Dbg( p_access, "opening file `%s'", p_access->psz_filepath );
+    fd = open_file( p_access, p_access->psz_filepath );
 
     if( fd == -1 )
     {
@@ -168,14 +155,10 @@ static int Open( vlc_object_t *p_this )
     }
     p_sys->fd = fd;
 
-#ifdef HAVE_SYS_STAT_H
     struct stat st;
     if( fstat( fd, &st ) )
         msg_Err( p_access, "fstat(%d): %m", fd );
     p_access->info.i_size = st.st_size;
-#else
-# warning File size not known!
-#endif
 
     return VLC_SUCCESS;
 }
@@ -189,8 +172,9 @@ static void Close( vlc_object_t * p_this )
     access_sys_t *p_sys = p_access->p_sys;
 
     close ( p_sys->fd );
-    if(        utf8_unlink( p_access->psz_path ) != 0 )
-        msg_Err( p_access, "Error deleting file %s, %m", p_access->psz_path );
+    if(        vlc_unlink( p_access->psz_filepath ) != 0 )
+        msg_Err( p_access, "Error deleting file %s, %m",
+                 p_access->psz_filepath );
     free( p_sys );
 }
 
@@ -215,7 +199,7 @@ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
 
             default:
                 msg_Err( p_access, "read failed (%m)" );
-                dialog_Fatal( p_access, _( "File reading failed" ), "%s",
+                dialog_Fatal( p_access, _( "File reading failed" ), "%s (%m)",
                                 _( "VLC could not read the file." ) );
                 p_access->info.b_eof = true;
                 return 0;
@@ -235,7 +219,7 @@ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
 /*****************************************************************************
  * Seek: seek to a specific location in a file
  *****************************************************************************/
-static int Seek( access_t *p_access, int64_t i_pos )
+static int Seek( access_t *p_access, uint64_t i_pos )
 {
     p_access->info.i_pos = i_pos;
     p_access->info.b_eof = false;
@@ -269,7 +253,8 @@ 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 * );
-            *pi_64 = var_GetInteger( p_access, "file-caching" ) * INT64_C( 1000 );
+            *pi_64 = INT64_C(1000)
+                   * var_InheritInteger( p_access, "file-caching" );
             break;
 
         /* */
@@ -299,27 +284,19 @@ static int Control( access_t *p_access, int i_query, va_list args )
  *****************************************************************************/
 static int open_file( access_t *p_access, const char *path )
 {
-    int fd = utf8_open( path, O_RDONLY | O_NONBLOCK );
+    int fd = vlc_open( path, O_RDONLY | O_NONBLOCK );
     if( fd == -1 )
     {
         msg_Err( p_access, "cannot open file %s (%m)", path );
         dialog_Fatal( p_access, _( "File reading failed" ),
-                        _( "VLC could not open the file \"%s\"." ), path );
+                        _( "VLC could not open the file \"%s\". (%m)" ), path );
         return -1;
     }
-
-#if defined( HAVE_FCNTL )
-    fcntl( fd, F_SETFD, fcntl( fd, F_GETFD ) | FD_CLOEXEC );
-
-    /* We'd rather use any available memory for reading ahead
-     * than for caching what we've already seen/heard */
-# if defined( F_RDAHEAD )
+#ifdef F_RDAHEAD
     fcntl( fd, F_RDAHEAD, 1 );
-# endif
-# if defined( F_NOCACHE )
-    fcntl( fd, F_NOCACHE, 1 );
-# endif
 #endif
-
+#ifdef F_NOCACHE
+    fcntl( fd, F_NOCACHE, 0 );
+#endif
     return fd;
 }