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