changeset 25378:f0f03ec41cd3

Only read disc info once and save it for later using.
author ulion
date Sat, 15 Dec 2007 13:24:01 +0000
parents 31e0937ebe38
children 9befb9809011
files stream/vcd_read_darwin.h
diffstat 1 files changed, 6 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/stream/vcd_read_darwin.h	Sat Dec 15 13:05:06 2007 +0000
+++ b/stream/vcd_read_darwin.h	Sat Dec 15 13:24:01 2007 +0000
@@ -23,6 +23,7 @@
 	int fd;
 	cdsector_t buf;
 	dk_cd_read_track_info_t entry;
+	struct CDDiscInfo hdr;
 	CDMSF msf;
 } mp_vcd_priv_t;
 
@@ -57,32 +58,19 @@
 
 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;
 	
-	//read toc header
-    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) {
+	if (track > vcd->hdr.lastTrackNumberInLastSessionLSB) {
 		mp_msg(MSGT_OPEN, MSGL_ERR,
 		       "track number %d greater than last track number %d\n",
-		       track, hdr.lastTrackNumberInLastSessionLSB);
+		       track, vcd->hdr.lastTrackNumberInLastSessionLSB);
 		return -1;
 	}
 	
 	//read track info
 	memset( &vcd->entry, 0, sizeof(vcd->entry));
 	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.buffer = &entry;
   
@@ -91,7 +79,7 @@
 		mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif2: %s\n",strerror(errno));
 		return -1;
 	}
-	if (track == hdr.lastTrackNumberInLastSessionLSB)
+	if (track == vcd->hdr.lastTrackNumberInLastSessionLSB)
 		vcd->msf = CDConvertLBAToMSF(be2me_32(entry.trackStartAddress) +
 		                             be2me_32(entry.trackSize));
 	else
@@ -185,6 +173,7 @@
  
 	vcd = malloc(sizeof(mp_vcd_priv_t));
 	vcd->fd = fd;
+	vcd->hdr = hdr;
 	vcd->msf = trackMSF;
 	return vcd;
 }