2003-04-09 09:31:11 +02:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2007-03-12 16:48:13 +01:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2003-04-09 09:31:11 +02:00
|
|
|
#include "mp_msg.h"
|
|
|
|
#include "stream.h"
|
|
|
|
#include "help_mp.h"
|
2005-11-18 15:39:25 +01:00
|
|
|
#include "m_option.h"
|
|
|
|
#include "m_struct.h"
|
2003-04-09 09:31:11 +02:00
|
|
|
|
2003-05-17 14:24:01 +02:00
|
|
|
#include <fcntl.h>
|
2003-04-09 09:31:11 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2007-03-12 16:48:13 +01:00
|
|
|
#ifndef WIN32
|
2003-04-09 09:31:11 +02:00
|
|
|
#include <sys/ioctl.h>
|
2007-03-12 16:48:13 +01:00
|
|
|
#endif
|
2003-04-09 09:31:11 +02:00
|
|
|
#include <errno.h>
|
|
|
|
|
2007-07-27 19:37:53 +02:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__)
|
2003-04-09 09:31:11 +02:00
|
|
|
#include "vcd_read_fbsd.h"
|
2004-10-18 23:05:14 +02:00
|
|
|
#elif defined(SYS_DARWIN)
|
|
|
|
#include "vcd_read_darwin.h"
|
2007-03-12 16:48:13 +01:00
|
|
|
#elif defined(WIN32)
|
|
|
|
#include "vcd_read_win32.h"
|
2003-04-09 09:31:11 +02:00
|
|
|
#else
|
|
|
|
#include "vcd_read.h"
|
|
|
|
#endif
|
|
|
|
|
2007-01-16 23:38:26 +01:00
|
|
|
#include "libmpdemux/demuxer.h"
|
|
|
|
|
2003-08-13 13:18:24 +02:00
|
|
|
extern char *cdrom_device;
|
|
|
|
|
2003-04-09 09:31:11 +02:00
|
|
|
static struct stream_priv_s {
|
|
|
|
int track;
|
|
|
|
char* device;
|
|
|
|
} stream_priv_dflts = {
|
|
|
|
1,
|
2003-08-13 13:18:24 +02:00
|
|
|
NULL
|
2003-04-09 09:31:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
|
|
|
|
/// URL definition
|
|
|
|
static m_option_t stream_opts_fields[] = {
|
|
|
|
{ "track", ST_OFF(track), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL },
|
|
|
|
{ "device", ST_OFF(device), CONF_TYPE_STRING, 0, 0 ,0, NULL},
|
|
|
|
/// For url parsing
|
|
|
|
{ "hostname", ST_OFF(track), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL },
|
|
|
|
{ "filename", ST_OFF(device), CONF_TYPE_STRING, 0, 0 ,0, NULL},
|
|
|
|
{ NULL, NULL, 0, 0, 0, 0, NULL }
|
|
|
|
};
|
|
|
|
static struct m_struct_st stream_opts = {
|
|
|
|
"vcd",
|
|
|
|
sizeof(struct stream_priv_s),
|
|
|
|
&stream_priv_dflts,
|
|
|
|
stream_opts_fields
|
|
|
|
};
|
|
|
|
|
|
|
|
static int fill_buffer(stream_t *s, char* buffer, int max_len){
|
2005-07-03 17:20:14 +02:00
|
|
|
if(s->pos > s->end_pos) /// don't past end of current track
|
|
|
|
return 0;
|
2003-04-09 09:31:11 +02:00
|
|
|
return vcd_read(s->priv,buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int seek(stream_t *s,off_t newpos) {
|
|
|
|
s->pos = newpos;
|
|
|
|
vcd_set_msf(s->priv,s->pos/VCD_SECTOR_DATA);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void close_s(stream_t *stream) {
|
|
|
|
free(stream->priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int open_s(stream_t *stream,int mode, void* opts, int* file_format) {
|
|
|
|
struct stream_priv_s* p = (struct stream_priv_s*)opts;
|
2007-03-24 11:37:05 +01:00
|
|
|
int ret,ret2,f,sect,tmp;
|
2003-04-09 09:31:11 +02:00
|
|
|
mp_vcd_priv_t* vcd;
|
2007-01-10 15:56:23 +01:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
2003-04-09 09:31:11 +02:00
|
|
|
int bsize = VCD_SECTOR_SIZE;
|
|
|
|
#endif
|
2007-03-12 16:48:13 +01:00
|
|
|
#ifdef WIN32
|
|
|
|
HANDLE hd;
|
|
|
|
char device[] = "\\\\.\\?:";
|
|
|
|
#endif
|
2003-04-09 09:31:11 +02:00
|
|
|
|
2007-03-12 16:48:13 +01:00
|
|
|
if(mode != STREAM_READ
|
|
|
|
#ifdef WIN32
|
|
|
|
|| GetVersion() > 0x80000000 // Win9x
|
|
|
|
#endif
|
|
|
|
) {
|
2003-04-09 09:31:11 +02:00
|
|
|
m_struct_free(&stream_opts,opts);
|
2007-08-29 00:38:45 +02:00
|
|
|
return STREAM_UNSUPPORTED;
|
2003-04-09 09:31:11 +02:00
|
|
|
}
|
|
|
|
|
2003-08-13 13:18:24 +02:00
|
|
|
if (!p->device) {
|
|
|
|
if(cdrom_device)
|
|
|
|
p->device = strdup(cdrom_device);
|
|
|
|
else
|
|
|
|
p->device = strdup(DEFAULT_CDROM_DEVICE);
|
|
|
|
}
|
|
|
|
|
2007-03-12 16:48:13 +01:00
|
|
|
#ifdef WIN32
|
|
|
|
device[4] = p->device[0];
|
|
|
|
/* 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);
|
|
|
|
f = _open_osfhandle((long)hd, _O_RDONLY);
|
|
|
|
#else
|
2003-04-09 09:31:11 +02:00
|
|
|
f=open(p->device,O_RDONLY);
|
2007-03-12 16:48:13 +01:00
|
|
|
#endif
|
2003-04-09 09:31:11 +02:00
|
|
|
if(f<0){
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CdDevNotfound,p->device);
|
|
|
|
m_struct_free(&stream_opts,opts);
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
vcd = vcd_read_toc(f);
|
|
|
|
if(!vcd) {
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_ERR,"Failed to get cd toc\n");
|
|
|
|
close(f);
|
|
|
|
m_struct_free(&stream_opts,opts);
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
|
|
|
ret2=vcd_get_track_end(vcd,p->track);
|
|
|
|
if(ret2<0){
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (get)\n");
|
|
|
|
close(f);
|
|
|
|
free(vcd);
|
|
|
|
m_struct_free(&stream_opts,opts);
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
|
|
|
ret=vcd_seek_to_track(vcd,p->track);
|
|
|
|
if(ret<0){
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (seek)\n");
|
|
|
|
close(f);
|
|
|
|
free(vcd);
|
|
|
|
m_struct_free(&stream_opts,opts);
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
2007-03-24 11:37:05 +01: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 09:31:11 +02:00
|
|
|
mp_msg(MSGT_OPEN,MSGL_V,"VCD start byte position: 0x%X end: 0x%X\n",ret,ret2);
|
|
|
|
|
2007-01-10 15:56:23 +01:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
2003-04-09 09:31:11 +02:00
|
|
|
if (ioctl (f, CDRIOCSETBLOCKSIZE, &bsize) == -1) {
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_WARN,"Error in CDRIOCSETBLOCKSIZE");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
stream->fd = f;
|
|
|
|
stream->type = STREAMTYPE_VCD;
|
|
|
|
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;
|
2007-01-16 23:38:26 +01:00
|
|
|
*file_format = DEMUXER_TYPE_MPEG_PS;
|
2003-04-09 09:31:11 +02:00
|
|
|
|
|
|
|
m_struct_free(&stream_opts,opts);
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
stream_info_t stream_info_vcd = {
|
|
|
|
"Video CD",
|
|
|
|
"vcd",
|
|
|
|
"Albeu",
|
|
|
|
"based on the code from ???",
|
|
|
|
open_s,
|
|
|
|
{ "vcd", NULL },
|
|
|
|
&stream_opts,
|
|
|
|
1 // Urls are an option string
|
|
|
|
};
|