annotate libmpdemux/vcd_read_darwin.h @ 13740:7b459982a1a8

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