Mercurial > mplayer.hg
annotate libmpdemux/vcd_read_darwin.h @ 17479:92a9690cc3e2
setting codec_tag unconditionally to FMP4 is a bad idea (breaks mov/mp4)
author | michael |
---|---|
date | Tue, 24 Jan 2006 23:55:43 +0000 |
parents | aa15d627a00b |
children | 4231482179b6 |
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 return 0; | |
44 } | |
45 | |
46 int vcd_seek_to_track(mp_vcd_priv_t* vcd, int track) | |
47 { | |
48 dk_cd_read_track_info_t tocentry; | |
49 struct CDTrackInfo entry; | |
50 | |
51 memset( &vcd->entry, 0, sizeof(vcd->entry)); | |
52 vcd->entry.addressType = kCDTrackInfoAddressTypeTrackNumber; | |
53 vcd->entry.address = track; | |
54 vcd->entry.bufferLength = sizeof(entry); | |
55 vcd->entry.buffer = &entry; | |
56 | |
57 if (ioctl(vcd->fd, DKIOCCDREADTRACKINFO, &vcd->entry)) | |
58 { | |
59 mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif1: %s\n",strerror(errno)); | |
60 return -1; | |
61 } | |
62 return VCD_SECTOR_DATA*vcd_get_msf(vcd); | |
63 | |
64 return -1; | |
65 } | |
66 | |
67 int vcd_get_track_end(mp_vcd_priv_t* vcd, int track) | |
68 { | |
69 dk_cd_read_disc_info_t tochdr; | |
70 struct CDDiscInfo hdr; | |
71 | |
72 dk_cd_read_track_info_t tocentry; | |
73 struct CDTrackInfo entry; | |
74 | |
75 //read toc header | |
76 memset(&tochdr, 0, sizeof(tochdr)); | |
77 tochdr.buffer = &hdr; | |
78 tochdr.bufferLength = sizeof(hdr); | |
79 | |
80 if (ioctl(vcd->fd, DKIOCCDREADDISCINFO, &tochdr) < 0) | |
81 { | |
82 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno)); | |
83 return NULL; | |
84 } | |
85 | |
86 //read track info | |
87 memset( &vcd->entry, 0, sizeof(vcd->entry)); | |
88 vcd->entry.addressType = kCDTrackInfoAddressTypeTrackNumber; | |
89 vcd->entry.address = track<(hdr.lastTrackNumberInLastSessionLSB+1)?(track):CDROM_LEADOUT; | |
90 vcd->entry.bufferLength = sizeof(entry); | |
91 vcd->entry.buffer = &entry; | |
92 | |
93 if (ioctl(vcd->fd, DKIOCCDREADTRACKINFO, &vcd->entry)) | |
94 { | |
95 mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif2: %s\n",strerror(errno)); | |
96 return -1; | |
97 } | |
98 return VCD_SECTOR_DATA*vcd_get_msf(vcd); | |
99 | |
100 return -1; | |
101 } | |
102 | |
103 mp_vcd_priv_t* vcd_read_toc(int fd) | |
104 { | |
105 dk_cd_read_disc_info_t tochdr; | |
106 struct CDDiscInfo hdr; | |
107 | |
108 dk_cd_read_track_info_t tocentry; | |
109 struct CDTrackInfo entry; | |
110 CDMSF trackMSF; | |
111 | |
112 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
|
113 int i, min = 0, sec = 0, frame = 0; |
13682 | 114 |
115 //read toc header | |
116 memset(&tochdr, 0, sizeof(tochdr)); | |
117 tochdr.buffer = &hdr; | |
118 tochdr.bufferLength = sizeof(hdr); | |
119 | |
120 if (ioctl(fd, DKIOCCDREADDISCINFO, &tochdr) < 0) | |
121 { | |
122 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno)); | |
123 return NULL; | |
124 } | |
125 | |
126 //print all track info | |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
127 if (identify) |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
128 { |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
129 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_VCD_START_TRACK=%d\n", hdr.firstTrackNumberInLastSessionLSB); |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
130 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_VCD_END_TRACK=%d\n", hdr.lastTrackNumberInLastSessionLSB); |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
131 } |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
132 for (i=hdr.firstTrackNumberInLastSessionLSB ; i<=hdr.lastTrackNumberInLastSessionLSB + 1; i++) |
13682 | 133 { |
134 memset( &tocentry, 0, sizeof(tocentry)); | |
135 tocentry.addressType = kCDTrackInfoAddressTypeTrackNumber; | |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
136 tocentry.address = i<=hdr.lastTrackNumberInLastSessionLSB ? i : CDROM_LEADOUT; |
13682 | 137 tocentry.bufferLength = sizeof(entry); |
138 tocentry.buffer = &entry; | |
139 | |
140 if (ioctl(fd,DKIOCCDREADTRACKINFO,&tocentry)==-1) | |
141 { | |
142 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc entry: %s\n",strerror(errno)); | |
143 return NULL; | |
144 } | |
145 | |
146 trackMSF = CDConvertLBAToMSF(entry.trackStartAddress); | |
147 | |
148 //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
|
149 if (i<=hdr.lastTrackNumberInLastSessionLSB) |
13682 | 150 mp_msg(MSGT_OPEN,MSGL_INFO,"track %02d: format=%d %02d:%02d:%02d\n", |
151 (int)tocentry.address, | |
152 //(int)tocentry.entry.addr_type, | |
153 //(int)tocentry.entry.control, | |
154 (int)tocentry.addressType, | |
155 (int)trackMSF.minute, | |
156 (int)trackMSF.second, | |
157 (int)trackMSF.frame | |
158 ); | |
16547
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 if (identify) |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
161 { |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
162 if (i > hdr.firstTrackNumberInLastSessionLSB) |
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 min = trackMSF.minute - min; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
165 sec = trackMSF.second - sec; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
166 frame = trackMSF.frame - frame; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
167 if ( frame < 0 ) |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
168 { |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
169 frame += 75; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
170 sec --; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
171 } |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
172 if ( sec < 0 ) |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
173 { |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
174 sec += 60; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
175 min --; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
176 } |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
177 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_VCD_TRACK_%d_MSF=%02d:%02d:%02d\n", i - 1, min, sec, frame); |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
178 } |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
179 min = trackMSF.minute; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
180 sec = trackMSF.second; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
181 frame = trackMSF.frame; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
13842
diff
changeset
|
182 } |
13682 | 183 } |
184 | |
185 vcd = malloc(sizeof(mp_vcd_priv_t)); | |
186 vcd->fd = fd; | |
187 vcd->msf = trackMSF; | |
188 return vcd; | |
189 | |
190 return NULL; | |
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++; | |
203 | |
204 if (vcd->msf.second==60) | |
205 { | |
206 vcd->msf.second=0; | |
207 vcd->msf.minute++; | |
208 } | |
209 } | |
210 | |
211 memcpy(mem,vcd->buf.data,VCD_SECTOR_DATA); | |
212 return VCD_SECTOR_DATA; | |
213 return 0; | |
214 } | |
215 |