Mercurial > mplayer.hg
annotate stream/vcd_read_darwin.h @ 23586:16db18293ebd
unbreak armv6 previously broken by me...
author | lu_zero |
---|---|
date | Fri, 22 Jun 2007 19:58:44 +0000 |
parents | 300e9b7c499f |
children | 78f77927050c |
rev | line source |
---|---|
13842 | 1 #include <sys/types.h> |
2 #include <CoreFoundation/CFBase.h> | |
3 #include <IOKit/IOKitLib.h> | |
4 #include <IOKit/storage/IOCDTypes.h> | |
5 #include <IOKit/storage/IOCDMedia.h> | |
13682 | 6 #include <IOKit/storage/IOCDMediaBSDClient.h> |
7 | |
8 //=================== VideoCD ========================== | |
9 #define CDROM_LEADOUT 0xAA | |
10 | |
11 typedef struct | |
12 { | |
13 uint8_t sync [12]; | |
14 uint8_t header [4]; | |
15 uint8_t subheader [8]; | |
16 uint8_t data [2324]; | |
17 uint8_t spare [4]; | |
18 } cdsector_t; | |
19 | |
20 typedef struct mp_vcd_priv_st | |
21 { | |
22 int fd; | |
23 dk_cd_read_track_info_t entry; | |
24 CDMSF msf; | |
25 cdsector_t buf; | |
26 } mp_vcd_priv_t; | |
27 | |
28 static inline void vcd_set_msf(mp_vcd_priv_t* vcd, unsigned int sect) | |
29 { | |
30 vcd->msf.frame=sect%75; | |
31 sect=sect/75; | |
32 vcd->msf.second=sect%60; | |
33 sect=sect/60; | |
34 vcd->msf.minute=sect; | |
35 } | |
36 | |
37 static inline unsigned int vcd_get_msf(mp_vcd_priv_t* vcd) | |
38 { | |
39 return vcd->msf.frame + | |
40 (vcd->msf.second+ | |
41 vcd->msf.minute*60)*75; | |
42 | |
43 return 0; | |
44 } | |
45 | |
46 int vcd_seek_to_track(mp_vcd_priv_t* vcd, int track) | |
47 { | |
48 struct CDTrackInfo entry; | |
49 | |
50 memset( &vcd->entry, 0, sizeof(vcd->entry)); | |
51 vcd->entry.addressType = kCDTrackInfoAddressTypeTrackNumber; | |
52 vcd->entry.address = track; | |
53 vcd->entry.bufferLength = sizeof(entry); | |
54 vcd->entry.buffer = &entry; | |
55 | |
56 if (ioctl(vcd->fd, DKIOCCDREADTRACKINFO, &vcd->entry)) | |
57 { | |
58 mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif1: %s\n",strerror(errno)); | |
59 return -1; | |
60 } | |
61 return VCD_SECTOR_DATA*vcd_get_msf(vcd); | |
62 | |
63 return -1; | |
64 } | |
65 | |
66 int vcd_get_track_end(mp_vcd_priv_t* vcd, int track) | |
67 { | |
68 dk_cd_read_disc_info_t tochdr; | |
69 struct CDDiscInfo hdr; | |
70 | |
71 struct CDTrackInfo entry; | |
72 | |
73 //read toc header | |
74 memset(&tochdr, 0, sizeof(tochdr)); | |
75 tochdr.buffer = &hdr; | |
76 tochdr.bufferLength = sizeof(hdr); | |
77 | |
78 if (ioctl(vcd->fd, DKIOCCDREADDISCINFO, &tochdr) < 0) | |
79 { | |
80 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno)); | |
81 return NULL; | |
82 } | |
83 | |
84 //read track info | |
85 memset( &vcd->entry, 0, sizeof(vcd->entry)); | |
86 vcd->entry.addressType = kCDTrackInfoAddressTypeTrackNumber; | |
87 vcd->entry.address = track<(hdr.lastTrackNumberInLastSessionLSB+1)?(track):CDROM_LEADOUT; | |
88 vcd->entry.bufferLength = sizeof(entry); | |
89 vcd->entry.buffer = &entry; | |
90 | |
91 if (ioctl(vcd->fd, DKIOCCDREADTRACKINFO, &vcd->entry)) | |
92 { | |
93 mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif2: %s\n",strerror(errno)); | |
94 return -1; | |
95 } | |
96 return VCD_SECTOR_DATA*vcd_get_msf(vcd); | |
97 | |
98 return -1; | |
99 } | |
100 | |
101 mp_vcd_priv_t* vcd_read_toc(int fd) | |
102 { | |
103 dk_cd_read_disc_info_t tochdr; | |
104 struct CDDiscInfo hdr; | |
105 | |
106 dk_cd_read_track_info_t tocentry; | |
107 struct CDTrackInfo entry; | |
108 CDMSF trackMSF; | |
109 | |
110 mp_vcd_priv_t* vcd; | |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
111 int i, min = 0, sec = 0, frame = 0; |
13682 | 112 |
113 //read toc header | |
114 memset(&tochdr, 0, sizeof(tochdr)); | |
115 tochdr.buffer = &hdr; | |
116 tochdr.bufferLength = sizeof(hdr); | |
117 | |
118 if (ioctl(fd, DKIOCCDREADDISCINFO, &tochdr) < 0) | |
119 { | |
120 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno)); | |
121 return NULL; | |
122 } | |
123 | |
124 //print all track info | |
18237
4231482179b6
Get ride of the several if(identify) messy lines and rearangment of some of the output, both patches by Kiriuja mplayer-patches AT en-directo_net, his changes are barely unrelated, nevertheless Im commiting them thogeter just for the sake of my mental healt, I had both patches already applied on my local three
reynaldo
parents:
16547
diff
changeset
|
125 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_START_TRACK=%d\n", hdr.firstTrackNumberInLastSessionLSB); |
4231482179b6
Get ride of the several if(identify) messy lines and rearangment of some of the output, both patches by Kiriuja mplayer-patches AT en-directo_net, his changes are barely unrelated, nevertheless Im commiting them thogeter just for the sake of my mental healt, I had both patches already applied on my local three
reynaldo
parents:
16547
diff
changeset
|
126 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_END_TRACK=%d\n", hdr.lastTrackNumberInLastSessionLSB); |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
127 for (i=hdr.firstTrackNumberInLastSessionLSB ; i<=hdr.lastTrackNumberInLastSessionLSB + 1; i++) |
13682 | 128 { |
129 memset( &tocentry, 0, sizeof(tocentry)); | |
130 tocentry.addressType = kCDTrackInfoAddressTypeTrackNumber; | |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
131 tocentry.address = i<=hdr.lastTrackNumberInLastSessionLSB ? i : CDROM_LEADOUT; |
13682 | 132 tocentry.bufferLength = sizeof(entry); |
133 tocentry.buffer = &entry; | |
134 | |
135 if (ioctl(fd,DKIOCCDREADTRACKINFO,&tocentry)==-1) | |
136 { | |
137 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc entry: %s\n",strerror(errno)); | |
138 return NULL; | |
139 } | |
140 | |
141 trackMSF = CDConvertLBAToMSF(entry.trackStartAddress); | |
142 | |
143 //mp_msg(MSGT_OPEN,MSGL_INFO,"track %02d: adr=%d ctrl=%d format=%d %02d:%02d:%02d\n", | |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
144 if (i<=hdr.lastTrackNumberInLastSessionLSB) |
13682 | 145 mp_msg(MSGT_OPEN,MSGL_INFO,"track %02d: format=%d %02d:%02d:%02d\n", |
146 (int)tocentry.address, | |
147 //(int)tocentry.entry.addr_type, | |
148 //(int)tocentry.entry.control, | |
149 (int)tocentry.addressType, | |
150 (int)trackMSF.minute, | |
151 (int)trackMSF.second, | |
152 (int)trackMSF.frame | |
153 ); | |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
154 |
18237
4231482179b6
Get ride of the several if(identify) messy lines and rearangment of some of the output, both patches by Kiriuja mplayer-patches AT en-directo_net, his changes are barely unrelated, nevertheless Im commiting them thogeter just for the sake of my mental healt, I had both patches already applied on my local three
reynaldo
parents:
16547
diff
changeset
|
155 if (mp_msg_test(MSGT_IDENTIFY, MSGL_INFO)) |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
156 { |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
157 if (i > hdr.firstTrackNumberInLastSessionLSB) |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
158 { |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
159 min = trackMSF.minute - min; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
160 sec = trackMSF.second - sec; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
161 frame = trackMSF.frame - frame; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
162 if ( frame < 0 ) |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
163 { |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
164 frame += 75; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
165 sec --; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
166 } |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
167 if ( sec < 0 ) |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
168 { |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
169 sec += 60; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
170 min --; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
171 } |
18237
4231482179b6
Get ride of the several if(identify) messy lines and rearangment of some of the output, both patches by Kiriuja mplayer-patches AT en-directo_net, his changes are barely unrelated, nevertheless Im commiting them thogeter just for the sake of my mental healt, I had both patches already applied on my local three
reynaldo
parents:
16547
diff
changeset
|
172 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_TRACK_%d_MSF=%02d:%02d:%02d\n", i - 1, min, sec, frame); |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
173 } |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
174 min = trackMSF.minute; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
175 sec = trackMSF.second; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
176 frame = trackMSF.frame; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
177 } |
13682 | 178 } |
179 | |
180 vcd = malloc(sizeof(mp_vcd_priv_t)); | |
181 vcd->fd = fd; | |
182 vcd->msf = trackMSF; | |
183 return vcd; | |
184 | |
185 return NULL; | |
186 } | |
187 | |
188 static int vcd_read(mp_vcd_priv_t* vcd,char *mem) | |
189 { | |
190 if (pread(vcd->fd,&vcd->buf,VCD_SECTOR_SIZE,vcd_get_msf(vcd)*VCD_SECTOR_SIZE) != VCD_SECTOR_SIZE) | |
191 return 0; // EOF? | |
192 | |
193 vcd->msf.frame++; | |
194 if (vcd->msf.frame==75) | |
195 { | |
196 vcd->msf.frame=0; | |
197 vcd->msf.second++; | |
198 | |
199 if (vcd->msf.second==60) | |
200 { | |
201 vcd->msf.second=0; | |
202 vcd->msf.minute++; | |
203 } | |
204 } | |
205 | |
206 memcpy(mem,vcd->buf.data,VCD_SECTOR_DATA); | |
207 return VCD_SECTOR_DATA; | |
208 return 0; | |
209 } | |
210 |