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