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