2002-08-04 19:23:44 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* file.c: file input (file: access plug-in)
|
|
|
|
*****************************************************************************
|
2006-04-29 15:55:07 +02:00
|
|
|
* Copyright (C) 2001-2006 the VideoLAN team
|
2007-11-26 21:27:15 +01:00
|
|
|
* Copyright © 2006-2007 Rémi Denis-Courmont
|
2004-03-10 18:10:40 +01:00
|
|
|
* $Id$
|
2002-08-04 19:23:44 +02:00
|
|
|
*
|
|
|
|
* Authors: Christophe Massiot <massiot@via.ecp.fr>
|
2006-04-29 15:55:07 +02:00
|
|
|
* Rémi Denis-Courmont <rem # videolan # org>
|
2002-08-04 19:23:44 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* (at your option) any later version.
|
2004-06-03 02:08:54 +02:00
|
|
|
*
|
2002-08-04 19:23:44 +02:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2006-01-13 00:10:04 +01:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
|
2002-08-04 19:23:44 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Preamble
|
|
|
|
*****************************************************************************/
|
2008-01-23 22:50:58 +01:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2008-05-31 20:49:57 +02:00
|
|
|
#include <vlc_common.h>
|
2008-05-08 17:30:33 +02:00
|
|
|
#include <vlc_plugin.h>
|
2006-11-26 15:20:34 +01:00
|
|
|
#include <vlc_input.h>
|
|
|
|
#include <vlc_access.h>
|
2009-03-05 20:09:21 +01:00
|
|
|
#include <vlc_dialog.h>
|
2002-08-04 19:23:44 +02:00
|
|
|
|
2007-11-26 21:27:15 +01:00
|
|
|
#include <assert.h>
|
2004-10-04 16:09:33 +02:00
|
|
|
#include <errno.h>
|
2002-11-20 14:37:36 +01:00
|
|
|
#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
|
2009-06-25 19:30:57 +02:00
|
|
|
#if defined (__linux__)
|
|
|
|
# include <sys/vfs.h>
|
|
|
|
# include <linux/magic.h>
|
|
|
|
#elif defined (HAVE_SYS_MOUNT_H)
|
2009-08-03 17:09:32 +02:00
|
|
|
# include <sys/param.h>
|
2009-06-25 19:30:57 +02:00
|
|
|
# include <sys/mount.h>
|
2009-06-25 18:40:37 +02:00
|
|
|
#endif
|
2002-11-20 14:37:36 +01:00
|
|
|
|
2008-10-06 12:40:19 +02:00
|
|
|
#if defined( WIN32 )
|
2006-04-29 16:23:00 +02:00
|
|
|
# include <io.h>
|
2008-03-19 17:46:53 +01:00
|
|
|
# include <ctype.h>
|
2009-07-23 17:08:44 +02:00
|
|
|
# include <shlwapi.h>
|
2006-04-29 16:23:00 +02:00
|
|
|
#else
|
2002-08-04 19:23:44 +02:00
|
|
|
# include <unistd.h>
|
2006-04-29 15:55:07 +02:00
|
|
|
# include <poll.h>
|
2002-08-04 19:23:44 +02:00
|
|
|
#endif
|
|
|
|
|
2003-05-08 17:58:56 +02:00
|
|
|
#if defined( WIN32 ) && !defined( UNDER_CE )
|
2004-10-05 17:31:22 +02:00
|
|
|
# ifdef lseek
|
|
|
|
# undef lseek
|
|
|
|
# endif
|
|
|
|
# define lseek _lseeki64
|
|
|
|
#elif defined( UNDER_CE )
|
2008-10-06 12:40:19 +02:00
|
|
|
/* FIXME the commandline on wince is a mess */
|
|
|
|
# define dup(a) -1
|
2009-07-27 17:36:09 +02:00
|
|
|
# define PathIsNetworkPathW(wpath) (! wcsncmp(wpath, L"\\\\", 2))
|
2004-03-10 18:10:40 +01:00
|
|
|
#endif
|
|
|
|
|
2006-11-26 15:20:34 +01:00
|
|
|
#include <vlc_charset.h>
|
2005-08-03 21:01:44 +02:00
|
|
|
|
2002-11-12 14:57:13 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* Module descriptor
|
|
|
|
*****************************************************************************/
|
2004-06-03 02:08:54 +02:00
|
|
|
static int Open ( vlc_object_t * );
|
|
|
|
static void Close( vlc_object_t * );
|
|
|
|
|
2009-07-20 18:37:17 +02:00
|
|
|
#define CACHING_TEXT N_("Caching value (ms)")
|
2002-12-12 16:10:58 +01:00
|
|
|
#define CACHING_LONGTEXT N_( \
|
2009-07-20 18:37:17 +02:00
|
|
|
"Caching value for files, in milliseconds." )
|
|
|
|
|
|
|
|
#define NETWORK_CACHING_TEXT N_("Extra network caching value (ms)")
|
|
|
|
#define NETWORK_CACHING_LONGTEXT N_( \
|
|
|
|
"Supplementary caching value for remote files, in milliseconds." )
|
2002-12-12 16:10:58 +01:00
|
|
|
|
2008-10-29 20:59:01 +01:00
|
|
|
vlc_module_begin ()
|
|
|
|
set_description( N_("File input") )
|
|
|
|
set_shortname( N_("File") )
|
|
|
|
set_category( CAT_INPUT )
|
|
|
|
set_subcategory( SUBCAT_INPUT_ACCESS )
|
2009-07-20 18:37:17 +02:00
|
|
|
add_integer( "file-caching", DEFAULT_PTS_DELAY / 1000, NULL,
|
|
|
|
CACHING_TEXT, CACHING_LONGTEXT, true )
|
|
|
|
change_safe()
|
|
|
|
add_integer( "network-caching", 3 * DEFAULT_PTS_DELAY / 1000, NULL,
|
|
|
|
NETWORK_CACHING_TEXT, NETWORK_CACHING_LONGTEXT, true )
|
2009-05-01 14:57:04 +02:00
|
|
|
change_safe()
|
2008-10-29 20:59:01 +01:00
|
|
|
add_obsolete_string( "file-cat" )
|
|
|
|
set_capability( "access", 50 )
|
|
|
|
add_shortcut( "file" )
|
2009-02-21 10:55:14 +01:00
|
|
|
add_shortcut( "fd" )
|
2008-10-29 20:59:01 +01:00
|
|
|
add_shortcut( "stream" )
|
|
|
|
set_callbacks( Open, Close )
|
|
|
|
vlc_module_end ()
|
2004-06-03 02:08:54 +02:00
|
|
|
|
|
|
|
|
2003-01-03 14:07:17 +01:00
|
|
|
/*****************************************************************************
|
2004-06-03 02:08:54 +02:00
|
|
|
* Exported prototypes
|
2003-01-03 14:07:17 +01:00
|
|
|
*****************************************************************************/
|
2004-06-03 02:08:54 +02:00
|
|
|
static int Seek( access_t *, int64_t );
|
2009-02-05 21:27:10 +01:00
|
|
|
static int NoSeek( access_t *, int64_t );
|
2007-12-09 18:39:28 +01:00
|
|
|
static ssize_t Read( access_t *, uint8_t *, size_t );
|
2004-06-03 02:08:54 +02:00
|
|
|
static int Control( access_t *, int, va_list );
|
|
|
|
|
2006-10-31 18:51:59 +01:00
|
|
|
static int open_file( access_t *, const char * );
|
2004-03-10 18:10:40 +01:00
|
|
|
|
2004-06-03 02:08:54 +02:00
|
|
|
struct access_sys_t
|
2003-01-03 14:07:17 +01:00
|
|
|
{
|
2004-06-03 02:08:54 +02:00
|
|
|
unsigned int i_nb_reads;
|
2004-03-10 18:10:40 +01:00
|
|
|
|
2006-11-01 21:50:18 +01:00
|
|
|
int fd;
|
2004-03-10 18:10:40 +01:00
|
|
|
|
2004-06-03 02:08:54 +02:00
|
|
|
/* */
|
2009-07-20 18:37:17 +02:00
|
|
|
unsigned caching;
|
2008-04-14 00:08:29 +02:00
|
|
|
bool b_pace_control;
|
2004-06-03 02:08:54 +02:00
|
|
|
};
|
2003-01-03 14:07:17 +01:00
|
|
|
|
2009-06-25 19:30:57 +02:00
|
|
|
static bool IsRemote (int fd)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_FSTATFS
|
|
|
|
struct statfs stf;
|
|
|
|
|
|
|
|
if (fstatfs (fd, &stf))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
#if defined(MNT_LOCAL)
|
|
|
|
return !(stf.f_flags & MNT_LOCAL);
|
|
|
|
|
|
|
|
#elif defined (__linux__)
|
|
|
|
switch (stf.f_type)
|
|
|
|
{
|
|
|
|
case AFS_SUPER_MAGIC:
|
|
|
|
case CODA_SUPER_MAGIC:
|
|
|
|
case NCP_SUPER_MAGIC:
|
|
|
|
case NFS_SUPER_MAGIC:
|
|
|
|
case SMB_SUPER_MAGIC:
|
|
|
|
case 0xFF534D42 /*CIFS_MAGIC_NUMBER*/:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#else /* !HAVE_FSTATFS */
|
2009-07-23 17:05:08 +02:00
|
|
|
(void)fd;
|
2009-06-25 19:30:57 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-07-23 22:20:12 +02:00
|
|
|
#ifndef HAVE_POSIX_FADVISE
|
|
|
|
# define posix_fadvise(fd, off, len, adv) (0)
|
|
|
|
#endif
|
2009-06-25 19:30:57 +02:00
|
|
|
|
2002-08-04 19:23:44 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* Open: open the file
|
|
|
|
*****************************************************************************/
|
|
|
|
static int Open( vlc_object_t *p_this )
|
|
|
|
{
|
2004-06-03 02:08:54 +02:00
|
|
|
access_t *p_access = (access_t*)p_this;
|
|
|
|
access_sys_t *p_sys;
|
2009-07-23 17:08:44 +02:00
|
|
|
#ifdef WIN32
|
|
|
|
wchar_t wpath[MAX_PATH+1];
|
|
|
|
bool is_remote = false;
|
|
|
|
#endif
|
2004-06-03 02:08:54 +02:00
|
|
|
|
2006-07-19 11:33:41 +02:00
|
|
|
STANDARD_READ_ACCESS_INIT;
|
2004-06-03 02:08:54 +02:00
|
|
|
p_sys->i_nb_reads = 0;
|
2009-04-08 17:49:08 +02:00
|
|
|
p_sys->b_pace_control = true;
|
2002-08-04 19:23:44 +02:00
|
|
|
|
2006-11-01 21:50:18 +01:00
|
|
|
/* Open file */
|
2009-02-05 16:52:52 +01:00
|
|
|
int fd = -1;
|
2009-02-21 10:55:14 +01:00
|
|
|
|
|
|
|
if (!strcasecmp (p_access->psz_access, "fd"))
|
|
|
|
fd = dup (atoi (p_access->psz_path));
|
|
|
|
else if (!strcmp (p_access->psz_path, "-"))
|
2006-11-01 21:50:18 +01:00
|
|
|
fd = dup (0);
|
|
|
|
else
|
2009-02-21 10:55:14 +01:00
|
|
|
{
|
|
|
|
msg_Dbg (p_access, "opening file `%s'", p_access->psz_path);
|
2006-11-01 21:50:18 +01:00
|
|
|
fd = open_file (p_access, p_access->psz_path);
|
2009-07-23 17:08:44 +02:00
|
|
|
#ifdef WIN32
|
|
|
|
if (MultiByteToWideChar (CP_UTF8, 0, p_access->psz_path, -1,
|
|
|
|
wpath, MAX_PATH)
|
|
|
|
&& PathIsNetworkPathW (wpath))
|
|
|
|
is_remote = true;
|
|
|
|
# define IsRemote( fd ) ((void)fd, is_remote)
|
|
|
|
#endif
|
2009-02-21 10:55:14 +01:00
|
|
|
}
|
2009-02-05 16:52:52 +01:00
|
|
|
if (fd == -1)
|
|
|
|
goto error;
|
2002-12-31 02:54:36 +01:00
|
|
|
|
2006-11-01 21:50:18 +01:00
|
|
|
#ifdef HAVE_SYS_STAT_H
|
2006-11-12 13:02:55 +01:00
|
|
|
struct stat st;
|
2004-03-10 18:10:40 +01:00
|
|
|
|
2009-02-05 16:52:52 +01:00
|
|
|
if (fstat (fd, &st))
|
2004-03-10 18:10:40 +01:00
|
|
|
{
|
2009-02-05 16:52:52 +01:00
|
|
|
msg_Err (p_access, "failed to read (%m)");
|
|
|
|
goto error;
|
2006-11-01 21:50:18 +01:00
|
|
|
}
|
2009-02-05 16:52:52 +01:00
|
|
|
/* Directories can be opened and read from, but only readdir() knows
|
|
|
|
* how to parse the data. The directory plugin will do it. */
|
|
|
|
if (S_ISDIR (st.st_mode))
|
2006-11-01 21:50:18 +01:00
|
|
|
{
|
2009-02-05 16:52:52 +01:00
|
|
|
msg_Dbg (p_access, "ignoring directory");
|
|
|
|
goto error;
|
2006-11-01 21:50:18 +01:00
|
|
|
}
|
2009-02-05 17:34:43 +01:00
|
|
|
if (S_ISREG (st.st_mode))
|
|
|
|
p_access->info.i_size = st.st_size;
|
|
|
|
else if (!S_ISBLK (st.st_mode))
|
2009-04-08 17:49:08 +02:00
|
|
|
{
|
2009-02-05 21:27:10 +01:00
|
|
|
p_access->pf_seek = NoSeek;
|
2009-04-08 17:49:08 +02:00
|
|
|
p_sys->b_pace_control = strcasecmp (p_access->psz_access, "stream");
|
|
|
|
}
|
2006-10-31 18:41:04 +01:00
|
|
|
#else
|
2006-11-10 21:50:34 +01:00
|
|
|
# warning File size not known!
|
2006-10-31 18:41:04 +01:00
|
|
|
#endif
|
|
|
|
|
2009-07-20 18:37:17 +02:00
|
|
|
p_sys->caching = var_CreateGetInteger (p_access, "file-caching");
|
2009-06-25 19:30:57 +02:00
|
|
|
if (IsRemote(fd))
|
2009-07-20 18:37:17 +02:00
|
|
|
p_sys->caching += var_CreateGetInteger (p_access, "network-caching");
|
2009-06-25 18:40:37 +02:00
|
|
|
|
2009-02-05 16:52:52 +01:00
|
|
|
p_sys->fd = fd;
|
2009-07-23 22:20:12 +02:00
|
|
|
|
|
|
|
if (p_access->pf_seek != NoSeek)
|
|
|
|
{
|
|
|
|
/* Demuxers will need the beginning of the file for probing. */
|
|
|
|
posix_fadvise (fd, 0, 4096, POSIX_FADV_WILLNEED);
|
|
|
|
/* In most cases, we only read the file once. */
|
|
|
|
posix_fadvise (fd, 0, 0, POSIX_FADV_NOREUSE);
|
|
|
|
}
|
2002-11-12 14:57:13 +01:00
|
|
|
return VLC_SUCCESS;
|
2009-02-05 16:52:52 +01:00
|
|
|
|
|
|
|
error:
|
|
|
|
if (fd != -1)
|
|
|
|
close (fd);
|
|
|
|
free (p_sys);
|
|
|
|
return VLC_EGENERIC;
|
2002-08-04 19:23:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2002-11-12 14:57:13 +01:00
|
|
|
* Close: close the target
|
2002-08-04 19:23:44 +02:00
|
|
|
*****************************************************************************/
|
2006-10-31 18:41:04 +01:00
|
|
|
static void Close (vlc_object_t * p_this)
|
2002-11-12 14:57:13 +01:00
|
|
|
{
|
2004-06-03 02:08:54 +02:00
|
|
|
access_t *p_access = (access_t*)p_this;
|
|
|
|
access_sys_t *p_sys = p_access->p_sys;
|
2002-11-12 14:57:13 +01:00
|
|
|
|
2006-11-01 21:50:18 +01:00
|
|
|
close (p_sys->fd);
|
2006-10-31 18:41:04 +01:00
|
|
|
free (p_sys);
|
2002-11-12 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
2008-09-30 17:39:26 +02:00
|
|
|
|
|
|
|
#include <vlc_network.h>
|
|
|
|
|
2002-11-12 14:57:13 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* Read: standard read on a file descriptor.
|
|
|
|
*****************************************************************************/
|
2007-12-09 18:39:28 +01:00
|
|
|
static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
|
2002-11-12 14:57:13 +01:00
|
|
|
{
|
2004-06-03 02:08:54 +02:00
|
|
|
access_sys_t *p_sys = p_access->p_sys;
|
2006-11-01 21:50:18 +01:00
|
|
|
int fd = p_sys->fd;
|
2008-09-30 17:39:26 +02:00
|
|
|
ssize_t i_ret;
|
2004-06-03 02:08:54 +02:00
|
|
|
|
2008-09-30 17:39:26 +02:00
|
|
|
#ifndef WIN32
|
2009-02-05 21:27:10 +01:00
|
|
|
if (p_access->pf_seek == NoSeek)
|
2009-02-05 17:18:19 +01:00
|
|
|
i_ret = net_Read (p_access, fd, NULL, p_buffer, i_len, false);
|
|
|
|
else
|
2008-09-30 17:39:26 +02:00
|
|
|
#endif
|
2009-02-05 17:18:19 +01:00
|
|
|
i_ret = read (fd, p_buffer, i_len);
|
2008-10-06 12:40:19 +02:00
|
|
|
|
2002-11-12 14:57:13 +01:00
|
|
|
if( i_ret < 0 )
|
|
|
|
{
|
2006-10-31 18:41:04 +01:00
|
|
|
switch (errno)
|
2006-08-23 01:22:14 +02:00
|
|
|
{
|
2006-10-31 18:41:04 +01:00
|
|
|
case EINTR:
|
|
|
|
case EAGAIN:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-02-05 16:52:52 +01:00
|
|
|
msg_Err (p_access, "failed to read (%m)");
|
2009-03-24 22:43:39 +01:00
|
|
|
dialog_Fatal (p_access, _("File reading failed"), "%s",
|
2009-03-05 20:09:21 +01:00
|
|
|
_("VLC could not read the file."));
|
2009-01-18 19:16:03 +01:00
|
|
|
p_access->info.b_eof = true;
|
2008-09-28 17:45:59 +02:00
|
|
|
return 0;
|
2006-08-23 01:22:14 +02:00
|
|
|
}
|
2002-11-12 14:57:13 +01:00
|
|
|
}
|
2008-06-20 23:27:44 +02:00
|
|
|
else if( i_ret > 0 )
|
|
|
|
p_access->info.i_pos += i_ret;
|
2009-01-14 11:13:47 +01:00
|
|
|
else
|
2008-06-20 23:27:44 +02:00
|
|
|
p_access->info.b_eof = true;
|
2004-06-03 02:08:54 +02:00
|
|
|
|
|
|
|
p_sys->i_nb_reads++;
|
2006-10-31 18:41:04 +01:00
|
|
|
|
2009-04-08 17:49:51 +02:00
|
|
|
if ((p_access->info.i_size && !(p_sys->i_nb_reads % INPUT_FSTAT_NB_READS))
|
|
|
|
|| (p_access->info.i_pos > p_access->info.i_size))
|
2003-01-03 14:07:17 +01:00
|
|
|
{
|
2009-07-23 22:20:12 +02:00
|
|
|
#ifdef HAVE_SYS_STAT_H
|
2006-11-12 13:02:55 +01:00
|
|
|
struct stat st;
|
2004-03-10 18:10:40 +01:00
|
|
|
|
2006-10-31 18:41:04 +01:00
|
|
|
if ((fstat (fd, &st) == 0)
|
2006-11-01 21:50:18 +01:00
|
|
|
&& (p_access->info.i_size != st.st_size))
|
2003-01-03 14:07:17 +01:00
|
|
|
{
|
2006-11-01 21:50:18 +01:00
|
|
|
p_access->info.i_size = st.st_size;
|
2004-06-03 02:08:54 +02:00
|
|
|
p_access->info.i_update |= INPUT_UPDATE_SIZE;
|
2003-01-03 14:07:17 +01:00
|
|
|
}
|
|
|
|
#endif
|
2009-07-23 22:20:12 +02:00
|
|
|
}
|
2002-11-12 14:57:13 +01:00
|
|
|
return i_ret;
|
|
|
|
}
|
|
|
|
|
2007-11-26 21:27:15 +01:00
|
|
|
|
2002-11-12 14:57:13 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* Seek: seek to a specific location in a file
|
|
|
|
*****************************************************************************/
|
2006-10-31 18:41:04 +01:00
|
|
|
static int Seek (access_t *p_access, int64_t i_pos)
|
2002-11-12 14:57:13 +01:00
|
|
|
{
|
2006-10-31 18:41:04 +01:00
|
|
|
p_access->info.i_pos = i_pos;
|
2008-04-14 00:08:29 +02:00
|
|
|
p_access->info.b_eof = false;
|
2006-10-31 18:41:04 +01:00
|
|
|
|
2008-02-20 22:24:37 +01:00
|
|
|
lseek (p_access->p_sys->fd, i_pos, SEEK_SET);
|
2004-06-03 02:08:54 +02:00
|
|
|
return VLC_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-02-05 21:27:10 +01:00
|
|
|
static int NoSeek (access_t *p_access, int64_t i_pos)
|
|
|
|
{
|
|
|
|
/* assert(0); ?? */
|
|
|
|
(void) p_access; (void) i_pos;
|
|
|
|
return VLC_EGENERIC;
|
|
|
|
}
|
|
|
|
|
2004-06-03 02:08:54 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* Control:
|
|
|
|
*****************************************************************************/
|
|
|
|
static int Control( access_t *p_access, int i_query, va_list args )
|
|
|
|
{
|
|
|
|
access_sys_t *p_sys = p_access->p_sys;
|
2009-01-20 22:28:47 +01:00
|
|
|
bool *pb_bool;
|
|
|
|
int64_t *pi_64;
|
2004-06-03 02:08:54 +02:00
|
|
|
|
|
|
|
switch( i_query )
|
2002-11-12 14:57:13 +01:00
|
|
|
{
|
2004-06-03 02:08:54 +02:00
|
|
|
/* */
|
|
|
|
case ACCESS_CAN_SEEK:
|
|
|
|
case ACCESS_CAN_FASTSEEK:
|
2008-04-14 00:08:29 +02:00
|
|
|
pb_bool = (bool*)va_arg( args, bool* );
|
2009-02-05 21:27:10 +01:00
|
|
|
*pb_bool = (p_access->pf_seek != NoSeek);
|
2004-06-03 02:08:54 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACCESS_CAN_PAUSE:
|
|
|
|
case ACCESS_CAN_CONTROL_PACE:
|
2008-04-14 00:08:29 +02:00
|
|
|
pb_bool = (bool*)va_arg( args, bool* );
|
2004-06-03 02:08:54 +02:00
|
|
|
*pb_bool = p_sys->b_pace_control;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* */
|
|
|
|
case ACCESS_GET_PTS_DELAY:
|
|
|
|
pi_64 = (int64_t*)va_arg( args, int64_t * );
|
2009-07-20 18:37:17 +02:00
|
|
|
*pi_64 = p_sys->caching * INT64_C(1000);
|
2004-06-03 02:08:54 +02:00
|
|
|
break;
|
2004-10-05 17:31:22 +02:00
|
|
|
|
2004-06-03 02:08:54 +02:00
|
|
|
/* */
|
|
|
|
case ACCESS_SET_PAUSE_STATE:
|
|
|
|
/* Nothing to do */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACCESS_GET_TITLE_INFO:
|
|
|
|
case ACCESS_SET_TITLE:
|
|
|
|
case ACCESS_SET_SEEKPOINT:
|
2004-06-05 21:36:51 +02:00
|
|
|
case ACCESS_SET_PRIVATE_ID_STATE:
|
2005-03-11 23:36:40 +01:00
|
|
|
case ACCESS_GET_META:
|
2008-01-25 16:15:56 +01:00
|
|
|
case ACCESS_GET_PRIVATE_ID_STATE:
|
2007-10-02 17:54:16 +02:00
|
|
|
case ACCESS_GET_CONTENT_TYPE:
|
2004-06-03 02:08:54 +02:00
|
|
|
return VLC_EGENERIC;
|
|
|
|
|
|
|
|
default:
|
2008-01-25 16:15:56 +01:00
|
|
|
msg_Warn( p_access, "unimplemented query %d in control", i_query );
|
2004-06-03 02:08:54 +02:00
|
|
|
return VLC_EGENERIC;
|
|
|
|
|
2002-11-12 14:57:13 +01:00
|
|
|
}
|
2004-06-03 02:08:54 +02:00
|
|
|
return VLC_SUCCESS;
|
2002-11-12 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
2004-03-10 18:10:40 +01:00
|
|
|
/*****************************************************************************
|
2006-10-31 18:51:59 +01:00
|
|
|
* open_file: Opens a specific file
|
2004-03-10 18:10:40 +01:00
|
|
|
*****************************************************************************/
|
2008-03-19 17:46:53 +01:00
|
|
|
static int open_file (access_t *p_access, const char *path)
|
2004-03-10 18:10:40 +01:00
|
|
|
{
|
2008-03-19 17:46:53 +01:00
|
|
|
#if defined(WIN32)
|
|
|
|
if (!strcasecmp (p_access->psz_access, "file")
|
|
|
|
&& ('/' == path[0]) && isalpha (path[1])
|
|
|
|
&& (':' == path[2]) && ('/' == path[3]))
|
|
|
|
/* Explorer can open path such as file:/C:/ or file:///C:/
|
|
|
|
* hence remove leading / if found */
|
|
|
|
path++;
|
|
|
|
#endif
|
2004-03-10 18:10:40 +01:00
|
|
|
|
2009-08-15 20:25:21 +02:00
|
|
|
int fd = utf8_open (path, O_RDONLY | O_NONBLOCK);
|
2006-10-31 18:41:04 +01:00
|
|
|
if (fd == -1)
|
2004-03-10 18:10:40 +01:00
|
|
|
{
|
2008-03-19 17:46:53 +01:00
|
|
|
msg_Err (p_access, "cannot open file %s (%m)", path);
|
2009-03-05 20:09:21 +01:00
|
|
|
dialog_Fatal (p_access, _("File reading failed"),
|
|
|
|
_("VLC could not open the file \"%s\"."), path);
|
2006-10-31 18:41:04 +01:00
|
|
|
return -1;
|
2004-03-10 18:10:40 +01:00
|
|
|
}
|
2006-01-07 23:01:17 +01:00
|
|
|
|
2008-10-14 12:06:05 +02:00
|
|
|
#if defined(HAVE_FCNTL)
|
2006-01-07 23:01:17 +01:00
|
|
|
/* We'd rather use any available memory for reading ahead
|
|
|
|
* than for caching what we've already seen/heard */
|
2008-10-10 13:53:08 +02:00
|
|
|
# if defined(F_RDAHEAD)
|
2006-10-31 18:41:04 +01:00
|
|
|
fcntl (fd, F_RDAHEAD, 1);
|
2008-10-10 13:53:08 +02:00
|
|
|
# endif
|
|
|
|
# if defined(F_NOCACHE)
|
2006-10-31 18:41:04 +01:00
|
|
|
fcntl (fd, F_NOCACHE, 1);
|
|
|
|
# endif
|
2008-10-10 13:53:08 +02:00
|
|
|
#endif
|
2004-03-10 18:10:40 +01:00
|
|
|
|
2006-10-31 18:41:04 +01:00
|
|
|
return fd;
|
2004-03-10 18:10:40 +01:00
|
|
|
}
|