2002-08-04 19:23:44 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* file.c: file input (file: access plug-in)
|
|
|
|
*****************************************************************************
|
LGPL
Re-license almost all the playback modules to LGPLv2.1+ with
authorization from their respective contributors (230+)
This includes:
- access, codec, packetizers, demux
- audio filters, audio mixers, audio output
- video filters, video chroma, video output
- text renderers
- XML parser
- ARM NEON and SSE2 optimisations (mostly for chromas and filters)
Some modules are not concerned:
- BDA and DShow access modules because Manol Manolov is AWOL
- Real RTSP, because it is derived from Xine
- x264 and t140 because they are encoders only
- DLL Loader, because it is derived from MPlayer
- DTS packetizer, because Jon Lech Johansen is AWOL
- Shine and WMAfixed, because they are derived from Rockbox
- Real demuxer, as it is derived from MPlayer and Wang Bo is AWOL
- MPC demuxer, as Yavor Doganov is AWOL
- Tivo demuxer, because it is derived from an MPlayer fork
- Playlist demuxer, (WPL and ZPL parts missing), because suheaven is AWOL
- iOS audio output and video display, because author refuses the license change
- Equalizer and compressor, because Ronald Wright is AWOL
- Mono, Headphone and Dolby, because author refuses the license change
- hqdn3d and yadif, because they are from MPlayer/libavfilter
- remoteosd, because it derives from RealVNC code
- MMX optimisations, because Ollie Lho, from SiS, is AWOL
- Rotate, because it depends on GPL motion
Nota Bene:
- Some modules depend on GPL-only libraries, a LGPL module does not mean
that the resulting binary module will be LGPL.
Libraries affected would include liba52, libdvdcss, libdvdnav, libdvdread,
faad2, libdca, libmad, libmpeg2, libpostproc, SRC, sid, zvbi and probably others.
2012-11-06 17:48:33 +01:00
|
|
|
* Copyright (C) 2001-2006 VLC authors and VideoLAN
|
2007-11-26 21:27:15 +01:00
|
|
|
* Copyright © 2006-2007 Rémi Denis-Courmont
|
2002-08-04 19:23:44 +02:00
|
|
|
*
|
|
|
|
* Authors: Christophe Massiot <massiot@via.ecp.fr>
|
2019-09-04 21:10:51 +02:00
|
|
|
* Rémi Denis-Courmont
|
2002-08-04 19:23:44 +02:00
|
|
|
*
|
LGPL
Re-license almost all the playback modules to LGPLv2.1+ with
authorization from their respective contributors (230+)
This includes:
- access, codec, packetizers, demux
- audio filters, audio mixers, audio output
- video filters, video chroma, video output
- text renderers
- XML parser
- ARM NEON and SSE2 optimisations (mostly for chromas and filters)
Some modules are not concerned:
- BDA and DShow access modules because Manol Manolov is AWOL
- Real RTSP, because it is derived from Xine
- x264 and t140 because they are encoders only
- DLL Loader, because it is derived from MPlayer
- DTS packetizer, because Jon Lech Johansen is AWOL
- Shine and WMAfixed, because they are derived from Rockbox
- Real demuxer, as it is derived from MPlayer and Wang Bo is AWOL
- MPC demuxer, as Yavor Doganov is AWOL
- Tivo demuxer, because it is derived from an MPlayer fork
- Playlist demuxer, (WPL and ZPL parts missing), because suheaven is AWOL
- iOS audio output and video display, because author refuses the license change
- Equalizer and compressor, because Ronald Wright is AWOL
- Mono, Headphone and Dolby, because author refuses the license change
- hqdn3d and yadif, because they are from MPlayer/libavfilter
- remoteosd, because it derives from RealVNC code
- MMX optimisations, because Ollie Lho, from SiS, is AWOL
- Rotate, because it depends on GPL motion
Nota Bene:
- Some modules depend on GPL-only libraries, a LGPL module does not mean
that the resulting binary module will be LGPL.
Libraries affected would include liba52, libdvdcss, libdvdnav, libdvdread,
faad2, libdca, libmad, libmpeg2, libpostproc, SRC, sid, zvbi and probably others.
2012-11-06 17:48:33 +01:00
|
|
|
* 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
|
2002-08-04 19:23:44 +02:00
|
|
|
* (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
|
LGPL
Re-license almost all the playback modules to LGPLv2.1+ with
authorization from their respective contributors (230+)
This includes:
- access, codec, packetizers, demux
- audio filters, audio mixers, audio output
- video filters, video chroma, video output
- text renderers
- XML parser
- ARM NEON and SSE2 optimisations (mostly for chromas and filters)
Some modules are not concerned:
- BDA and DShow access modules because Manol Manolov is AWOL
- Real RTSP, because it is derived from Xine
- x264 and t140 because they are encoders only
- DLL Loader, because it is derived from MPlayer
- DTS packetizer, because Jon Lech Johansen is AWOL
- Shine and WMAfixed, because they are derived from Rockbox
- Real demuxer, as it is derived from MPlayer and Wang Bo is AWOL
- MPC demuxer, as Yavor Doganov is AWOL
- Tivo demuxer, because it is derived from an MPlayer fork
- Playlist demuxer, (WPL and ZPL parts missing), because suheaven is AWOL
- iOS audio output and video display, because author refuses the license change
- Equalizer and compressor, because Ronald Wright is AWOL
- Mono, Headphone and Dolby, because author refuses the license change
- hqdn3d and yadif, because they are from MPlayer/libavfilter
- remoteosd, because it derives from RealVNC code
- MMX optimisations, because Ollie Lho, from SiS, is AWOL
- Rotate, because it depends on GPL motion
Nota Bene:
- Some modules depend on GPL-only libraries, a LGPL module does not mean
that the resulting binary module will be LGPL.
Libraries affected would include liba52, libdvdcss, libdvdnav, libdvdread,
faad2, libdca, libmad, libmpeg2, libpostproc, SRC, sid, zvbi and probably others.
2012-11-06 17:48:33 +01:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
2002-08-04 19:23:44 +02:00
|
|
|
*
|
LGPL
Re-license almost all the playback modules to LGPLv2.1+ with
authorization from their respective contributors (230+)
This includes:
- access, codec, packetizers, demux
- audio filters, audio mixers, audio output
- video filters, video chroma, video output
- text renderers
- XML parser
- ARM NEON and SSE2 optimisations (mostly for chromas and filters)
Some modules are not concerned:
- BDA and DShow access modules because Manol Manolov is AWOL
- Real RTSP, because it is derived from Xine
- x264 and t140 because they are encoders only
- DLL Loader, because it is derived from MPlayer
- DTS packetizer, because Jon Lech Johansen is AWOL
- Shine and WMAfixed, because they are derived from Rockbox
- Real demuxer, as it is derived from MPlayer and Wang Bo is AWOL
- MPC demuxer, as Yavor Doganov is AWOL
- Tivo demuxer, because it is derived from an MPlayer fork
- Playlist demuxer, (WPL and ZPL parts missing), because suheaven is AWOL
- iOS audio output and video display, because author refuses the license change
- Equalizer and compressor, because Ronald Wright is AWOL
- Mono, Headphone and Dolby, because author refuses the license change
- hqdn3d and yadif, because they are from MPlayer/libavfilter
- remoteosd, because it derives from RealVNC code
- MMX optimisations, because Ollie Lho, from SiS, is AWOL
- Rotate, because it depends on GPL motion
Nota Bene:
- Some modules depend on GPL-only libraries, a LGPL module does not mean
that the resulting binary module will be LGPL.
Libraries affected would include liba52, libdvdcss, libdvdnav, libdvdread,
faad2, libdca, libmad, libmpeg2, libpostproc, SRC, sid, zvbi and probably others.
2012-11-06 17:48:33 +01:00
|
|
|
* 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.
|
2002-08-04 19:23:44 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2008-01-23 22:50:58 +01:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2007-11-26 21:27:15 +01:00
|
|
|
#include <assert.h>
|
2004-10-04 16:09:33 +02:00
|
|
|
#include <errno.h>
|
2010-01-16 13:13:50 +01:00
|
|
|
#include <sys/types.h>
|
2012-01-27 22:06:50 +01:00
|
|
|
#include <sys/stat.h>
|
2012-01-27 22:03:23 +01:00
|
|
|
#include <fcntl.h>
|
2010-06-20 18:56:44 +02:00
|
|
|
#ifdef HAVE_FSTATVFS
|
|
|
|
# include <sys/statvfs.h>
|
|
|
|
# if defined (HAVE_SYS_MOUNT_H)
|
|
|
|
# include <sys/param.h>
|
|
|
|
# include <sys/mount.h>
|
|
|
|
# endif
|
|
|
|
#endif
|
2009-08-31 16:01:47 +02:00
|
|
|
#ifdef HAVE_LINUX_MAGIC_H
|
2010-06-20 18:56:44 +02:00
|
|
|
# include <sys/vfs.h>
|
2009-06-25 19:30:57 +02:00
|
|
|
# include <linux/magic.h>
|
2009-08-31 16:01:47 +02:00
|
|
|
#endif
|
2002-11-20 14:37:36 +01:00
|
|
|
|
2013-06-05 15:41:18 +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>
|
|
|
|
#endif
|
2010-04-10 17:19:20 +02:00
|
|
|
#include <dirent.h>
|
2002-08-04 19:23:44 +02:00
|
|
|
|
2012-01-27 21:45:34 +01:00
|
|
|
#include <vlc_common.h>
|
|
|
|
#include "fs.h"
|
|
|
|
#include <vlc_access.h>
|
2013-06-05 15:41:18 +02:00
|
|
|
#ifdef _WIN32
|
2012-01-27 21:45:34 +01:00
|
|
|
# include <vlc_charset.h>
|
|
|
|
#endif
|
2010-02-07 14:18:02 +01:00
|
|
|
#include <vlc_fs.h>
|
2010-01-16 17:34:31 +01:00
|
|
|
#include <vlc_url.h>
|
2015-06-30 22:52:51 +02:00
|
|
|
#include <vlc_interrupt.h>
|
2005-08-03 21:01:44 +02:00
|
|
|
|
2018-04-27 22:10:57 +02:00
|
|
|
typedef struct
|
2003-01-03 14:07:17 +01:00
|
|
|
{
|
2006-11-01 21:50:18 +01:00
|
|
|
int fd;
|
2004-03-10 18:10:40 +01:00
|
|
|
|
2008-04-14 00:08:29 +02:00
|
|
|
bool b_pace_control;
|
2018-04-27 22:10:57 +02:00
|
|
|
} access_sys_t;
|
2003-01-03 14:07:17 +01:00
|
|
|
|
2013-06-05 15:41:18 +02:00
|
|
|
#if !defined (_WIN32) && !defined (__OS2__)
|
2009-06-25 19:30:57 +02:00
|
|
|
static bool IsRemote (int fd)
|
|
|
|
{
|
2010-06-20 18:56:44 +02:00
|
|
|
#if defined (HAVE_FSTATVFS) && defined (MNT_LOCAL)
|
|
|
|
struct statvfs stf;
|
|
|
|
|
|
|
|
if (fstatvfs (fd, &stf))
|
|
|
|
return false;
|
|
|
|
/* fstatvfs() is in POSIX, but MNT_LOCAL is not */
|
2010-06-22 08:19:52 +02:00
|
|
|
return !(stf.f_flag & MNT_LOCAL);
|
2010-06-20 18:56:44 +02:00
|
|
|
|
|
|
|
#elif defined (HAVE_LINUX_MAGIC_H)
|
2009-06-25 19:30:57 +02:00
|
|
|
struct statfs stf;
|
|
|
|
|
|
|
|
if (fstatfs (fd, &stf))
|
|
|
|
return false;
|
|
|
|
|
2010-07-17 20:50:22 +02:00
|
|
|
switch ((unsigned long)stf.f_type)
|
2009-06-25 19:30:57 +02:00
|
|
|
{
|
|
|
|
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;
|
2010-06-20 18:56:44 +02:00
|
|
|
|
|
|
|
#else
|
2009-07-23 17:05:08 +02:00
|
|
|
(void)fd;
|
2009-06-25 19:30:57 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
2011-09-05 02:28:06 +02:00
|
|
|
# define IsRemote(fd,path) IsRemote(fd)
|
|
|
|
|
2013-06-05 15:41:18 +02:00
|
|
|
#else /* _WIN32 || __OS2__ */
|
2011-09-05 02:28:06 +02:00
|
|
|
static bool IsRemote (const char *path)
|
|
|
|
{
|
2013-04-22 07:47:28 +02:00
|
|
|
# if !defined(__OS2__) && !VLC_WINSTORE_APP
|
2011-09-05 02:28:06 +02:00
|
|
|
wchar_t *wpath = ToWide (path);
|
|
|
|
bool is_remote = (wpath != NULL && PathIsNetworkPathW (wpath));
|
|
|
|
free (wpath);
|
|
|
|
return is_remote;
|
|
|
|
# else
|
|
|
|
return (! strncmp(path, "\\\\", 2));
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
# define IsRemote(fd,path) IsRemote(path)
|
|
|
|
#endif
|
2009-06-25 19:30:57 +02:00
|
|
|
|
2009-07-23 22:20:12 +02:00
|
|
|
#ifndef HAVE_POSIX_FADVISE
|
2009-08-20 11:03:36 +02:00
|
|
|
# define posix_fadvise(fd, off, len, adv)
|
2009-07-23 22:20:12 +02:00
|
|
|
#endif
|
2009-06-25 19:30:57 +02:00
|
|
|
|
2017-07-23 07:43:16 +02:00
|
|
|
static ssize_t Read (stream_t *, void *, size_t);
|
|
|
|
static int FileSeek (stream_t *, uint64_t);
|
|
|
|
static int FileControl (stream_t *, int, va_list);
|
2012-12-17 18:26:09 +01:00
|
|
|
|
2002-08-04 19:23:44 +02:00
|
|
|
/*****************************************************************************
|
2011-08-31 06:19:58 +02:00
|
|
|
* FileOpen: open the file
|
2002-08-04 19:23:44 +02:00
|
|
|
*****************************************************************************/
|
2011-08-31 06:19:58 +02:00
|
|
|
int FileOpen( vlc_object_t *p_this )
|
2002-08-04 19:23:44 +02:00
|
|
|
{
|
2017-07-23 07:43:16 +02:00
|
|
|
stream_t *p_access = (stream_t*)p_this;
|
2004-06-03 02:08:54 +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
|
|
|
|
2016-07-18 19:04:33 +02:00
|
|
|
if (!strcasecmp (p_access->psz_name, "fd"))
|
2010-01-16 17:34:31 +01:00
|
|
|
{
|
|
|
|
char *end;
|
2010-06-26 18:06:49 +02:00
|
|
|
int oldfd = strtol (p_access->psz_location, &end, 10);
|
2010-01-16 17:34:31 +01:00
|
|
|
|
|
|
|
if (*end == '\0')
|
2010-02-07 14:54:39 +01:00
|
|
|
fd = vlc_dup (oldfd);
|
2010-06-26 18:06:49 +02:00
|
|
|
else if (*end == '/' && end > p_access->psz_location)
|
2010-01-16 17:34:31 +01:00
|
|
|
{
|
2015-11-29 14:13:27 +01:00
|
|
|
char *name = vlc_uri_decode_duplicate (end - 1);
|
2010-02-14 12:33:35 +01:00
|
|
|
if (name != NULL)
|
2010-01-16 17:34:31 +01:00
|
|
|
{
|
|
|
|
name[0] = '.';
|
2010-02-14 12:33:35 +01:00
|
|
|
fd = vlc_openat (oldfd, name, O_RDONLY | O_NONBLOCK);
|
2010-01-16 17:34:31 +01:00
|
|
|
free (name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-11-01 21:50:18 +01:00
|
|
|
else
|
2009-02-21 10:55:14 +01:00
|
|
|
{
|
2015-11-01 18:15:15 +01:00
|
|
|
if (unlikely(p_access->psz_filepath == NULL))
|
2012-05-12 18:38:27 +02:00
|
|
|
return VLC_EGENERIC;
|
2015-11-01 18:15:15 +01:00
|
|
|
fd = vlc_open (p_access->psz_filepath, O_RDONLY | O_NONBLOCK);
|
2009-02-21 10:55:14 +01:00
|
|
|
}
|
2015-11-01 18:15:15 +01:00
|
|
|
|
2009-02-05 16:52:52 +01:00
|
|
|
if (fd == -1)
|
2015-11-01 18:15:15 +01:00
|
|
|
{
|
|
|
|
msg_Err (p_access, "cannot open file %s (%s)",
|
|
|
|
p_access->psz_filepath ? p_access->psz_filepath
|
|
|
|
: p_access->psz_location,
|
|
|
|
vlc_strerror_c(errno));
|
2010-01-16 12:13:46 +01:00
|
|
|
return VLC_EGENERIC;
|
2015-11-01 18:15:15 +01:00
|
|
|
}
|
2002-12-31 02:54:36 +01:00
|
|
|
|
2006-11-12 13:02:55 +01:00
|
|
|
struct stat st;
|
2009-02-05 16:52:52 +01:00
|
|
|
if (fstat (fd, &st))
|
2004-03-10 18:10:40 +01:00
|
|
|
{
|
2013-12-28 16:57:55 +01:00
|
|
|
msg_Err (p_access, "read error: %s", vlc_strerror_c(errno));
|
2009-02-05 16:52:52 +01:00
|
|
|
goto error;
|
2006-11-01 21:50:18 +01:00
|
|
|
}
|
2012-06-20 07:16:16 +02:00
|
|
|
|
2012-08-24 17:06:12 +02:00
|
|
|
#if O_NONBLOCK
|
2015-06-30 22:52:51 +02:00
|
|
|
/* Force blocking mode back */
|
2015-08-22 11:08:34 +02:00
|
|
|
fcntl (fd, F_SETFL, fcntl (fd, F_GETFL) & ~O_NONBLOCK);
|
2012-06-25 16:25:15 +02:00
|
|
|
#endif
|
2012-06-20 07:16:16 +02: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
|
|
|
{
|
2010-01-16 12:25:23 +01:00
|
|
|
#ifdef HAVE_FDOPENDIR
|
2015-06-16 14:05:26 +02:00
|
|
|
DIR *p_dir = fdopendir(fd);
|
|
|
|
if (!p_dir) {
|
|
|
|
msg_Err (p_access, "fdopendir error: %s", vlc_strerror_c(errno));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
return DirInit (p_access, p_dir);
|
2010-01-16 12:25:23 +01:00
|
|
|
#else
|
2009-02-05 16:52:52 +01:00
|
|
|
msg_Dbg (p_access, "ignoring directory");
|
|
|
|
goto error;
|
2010-01-16 12:25:23 +01:00
|
|
|
#endif
|
2006-11-01 21:50:18 +01:00
|
|
|
}
|
2010-01-16 12:13:46 +01:00
|
|
|
|
2017-11-28 17:54:06 +01:00
|
|
|
access_sys_t *p_sys = vlc_obj_malloc(p_this, sizeof (*p_sys));
|
2010-01-16 12:13:46 +01:00
|
|
|
if (unlikely(p_sys == NULL))
|
|
|
|
goto error;
|
2015-08-31 22:01:45 +02:00
|
|
|
p_access->pf_read = Read;
|
2010-01-16 12:13:46 +01:00
|
|
|
p_access->pf_block = NULL;
|
|
|
|
p_access->pf_control = FileControl;
|
|
|
|
p_access->p_sys = p_sys;
|
|
|
|
p_sys->fd = fd;
|
|
|
|
|
2012-12-17 18:26:09 +01:00
|
|
|
if (S_ISREG (st.st_mode) || S_ISBLK (st.st_mode))
|
2009-04-08 17:49:08 +02:00
|
|
|
{
|
2012-12-17 18:26:09 +01:00
|
|
|
p_access->pf_seek = FileSeek;
|
|
|
|
p_sys->b_pace_control = true;
|
2009-07-23 22:20:12 +02:00
|
|
|
|
|
|
|
/* 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);
|
2013-04-16 17:33:43 +02:00
|
|
|
#ifdef F_NOCACHE
|
|
|
|
fcntl (fd, F_NOCACHE, 0);
|
2014-04-27 12:33:15 +02:00
|
|
|
#endif
|
|
|
|
#ifdef F_RDAHEAD
|
|
|
|
if (IsRemote(fd, p_access->psz_filepath))
|
|
|
|
fcntl (fd, F_RDAHEAD, 0);
|
|
|
|
else
|
|
|
|
fcntl (fd, F_RDAHEAD, 1);
|
2010-01-16 10:38:17 +01:00
|
|
|
#endif
|
2009-07-23 22:20:12 +02:00
|
|
|
}
|
2012-12-17 18:26:09 +01:00
|
|
|
else
|
|
|
|
{
|
2019-06-18 18:17:26 +02:00
|
|
|
p_access->pf_seek = NULL;
|
2016-07-18 19:04:33 +02:00
|
|
|
p_sys->b_pace_control = strcasecmp (p_access->psz_name, "stream");
|
2012-12-17 18:26:09 +01:00
|
|
|
}
|
|
|
|
|
2002-11-12 14:57:13 +01:00
|
|
|
return VLC_SUCCESS;
|
2009-02-05 16:52:52 +01:00
|
|
|
|
|
|
|
error:
|
2016-04-21 23:11:43 +02:00
|
|
|
vlc_close (fd);
|
2009-02-05 16:52:52 +01:00
|
|
|
return VLC_EGENERIC;
|
2002-08-04 19:23:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2011-08-31 06:19:58 +02:00
|
|
|
* FileClose: close the target
|
2002-08-04 19:23:44 +02:00
|
|
|
*****************************************************************************/
|
2011-08-31 06:19:58 +02:00
|
|
|
void FileClose (vlc_object_t * p_this)
|
2002-11-12 14:57:13 +01:00
|
|
|
{
|
2017-07-23 07:43:16 +02:00
|
|
|
stream_t *p_access = (stream_t*)p_this;
|
2010-01-16 12:25:23 +01:00
|
|
|
|
|
|
|
if (p_access->pf_read == NULL)
|
|
|
|
{
|
|
|
|
DirClose (p_this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-06-03 02:08:54 +02:00
|
|
|
access_sys_t *p_sys = p_access->p_sys;
|
2002-11-12 14:57:13 +01:00
|
|
|
|
2016-04-21 23:11:43 +02:00
|
|
|
vlc_close (p_sys->fd);
|
2002-11-12 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
2008-09-30 17:39:26 +02:00
|
|
|
|
2017-07-23 07:43:16 +02:00
|
|
|
static ssize_t Read (stream_t *p_access, void *p_buffer, size_t i_len)
|
2012-12-17 18:26:09 +01:00
|
|
|
{
|
|
|
|
access_sys_t *p_sys = p_access->p_sys;
|
|
|
|
int fd = p_sys->fd;
|
|
|
|
|
2015-06-30 22:52:51 +02:00
|
|
|
ssize_t val = vlc_read_i11e (fd, p_buffer, i_len);
|
2012-12-17 18:26:09 +01:00
|
|
|
if (val < 0)
|
|
|
|
{
|
|
|
|
switch (errno)
|
|
|
|
{
|
|
|
|
case EINTR:
|
|
|
|
case EAGAIN:
|
|
|
|
return -1;
|
|
|
|
}
|
2015-06-30 22:52:51 +02:00
|
|
|
|
2013-12-28 16:57:55 +01:00
|
|
|
msg_Err (p_access, "read error: %s", vlc_strerror_c(errno));
|
2012-12-17 18:26:09 +01:00
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2015-08-31 22:01:45 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* Seek: seek to a specific location in a file
|
|
|
|
*****************************************************************************/
|
2017-07-23 07:43:16 +02:00
|
|
|
static int FileSeek (stream_t *p_access, uint64_t i_pos)
|
2015-08-31 22:01:45 +02:00
|
|
|
{
|
2016-07-18 19:29:31 +02:00
|
|
|
access_sys_t *sys = p_access->p_sys;
|
|
|
|
|
|
|
|
if (lseek(sys->fd, i_pos, SEEK_SET) == (off_t)-1)
|
2015-08-31 22:01:45 +02:00
|
|
|
return VLC_EGENERIC;
|
|
|
|
return VLC_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2004-06-03 02:08:54 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* Control:
|
|
|
|
*****************************************************************************/
|
2017-07-23 07:43:16 +02:00
|
|
|
static int FileControl( stream_t *p_access, int i_query, va_list args )
|
2004-06-03 02:08:54 +02:00
|
|
|
{
|
|
|
|
access_sys_t *p_sys = p_access->p_sys;
|
2009-01-20 22:28:47 +01:00
|
|
|
bool *pb_bool;
|
2018-07-06 10:28:54 +02:00
|
|
|
vlc_tick_t *pi_64;
|
2004-06-03 02:08:54 +02:00
|
|
|
|
|
|
|
switch( i_query )
|
2002-11-12 14:57:13 +01:00
|
|
|
{
|
2016-07-18 18:00:59 +02:00
|
|
|
case STREAM_CAN_SEEK:
|
|
|
|
case STREAM_CAN_FASTSEEK:
|
2017-04-19 19:23:50 +02:00
|
|
|
pb_bool = va_arg( args, bool * );
|
2019-06-18 18:17:26 +02:00
|
|
|
*pb_bool = (p_access->pf_seek != NULL);
|
2004-06-03 02:08:54 +02:00
|
|
|
break;
|
|
|
|
|
2016-07-18 18:00:59 +02:00
|
|
|
case STREAM_CAN_PAUSE:
|
|
|
|
case STREAM_CAN_CONTROL_PACE:
|
2017-04-19 19:23:50 +02:00
|
|
|
pb_bool = va_arg( args, bool * );
|
2004-06-03 02:08:54 +02:00
|
|
|
*pb_bool = p_sys->b_pace_control;
|
|
|
|
break;
|
|
|
|
|
2016-07-18 18:00:59 +02:00
|
|
|
case STREAM_GET_SIZE:
|
2013-08-25 11:44:17 +02:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
2015-08-31 22:03:03 +02:00
|
|
|
if (fstat (p_sys->fd, &st) || !S_ISREG(st.st_mode))
|
2015-07-24 15:00:48 +02:00
|
|
|
return VLC_EGENERIC;
|
2015-08-31 22:01:45 +02:00
|
|
|
*va_arg( args, uint64_t * ) = st.st_size;
|
2013-07-21 15:15:17 +02:00
|
|
|
break;
|
2013-08-25 11:44:17 +02:00
|
|
|
}
|
2013-07-21 15:15:17 +02:00
|
|
|
|
2016-07-18 18:00:59 +02:00
|
|
|
case STREAM_GET_PTS_DELAY:
|
2018-07-06 10:28:54 +02:00
|
|
|
pi_64 = va_arg( args, vlc_tick_t * );
|
2011-09-05 02:28:06 +02:00
|
|
|
if (IsRemote (p_sys->fd, p_access->psz_filepath))
|
2018-07-06 09:53:20 +02:00
|
|
|
*pi_64 = VLC_TICK_FROM_MS(
|
|
|
|
var_InheritInteger (p_access, "network-caching") );
|
2011-08-30 17:28:20 +02:00
|
|
|
else
|
2018-07-06 09:57:46 +02:00
|
|
|
*pi_64 = VLC_TICK_FROM_MS(
|
|
|
|
var_InheritInteger (p_access, "file-caching") );
|
2004-06-03 02:08:54 +02:00
|
|
|
break;
|
2004-10-05 17:31:22 +02:00
|
|
|
|
2016-07-18 18:00:59 +02:00
|
|
|
case STREAM_SET_PAUSE_STATE:
|
2004-06-03 02:08:54 +02:00
|
|
|
/* Nothing to do */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
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
|
|
|
}
|