1 #ifndef MPLAYER_VCD_READ_DARWIN_H
2 #define MPLAYER_VCD_READ_DARWIN_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>
19 //=================== VideoCD ==========================
20 #define CDROM_LEADOUT 0xAA
26 uint8_t subheader
[8];
31 typedef struct mp_vcd_priv_st
35 dk_cd_read_track_info_t entry
;
36 struct CDDiscInfo hdr
;
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
));
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
);
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
));
92 if (track
== vcd
->hdr
.lastTrackNumberInLastSessionLSB
)
93 vcd
->msf
= CDConvertLBAToMSF(be2me_32(entry
.trackStartAddress
) +
94 be2me_32(entry
.trackSize
));
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
;
110 int i
, min
= 0, sec
= 0, frame
= 0;
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
));
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
));
141 trackMSF
= CDConvertLBAToMSF(be2me_32(entry
.trackStartAddress
));
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
,
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
;
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
));
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
)
197 if (vcd
->msf
.frame
==75)
202 if (vcd
->msf
.second
==60)
209 memcpy(mem
,vcd
->buf
.data
,VCD_SECTOR_DATA
);
210 return VCD_SECTOR_DATA
;
213 #endif /* MPLAYER_VCD_READ_DARWIN_H */