annotate libmpdemux/vcd_read_darwin.h @ 14425:97a7bb77adfc

synced to 1.52
author gabrov
date Sat, 08 Jan 2005 00:42:52 +0000
parents 78e5886bc211
children aa15d627a00b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13842
78e5886bc211 fix build on darwin ppc
nplourde
parents: 13682
diff changeset
1 #include <sys/types.h>
78e5886bc211 fix build on darwin ppc
nplourde
parents: 13682
diff changeset
2 #include <CoreFoundation/CFBase.h>
78e5886bc211 fix build on darwin ppc
nplourde
parents: 13682
diff changeset
3 #include <IOKit/IOKitLib.h>
78e5886bc211 fix build on darwin ppc
nplourde
parents: 13682
diff changeset
4 #include <IOKit/storage/IOCDTypes.h>
78e5886bc211 fix build on darwin ppc
nplourde
parents: 13682
diff changeset
5 #include <IOKit/storage/IOCDMedia.h>
13682
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
6 #include <IOKit/storage/IOCDMediaBSDClient.h>
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
7
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
8 //=================== VideoCD ==========================
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
9 #define CDROM_LEADOUT 0xAA
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
10
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
11 typedef struct
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
12 {
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
13 uint8_t sync [12];
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
14 uint8_t header [4];
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
15 uint8_t subheader [8];
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
16 uint8_t data [2324];
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
17 uint8_t spare [4];
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
18 } cdsector_t;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
19
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
20 typedef struct mp_vcd_priv_st
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
21 {
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
22 int fd;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
23 dk_cd_read_track_info_t entry;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
24 CDMSF msf;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
25 cdsector_t buf;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
26 } mp_vcd_priv_t;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
27
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
28 static inline void vcd_set_msf(mp_vcd_priv_t* vcd, unsigned int sect)
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
29 {
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
30 vcd->msf.frame=sect%75;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
31 sect=sect/75;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
32 vcd->msf.second=sect%60;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
33 sect=sect/60;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
34 vcd->msf.minute=sect;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
35 }
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
36
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
37 static inline unsigned int vcd_get_msf(mp_vcd_priv_t* vcd)
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
38 {
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
39 return vcd->msf.frame +
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
40 (vcd->msf.second+
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
41 vcd->msf.minute*60)*75;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
42
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
43 return 0;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
44 }
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
45
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
46 int vcd_seek_to_track(mp_vcd_priv_t* vcd, int track)
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
47 {
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
48 dk_cd_read_track_info_t tocentry;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
49 struct CDTrackInfo entry;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
50
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
51 memset( &vcd->entry, 0, sizeof(vcd->entry));
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
52 vcd->entry.addressType = kCDTrackInfoAddressTypeTrackNumber;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
53 vcd->entry.address = track;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
54 vcd->entry.bufferLength = sizeof(entry);
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
55 vcd->entry.buffer = &entry;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
56
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
57 if (ioctl(vcd->fd, DKIOCCDREADTRACKINFO, &vcd->entry))
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
58 {
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
59 mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif1: %s\n",strerror(errno));
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
60 return -1;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
61 }
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
62 return VCD_SECTOR_DATA*vcd_get_msf(vcd);
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
63
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
64 return -1;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
65 }
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
66
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
67 int vcd_get_track_end(mp_vcd_priv_t* vcd, int track)
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
68 {
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
69 dk_cd_read_disc_info_t tochdr;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
70 struct CDDiscInfo hdr;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
71
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
72 dk_cd_read_track_info_t tocentry;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
73 struct CDTrackInfo entry;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
74
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
75 //read toc header
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
76 memset(&tochdr, 0, sizeof(tochdr));
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
77 tochdr.buffer = &hdr;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
78 tochdr.bufferLength = sizeof(hdr);
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
79
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
80 if (ioctl(vcd->fd, DKIOCCDREADDISCINFO, &tochdr) < 0)
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
81 {
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
82 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno));
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
83 return NULL;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
84 }
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
85
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
86 //read track info
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
87 memset( &vcd->entry, 0, sizeof(vcd->entry));
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
88 vcd->entry.addressType = kCDTrackInfoAddressTypeTrackNumber;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
89 vcd->entry.address = track<(hdr.lastTrackNumberInLastSessionLSB+1)?(track):CDROM_LEADOUT;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
90 vcd->entry.bufferLength = sizeof(entry);
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
91 vcd->entry.buffer = &entry;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
92
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
93 if (ioctl(vcd->fd, DKIOCCDREADTRACKINFO, &vcd->entry))
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
94 {
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
95 mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif2: %s\n",strerror(errno));
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
96 return -1;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
97 }
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
98 return VCD_SECTOR_DATA*vcd_get_msf(vcd);
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
99
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
100 return -1;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
101 }
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
102
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
103 mp_vcd_priv_t* vcd_read_toc(int fd)
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
104 {
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
105 dk_cd_read_disc_info_t tochdr;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
106 struct CDDiscInfo hdr;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
107
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
108 dk_cd_read_track_info_t tocentry;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
109 struct CDTrackInfo entry;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
110 CDMSF trackMSF;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
111
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
112 mp_vcd_priv_t* vcd;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
113 int i;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
114
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
115 //read toc header
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
116 memset(&tochdr, 0, sizeof(tochdr));
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
117 tochdr.buffer = &hdr;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
118 tochdr.bufferLength = sizeof(hdr);
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
119
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
120 if (ioctl(fd, DKIOCCDREADDISCINFO, &tochdr) < 0)
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
121 {
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
122 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno));
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
123 return NULL;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
124 }
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
125
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
126 //print all track info
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
127 for (i=hdr.firstTrackNumberInLastSessionLSB ; i<=hdr.lastTrackNumberInLastSessionLSB ; i++)
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
128 {
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
129 memset( &tocentry, 0, sizeof(tocentry));
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
130 tocentry.addressType = kCDTrackInfoAddressTypeTrackNumber;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
131 tocentry.address = i;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
132 tocentry.bufferLength = sizeof(entry);
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
133 tocentry.buffer = &entry;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
134
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
135 if (ioctl(fd,DKIOCCDREADTRACKINFO,&tocentry)==-1)
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
136 {
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
137 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc entry: %s\n",strerror(errno));
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
138 return NULL;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
139 }
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
140
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
141 trackMSF = CDConvertLBAToMSF(entry.trackStartAddress);
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
142
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
143 //mp_msg(MSGT_OPEN,MSGL_INFO,"track %02d: adr=%d ctrl=%d format=%d %02d:%02d:%02d\n",
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
144 mp_msg(MSGT_OPEN,MSGL_INFO,"track %02d: format=%d %02d:%02d:%02d\n",
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
145 (int)tocentry.address,
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
146 //(int)tocentry.entry.addr_type,
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
147 //(int)tocentry.entry.control,
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
148 (int)tocentry.addressType,
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
149 (int)trackMSF.minute,
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
150 (int)trackMSF.second,
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
151 (int)trackMSF.frame
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
152 );
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
153 }
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
154
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
155 vcd = malloc(sizeof(mp_vcd_priv_t));
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
156 vcd->fd = fd;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
157 vcd->msf = trackMSF;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
158 return vcd;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
159
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
160 return NULL;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
161 }
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
162
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
163 static int vcd_read(mp_vcd_priv_t* vcd,char *mem)
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
164 {
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
165 if (pread(vcd->fd,&vcd->buf,VCD_SECTOR_SIZE,vcd_get_msf(vcd)*VCD_SECTOR_SIZE) != VCD_SECTOR_SIZE)
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
166 return 0; // EOF?
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
167
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
168 vcd->msf.frame++;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
169 if (vcd->msf.frame==75)
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
170 {
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
171 vcd->msf.frame=0;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
172 vcd->msf.second++;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
173
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
174 if (vcd->msf.second==60)
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
175 {
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
176 vcd->msf.second=0;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
177 vcd->msf.minute++;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
178 }
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
179 }
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
180
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
181 memcpy(mem,vcd->buf.data,VCD_SECTOR_DATA);
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
182 return VCD_SECTOR_DATA;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
183 return 0;
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
184 }
aedf94d36d2a support function for vcd on darwin
nplourde
parents:
diff changeset
185