Mercurial > mplayer.hg
annotate stream/vcd_read_darwin.h @ 23895:5ebab6056efc
Make vcd_get_track_end actually return the end, not the start on Darwin
author | reimar |
---|---|
date | Sun, 29 Jul 2007 15:35:52 +0000 |
parents | 10fb4653c48d |
children | ae9ebf311ffd |
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 | |
44 int vcd_seek_to_track(mp_vcd_priv_t* vcd, int track) | |
45 { | |
46 struct CDTrackInfo entry; | |
47 | |
48 memset( &vcd->entry, 0, sizeof(vcd->entry)); | |
49 vcd->entry.addressType = kCDTrackInfoAddressTypeTrackNumber; | |
50 vcd->entry.address = track; | |
51 vcd->entry.bufferLength = sizeof(entry); | |
52 vcd->entry.buffer = &entry; | |
53 | |
54 if (ioctl(vcd->fd, DKIOCCDREADTRACKINFO, &vcd->entry)) | |
55 { | |
56 mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif1: %s\n",strerror(errno)); | |
57 return -1; | |
58 } | |
23894
10fb4653c48d
Make the vcd seek and get track end functions actually have an effect
reimar
parents:
23891
diff
changeset
|
59 vcd->msf = CDConvertLBAToMSF(entry.trackStartAddress); |
13682 | 60 return VCD_SECTOR_DATA*vcd_get_msf(vcd); |
61 } | |
62 | |
63 int vcd_get_track_end(mp_vcd_priv_t* vcd, int track) | |
64 { | |
65 dk_cd_read_disc_info_t tochdr; | |
66 struct CDDiscInfo hdr; | |
67 | |
68 struct CDTrackInfo entry; | |
69 | |
70 //read toc header | |
71 memset(&tochdr, 0, sizeof(tochdr)); | |
72 tochdr.buffer = &hdr; | |
73 tochdr.bufferLength = sizeof(hdr); | |
74 | |
75 if (ioctl(vcd->fd, DKIOCCDREADDISCINFO, &tochdr) < 0) | |
76 { | |
77 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno)); | |
23891 | 78 return -1; |
13682 | 79 } |
80 | |
81 //read track info | |
82 memset( &vcd->entry, 0, sizeof(vcd->entry)); | |
83 vcd->entry.addressType = kCDTrackInfoAddressTypeTrackNumber; | |
23895
5ebab6056efc
Make vcd_get_track_end actually return the end, not the start on Darwin
reimar
parents:
23894
diff
changeset
|
84 vcd->entry.address = track<hdr.lastTrackNumberInLastSessionLSB?track+1:CDROM_LEADOUT; |
13682 | 85 vcd->entry.bufferLength = sizeof(entry); |
86 vcd->entry.buffer = &entry; | |
87 | |
88 if (ioctl(vcd->fd, DKIOCCDREADTRACKINFO, &vcd->entry)) | |
89 { | |
90 mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif2: %s\n",strerror(errno)); | |
91 return -1; | |
92 } | |
23894
10fb4653c48d
Make the vcd seek and get track end functions actually have an effect
reimar
parents:
23891
diff
changeset
|
93 vcd->msf = CDConvertLBAToMSF(entry.trackStartAddress); |
13682 | 94 return VCD_SECTOR_DATA*vcd_get_msf(vcd); |
95 } | |
96 | |
97 mp_vcd_priv_t* vcd_read_toc(int fd) | |
98 { | |
99 dk_cd_read_disc_info_t tochdr; | |
100 struct CDDiscInfo hdr; | |
101 | |
102 dk_cd_read_track_info_t tocentry; | |
103 struct CDTrackInfo entry; | |
104 CDMSF trackMSF; | |
105 | |
106 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
|
107 int i, min = 0, sec = 0, frame = 0; |
13682 | 108 |
109 //read toc header | |
110 memset(&tochdr, 0, sizeof(tochdr)); | |
111 tochdr.buffer = &hdr; | |
112 tochdr.bufferLength = sizeof(hdr); | |
113 | |
114 if (ioctl(fd, DKIOCCDREADDISCINFO, &tochdr) < 0) | |
115 { | |
116 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno)); | |
117 return NULL; | |
118 } | |
119 | |
120 //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
|
121 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
|
122 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
|
123 for (i=hdr.firstTrackNumberInLastSessionLSB ; i<=hdr.lastTrackNumberInLastSessionLSB + 1; i++) |
13682 | 124 { |
125 memset( &tocentry, 0, sizeof(tocentry)); | |
126 tocentry.addressType = kCDTrackInfoAddressTypeTrackNumber; | |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
127 tocentry.address = i<=hdr.lastTrackNumberInLastSessionLSB ? i : CDROM_LEADOUT; |
13682 | 128 tocentry.bufferLength = sizeof(entry); |
129 tocentry.buffer = &entry; | |
130 | |
131 if (ioctl(fd,DKIOCCDREADTRACKINFO,&tocentry)==-1) | |
132 { | |
133 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc entry: %s\n",strerror(errno)); | |
134 return NULL; | |
135 } | |
136 | |
137 trackMSF = CDConvertLBAToMSF(entry.trackStartAddress); | |
138 | |
139 //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
|
140 if (i<=hdr.lastTrackNumberInLastSessionLSB) |
13682 | 141 mp_msg(MSGT_OPEN,MSGL_INFO,"track %02d: format=%d %02d:%02d:%02d\n", |
142 (int)tocentry.address, | |
143 //(int)tocentry.entry.addr_type, | |
144 //(int)tocentry.entry.control, | |
145 (int)tocentry.addressType, | |
146 (int)trackMSF.minute, | |
147 (int)trackMSF.second, | |
148 (int)trackMSF.frame | |
149 ); | |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
150 |
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
|
151 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
|
152 { |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
153 if (i > hdr.firstTrackNumberInLastSessionLSB) |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
154 { |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
155 min = trackMSF.minute - min; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
156 sec = trackMSF.second - sec; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
157 frame = trackMSF.frame - frame; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
158 if ( frame < 0 ) |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
159 { |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
160 frame += 75; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
161 sec --; |
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 ( sec < 0 ) |
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 sec += 60; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
166 min --; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
167 } |
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
|
168 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
|
169 } |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
170 min = trackMSF.minute; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
171 sec = trackMSF.second; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
172 frame = trackMSF.frame; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
173 } |
13682 | 174 } |
175 | |
176 vcd = malloc(sizeof(mp_vcd_priv_t)); | |
177 vcd->fd = fd; | |
178 vcd->msf = trackMSF; | |
179 return vcd; | |
180 } | |
181 | |
182 static int vcd_read(mp_vcd_priv_t* vcd,char *mem) | |
183 { | |
184 if (pread(vcd->fd,&vcd->buf,VCD_SECTOR_SIZE,vcd_get_msf(vcd)*VCD_SECTOR_SIZE) != VCD_SECTOR_SIZE) | |
185 return 0; // EOF? | |
186 | |
187 vcd->msf.frame++; | |
188 if (vcd->msf.frame==75) | |
189 { | |
190 vcd->msf.frame=0; | |
191 vcd->msf.second++; | |
192 | |
193 if (vcd->msf.second==60) | |
194 { | |
195 vcd->msf.second=0; | |
196 vcd->msf.minute++; | |
197 } | |
198 } | |
199 | |
200 memcpy(mem,vcd->buf.data,VCD_SECTOR_DATA); | |
201 return VCD_SECTOR_DATA; | |
202 } | |
203 |