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