2010-01-30 22:26:47 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
2013-07-12 20:11:08 +00:00
|
|
|
* Original author: Albeu
|
|
|
|
*
|
2010-01-30 22:26:47 +00:00
|
|
|
* MPlayer 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.
|
|
|
|
*
|
|
|
|
* MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2003-04-09 07:31:11 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-10-13 16:23:55 +00:00
|
|
|
#if defined(__MINGW32__) || defined(__CYGWIN__)
|
2007-03-12 15:48:13 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2003-04-09 07:31:11 +00:00
|
|
|
#include "stream.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/m_option.h"
|
2003-04-09 07:31:11 +00:00
|
|
|
|
2003-05-17 12:24:01 +00:00
|
|
|
#include <fcntl.h>
|
2003-04-09 07:31:11 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2008-10-13 16:23:55 +00:00
|
|
|
#if !defined(__MINGW32__) && !defined(__CYGWIN__)
|
2003-04-09 07:31:11 +00:00
|
|
|
#include <sys/ioctl.h>
|
2007-03-12 15:48:13 +00:00
|
|
|
#endif
|
2003-04-09 07:31:11 +00:00
|
|
|
#include <errno.h>
|
|
|
|
|
2012-01-16 20:33:52 +00:00
|
|
|
#include "talloc.h"
|
|
|
|
|
2013-06-05 00:05:52 +00:00
|
|
|
#define VCD_SECTOR_SIZE 2352
|
|
|
|
#define VCD_SECTOR_OFFS 24
|
|
|
|
#define VCD_SECTOR_DATA 2324
|
|
|
|
|
2007-07-27 17:37:53 +00:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__)
|
2009-07-06 23:26:13 +00:00
|
|
|
#include "vcd_read_fbsd.h"
|
2007-12-11 23:52:55 +00:00
|
|
|
#elif defined(__APPLE__)
|
2009-07-06 23:26:13 +00:00
|
|
|
#include "vcd_read_darwin.h"
|
2008-10-13 16:23:55 +00:00
|
|
|
#elif defined(__MINGW32__) || defined(__CYGWIN__)
|
2007-03-12 15:48:13 +00:00
|
|
|
#include "vcd_read_win32.h"
|
2003-04-09 07:31:11 +00:00
|
|
|
#else
|
|
|
|
#include "vcd_read.h"
|
|
|
|
#endif
|
|
|
|
|
2013-07-21 19:54:58 +00:00
|
|
|
#ifndef vcd_close
|
|
|
|
#define vcd_close(priv) (close(((mp_vcd_priv_t*)priv)->fd))
|
|
|
|
#endif
|
|
|
|
|
2013-11-30 21:40:51 +00:00
|
|
|
#include "osdep/io.h"
|
|
|
|
|
2003-04-09 07:31:11 +00:00
|
|
|
static int fill_buffer(stream_t *s, char* buffer, int max_len){
|
2005-07-03 15:20:14 +00:00
|
|
|
if(s->pos > s->end_pos) /// don't past end of current track
|
|
|
|
return 0;
|
2013-06-05 00:04:21 +00:00
|
|
|
if (max_len < VCD_SECTOR_DATA)
|
|
|
|
return -1;
|
2003-04-09 07:31:11 +00:00
|
|
|
return vcd_read(s->priv,buffer);
|
|
|
|
}
|
|
|
|
|
2012-11-18 19:46:12 +00:00
|
|
|
static int seek(stream_t *s,int64_t newpos) {
|
2013-08-22 16:23:33 +00:00
|
|
|
vcd_set_msf(s->priv,newpos/VCD_SECTOR_DATA);
|
2003-04-09 07:31:11 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void close_s(stream_t *stream) {
|
2013-07-21 19:54:58 +00:00
|
|
|
vcd_close(stream->priv);
|
|
|
|
free(stream->priv);
|
2003-04-09 07:31:11 +00:00
|
|
|
}
|
|
|
|
|
2013-08-02 15:02:34 +00:00
|
|
|
static int open_s(stream_t *stream,int mode)
|
2013-07-11 19:10:42 +00:00
|
|
|
{
|
2007-03-24 10:37:05 +00:00
|
|
|
int ret,ret2,f,sect,tmp;
|
2003-04-09 07:31:11 +00:00
|
|
|
mp_vcd_priv_t* vcd;
|
2007-01-10 14:56:23 +00:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
2003-04-09 07:31:11 +00:00
|
|
|
int bsize = VCD_SECTOR_SIZE;
|
|
|
|
#endif
|
2008-10-13 16:23:55 +00:00
|
|
|
#if defined(__MINGW32__) || defined(__CYGWIN__)
|
2007-03-12 15:48:13 +00:00
|
|
|
HANDLE hd;
|
2013-08-02 15:02:34 +00:00
|
|
|
char device[20] = "\\\\.\\?:";
|
2007-03-12 15:48:13 +00:00
|
|
|
#endif
|
2003-04-09 07:31:11 +00:00
|
|
|
|
2007-03-12 15:48:13 +00:00
|
|
|
if(mode != STREAM_READ
|
2008-10-13 16:23:55 +00:00
|
|
|
#if defined(__MINGW32__) || defined(__CYGWIN__)
|
2007-03-12 15:48:13 +00:00
|
|
|
|| GetVersion() > 0x80000000 // Win9x
|
|
|
|
#endif
|
|
|
|
) {
|
2007-08-28 22:38:45 +00:00
|
|
|
return STREAM_UNSUPPORTED;
|
2003-04-09 07:31:11 +00:00
|
|
|
}
|
|
|
|
|
2013-08-02 15:02:34 +00:00
|
|
|
char *dev = stream->url;
|
|
|
|
if (strncmp("vcd://", dev, 6) != 0)
|
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
dev += 6;
|
|
|
|
if (!dev[0]) {
|
2003-08-13 11:18:24 +00:00
|
|
|
if(cdrom_device)
|
2013-08-02 15:02:34 +00:00
|
|
|
dev = cdrom_device;
|
2003-08-13 11:18:24 +00:00
|
|
|
else
|
2013-08-02 15:02:34 +00:00
|
|
|
dev = DEFAULT_CDROM_DEVICE;
|
2003-08-13 11:18:24 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 16:23:55 +00:00
|
|
|
#if defined(__MINGW32__) || defined(__CYGWIN__)
|
2013-08-02 15:02:34 +00:00
|
|
|
device[4] = dev ? dev[0] : 0;
|
2007-03-12 15:48:13 +00:00
|
|
|
/* open() can't be used for devices so do it the complicated way */
|
|
|
|
hd = CreateFile(device, GENERIC_READ, FILE_SHARE_READ, NULL,
|
|
|
|
OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
2013-07-13 01:58:49 +00:00
|
|
|
f = _open_osfhandle((intptr_t)hd, _O_RDONLY);
|
2007-03-12 15:48:13 +00:00
|
|
|
#else
|
2013-11-30 21:40:51 +00:00
|
|
|
f=open(dev,O_RDONLY | O_CLOEXEC);
|
2007-03-12 15:48:13 +00:00
|
|
|
#endif
|
2009-07-06 23:26:13 +00:00
|
|
|
if(f<0){
|
2013-12-16 19:40:02 +00:00
|
|
|
mp_msg(MSGT_OPEN,MSGL_ERR,"CD-ROM Device '%s' not found.\n",dev);
|
2003-04-09 07:31:11 +00:00
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
vcd = vcd_read_toc(f);
|
|
|
|
if(!vcd) {
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_ERR,"Failed to get cd toc\n");
|
|
|
|
close(f);
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
2013-08-02 15:02:34 +00:00
|
|
|
ret2=vcd_get_track_end(vcd,1);
|
2003-04-09 07:31:11 +00:00
|
|
|
if(ret2<0){
|
2013-12-16 19:40:02 +00:00
|
|
|
mp_msg(MSGT_OPEN, MSGL_ERR, "%s (get)\n", "Error selecting VCD track.");
|
2003-04-09 07:31:11 +00:00
|
|
|
close(f);
|
|
|
|
free(vcd);
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
2013-08-02 15:02:34 +00:00
|
|
|
ret=vcd_seek_to_track(vcd,1);
|
2003-04-09 07:31:11 +00:00
|
|
|
if(ret<0){
|
2013-12-16 19:40:02 +00:00
|
|
|
mp_msg(MSGT_OPEN, MSGL_ERR, "%s (seek)\n", "Error selecting VCD track.");
|
2003-04-09 07:31:11 +00:00
|
|
|
close(f);
|
|
|
|
free(vcd);
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
2007-03-24 10:37:05 +00:00
|
|
|
/* search forward up to at most 3 seconds to skip leading margin */
|
|
|
|
sect = ret / VCD_SECTOR_DATA;
|
|
|
|
for (tmp = sect; tmp < sect + 3 * 75; tmp++) {
|
|
|
|
char mem[VCD_SECTOR_DATA];
|
|
|
|
//since MPEG packs are block-aligned we stop discarding sectors if they are non-null
|
|
|
|
if (vcd_read(vcd, mem) != VCD_SECTOR_DATA || mem[2] || mem[3])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mp_msg(MSGT_OPEN, MSGL_DBG2, "%d leading sectors skipped\n", tmp - sect);
|
|
|
|
vcd_set_msf(vcd, tmp);
|
|
|
|
ret = tmp * VCD_SECTOR_DATA;
|
|
|
|
|
2003-04-09 07:31:11 +00:00
|
|
|
mp_msg(MSGT_OPEN,MSGL_V,"VCD start byte position: 0x%X end: 0x%X\n",ret,ret2);
|
|
|
|
|
2007-01-10 14:56:23 +00:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
2003-04-09 07:31:11 +00:00
|
|
|
if (ioctl (f, CDRIOCSETBLOCKSIZE, &bsize) == -1) {
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_WARN,"Error in CDRIOCSETBLOCKSIZE");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
stream->sector_size = VCD_SECTOR_DATA;
|
|
|
|
stream->start_pos=ret;
|
|
|
|
stream->end_pos=ret2;
|
|
|
|
stream->priv = vcd;
|
|
|
|
|
|
|
|
stream->fill_buffer = fill_buffer;
|
|
|
|
stream->seek = seek;
|
|
|
|
stream->close = close_s;
|
2013-07-11 19:10:42 +00:00
|
|
|
stream->demuxer = "lavf"; // mpegps ( or "vcd"?)
|
2003-04-09 07:31:11 +00:00
|
|
|
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
|
2007-12-02 13:22:53 +00:00
|
|
|
const stream_info_t stream_info_vcd = {
|
stream: fix url_options field, make protocols field not fixed length
The way the url_options field was handled was not entirely sane: it's
actually a flexible array member, so it points to garbage for streams
which do not initialize this member (it just points to the data right
after the struct, which is garbage in theory and practice). This was
not actually a problem, since the field is only used if priv_size is
set (due to how this stuff is used). But it doesn't allow setting
priv_size only, which might be useful in some cases.
Also, make the protocols array not a fixed size array. Most stream
implementations have only 1 protocol prefix, but stream_lavf.c has
over 10 (whitelists ffmpeg protocols). The high size of the fixed
size protocol array wastes space, and it is _still_ annoying to
add new prefixes to stream_lavf (have to bump the maximum length),
so make it arbitrary length.
The two changes (plus some more cosmetic changes) arte conflated into
one, because it was annoying going over all the stream implementations.
2013-08-25 20:49:27 +00:00
|
|
|
.name = "vcd",
|
|
|
|
.open = open_s,
|
|
|
|
.protocols = (const char*[]){ "vcd", NULL },
|
2003-04-09 07:31:11 +00:00
|
|
|
};
|