2010-01-30 22:26:47 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#ifndef MPLAYER_VCD_READ_FBSD_H
|
|
|
|
#define MPLAYER_VCD_READ_FBSD_H
|
2008-02-21 00:12:02 +00:00
|
|
|
|
2010-01-04 18:58:35 +00:00
|
|
|
#define _XOPEN_SOURCE 500
|
|
|
|
|
2007-07-27 17:37:53 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <inttypes.h>
|
2010-01-04 18:58:35 +00:00
|
|
|
#include <unistd.h>
|
2001-06-05 18:40:44 +00:00
|
|
|
#include <sys/cdio.h>
|
2010-01-04 18:58:35 +00:00
|
|
|
#include <sys/ioctl.h>
|
2012-02-01 18:01:16 +00:00
|
|
|
|
|
|
|
#include <libavutil/intreadwrite.h>
|
|
|
|
|
2007-07-27 17:37:53 +00:00
|
|
|
#if defined(__NetBSD__) || defined(__OpenBSD__)
|
|
|
|
#define VCD_NETBSD 1
|
|
|
|
#endif
|
|
|
|
#ifdef VCD_NETBSD
|
|
|
|
#include <sys/scsiio.h>
|
|
|
|
#define TOCADDR(te) ((te).data->addr)
|
|
|
|
#define READ_TOC CDIOREADTOCENTRYS
|
|
|
|
#else
|
2001-06-05 18:40:44 +00:00
|
|
|
#include <sys/cdrio.h>
|
2007-07-27 17:37:53 +00:00
|
|
|
#define TOCADDR(te) ((te).entry.addr)
|
|
|
|
#define READ_TOC CDIOREADTOCENTRY
|
|
|
|
#endif
|
2008-03-10 19:28:42 +00:00
|
|
|
#include "mp_msg.h"
|
2001-06-05 18:40:44 +00:00
|
|
|
|
2001-06-03 00:31:41 +00:00
|
|
|
//=================== VideoCD ==========================
|
|
|
|
#define CDROM_LEADOUT 0xAA
|
|
|
|
|
2001-06-21 00:06:40 +00:00
|
|
|
typedef struct {
|
|
|
|
uint8_t sync [12];
|
|
|
|
uint8_t header [4];
|
|
|
|
uint8_t subheader [8];
|
|
|
|
uint8_t data [2324];
|
|
|
|
uint8_t spare [4];
|
|
|
|
} cdsector_t;
|
2001-06-03 00:31:41 +00:00
|
|
|
|
2007-07-27 18:04:52 +00:00
|
|
|
#ifdef VCD_NETBSD
|
2007-07-27 18:31:50 +00:00
|
|
|
typedef struct ioc_read_toc_entry vcd_tocentry;
|
2007-07-27 18:04:52 +00:00
|
|
|
#else
|
2007-07-27 18:31:50 +00:00
|
|
|
typedef struct ioc_read_toc_single_entry vcd_tocentry;
|
2007-07-27 18:04:52 +00:00
|
|
|
#endif
|
|
|
|
|
2003-04-09 07:33:59 +00:00
|
|
|
typedef struct mp_vcd_priv_st {
|
|
|
|
int fd;
|
2007-07-27 18:04:52 +00:00
|
|
|
vcd_tocentry entry;
|
2007-07-27 17:37:53 +00:00
|
|
|
#ifdef VCD_NETBSD
|
|
|
|
struct cd_toc_entry entry_data;
|
|
|
|
#else
|
2003-04-09 07:33:59 +00:00
|
|
|
cdsector_t buf;
|
2007-07-27 17:37:53 +00:00
|
|
|
#endif
|
2007-12-17 15:24:40 +00:00
|
|
|
struct ioc_toc_header tochdr;
|
2003-04-09 07:33:59 +00:00
|
|
|
} mp_vcd_priv_t;
|
2001-06-03 00:31:41 +00:00
|
|
|
|
2007-07-26 23:15:54 +00:00
|
|
|
static inline void
|
|
|
|
vcd_set_msf(mp_vcd_priv_t* vcd, unsigned int sect)
|
|
|
|
{
|
2007-07-27 17:37:53 +00:00
|
|
|
#ifdef VCD_NETBSD
|
|
|
|
vcd->entry.data = &vcd->entry_data;
|
|
|
|
#endif
|
2007-07-27 18:51:07 +00:00
|
|
|
sect += 150;
|
2007-07-26 23:15:54 +00:00
|
|
|
TOCADDR(vcd->entry).msf.frame = sect % 75;
|
|
|
|
sect = sect / 75;
|
|
|
|
TOCADDR(vcd->entry).msf.second = sect % 60;
|
|
|
|
sect = sect / 60;
|
|
|
|
TOCADDR(vcd->entry).msf.minute = sect;
|
2001-06-03 00:31:41 +00:00
|
|
|
}
|
|
|
|
|
2007-07-27 16:34:52 +00:00
|
|
|
static inline void
|
|
|
|
vcd_inc_msf(mp_vcd_priv_t* vcd)
|
|
|
|
{
|
2007-07-27 17:37:53 +00:00
|
|
|
#ifdef VCD_NETBSD
|
|
|
|
vcd->entry.data = &vcd->entry_data;
|
|
|
|
#endif
|
2007-07-27 16:34:52 +00:00
|
|
|
TOCADDR(vcd->entry).msf.frame++;
|
|
|
|
if (TOCADDR(vcd->entry).msf.frame==75){
|
|
|
|
TOCADDR(vcd->entry).msf.frame=0;
|
|
|
|
TOCADDR(vcd->entry).msf.second++;
|
|
|
|
if (TOCADDR(vcd->entry).msf.second==60){
|
|
|
|
TOCADDR(vcd->entry).msf.second=0;
|
|
|
|
TOCADDR(vcd->entry).msf.minute++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-26 23:15:54 +00:00
|
|
|
static inline unsigned int
|
|
|
|
vcd_get_msf(mp_vcd_priv_t* vcd)
|
|
|
|
{
|
2007-07-27 17:37:53 +00:00
|
|
|
#ifdef VCD_NETBSD
|
|
|
|
vcd->entry.data = &vcd->entry_data;
|
|
|
|
#endif
|
2007-07-26 22:51:23 +00:00
|
|
|
return TOCADDR(vcd->entry).msf.frame +
|
2007-07-26 23:15:54 +00:00
|
|
|
(TOCADDR(vcd->entry).msf.second +
|
2007-07-27 18:51:07 +00:00
|
|
|
TOCADDR(vcd->entry).msf.minute * 60) * 75 - 150;
|
2001-06-03 00:31:41 +00:00
|
|
|
}
|
|
|
|
|
2007-07-27 18:04:52 +00:00
|
|
|
/**
|
|
|
|
* \brief read a TOC entry
|
|
|
|
* \param fd device to read from
|
|
|
|
* \param dst buffer to read data into
|
|
|
|
* \param nr track number to read info for
|
|
|
|
* \return 1 on success, 0 on failure
|
|
|
|
*/
|
|
|
|
static int
|
2007-07-27 18:34:09 +00:00
|
|
|
read_toc_entry(mp_vcd_priv_t *vcd, int nr)
|
2007-07-27 18:04:52 +00:00
|
|
|
{
|
2007-07-27 18:34:09 +00:00
|
|
|
vcd->entry.address_format = CD_MSF_FORMAT;
|
2007-07-27 18:04:52 +00:00
|
|
|
#ifdef VCD_NETBSD
|
2007-07-27 18:34:09 +00:00
|
|
|
vcd->entry.data_len = sizeof(struct cd_toc_entry);
|
|
|
|
vcd->entry.data = &vcd->entry_data;
|
|
|
|
vcd->entry.starting_track = nr;
|
2007-07-27 18:04:52 +00:00
|
|
|
#else
|
2007-07-27 18:34:09 +00:00
|
|
|
vcd->entry.track = nr;
|
2007-07-27 18:04:52 +00:00
|
|
|
#endif
|
2007-07-27 18:34:09 +00:00
|
|
|
if (ioctl(vcd->fd, READ_TOC, &vcd->entry) == -1) {
|
2007-07-27 18:04:52 +00:00
|
|
|
mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc entry: %s\n",strerror(errno));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-05-07 21:32:50 +00:00
|
|
|
static int
|
2007-07-26 23:15:54 +00:00
|
|
|
vcd_seek_to_track(mp_vcd_priv_t* vcd, int track)
|
|
|
|
{
|
2007-07-27 18:34:09 +00:00
|
|
|
if (!read_toc_entry(vcd, track))
|
2001-06-03 00:31:41 +00:00
|
|
|
return -1;
|
2007-07-26 23:15:54 +00:00
|
|
|
return VCD_SECTOR_DATA * vcd_get_msf(vcd);
|
2001-06-03 00:31:41 +00:00
|
|
|
}
|
|
|
|
|
2010-02-22 16:32:03 +00:00
|
|
|
static int
|
2007-07-26 23:15:54 +00:00
|
|
|
vcd_get_track_end(mp_vcd_priv_t* vcd, int track)
|
|
|
|
{
|
2007-07-27 18:34:09 +00:00
|
|
|
if (!read_toc_entry(vcd,
|
2007-12-17 15:24:40 +00:00
|
|
|
track < vcd->tochdr.ending_track ? track + 1 : CDROM_LEADOUT))
|
2003-04-09 07:33:59 +00:00
|
|
|
return -1;
|
2007-07-26 23:15:54 +00:00
|
|
|
return VCD_SECTOR_DATA * vcd_get_msf(vcd);
|
2001-06-03 00:31:41 +00:00
|
|
|
}
|
|
|
|
|
2010-02-22 16:32:03 +00:00
|
|
|
static mp_vcd_priv_t*
|
2007-07-26 23:15:54 +00:00
|
|
|
vcd_read_toc(int fd)
|
|
|
|
{
|
2001-06-03 00:31:41 +00:00
|
|
|
struct ioc_toc_header tochdr;
|
2003-04-09 07:33:59 +00:00
|
|
|
mp_vcd_priv_t* vcd;
|
2007-07-27 18:47:44 +00:00
|
|
|
int i, last_startsect;
|
2007-07-26 23:15:54 +00:00
|
|
|
if (ioctl(fd, CDIOREADTOCHEADER, &tochdr) == -1) {
|
2003-04-09 07:33:59 +00:00
|
|
|
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.starting_track);
|
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_END_TRACK=%d\n", tochdr.ending_track);
|
2007-07-27 18:34:09 +00:00
|
|
|
vcd = malloc(sizeof(mp_vcd_priv_t));
|
|
|
|
vcd->fd = fd;
|
2007-12-17 15:24:40 +00:00
|
|
|
vcd->tochdr = tochdr;
|
2007-07-26 23:15:54 +00:00
|
|
|
for (i = tochdr.starting_track; i <= tochdr.ending_track + 1; i++) {
|
2007-07-27 18:34:09 +00:00
|
|
|
if (!read_toc_entry(vcd,
|
|
|
|
i <= tochdr.ending_track ? i : CDROM_LEADOUT)) {
|
|
|
|
free(vcd);
|
2007-07-26 23:15:54 +00:00
|
|
|
return NULL;
|
2007-07-27 18:34:09 +00:00
|
|
|
}
|
2007-07-27 08:49:14 +00:00
|
|
|
|
2007-07-26 23:15:54 +00:00
|
|
|
if (i <= tochdr.ending_track)
|
|
|
|
mp_msg(MSGT_OPEN,MSGL_INFO,"track %02d: adr=%d ctrl=%d format=%d %02d:%02d:%02d\n",
|
2007-07-27 17:37:53 +00:00
|
|
|
#ifdef VCD_NETBSD
|
2007-07-27 18:34:09 +00:00
|
|
|
(int)vcd->entry.starting_track,
|
|
|
|
(int)vcd->entry.data->addr_type,
|
|
|
|
(int)vcd->entry.data->control,
|
2007-07-27 17:37:53 +00:00
|
|
|
#else
|
2007-07-27 18:34:09 +00:00
|
|
|
(int)vcd->entry.track,
|
|
|
|
(int)vcd->entry.entry.addr_type,
|
|
|
|
(int)vcd->entry.entry.control,
|
2007-07-27 17:37:53 +00:00
|
|
|
#endif
|
2007-07-27 18:34:09 +00:00
|
|
|
(int)vcd->entry.address_format,
|
|
|
|
(int)TOCADDR(vcd->entry).msf.minute,
|
|
|
|
(int)TOCADDR(vcd->entry).msf.second,
|
|
|
|
(int)TOCADDR(vcd->entry).msf.frame
|
2001-06-03 00:31:41 +00:00
|
|
|
);
|
2005-09-22 08:46:05 +00:00
|
|
|
|
2007-07-26 23:15:54 +00:00
|
|
|
if (mp_msg_test(MSGT_IDENTIFY, MSGL_INFO))
|
|
|
|
{
|
2007-07-27 18:47:44 +00:00
|
|
|
int startsect = vcd_get_msf(vcd);
|
2007-07-26 23:15:54 +00:00
|
|
|
if (i > tochdr.starting_track)
|
2005-09-22 08:46:05 +00:00
|
|
|
{
|
2007-07-27 18:47:44 +00:00
|
|
|
// convert duraion to MSF
|
|
|
|
vcd_set_msf(vcd, startsect - last_startsect);
|
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO,
|
|
|
|
"ID_VCD_TRACK_%d_MSF=%02d:%02d:%02d\n",
|
|
|
|
i - 1,
|
|
|
|
TOCADDR(vcd->entry).msf.minute,
|
|
|
|
TOCADDR(vcd->entry).msf.second,
|
|
|
|
TOCADDR(vcd->entry).msf.frame);
|
2005-09-22 08:46:05 +00:00
|
|
|
}
|
2007-07-27 18:47:44 +00:00
|
|
|
last_startsect = startsect;
|
2001-06-03 00:31:41 +00:00
|
|
|
}
|
2007-07-26 23:15:54 +00:00
|
|
|
}
|
|
|
|
return vcd;
|
2001-06-03 00:31:41 +00:00
|
|
|
}
|
|
|
|
|
2010-04-05 19:31:55 +00:00
|
|
|
static int vcd_end_track(mp_vcd_priv_t* vcd)
|
|
|
|
{
|
|
|
|
return vcd->tochdr.ending_track;
|
|
|
|
}
|
|
|
|
|
2007-07-26 23:15:54 +00:00
|
|
|
static int
|
|
|
|
vcd_read(mp_vcd_priv_t* vcd, char *mem)
|
|
|
|
{
|
2007-07-27 17:37:53 +00:00
|
|
|
#ifdef VCD_NETBSD
|
|
|
|
struct scsireq sc;
|
|
|
|
int lba = vcd_get_msf(vcd);
|
|
|
|
int blocks;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
blocks = 1;
|
|
|
|
|
|
|
|
memset(&sc, 0, sizeof(sc));
|
|
|
|
sc.cmd[0] = 0xBE;
|
|
|
|
sc.cmd[1] = 5 << 2; // mode2/form2
|
|
|
|
AV_WB32(&sc.cmd[2], lba);
|
|
|
|
AV_WB24(&sc.cmd[6], blocks);
|
|
|
|
sc.cmd[9] = 1 << 4; // user data only
|
|
|
|
sc.cmd[10] = 0; // no subchannel
|
|
|
|
sc.cmdlen = 12;
|
|
|
|
sc.databuf = (caddr_t) mem;
|
2008-01-28 12:18:05 +00:00
|
|
|
sc.datalen = VCD_SECTOR_DATA;
|
2007-07-27 17:37:53 +00:00
|
|
|
sc.senselen = sizeof(sc.sense);
|
|
|
|
sc.flags = SCCMD_READ;
|
|
|
|
sc.timeout = 10000;
|
|
|
|
rc = ioctl(vcd->fd, SCIOCCOMMAND, &sc);
|
|
|
|
if (rc == -1) {
|
|
|
|
mp_msg(MSGT_STREAM,MSGL_ERR,"SCIOCCOMMAND: %s\n",strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (sc.retsts || sc.error) {
|
|
|
|
mp_msg(MSGT_STREAM,MSGL_ERR,"scsi command failed: status %d error %d\n",
|
|
|
|
sc.retsts,sc.error);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#else
|
2007-07-27 08:49:14 +00:00
|
|
|
if (pread(vcd->fd,&vcd->buf,VCD_SECTOR_SIZE,vcd_get_msf(vcd)*VCD_SECTOR_SIZE)
|
|
|
|
!= VCD_SECTOR_SIZE) return 0; // EOF?
|
2001-06-21 00:06:40 +00:00
|
|
|
|
2007-07-27 08:49:14 +00:00
|
|
|
memcpy(mem,vcd->buf.data,VCD_SECTOR_DATA);
|
2007-07-27 17:37:53 +00:00
|
|
|
#endif
|
|
|
|
vcd_inc_msf(vcd);
|
2007-07-27 08:49:14 +00:00
|
|
|
return VCD_SECTOR_DATA;
|
2001-06-03 00:31:41 +00:00
|
|
|
}
|
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#endif /* MPLAYER_VCD_READ_FBSD_H */
|