2007-07-30 15:53:50 +00:00
|
|
|
#include "libavutil/intreadwrite.h"
|
2001-02-24 20:28:24 +00:00
|
|
|
//=================== VideoCD ==========================
|
2001-10-05 00:39:54 +00:00
|
|
|
#if defined(linux) || defined(sun) || defined(__bsdi__)
|
2001-06-05 18:40:44 +00:00
|
|
|
|
2003-04-09 07:33:59 +00:00
|
|
|
typedef struct mp_vcd_priv_st mp_vcd_priv_t;
|
|
|
|
|
2001-06-05 18:40:44 +00:00
|
|
|
#if defined(linux)
|
|
|
|
#include <linux/cdrom.h>
|
|
|
|
#elif defined(sun)
|
|
|
|
#include <sys/cdio.h>
|
2003-04-09 07:33:59 +00:00
|
|
|
static int sun_vcd_read(mp_vcd_priv_t*, int*);
|
2001-10-05 00:39:54 +00:00
|
|
|
#elif defined(__bsdi__)
|
|
|
|
#include <dvd.h>
|
2001-06-05 18:40:44 +00:00
|
|
|
#endif
|
|
|
|
|
2003-04-09 07:33:59 +00:00
|
|
|
struct mp_vcd_priv_st {
|
|
|
|
int fd;
|
|
|
|
struct cdrom_tocentry entry;
|
|
|
|
char buf[VCD_SECTOR_SIZE];
|
|
|
|
};
|
2001-06-05 18:40:44 +00:00
|
|
|
|
2003-04-09 07:33:59 +00:00
|
|
|
static inline void vcd_set_msf(mp_vcd_priv_t* vcd, unsigned int sect){
|
2007-07-30 16:13:04 +00:00
|
|
|
sect += 150;
|
2003-04-09 07:33:59 +00:00
|
|
|
vcd->entry.cdte_addr.msf.frame=sect%75;
|
2001-02-24 20:28:24 +00:00
|
|
|
sect=sect/75;
|
2003-04-09 07:33:59 +00:00
|
|
|
vcd->entry.cdte_addr.msf.second=sect%60;
|
2001-02-24 20:28:24 +00:00
|
|
|
sect=sect/60;
|
2003-04-09 07:33:59 +00:00
|
|
|
vcd->entry.cdte_addr.msf.minute=sect;
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
2003-04-09 07:33:59 +00:00
|
|
|
static inline unsigned int vcd_get_msf(mp_vcd_priv_t* vcd){
|
|
|
|
return vcd->entry.cdte_addr.msf.frame +
|
|
|
|
(vcd->entry.cdte_addr.msf.second+
|
2007-07-30 16:13:04 +00:00
|
|
|
vcd->entry.cdte_addr.msf.minute*60)*75 - 150;
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
2003-04-09 07:33:59 +00:00
|
|
|
int vcd_seek_to_track(mp_vcd_priv_t* vcd,int track){
|
|
|
|
vcd->entry.cdte_format = CDROM_MSF;
|
|
|
|
vcd->entry.cdte_track = track;
|
|
|
|
if (ioctl(vcd->fd, CDROMREADTOCENTRY, &vcd->entry)) {
|
|
|
|
mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif1: %s\n",strerror(errno));
|
2001-04-23 03:42:17 +00:00
|
|
|
return -1;
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
2003-04-09 07:33:59 +00:00
|
|
|
return VCD_SECTOR_DATA*vcd_get_msf(vcd);
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
2003-04-09 07:33:59 +00:00
|
|
|
int vcd_get_track_end(mp_vcd_priv_t* vcd,int track){
|
2001-04-23 21:25:09 +00:00
|
|
|
struct cdrom_tochdr tochdr;
|
2003-04-09 07:33:59 +00:00
|
|
|
if (ioctl(vcd->fd,CDROMREADTOCHDR,&tochdr)==-1) {
|
|
|
|
mp_msg(MSGT_STREAM,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
vcd->entry.cdte_format = CDROM_MSF;
|
|
|
|
vcd->entry.cdte_track = track<tochdr.cdth_trk1?(track+1):CDROM_LEADOUT;
|
|
|
|
if (ioctl(vcd->fd, CDROMREADTOCENTRY, &vcd->entry)) {
|
|
|
|
mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif2: %s\n",strerror(errno));
|
2001-04-23 21:25:09 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2003-04-09 07:33:59 +00:00
|
|
|
return VCD_SECTOR_DATA*vcd_get_msf(vcd);
|
2001-04-23 21:25:09 +00:00
|
|
|
}
|
|
|
|
|
2003-04-09 07:33:59 +00:00
|
|
|
mp_vcd_priv_t* vcd_read_toc(int fd){
|
2001-02-24 20:28:24 +00:00
|
|
|
struct cdrom_tochdr tochdr;
|
2003-04-09 07:33:59 +00:00
|
|
|
mp_vcd_priv_t* vcd;
|
2005-09-22 08:46:05 +00:00
|
|
|
int i, min = 0, sec = 0, frame = 0;
|
2003-04-09 07:33:59 +00:00
|
|
|
if (ioctl(fd,CDROMREADTOCHDR,&tochdr)==-1) {
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno));
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-04-24 07:20:34 +00:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_START_TRACK=%d\n", tochdr.cdth_trk0);
|
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_END_TRACK=%d\n", tochdr.cdth_trk1);
|
2005-09-22 08:46:05 +00:00
|
|
|
for (i=tochdr.cdth_trk0 ; i<=tochdr.cdth_trk1 + 1; i++){
|
2001-02-24 20:28:24 +00:00
|
|
|
struct cdrom_tocentry tocentry;
|
|
|
|
|
2005-09-22 08:46:05 +00:00
|
|
|
tocentry.cdte_track = i<=tochdr.cdth_trk1 ? i : CDROM_LEADOUT;
|
2001-02-24 20:28:24 +00:00
|
|
|
tocentry.cdte_format = CDROM_MSF;
|
|
|
|
|
2003-04-09 07:33:59 +00:00
|
|
|
if (ioctl(fd,CDROMREADTOCENTRY,&tocentry)==-1) {
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc entry: %s\n",strerror(errno));
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2005-09-22 08:46:05 +00:00
|
|
|
if (i<=tochdr.cdth_trk1)
|
2001-09-26 21:35:14 +00:00
|
|
|
mp_msg(MSGT_OPEN,MSGL_INFO,"track %02d: adr=%d ctrl=%d format=%d %02d:%02d:%02d mode: %d\n",
|
2001-02-24 20:28:24 +00:00
|
|
|
(int)tocentry.cdte_track,
|
|
|
|
(int)tocentry.cdte_adr,
|
|
|
|
(int)tocentry.cdte_ctrl,
|
|
|
|
(int)tocentry.cdte_format,
|
|
|
|
(int)tocentry.cdte_addr.msf.minute,
|
|
|
|
(int)tocentry.cdte_addr.msf.second,
|
|
|
|
(int)tocentry.cdte_addr.msf.frame,
|
|
|
|
(int)tocentry.cdte_datamode
|
|
|
|
);
|
2005-09-22 08:46:05 +00:00
|
|
|
|
2006-04-24 07:20:34 +00:00
|
|
|
if (mp_msg_test(MSGT_IDENTIFY, MSGL_INFO))
|
2005-09-22 08:46:05 +00:00
|
|
|
{
|
|
|
|
if (i > tochdr.cdth_trk0)
|
|
|
|
{
|
|
|
|
min = tocentry.cdte_addr.msf.minute - min;
|
|
|
|
sec = tocentry.cdte_addr.msf.second - sec;
|
|
|
|
frame = tocentry.cdte_addr.msf.frame - frame;
|
|
|
|
if ( frame < 0 )
|
|
|
|
{
|
|
|
|
frame += 75;
|
|
|
|
sec --;
|
|
|
|
}
|
|
|
|
if ( sec < 0 )
|
|
|
|
{
|
|
|
|
sec += 60;
|
|
|
|
min --;
|
|
|
|
}
|
2006-04-24 07:20:34 +00:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_TRACK_%d_MSF=%02d:%02d:%02d\n", i - 1, min, sec, frame);
|
2005-09-22 08:46:05 +00:00
|
|
|
}
|
|
|
|
min = tocentry.cdte_addr.msf.minute;
|
|
|
|
sec = tocentry.cdte_addr.msf.second;
|
|
|
|
frame = tocentry.cdte_addr.msf.frame;
|
|
|
|
}
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
2003-04-09 07:33:59 +00:00
|
|
|
vcd = malloc(sizeof(mp_vcd_priv_t));
|
|
|
|
vcd->fd = fd;
|
|
|
|
return vcd;
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
2003-04-09 07:33:59 +00:00
|
|
|
static int vcd_read(mp_vcd_priv_t* vcd,char *mem){
|
2001-10-05 00:39:54 +00:00
|
|
|
#if defined(linux) || defined(__bsdi__)
|
2003-04-09 07:33:59 +00:00
|
|
|
memcpy(vcd->buf,&vcd->entry.cdte_addr.msf,sizeof(struct cdrom_msf));
|
|
|
|
if(ioctl(vcd->fd,CDROMREADRAW,vcd->buf)==-1) return 0; // EOF?
|
|
|
|
memcpy(mem,&vcd->buf[VCD_SECTOR_OFFS],VCD_SECTOR_DATA);
|
2001-06-05 18:40:44 +00:00
|
|
|
#elif defined(sun)
|
|
|
|
{
|
|
|
|
int offset;
|
2007-07-30 15:47:17 +00:00
|
|
|
if (sun_vcd_read(vcd, &offset) <= 0) return 0;
|
2003-04-09 07:33:59 +00:00
|
|
|
memcpy(mem,&vcd->buf[offset],VCD_SECTOR_DATA);
|
2001-06-05 18:40:44 +00:00
|
|
|
}
|
2001-06-05 02:26:56 +00:00
|
|
|
#endif
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2003-04-09 07:33:59 +00:00
|
|
|
vcd->entry.cdte_addr.msf.frame++;
|
|
|
|
if (vcd->entry.cdte_addr.msf.frame==75){
|
|
|
|
vcd->entry.cdte_addr.msf.frame=0;
|
|
|
|
vcd->entry.cdte_addr.msf.second++;
|
|
|
|
if (vcd->entry.cdte_addr.msf.second==60){
|
|
|
|
vcd->entry.cdte_addr.msf.second=0;
|
|
|
|
vcd->entry.cdte_addr.msf.minute++;
|
2001-06-05 18:40:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return VCD_SECTOR_DATA;
|
|
|
|
}
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-06-05 18:40:44 +00:00
|
|
|
|
|
|
|
#ifdef sun
|
|
|
|
#include <sys/scsi/generic/commands.h>
|
|
|
|
#include <sys/scsi/impl/uscsi.h>
|
|
|
|
|
|
|
|
#define SUN_XAREAD 1 /*fails on atapi drives*/
|
|
|
|
#define SUN_MODE2READ 2 /*fails on atapi drives*/
|
|
|
|
#define SUN_SCSIREAD 3
|
|
|
|
#define SUN_VCDREAD SUN_SCSIREAD
|
|
|
|
|
2003-04-09 07:33:59 +00:00
|
|
|
static int sun_vcd_read(mp_vcd_priv_t* vcd, int *offset)
|
2001-06-05 18:40:44 +00:00
|
|
|
{
|
|
|
|
#if SUN_VCDREAD == SUN_XAREAD
|
|
|
|
struct cdrom_cdxa cdxa;
|
2003-04-09 07:33:59 +00:00
|
|
|
cdxa.cdxa_addr = vcd_get_msf(vcd);
|
2001-06-05 18:40:44 +00:00
|
|
|
cdxa.cdxa_length = 1;
|
2003-04-09 07:33:59 +00:00
|
|
|
cdxa.cdxa_data = vcd->buf;
|
2001-06-05 18:40:44 +00:00
|
|
|
cdxa.cdxa_format = CDROM_XA_SECTOR_DATA;
|
|
|
|
|
2003-06-17 22:28:29 +00:00
|
|
|
if(ioctl(vcd->fd,CDROMCDXA,&cdxa)==-1) {
|
2003-04-09 07:33:59 +00:00
|
|
|
mp_msg(MSGT_STREAM,MSGL_ERR,"CDROMCDXA: %s\n",strerror(errno));
|
2001-06-05 18:40:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
*offset = 0;
|
|
|
|
#elif SUN_VCDREAD == SUN_MODE2READ
|
|
|
|
struct cdrom_read cdread;
|
2003-04-09 07:33:59 +00:00
|
|
|
cdread.cdread_lba = 4*vcd_get_msf(vcd);
|
|
|
|
cdread.cdread_bufaddr = vcd->buf;
|
2001-06-05 18:40:44 +00:00
|
|
|
cdread.cdread_buflen = 2336;
|
|
|
|
|
2003-06-17 22:28:29 +00:00
|
|
|
if(ioctl(vcd->fd,CDROMREADMODE2,&cdread)==-1) {
|
2003-04-09 07:33:59 +00:00
|
|
|
mp_msg(MSGT_STREAM,MSGL_ERR,"CDROMREADMODE2: %s\n",strerror(errno));
|
2001-06-05 18:40:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
*offset = 8;
|
|
|
|
#elif SUN_VCDREAD == SUN_SCSIREAD
|
|
|
|
struct uscsi_cmd sc;
|
|
|
|
union scsi_cdb cdb;
|
2003-04-09 07:33:59 +00:00
|
|
|
int lba = vcd_get_msf(vcd);
|
2001-06-05 18:40:44 +00:00
|
|
|
int blocks = 1;
|
|
|
|
|
|
|
|
memset(&cdb, 0, sizeof(cdb));
|
|
|
|
memset(&sc, 0, sizeof(sc));
|
|
|
|
cdb.scc_cmd = 0xBE;
|
2007-07-30 15:53:50 +00:00
|
|
|
cdb.cdb_opaque[1] = 5 << 2; // mode2 / form2
|
|
|
|
AV_WB32(&cdb.cdb_opaque[2], lba);
|
|
|
|
AV_WB24(&cdb.cdb_opaque[6], blocks);
|
|
|
|
cdb.cdb_opaque[9] = 1 << 4; // user data only
|
|
|
|
cdb.cdb_opaque[10] = 0; // subchannel
|
2001-06-05 18:40:44 +00:00
|
|
|
|
2001-06-08 23:36:58 +00:00
|
|
|
sc.uscsi_cdb = (caddr_t)&cdb;
|
2001-06-05 18:40:44 +00:00
|
|
|
sc.uscsi_cdblen = 12;
|
2003-04-09 07:33:59 +00:00
|
|
|
sc.uscsi_bufaddr = vcd->buf;
|
2001-06-05 18:40:44 +00:00
|
|
|
sc.uscsi_buflen = 2336;
|
|
|
|
sc.uscsi_flags = USCSI_ISOLATE | USCSI_READ;
|
|
|
|
sc.uscsi_timeout = 20;
|
2003-06-17 22:28:29 +00:00
|
|
|
if (ioctl(vcd->fd, USCSICMD, &sc)) {
|
2003-04-09 07:33:59 +00:00
|
|
|
mp_msg(MSGT_STREAM,MSGL_ERR,"USCSICMD: READ CD: %s\n",strerror(errno));
|
2001-06-05 18:40:44 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (sc.uscsi_status) {
|
2003-04-09 07:33:59 +00:00
|
|
|
mp_msg(MSGT_STREAM,MSGL_ERR,"scsi command failed with status %d\n", sc.uscsi_status);
|
2001-06-05 18:40:44 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
*offset = 0;
|
|
|
|
return 1;
|
|
|
|
#else
|
|
|
|
#error SUN_VCDREAD
|
|
|
|
#endif
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
2001-06-05 18:40:44 +00:00
|
|
|
#endif /*sun*/
|
|
|
|
|
2001-12-01 23:40:24 +00:00
|
|
|
#else /* linux || sun || __bsdi__ */
|
2001-06-05 18:40:44 +00:00
|
|
|
|
2001-12-01 23:40:24 +00:00
|
|
|
#error vcd is not yet supported on this arch...
|
2001-06-05 18:40:44 +00:00
|
|
|
|
2001-12-01 23:40:24 +00:00
|
|
|
#endif
|