26029
|
1 #ifndef MPLAYER_VCD_READ_WIN32_H
|
|
2 #define MPLAYER_VCD_READ_WIN32_H
|
26013
|
3
|
22508
|
4 #include <ddk/ntddcdrm.h>
|
|
5
|
|
6 typedef struct mp_vcd_priv_st mp_vcd_priv_t;
|
|
7
|
|
8 /*
|
|
9 Unlike Unices, upon reading TOC, Windows will retrieve information for
|
|
10 all tracks, so we don't need to call DeviceIoControl() in functions
|
|
11 like vcd_seek_to_track() and vcd_get_track_end() for each track. Instead
|
|
12 we cache the information in mp_vcd_priv_st.
|
|
13 */
|
|
14 struct mp_vcd_priv_st {
|
|
15 HANDLE hd;
|
|
16 CDROM_TOC toc;
|
|
17 unsigned sect;
|
|
18 char buf[VCD_SECTOR_SIZE];
|
|
19 };
|
|
20
|
|
21 static inline void vcd_set_msf(mp_vcd_priv_t* vcd, unsigned sect)
|
|
22 {
|
|
23 vcd->sect = sect;
|
|
24 }
|
|
25
|
|
26 static inline unsigned vcd_get_msf(mp_vcd_priv_t* vcd, int track){
|
25160
|
27 int index = track - vcd->toc.FirstTrack;
|
22508
|
28 /* -150 to compensate the 2-second pregap */
|
|
29 return vcd->toc.TrackData[index].Address[3] +
|
|
30 (vcd->toc.TrackData[index].Address[2] +
|
|
31 vcd->toc.TrackData[index].Address[1] * 60) * 75 - 150;
|
|
32 }
|
|
33
|
|
34 int vcd_seek_to_track(mp_vcd_priv_t* vcd, int track)
|
|
35 {
|
|
36 unsigned sect;
|
|
37 if (track < vcd->toc.FirstTrack || track > vcd->toc.LastTrack)
|
|
38 return -1;
|
|
39 sect = vcd_get_msf(vcd, track);
|
|
40 vcd_set_msf(vcd, sect);
|
|
41 return VCD_SECTOR_DATA * (sect + 2);
|
|
42 }
|
|
43
|
|
44 int vcd_get_track_end(mp_vcd_priv_t* vcd, int track)
|
|
45 {
|
|
46 if (track < vcd->toc.FirstTrack || track > vcd->toc.LastTrack)
|
|
47 return -1;
|
|
48 return VCD_SECTOR_DATA * (vcd_get_msf(vcd, track + 1));
|
|
49 }
|
|
50
|
|
51 mp_vcd_priv_t* vcd_read_toc(int fd)
|
|
52 {
|
|
53 DWORD dwBytesReturned;
|
|
54 HANDLE hd;
|
|
55 int i, min = 0, sec = 0, frame = 0;
|
|
56 mp_vcd_priv_t* vcd = malloc(sizeof(mp_vcd_priv_t));
|
|
57 if (!vcd)
|
|
58 return NULL;
|
|
59
|
|
60 hd = (HANDLE)_get_osfhandle(fd);
|
|
61 if (!DeviceIoControl(hd, IOCTL_CDROM_READ_TOC, NULL, 0, &vcd->toc,
|
|
62 sizeof(CDROM_TOC), &dwBytesReturned, NULL)) {
|
25159
|
63 mp_msg(MSGT_OPEN, MSGL_ERR, "read CDROM toc header: %lu\n",
|
22508
|
64 GetLastError());
|
|
65 free(vcd);
|
|
66 return NULL;
|
|
67 }
|
|
68
|
|
69 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_START_TRACK=%d\n",
|
|
70 vcd->toc.FirstTrack);
|
|
71 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_END_TRACK=%d\n",
|
|
72 vcd->toc.LastTrack);
|
|
73
|
|
74 for (i = vcd->toc.FirstTrack; i <= vcd->toc.LastTrack + 1; i++) {
|
|
75 int index = i - vcd->toc.FirstTrack;
|
|
76 if (i <= vcd->toc.LastTrack) {
|
|
77 mp_msg(MSGT_OPEN, MSGL_INFO, "track %02d: adr=%d ctrl=%d"
|
|
78 " %02d:%02d:%02d\n",
|
|
79 vcd->toc.TrackData[index].TrackNumber,
|
|
80 vcd->toc.TrackData[index].Adr,
|
|
81 vcd->toc.TrackData[index].Control,
|
|
82 vcd->toc.TrackData[index].Address[1],
|
|
83 vcd->toc.TrackData[index].Address[2],
|
|
84 vcd->toc.TrackData[index].Address[3]);
|
|
85 }
|
|
86
|
|
87 if (mp_msg_test(MSGT_IDENTIFY, MSGL_INFO)) {
|
|
88 if (i > vcd->toc.FirstTrack) {
|
|
89 min = vcd->toc.TrackData[index].Address[1] - min;
|
25158
|
90 sec = vcd->toc.TrackData[index].Address[2] - sec;
|
|
91 frame = vcd->toc.TrackData[index].Address[3] - frame;
|
22508
|
92 if (frame < 0) {
|
|
93 frame += 75;
|
|
94 sec--;
|
|
95 }
|
|
96 if (sec < 0) {
|
|
97 sec += 60;
|
|
98 min--;
|
|
99 }
|
|
100 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_TRACK_%d_MSF="
|
|
101 "%02d:%02d:%02d\n", i - 1, min, sec, frame);
|
|
102 min = vcd->toc.TrackData[index].Address[1];
|
|
103 sec = vcd->toc.TrackData[index].Address[2];
|
|
104 frame = vcd->toc.TrackData[index].Address[3];
|
|
105 }
|
|
106 }
|
|
107 }
|
|
108
|
|
109 vcd->hd = hd;
|
|
110 return vcd;
|
|
111 }
|
|
112
|
|
113 static int vcd_read(mp_vcd_priv_t* vcd, char *mem)
|
|
114 {
|
|
115 DWORD dwBytesReturned;
|
|
116 RAW_READ_INFO cdrom_raw;
|
|
117
|
|
118 /* 2048 isn't a typo: it's the Windows way. */
|
|
119 cdrom_raw.DiskOffset.QuadPart = (long long)(2048 * vcd->sect);
|
|
120 cdrom_raw.SectorCount = 1;
|
|
121 cdrom_raw.TrackMode = XAForm2;
|
|
122
|
|
123 if (!DeviceIoControl(vcd->hd, IOCTL_CDROM_RAW_READ, &cdrom_raw,
|
|
124 sizeof(RAW_READ_INFO), vcd->buf, sizeof(vcd->buf),
|
|
125 &dwBytesReturned, NULL))
|
|
126 return 0;
|
|
127
|
|
128 vcd->sect++;
|
|
129 memcpy(mem, &vcd->buf[VCD_SECTOR_OFFS], VCD_SECTOR_DATA);
|
|
130 return VCD_SECTOR_DATA;
|
|
131 }
|
|
132
|
26029
|
133 #endif /* MPLAYER_VCD_READ_WIN32_H */
|
26013
|
134
|
22508
|
135 /*
|
|
136 vim:noet:sw=4:cino=\:0,g0
|
|
137 */
|