Cosmetics: get rid of trailing whitespace.
[mplayer/glamo.git] / stream / vcd_read_darwin.h
blob4d92458486dd9811b18d515dbe677ed9e1efb48b
1 #ifndef MPLAYER_VCD_READ_DARWIN_H
2 #define MPLAYER_VCD_READ_DARWIN_H
4 #include <stdlib.h>
5 #include <string.h>
6 #include <errno.h>
7 #include <sys/types.h>
8 #include <sys/uio.h>
9 #include <unistd.h>
10 #include <CoreFoundation/CFBase.h>
11 #include <IOKit/IOKitLib.h>
12 #include <IOKit/storage/IOCDTypes.h>
13 #include <IOKit/storage/IOCDMedia.h>
14 #include <IOKit/storage/IOCDMediaBSDClient.h>
15 #include "mpbswap.h"
16 #include "mp_msg.h"
17 #include "stream.h"
19 //=================== VideoCD ==========================
20 #define CDROM_LEADOUT 0xAA
22 typedef struct
24 uint8_t sync [12];
25 uint8_t header [4];
26 uint8_t subheader [8];
27 uint8_t data [2324];
28 uint8_t spare [4];
29 } cdsector_t;
31 typedef struct mp_vcd_priv_st
33 int fd;
34 cdsector_t buf;
35 dk_cd_read_track_info_t entry;
36 struct CDDiscInfo hdr;
37 CDMSF msf;
38 } mp_vcd_priv_t;
40 static inline void vcd_set_msf(mp_vcd_priv_t* vcd, unsigned int sect)
42 vcd->msf = CDConvertLBAToMSF(sect);
45 static inline unsigned int vcd_get_msf(mp_vcd_priv_t* vcd)
47 return CDConvertMSFToLBA(vcd->msf);
50 int vcd_seek_to_track(mp_vcd_priv_t* vcd, int track)
52 struct CDTrackInfo entry;
54 memset( &vcd->entry, 0, sizeof(vcd->entry));
55 vcd->entry.addressType = kCDTrackInfoAddressTypeTrackNumber;
56 vcd->entry.address = track;
57 vcd->entry.bufferLength = sizeof(entry);
58 vcd->entry.buffer = &entry;
60 if (ioctl(vcd->fd, DKIOCCDREADTRACKINFO, &vcd->entry))
62 mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif1: %s\n",strerror(errno));
63 return -1;
65 vcd->msf = CDConvertLBAToMSF(be2me_32(entry.trackStartAddress));
66 return VCD_SECTOR_DATA*vcd_get_msf(vcd);
69 int vcd_get_track_end(mp_vcd_priv_t* vcd, int track)
71 struct CDTrackInfo entry;
73 if (track > vcd->hdr.lastTrackNumberInLastSessionLSB) {
74 mp_msg(MSGT_OPEN, MSGL_ERR,
75 "track number %d greater than last track number %d\n",
76 track, vcd->hdr.lastTrackNumberInLastSessionLSB);
77 return -1;
80 //read track info
81 memset( &vcd->entry, 0, sizeof(vcd->entry));
82 vcd->entry.addressType = kCDTrackInfoAddressTypeTrackNumber;
83 vcd->entry.address = track<vcd->hdr.lastTrackNumberInLastSessionLSB?track+1:vcd->hdr.lastTrackNumberInLastSessionLSB;
84 vcd->entry.bufferLength = sizeof(entry);
85 vcd->entry.buffer = &entry;
87 if (ioctl(vcd->fd, DKIOCCDREADTRACKINFO, &vcd->entry))
89 mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif2: %s\n",strerror(errno));
90 return -1;
92 if (track == vcd->hdr.lastTrackNumberInLastSessionLSB)
93 vcd->msf = CDConvertLBAToMSF(be2me_32(entry.trackStartAddress) +
94 be2me_32(entry.trackSize));
95 else
96 vcd->msf = CDConvertLBAToMSF(be2me_32(entry.trackStartAddress));
97 return VCD_SECTOR_DATA*vcd_get_msf(vcd);
100 mp_vcd_priv_t* vcd_read_toc(int fd)
102 dk_cd_read_disc_info_t tochdr;
103 struct CDDiscInfo hdr;
105 dk_cd_read_track_info_t tocentry;
106 struct CDTrackInfo entry;
107 CDMSF trackMSF;
109 mp_vcd_priv_t* vcd;
110 int i, min = 0, sec = 0, frame = 0;
112 //read toc header
113 memset(&tochdr, 0, sizeof(tochdr));
114 tochdr.buffer = &hdr;
115 tochdr.bufferLength = sizeof(hdr);
117 if (ioctl(fd, DKIOCCDREADDISCINFO, &tochdr) < 0)
119 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno));
120 return NULL;
123 //print all track info
124 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_START_TRACK=%d\n", hdr.firstTrackNumberInLastSessionLSB);
125 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_END_TRACK=%d\n", hdr.lastTrackNumberInLastSessionLSB);
126 for (i=hdr.firstTrackNumberInLastSessionLSB ; i<=hdr.lastTrackNumberInLastSessionLSB + 1; i++)
128 if (i <= hdr.lastTrackNumberInLastSessionLSB) {
129 memset( &tocentry, 0, sizeof(tocentry));
130 tocentry.addressType = kCDTrackInfoAddressTypeTrackNumber;
131 tocentry.address = i;
132 tocentry.bufferLength = sizeof(entry);
133 tocentry.buffer = &entry;
135 if (ioctl(fd,DKIOCCDREADTRACKINFO,&tocentry)==-1)
137 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc entry: %s\n",strerror(errno));
138 return NULL;
141 trackMSF = CDConvertLBAToMSF(be2me_32(entry.trackStartAddress));
143 else
144 trackMSF = CDConvertLBAToMSF(be2me_32(entry.trackStartAddress)
145 + be2me_32(entry.trackSize));
147 //mp_msg(MSGT_OPEN,MSGL_INFO,"track %02d: adr=%d ctrl=%d format=%d %02d:%02d:%02d\n",
148 if (i<=hdr.lastTrackNumberInLastSessionLSB)
149 mp_msg(MSGT_OPEN,MSGL_INFO,"track %02d: format=%d %02d:%02d:%02d\n",
150 (int)tocentry.address,
151 //(int)tocentry.entry.addr_type,
152 //(int)tocentry.entry.control,
153 (int)tocentry.addressType,
154 (int)trackMSF.minute,
155 (int)trackMSF.second,
156 (int)trackMSF.frame
159 if (mp_msg_test(MSGT_IDENTIFY, MSGL_INFO))
161 if (i > hdr.firstTrackNumberInLastSessionLSB)
163 min = trackMSF.minute - min;
164 sec = trackMSF.second - sec;
165 frame = trackMSF.frame - frame;
166 if ( frame < 0 )
168 frame += 75;
169 sec --;
171 if ( sec < 0 )
173 sec += 60;
174 min --;
176 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_TRACK_%d_MSF=%02d:%02d:%02d\n", i - 1, min, sec, frame);
178 min = trackMSF.minute;
179 sec = trackMSF.second;
180 frame = trackMSF.frame;
184 vcd = malloc(sizeof(mp_vcd_priv_t));
185 vcd->fd = fd;
186 vcd->hdr = hdr;
187 vcd->msf = trackMSF;
188 return vcd;
191 static int vcd_read(mp_vcd_priv_t* vcd,char *mem)
193 if (pread(vcd->fd,&vcd->buf,VCD_SECTOR_SIZE,vcd_get_msf(vcd)*VCD_SECTOR_SIZE) != VCD_SECTOR_SIZE)
194 return 0; // EOF?
196 vcd->msf.frame++;
197 if (vcd->msf.frame==75)
199 vcd->msf.frame=0;
200 vcd->msf.second++;
202 if (vcd->msf.second==60)
204 vcd->msf.second=0;
205 vcd->msf.minute++;
209 memcpy(mem,vcd->buf.data,VCD_SECTOR_DATA);
210 return VCD_SECTOR_DATA;
213 #endif /* MPLAYER_VCD_READ_DARWIN_H */