Only read disc info once and save it for later using.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@25406 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
ulion 2007-12-15 13:24:01 +00:00
parent c5ad15d8c0
commit 43bfd2d128
1 changed files with 6 additions and 17 deletions

View File

@ -23,6 +23,7 @@ typedef struct mp_vcd_priv_st
int fd; int fd;
cdsector_t buf; cdsector_t buf;
dk_cd_read_track_info_t entry; dk_cd_read_track_info_t entry;
struct CDDiscInfo hdr;
CDMSF msf; CDMSF msf;
} mp_vcd_priv_t; } mp_vcd_priv_t;
@ -57,32 +58,19 @@ int vcd_seek_to_track(mp_vcd_priv_t* vcd, int track)
int vcd_get_track_end(mp_vcd_priv_t* vcd, int track) int vcd_get_track_end(mp_vcd_priv_t* vcd, int track)
{ {
dk_cd_read_disc_info_t tochdr;
struct CDDiscInfo hdr;
struct CDTrackInfo entry; struct CDTrackInfo entry;
//read toc header if (track > vcd->hdr.lastTrackNumberInLastSessionLSB) {
memset(&tochdr, 0, sizeof(tochdr));
tochdr.buffer = &hdr;
tochdr.bufferLength = sizeof(hdr);
if (ioctl(vcd->fd, DKIOCCDREADDISCINFO, &tochdr) < 0)
{
mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno));
return -1;
}
if (track > hdr.lastTrackNumberInLastSessionLSB) {
mp_msg(MSGT_OPEN, MSGL_ERR, mp_msg(MSGT_OPEN, MSGL_ERR,
"track number %d greater than last track number %d\n", "track number %d greater than last track number %d\n",
track, hdr.lastTrackNumberInLastSessionLSB); track, vcd->hdr.lastTrackNumberInLastSessionLSB);
return -1; return -1;
} }
//read track info //read track info
memset( &vcd->entry, 0, sizeof(vcd->entry)); memset( &vcd->entry, 0, sizeof(vcd->entry));
vcd->entry.addressType = kCDTrackInfoAddressTypeTrackNumber; vcd->entry.addressType = kCDTrackInfoAddressTypeTrackNumber;
vcd->entry.address = track<hdr.lastTrackNumberInLastSessionLSB?track+1:hdr.lastTrackNumberInLastSessionLSB; vcd->entry.address = track<vcd->hdr.lastTrackNumberInLastSessionLSB?track+1:vcd->hdr.lastTrackNumberInLastSessionLSB;
vcd->entry.bufferLength = sizeof(entry); vcd->entry.bufferLength = sizeof(entry);
vcd->entry.buffer = &entry; vcd->entry.buffer = &entry;
@ -91,7 +79,7 @@ int vcd_get_track_end(mp_vcd_priv_t* vcd, int track)
mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif2: %s\n",strerror(errno)); mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif2: %s\n",strerror(errno));
return -1; return -1;
} }
if (track == hdr.lastTrackNumberInLastSessionLSB) if (track == vcd->hdr.lastTrackNumberInLastSessionLSB)
vcd->msf = CDConvertLBAToMSF(be2me_32(entry.trackStartAddress) + vcd->msf = CDConvertLBAToMSF(be2me_32(entry.trackStartAddress) +
be2me_32(entry.trackSize)); be2me_32(entry.trackSize));
else else
@ -185,6 +173,7 @@ mp_vcd_priv_t* vcd_read_toc(int fd)
vcd = malloc(sizeof(mp_vcd_priv_t)); vcd = malloc(sizeof(mp_vcd_priv_t));
vcd->fd = fd; vcd->fd = fd;
vcd->hdr = hdr;
vcd->msf = trackMSF; vcd->msf = trackMSF;
return vcd; return vcd;
} }