Mercurial > mplayer.hg
annotate stream/vcd_read_win32.h @ 36508:449868d26489
vo_bl: Do memory allocation only in one place.
This avoids duplicating code.
author | reimar |
---|---|
date | Sat, 18 Jan 2014 13:43:10 +0000 |
parents | 3a192d8ecc56 |
children |
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]; | |
36433 | 41 unsigned int track; |
22508 | 42 }; |
43 | |
44 static inline void vcd_set_msf(mp_vcd_priv_t* vcd, unsigned sect) | |
45 { | |
46 vcd->sect = sect; | |
47 } | |
48 | |
49 static inline unsigned vcd_get_msf(mp_vcd_priv_t* vcd, int track){ | |
25160 | 50 int index = track - vcd->toc.FirstTrack; |
22508 | 51 /* -150 to compensate the 2-second pregap */ |
52 return vcd->toc.TrackData[index].Address[3] + | |
53 (vcd->toc.TrackData[index].Address[2] + | |
54 vcd->toc.TrackData[index].Address[1] * 60) * 75 - 150; | |
55 } | |
56 | |
33349
3ab3212fb624
Make vcd_seek_to_track static, the GUI no longer needs to
reimar
parents:
32139
diff
changeset
|
57 static int vcd_seek_to_track(mp_vcd_priv_t* vcd, int track) |
22508 | 58 { |
59 unsigned sect; | |
60 if (track < vcd->toc.FirstTrack || track > vcd->toc.LastTrack) | |
61 return -1; | |
62 sect = vcd_get_msf(vcd, track); | |
63 vcd_set_msf(vcd, sect); | |
64 return VCD_SECTOR_DATA * (sect + 2); | |
65 } | |
66 | |
30670
fbd6ba7e0e14
Mark vcd_get_track_end () and vcd_read_toc() as static.
diego
parents:
30426
diff
changeset
|
67 static int vcd_get_track_end(mp_vcd_priv_t* vcd, int track) |
22508 | 68 { |
69 if (track < vcd->toc.FirstTrack || track > vcd->toc.LastTrack) | |
70 return -1; | |
71 return VCD_SECTOR_DATA * (vcd_get_msf(vcd, track + 1)); | |
72 } | |
73 | |
30670
fbd6ba7e0e14
Mark vcd_get_track_end () and vcd_read_toc() as static.
diego
parents:
30426
diff
changeset
|
74 static mp_vcd_priv_t* vcd_read_toc(int fd) |
22508 | 75 { |
76 DWORD dwBytesReturned; | |
77 HANDLE hd; | |
78 int i, min = 0, sec = 0, frame = 0; | |
79 mp_vcd_priv_t* vcd = malloc(sizeof(mp_vcd_priv_t)); | |
80 if (!vcd) | |
81 return NULL; | |
82 | |
83 hd = (HANDLE)_get_osfhandle(fd); | |
84 if (!DeviceIoControl(hd, IOCTL_CDROM_READ_TOC, NULL, 0, &vcd->toc, | |
85 sizeof(CDROM_TOC), &dwBytesReturned, NULL)) { | |
25159 | 86 mp_msg(MSGT_OPEN, MSGL_ERR, "read CDROM toc header: %lu\n", |
22508 | 87 GetLastError()); |
88 free(vcd); | |
89 return NULL; | |
90 } | |
91 | |
92 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_START_TRACK=%d\n", | |
93 vcd->toc.FirstTrack); | |
94 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_END_TRACK=%d\n", | |
95 vcd->toc.LastTrack); | |
96 | |
97 for (i = vcd->toc.FirstTrack; i <= vcd->toc.LastTrack + 1; i++) { | |
98 int index = i - vcd->toc.FirstTrack; | |
99 if (i <= vcd->toc.LastTrack) { | |
100 mp_msg(MSGT_OPEN, MSGL_INFO, "track %02d: adr=%d ctrl=%d" | |
101 " %02d:%02d:%02d\n", | |
102 vcd->toc.TrackData[index].TrackNumber, | |
103 vcd->toc.TrackData[index].Adr, | |
104 vcd->toc.TrackData[index].Control, | |
105 vcd->toc.TrackData[index].Address[1], | |
106 vcd->toc.TrackData[index].Address[2], | |
107 vcd->toc.TrackData[index].Address[3]); | |
108 } | |
109 | |
110 if (mp_msg_test(MSGT_IDENTIFY, MSGL_INFO)) { | |
111 if (i > vcd->toc.FirstTrack) { | |
112 min = vcd->toc.TrackData[index].Address[1] - min; | |
25158 | 113 sec = vcd->toc.TrackData[index].Address[2] - sec; |
114 frame = vcd->toc.TrackData[index].Address[3] - frame; | |
22508 | 115 if (frame < 0) { |
116 frame += 75; | |
117 sec--; | |
118 } | |
119 if (sec < 0) { | |
120 sec += 60; | |
121 min--; | |
122 } | |
123 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_TRACK_%d_MSF=" | |
124 "%02d:%02d:%02d\n", i - 1, min, sec, frame); | |
125 min = vcd->toc.TrackData[index].Address[1]; | |
126 sec = vcd->toc.TrackData[index].Address[2]; | |
127 frame = vcd->toc.TrackData[index].Address[3]; | |
128 } | |
129 } | |
130 } | |
131 | |
132 vcd->hd = hd; | |
133 return vcd; | |
134 } | |
135 | |
30981 | 136 static int vcd_end_track(mp_vcd_priv_t* vcd) |
137 { | |
138 return vcd->toc.LastTrack; | |
139 } | |
140 | |
22508 | 141 static int vcd_read(mp_vcd_priv_t* vcd, char *mem) |
142 { | |
143 DWORD dwBytesReturned; | |
144 RAW_READ_INFO cdrom_raw; | |
145 | |
146 /* 2048 isn't a typo: it's the Windows way. */ | |
147 cdrom_raw.DiskOffset.QuadPart = (long long)(2048 * vcd->sect); | |
148 cdrom_raw.SectorCount = 1; | |
149 cdrom_raw.TrackMode = XAForm2; | |
150 | |
151 if (!DeviceIoControl(vcd->hd, IOCTL_CDROM_RAW_READ, &cdrom_raw, | |
152 sizeof(RAW_READ_INFO), vcd->buf, sizeof(vcd->buf), | |
153 &dwBytesReturned, NULL)) | |
154 return 0; | |
155 | |
156 vcd->sect++; | |
157 memcpy(mem, &vcd->buf[VCD_SECTOR_OFFS], VCD_SECTOR_DATA); | |
158 return VCD_SECTOR_DATA; | |
159 } | |
160 | |
26029 | 161 #endif /* MPLAYER_VCD_READ_WIN32_H */ |