annotate stream/vcd_read_win32.h @ 24928:62b57875bb28

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