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