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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
4129c8cfa742 Add MPLAYER_ prefix to multiple inclusion guards.
diego
parents: 26013
diff changeset
19 #ifndef MPLAYER_VCD_READ_WIN32_H
4129c8cfa742 Add MPLAYER_ prefix to multiple inclusion guards.
diego
parents: 26013
diff changeset
20 #define MPLAYER_VCD_READ_WIN32_H
26013
dcc1f1ac4f0c Add multiple inclusion guard.
diego
parents: 25160
diff changeset
21
30165
b4cbeff5153e Add a few missing header #includes and #defines.
diego
parents: 26184
diff changeset
22 #include <stddef.h>
b4cbeff5153e Add a few missing header #includes and #defines.
diego
parents: 26184
diff changeset
23 #include <stdlib.h>
b4cbeff5153e Add a few missing header #includes and #defines.
diego
parents: 26184
diff changeset
24 #include <string.h>
22508
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
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
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
27
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
28 typedef struct mp_vcd_priv_st mp_vcd_priv_t;
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 Unlike Unices, upon reading TOC, Windows will retrieve information for
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
32 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
33 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
34 we cache the information in mp_vcd_priv_st.
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
35 */
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
36 struct mp_vcd_priv_st {
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
37 HANDLE hd;
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
38 CDROM_TOC toc;
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
39 unsigned sect;
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
40 char buf[VCD_SECTOR_SIZE];
36433
3a192d8ecc56 Revise and fix stream control for VCD.
ib
parents: 33349
diff changeset
41 unsigned int track;
22508
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
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
44 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
45 {
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
46 vcd->sect = sect;
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
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
49 static inline unsigned vcd_get_msf(mp_vcd_priv_t* vcd, int track){
25160
fa4dc90bfe06 Correct VCD track no. calculation on Windows.
zuxy
parents: 25159
diff changeset
50 int index = track - vcd->toc.FirstTrack;
22508
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
51 /* -150 to compensate the 2-second pregap */
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
52 return vcd->toc.TrackData[index].Address[3] +
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
53 (vcd->toc.TrackData[index].Address[2] +
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
54 vcd->toc.TrackData[index].Address[1] * 60) * 75 - 150;
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
55 }
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
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
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
58 {
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
59 unsigned sect;
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
60 if (track < vcd->toc.FirstTrack || track > vcd->toc.LastTrack)
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
61 return -1;
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
62 sect = vcd_get_msf(vcd, track);
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
63 vcd_set_msf(vcd, sect);
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
64 return VCD_SECTOR_DATA * (sect + 2);
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
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
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
68 {
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
69 if (track < vcd->toc.FirstTrack || track > vcd->toc.LastTrack)
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
70 return -1;
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
71 return VCD_SECTOR_DATA * (vcd_get_msf(vcd, track + 1));
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
72 }
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
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
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
75 {
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
76 DWORD dwBytesReturned;
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
77 HANDLE hd;
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
78 int i, min = 0, sec = 0, frame = 0;
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
79 mp_vcd_priv_t* vcd = malloc(sizeof(mp_vcd_priv_t));
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
80 if (!vcd)
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
81 return NULL;
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 hd = (HANDLE)_get_osfhandle(fd);
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
84 if (!DeviceIoControl(hd, IOCTL_CDROM_READ_TOC, NULL, 0, &vcd->toc,
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
85 sizeof(CDROM_TOC), &dwBytesReturned, NULL)) {
25159
fb1bd7bf749d Avoid gcc warning:
zuxy
parents: 25158
diff changeset
86 mp_msg(MSGT_OPEN, MSGL_ERR, "read CDROM toc header: %lu\n",
22508
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
87 GetLastError());
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
88 free(vcd);
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
89 return NULL;
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
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
92 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
93 vcd->toc.FirstTrack);
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
94 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
95 vcd->toc.LastTrack);
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
96
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
97 for (i = vcd->toc.FirstTrack; i <= vcd->toc.LastTrack + 1; i++) {
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
98 int index = i - vcd->toc.FirstTrack;
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
99 if (i <= vcd->toc.LastTrack) {
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
100 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
101 " %02d:%02d:%02d\n",
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
102 vcd->toc.TrackData[index].TrackNumber,
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
103 vcd->toc.TrackData[index].Adr,
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
104 vcd->toc.TrackData[index].Control,
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
105 vcd->toc.TrackData[index].Address[1],
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
106 vcd->toc.TrackData[index].Address[2],
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
107 vcd->toc.TrackData[index].Address[3]);
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
108 }
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 if (mp_msg_test(MSGT_IDENTIFY, MSGL_INFO)) {
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
111 if (i > vcd->toc.FirstTrack) {
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
112 min = vcd->toc.TrackData[index].Address[1] - min;
25158
ad0ac6f589eb Return correct length in ID_VCD_TRACK_n_MSF
zuxy
parents: 22508
diff changeset
113 sec = vcd->toc.TrackData[index].Address[2] - sec;
ad0ac6f589eb Return correct length in ID_VCD_TRACK_n_MSF
zuxy
parents: 22508
diff changeset
114 frame = vcd->toc.TrackData[index].Address[3] - frame;
22508
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
115 if (frame < 0) {
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
116 frame += 75;
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
117 sec--;
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
118 }
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
119 if (sec < 0) {
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
120 sec += 60;
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
121 min--;
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 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_TRACK_%d_MSF="
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
124 "%02d:%02d:%02d\n", i - 1, min, sec, frame);
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
125 min = vcd->toc.TrackData[index].Address[1];
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
126 sec = vcd->toc.TrackData[index].Address[2];
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
127 frame = vcd->toc.TrackData[index].Address[3];
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 }
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
130 }
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
131
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
132 vcd->hd = hd;
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
133 return vcd;
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
134 }
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
135
30981
9bab99cfdff2 Try to fix VCD compilation on non-Linux systems.
reimar
parents: 30670
diff changeset
136 static int vcd_end_track(mp_vcd_priv_t* vcd)
9bab99cfdff2 Try to fix VCD compilation on non-Linux systems.
reimar
parents: 30670
diff changeset
137 {
9bab99cfdff2 Try to fix VCD compilation on non-Linux systems.
reimar
parents: 30670
diff changeset
138 return vcd->toc.LastTrack;
9bab99cfdff2 Try to fix VCD compilation on non-Linux systems.
reimar
parents: 30670
diff changeset
139 }
9bab99cfdff2 Try to fix VCD compilation on non-Linux systems.
reimar
parents: 30670
diff changeset
140
22508
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
141 static int vcd_read(mp_vcd_priv_t* vcd, char *mem)
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
142 {
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
143 DWORD dwBytesReturned;
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
144 RAW_READ_INFO cdrom_raw;
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
145
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
146 /* 2048 isn't a typo: it's the Windows way. */
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
147 cdrom_raw.DiskOffset.QuadPart = (long long)(2048 * vcd->sect);
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
148 cdrom_raw.SectorCount = 1;
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
149 cdrom_raw.TrackMode = XAForm2;
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
150
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
151 if (!DeviceIoControl(vcd->hd, IOCTL_CDROM_RAW_READ, &cdrom_raw,
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
152 sizeof(RAW_READ_INFO), vcd->buf, sizeof(vcd->buf),
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
153 &dwBytesReturned, NULL))
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
154 return 0;
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
155
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
156 vcd->sect++;
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
157 memcpy(mem, &vcd->buf[VCD_SECTOR_OFFS], VCD_SECTOR_DATA);
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
158 return VCD_SECTOR_DATA;
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
159 }
499052866262 add vcd:// for win32, patch by zuxy meng
compn
parents:
diff changeset
160
26029
4129c8cfa742 Add MPLAYER_ prefix to multiple inclusion guards.
diego
parents: 26013
diff changeset
161 #endif /* MPLAYER_VCD_READ_WIN32_H */