Mercurial > mplayer.hg
annotate stream/vcd_read_darwin.h @ 26053:a48a280fc0e1
Add #include <sys/sysctl.h> for Mac OS X, fixes the warning
cpudetect.c:344: warning: implicit declaration of function sysctlbyname
patch by Elias Pipping, elias pipping org
author | diego |
---|---|
date | Sun, 24 Feb 2008 12:05:20 +0000 |
parents | 4129c8cfa742 |
children | 7ee4ae1648e6 |
rev | line source |
---|---|
26029 | 1 #ifndef MPLAYER_VCD_READ_DARWIN_H |
2 #define MPLAYER_VCD_READ_DARWIN_H | |
26012 | 3 |
13842 | 4 #include <sys/types.h> |
5 #include <CoreFoundation/CFBase.h> | |
6 #include <IOKit/IOKitLib.h> | |
7 #include <IOKit/storage/IOCDTypes.h> | |
8 #include <IOKit/storage/IOCDMedia.h> | |
13682 | 9 #include <IOKit/storage/IOCDMediaBSDClient.h> |
23896 | 10 #include "mpbswap.h" |
13682 | 11 |
12 //=================== VideoCD ========================== | |
13 #define CDROM_LEADOUT 0xAA | |
14 | |
15 typedef struct | |
16 { | |
17 uint8_t sync [12]; | |
18 uint8_t header [4]; | |
19 uint8_t subheader [8]; | |
20 uint8_t data [2324]; | |
21 uint8_t spare [4]; | |
22 } cdsector_t; | |
23 | |
24 typedef struct mp_vcd_priv_st | |
25 { | |
26 int fd; | |
25376
382aeacc771f
The buffer used for pread need be aligned, but currently it got an offset 23
ulion
parents:
25375
diff
changeset
|
27 cdsector_t buf; |
13682 | 28 dk_cd_read_track_info_t entry; |
25378
f0f03ec41cd3
Only read disc info once and save it for later using.
ulion
parents:
25376
diff
changeset
|
29 struct CDDiscInfo hdr; |
13682 | 30 CDMSF msf; |
31 } mp_vcd_priv_t; | |
32 | |
33 static inline void vcd_set_msf(mp_vcd_priv_t* vcd, unsigned int sect) | |
34 { | |
23898
3a5f766397b5
Simplify and fix missing offset for Darwin vcd_get/set_msf functions
reimar
parents:
23896
diff
changeset
|
35 vcd->msf = CDConvertLBAToMSF(sect); |
13682 | 36 } |
37 | |
38 static inline unsigned int vcd_get_msf(mp_vcd_priv_t* vcd) | |
39 { | |
23898
3a5f766397b5
Simplify and fix missing offset for Darwin vcd_get/set_msf functions
reimar
parents:
23896
diff
changeset
|
40 return CDConvertMSFToLBA(vcd->msf); |
13682 | 41 } |
42 | |
43 int vcd_seek_to_track(mp_vcd_priv_t* vcd, int track) | |
44 { | |
45 struct CDTrackInfo entry; | |
46 | |
47 memset( &vcd->entry, 0, sizeof(vcd->entry)); | |
48 vcd->entry.addressType = kCDTrackInfoAddressTypeTrackNumber; | |
49 vcd->entry.address = track; | |
50 vcd->entry.bufferLength = sizeof(entry); | |
51 vcd->entry.buffer = &entry; | |
52 | |
53 if (ioctl(vcd->fd, DKIOCCDREADTRACKINFO, &vcd->entry)) | |
54 { | |
55 mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif1: %s\n",strerror(errno)); | |
56 return -1; | |
57 } | |
23896 | 58 vcd->msf = CDConvertLBAToMSF(be2me_32(entry.trackStartAddress)); |
13682 | 59 return VCD_SECTOR_DATA*vcd_get_msf(vcd); |
60 } | |
61 | |
62 int vcd_get_track_end(mp_vcd_priv_t* vcd, int track) | |
63 { | |
64 struct CDTrackInfo entry; | |
65 | |
25378
f0f03ec41cd3
Only read disc info once and save it for later using.
ulion
parents:
25376
diff
changeset
|
66 if (track > vcd->hdr.lastTrackNumberInLastSessionLSB) { |
25375
e1884244ba98
Get end position of last track by adding its starting address with track size.
ulion
parents:
23898
diff
changeset
|
67 mp_msg(MSGT_OPEN, MSGL_ERR, |
e1884244ba98
Get end position of last track by adding its starting address with track size.
ulion
parents:
23898
diff
changeset
|
68 "track number %d greater than last track number %d\n", |
25378
f0f03ec41cd3
Only read disc info once and save it for later using.
ulion
parents:
25376
diff
changeset
|
69 track, vcd->hdr.lastTrackNumberInLastSessionLSB); |
25375
e1884244ba98
Get end position of last track by adding its starting address with track size.
ulion
parents:
23898
diff
changeset
|
70 return -1; |
e1884244ba98
Get end position of last track by adding its starting address with track size.
ulion
parents:
23898
diff
changeset
|
71 } |
13682 | 72 |
73 //read track info | |
74 memset( &vcd->entry, 0, sizeof(vcd->entry)); | |
75 vcd->entry.addressType = kCDTrackInfoAddressTypeTrackNumber; | |
25378
f0f03ec41cd3
Only read disc info once and save it for later using.
ulion
parents:
25376
diff
changeset
|
76 vcd->entry.address = track<vcd->hdr.lastTrackNumberInLastSessionLSB?track+1:vcd->hdr.lastTrackNumberInLastSessionLSB; |
13682 | 77 vcd->entry.bufferLength = sizeof(entry); |
78 vcd->entry.buffer = &entry; | |
79 | |
80 if (ioctl(vcd->fd, DKIOCCDREADTRACKINFO, &vcd->entry)) | |
81 { | |
82 mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif2: %s\n",strerror(errno)); | |
83 return -1; | |
84 } | |
25378
f0f03ec41cd3
Only read disc info once and save it for later using.
ulion
parents:
25376
diff
changeset
|
85 if (track == vcd->hdr.lastTrackNumberInLastSessionLSB) |
25375
e1884244ba98
Get end position of last track by adding its starting address with track size.
ulion
parents:
23898
diff
changeset
|
86 vcd->msf = CDConvertLBAToMSF(be2me_32(entry.trackStartAddress) + |
e1884244ba98
Get end position of last track by adding its starting address with track size.
ulion
parents:
23898
diff
changeset
|
87 be2me_32(entry.trackSize)); |
e1884244ba98
Get end position of last track by adding its starting address with track size.
ulion
parents:
23898
diff
changeset
|
88 else |
23896 | 89 vcd->msf = CDConvertLBAToMSF(be2me_32(entry.trackStartAddress)); |
13682 | 90 return VCD_SECTOR_DATA*vcd_get_msf(vcd); |
91 } | |
92 | |
93 mp_vcd_priv_t* vcd_read_toc(int fd) | |
94 { | |
95 dk_cd_read_disc_info_t tochdr; | |
96 struct CDDiscInfo hdr; | |
97 | |
98 dk_cd_read_track_info_t tocentry; | |
99 struct CDTrackInfo entry; | |
100 CDMSF trackMSF; | |
101 | |
102 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
|
103 int i, min = 0, sec = 0, frame = 0; |
13682 | 104 |
105 //read toc header | |
106 memset(&tochdr, 0, sizeof(tochdr)); | |
107 tochdr.buffer = &hdr; | |
108 tochdr.bufferLength = sizeof(hdr); | |
109 | |
110 if (ioctl(fd, DKIOCCDREADDISCINFO, &tochdr) < 0) | |
111 { | |
112 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno)); | |
113 return NULL; | |
114 } | |
115 | |
116 //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
|
117 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
|
118 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
|
119 for (i=hdr.firstTrackNumberInLastSessionLSB ; i<=hdr.lastTrackNumberInLastSessionLSB + 1; i++) |
13682 | 120 { |
25375
e1884244ba98
Get end position of last track by adding its starting address with track size.
ulion
parents:
23898
diff
changeset
|
121 if (i <= hdr.lastTrackNumberInLastSessionLSB) { |
13682 | 122 memset( &tocentry, 0, sizeof(tocentry)); |
123 tocentry.addressType = kCDTrackInfoAddressTypeTrackNumber; | |
25375
e1884244ba98
Get end position of last track by adding its starting address with track size.
ulion
parents:
23898
diff
changeset
|
124 tocentry.address = i; |
13682 | 125 tocentry.bufferLength = sizeof(entry); |
126 tocentry.buffer = &entry; | |
127 | |
128 if (ioctl(fd,DKIOCCDREADTRACKINFO,&tocentry)==-1) | |
129 { | |
130 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc entry: %s\n",strerror(errno)); | |
131 return NULL; | |
132 } | |
133 | |
23896 | 134 trackMSF = CDConvertLBAToMSF(be2me_32(entry.trackStartAddress)); |
25375
e1884244ba98
Get end position of last track by adding its starting address with track size.
ulion
parents:
23898
diff
changeset
|
135 } |
e1884244ba98
Get end position of last track by adding its starting address with track size.
ulion
parents:
23898
diff
changeset
|
136 else |
e1884244ba98
Get end position of last track by adding its starting address with track size.
ulion
parents:
23898
diff
changeset
|
137 trackMSF = CDConvertLBAToMSF(be2me_32(entry.trackStartAddress) |
e1884244ba98
Get end position of last track by adding its starting address with track size.
ulion
parents:
23898
diff
changeset
|
138 + be2me_32(entry.trackSize)); |
13682 | 139 |
140 //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
|
141 if (i<=hdr.lastTrackNumberInLastSessionLSB) |
13682 | 142 mp_msg(MSGT_OPEN,MSGL_INFO,"track %02d: format=%d %02d:%02d:%02d\n", |
143 (int)tocentry.address, | |
144 //(int)tocentry.entry.addr_type, | |
145 //(int)tocentry.entry.control, | |
146 (int)tocentry.addressType, | |
147 (int)trackMSF.minute, | |
148 (int)trackMSF.second, | |
149 (int)trackMSF.frame | |
150 ); | |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
151 |
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
|
152 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
|
153 { |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
154 if (i > hdr.firstTrackNumberInLastSessionLSB) |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
155 { |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
156 min = trackMSF.minute - min; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
157 sec = trackMSF.second - sec; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
158 frame = trackMSF.frame - frame; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
159 if ( frame < 0 ) |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
160 { |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
161 frame += 75; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
162 sec --; |
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 if ( sec < 0 ) |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
165 { |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
166 sec += 60; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
167 min --; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
168 } |
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
|
169 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
|
170 } |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
171 min = trackMSF.minute; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
172 sec = trackMSF.second; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
173 frame = trackMSF.frame; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
174 } |
13682 | 175 } |
176 | |
177 vcd = malloc(sizeof(mp_vcd_priv_t)); | |
178 vcd->fd = fd; | |
25378
f0f03ec41cd3
Only read disc info once and save it for later using.
ulion
parents:
25376
diff
changeset
|
179 vcd->hdr = hdr; |
13682 | 180 vcd->msf = trackMSF; |
181 return vcd; | |
182 } | |
183 | |
184 static int vcd_read(mp_vcd_priv_t* vcd,char *mem) | |
185 { | |
186 if (pread(vcd->fd,&vcd->buf,VCD_SECTOR_SIZE,vcd_get_msf(vcd)*VCD_SECTOR_SIZE) != VCD_SECTOR_SIZE) | |
187 return 0; // EOF? | |
188 | |
189 vcd->msf.frame++; | |
190 if (vcd->msf.frame==75) | |
191 { | |
192 vcd->msf.frame=0; | |
193 vcd->msf.second++; | |
194 | |
195 if (vcd->msf.second==60) | |
196 { | |
197 vcd->msf.second=0; | |
198 vcd->msf.minute++; | |
199 } | |
200 } | |
201 | |
202 memcpy(mem,vcd->buf.data,VCD_SECTOR_DATA); | |
203 return VCD_SECTOR_DATA; | |
204 } | |
205 | |
26029 | 206 #endif /* MPLAYER_VCD_READ_DARWIN_H */ |