Mercurial > mplayer.hg
annotate libmpdvdkit2/device.c @ 8715:165d62ad8155
// Translated by: "heart_of_the_ocean" Murat ALKAN
author | arpi |
---|---|
date | Thu, 02 Jan 2003 13:10:26 +0000 |
parents | 0211de3039eb |
children | f0f0f176d298 |
rev | line source |
---|---|
7027 | 1 /***************************************************************************** |
2 * device.h: DVD device access | |
3 ***************************************************************************** | |
4 * Copyright (C) 1998-2002 VideoLAN | |
5 * $Id$ | |
6 * | |
7 * Authors: Stéphane Borel <stef@via.ecp.fr> | |
8 * Samuel Hocevar <sam@zoy.org> | |
9 * Håkan Hjort <d95hjort@dtek.chalmers.se> | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. | |
24 *****************************************************************************/ | |
25 | |
26 /***************************************************************************** | |
27 * Preamble | |
28 *****************************************************************************/ | |
29 #include "config.h" | |
30 | |
31 #include <stdio.h> | |
32 #include <stdlib.h> | |
33 #include <string.h> | |
34 #include <sys/types.h> | |
35 #include <sys/stat.h> | |
36 #include <fcntl.h> | |
37 | |
38 #ifdef HAVE_UNISTD_H | |
39 # include <unistd.h> | |
40 #endif | |
41 | |
42 #if defined( WIN32 ) | |
43 # include <io.h> /* read() */ | |
44 #else | |
45 # include <sys/uio.h> /* struct iovec */ | |
46 #endif | |
47 | |
7033 | 48 #include "dvdcss.h" |
7027 | 49 |
50 #include "common.h" | |
51 #include "css.h" | |
52 #include "libdvdcss.h" | |
53 #include "ioctl.h" | |
54 #include "device.h" | |
55 | |
56 /***************************************************************************** | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
57 * Device reading prototypes |
7027 | 58 *****************************************************************************/ |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
59 static int libc_open ( dvdcss_t, char const * ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
60 static int libc_seek ( dvdcss_t, int ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
61 static int libc_read ( dvdcss_t, void *, int ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
62 static int libc_readv ( dvdcss_t, struct iovec *, int ); |
7027 | 63 |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
64 #ifdef WIN32 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
65 static int win2k_open ( dvdcss_t, char const * ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
66 static int aspi_open ( dvdcss_t, char const * ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
67 static int win2k_seek ( dvdcss_t, int ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
68 static int aspi_seek ( dvdcss_t, int ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
69 static int win2k_read ( dvdcss_t, void *, int ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
70 static int aspi_read ( dvdcss_t, void *, int ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
71 static int win_readv ( dvdcss_t, struct iovec *, int ); |
7027 | 72 |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
73 static int aspi_read_internal ( int, void *, int ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
74 #endif |
7027 | 75 |
76 int _dvdcss_use_ioctls( dvdcss_t dvdcss ) | |
77 { | |
78 #if defined( WIN32 ) | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
79 if( dvdcss->b_file ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
80 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
81 return 0; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
82 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
83 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
84 /* FIXME: implement this for Windows */ |
7027 | 85 if( WIN2K ) |
86 { | |
87 return 1; | |
88 } | |
89 else | |
90 { | |
91 return 1; | |
92 } | |
93 #else | |
94 struct stat fileinfo; | |
95 int ret; | |
96 | |
97 ret = fstat( dvdcss->i_fd, &fileinfo ); | |
98 if( ret < 0 ) | |
99 { | |
100 return 1; /* What to do? Be conservative and try to use the ioctls */ | |
101 } | |
102 | |
103 /* Complete this list and check that we test for the right things | |
104 * (I've assumed for all OSs that 'r', (raw) device, are char devices | |
105 * and those that don't contain/use an 'r' in the name are block devices) | |
106 * | |
107 * Linux needs a block device | |
108 * Solaris needs a char device | |
109 * Darwin needs a char device | |
110 * OpenBSD needs a char device | |
111 * NetBSD needs a char device | |
112 * FreeBSD can use either the block or the char device | |
113 * BSD/OS can use either the block or the char device | |
114 */ | |
115 | |
116 /* Check if this is a block/char device */ | |
117 if( S_ISBLK( fileinfo.st_mode ) || | |
118 S_ISCHR( fileinfo.st_mode ) ) | |
119 { | |
120 return 1; | |
121 } | |
122 else | |
123 { | |
124 return 0; | |
125 } | |
126 #endif | |
127 } | |
128 | |
129 int _dvdcss_open ( dvdcss_t dvdcss ) | |
130 { | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
131 char psz_debug[200]; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
132 char const *psz_device = dvdcss->psz_device; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
133 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
134 snprintf( psz_debug, 199, "opening target `%s'", psz_device ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
135 psz_debug[199] = '\0'; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
136 _dvdcss_debug( dvdcss, psz_debug ); |
7027 | 137 |
138 #if defined( WIN32 ) | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
139 /* If device is not "X:", we are actually opening a file. */ |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
140 dvdcss->b_file = !psz_device[0] || psz_device[1] != ':' || psz_device[3]; |
7027 | 141 |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
142 /* Initialize readv temporary buffer */ |
7027 | 143 dvdcss->p_readv_buffer = NULL; |
144 dvdcss->i_readv_buf_size = 0; | |
145 | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
146 if( !dvdcss->b_file && WIN2K ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
147 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
148 _dvdcss_debug( dvdcss, "using Win2K API for access" ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
149 dvdcss->pf_seek = win2k_seek; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
150 dvdcss->pf_read = win2k_read; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
151 dvdcss->pf_readv = win_readv; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
152 return win2k_open( dvdcss, psz_device ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
153 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
154 else if( !dvdcss->b_file ) |
7027 | 155 { |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
156 _dvdcss_debug( dvdcss, "using ASPI for access" ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
157 dvdcss->pf_seek = aspi_seek; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
158 dvdcss->pf_read = aspi_read; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
159 dvdcss->pf_readv = win_readv; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
160 return aspi_open( dvdcss, psz_device ); |
7027 | 161 } |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
162 else |
7027 | 163 #endif |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
164 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
165 _dvdcss_debug( dvdcss, "using libc for access" ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
166 dvdcss->pf_seek = libc_seek; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
167 dvdcss->pf_read = libc_read; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
168 dvdcss->pf_readv = libc_readv; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
169 return libc_open( dvdcss, psz_device ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
170 } |
7027 | 171 } |
172 | |
173 #ifndef WIN32 | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
174 int _dvdcss_raw_open ( dvdcss_t dvdcss, char const *psz_device ) |
7027 | 175 { |
176 dvdcss->i_raw_fd = open( psz_device, 0 ); | |
177 | |
178 if( dvdcss->i_raw_fd == -1 ) | |
179 { | |
180 _dvdcss_error( dvdcss, "failed opening raw device, continuing" ); | |
181 return -1; | |
182 } | |
183 else | |
184 { | |
185 dvdcss->i_read_fd = dvdcss->i_raw_fd; | |
186 } | |
187 | |
188 return 0; | |
189 } | |
190 #endif | |
191 | |
192 int _dvdcss_close ( dvdcss_t dvdcss ) | |
193 { | |
194 #if defined( WIN32 ) | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
195 if( dvdcss->b_file ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
196 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
197 close( dvdcss->i_fd ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
198 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
199 else if( WIN2K ) |
7027 | 200 { |
201 CloseHandle( (HANDLE) dvdcss->i_fd ); | |
202 } | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
203 else /* ASPI */ |
7027 | 204 { |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
205 struct w32_aspidev *fd = (struct w32_aspidev *) dvdcss->i_fd; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
206 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
207 /* Unload aspi and free w32_aspidev structure */ |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
208 FreeLibrary( (HMODULE) fd->hASPI ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
209 free( (void*) dvdcss->i_fd ); |
7027 | 210 } |
211 | |
212 /* Free readv temporary buffer */ | |
213 if( dvdcss->p_readv_buffer ) | |
214 { | |
215 free( dvdcss->p_readv_buffer ); | |
216 dvdcss->p_readv_buffer = NULL; | |
217 dvdcss->i_readv_buf_size = 0; | |
218 } | |
219 | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
220 return 0; |
7027 | 221 #else |
222 close( dvdcss->i_fd ); | |
223 | |
224 if( dvdcss->i_raw_fd >= 0 ) | |
225 { | |
226 close( dvdcss->i_raw_fd ); | |
227 dvdcss->i_raw_fd = -1; | |
228 } | |
229 | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
230 return 0; |
7027 | 231 #endif |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
232 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
233 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
234 /* Following functions are local */ |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
235 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
236 /***************************************************************************** |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
237 * Open commands. |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
238 *****************************************************************************/ |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
239 static int libc_open ( dvdcss_t dvdcss, char const *psz_device ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
240 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
241 #if !defined( WIN32 ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
242 dvdcss->i_fd = dvdcss->i_read_fd = open( psz_device, 0 ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
243 #else |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
244 dvdcss->i_fd = dvdcss->i_read_fd = open( psz_device, O_BINARY ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
245 #endif |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
246 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
247 if( dvdcss->i_fd == -1 ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
248 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
249 _dvdcss_error( dvdcss, "failed opening device" ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
250 return -1; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
251 } |
7027 | 252 |
253 return 0; | |
254 } | |
255 | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
256 #if defined( WIN32 ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
257 static int win2k_open ( dvdcss_t dvdcss, char const *psz_device ) |
7027 | 258 { |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
259 char psz_dvd[7]; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
260 _snprintf( psz_dvd, 7, "\\\\.\\%c:", psz_device[0] ); |
7027 | 261 |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
262 /* To work around an M$ bug in IOCTL_DVD_READ_STRUCTURE, we need read |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
263 * _and_ write access to the device (so we can make SCSI Pass Through |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
264 * Requests). Unfortunately this is only allowed if you have |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
265 * administrator priviledges so we allow for a fallback method with |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
266 * only read access to the device (in this case ioctl_ReadCopyright() |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
267 * won't send back the right result). |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
268 * (See Microsoft Q241374: Read and Write Access Required for SCSI |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
269 * Pass Through Requests) */ |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
270 (HANDLE) dvdcss->i_fd = |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
271 CreateFile( psz_dvd, GENERIC_READ | GENERIC_WRITE, |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
272 FILE_SHARE_READ | FILE_SHARE_WRITE, |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
273 NULL, OPEN_EXISTING, |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
274 FILE_FLAG_RANDOM_ACCESS, NULL ); |
7027 | 275 |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
276 if( (HANDLE) dvdcss->i_fd == INVALID_HANDLE_VALUE ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
277 (HANDLE) dvdcss->i_fd = |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
278 CreateFile( psz_dvd, GENERIC_READ, FILE_SHARE_READ, |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
279 NULL, OPEN_EXISTING, |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
280 FILE_FLAG_RANDOM_ACCESS, NULL ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
281 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
282 if( (HANDLE) dvdcss->i_fd == INVALID_HANDLE_VALUE ) |
7027 | 283 { |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
284 _dvdcss_error( dvdcss, "failed opening device" ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
285 return -1; |
7027 | 286 } |
287 | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
288 return 0; |
7027 | 289 } |
290 | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
291 static int aspi_open( dvdcss_t dvdcss, char const * psz_device ) |
7027 | 292 { |
293 HMODULE hASPI; | |
294 DWORD dwSupportInfo; | |
295 struct w32_aspidev *fd; | |
296 int i, j, i_hostadapters; | |
297 long (*lpGetSupport)( void ); | |
298 long (*lpSendCommand)( void* ); | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
299 char c_drive = psz_device[0]; |
7027 | 300 |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
301 /* load aspi and init w32_aspidev structure */ |
7027 | 302 hASPI = LoadLibrary( "wnaspi32.dll" ); |
303 if( hASPI == NULL ) | |
304 { | |
305 _dvdcss_error( dvdcss, "unable to load wnaspi32.dll" ); | |
306 return -1; | |
307 } | |
308 | |
309 (FARPROC) lpGetSupport = GetProcAddress( hASPI, "GetASPI32SupportInfo" ); | |
310 (FARPROC) lpSendCommand = GetProcAddress( hASPI, "SendASPI32Command" ); | |
311 | |
312 if(lpGetSupport == NULL || lpSendCommand == NULL ) | |
313 { | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
314 _dvdcss_error( dvdcss, "unable to get aspi function pointers" ); |
7027 | 315 FreeLibrary( hASPI ); |
316 return -1; | |
317 } | |
318 | |
319 dwSupportInfo = lpGetSupport(); | |
320 | |
321 if( HIBYTE( LOWORD ( dwSupportInfo ) ) == SS_NO_ADAPTERS ) | |
322 { | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
323 _dvdcss_error( dvdcss, "no ASPI adapters found" ); |
7027 | 324 FreeLibrary( hASPI ); |
325 return -1; | |
326 } | |
327 | |
328 if( HIBYTE( LOWORD ( dwSupportInfo ) ) != SS_COMP ) | |
329 { | |
330 _dvdcss_error( dvdcss, "unable to initalize aspi layer" ); | |
331 FreeLibrary( hASPI ); | |
332 return -1; | |
333 } | |
334 | |
335 i_hostadapters = LOBYTE( LOWORD( dwSupportInfo ) ); | |
336 if( i_hostadapters == 0 ) | |
337 { | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
338 _dvdcss_error( dvdcss, "no ASPI adapters ready" ); |
7027 | 339 FreeLibrary( hASPI ); |
340 return -1; | |
341 } | |
342 | |
343 fd = malloc( sizeof( struct w32_aspidev ) ); | |
344 if( fd == NULL ) | |
345 { | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
346 _dvdcss_error( dvdcss, "not enough memory" ); |
7027 | 347 FreeLibrary( hASPI ); |
348 return -1; | |
349 } | |
350 | |
351 fd->i_blocks = 0; | |
352 fd->hASPI = (long) hASPI; | |
353 fd->lpSendCommand = lpSendCommand; | |
354 | |
355 c_drive = c_drive > 'Z' ? c_drive - 'a' : c_drive - 'A'; | |
356 | |
357 for( i = 0; i < i_hostadapters; i++ ) | |
358 { | |
359 for( j = 0; j < 15; j++ ) | |
360 { | |
361 struct SRB_GetDiskInfo srbDiskInfo; | |
362 | |
363 srbDiskInfo.SRB_Cmd = SC_GET_DISK_INFO; | |
364 srbDiskInfo.SRB_HaId = i; | |
365 srbDiskInfo.SRB_Flags = 0; | |
366 srbDiskInfo.SRB_Hdr_Rsvd = 0; | |
367 srbDiskInfo.SRB_Target = j; | |
368 srbDiskInfo.SRB_Lun = 0; | |
369 | |
370 lpSendCommand( (void*) &srbDiskInfo ); | |
371 | |
372 if( (srbDiskInfo.SRB_Status == SS_COMP) && | |
373 (srbDiskInfo.SRB_Int13HDriveInfo == c_drive) ) | |
374 { | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
375 /* Make sure this is a cdrom device */ |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
376 struct SRB_GDEVBlock srbGDEVBlock; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
377 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
378 memset( &srbGDEVBlock, 0, sizeof(struct SRB_GDEVBlock) ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
379 srbGDEVBlock.SRB_Cmd = SC_GET_DEV_TYPE; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
380 srbGDEVBlock.SRB_HaId = i; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
381 srbGDEVBlock.SRB_Target = j; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
382 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
383 lpSendCommand( (void*) &srbGDEVBlock ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
384 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
385 if( ( srbGDEVBlock.SRB_Status == SS_COMP ) && |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
386 ( srbGDEVBlock.SRB_DeviceType == DTYPE_CDROM ) ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
387 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
388 fd->i_sid = MAKEWORD( i, j ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
389 dvdcss->i_fd = (int) fd; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
390 return 0; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
391 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
392 else |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
393 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
394 free( (void*) fd ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
395 FreeLibrary( hASPI ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
396 _dvdcss_error( dvdcss,"this is not a cdrom drive" ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
397 return -1; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
398 } |
7027 | 399 } |
400 } | |
401 } | |
402 | |
403 free( (void*) fd ); | |
404 FreeLibrary( hASPI ); | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
405 _dvdcss_error( dvdcss, "unable to get haid and target (aspi)" ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
406 return -1; |
7027 | 407 } |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
408 #endif |
7027 | 409 |
410 /***************************************************************************** | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
411 * Seek commands. |
7027 | 412 *****************************************************************************/ |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
413 static int libc_seek( dvdcss_t dvdcss, int i_blocks ) |
7027 | 414 { |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
415 off_t i_read; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
416 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
417 dvdcss->i_seekpos = i_blocks; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
418 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
419 i_read = lseek( dvdcss->i_read_fd, |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
420 (off_t)i_blocks * (off_t)DVDCSS_BLOCK_SIZE, SEEK_SET ); |
7027 | 421 |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
422 if( i_read < 0 ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
423 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
424 _dvdcss_error( dvdcss, "seek error" ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
425 } |
7027 | 426 |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
427 return i_read / DVDCSS_BLOCK_SIZE; |
7027 | 428 } |
429 | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
430 #if defined( WIN32 ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
431 static int win2k_seek( dvdcss_t dvdcss, int i_blocks ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
432 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
433 LARGE_INTEGER li_read; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
434 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
435 dvdcss->i_seekpos = i_blocks; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
436 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
437 #ifndef INVALID_SET_FILE_POINTER |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
438 # define INVALID_SET_FILE_POINTER ((DWORD)-1) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
439 #endif |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
440 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
441 li_read.QuadPart = (LONGLONG)i_blocks * DVDCSS_BLOCK_SIZE; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
442 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
443 li_read.LowPart = SetFilePointer( (HANDLE) dvdcss->i_fd, |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
444 li_read.LowPart, |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
445 &li_read.HighPart, FILE_BEGIN ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
446 if( (li_read.LowPart == INVALID_SET_FILE_POINTER) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
447 && GetLastError() != NO_ERROR) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
448 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
449 li_read.QuadPart = -DVDCSS_BLOCK_SIZE; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
450 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
451 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
452 li_read.QuadPart /= DVDCSS_BLOCK_SIZE; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
453 return (int)li_read.QuadPart; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
454 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
455 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
456 static int aspi_seek( dvdcss_t dvdcss, int i_blocks ) |
7027 | 457 { |
458 int i_old_blocks; | |
459 char sz_buf[ DVDCSS_BLOCK_SIZE ]; | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
460 struct w32_aspidev *fd = (struct w32_aspidev *) dvdcss->i_fd; |
7027 | 461 |
462 i_old_blocks = fd->i_blocks; | |
463 fd->i_blocks = i_blocks; | |
464 | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
465 if( aspi_read_internal( dvdcss->i_fd, sz_buf, 1 ) == -1 ) |
7027 | 466 { |
467 fd->i_blocks = i_old_blocks; | |
468 return -1; | |
469 } | |
470 | |
471 (fd->i_blocks)--; | |
472 | |
473 return fd->i_blocks; | |
474 } | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
475 #endif |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
476 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
477 /***************************************************************************** |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
478 * Read commands. |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
479 *****************************************************************************/ |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
480 static int libc_read ( dvdcss_t dvdcss, void *p_buffer, int i_blocks ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
481 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
482 int i_ret; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
483 /* TODO: partial reads are wrong,i.e 2200/2048 = 1 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
484 * but the location has advanced 2200 bytes (lseek possition that is) */ |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
485 i_ret = read( dvdcss->i_read_fd, p_buffer, |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
486 (off_t)i_blocks * DVDCSS_BLOCK_SIZE ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
487 if( i_ret < 0 ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
488 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
489 _dvdcss_error( dvdcss, "read error" ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
490 return i_ret; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
491 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
492 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
493 return i_ret / DVDCSS_BLOCK_SIZE; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
494 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
495 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
496 #if defined( WIN32 ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
497 static int win2k_read ( dvdcss_t dvdcss, void *p_buffer, int i_blocks ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
498 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
499 int i_bytes; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
500 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
501 if( !ReadFile( (HANDLE) dvdcss->i_fd, p_buffer, |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
502 i_blocks * DVDCSS_BLOCK_SIZE, |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
503 (LPDWORD)&i_bytes, NULL ) ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
504 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
505 return -1; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
506 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
507 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
508 return i_bytes / DVDCSS_BLOCK_SIZE; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
509 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
510 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
511 static int aspi_read ( dvdcss_t dvdcss, void *p_buffer, int i_blocks ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
512 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
513 return aspi_read_internal( dvdcss->i_fd, p_buffer, i_blocks ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
514 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
515 #endif |
7027 | 516 |
517 /***************************************************************************** | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
518 * Readv commands. |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
519 *****************************************************************************/ |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
520 static int libc_readv ( dvdcss_t dvdcss, struct iovec *p_iovec, int i_blocks ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
521 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
522 #if defined( WIN32 ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
523 int i_index, i_len, i_total = 0; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
524 unsigned char *p_base; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
525 int i_bytes; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
526 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
527 for( i_index = i_blocks; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
528 i_index; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
529 i_index--, p_iovec++ ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
530 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
531 i_len = p_iovec->iov_len; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
532 p_base = p_iovec->iov_base; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
533 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
534 if( i_len <= 0 ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
535 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
536 continue; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
537 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
538 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
539 i_bytes = read( dvdcss->i_fd, p_base, i_len ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
540 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
541 if( i_bytes < 0 ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
542 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
543 /* One of the reads failed, too bad. |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
544 * We won't even bother returning the reads that went ok, |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
545 * and as in the posix spec the file postition is left |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
546 * unspecified after a failure */ |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
547 return -1; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
548 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
549 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
550 i_total += i_bytes; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
551 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
552 if( i_bytes != i_len ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
553 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
554 /* We reached the end of the file or a signal interrupted |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
555 * the read. Return a partial read. */ |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
556 return i_total / DVDCSS_BLOCK_SIZE; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
557 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
558 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
559 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
560 return i_total / DVDCSS_BLOCK_SIZE; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
561 #else |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
562 int i_read = readv( dvdcss->i_read_fd, p_iovec, i_blocks ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
563 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
564 return i_read / DVDCSS_BLOCK_SIZE; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
565 #endif |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
566 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
567 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
568 #if defined( WIN32 ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
569 /***************************************************************************** |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
570 * win_readv: vectored read using ReadFile for Win2K and ASPI for win9x |
7027 | 571 *****************************************************************************/ |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
572 static int win_readv ( dvdcss_t dvdcss, struct iovec *p_iovec, int i_blocks ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
573 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
574 int i_index; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
575 int i_blocks_read, i_blocks_total = 0; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
576 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
577 /* Check the size of the readv temp buffer, just in case we need to |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
578 * realloc something bigger */ |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
579 if( dvdcss->i_readv_buf_size < i_blocks * DVDCSS_BLOCK_SIZE ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
580 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
581 dvdcss->i_readv_buf_size = i_blocks * DVDCSS_BLOCK_SIZE; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
582 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
583 if( dvdcss->p_readv_buffer ) free( dvdcss->p_readv_buffer ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
584 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
585 /* Allocate a buffer which will be used as a temporary storage |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
586 * for readv */ |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
587 dvdcss->p_readv_buffer = malloc( dvdcss->i_readv_buf_size ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
588 if( !dvdcss->p_readv_buffer ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
589 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
590 _dvdcss_error( dvdcss, " failed (readv)" ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
591 return -1; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
592 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
593 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
594 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
595 for( i_index = i_blocks; i_index; i_index-- ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
596 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
597 i_blocks_total += p_iovec[i_index-1].iov_len; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
598 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
599 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
600 if( i_blocks_total <= 0 ) return 0; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
601 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
602 i_blocks_total /= DVDCSS_BLOCK_SIZE; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
603 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
604 if( WIN2K ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
605 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
606 unsigned long int i_bytes; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
607 if( !ReadFile( (HANDLE)dvdcss->i_fd, dvdcss->p_readv_buffer, |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
608 i_blocks_total * DVDCSS_BLOCK_SIZE, &i_bytes, NULL ) ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
609 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
610 /* The read failed... too bad. |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
611 * As in the posix spec the file postition is left |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
612 * unspecified after a failure */ |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
613 return -1; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
614 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
615 i_blocks_read = i_bytes / DVDCSS_BLOCK_SIZE; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
616 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
617 else /* Win9x */ |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
618 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
619 i_blocks_read = aspi_read_internal( dvdcss->i_fd, |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
620 dvdcss->p_readv_buffer, |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
621 i_blocks_total ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
622 if( i_blocks_read < 0 ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
623 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
624 /* See above */ |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
625 return -1; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
626 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
627 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
628 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
629 /* We just have to copy the content of the temp buffer into the iovecs */ |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
630 for( i_index = 0, i_blocks_total = i_blocks_read; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
631 i_blocks_total > 0; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
632 i_index++ ) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
633 { |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
634 memcpy( p_iovec[i_index].iov_base, |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
635 dvdcss->p_readv_buffer + (i_blocks_read - i_blocks_total) |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
636 * DVDCSS_BLOCK_SIZE, |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
637 p_iovec[i_index].iov_len ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
638 /* if we read less blocks than asked, we'll just end up copying |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
639 * garbage, this isn't an issue as we return the number of |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
640 * blocks actually read */ |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
641 i_blocks_total -= ( p_iovec[i_index].iov_len / DVDCSS_BLOCK_SIZE ); |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
642 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
643 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
644 return i_blocks_read; |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
645 } |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
646 |
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
647 static int aspi_read_internal( int i_fd, void *p_data, int i_blocks ) |
7027 | 648 { |
649 HANDLE hEvent; | |
650 struct SRB_ExecSCSICmd ssc; | |
651 struct w32_aspidev *fd = (struct w32_aspidev *) i_fd; | |
652 | |
653 /* Create the transfer completion event */ | |
654 hEvent = CreateEvent( NULL, TRUE, FALSE, NULL ); | |
655 if( hEvent == NULL ) | |
656 { | |
657 return -1; | |
658 } | |
659 | |
660 memset( &ssc, 0, sizeof( ssc ) ); | |
661 | |
662 ssc.SRB_Cmd = SC_EXEC_SCSI_CMD; | |
663 ssc.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY; | |
664 ssc.SRB_HaId = LOBYTE( fd->i_sid ); | |
665 ssc.SRB_Target = HIBYTE( fd->i_sid ); | |
666 ssc.SRB_SenseLen = SENSE_LEN; | |
667 | |
668 ssc.SRB_PostProc = (LPVOID) hEvent; | |
669 ssc.SRB_BufPointer = p_data; | |
670 ssc.SRB_CDBLen = 12; | |
671 | |
672 ssc.CDBByte[0] = 0xA8; /* RAW */ | |
673 ssc.CDBByte[2] = (UCHAR) (fd->i_blocks >> 24); | |
674 ssc.CDBByte[3] = (UCHAR) (fd->i_blocks >> 16) & 0xff; | |
675 ssc.CDBByte[4] = (UCHAR) (fd->i_blocks >> 8) & 0xff; | |
676 ssc.CDBByte[5] = (UCHAR) (fd->i_blocks) & 0xff; | |
677 | |
678 /* We have to break down the reads into 64kb pieces (ASPI restriction) */ | |
679 if( i_blocks > 32 ) | |
680 { | |
681 ssc.SRB_BufLen = 32 * DVDCSS_BLOCK_SIZE; | |
682 ssc.CDBByte[9] = 32; | |
683 fd->i_blocks += 32; | |
684 | |
685 /* Initiate transfer */ | |
686 ResetEvent( hEvent ); | |
687 fd->lpSendCommand( (void*) &ssc ); | |
688 | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
689 /* transfer the next 64kb (aspi_read_internal is called recursively) |
7027 | 690 * We need to check the status of the read on return */ |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
7033
diff
changeset
|
691 if( aspi_read_internal( i_fd, (u8*) p_data + 32 * DVDCSS_BLOCK_SIZE, |
7027 | 692 i_blocks - 32) < 0 ) |
693 { | |
694 return -1; | |
695 } | |
696 } | |
697 else | |
698 { | |
699 /* This is the last transfer */ | |
700 ssc.SRB_BufLen = i_blocks * DVDCSS_BLOCK_SIZE; | |
701 ssc.CDBByte[9] = (UCHAR) i_blocks; | |
702 fd->i_blocks += i_blocks; | |
703 | |
704 /* Initiate transfer */ | |
705 ResetEvent( hEvent ); | |
706 fd->lpSendCommand( (void*) &ssc ); | |
707 | |
708 } | |
709 | |
710 /* If the command has still not been processed, wait until it's finished */ | |
711 if( ssc.SRB_Status == SS_PENDING ) | |
712 { | |
713 WaitForSingleObject( hEvent, INFINITE ); | |
714 } | |
715 CloseHandle( hEvent ); | |
716 | |
717 /* check that the transfer went as planned */ | |
718 if( ssc.SRB_Status != SS_COMP ) | |
719 { | |
720 return -1; | |
721 } | |
722 | |
723 return i_blocks; | |
724 } | |
725 #endif | |
726 |