annotate dvd_reader.c @ 42:3aa39a1cff0f src

Remove empty if clause. An if clause is empty. This makes the else do all of the work and still ends up w/ a larger object file because the if clause is stuck into the object file. By moving to the logical not of the if we can remove the empty clause.
author erik
date Wed, 02 Sep 2009 01:34:23 +0000
parents ef679522d00f
children 92b4694792da
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1 /*
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
2 * Copyright (C) 2001-2004 Billy Biggs <vektor@dumbterm.net>,
22
447c5319a522 Convert all ISO8859-1 sequences to proper UTF-8.
diego
parents: 21
diff changeset
3 * Håkan Hjort <d95hjort@dtek.chalmers.se>,
447c5319a522 Convert all ISO8859-1 sequences to proper UTF-8.
diego
parents: 21
diff changeset
4 * Björn Englund <d4bjorn@dtek.chalmers.se>
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
5 *
21
4aa618ae094f Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents: 20
diff changeset
6 * This file is part of libdvdread.
4aa618ae094f Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents: 20
diff changeset
7 *
4aa618ae094f Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents: 20
diff changeset
8 * libdvdread is free software; you can redistribute it and/or modify
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
21
4aa618ae094f Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents: 20
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
4aa618ae094f Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents: 20
diff changeset
11 * (at your option) any later version.
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
12 *
21
4aa618ae094f Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents: 20
diff changeset
13 * libdvdread is distributed in the hope that it will be useful,
4aa618ae094f Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents: 20
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4aa618ae094f Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents: 20
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4aa618ae094f Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents: 20
diff changeset
16 * GNU General Public License for more details.
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
17 *
21
4aa618ae094f Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents: 20
diff changeset
18 * You should have received a copy of the GNU General Public License along
4aa618ae094f Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents: 20
diff changeset
19 * with libdvdread; if not, write to the Free Software Foundation, Inc.,
4aa618ae094f Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents: 20
diff changeset
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
21 */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
22
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
23 #include <sys/types.h>
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
24 #include <sys/stat.h>
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
25 #include <sys/time.h> /* For the timing of dvdcss_title crack. */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
26 #include <fcntl.h>
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
27 #include <stdlib.h>
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
28 #include <stdio.h>
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
29 #include <errno.h>
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
30 #include <string.h>
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
31 #include <unistd.h>
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
32 #include <limits.h>
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
33 #include <dirent.h>
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
34
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
35 /* misc win32 helpers */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
36 #ifdef WIN32
6
e5663591d13c gettimeofday() doesn't exist in windows, but recent mingw32 runtime
nicodvb
parents: 3
diff changeset
37 #ifndef HAVE_GETTIMEOFDAY
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
38 /* replacement gettimeofday implementation */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
39 #include <sys/timeb.h>
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
40 static inline int _private_gettimeofday( struct timeval *tv, void *tz )
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
41 {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
42 struct timeb t;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
43 ftime( &t );
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
44 tv->tv_sec = t.time;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
45 tv->tv_usec = t.millitm * 1000;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
46 return 0;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
47 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
48 #define gettimeofday(TV, TZ) _private_gettimeofday((TV), (TZ))
6
e5663591d13c gettimeofday() doesn't exist in windows, but recent mingw32 runtime
nicodvb
parents: 3
diff changeset
49 #endif
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
50 #include <io.h> /* read() */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
51 #define lseek64 _lseeki64
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
52 #endif
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
53
36
79c9b639bf9d Use __APPLE__ instead of __DARWIN__ in preprocessor check.
diego
parents: 35
diff changeset
54 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__bsdi__) || defined(__APPLE__)
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
55 #define SYS_BSD 1
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
56 #endif
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
57
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
58 #if defined(__sun)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
59 #include <sys/mnttab.h>
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
60 #elif defined(SYS_BSD)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
61 #include <fstab.h>
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
62 #elif defined(__linux__)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
63 #include <mntent.h>
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
64 #endif
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
65
33
c743d79f187b Move installed headers into dvdread directory to make them easier to
reimar
parents: 30
diff changeset
66 #include "dvdread/dvd_udf.h"
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
67 #include "dvd_input.h"
33
c743d79f187b Move installed headers into dvdread directory to make them easier to
reimar
parents: 30
diff changeset
68 #include "dvdread/dvd_reader.h"
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
69 #include "md5.h"
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
70
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
71 #define DEFAULT_UDF_CACHE_LEVEL 1
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
72
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
73 struct dvd_reader_s {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
74 /* Basic information. */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
75 int isImageFile;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
76
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
77 /* Hack for keeping track of the css status.
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
78 * 0: no css, 1: perhaps (need init of keys), 2: have done init */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
79 int css_state;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
80 int css_title; /* Last title that we have called dvdinpute_title for. */
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
81
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
82 /* Information required for an image file. */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
83 dvd_input_t dev;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
84
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
85 /* Information required for a directory path drive. */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
86 char *path_root;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
87
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
88 /* Filesystem cache */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
89 int udfcache_level; /* 0 - turned off, 1 - on */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
90 void *udfcache;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
91 };
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
92
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
93 #define TITLES_MAX 9
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
94
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
95 struct dvd_file_s {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
96 /* Basic information. */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
97 dvd_reader_t *dvd;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
98
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
99 /* Hack for selecting the right css title. */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
100 int css_title;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
101
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
102 /* Information required for an image file. */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
103 uint32_t lb_start;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
104 uint32_t seek_pos;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
105
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
106 /* Information required for a directory path drive. */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
107 size_t title_sizes[ TITLES_MAX ];
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
108 dvd_input_t title_devs[ TITLES_MAX ];
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
109
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
110 /* Calculated at open-time, size in blocks. */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
111 ssize_t filesize;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
112 };
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
113
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
114 int UDFReadBlocksRaw( dvd_reader_t *device, uint32_t lb_number,
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
115 size_t block_count, unsigned char *data,
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
116 int encrypted );
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
117
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
118 /**
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
119 * Set the level of caching on udf
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
120 * level = 0 (no caching)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
121 * level = 1 (caching filesystem info)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
122 */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
123 int DVDUDFCacheLevel(dvd_reader_t *device, int level)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
124 {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
125 struct dvd_reader_s *dev = (struct dvd_reader_s *)device;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
126
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
127 if(level > 0) {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
128 level = 1;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
129 } else if(level < 0) {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
130 return dev->udfcache_level;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
131 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
132
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
133 dev->udfcache_level = level;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
134
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
135 return level;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
136 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
137
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
138 void *GetUDFCacheHandle(dvd_reader_t *device)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
139 {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
140 struct dvd_reader_s *dev = (struct dvd_reader_s *)device;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
141
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
142 return dev->udfcache;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
143 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
144
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
145 void SetUDFCacheHandle(dvd_reader_t *device, void *cache)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
146 {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
147 struct dvd_reader_s *dev = (struct dvd_reader_s *)device;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
148
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
149 dev->udfcache = cache;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
150 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
151
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
152
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
153
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
154 /* Loop over all titles and call dvdcss_title to crack the keys. */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
155 static int initAllCSSKeys( dvd_reader_t *dvd )
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
156 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
157 struct timeval all_s, all_e;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
158 struct timeval t_s, t_e;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
159 char filename[ MAX_UDF_FILE_NAME_LEN ];
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
160 uint32_t start, len;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
161 int title;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
162
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
163 char *nokeys_str = getenv("DVDREAD_NOKEYS");
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
164 if(nokeys_str != NULL)
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
165 return 0;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
166
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
167 fprintf( stderr, "\n" );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
168 fprintf( stderr, "libdvdread: Attempting to retrieve all CSS keys\n" );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
169 fprintf( stderr, "libdvdread: This can take a _long_ time, "
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
170 "please be patient\n\n" );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
171 gettimeofday(&all_s, NULL);
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
172
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
173 for( title = 0; title < 100; title++ ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
174 gettimeofday( &t_s, NULL );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
175 if( title == 0 ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
176 sprintf( filename, "/VIDEO_TS/VIDEO_TS.VOB" );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
177 } else {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
178 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, 0 );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
179 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
180 start = UDFFindFile( dvd, filename, &len );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
181 if( start != 0 && len != 0 ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
182 /* Perform CSS key cracking for this title. */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
183 fprintf( stderr, "libdvdread: Get key for %s at 0x%08x\n",
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
184 filename, start );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
185 if( dvdinput_title( dvd->dev, (int)start ) < 0 ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
186 fprintf( stderr, "libdvdread: Error cracking CSS key for %s (0x%08x)\n", filename, start);
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
187 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
188 gettimeofday( &t_e, NULL );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
189 fprintf( stderr, "libdvdread: Elapsed time %ld\n",
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
190 (long int) t_e.tv_sec - t_s.tv_sec );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
191 }
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
192
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
193 if( title == 0 ) continue;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
194
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
195 gettimeofday( &t_s, NULL );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
196 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, 1 );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
197 start = UDFFindFile( dvd, filename, &len );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
198 if( start == 0 || len == 0 ) break;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
199
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
200 /* Perform CSS key cracking for this title. */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
201 fprintf( stderr, "libdvdread: Get key for %s at 0x%08x\n",
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
202 filename, start );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
203 if( dvdinput_title( dvd->dev, (int)start ) < 0 ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
204 fprintf( stderr, "libdvdread: Error cracking CSS key for %s (0x%08x)!!\n", filename, start);
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
205 }
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
206 gettimeofday( &t_e, NULL );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
207 fprintf( stderr, "libdvdread: Elapsed time %ld\n",
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
208 (long int) t_e.tv_sec - t_s.tv_sec );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
209 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
210 title--;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
211
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
212 fprintf( stderr, "libdvdread: Found %d VTS's\n", title );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
213 gettimeofday(&all_e, NULL);
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
214 fprintf( stderr, "libdvdread: Elapsed time %ld\n",
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
215 (long int) all_e.tv_sec - all_s.tv_sec );
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
216
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
217 return 0;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
218 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
219
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
220
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
221
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
222 /**
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
223 * Open a DVD image or block device file.
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
224 */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
225 static dvd_reader_t *DVDOpenImageFile( const char *location, int have_css )
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
226 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
227 dvd_reader_t *dvd;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
228 dvd_input_t dev;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
229
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
230 dev = dvdinput_open( location );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
231 if( !dev ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
232 fprintf( stderr, "libdvdread: Can't open %s for reading\n", location );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
233 return NULL;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
234 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
235
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
236 dvd = (dvd_reader_t *) malloc( sizeof( dvd_reader_t ) );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
237 if( !dvd ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
238 dvdinput_close(dev);
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
239 return NULL;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
240 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
241 dvd->isImageFile = 1;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
242 dvd->dev = dev;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
243 dvd->path_root = NULL;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
244
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
245 dvd->udfcache_level = DEFAULT_UDF_CACHE_LEVEL;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
246 dvd->udfcache = NULL;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
247
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
248 if( have_css ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
249 /* Only if DVDCSS_METHOD = title, a bit if it's disc or if
35
7b3c6a7220c3 spelling fixes by Erik Hovland
nicodvb
parents: 33
diff changeset
250 * DVDCSS_METHOD = key but region mismatch. Unfortunately we
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
251 * don't have that information. */
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
252
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
253 dvd->css_state = 1; /* Need key init. */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
254 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
255 dvd->css_title = 0;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
256
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
257 return dvd;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
258 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
259
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
260 static dvd_reader_t *DVDOpenPath( const char *path_root )
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
261 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
262 dvd_reader_t *dvd;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
263
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
264 dvd = (dvd_reader_t *) malloc( sizeof( dvd_reader_t ) );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
265 if( !dvd ) return NULL;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
266 dvd->isImageFile = 0;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
267 dvd->dev = 0;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
268 dvd->path_root = strdup( path_root );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
269 if(!dvd->path_root) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
270 free(dvd);
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
271 return 0;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
272 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
273 dvd->udfcache_level = DEFAULT_UDF_CACHE_LEVEL;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
274 dvd->udfcache = NULL;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
275
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
276 dvd->css_state = 0; /* Only used in the UDF path */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
277 dvd->css_title = 0; /* Only matters in the UDF path */
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
278
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
279 return dvd;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
280 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
281
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
282 #if defined(__sun)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
283 /* /dev/rdsk/c0t6d0s0 (link to /devices/...)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
284 /vol/dev/rdsk/c0t6d0/??
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
285 /vol/rdsk/<name> */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
286 static char *sun_block2char( const char *path )
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
287 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
288 char *new_path;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
289
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
290 /* Must contain "/dsk/" */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
291 if( !strstr( path, "/dsk/" ) ) return (char *) strdup( path );
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
292
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
293 /* Replace "/dsk/" with "/rdsk/" */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
294 new_path = malloc( strlen(path) + 2 );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
295 strcpy( new_path, path );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
296 strcpy( strstr( new_path, "/dsk/" ), "" );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
297 strcat( new_path, "/rdsk/" );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
298 strcat( new_path, strstr( path, "/dsk/" ) + strlen( "/dsk/" ) );
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
299
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
300 return new_path;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
301 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
302 #endif
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
303
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
304 #if defined(SYS_BSD)
35
7b3c6a7220c3 spelling fixes by Erik Hovland
nicodvb
parents: 33
diff changeset
305 /* FreeBSD /dev/(r)(a)cd0c (a is for atapi), recommended to _not_ use r
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
306 OpenBSD /dev/rcd0c, it needs to be the raw device
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
307 NetBSD /dev/rcd0[d|c|..] d for x86, c (for non x86), perhaps others
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
308 Darwin /dev/rdisk0, it needs to be the raw device
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
309 BSD/OS /dev/sr0c (if not mounted) or /dev/rsr0c ('c' any letter will do) */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
310 static char *bsd_block2char( const char *path )
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
311 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
312 char *new_path;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
313
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
314 /* If it doesn't start with "/dev/" or does start with "/dev/r" exit */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
315 if( !strncmp( path, "/dev/", 5 ) || strncmp( path, "/dev/r", 6 ) )
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
316 return (char *) strdup( path );
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
317
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
318 /* Replace "/dev/" with "/dev/r" */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
319 new_path = malloc( strlen(path) + 2 );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
320 strcpy( new_path, "/dev/r" );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
321 strcat( new_path, path + strlen( "/dev/" ) );
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
322
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
323 return new_path;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
324 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
325 #endif
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
326
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
327
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
328 dvd_reader_t *DVDOpen( const char *ppath )
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
329 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
330 struct stat fileinfo;
37
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
331 int ret, have_css, retval, cdir = 0;
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
332 dvd_reader_t *ret_val = NULL;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
333 char *dev_name = NULL;
37
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
334 char *path = NULL, *new_path = NULL, *path_copy = NULL;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
335
41
ef679522d00f replaced conditional checks on MSC with _WIN32 to permit MINGW to mount and decrypt images; patch by John Stebbins (stebbing jetheaddev com)
nicodvb
parents: 38
diff changeset
336 #ifdef _WIN32
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
337 int len;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
338 #endif
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
339
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
340 if( ppath == NULL )
37
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
341 goto DVDOpen_error;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
342
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
343 path = strdup(ppath);
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
344 if( path == NULL )
37
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
345 goto DVDOpen_error;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
346
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
347 /* Try to open libdvdcss or fall back to standard functions */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
348 have_css = dvdinput_setup();
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
349
41
ef679522d00f replaced conditional checks on MSC with _WIN32 to permit MINGW to mount and decrypt images; patch by John Stebbins (stebbing jetheaddev com)
nicodvb
parents: 38
diff changeset
350 #ifdef _WIN32
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
351 /* Strip off the trailing \ if it is not a drive */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
352 len = strlen(path);
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
353 if ((len > 1) &&
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
354 (path[len - 1] == '\\') &&
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
355 (path[len - 2] != ':'))
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
356 {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
357 path[len-1] = '\0';
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
358 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
359 #endif
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
360
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
361 ret = stat( path, &fileinfo );
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
362
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
363 if( ret < 0 ) {
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
364
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
365 /* maybe "host:port" url? try opening it with acCeSS library */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
366 if( strchr(path,':') ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
367 ret_val = DVDOpenImageFile( path, have_css );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
368 free(path);
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
369 return ret_val;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
370 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
371
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
372 /* If we can't stat the file, give up */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
373 fprintf( stderr, "libdvdread: Can't stat %s\n", path );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
374 perror("");
37
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
375 goto DVDOpen_error;
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
376 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
377
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
378 /* First check if this is a block/char device or a file*/
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
379 if( S_ISBLK( fileinfo.st_mode ) ||
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
380 S_ISCHR( fileinfo.st_mode ) ||
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
381 S_ISREG( fileinfo.st_mode ) ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
382
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
383 /**
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
384 * Block devices and regular files are assumed to be DVD-Video images.
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
385 */
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
386 #if defined(__sun)
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
387 ret_val = DVDOpenImageFile( sun_block2char( path ), have_css );
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
388 #elif defined(SYS_BSD)
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
389 ret_val = DVDOpenImageFile( bsd_block2char( path ), have_css );
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
390 #else
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
391 ret_val = DVDOpenImageFile( path, have_css );
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
392 #endif
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
393
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
394 free(path);
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
395 return ret_val;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
396
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
397 } else if( S_ISDIR( fileinfo.st_mode ) ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
398 dvd_reader_t *auth_drive = 0;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
399 #if defined(SYS_BSD)
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
400 struct fstab* fe;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
401 #elif defined(__sun) || defined(__linux__)
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
402 FILE *mntfile;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
403 #endif
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
404
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
405 /* XXX: We should scream real loud here. */
37
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
406 if( !(path_copy = strdup( path ) ) )
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
407 goto DVDOpen_error;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
408
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
409 #ifndef WIN32 /* don't have fchdir, and getcwd( NULL, ... ) is strange */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
410 /* Also WIN32 does not have symlinks, so we don't need this bit of code. */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
411
35
7b3c6a7220c3 spelling fixes by Erik Hovland
nicodvb
parents: 33
diff changeset
412 /* Resolve any symlinks and get the absolute dir name. */
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
413 {
37
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
414 if( ( cdir = open( ".", O_RDONLY ) ) >= 0 ) {
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
415 if( chdir( path_copy ) == -1 ) {
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
416 goto DVDOpen_error;
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
417 }
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
418 new_path = malloc(PATH_MAX+1);
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
419 if(!new_path) {
37
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
420 goto DVDOpen_error;
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
421 }
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
422 if( getcwd( new_path, PATH_MAX ) == NULL ) {
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
423 goto DVDOpen_error;
26
0d82d0f30c98 cosmetics: Convert all tabs to spaces.
diego
parents: 22
diff changeset
424 }
37
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
425 retval = fchdir( cdir );
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
426 close( cdir );
37
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
427 cdir = -1;
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
428 if( retval == -1 ) {
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
429 goto DVDOpen_error;
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
430 }
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
431 path_copy = new_path;
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
432 new_path = NULL;
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
433 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
434 }
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
435 #endif
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
436
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
437 /**
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
438 * If we're being asked to open a directory, check if that directory
35
7b3c6a7220c3 spelling fixes by Erik Hovland
nicodvb
parents: 33
diff changeset
439 * is the mount point for a DVD-ROM which we can use instead.
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
440 */
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
441
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
442 if( strlen( path_copy ) > 1 ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
443 if( path_copy[ strlen( path_copy ) - 1 ] == '/' ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
444 path_copy[ strlen( path_copy ) - 1 ] = '\0';
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
445 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
446 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
447
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
448 if( strlen( path_copy ) > TITLES_MAX ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
449 if( !strcasecmp( &(path_copy[ strlen( path_copy ) - TITLES_MAX ]),
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
450 "/video_ts" ) ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
451 path_copy[ strlen( path_copy ) - TITLES_MAX ] = '\0';
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
452 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
453 }
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
454
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
455 if(path_copy[0] == '\0') {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
456 path_copy[0] = '/';
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
457 path_copy[1] = '\0';
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
458 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
459
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
460 #if defined(SYS_BSD)
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
461 if( ( fe = getfsfile( path_copy ) ) ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
462 dev_name = bsd_block2char( fe->fs_spec );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
463 fprintf( stderr,
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
464 "libdvdread: Attempting to use device %s"
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
465 " mounted on %s for CSS authentication\n",
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
466 dev_name,
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
467 fe->fs_file );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
468 auth_drive = DVDOpenImageFile( dev_name, have_css );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
469 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
470 #elif defined(__sun)
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
471 mntfile = fopen( MNTTAB, "r" );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
472 if( mntfile ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
473 struct mnttab mp;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
474 int res;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
475
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
476 while( ( res = getmntent( mntfile, &mp ) ) != -1 ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
477 if( res == 0 && !strcmp( mp.mnt_mountp, path_copy ) ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
478 dev_name = sun_block2char( mp.mnt_special );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
479 fprintf( stderr,
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
480 "libdvdread: Attempting to use device %s"
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
481 " mounted on %s for CSS authentication\n",
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
482 dev_name,
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
483 mp.mnt_mountp );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
484 auth_drive = DVDOpenImageFile( dev_name, have_css );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
485 break;
26
0d82d0f30c98 cosmetics: Convert all tabs to spaces.
diego
parents: 22
diff changeset
486 }
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
487 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
488 fclose( mntfile );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
489 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
490 #elif defined(__linux__)
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
491 mntfile = fopen( MOUNTED, "r" );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
492 if( mntfile ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
493 struct mntent *me;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
494
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
495 while( ( me = getmntent( mntfile ) ) ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
496 if( !strcmp( me->mnt_dir, path_copy ) ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
497 fprintf( stderr,
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
498 "libdvdread: Attempting to use device %s"
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
499 " mounted on %s for CSS authentication\n",
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
500 me->mnt_fsname,
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
501 me->mnt_dir );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
502 auth_drive = DVDOpenImageFile( me->mnt_fsname, have_css );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
503 dev_name = strdup(me->mnt_fsname);
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
504 break;
26
0d82d0f30c98 cosmetics: Convert all tabs to spaces.
diego
parents: 22
diff changeset
505 }
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
506 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
507 fclose( mntfile );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
508 }
41
ef679522d00f replaced conditional checks on MSC with _WIN32 to permit MINGW to mount and decrypt images; patch by John Stebbins (stebbing jetheaddev com)
nicodvb
parents: 38
diff changeset
509 #elif defined(_WIN32) || defined(__OS2__)
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
510 auth_drive = DVDOpenImageFile( path, have_css );
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
511 #endif
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
512
41
ef679522d00f replaced conditional checks on MSC with _WIN32 to permit MINGW to mount and decrypt images; patch by John Stebbins (stebbing jetheaddev com)
nicodvb
parents: 38
diff changeset
513 #if !defined(_WIN32) && !defined(__OS2__)
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
514 if( !dev_name ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
515 fprintf( stderr, "libdvdread: Couldn't find device name.\n" );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
516 } else if( !auth_drive ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
517 fprintf( stderr, "libdvdread: Device %s inaccessible, "
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
518 "CSS authentication not available.\n", dev_name );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
519 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
520 #else
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
521 if( !auth_drive ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
522 fprintf( stderr, "libdvdread: Device %s inaccessible, "
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
523 "CSS authentication not available.\n", dev_name );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
524 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
525 #endif
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
526
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
527 free( dev_name );
37
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
528 dev_name = NULL;
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
529 free( path_copy );
37
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
530 path_copy = NULL;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
531
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
532 /**
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
533 * If we've opened a drive, just use that.
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
534 */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
535 if( auth_drive ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
536 free(path);
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
537 return auth_drive;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
538 }
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
539 /**
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
540 * Otherwise, we now try to open the directory tree instead.
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
541 */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
542 ret_val = DVDOpenPath( path );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
543 free( path );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
544 return ret_val;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
545 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
546
37
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
547 DVDOpen_error:
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
548 /* If it's none of the above, screw it. */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
549 fprintf( stderr, "libdvdread: Could not open %s\n", path );
37
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
550 if( path != NULL )
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
551 free( path );
37
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
552 if ( path_copy != NULL )
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
553 free( path_copy );
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
554 if ( cdir >= 0 )
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
555 close( cdir );
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
556 if ( new_path != NULL )
a57cd30a83bb modified DVDOpen() to use a unified DVDOpen_error label; patch by Erik Hovland
nicodvb
parents: 36
diff changeset
557 free( new_path );
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
558 return NULL;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
559 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
560
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
561 void DVDClose( dvd_reader_t *dvd )
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
562 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
563 if( dvd ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
564 if( dvd->dev ) dvdinput_close( dvd->dev );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
565 if( dvd->path_root ) free( dvd->path_root );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
566 if( dvd->udfcache ) FreeUDFCache( dvd->udfcache );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
567 free( dvd );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
568 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
569 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
570
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
571 /**
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
572 * Open an unencrypted file on a DVD image file.
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
573 */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
574 static dvd_file_t *DVDOpenFileUDF( dvd_reader_t *dvd, char *filename )
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
575 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
576 uint32_t start, len;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
577 dvd_file_t *dvd_file;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
578
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
579 start = UDFFindFile( dvd, filename, &len );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
580 if( !start ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
581 fprintf( stderr, "libdvdnav:DVDOpenFileUDF:UDFFindFile %s failed\n", filename );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
582 return NULL;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
583 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
584
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
585 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
586 if( !dvd_file ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
587 fprintf( stderr, "libdvdnav:DVDOpenFileUDF:malloc failed\n" );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
588 return NULL;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
589 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
590 dvd_file->dvd = dvd;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
591 dvd_file->lb_start = start;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
592 dvd_file->seek_pos = 0;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
593 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
594 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
595 dvd_file->filesize = len / DVD_VIDEO_LB_LEN;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
596
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
597 return dvd_file;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
598 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
599
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
600 /**
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
601 * Searches for <file> in directory <path>, ignoring case.
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
602 * Returns 0 and full filename in <filename>.
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
603 * or -1 on file not found.
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
604 * or -2 on path not found.
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
605 */
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
606 static int findDirFile( const char *path, const char *file, char *filename )
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
607 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
608 DIR *dir;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
609 struct dirent *ent;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
610
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
611 dir = opendir( path );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
612 if( !dir ) return -2;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
613
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
614 while( ( ent = readdir( dir ) ) != NULL ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
615 if( !strcasecmp( ent->d_name, file ) ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
616 sprintf( filename, "%s%s%s", path,
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
617 ( ( path[ strlen( path ) - 1 ] == '/' ) ? "" : "/" ),
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
618 ent->d_name );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
619 closedir(dir);
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
620 return 0;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
621 }
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
622 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
623 closedir(dir);
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
624 return -1;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
625 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
626
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
627 static int findDVDFile( dvd_reader_t *dvd, const char *file, char *filename )
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
628 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
629 char video_path[ PATH_MAX + 1 ];
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
630 const char *nodirfile;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
631 int ret;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
632
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
633 /* Strip off the directory for our search */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
634 if( !strncasecmp( "/VIDEO_TS/", file, 10 ) ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
635 nodirfile = &(file[ 10 ]);
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
636 } else {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
637 nodirfile = file;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
638 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
639
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
640 ret = findDirFile( dvd->path_root, nodirfile, filename );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
641 if( ret < 0 ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
642 /* Try also with adding the path, just in case. */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
643 sprintf( video_path, "%s/VIDEO_TS/", dvd->path_root );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
644 ret = findDirFile( video_path, nodirfile, filename );
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
645 if( ret < 0 ) {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
646 /* Try with the path, but in lower case. */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
647 sprintf( video_path, "%s/video_ts/", dvd->path_root );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
648 ret = findDirFile( video_path, nodirfile, filename );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
649 if( ret < 0 ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
650 return 0;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
651 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
652 }
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
653 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
654
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
655 return 1;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
656 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
657
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
658 /**
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
659 * Open an unencrypted file from a DVD directory tree.
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
660 */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
661 static dvd_file_t *DVDOpenFilePath( dvd_reader_t *dvd, char *filename )
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
662 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
663 char full_path[ PATH_MAX + 1 ];
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
664 dvd_file_t *dvd_file;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
665 struct stat fileinfo;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
666 dvd_input_t dev;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
667
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
668 /* Get the full path of the file. */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
669 if( !findDVDFile( dvd, filename, full_path ) ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
670 fprintf( stderr, "libdvdnav:DVDOpenFilePath:findDVDFile %s failed\n", filename );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
671 return NULL;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
672 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
673
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
674 dev = dvdinput_open( full_path );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
675 if( !dev ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
676 fprintf( stderr, "libdvdnav:DVDOpenFilePath:dvdinput_open %s failed\n", full_path );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
677 return NULL;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
678 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
679
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
680 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
681 if( !dvd_file ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
682 fprintf( stderr, "libdvdnav:DVDOpenFilePath:dvd_file malloc failed\n" );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
683 dvdinput_close(dev);
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
684 return NULL;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
685 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
686 dvd_file->dvd = dvd;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
687 dvd_file->lb_start = 0;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
688 dvd_file->seek_pos = 0;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
689 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
690 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
691 dvd_file->filesize = 0;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
692
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
693 if( stat( full_path, &fileinfo ) < 0 ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
694 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
695 free( dvd_file );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
696 return NULL;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
697 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
698 dvd_file->title_sizes[ 0 ] = fileinfo.st_size / DVD_VIDEO_LB_LEN;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
699 dvd_file->title_devs[ 0 ] = dev;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
700 dvd_file->filesize = dvd_file->title_sizes[ 0 ];
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
701
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
702 return dvd_file;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
703 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
704
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
705 static dvd_file_t *DVDOpenVOBUDF( dvd_reader_t *dvd, int title, int menu )
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
706 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
707 char filename[ MAX_UDF_FILE_NAME_LEN ];
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
708 uint32_t start, len;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
709 dvd_file_t *dvd_file;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
710
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
711 if( title == 0 ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
712 sprintf( filename, "/VIDEO_TS/VIDEO_TS.VOB" );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
713 } else {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
714 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, menu ? 0 : 1 );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
715 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
716 start = UDFFindFile( dvd, filename, &len );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
717 if( start == 0 ) return NULL;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
718
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
719 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
720 if( !dvd_file ) return NULL;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
721 dvd_file->dvd = dvd;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
722 /*Hack*/ dvd_file->css_title = title << 1 | menu;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
723 dvd_file->lb_start = start;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
724 dvd_file->seek_pos = 0;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
725 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
726 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
727 dvd_file->filesize = len / DVD_VIDEO_LB_LEN;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
728
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
729 /* Calculate the complete file size for every file in the VOBS */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
730 if( !menu ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
731 int cur;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
732
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
733 for( cur = 2; cur < 10; cur++ ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
734 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, cur );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
735 if( !UDFFindFile( dvd, filename, &len ) ) break;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
736 dvd_file->filesize += len / DVD_VIDEO_LB_LEN;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
737 }
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
738 }
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
739
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
740 if( dvd->css_state == 1 /* Need key init */ ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
741 initAllCSSKeys( dvd );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
742 dvd->css_state = 2;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
743 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
744 /*
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
745 if( dvdinput_title( dvd_file->dvd->dev, (int)start ) < 0 ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
746 fprintf( stderr, "libdvdread: Error cracking CSS key for %s\n",
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
747 filename );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
748 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
749 */
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
750
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
751 return dvd_file;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
752 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
753
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
754 static dvd_file_t *DVDOpenVOBPath( dvd_reader_t *dvd, int title, int menu )
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
755 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
756 char filename[ MAX_UDF_FILE_NAME_LEN ];
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
757 char full_path[ PATH_MAX + 1 ];
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
758 struct stat fileinfo;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
759 dvd_file_t *dvd_file;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
760 int i;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
761
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
762 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
763 if( !dvd_file ) return NULL;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
764 dvd_file->dvd = dvd;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
765 /*Hack*/ dvd_file->css_title = title << 1 | menu;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
766 dvd_file->lb_start = 0;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
767 dvd_file->seek_pos = 0;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
768 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
769 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
770 dvd_file->filesize = 0;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
771
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
772 if( menu ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
773 dvd_input_t dev;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
774
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
775 if( title == 0 ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
776 sprintf( filename, "VIDEO_TS.VOB" );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
777 } else {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
778 sprintf( filename, "VTS_%02i_0.VOB", title );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
779 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
780 if( !findDVDFile( dvd, filename, full_path ) ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
781 free( dvd_file );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
782 return NULL;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
783 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
784
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
785 dev = dvdinput_open( full_path );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
786 if( dev == NULL ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
787 free( dvd_file );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
788 return NULL;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
789 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
790
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
791 if( stat( full_path, &fileinfo ) < 0 ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
792 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
793 dvdinput_close(dev);
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
794 free( dvd_file );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
795 return NULL;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
796 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
797 dvd_file->title_sizes[ 0 ] = fileinfo.st_size / DVD_VIDEO_LB_LEN;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
798 dvd_file->title_devs[ 0 ] = dev;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
799 dvdinput_title( dvd_file->title_devs[0], 0);
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
800 dvd_file->filesize = dvd_file->title_sizes[ 0 ];
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
801
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
802 } else {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
803 for( i = 0; i < TITLES_MAX; ++i ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
804
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
805 sprintf( filename, "VTS_%02i_%i.VOB", title, i + 1 );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
806 if( !findDVDFile( dvd, filename, full_path ) ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
807 break;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
808 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
809
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
810 if( stat( full_path, &fileinfo ) < 0 ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
811 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
812 break;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
813 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
814
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
815 dvd_file->title_sizes[ i ] = fileinfo.st_size / DVD_VIDEO_LB_LEN;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
816 dvd_file->title_devs[ i ] = dvdinput_open( full_path );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
817 dvdinput_title( dvd_file->title_devs[ i ], 0 );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
818 dvd_file->filesize += dvd_file->title_sizes[ i ];
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
819 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
820 if( !dvd_file->title_devs[ 0 ] ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
821 free( dvd_file );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
822 return NULL;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
823 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
824 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
825
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
826 return dvd_file;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
827 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
828
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
829 dvd_file_t *DVDOpenFile( dvd_reader_t *dvd, int titlenum,
26
0d82d0f30c98 cosmetics: Convert all tabs to spaces.
diego
parents: 22
diff changeset
830 dvd_read_domain_t domain )
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
831 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
832 char filename[ MAX_UDF_FILE_NAME_LEN ];
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
833
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
834 /* Check arguments. */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
835 if( dvd == NULL || titlenum < 0 )
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
836 return NULL;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
837
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
838 switch( domain ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
839 case DVD_READ_INFO_FILE:
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
840 if( titlenum == 0 ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
841 sprintf( filename, "/VIDEO_TS/VIDEO_TS.IFO" );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
842 } else {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
843 sprintf( filename, "/VIDEO_TS/VTS_%02i_0.IFO", titlenum );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
844 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
845 break;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
846 case DVD_READ_INFO_BACKUP_FILE:
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
847 if( titlenum == 0 ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
848 sprintf( filename, "/VIDEO_TS/VIDEO_TS.BUP" );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
849 } else {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
850 sprintf( filename, "/VIDEO_TS/VTS_%02i_0.BUP", titlenum );
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
851 }
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
852 break;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
853 case DVD_READ_MENU_VOBS:
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
854 if( dvd->isImageFile ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
855 return DVDOpenVOBUDF( dvd, titlenum, 1 );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
856 } else {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
857 return DVDOpenVOBPath( dvd, titlenum, 1 );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
858 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
859 break;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
860 case DVD_READ_TITLE_VOBS:
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
861 if( titlenum == 0 ) return 0;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
862 if( dvd->isImageFile ) {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
863 return DVDOpenVOBUDF( dvd, titlenum, 0 );
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
864 } else {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
865 return DVDOpenVOBPath( dvd, titlenum, 0 );
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
866 }
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
867 break;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
868 default:
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
869 fprintf( stderr, "libdvdread: Invalid domain for file open.\n" );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
870 return NULL;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
871 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
872
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
873 if( dvd->isImageFile ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
874 return DVDOpenFileUDF( dvd, filename );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
875 } else {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
876 return DVDOpenFilePath( dvd, filename );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
877 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
878 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
879
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
880 void DVDCloseFile( dvd_file_t *dvd_file )
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
881 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
882 int i;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
883
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
884 if( dvd_file ) {
42
3aa39a1cff0f Remove empty if clause.
erik
parents: 41
diff changeset
885 if( !dvd_file->dvd->isImageFile ) {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
886 for( i = 0; i < TITLES_MAX; ++i ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
887 if( dvd_file->title_devs[ i ] ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
888 dvdinput_close( dvd_file->title_devs[i] );
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
889 }
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
890 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
891 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
892
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
893 free( dvd_file );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
894 dvd_file = 0;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
895 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
896 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
897
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
898 /* Internal, but used from dvd_udf.c */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
899 int UDFReadBlocksRaw( dvd_reader_t *device, uint32_t lb_number,
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
900 size_t block_count, unsigned char *data,
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
901 int encrypted )
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
902 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
903 int ret;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
904
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
905 if( !device->dev ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
906 fprintf( stderr, "libdvdread: Fatal error in block read.\n" );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
907 return 0;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
908 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
909
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
910 ret = dvdinput_seek( device->dev, (int) lb_number );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
911 if( ret != (int) lb_number ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
912 fprintf( stderr, "libdvdread: Can't seek to block %u\n", lb_number );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
913 return 0;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
914 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
915
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
916 ret = dvdinput_read( device->dev, (char *) data,
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
917 (int) block_count, encrypted );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
918 return ret;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
919 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
920
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
921 /* This is using a single input and starting from 'dvd_file->lb_start' offset.
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
922 *
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
923 * Reads 'block_count' blocks from 'dvd_file' at block offset 'offset'
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
924 * into the buffer located at 'data' and if 'encrypted' is set
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
925 * descramble the data if it's encrypted. Returning either an
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
926 * negative error or the number of blocks read. */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
927 static int DVDReadBlocksUDF( dvd_file_t *dvd_file, uint32_t offset,
26
0d82d0f30c98 cosmetics: Convert all tabs to spaces.
diego
parents: 22
diff changeset
928 size_t block_count, unsigned char *data,
0d82d0f30c98 cosmetics: Convert all tabs to spaces.
diego
parents: 22
diff changeset
929 int encrypted )
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
930 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
931 return UDFReadBlocksRaw( dvd_file->dvd, dvd_file->lb_start + offset,
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
932 block_count, data, encrypted );
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
933 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
934
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
935 /* This is using possibly several inputs and starting from an offset of '0'.
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
936 *
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
937 * Reads 'block_count' blocks from 'dvd_file' at block offset 'offset'
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
938 * into the buffer located at 'data' and if 'encrypted' is set
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
939 * descramble the data if it's encrypted. Returning either an
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
940 * negative error or the number of blocks read. */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
941 static int DVDReadBlocksPath( dvd_file_t *dvd_file, unsigned int offset,
26
0d82d0f30c98 cosmetics: Convert all tabs to spaces.
diego
parents: 22
diff changeset
942 size_t block_count, unsigned char *data,
0d82d0f30c98 cosmetics: Convert all tabs to spaces.
diego
parents: 22
diff changeset
943 int encrypted )
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
944 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
945 int i;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
946 int ret, ret2, off;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
947
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
948 ret = 0;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
949 ret2 = 0;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
950 for( i = 0; i < TITLES_MAX; ++i ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
951 if( !dvd_file->title_sizes[ i ] ) return 0; /* Past end of file */
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
952
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
953 if( offset < dvd_file->title_sizes[ i ] ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
954 if( ( offset + block_count ) <= dvd_file->title_sizes[ i ] ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
955 off = dvdinput_seek( dvd_file->title_devs[ i ], (int)offset );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
956 if( off < 0 || off != (int)offset ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
957 fprintf( stderr, "libdvdread: Can't seek to block %d\n",
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
958 offset );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
959 return off < 0 ? off : 0;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
960 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
961 ret = dvdinput_read( dvd_file->title_devs[ i ], data,
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
962 (int)block_count, encrypted );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
963 break;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
964 } else {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
965 size_t part1_size = dvd_file->title_sizes[ i ] - offset;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
966 /* FIXME: Really needs to be a while loop.
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
967 * (This is only true if you try and read >1GB at a time) */
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
968
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
969 /* Read part 1 */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
970 off = dvdinput_seek( dvd_file->title_devs[ i ], (int)offset );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
971 if( off < 0 || off != (int)offset ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
972 fprintf( stderr, "libdvdread: Can't seek to block %d\n",
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
973 offset );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
974 return off < 0 ? off : 0;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
975 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
976 ret = dvdinput_read( dvd_file->title_devs[ i ], data,
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
977 (int)part1_size, encrypted );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
978 if( ret < 0 ) return ret;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
979 /* FIXME: This is wrong if i is the last file in the set.
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
980 * also error from this read will not show in ret. */
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
981
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
982 /* Does the next part exist? If not then return now. */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
983 if( i + 1 >= TITLES_MAX || !dvd_file->title_devs[ i + 1 ] )
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
984 return ret;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
985
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
986 /* Read part 2 */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
987 off = dvdinput_seek( dvd_file->title_devs[ i + 1 ], 0 );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
988 if( off < 0 || off != 0 ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
989 fprintf( stderr, "libdvdread: Can't seek to block %d\n",
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
990 0 );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
991 return off < 0 ? off : 0;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
992 }
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
993 ret2 = dvdinput_read( dvd_file->title_devs[ i + 1 ],
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
994 data + ( part1_size
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
995 * (int64_t)DVD_VIDEO_LB_LEN ),
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
996 (int)(block_count - part1_size),
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
997 encrypted );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
998 if( ret2 < 0 ) return ret2;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
999 break;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1000 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1001 } else {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1002 offset -= dvd_file->title_sizes[ i ];
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1003 }
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1004 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1005
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1006 return ret + ret2;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1007 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1008
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1009 /* This is broken reading more than 2Gb at a time is ssize_t is 32-bit. */
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
1010 ssize_t DVDReadBlocks( dvd_file_t *dvd_file, int offset,
26
0d82d0f30c98 cosmetics: Convert all tabs to spaces.
diego
parents: 22
diff changeset
1011 size_t block_count, unsigned char *data )
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1012 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1013 int ret;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1014
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1015 /* Check arguments. */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1016 if( dvd_file == NULL || offset < 0 || data == NULL )
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1017 return -1;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
1018
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1019 /* Hack, and it will still fail for multiple opens in a threaded app ! */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1020 if( dvd_file->dvd->css_title != dvd_file->css_title ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1021 dvd_file->dvd->css_title = dvd_file->css_title;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1022 if( dvd_file->dvd->isImageFile ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1023 dvdinput_title( dvd_file->dvd->dev, (int)dvd_file->lb_start );
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1024 }
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1025 /* Here each vobu has it's own dvdcss handle, so no need to update
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1026 else {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1027 dvdinput_title( dvd_file->title_devs[ 0 ], (int)dvd_file->lb_start );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1028 }*/
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1029 }
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
1030
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1031 if( dvd_file->dvd->isImageFile ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1032 ret = DVDReadBlocksUDF( dvd_file, (uint32_t)offset,
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1033 block_count, data, DVDINPUT_READ_DECRYPT );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1034 } else {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1035 ret = DVDReadBlocksPath( dvd_file, (unsigned int)offset,
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1036 block_count, data, DVDINPUT_READ_DECRYPT );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1037 }
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
1038
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1039 return (ssize_t)ret;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1040 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1041
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1042 int32_t DVDFileSeek( dvd_file_t *dvd_file, int32_t offset )
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1043 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1044 /* Check arguments. */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1045 if( dvd_file == NULL || offset < 0 )
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1046 return -1;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
1047
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1048 if( offset > dvd_file->filesize * DVD_VIDEO_LB_LEN ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1049 return -1;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1050 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1051 dvd_file->seek_pos = (uint32_t) offset;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1052 return offset;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1053 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1054
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1055 int DVDFileSeekForce(dvd_file_t *dvd_file, int offset, int force_size)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1056 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1057 /* Check arguments. */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1058 if( dvd_file == NULL || offset <= 0 )
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1059 return -1;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1060
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1061 if( dvd_file->dvd->isImageFile ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1062 if( force_size < 0 )
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1063 force_size = (offset - 1) / DVD_VIDEO_LB_LEN + 1;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1064 if( dvd_file->filesize < force_size ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1065 dvd_file->filesize = force_size;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1066 fprintf(stderr, "libdvdread: Ignored size of file indicated in UDF.\n");
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1067 }
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1068 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1069
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1070 if( offset > dvd_file->filesize * DVD_VIDEO_LB_LEN )
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1071 return -1;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1072
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1073 dvd_file->seek_pos = (uint32_t) offset;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1074 return offset;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1075 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1076
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1077 ssize_t DVDReadBytes( dvd_file_t *dvd_file, void *data, size_t byte_size )
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1078 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1079 unsigned char *secbuf_base, *secbuf;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1080 unsigned int numsec, seek_sector, seek_byte;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1081 int ret;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
1082
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1083 /* Check arguments. */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1084 if( dvd_file == NULL || data == NULL )
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1085 return -1;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1086
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1087 seek_sector = dvd_file->seek_pos / DVD_VIDEO_LB_LEN;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1088 seek_byte = dvd_file->seek_pos % DVD_VIDEO_LB_LEN;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1089
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1090 numsec = ( ( seek_byte + byte_size ) / DVD_VIDEO_LB_LEN ) +
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1091 ( ( ( seek_byte + byte_size ) % DVD_VIDEO_LB_LEN ) ? 1 : 0 );
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
1092
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1093 secbuf_base = (unsigned char *) malloc( numsec * DVD_VIDEO_LB_LEN + 2048 );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1094 secbuf = (unsigned char *)(((uintptr_t)secbuf_base & ~((uintptr_t)2047)) + 2048);
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1095 if( !secbuf_base ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1096 fprintf( stderr, "libdvdread: Can't allocate memory "
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1097 "for file read!\n" );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1098 return 0;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1099 }
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
1100
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1101 if( dvd_file->dvd->isImageFile ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1102 ret = DVDReadBlocksUDF( dvd_file, (uint32_t) seek_sector,
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1103 (size_t) numsec, secbuf, DVDINPUT_NOFLAGS );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1104 } else {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1105 ret = DVDReadBlocksPath( dvd_file, seek_sector,
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1106 (size_t) numsec, secbuf, DVDINPUT_NOFLAGS );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1107 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1108
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1109 if( ret != (int) numsec ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1110 free( secbuf_base );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1111 return ret < 0 ? ret : 0;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1112 }
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1113
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1114 memcpy( data, &(secbuf[ seek_byte ]), byte_size );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1115 free( secbuf_base );
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1116
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1117 DVDFileSeekForce(dvd_file, dvd_file->seek_pos + byte_size, -1);
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1118 return byte_size;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1119 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1120
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1121 ssize_t DVDFileSize( dvd_file_t *dvd_file )
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1122 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1123 /* Check arguments. */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1124 if( dvd_file == NULL )
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1125 return -1;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
1126
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1127 return dvd_file->filesize;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1128 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1129
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1130 int DVDDiscID( dvd_reader_t *dvd, unsigned char *discid )
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1131 {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1132 struct md5_ctx ctx;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1133 int title;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1134 int nr_of_files = 0;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1135
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1136 /* Check arguments. */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1137 if( dvd == NULL || discid == NULL )
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1138 return 0;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
1139
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1140 /* Go through the first 10 IFO:s, in order,
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1141 * and md5sum them, i.e VIDEO_TS.IFO and VTS_0?_0.IFO */
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1142 md5_init_ctx( &ctx );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1143 for( title = 0; title < 10; title++ ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1144 dvd_file_t *dvd_file = DVDOpenFile( dvd, title, DVD_READ_INFO_FILE );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1145 if( dvd_file != NULL ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1146 ssize_t bytes_read;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1147 size_t file_size = dvd_file->filesize * DVD_VIDEO_LB_LEN;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1148 char *buffer_base = malloc( file_size + 2048 );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1149 char *buffer = (char *)(((uintptr_t)buffer_base & ~((uintptr_t)2047)) + 2048);
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
1150
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1151 if( buffer_base == NULL ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1152 DVDCloseFile( dvd_file );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1153 fprintf( stderr, "libdvdread: DVDDiscId, failed to "
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1154 "allocate memory for file read!\n" );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1155 return -1;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1156 }
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
1157
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1158 bytes_read = DVDReadBytes( dvd_file, buffer, file_size );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1159 if( bytes_read != file_size ) {
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1160 fprintf( stderr, "libdvdread: DVDDiscId read returned %zd bytes"
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1161 ", wanted %zd\n", bytes_read, file_size );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1162 DVDCloseFile( dvd_file );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1163 free( buffer_base );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1164 return -1;
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1165 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1166
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1167 md5_process_bytes( buffer, file_size, &ctx );
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
1168
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1169 DVDCloseFile( dvd_file );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1170 free( buffer_base );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1171 nr_of_files++;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1172 }
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1173 }
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1174 md5_finish_ctx( &ctx, discid );
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1175 if(!nr_of_files)
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1176 return -1;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
1177
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
1178 return 0;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1179 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1180
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1181
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1182 int DVDISOVolumeInfo( dvd_reader_t *dvd,
26
0d82d0f30c98 cosmetics: Convert all tabs to spaces.
diego
parents: 22
diff changeset
1183 char *volid, unsigned int volid_size,
0d82d0f30c98 cosmetics: Convert all tabs to spaces.
diego
parents: 22
diff changeset
1184 unsigned char *volsetid, unsigned int volsetid_size )
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1185 {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1186 unsigned char *buffer, *buffer_base;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1187 int ret;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1188
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1189 /* Check arguments. */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1190 if( dvd == NULL )
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1191 return 0;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
1192
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1193 if( dvd->dev == NULL ) {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1194 /* No block access, so no ISO... */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1195 return -1;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1196 }
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
1197
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1198 buffer_base = malloc( DVD_VIDEO_LB_LEN + 2048 );
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1199 buffer = (unsigned char *)(((uintptr_t)buffer_base & ~((uintptr_t)2047)) + 2048);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1200
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1201 if( buffer_base == NULL ) {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1202 fprintf( stderr, "libdvdread: DVDISOVolumeInfo, failed to "
26
0d82d0f30c98 cosmetics: Convert all tabs to spaces.
diego
parents: 22
diff changeset
1203 "allocate memory for file read!\n" );
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1204 return -1;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1205 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1206
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1207 ret = UDFReadBlocksRaw( dvd, 16, 1, buffer, 0 );
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1208 if( ret != 1 ) {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1209 fprintf( stderr, "libdvdread: DVDISOVolumeInfo, failed to "
26
0d82d0f30c98 cosmetics: Convert all tabs to spaces.
diego
parents: 22
diff changeset
1210 "read ISO9660 Primary Volume Descriptor!\n" );
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1211 free( buffer_base );
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1212 return -1;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1213 }
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
1214
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1215 if( (volid != NULL) && (volid_size > 0) ) {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1216 unsigned int n;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1217 for(n = 0; n < 32; n++) {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1218 if(buffer[40+n] == 0x20) {
26
0d82d0f30c98 cosmetics: Convert all tabs to spaces.
diego
parents: 22
diff changeset
1219 break;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1220 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1221 }
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
1222
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1223 if(volid_size > n+1) {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1224 volid_size = n+1;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1225 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1226
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1227 memcpy(volid, &buffer[40], volid_size-1);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1228 volid[volid_size-1] = '\0';
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1229 }
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
1230
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1231 if( (volsetid != NULL) && (volsetid_size > 0) ) {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1232 if(volsetid_size > 128) {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1233 volsetid_size = 128;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1234 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1235 memcpy(volsetid, &buffer[190], volsetid_size);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1236 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1237 free( buffer_base );
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1238 return 0;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1239 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1240
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1241
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1242 int DVDUDFVolumeInfo( dvd_reader_t *dvd,
26
0d82d0f30c98 cosmetics: Convert all tabs to spaces.
diego
parents: 22
diff changeset
1243 char *volid, unsigned int volid_size,
0d82d0f30c98 cosmetics: Convert all tabs to spaces.
diego
parents: 22
diff changeset
1244 unsigned char *volsetid, unsigned int volsetid_size )
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1245 {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1246 int ret;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1247 /* Check arguments. */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1248 if( dvd == NULL )
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1249 return -1;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
1250
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1251 if( dvd->dev == NULL ) {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1252 /* No block access, so no UDF VolumeSet Identifier */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1253 return -1;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1254 }
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
1255
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1256 if( (volid != NULL) && (volid_size > 0) ) {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1257 ret = UDFGetVolumeIdentifier(dvd, volid, volid_size);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1258 if(!ret) {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1259 return -1;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1260 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1261 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1262 if( (volsetid != NULL) && (volsetid_size > 0) ) {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1263 ret = UDFGetVolumeSetIdentifier(dvd, volsetid, volsetid_size);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1264 if(!ret) {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1265 return -1;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1266 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1267 }
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
1268
fce16251755c Remove all trailing whitespace,
rathann
parents: 7
diff changeset
1269 return 0;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1270 }