Mercurial > mplayer.hg
annotate stream/vcd_read_win32.h @ 35335:85003f7fa621
stream ftp: readline: Always try to read complete lines
If there is not enough space in the provided line buffer just
skip the remaining bytes until reaching EOL.
Usually we are only interested in the first 5 characters and
for everything else the (on-stack) response buffer should still
be big enough.
author | al |
---|---|
date | Tue, 20 Nov 2012 22:18:25 +0000 |
parents | 3ab3212fb624 |
children | 3a192d8ecc56 |
rev | line source |
---|---|
30426
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30165
diff
changeset
|
1 /* |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30165
diff
changeset
|
2 * This file is part of MPlayer. |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30165
diff
changeset
|
3 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30165
diff
changeset
|
4 * MPlayer is free software; you can redistribute it and/or modify |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30165
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30165
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30165
diff
changeset
|
7 * (at your option) any later version. |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30165
diff
changeset
|
8 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30165
diff
changeset
|
9 * MPlayer is distributed in the hope that it will be useful, |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30165
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30165
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30165
diff
changeset
|
12 * GNU General Public License for more details. |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30165
diff
changeset
|
13 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30165
diff
changeset
|
14 * You should have received a copy of the GNU General Public License along |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30165
diff
changeset
|
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30165
diff
changeset
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30165
diff
changeset
|
17 */ |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30165
diff
changeset
|
18 |
26029 | 19 #ifndef MPLAYER_VCD_READ_WIN32_H |
20 #define MPLAYER_VCD_READ_WIN32_H | |
26013 | 21 |
30165 | 22 #include <stddef.h> |
23 #include <stdlib.h> | |
24 #include <string.h> | |
22508 | 25 #include <ddk/ntddcdrm.h> |
26184
7ee4ae1648e6
Add missing header #includes to fix 'make checkheaders'.
diego
parents:
26029
diff
changeset
|
26 #include "mp_msg.h" |
22508 | 27 |
28 typedef struct mp_vcd_priv_st mp_vcd_priv_t; | |
29 | |
30 /* | |
31 Unlike Unices, upon reading TOC, Windows will retrieve information for | |
32 all tracks, so we don't need to call DeviceIoControl() in functions | |
33 like vcd_seek_to_track() and vcd_get_track_end() for each track. Instead | |
34 we cache the information in mp_vcd_priv_st. | |
35 */ | |
36 struct mp_vcd_priv_st { | |
37 HANDLE hd; | |
38 CDROM_TOC toc; | |
39 unsigned sect; | |
40 char buf[VCD_SECTOR_SIZE]; | |
41 }; | |
42 | |
43 static inline void vcd_set_msf(mp_vcd_priv_t* vcd, unsigned sect) | |
44 { | |
45 vcd->sect = sect; | |
46 } | |
47 | |
48 static inline unsigned vcd_get_msf(mp_vcd_priv_t* vcd, int track){ | |
25160 | 49 int index = track - vcd->toc.FirstTrack; |
22508 | 50 /* -150 to compensate the 2-second pregap */ |
51 return vcd->toc.TrackData[index].Address[3] + | |
52 (vcd->toc.TrackData[index].Address[2] + | |
53 vcd->toc.TrackData[index].Address[1] * 60) * 75 - 150; | |
54 } | |
55 | |
33349
3ab3212fb624
Make vcd_seek_to_track static, the GUI no longer needs to
reimar
parents:
32139
diff
changeset
|
56 static int vcd_seek_to_track(mp_vcd_priv_t* vcd, int track) |
22508 | 57 { |
58 unsigned sect; | |
59 if (track < vcd->toc.FirstTrack || track > vcd->toc.LastTrack) | |
60 return -1; | |
61 sect = vcd_get_msf(vcd, track); | |
62 vcd_set_msf(vcd, sect); | |
63 return VCD_SECTOR_DATA * (sect + 2); | |
64 } | |
65 | |
30670
fbd6ba7e0e14
Mark vcd_get_track_end () and vcd_read_toc() as static.
diego
parents:
30426
diff
changeset
|
66 static int vcd_get_track_end(mp_vcd_priv_t* vcd, int track) |
22508 | 67 { |
68 if (track < vcd->toc.FirstTrack || track > vcd->toc.LastTrack) | |
69 return -1; | |
70 return VCD_SECTOR_DATA * (vcd_get_msf(vcd, track + 1)); | |
71 } | |
72 | |
30670
fbd6ba7e0e14
Mark vcd_get_track_end () and vcd_read_toc() as static.
diego
parents:
30426
diff
changeset
|
73 static mp_vcd_priv_t* vcd_read_toc(int fd) |
22508 | 74 { |
75 DWORD dwBytesReturned; | |
76 HANDLE hd; | |
77 int i, min = 0, sec = 0, frame = 0; | |
78 mp_vcd_priv_t* vcd = malloc(sizeof(mp_vcd_priv_t)); | |
79 if (!vcd) | |
80 return NULL; | |
81 | |
82 hd = (HANDLE)_get_osfhandle(fd); | |
83 if (!DeviceIoControl(hd, IOCTL_CDROM_READ_TOC, NULL, 0, &vcd->toc, | |
84 sizeof(CDROM_TOC), &dwBytesReturned, NULL)) { | |
25159 | 85 mp_msg(MSGT_OPEN, MSGL_ERR, "read CDROM toc header: %lu\n", |
22508 | 86 GetLastError()); |
87 free(vcd); | |
88 return NULL; | |
89 } | |
90 | |
91 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_START_TRACK=%d\n", | |
92 vcd->toc.FirstTrack); | |
93 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_END_TRACK=%d\n", | |
94 vcd->toc.LastTrack); | |
95 | |
96 for (i = vcd->toc.FirstTrack; i <= vcd->toc.LastTrack + 1; i++) { | |
97 int index = i - vcd->toc.FirstTrack; | |
98 if (i <= vcd->toc.LastTrack) { | |
99 mp_msg(MSGT_OPEN, MSGL_INFO, "track %02d: adr=%d ctrl=%d" | |
100 " %02d:%02d:%02d\n", | |
101 vcd->toc.TrackData[index].TrackNumber, | |
102 vcd->toc.TrackData[index].Adr, | |
103 vcd->toc.TrackData[index].Control, | |
104 vcd->toc.TrackData[index].Address[1], | |
105 vcd->toc.TrackData[index].Address[2], | |
106 vcd->toc.TrackData[index].Address[3]); | |
107 } | |
108 | |
109 if (mp_msg_test(MSGT_IDENTIFY, MSGL_INFO)) { | |
110 if (i > vcd->toc.FirstTrack) { | |
111 min = vcd->toc.TrackData[index].Address[1] - min; | |
25158 | 112 sec = vcd->toc.TrackData[index].Address[2] - sec; |
113 frame = vcd->toc.TrackData[index].Address[3] - frame; | |
22508 | 114 if (frame < 0) { |
115 frame += 75; | |
116 sec--; | |
117 } | |
118 if (sec < 0) { | |
119 sec += 60; | |
120 min--; | |
121 } | |
122 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_TRACK_%d_MSF=" | |
123 "%02d:%02d:%02d\n", i - 1, min, sec, frame); | |
124 min = vcd->toc.TrackData[index].Address[1]; | |
125 sec = vcd->toc.TrackData[index].Address[2]; | |
126 frame = vcd->toc.TrackData[index].Address[3]; | |
127 } | |
128 } | |
129 } | |
130 | |
131 vcd->hd = hd; | |
132 return vcd; | |
133 } | |
134 | |
30981 | 135 static int vcd_end_track(mp_vcd_priv_t* vcd) |
136 { | |
137 return vcd->toc.LastTrack; | |
138 } | |
139 | |
22508 | 140 static int vcd_read(mp_vcd_priv_t* vcd, char *mem) |
141 { | |
142 DWORD dwBytesReturned; | |
143 RAW_READ_INFO cdrom_raw; | |
144 | |
145 /* 2048 isn't a typo: it's the Windows way. */ | |
146 cdrom_raw.DiskOffset.QuadPart = (long long)(2048 * vcd->sect); | |
147 cdrom_raw.SectorCount = 1; | |
148 cdrom_raw.TrackMode = XAForm2; | |
149 | |
150 if (!DeviceIoControl(vcd->hd, IOCTL_CDROM_RAW_READ, &cdrom_raw, | |
151 sizeof(RAW_READ_INFO), vcd->buf, sizeof(vcd->buf), | |
152 &dwBytesReturned, NULL)) | |
153 return 0; | |
154 | |
155 vcd->sect++; | |
156 memcpy(mem, &vcd->buf[VCD_SECTOR_OFFS], VCD_SECTOR_DATA); | |
157 return VCD_SECTOR_DATA; | |
158 } | |
159 | |
26029 | 160 #endif /* MPLAYER_VCD_READ_WIN32_H */ |