Mercurial > mplayer.hg
annotate dvdread/dvd_reader.c @ 24050:1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
author | diego |
---|---|
date | Wed, 15 Aug 2007 11:57:30 +0000 |
parents | de28f9e8cb00 |
children | 98ba5d5bfe2d |
rev | line source |
---|---|
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1 /* -*- c-basic-offset: 2; indent-tabs-mode: nil -*- */ |
7029 | 2 /* |
15874 | 3 * Copyright (C) 2001, 2002, 2003 Billy Biggs <vektor@dumbterm.net>, |
4 * Håkan Hjort <d95hjort@dtek.chalmers.se>, | |
5 * Björn Englund <d4bjorn@dtek.chalmers.se> | |
7029 | 6 * |
14938
25df9508f9a8
Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents:
12431
diff
changeset
|
7 * Modified for use with MPlayer, changes contained in libdvdread_changes.diff. |
18783 | 8 * detailed changelog at http://svn.mplayerhq.hu/mplayer/trunk/ |
14938
25df9508f9a8
Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents:
12431
diff
changeset
|
9 * $Id$ |
25df9508f9a8
Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents:
12431
diff
changeset
|
10 * |
7029 | 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 (at | |
14 * your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, but | |
17 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 * 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 | |
7033 | 26 #include "config.h" |
27 | |
7029 | 28 #include <sys/types.h> |
29 #include <sys/stat.h> | |
30 #include <sys/time.h> /* For the timing of dvdcss_title crack. */ | |
31 #include <fcntl.h> | |
32 #include <stdlib.h> | |
33 #include <stdio.h> | |
34 #include <errno.h> | |
35 #include <string.h> | |
36 #include <unistd.h> | |
37 #include <limits.h> | |
38 #include <dirent.h> | |
39 | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
40 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__bsdi__) || defined(__DARWIN__) || defined(__DragonFly__) |
7029 | 41 #define SYS_BSD 1 |
42 #endif | |
43 | |
44 #if defined(__sun) | |
45 #include <sys/mnttab.h> | |
7423
ad967766679a
hpux DVD support fixes by Martin Gansser <mgansser@ngi.de>
arpi
parents:
7358
diff
changeset
|
46 #elif defined(hpux) |
ad967766679a
hpux DVD support fixes by Martin Gansser <mgansser@ngi.de>
arpi
parents:
7358
diff
changeset
|
47 #include </usr/conf/h/mnttab.h> |
7029 | 48 #elif defined(SYS_BSD) |
49 #include <fstab.h> | |
15534 | 50 #elif defined(__linux__) || defined(__CYGWIN__) |
7029 | 51 #include <mntent.h> |
52 #endif | |
53 | |
18910 | 54 #if defined(__MINGW32__) && (__MINGW32_MAJOR_VERSION <= 3) && (__MINGW32_MINOR_VERSION < 10) |
10825 | 55 #include <sys/timeb.h> |
56 static void gettimeofday(struct timeval* t,void* timezone){ | |
57 struct timeb timebuffer; | |
58 ftime( &timebuffer ); | |
59 t->tv_sec=timebuffer.time; | |
60 t->tv_usec=1000*timebuffer.millitm; | |
61 } | |
62 #endif | |
63 | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
64 #include "dvd_reader.h" |
7029 | 65 #include "dvd_input.h" |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
66 #include "dvd_udf.h" |
15874 | 67 #include "md5.h" |
68 | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
69 #include "dvdread_internal.h" |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
70 |
15874 | 71 #define DEFAULT_UDF_CACHE_LEVEL 0 |
7029 | 72 |
73 struct dvd_reader_s { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
74 /* Basic information. */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
75 int isImageFile; |
7029 | 76 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
77 /* Hack for keeping track of the css status. |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
78 * 0: no css, 1: perhaps (need init of keys), 2: have done init */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
79 int css_state; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
80 int css_title; /* Last title that we have called dvdinpute_title for. */ |
7029 | 81 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
82 /* Information required for an image file. */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
83 dvd_input_t dev; |
7029 | 84 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
85 /* Information required for a directory path drive. */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
86 char *path_root; |
15874 | 87 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
88 /* Filesystem cache */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
89 int udfcache_level; /* 0 - turned off, 1 - on */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
90 void *udfcache; |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
91 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
92 /* block aligned malloc */ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
93 void *align; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
94 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
95 /* error message verbosity level */ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
96 int verbose; |
7029 | 97 }; |
98 | |
99 struct dvd_file_s { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
100 /* Basic information. */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
101 dvd_reader_t *dvd; |
7029 | 102 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
103 /* Hack for selecting the right css title. */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
104 int css_title; |
7029 | 105 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
106 /* Information required for an image file. */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
107 uint32_t lb_start; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
108 uint32_t seek_pos; |
7029 | 109 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
110 /* Information required for a directory path drive. */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
111 size_t title_sizes[ 9 ]; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
112 dvd_input_t title_devs[ 9 ]; |
7029 | 113 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
114 /* Calculated at open-time, size in blocks. */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
115 ssize_t filesize; |
7029 | 116 }; |
117 | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
118 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
119 #define DVDREAD_VERBOSE_DEFAULT 0 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
120 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
121 int get_verbose(void) |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
122 { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
123 char *dvdread_verbose; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
124 int verbose; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
125 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
126 dvdread_verbose = getenv("DVDREAD_VERBOSE"); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
127 if(dvdread_verbose) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
128 verbose = (int)strtol(dvdread_verbose, NULL, 0); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
129 } else { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
130 verbose = DVDREAD_VERBOSE_DEFAULT; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
131 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
132 return verbose; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
133 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
134 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
135 int dvdread_verbose(dvd_reader_t *dvd) |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
136 { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
137 return dvd->verbose; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
138 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
139 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
140 dvd_reader_t *device_of_file(dvd_file_t *file) |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
141 { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
142 return file->dvd; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
143 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
144 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
145 /** |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
146 * Returns the compiled version. (DVDREAD_VERSION as an int) |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
147 */ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
148 int DVDVersion(void) |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
149 { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
150 return DVDREAD_VERSION; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
151 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
152 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
153 |
15874 | 154 /** |
155 * Set the level of caching on udf | |
156 * level = 0 (no caching) | |
157 * level = 1 (caching filesystem info) | |
158 */ | |
159 int DVDUDFCacheLevel(dvd_reader_t *device, int level) | |
160 { | |
161 struct dvd_reader_s *dev = (struct dvd_reader_s *)device; | |
162 | |
163 if(level > 0) { | |
164 level = 1; | |
165 } else if(level < 0) { | |
166 return dev->udfcache_level; | |
167 } | |
168 | |
169 dev->udfcache_level = level; | |
170 | |
171 return level; | |
172 } | |
173 | |
174 void *GetUDFCacheHandle(dvd_reader_t *device) | |
175 { | |
176 struct dvd_reader_s *dev = (struct dvd_reader_s *)device; | |
177 | |
178 return dev->udfcache; | |
179 } | |
180 | |
181 void SetUDFCacheHandle(dvd_reader_t *device, void *cache) | |
182 { | |
183 struct dvd_reader_s *dev = (struct dvd_reader_s *)device; | |
184 | |
185 dev->udfcache = cache; | |
186 } | |
187 | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
188 void *GetAlignHandle(dvd_reader_t *device) |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
189 { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
190 struct dvd_reader_s *dev = (struct dvd_reader_s *)device; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
191 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
192 return dev->align; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
193 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
194 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
195 void SetAlignHandle(dvd_reader_t *device, void *align) |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
196 { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
197 struct dvd_reader_s *dev = (struct dvd_reader_s *)device; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
198 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
199 dev->align = align; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
200 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
201 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
202 #ifdef WIN32 /* replacement gettimeofday implementation */ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
203 #include <sys/timeb.h> |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
204 static int gettimeofday( struct timeval *tv, void *tz ) |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
205 { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
206 struct timeb t; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
207 ftime( &t ); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
208 tv->tv_sec = t.time; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
209 tv->tv_usec = t.millitm * 1000; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
210 return 0; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
211 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
212 #endif |
15874 | 213 |
214 | |
7029 | 215 /* Loop over all titles and call dvdcss_title to crack the keys. */ |
216 static int initAllCSSKeys( dvd_reader_t *dvd ) | |
217 { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
218 struct timeval all_s, all_e; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
219 struct timeval t_s, t_e; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
220 char filename[ MAX_UDF_FILE_NAME_LEN ]; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
221 uint32_t start, len; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
222 int title; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
223 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
224 char *nokeys_str = getenv("DVDREAD_NOKEYS"); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
225 if(nokeys_str != NULL) |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
226 return 0; |
15874 | 227 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
228 if(dvd->verbose >= 1) { |
7029 | 229 fprintf( stderr, "\n" ); |
230 fprintf( stderr, "libdvdread: Attempting to retrieve all CSS keys\n" ); | |
231 fprintf( stderr, "libdvdread: This can take a _long_ time, " | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
232 "please be patient\n\n" ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
233 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
234 gettimeofday(&all_s, NULL); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
235 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
236 for( title = 0; title < 100; title++ ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
237 gettimeofday( &t_s, NULL ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
238 if( title == 0 ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
239 sprintf( filename, "/VIDEO_TS/VIDEO_TS.VOB" ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
240 } else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
241 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, 0 ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
242 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
243 start = UDFFindFile( dvd, filename, &len ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
244 if( start != 0 && len != 0 ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
245 /* Perform CSS key cracking for this title. */ |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
246 if(dvd->verbose >= 1) { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
247 fprintf( stderr, "libdvdread: Get key for %s at 0x%08x\n", |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
248 filename, start ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
249 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
250 if( dvdinput_title( dvd->dev, (int)start ) < 0 ) { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
251 if(dvd->verbose >= 0) { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
252 fprintf( stderr, "libdvdread: Error cracking CSS key for %s (0x%08x)\n", filename, start); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
253 } |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
254 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
255 gettimeofday( &t_e, NULL ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
256 if(dvd->verbose >= 1) { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
257 fprintf( stderr, "libdvdread: Elapsed time %ld\n", |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
258 (long int) t_e.tv_sec - t_s.tv_sec ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
259 } |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
260 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
261 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
262 if( title == 0 ) continue; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
263 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
264 gettimeofday( &t_s, NULL ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
265 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, 1 ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
266 start = UDFFindFile( dvd, filename, &len ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
267 if( start == 0 || len == 0 ) break; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
268 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
269 /* Perform CSS key cracking for this title. */ |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
270 if(dvd->verbose >= 1) { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
271 fprintf( stderr, "libdvdread: Get key for %s at 0x%08x\n", |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
272 filename, start ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
273 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
274 if( dvdinput_title( dvd->dev, (int)start ) < 0 ) { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
275 if(dvd->verbose >= 0) { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
276 fprintf( stderr, "libdvdread: Error cracking CSS key for %s (0x%08x)!!\n", filename, start); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
277 } |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
278 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
279 gettimeofday( &t_e, NULL ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
280 if(dvd->verbose >= 1) { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
281 fprintf( stderr, "libdvdread: Elapsed time %ld\n", |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
282 (long int) t_e.tv_sec - t_s.tv_sec ); |
7029 | 283 } |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
284 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
285 title--; |
7029 | 286 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
287 if(dvd->verbose >= 1) { |
7029 | 288 fprintf( stderr, "libdvdread: Found %d VTS's\n", title ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
289 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
290 gettimeofday(&all_e, NULL); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
291 if(dvd->verbose >= 1) { |
7029 | 292 fprintf( stderr, "libdvdread: Elapsed time %ld\n", |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
293 (long int) all_e.tv_sec - all_s.tv_sec ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
294 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
295 return 0; |
7029 | 296 } |
297 | |
298 | |
299 | |
300 /** | |
301 * Open a DVD image or block device file. | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
302 * Checks if the root directory in the udf image file can be found. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
303 * If not it assumes this isn't a valid udf image and returns NULL |
7029 | 304 */ |
305 static dvd_reader_t *DVDOpenImageFile( const char *location, int have_css ) | |
306 { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
307 dvd_reader_t *dvd; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
308 dvd_input_t dev; |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
309 int verbose; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
310 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
311 verbose = get_verbose(); |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
312 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
313 dev = dvdinput_open( location ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
314 if( !dev ) { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
315 if(verbose >= 1) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
316 fprintf( stderr, "libdvdread: Can't open '%s' for reading: %s\n", |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
317 location, strerror(errno)); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
318 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
319 return NULL; |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
320 } |
7029 | 321 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
322 dvd = (dvd_reader_t *) malloc( sizeof( dvd_reader_t ) ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
323 if( !dvd ) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
324 int tmp_errno = errno; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
325 dvdinput_close(dev); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
326 errno = tmp_errno; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
327 return NULL; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
328 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
329 dvd->verbose = verbose; |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
330 dvd->isImageFile = 1; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
331 dvd->dev = dev; |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
332 dvd->path_root = NULL; |
7029 | 333 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
334 dvd->udfcache_level = DEFAULT_UDF_CACHE_LEVEL; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
335 dvd->udfcache = NULL; |
15874 | 336 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
337 dvd->align = NULL; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
338 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
339 if( have_css ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
340 /* Only if DVDCSS_METHOD = title, a bit if it's disc or if |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
341 * DVDCSS_METHOD = key but region missmatch. Unfortunaly we |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
342 * don't have that information. */ |
7029 | 343 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
344 dvd->css_state = 1; /* Need key init. */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
345 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
346 dvd->css_title = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
347 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
348 /* sanity check, is it a valid UDF image, can we find the root dir */ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
349 if(!UDFFindFile(dvd, "/", NULL)) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
350 dvdinput_close(dvd->dev); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
351 if(dvd->udfcache) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
352 FreeUDFCache(dvd, dvd->udfcache); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
353 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
354 if(dvd->align) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
355 if(dvd->verbose >= 0) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
356 fprintf(stderr, "libdvdread: DVDOpenImageFile(): Memory leak in align functions 1\n"); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
357 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
358 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
359 free(dvd); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
360 return NULL; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
361 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
362 return dvd; |
7029 | 363 } |
364 | |
365 static dvd_reader_t *DVDOpenPath( const char *path_root ) | |
366 { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
367 dvd_reader_t *dvd; |
7029 | 368 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
369 dvd = (dvd_reader_t *) malloc( sizeof( dvd_reader_t ) ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
370 if( !dvd ) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
371 return NULL; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
372 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
373 dvd->verbose = get_verbose(); |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
374 dvd->isImageFile = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
375 dvd->dev = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
376 dvd->path_root = strdup( path_root ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
377 if(!dvd->path_root) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
378 free(dvd); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
379 return 0; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
380 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
381 dvd->udfcache_level = DEFAULT_UDF_CACHE_LEVEL; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
382 dvd->udfcache = NULL; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
383 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
384 dvd->align = NULL; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
385 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
386 dvd->css_state = 0; /* Only used in the UDF path */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
387 dvd->css_title = 0; /* Only matters in the UDF path */ |
15874 | 388 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
389 return dvd; |
7029 | 390 } |
391 | |
392 #if defined(__sun) | |
393 /* /dev/rdsk/c0t6d0s0 (link to /devices/...) | |
394 /vol/dev/rdsk/c0t6d0/?? | |
395 /vol/rdsk/<name> */ | |
396 static char *sun_block2char( const char *path ) | |
397 { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
398 char *new_path; |
7029 | 399 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
400 /* Must contain "/dsk/" */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
401 if( !strstr( path, "/dsk/" ) ) return (char *) strdup( path ); |
7029 | 402 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
403 /* Replace "/dsk/" with "/rdsk/" */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
404 new_path = malloc( strlen(path) + 2 ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
405 strcpy( new_path, path ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
406 strcpy( strstr( new_path, "/dsk/" ), "" ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
407 strcat( new_path, "/rdsk/" ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
408 strcat( new_path, strstr( path, "/dsk/" ) + strlen( "/dsk/" ) ); |
7029 | 409 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
410 return new_path; |
7029 | 411 } |
412 #endif | |
413 | |
414 #if defined(SYS_BSD) | |
415 /* FreeBSD /dev/(r)(a)cd0c (a is for atapi), recomended to _not_ use r | |
416 OpenBSD /dev/rcd0c, it needs to be the raw device | |
417 NetBSD /dev/rcd0[d|c|..] d for x86, c (for non x86), perhaps others | |
418 Darwin /dev/rdisk0, it needs to be the raw device | |
419 BSD/OS /dev/sr0c (if not mounted) or /dev/rsr0c ('c' any letter will do) */ | |
420 static char *bsd_block2char( const char *path ) | |
16510 | 421 #if defined(__FreeBSD__) |
422 { | |
423 return (char *) strdup( path ); | |
424 } | |
425 #else | |
7029 | 426 { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
427 char *new_path; |
7029 | 428 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
429 /* If it doesn't start with "/dev/" or does start with "/dev/r" exit */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
430 if( strncmp( path, "/dev/", 5 ) || !strncmp( path, "/dev/r", 6 ) ) |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
431 return (char *) strdup( path ); |
7029 | 432 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
433 /* Replace "/dev/" with "/dev/r" */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
434 new_path = malloc( strlen(path) + 2 ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
435 strcpy( new_path, "/dev/r" ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
436 strcat( new_path, path + strlen( "/dev/" ) ); |
7029 | 437 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
438 return new_path; |
7029 | 439 } |
16510 | 440 #endif /* __FreeBSD__ */ |
7029 | 441 #endif |
442 | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
443 |
7029 | 444 dvd_reader_t *DVDOpen( const char *path ) |
445 { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
446 struct stat fileinfo; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
447 int ret, have_css; |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
448 char *dev_name = NULL; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
449 int internal_errno = 0; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
450 int verbose; |
7029 | 451 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
452 if( path == NULL ) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
453 errno = EINVAL; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
454 return NULL; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
455 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
456 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
457 verbose = get_verbose(); |
7029 | 458 |
12431
663fdd72e594
Encrypted dvd playback now accepts -dvd-drive e: on mingw. fix from libdvdread, left out the various cosmetics changes for now
faust3
parents:
10825
diff
changeset
|
459 #ifdef WIN32 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
460 /* Stat doesn't work on devices under mingwin/cygwin. */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
461 if( path[0] && path[1] == ':' && path[2] == '\0' ) |
12431
663fdd72e594
Encrypted dvd playback now accepts -dvd-drive e: on mingw. fix from libdvdread, left out the various cosmetics changes for now
faust3
parents:
10825
diff
changeset
|
462 { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
463 /* Don't try to stat the file */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
464 fileinfo.st_mode = S_IFBLK; |
12431
663fdd72e594
Encrypted dvd playback now accepts -dvd-drive e: on mingw. fix from libdvdread, left out the various cosmetics changes for now
faust3
parents:
10825
diff
changeset
|
465 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
466 else |
12431
663fdd72e594
Encrypted dvd playback now accepts -dvd-drive e: on mingw. fix from libdvdread, left out the various cosmetics changes for now
faust3
parents:
10825
diff
changeset
|
467 #endif |
663fdd72e594
Encrypted dvd playback now accepts -dvd-drive e: on mingw. fix from libdvdread, left out the various cosmetics changes for now
faust3
parents:
10825
diff
changeset
|
468 { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
469 ret = stat( path, &fileinfo ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
470 if( ret < 0 ) { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
471 int tmp_errno = errno; |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
472 /* If we can't stat the file, give up */ |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
473 if(verbose >= 1) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
474 fprintf( stderr, "libdvdread: Can't stat '%s': %s\n", |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
475 path, strerror(errno)); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
476 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
477 errno = tmp_errno; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
478 return NULL; |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
479 } |
12431
663fdd72e594
Encrypted dvd playback now accepts -dvd-drive e: on mingw. fix from libdvdread, left out the various cosmetics changes for now
faust3
parents:
10825
diff
changeset
|
480 } |
7029 | 481 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
482 /* Try to open libdvdcss or fall back to standard functions */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
483 have_css = dvdinput_setup(); |
7029 | 484 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
485 /* First check if this is a block/char device or a file*/ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
486 if( S_ISBLK( fileinfo.st_mode ) || |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
487 S_ISCHR( fileinfo.st_mode ) || |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
488 S_ISREG( fileinfo.st_mode ) ) { |
7029 | 489 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
490 /** |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
491 * Block devices and regular files are assumed to be DVD-Video images. |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
492 */ |
7029 | 493 #if defined(__sun) |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
494 return DVDOpenImageFile( sun_block2char( path ), have_css ); |
7029 | 495 #elif defined(SYS_BSD) |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
496 return DVDOpenImageFile( bsd_block2char( path ), have_css ); |
7029 | 497 #else |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
498 return DVDOpenImageFile( path, have_css ); |
7029 | 499 #endif |
500 | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
501 } else if( S_ISDIR( fileinfo.st_mode ) ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
502 dvd_reader_t *auth_drive = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
503 char *path_copy; |
7029 | 504 #if defined(SYS_BSD) |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
505 struct fstab* fe; |
15534 | 506 #elif defined(__sun) || defined(__linux__) || defined(__CYGWIN__) |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
507 FILE *mntfile; |
7029 | 508 #endif |
509 | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
510 /* XXX: We should scream real loud here. */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
511 if( !(path_copy = strdup( path ) ) ) return 0; |
7029 | 512 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
513 #ifndef WIN32 /* don't have fchdir, and getcwd( NULL, ... ) is strange */ |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
514 /* Resolve any symlinks and get the absolut dir name. */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
515 { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
516 char *new_path; |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
517 char *current_path; |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
518 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
519 current_path = malloc(PATH_MAX); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
520 if(current_path) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
521 if(!getcwd(current_path, PATH_MAX)) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
522 free(current_path); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
523 current_path = NULL; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
524 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
525 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
526 if(current_path) { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
527 chdir( path_copy ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
528 new_path = malloc(PATH_MAX); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
529 if(new_path) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
530 if(!getcwd(new_path, PATH_MAX )) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
531 free(new_path); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
532 new_path = NULL; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
533 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
534 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
535 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
536 chdir(current_path); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
537 free(current_path); |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
538 if( new_path ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
539 free( path_copy ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
540 path_copy = new_path; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
541 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
542 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
543 } |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
544 #endif |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
545 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
546 /** |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
547 * If we're being asked to open a directory, check if that directory |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
548 * is the mountpoint for a DVD-ROM which we can use instead. |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
549 */ |
7029 | 550 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
551 if( strlen( path_copy ) > 1 ) { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
552 if( path_copy[ strlen( path_copy ) - 1 ] == '/' ) { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
553 path_copy[ strlen( path_copy ) - 1 ] = '\0'; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
554 } |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
555 } |
7029 | 556 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
557 if( strlen( path_copy ) >= 9 ) { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
558 if( !strcasecmp( &(path_copy[ strlen( path_copy ) - 9 ]), |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
559 "/video_ts" ) ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
560 path_copy[ strlen( path_copy ) - 9 ] = '\0'; |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
561 if(path_copy[0] == '\0') { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
562 path_copy[0] = '/'; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
563 path_copy[1] = '\0'; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
564 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
565 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
566 } |
7029 | 567 |
568 #if defined(SYS_BSD) | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
569 if( ( fe = getfsfile( path_copy ) ) ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
570 dev_name = bsd_block2char( fe->fs_spec ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
571 if(verbose >= 1) { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
572 fprintf( stderr, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
573 "libdvdread: Attempting to use device %s" |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
574 " mounted on %s%s\n", |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
575 dev_name, |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
576 fe->fs_file, |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
577 have_css ? " for CSS authentication" : ""); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
578 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
579 auth_drive = DVDOpenImageFile( dev_name, have_css ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
580 if(!auth_drive) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
581 internal_errno = errno; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
582 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
583 } |
7029 | 584 #elif defined(__sun) |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
585 mntfile = fopen( MNTTAB, "r" ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
586 if( mntfile ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
587 struct mnttab mp; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
588 int res; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
589 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
590 while( ( res = getmntent( mntfile, &mp ) ) != -1 ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
591 if( res == 0 && !strcmp( mp.mnt_mountp, path_copy ) ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
592 dev_name = sun_block2char( mp.mnt_special ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
593 if(verbose >= 1) { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
594 fprintf( stderr, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
595 "libdvdread: Attempting to use device %s" |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
596 " mounted on %s%s\n", |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
597 dev_name, |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
598 mp.mnt_mountp, |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
599 have_css ? " for CSS authentication" : ""); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
600 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
601 auth_drive = DVDOpenImageFile( dev_name, have_css ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
602 if(!auth_drive) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
603 internal_errno = errno; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
604 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
605 break; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
606 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
607 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
608 fclose( mntfile ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
609 } |
15534 | 610 #elif defined(__linux__) || defined(__CYGWIN__) |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
611 mntfile = fopen( MOUNTED, "r" ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
612 if( mntfile ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
613 struct mntent *me; |
7029 | 614 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
615 while( ( me = getmntent( mntfile ) ) ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
616 if( !strcmp( me->mnt_dir, path_copy ) ) { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
617 if(verbose >= 1) { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
618 fprintf( stderr, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
619 "libdvdread: Attempting to use device %s" |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
620 " mounted on %s%s\n", |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
621 me->mnt_fsname, |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
622 me->mnt_dir, |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
623 have_css ? " for CSS authentication" : ""); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
624 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
625 auth_drive = DVDOpenImageFile( me->mnt_fsname, have_css ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
626 if(!auth_drive) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
627 internal_errno = errno; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
628 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
629 dev_name = strdup(me->mnt_fsname); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
630 break; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
631 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
632 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
633 fclose( mntfile ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
634 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
635 #elif defined(__MINGW32__) |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
636 dev_name = strdup(path); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
637 auth_drive = DVDOpenImageFile( path, have_css ); |
7029 | 638 #endif |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
639 if( !dev_name ) { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
640 if(verbose >= 1) { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
641 fprintf( stderr, "libdvdread: Couldn't find device name.\n" ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
642 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
643 } else if( !auth_drive ) { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
644 if(verbose >= 1) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
645 fprintf( stderr, "libdvdread: Device %s inaccessible%s: %s\n", |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
646 dev_name, |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
647 have_css ? ", CSS authentication not available" : "", |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
648 strerror(internal_errno)); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
649 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
650 } |
7029 | 651 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
652 free( dev_name ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
653 free( path_copy ); |
7029 | 654 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
655 /** |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
656 * If we've opened a drive, just use that. |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
657 */ |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
658 if( auth_drive ) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
659 return auth_drive; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
660 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
661 /** |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
662 * Otherwise, we now try to open the directory tree instead. |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
663 */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
664 return DVDOpenPath( path ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
665 } |
7029 | 666 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
667 /* If it's none of the above, screw it. */ |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
668 if(verbose >= 1) { |
7029 | 669 fprintf( stderr, "libdvdread: Could not open %s\n", path ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
670 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
671 return 0; |
7029 | 672 } |
673 | |
674 void DVDClose( dvd_reader_t *dvd ) | |
675 { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
676 if( dvd ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
677 if( dvd->dev ) dvdinput_close( dvd->dev ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
678 if( dvd->path_root ) free( dvd->path_root ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
679 if( dvd->udfcache ) FreeUDFCache( dvd, dvd->udfcache ); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
680 if(dvd->align) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
681 if(dvd->verbose >= 0) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
682 fprintf(stderr, "libdvdread: DVDClose(): Memory leak in align functions\n"); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
683 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
684 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
685 dvdinput_free(); |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
686 free( dvd ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
687 } |
7029 | 688 } |
689 | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
690 void DVDInit(void) |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
691 { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
692 dvdinput_setup(); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
693 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
694 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
695 void DVDFinish(void) |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
696 { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
697 dvdinput_free(); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
698 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
699 |
7029 | 700 /** |
701 * Open an unencrypted file on a DVD image file. | |
702 */ | |
703 static dvd_file_t *DVDOpenFileUDF( dvd_reader_t *dvd, char *filename ) | |
704 { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
705 uint32_t start, len; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
706 dvd_file_t *dvd_file; |
7029 | 707 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
708 start = UDFFindFile( dvd, filename, &len ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
709 if( !start ) return 0; |
7029 | 710 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
711 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
712 if( !dvd_file ) return 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
713 dvd_file->dvd = dvd; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
714 dvd_file->lb_start = start; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
715 dvd_file->seek_pos = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
716 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
717 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
718 dvd_file->filesize = len / DVD_VIDEO_LB_LEN; |
7029 | 719 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
720 return dvd_file; |
7029 | 721 } |
722 | |
723 /** | |
724 * Searches for <file> in directory <path>, ignoring case. | |
725 * Returns 0 and full filename in <filename>. | |
726 * or -1 on file not found. | |
727 * or -2 on path not found. | |
728 */ | |
729 static int findDirFile( const char *path, const char *file, char *filename ) | |
730 { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
731 DIR *dir; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
732 struct dirent *ent; |
7029 | 733 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
734 dir = opendir( path ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
735 if( !dir ) return -2; |
7029 | 736 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
737 while( ( ent = readdir( dir ) ) != NULL ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
738 if( !strcasecmp( ent->d_name, file ) ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
739 sprintf( filename, "%s%s%s", path, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
740 ( ( path[ strlen( path ) - 1 ] == '/' ) ? "" : "/" ), |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
741 ent->d_name ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
742 closedir(dir); |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
743 return 0; |
7029 | 744 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
745 } |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
746 closedir(dir); |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
747 return -1; |
7029 | 748 } |
749 | |
750 static int findDVDFile( dvd_reader_t *dvd, const char *file, char *filename ) | |
751 { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
752 char video_path[ PATH_MAX + 1 ]; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
753 const char *nodirfile; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
754 int ret; |
7029 | 755 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
756 /* Strip off the directory for our search */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
757 if( !strncasecmp( "/VIDEO_TS/", file, 10 ) ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
758 nodirfile = &(file[ 10 ]); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
759 } else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
760 nodirfile = file; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
761 } |
7029 | 762 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
763 ret = findDirFile( dvd->path_root, nodirfile, filename ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
764 if( ret < 0 ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
765 /* Try also with adding the path, just in case. */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
766 sprintf( video_path, "%s/VIDEO_TS/", dvd->path_root ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
767 ret = findDirFile( video_path, nodirfile, filename ); |
7029 | 768 if( ret < 0 ) { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
769 /* Try with the path, but in lower case. */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
770 sprintf( video_path, "%s/video_ts/", dvd->path_root ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
771 ret = findDirFile( video_path, nodirfile, filename ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
772 if( ret < 0 ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
773 return 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
774 } |
7029 | 775 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
776 } |
7029 | 777 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
778 return 1; |
7029 | 779 } |
780 | |
781 /** | |
782 * Open an unencrypted file from a DVD directory tree. | |
783 */ | |
784 static dvd_file_t *DVDOpenFilePath( dvd_reader_t *dvd, char *filename ) | |
785 { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
786 char full_path[ PATH_MAX + 1 ]; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
787 dvd_file_t *dvd_file; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
788 struct stat fileinfo; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
789 dvd_input_t dev; |
7029 | 790 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
791 /* Get the full path of the file. */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
792 if( !findDVDFile( dvd, filename, full_path ) ) return 0; |
7029 | 793 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
794 dev = dvdinput_open( full_path ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
795 if( !dev ) return 0; |
7029 | 796 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
797 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
798 if( !dvd_file ) return 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
799 dvd_file->dvd = dvd; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
800 dvd_file->lb_start = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
801 dvd_file->seek_pos = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
802 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
803 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
804 dvd_file->filesize = 0; |
7029 | 805 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
806 if( stat( full_path, &fileinfo ) < 0 ) { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
807 if(dvd->verbose >= 1) { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
808 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename ); |
7029 | 809 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
810 free( dvd_file ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
811 return 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
812 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
813 dvd_file->title_sizes[ 0 ] = fileinfo.st_size / DVD_VIDEO_LB_LEN; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
814 dvd_file->title_devs[ 0 ] = dev; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
815 dvd_file->filesize = dvd_file->title_sizes[ 0 ]; |
7029 | 816 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
817 return dvd_file; |
7029 | 818 } |
819 | |
820 static dvd_file_t *DVDOpenVOBUDF( dvd_reader_t *dvd, int title, int menu ) | |
821 { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
822 char filename[ MAX_UDF_FILE_NAME_LEN ]; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
823 uint32_t start, len; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
824 dvd_file_t *dvd_file; |
7029 | 825 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
826 if( title == 0 ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
827 sprintf( filename, "/VIDEO_TS/VIDEO_TS.VOB" ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
828 } else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
829 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, menu ? 0 : 1 ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
830 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
831 start = UDFFindFile( dvd, filename, &len ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
832 if( start == 0 ) return 0; |
7029 | 833 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
834 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
835 if( !dvd_file ) return 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
836 dvd_file->dvd = dvd; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
837 /*Hack*/ dvd_file->css_title = title << 1 | menu; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
838 dvd_file->lb_start = start; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
839 dvd_file->seek_pos = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
840 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
841 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
842 dvd_file->filesize = len / DVD_VIDEO_LB_LEN; |
7029 | 843 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
844 /* Calculate the complete file size for every file in the VOBS */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
845 if( !menu ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
846 int cur; |
7029 | 847 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
848 for( cur = 2; cur < 10; cur++ ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
849 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, cur ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
850 if( !UDFFindFile( dvd, filename, &len ) ) break; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
851 dvd_file->filesize += len / DVD_VIDEO_LB_LEN; |
7029 | 852 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
853 } |
7029 | 854 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
855 if( dvd->css_state == 1 /* Need key init */ ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
856 // initAllCSSKeys( dvd ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
857 // dvd->css_state = 2; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
858 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
859 /* |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
860 if( dvdinput_title( dvd_file->dvd->dev, (int)start ) < 0 ) { |
7029 | 861 fprintf( stderr, "libdvdread: Error cracking CSS key for %s\n", |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
862 filename ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
863 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
864 */ |
7029 | 865 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
866 return dvd_file; |
7029 | 867 } |
868 | |
869 static dvd_file_t *DVDOpenVOBPath( dvd_reader_t *dvd, int title, int menu ) | |
870 { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
871 char filename[ MAX_UDF_FILE_NAME_LEN ]; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
872 char full_path[ PATH_MAX + 1 ]; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
873 struct stat fileinfo; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
874 dvd_file_t *dvd_file; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
875 int i; |
7029 | 876 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
877 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
878 if( !dvd_file ) return 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
879 dvd_file->dvd = dvd; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
880 /*Hack*/ dvd_file->css_title = title << 1 | menu; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
881 dvd_file->lb_start = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
882 dvd_file->seek_pos = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
883 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
884 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
885 dvd_file->filesize = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
886 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
887 if( menu ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
888 dvd_input_t dev; |
7029 | 889 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
890 if( title == 0 ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
891 sprintf( filename, "VIDEO_TS.VOB" ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
892 } else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
893 sprintf( filename, "VTS_%02i_0.VOB", title ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
894 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
895 if( !findDVDFile( dvd, filename, full_path ) ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
896 free( dvd_file ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
897 return 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
898 } |
7029 | 899 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
900 dev = dvdinput_open( full_path ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
901 if( dev == NULL ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
902 free( dvd_file ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
903 return 0; |
7029 | 904 } |
905 | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
906 if( stat( full_path, &fileinfo ) < 0 ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
907 if(dvd->verbose >= 1) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
908 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
909 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
910 free( dvd_file ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
911 return 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
912 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
913 dvd_file->title_sizes[ 0 ] = fileinfo.st_size / DVD_VIDEO_LB_LEN; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
914 dvd_file->title_devs[ 0 ] = dev; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
915 dvdinput_title( dvd_file->title_devs[0], 0); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
916 dvd_file->filesize = dvd_file->title_sizes[ 0 ]; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
917 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
918 } else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
919 for( i = 0; i < 9; ++i ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
920 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
921 sprintf( filename, "VTS_%02i_%i.VOB", title, i + 1 ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
922 if( !findDVDFile( dvd, filename, full_path ) ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
923 break; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
924 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
925 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
926 if( stat( full_path, &fileinfo ) < 0 ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
927 if(dvd->verbose >= 1) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
928 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
929 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
930 break; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
931 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
932 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
933 dvd_file->title_sizes[ i ] = fileinfo.st_size / DVD_VIDEO_LB_LEN; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
934 dvd_file->title_devs[ i ] = dvdinput_open( full_path ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
935 dvdinput_title( dvd_file->title_devs[ i ], 0 ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
936 dvd_file->filesize += dvd_file->title_sizes[ i ]; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
937 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
938 if( !dvd_file->title_devs[ 0 ] ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
939 free( dvd_file ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
940 return 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
941 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
942 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
943 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
944 return dvd_file; |
7029 | 945 } |
946 | |
947 dvd_file_t *DVDOpenFile( dvd_reader_t *dvd, int titlenum, | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
948 dvd_read_domain_t domain ) |
7029 | 949 { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
950 char filename[ MAX_UDF_FILE_NAME_LEN ]; |
15874 | 951 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
952 /* Check arguments. */ |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
953 if( dvd == NULL || titlenum < 0 ) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
954 errno = EINVAL; |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
955 return NULL; |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
956 } |
7029 | 957 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
958 switch( domain ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
959 case DVD_READ_INFO_FILE: |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
960 if( titlenum == 0 ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
961 sprintf( filename, "/VIDEO_TS/VIDEO_TS.IFO" ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
962 } else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
963 sprintf( filename, "/VIDEO_TS/VTS_%02i_0.IFO", titlenum ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
964 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
965 break; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
966 case DVD_READ_INFO_BACKUP_FILE: |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
967 if( titlenum == 0 ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
968 sprintf( filename, "/VIDEO_TS/VIDEO_TS.BUP" ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
969 } else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
970 sprintf( filename, "/VIDEO_TS/VTS_%02i_0.BUP", titlenum ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
971 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
972 break; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
973 case DVD_READ_MENU_VOBS: |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
974 if( dvd->isImageFile ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
975 return DVDOpenVOBUDF( dvd, titlenum, 1 ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
976 } else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
977 return DVDOpenVOBPath( dvd, titlenum, 1 ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
978 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
979 break; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
980 case DVD_READ_TITLE_VOBS: |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
981 if( titlenum == 0 ) return 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
982 if( dvd->isImageFile ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
983 return DVDOpenVOBUDF( dvd, titlenum, 0 ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
984 } else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
985 return DVDOpenVOBPath( dvd, titlenum, 0 ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
986 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
987 break; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
988 default: |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
989 if(dvd->verbose >= 1) { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
990 fprintf( stderr, "libdvdread: Invalid domain for file open.\n" ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
991 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
992 errno = EINVAL; |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
993 return NULL; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
994 } |
7029 | 995 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
996 if( dvd->isImageFile ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
997 return DVDOpenFileUDF( dvd, filename ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
998 } else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
999 return DVDOpenFilePath( dvd, filename ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1000 } |
7029 | 1001 } |
1002 | |
1003 void DVDCloseFile( dvd_file_t *dvd_file ) | |
1004 { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1005 int i; |
7029 | 1006 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1007 if( dvd_file ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1008 if( dvd_file->dvd->isImageFile ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1009 ; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1010 } else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1011 for( i = 0; i < 9; ++i ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1012 if( dvd_file->title_devs[ i ] ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1013 dvdinput_close( dvd_file->title_devs[i] ); |
7029 | 1014 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1015 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1016 } |
7029 | 1017 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1018 free( dvd_file ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1019 dvd_file = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1020 } |
7029 | 1021 } |
1022 | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1023 /** |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1024 * Internal, but used from dvd_udf.c |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1025 * |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1026 * @param device A read handle. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1027 * @param lb_number Logical block number to start read from. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1028 * @param block_count Number of logical blocks to read. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1029 * @param data Pointer to buffer where read data should be stored. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1030 * This buffer must be large enough to hold lb_number*2048 bytes. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1031 * The pointer must be aligned to the logical block size when |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1032 * reading from a raw/O_DIRECT device. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1033 * @param encrypted 0 if no decryption shall be performed, |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1034 * 1 if decryption shall be performed |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1035 * @param return Returns number of blocks read on success, negative on error |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1036 */ |
15874 | 1037 int UDFReadBlocksRaw( dvd_reader_t *device, uint32_t lb_number, |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1038 size_t block_count, unsigned char *data, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1039 int encrypted ) |
7029 | 1040 { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1041 int ret; |
7029 | 1042 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1043 if( !device->dev ) { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1044 if(device->verbose >= 1) { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1045 fprintf( stderr, "libdvdread: Fatal error in block read.\n" ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1046 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1047 return 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1048 } |
7029 | 1049 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1050 ret = dvdinput_seek( device->dev, (int) lb_number ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1051 if( ret != (int) lb_number ) { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1052 if(device->verbose >= 1) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1053 fprintf( stderr, |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1054 "libdvdread: UDFReadBlocksRaw: Can't seek to block %u\n", |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1055 lb_number ); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1056 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1057 return 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1058 } |
7029 | 1059 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1060 return dvdinput_read( device->dev, (char *) data, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1061 (int) block_count, encrypted ); |
7029 | 1062 } |
1063 | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1064 /** |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1065 * This is using a single input and starting from 'dvd_file->lb_start' offset. |
7029 | 1066 * |
1067 * Reads 'block_count' blocks from 'dvd_file' at block offset 'offset' | |
1068 * into the buffer located at 'data' and if 'encrypted' is set | |
1069 * descramble the data if it's encrypted. Returning either an | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1070 * negative error or the number of blocks read. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1071 * |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1072 * @param data Pointer to buffer where read data should be placed. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1073 * This buffer must be large enough to hold block_count*2048 bytes. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1074 * The pointer must be aligned to 2048 bytes when reading from |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1075 * a raw/O_DIRECT device. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1076 * @return Returns the number of blocks read on success or a negative error. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1077 */ |
7029 | 1078 static int DVDReadBlocksUDF( dvd_file_t *dvd_file, uint32_t offset, |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1079 size_t block_count, unsigned char *data, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1080 int encrypted ) |
7029 | 1081 { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1082 return UDFReadBlocksRaw( dvd_file->dvd, dvd_file->lb_start + offset, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1083 block_count, data, encrypted ); |
7029 | 1084 } |
1085 | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1086 /** |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1087 * This is using possibly several inputs and starting from an offset of '0'. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1088 * data must be aligned to logical block size (2048 bytes) of the device |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1089 * for raw/O_DIRECT devices to work |
7029 | 1090 * Reads 'block_count' blocks from 'dvd_file' at block offset 'offset' |
1091 * into the buffer located at 'data' and if 'encrypted' is set | |
1092 * descramble the data if it's encrypted. Returning either an | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1093 * negative error or the number of blocks read. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1094 * |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1095 * @param dvd_file A file read handle. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1096 * @param offset Block offset from start of file. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1097 * @return Returns number of blocks read on success, negative on error. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1098 */ |
7029 | 1099 static int DVDReadBlocksPath( dvd_file_t *dvd_file, unsigned int offset, |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1100 size_t block_count, unsigned char *data, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1101 int encrypted ) |
7029 | 1102 { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1103 int i; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1104 int ret, ret2, off; |
7029 | 1105 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1106 ret = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1107 ret2 = 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1108 for( i = 0; i < 9; ++i ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1109 if( !dvd_file->title_sizes[ i ] ) return 0; /* Past end of file */ |
7029 | 1110 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1111 if( offset < dvd_file->title_sizes[ i ] ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1112 if( ( offset + block_count ) <= dvd_file->title_sizes[ i ] ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1113 off = dvdinput_seek( dvd_file->title_devs[ i ], (int)offset ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1114 if( off < 0 || off != (int)offset ) { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1115 if(dvd_file->dvd->verbose >= 1) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1116 fprintf( stderr, "libdvdread: DVDReadBlocksPath1: Can't seek to block %d\n", |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1117 offset ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1118 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1119 return off < 0 ? off : 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1120 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1121 ret = dvdinput_read( dvd_file->title_devs[ i ], data, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1122 (int)block_count, encrypted ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1123 break; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1124 } else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1125 size_t part1_size = dvd_file->title_sizes[ i ] - offset; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1126 /* FIXME: Really needs to be a while loop. |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1127 * (This is only true if you try and read >1GB at a time) */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1128 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1129 /* Read part 1 */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1130 off = dvdinput_seek( dvd_file->title_devs[ i ], (int)offset ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1131 if( off < 0 || off != (int)offset ) { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1132 if(dvd_file->dvd->verbose >= 1) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1133 fprintf( stderr, "libdvdread: DVDReadBlocksPath2: Can't seek to block %d\n", |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1134 offset ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1135 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1136 return off < 0 ? off : 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1137 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1138 ret = dvdinput_read( dvd_file->title_devs[ i ], data, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1139 (int)part1_size, encrypted ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1140 if( ret < 0 ) return ret; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1141 /* FIXME: This is wrong if i is the last file in the set. |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1142 * also error from this read will not show in ret. */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1143 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1144 /* Does the next part exist? If not then return now. */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1145 if( !dvd_file->title_devs[ i + 1 ] ) return ret; |
7358
bb40478265df
I experienced several segfaults when trying to play (unencrypted) DVDs
arpi
parents:
7033
diff
changeset
|
1146 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1147 /* Read part 2 */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1148 off = dvdinput_seek( dvd_file->title_devs[ i + 1 ], 0 ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1149 if( off < 0 || off != 0 ) { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1150 if(dvd_file->dvd->verbose >= 1) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1151 fprintf( stderr, "libdvdread: DVDReadBlocksPath3: Can't seek to block %d\n", 0 ); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1152 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1153 return off < 0 ? off : 0; |
7029 | 1154 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1155 ret2 = dvdinput_read( dvd_file->title_devs[ i + 1 ], |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1156 data + ( part1_size |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1157 * (int64_t)DVD_VIDEO_LB_LEN ), |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1158 (int)(block_count - part1_size), |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1159 encrypted ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1160 if( ret2 < 0 ) return ret2; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1161 break; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1162 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1163 } else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1164 offset -= dvd_file->title_sizes[ i ]; |
7029 | 1165 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1166 } |
7029 | 1167 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1168 return ret + ret2; |
7029 | 1169 } |
1170 | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1171 /** |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1172 * This is broken reading more than 2Gb at a time if ssize_t is 32-bit. |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1173 */ |
7029 | 1174 ssize_t DVDReadBlocks( dvd_file_t *dvd_file, int offset, |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1175 size_t block_count, unsigned char *data ) |
7029 | 1176 { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1177 int ret; |
7029 | 1178 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1179 /* Check arguments. */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1180 if( dvd_file == NULL || offset < 0 || data == NULL ) |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1181 return -1; |
15874 | 1182 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1183 /* Hack, and it will still fail for multiple opens in a threaded app ! */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1184 if( dvd_file->dvd->css_title != dvd_file->css_title ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1185 dvd_file->dvd->css_title = dvd_file->css_title; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1186 if( dvd_file->dvd->isImageFile ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1187 dvdinput_title( dvd_file->dvd->dev, (int)dvd_file->lb_start ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1188 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1189 /* Here each vobu has it's own dvdcss handle, so no need to update |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1190 else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1191 dvdinput_title( dvd_file->title_devs[ 0 ], (int)dvd_file->lb_start ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1192 }*/ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1193 } |
7029 | 1194 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1195 if( dvd_file->dvd->isImageFile ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1196 ret = DVDReadBlocksUDF( dvd_file, (uint32_t)offset, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1197 block_count, data, DVDINPUT_READ_DECRYPT ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1198 } else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1199 ret = DVDReadBlocksPath( dvd_file, (unsigned int)offset, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1200 block_count, data, DVDINPUT_READ_DECRYPT ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1201 } |
7029 | 1202 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1203 return (ssize_t)ret; |
7029 | 1204 } |
1205 | |
10017
535a53c058f8
There are conflicting definitions for DVDFileSeek in the .c and .h file.
diego
parents:
9333
diff
changeset
|
1206 int DVDFileSeek( dvd_file_t *dvd_file, int offset ) |
7029 | 1207 { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1208 /* Check arguments. */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1209 if( dvd_file == NULL || offset < 0 ) |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1210 return -1; |
15874 | 1211 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1212 if( offset > dvd_file->filesize * DVD_VIDEO_LB_LEN ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1213 return -1; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1214 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1215 dvd_file->seek_pos = (uint32_t) offset; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1216 return offset; |
7029 | 1217 } |
1218 | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1219 #ifndef HAVE_UINTPTR_T |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1220 #warning "Assuming that (unsigned long) can hold (void *)" |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1221 typedef unsigned long uintptr_t; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1222 #endif |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1223 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1224 #define DVD_ALIGN(ptr) (void *)((((uintptr_t)(ptr)) + (DVD_VIDEO_LB_LEN-1)) \ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1225 / DVD_VIDEO_LB_LEN * DVD_VIDEO_LB_LEN) |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1226 |
7029 | 1227 ssize_t DVDReadBytes( dvd_file_t *dvd_file, void *data, size_t byte_size ) |
1228 { | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1229 unsigned char *secbuf_start; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1230 unsigned char *secbuf; //must be aligned to 2048-bytes for raw/O_DIRECT |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1231 unsigned int numsec, seek_sector, seek_byte; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1232 int ret; |
7029 | 1233 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1234 /* Check arguments. */ |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1235 if( dvd_file == NULL || data == NULL ) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1236 errno = EINVAL; |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1237 return -1; |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1238 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1239 seek_sector = dvd_file->seek_pos / DVD_VIDEO_LB_LEN; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1240 seek_byte = dvd_file->seek_pos % DVD_VIDEO_LB_LEN; |
7029 | 1241 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1242 numsec = ( ( seek_byte + byte_size ) / DVD_VIDEO_LB_LEN ) + |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1243 ( ( ( seek_byte + byte_size ) % DVD_VIDEO_LB_LEN ) ? 1 : 0 ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1244 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1245 /* must align to 2048 bytes if we are reading from raw/O_DIRECT */ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1246 secbuf_start = (unsigned char *) malloc( (numsec+1) * DVD_VIDEO_LB_LEN ); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1247 if( !secbuf_start ) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1248 /* errno will be set to ENOMEM by malloc */ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1249 return -1; |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1250 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1251 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1252 secbuf = DVD_ALIGN(secbuf_start); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1253 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1254 if( dvd_file->dvd->isImageFile ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1255 ret = DVDReadBlocksUDF( dvd_file, (uint32_t) seek_sector, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1256 (size_t) numsec, secbuf, DVDINPUT_NOFLAGS ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1257 } else { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1258 ret = DVDReadBlocksPath( dvd_file, seek_sector, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1259 (size_t) numsec, secbuf, DVDINPUT_NOFLAGS ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1260 } |
7029 | 1261 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1262 if( ret != (int) numsec ) { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1263 free( secbuf_start ); |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1264 return ret < 0 ? ret : 0; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1265 } |
7029 | 1266 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1267 memcpy( data, &(secbuf[ seek_byte ]), byte_size ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1268 free( secbuf_start ); |
7029 | 1269 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1270 dvd_file->seek_pos += byte_size; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1271 return byte_size; |
7029 | 1272 } |
1273 | |
1274 ssize_t DVDFileSize( dvd_file_t *dvd_file ) | |
1275 { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1276 /* Check arguments. */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1277 if( dvd_file == NULL ) |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1278 return -1; |
15874 | 1279 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1280 return dvd_file->filesize; |
7029 | 1281 } |
15874 | 1282 |
1283 int DVDDiscID( dvd_reader_t *dvd, unsigned char *discid ) | |
1284 { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1285 struct md5_ctx ctx; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1286 int title; |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1287 int nr_of_files = 0; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1288 int tmp_errno; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1289 int nofiles_errno = ENOENT; |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1290 /* Check arguments. */ |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1291 if( dvd == NULL || discid == NULL ) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1292 errno = EINVAL; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1293 return -1; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1294 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1295 /* Go through the first 10 IFO:s, in order, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1296 * and md5sum them, i.e VIDEO_TS.IFO and VTS_0?_0.IFO */ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1297 md5_init_ctx( &ctx ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1298 for( title = 0; title < 10; title++ ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1299 dvd_file_t *dvd_file = DVDOpenFile( dvd, title, DVD_READ_INFO_FILE ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1300 if( dvd_file != NULL ) { |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1301 ssize_t bytes_read; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1302 size_t file_size = dvd_file->filesize * DVD_VIDEO_LB_LEN; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1303 char *buffer = malloc( file_size ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1304 |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1305 nr_of_files++; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1306 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1307 if( buffer == NULL ) { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1308 /* errno will be set to ENOMEM by malloc */ |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1309 return -1; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1310 } |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1311 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1312 bytes_read = DVDReadBytes( dvd_file, buffer, file_size ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1313 if( bytes_read != file_size ) { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1314 tmp_errno = errno; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1315 if(dvd->verbose >= 1) { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1316 fprintf( stderr, "libdvdread: DVDDiscId read returned %d bytes" |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1317 ", wanted %d\n", (int)bytes_read, (int)file_size ); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1318 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1319 free(buffer); |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1320 DVDCloseFile( dvd_file ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1321 errno = tmp_errno; |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1322 return -1; |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1323 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1324 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1325 md5_process_bytes( buffer, file_size, &ctx ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1326 |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1327 DVDCloseFile( dvd_file ); |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1328 free( buffer ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1329 } else { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1330 if(errno != ENOENT) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1331 nofiles_errno = errno; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1332 } |
15874 | 1333 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1334 } |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1335 md5_finish_ctx( &ctx, discid ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1336 if(nr_of_files == 0) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1337 errno = nofiles_errno; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1338 return -1; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1339 } |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1340 return 0; |
15874 | 1341 } |
1342 | |
1343 | |
1344 int DVDISOVolumeInfo( dvd_reader_t *dvd, | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1345 char *volid, unsigned int volid_size, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1346 unsigned char *volsetid, unsigned int volsetid_size ) |
15874 | 1347 { |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1348 unsigned char *buffer; /* must be aligned to 2048 for raw/O_DIRECT */ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1349 unsigned char *buffer_start; |
15874 | 1350 int ret; |
1351 | |
1352 /* Check arguments. */ | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1353 if( dvd == NULL ) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1354 errno = EINVAL; |
15874 | 1355 return -1; |
1356 } | |
1357 | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1358 if( dvd->dev == NULL ) { |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1359 /* No block access, so no ISO... */ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1360 errno = EINVAL; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1361 return -1; |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1362 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1363 |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1364 buffer_start = malloc( 2 * DVD_VIDEO_LB_LEN ); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1365 if( buffer_start == NULL ) { |
15874 | 1366 return -1; |
1367 } | |
1368 | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1369 buffer = DVD_ALIGN(buffer_start); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1370 |
15874 | 1371 ret = UDFReadBlocksRaw( dvd, 16, 1, buffer, 0 ); |
1372 if( ret != 1 ) { | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1373 if(dvd->verbose >= 1) { |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1374 fprintf( stderr, "libdvdread: DVDISOVolumeInfo, failed to " |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1375 "read ISO9660 Primary Volume Descriptor!\n" ); |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1376 } |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1377 free(buffer_start); |
15874 | 1378 return -1; |
1379 } | |
1380 | |
1381 if( (volid != NULL) && (volid_size > 0) ) { | |
1382 unsigned int n; | |
1383 for(n = 0; n < 32; n++) { | |
1384 if(buffer[40+n] == 0x20) { | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1385 break; |
15874 | 1386 } |
1387 } | |
1388 | |
1389 if(volid_size > n+1) { | |
1390 volid_size = n+1; | |
1391 } | |
1392 | |
1393 memcpy(volid, &buffer[40], volid_size-1); | |
1394 volid[volid_size-1] = '\0'; | |
1395 } | |
1396 | |
1397 if( (volsetid != NULL) && (volsetid_size > 0) ) { | |
1398 if(volsetid_size > 128) { | |
1399 volsetid_size = 128; | |
1400 } | |
1401 memcpy(volsetid, &buffer[190], volsetid_size); | |
1402 } | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1403 free(buffer_start); |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
20981
diff
changeset
|
1404 |
15874 | 1405 return 0; |
1406 } | |
1407 | |
1408 | |
1409 int DVDUDFVolumeInfo( dvd_reader_t *dvd, | |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1410 char *volid, unsigned int volid_size, |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
1411 unsigned char *volsetid, unsigned int volsetid_size ) |
15874 | 1412 { |
1413 int ret; | |
1414 /* Check arguments. */ | |
1415 if( dvd == NULL ) | |
1416 return -1; | |
1417 | |
1418 if( dvd->dev == NULL ) { | |
1419 /* No block access, so no UDF VolumeSet Identifier */ | |
1420 return -1; | |
1421 } | |
1422 | |
1423 if( (volid != NULL) && (volid_size > 0) ) { | |
1424 ret = UDFGetVolumeIdentifier(dvd, volid, volid_size); | |
1425 if(!ret) { | |
1426 return -1; | |
1427 } | |
1428 } | |
1429 if( (volsetid != NULL) && (volsetid_size > 0) ) { | |
1430 ret = UDFGetVolumeSetIdentifier(dvd, volsetid, volsetid_size); | |
1431 if(!ret) { | |
1432 return -1; | |
1433 } | |
1434 } | |
1435 | |
1436 return 0; | |
1437 } |