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