annotate libmpdvdkit2/dvd_reader.c @ 7029:9db58ffbd73c

importing libdvdread 0.9.3 files
author arpi
date Fri, 16 Aug 2002 22:37:48 +0000
parents
children 596919e4f601
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
1 /*
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
2 * Copyright (C) 2001, 2002 Billy Biggs <vektor@dumbterm.net>,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
3 * Håkan Hjort <d95hjort@dtek.chalmers.se>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
4 *
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
7 * the Free Software Foundation; either version 2 of the License, or (at
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
8 * your option) any later version.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
9 *
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful, but
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
13 * General Public License for more details.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
14 *
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
16 * along with this program; if not, write to the Free Software
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
18 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
19
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
20 #include <sys/types.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
21 #include <sys/stat.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
22 #include <sys/time.h> /* For the timing of dvdcss_title crack. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
23 #include <fcntl.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
24 #include <stdlib.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
25 #include <stdio.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
26 #include <errno.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
27 #include <string.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
28 #include <unistd.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
29 #include <limits.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
30 #include <dirent.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
31
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
32 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__bsdi__)|| defined(__DARWIN__)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
33 #define SYS_BSD 1
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
34 #endif
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
35
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
36 #if defined(__sun)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
37 #include <sys/mnttab.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
38 #elif defined(SYS_BSD)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
39 #include <fstab.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
40 #elif defined(__linux__)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
41 #include <mntent.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
42 #endif
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
43
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
44 #include "dvd_udf.h"
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
45 #include "dvd_input.h"
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
46 #include "dvd_reader.h"
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
47
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
48 struct dvd_reader_s {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
49 /* Basic information. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
50 int isImageFile;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
51
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
52 /* Hack for keeping track of the css status.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
53 * 0: no css, 1: perhaps (need init of keys), 2: have done init */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
54 int css_state;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
55 int css_title; /* Last title that we have called DVDinpute_title for. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
56
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
57 /* Information required for an image file. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
58 dvd_input_t dev;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
59
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
60 /* Information required for a directory path drive. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
61 char *path_root;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
62 };
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
63
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
64 struct dvd_file_s {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
65 /* Basic information. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
66 dvd_reader_t *dvd;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
67
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
68 /* Hack for selecting the right css title. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
69 int css_title;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
70
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
71 /* Information required for an image file. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
72 uint32_t lb_start;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
73 uint32_t seek_pos;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
74
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
75 /* Information required for a directory path drive. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
76 size_t title_sizes[ 9 ];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
77 dvd_input_t title_devs[ 9 ];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
78
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
79 /* Calculated at open-time, size in blocks. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
80 ssize_t filesize;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
81 };
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
82
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
83 /* Loop over all titles and call dvdcss_title to crack the keys. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
84 static int initAllCSSKeys( dvd_reader_t *dvd )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
85 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
86 struct timeval all_s, all_e;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
87 struct timeval t_s, t_e;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
88 char filename[ MAX_UDF_FILE_NAME_LEN ];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
89 uint32_t start, len;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
90 int title;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
91
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
92 fprintf( stderr, "\n" );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
93 fprintf( stderr, "libdvdread: Attempting to retrieve all CSS keys\n" );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
94 fprintf( stderr, "libdvdread: This can take a _long_ time, "
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
95 "please be patient\n\n" );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
96
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
97 gettimeofday(&all_s, NULL);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
98
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
99 for( title = 0; title < 100; title++ ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
100 gettimeofday( &t_s, NULL );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
101 if( title == 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
102 sprintf( filename, "/VIDEO_TS/VIDEO_TS.VOB" );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
103 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
104 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, 0 );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
105 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
106 start = UDFFindFile( dvd, filename, &len );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
107 if( start != 0 && len != 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
108 /* Perform CSS key cracking for this title. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
109 fprintf( stderr, "libdvdread: Get key for %s at 0x%08x\n",
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
110 filename, start );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
111 if( DVDinput_title( dvd->dev, (int)start ) < 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
112 fprintf( stderr, "libdvdread: Error cracking CSS key for %s (0x%08x)\n", filename, start);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
113 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
114 gettimeofday( &t_e, NULL );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
115 fprintf( stderr, "libdvdread: Elapsed time %ld\n",
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
116 (long int) t_e.tv_sec - t_s.tv_sec );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
117 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
118
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
119 if( title == 0 ) continue;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
120
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
121 gettimeofday( &t_s, NULL );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
122 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, 1 );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
123 start = UDFFindFile( dvd, filename, &len );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
124 if( start == 0 || len == 0 ) break;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
125
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
126 /* Perform CSS key cracking for this title. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
127 fprintf( stderr, "libdvdread: Get key for %s at 0x%08x\n",
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
128 filename, start );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
129 if( DVDinput_title( dvd->dev, (int)start ) < 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
130 fprintf( stderr, "libdvdread: Error cracking CSS key for %s (0x%08x)!!\n", filename, start);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
131 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
132 gettimeofday( &t_e, NULL );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
133 fprintf( stderr, "libdvdread: Elapsed time %ld\n",
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
134 (long int) t_e.tv_sec - t_s.tv_sec );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
135 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
136 title--;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
137
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
138 fprintf( stderr, "libdvdread: Found %d VTS's\n", title );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
139 gettimeofday(&all_e, NULL);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
140 fprintf( stderr, "libdvdread: Elapsed time %ld\n",
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
141 (long int) all_e.tv_sec - all_s.tv_sec );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
142
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
143 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
144 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
145
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
146
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
147
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
148 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
149 * Open a DVD image or block device file.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
150 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
151 static dvd_reader_t *DVDOpenImageFile( const char *location, int have_css )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
152 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
153 dvd_reader_t *dvd;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
154 dvd_input_t dev;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
155
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
156 dev = DVDinput_open( location );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
157 if( !dev ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
158 fprintf( stderr, "libdvdread: Can't open %s for reading\n", location );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
159 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
160 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
161
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
162 dvd = (dvd_reader_t *) malloc( sizeof( dvd_reader_t ) );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
163 if( !dvd ) return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
164 dvd->isImageFile = 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
165 dvd->dev = dev;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
166 dvd->path_root = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
167
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
168 if( have_css ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
169 /* Only if DVDCSS_METHOD = title, a bit if it's disc or if
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
170 * DVDCSS_METHOD = key but region missmatch. Unfortunaly we
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
171 * don't have that information. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
172
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
173 dvd->css_state = 1; /* Need key init. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
174 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
175
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
176 return dvd;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
177 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
178
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
179 static dvd_reader_t *DVDOpenPath( const char *path_root )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
180 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
181 dvd_reader_t *dvd;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
182
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
183 dvd = (dvd_reader_t *) malloc( sizeof( dvd_reader_t ) );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
184 if( !dvd ) return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
185 dvd->isImageFile = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
186 dvd->dev = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
187 dvd->path_root = strdup( path_root );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
188
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
189 return dvd;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
190 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
191
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
192 #if defined(__sun)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
193 /* /dev/rdsk/c0t6d0s0 (link to /devices/...)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
194 /vol/dev/rdsk/c0t6d0/??
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
195 /vol/rdsk/<name> */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
196 static char *sun_block2char( const char *path )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
197 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
198 char *new_path;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
199
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
200 /* Must contain "/dsk/" */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
201 if( !strstr( path, "/dsk/" ) ) return (char *) strdup( path );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
202
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
203 /* Replace "/dsk/" with "/rdsk/" */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
204 new_path = malloc( strlen(path) + 2 );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
205 strcpy( new_path, path );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
206 strcpy( strstr( new_path, "/dsk/" ), "" );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
207 strcat( new_path, "/rdsk/" );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
208 strcat( new_path, strstr( path, "/dsk/" ) + strlen( "/dsk/" ) );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
209
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
210 return new_path;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
211 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
212 #endif
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
213
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
214 #if defined(SYS_BSD)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
215 /* FreeBSD /dev/(r)(a)cd0c (a is for atapi), recomended to _not_ use r
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
216 OpenBSD /dev/rcd0c, it needs to be the raw device
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
217 NetBSD /dev/rcd0[d|c|..] d for x86, c (for non x86), perhaps others
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
218 Darwin /dev/rdisk0, it needs to be the raw device
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
219 BSD/OS /dev/sr0c (if not mounted) or /dev/rsr0c ('c' any letter will do) */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
220 static char *bsd_block2char( const char *path )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
221 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
222 char *new_path;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
223
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
224 /* If it doesn't start with "/dev/" or does start with "/dev/r" exit */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
225 if( !strncmp( path, "/dev/", 5 ) || strncmp( path, "/dev/r", 6 ) )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
226 return (char *) strdup( path );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
227
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
228 /* Replace "/dev/" with "/dev/r" */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
229 new_path = malloc( strlen(path) + 2 );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
230 strcpy( new_path, "/dev/r" );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
231 strcat( new_path, path + strlen( "/dev/" ) );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
232
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
233 return new_path;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
234 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
235 #endif
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
236
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
237 dvd_reader_t *DVDOpen( const char *path )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
238 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
239 struct stat fileinfo;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
240 int ret, have_css;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
241 char *dev_name = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
242
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
243 if( !path ) return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
244
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
245 ret = stat( path, &fileinfo );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
246 if( ret < 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
247 /* If we can't stat the file, give up */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
248 fprintf( stderr, "libdvdread: Can't stat %s\n", path );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
249 perror("");
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
250 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
251 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
252
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
253 /* Try to open libdvdcss or fall back to standard functions */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
254 have_css = DVDInputSetup();
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
255
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
256 /* First check if this is a block/char device or a file*/
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
257 if( S_ISBLK( fileinfo.st_mode ) ||
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
258 S_ISCHR( fileinfo.st_mode ) ||
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
259 S_ISREG( fileinfo.st_mode ) ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
260
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
261 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
262 * Block devices and regular files are assumed to be DVD-Video images.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
263 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
264 #if defined(__sun)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
265 return DVDOpenImageFile( sun_block2char( path ), have_css );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
266 #elif defined(SYS_BSD)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
267 return DVDOpenImageFile( bsd_block2char( path ), have_css );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
268 #else
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
269 return DVDOpenImageFile( path, have_css );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
270 #endif
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
271
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
272 } else if( S_ISDIR( fileinfo.st_mode ) ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
273 dvd_reader_t *auth_drive = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
274 char *path_copy;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
275 #if defined(SYS_BSD)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
276 struct fstab* fe;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
277 #elif defined(__sun) || defined(__linux__)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
278 FILE *mntfile;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
279 #endif
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
280
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
281 /* XXX: We should scream real loud here. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
282 if( !(path_copy = strdup( path ) ) ) return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
283
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
284 /* Resolve any symlinks and get the absolut dir name. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
285 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
286 char *new_path;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
287 int cdir = open( ".", O_RDONLY );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
288
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
289 if( cdir >= 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
290 chdir( path_copy );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
291 new_path = getcwd( NULL, PATH_MAX );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
292 fchdir( cdir );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
293 close( cdir );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
294 if( new_path ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
295 free( path_copy );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
296 path_copy = new_path;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
297 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
298 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
299 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
300
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
301 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
302 * If we're being asked to open a directory, check if that directory
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
303 * is the mountpoint for a DVD-ROM which we can use instead.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
304 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
305
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
306 if( strlen( path_copy ) > 1 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
307 if( path_copy[ strlen( path_copy ) - 1 ] == '/' )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
308 path_copy[ strlen( path_copy ) - 1 ] = '\0';
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
309 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
310
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
311 if( strlen( path_copy ) > 9 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
312 if( !strcasecmp( &(path_copy[ strlen( path_copy ) - 9 ]),
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
313 "/video_ts" ) ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
314 path_copy[ strlen( path_copy ) - 9 ] = '\0';
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
315 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
316 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
317
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
318 #if defined(SYS_BSD)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
319 if( ( fe = getfsfile( path_copy ) ) ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
320 dev_name = bsd_block2char( fe->fs_spec );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
321 fprintf( stderr,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
322 "libdvdread: Attempting to use device %s"
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
323 " mounted on %s for CSS authentication\n",
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
324 dev_name,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
325 fe->fs_file );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
326 auth_drive = DVDOpenImageFile( dev_name, have_css );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
327 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
328 #elif defined(__sun)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
329 mntfile = fopen( MNTTAB, "r" );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
330 if( mntfile ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
331 struct mnttab mp;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
332 int res;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
333
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
334 while( ( res = getmntent( mntfile, &mp ) ) != -1 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
335 if( res == 0 && !strcmp( mp.mnt_mountp, path_copy ) ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
336 dev_name = sun_block2char( mp.mnt_special );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
337 fprintf( stderr,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
338 "libdvdread: Attempting to use device %s"
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
339 " mounted on %s for CSS authentication\n",
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
340 dev_name,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
341 mp.mnt_mountp );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
342 auth_drive = DVDOpenImageFile( dev_name, have_css );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
343 break;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
344 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
345 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
346 fclose( mntfile );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
347 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
348 #elif defined(__linux__)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
349 mntfile = fopen( MOUNTED, "r" );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
350 if( mntfile ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
351 struct mntent *me;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
352
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
353 while( ( me = getmntent( mntfile ) ) ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
354 if( !strcmp( me->mnt_dir, path_copy ) ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
355 fprintf( stderr,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
356 "libdvdread: Attempting to use device %s"
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
357 " mounted on %s for CSS authentication\n",
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
358 me->mnt_fsname,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
359 me->mnt_dir );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
360 auth_drive = DVDOpenImageFile( me->mnt_fsname, have_css );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
361 dev_name = strdup(me->mnt_fsname);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
362 break;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
363 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
364 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
365 fclose( mntfile );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
366 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
367 #endif
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
368 if( !dev_name ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
369 fprintf( stderr, "libdvdread: Couldn't find device name.\n" );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
370 } else if( !auth_drive ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
371 fprintf( stderr, "libdvdread: Device %s inaccessible, "
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
372 "CSS authentication not available.\n", dev_name );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
373 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
374
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
375 free( dev_name );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
376 free( path_copy );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
377
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
378 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
379 * If we've opened a drive, just use that.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
380 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
381 if( auth_drive ) return auth_drive;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
382
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
383 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
384 * Otherwise, we now try to open the directory tree instead.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
385 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
386 return DVDOpenPath( path );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
387 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
388
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
389 /* If it's none of the above, screw it. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
390 fprintf( stderr, "libdvdread: Could not open %s\n", path );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
391 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
392 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
393
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
394 void DVDClose( dvd_reader_t *dvd )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
395 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
396 if( dvd ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
397 if( dvd->dev ) DVDinput_close( dvd->dev );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
398 if( dvd->path_root ) free( dvd->path_root );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
399 free( dvd );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
400 dvd = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
401 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
402 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
403
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
404 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
405 * Open an unencrypted file on a DVD image file.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
406 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
407 static dvd_file_t *DVDOpenFileUDF( dvd_reader_t *dvd, char *filename )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
408 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
409 uint32_t start, len;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
410 dvd_file_t *dvd_file;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
411
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
412 start = UDFFindFile( dvd, filename, &len );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
413 if( !start ) return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
414
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
415 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
416 if( !dvd_file ) return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
417 dvd_file->dvd = dvd;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
418 dvd_file->lb_start = start;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
419 dvd_file->seek_pos = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
420 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
421 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
422 dvd_file->filesize = len / DVD_VIDEO_LB_LEN;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
423
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
424 return dvd_file;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
425 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
426
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
427 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
428 * Searches for <file> in directory <path>, ignoring case.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
429 * Returns 0 and full filename in <filename>.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
430 * or -1 on file not found.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
431 * or -2 on path not found.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
432 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
433 static int findDirFile( const char *path, const char *file, char *filename )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
434 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
435 DIR *dir;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
436 struct dirent *ent;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
437
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
438 dir = opendir( path );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
439 if( !dir ) return -2;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
440
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
441 while( ( ent = readdir( dir ) ) != NULL ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
442 if( !strcasecmp( ent->d_name, file ) ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
443 sprintf( filename, "%s%s%s", path,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
444 ( ( path[ strlen( path ) - 1 ] == '/' ) ? "" : "/" ),
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
445 ent->d_name );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
446 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
447 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
448 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
449
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
450 return -1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
451 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
452
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
453 static int findDVDFile( dvd_reader_t *dvd, const char *file, char *filename )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
454 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
455 char video_path[ PATH_MAX + 1 ];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
456 const char *nodirfile;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
457 int ret;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
458
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
459 /* Strip off the directory for our search */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
460 if( !strncasecmp( "/VIDEO_TS/", file, 10 ) ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
461 nodirfile = &(file[ 10 ]);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
462 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
463 nodirfile = file;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
464 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
465
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
466 ret = findDirFile( dvd->path_root, nodirfile, filename );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
467 if( ret < 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
468 /* Try also with adding the path, just in case. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
469 sprintf( video_path, "%s/VIDEO_TS/", dvd->path_root );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
470 ret = findDirFile( video_path, nodirfile, filename );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
471 if( ret < 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
472 /* Try with the path, but in lower case. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
473 sprintf( video_path, "%s/video_ts/", dvd->path_root );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
474 ret = findDirFile( video_path, nodirfile, filename );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
475 if( ret < 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
476 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
477 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
478 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
479 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
480
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
481 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
482 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
483
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
484 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
485 * Open an unencrypted file from a DVD directory tree.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
486 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
487 static dvd_file_t *DVDOpenFilePath( dvd_reader_t *dvd, char *filename )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
488 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
489 char full_path[ PATH_MAX + 1 ];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
490 dvd_file_t *dvd_file;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
491 struct stat fileinfo;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
492 dvd_input_t dev;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
493
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
494 /* Get the full path of the file. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
495 if( !findDVDFile( dvd, filename, full_path ) ) return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
496
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
497 dev = DVDinput_open( full_path );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
498 if( !dev ) return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
499
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
500 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
501 if( !dvd_file ) return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
502 dvd_file->dvd = dvd;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
503 dvd_file->lb_start = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
504 dvd_file->seek_pos = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
505 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
506 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
507 dvd_file->filesize = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
508
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
509 if( stat( full_path, &fileinfo ) < 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
510 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
511 free( dvd_file );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
512 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
513 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
514 dvd_file->title_sizes[ 0 ] = fileinfo.st_size / DVD_VIDEO_LB_LEN;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
515 dvd_file->title_devs[ 0 ] = dev;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
516 dvd_file->filesize = dvd_file->title_sizes[ 0 ];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
517
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
518 return dvd_file;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
519 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
520
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
521 static dvd_file_t *DVDOpenVOBUDF( dvd_reader_t *dvd, int title, int menu )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
522 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
523 char filename[ MAX_UDF_FILE_NAME_LEN ];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
524 uint32_t start, len;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
525 dvd_file_t *dvd_file;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
526
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
527 if( title == 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
528 sprintf( filename, "/VIDEO_TS/VIDEO_TS.VOB" );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
529 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
530 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, menu ? 0 : 1 );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
531 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
532 start = UDFFindFile( dvd, filename, &len );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
533 if( start == 0 ) return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
534
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
535 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
536 if( !dvd_file ) return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
537 dvd_file->dvd = dvd;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
538 /*Hack*/ dvd_file->css_title = title << 1 | menu;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
539 dvd_file->lb_start = start;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
540 dvd_file->seek_pos = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
541 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
542 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
543 dvd_file->filesize = len / DVD_VIDEO_LB_LEN;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
544
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
545 /* Calculate the complete file size for every file in the VOBS */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
546 if( !menu ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
547 int cur;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
548
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
549 for( cur = 2; cur < 10; cur++ ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
550 sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, cur );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
551 if( !UDFFindFile( dvd, filename, &len ) ) break;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
552 dvd_file->filesize += len / DVD_VIDEO_LB_LEN;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
553 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
554 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
555
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
556 if( dvd->css_state == 1 /* Need key init */ ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
557 initAllCSSKeys( dvd );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
558 dvd->css_state = 2;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
559 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
560 /*
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
561 if( DVDinput_seek( dvd_file->dvd->dev,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
562 (int)start, DVDINPUT_SEEK_KEY ) < 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
563 fprintf( stderr, "libdvdread: Error cracking CSS key for %s\n",
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
564 filename );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
565 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
566 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
567
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
568 return dvd_file;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
569 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
570
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
571 static dvd_file_t *DVDOpenVOBPath( dvd_reader_t *dvd, int title, int menu )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
572 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
573 char filename[ MAX_UDF_FILE_NAME_LEN ];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
574 char full_path[ PATH_MAX + 1 ];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
575 struct stat fileinfo;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
576 dvd_file_t *dvd_file;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
577 int i;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
578
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
579 dvd_file = (dvd_file_t *) malloc( sizeof( dvd_file_t ) );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
580 if( !dvd_file ) return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
581 dvd_file->dvd = dvd;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
582 /*Hack*/ dvd_file->css_title = title << 1 | menu;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
583 dvd_file->lb_start = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
584 dvd_file->seek_pos = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
585 memset( dvd_file->title_sizes, 0, sizeof( dvd_file->title_sizes ) );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
586 memset( dvd_file->title_devs, 0, sizeof( dvd_file->title_devs ) );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
587 dvd_file->filesize = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
588
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
589 if( menu ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
590 dvd_input_t dev;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
591
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
592 if( title == 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
593 sprintf( filename, "VIDEO_TS.VOB" );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
594 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
595 sprintf( filename, "VTS_%02i_0.VOB", title );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
596 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
597 if( !findDVDFile( dvd, filename, full_path ) ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
598 free( dvd_file );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
599 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
600 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
601
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
602 dev = DVDinput_open( full_path );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
603 if( dev == NULL ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
604 free( dvd_file );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
605 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
606 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
607
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
608 if( stat( full_path, &fileinfo ) < 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
609 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
610 free( dvd_file );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
611 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
612 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
613 dvd_file->title_sizes[ 0 ] = fileinfo.st_size / DVD_VIDEO_LB_LEN;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
614 dvd_file->title_devs[ 0 ] = dev;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
615 DVDinput_seek( dvd_file->title_devs[0], 0, DVDINPUT_SEEK_KEY );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
616 dvd_file->filesize = dvd_file->title_sizes[ 0 ];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
617
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
618 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
619 for( i = 0; i < 9; ++i ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
620
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
621 sprintf( filename, "VTS_%02i_%i.VOB", title, i + 1 );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
622 if( !findDVDFile( dvd, filename, full_path ) ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
623 break;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
624 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
625
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
626 if( stat( full_path, &fileinfo ) < 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
627 fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
628 break;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
629 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
630
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
631 dvd_file->title_sizes[ i ] = fileinfo.st_size / DVD_VIDEO_LB_LEN;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
632 dvd_file->title_devs[ i ] = DVDinput_open( full_path );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
633 dvd_file->filesize += dvd_file->title_sizes[ i ];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
634 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
635 if( dvd_file->title_devs[ 0 ] ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
636 DVDinput_seek( dvd_file->title_devs[ 0 ], 0, DVDINPUT_SEEK_KEY );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
637 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
638 free( dvd_file );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
639 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
640 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
641 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
642
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
643 return dvd_file;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
644 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
645
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
646 dvd_file_t *DVDOpenFile( dvd_reader_t *dvd, int titlenum,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
647 dvd_read_domain_t domain )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
648 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
649 char filename[ MAX_UDF_FILE_NAME_LEN ];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
650
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
651 switch( domain ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
652 case DVD_READ_INFO_FILE:
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
653 if( titlenum == 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
654 sprintf( filename, "/VIDEO_TS/VIDEO_TS.IFO" );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
655 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
656 sprintf( filename, "/VIDEO_TS/VTS_%02i_0.IFO", titlenum );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
657 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
658 break;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
659 case DVD_READ_INFO_BACKUP_FILE:
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
660 if( titlenum == 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
661 sprintf( filename, "/VIDEO_TS/VIDEO_TS.BUP" );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
662 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
663 sprintf( filename, "/VIDEO_TS/VTS_%02i_0.BUP", titlenum );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
664 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
665 break;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
666 case DVD_READ_MENU_VOBS:
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
667 if( dvd->isImageFile ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
668 return DVDOpenVOBUDF( dvd, titlenum, 1 );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
669 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
670 return DVDOpenVOBPath( dvd, titlenum, 1 );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
671 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
672 break;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
673 case DVD_READ_TITLE_VOBS:
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
674 if( titlenum == 0 ) return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
675 if( dvd->isImageFile ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
676 return DVDOpenVOBUDF( dvd, titlenum, 0 );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
677 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
678 return DVDOpenVOBPath( dvd, titlenum, 0 );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
679 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
680 break;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
681 default:
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
682 fprintf( stderr, "libdvdread: Invalid domain for file open.\n" );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
683 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
684 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
685
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
686 if( dvd->isImageFile ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
687 return DVDOpenFileUDF( dvd, filename );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
688 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
689 return DVDOpenFilePath( dvd, filename );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
690 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
691 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
692
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
693 void DVDCloseFile( dvd_file_t *dvd_file )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
694 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
695 int i;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
696
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
697 if( dvd_file ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
698 if( dvd_file->dvd->isImageFile ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
699 ;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
700 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
701 for( i = 0; i < 9; ++i ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
702 if( dvd_file->title_devs[ i ] ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
703 DVDinput_close( dvd_file->title_devs[i] );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
704 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
705 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
706 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
707
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
708 free( dvd_file );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
709 dvd_file = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
710 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
711 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
712
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
713 /* Internal, but used from dvd_udf.c */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
714 int DVDReadBlocksUDFRaw( dvd_reader_t *device, uint32_t lb_number,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
715 size_t block_count, unsigned char *data,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
716 int encrypted )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
717 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
718 int ret;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
719
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
720 if( !device->dev ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
721 fprintf( stderr, "libdvdread: Fatal error in block read.\n" );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
722 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
723 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
724
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
725 ret = DVDinput_seek( device->dev, (int) lb_number, DVDINPUT_NOFLAGS );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
726 if( ret != (int) lb_number ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
727 fprintf( stderr, "libdvdread: Can't seek to block %u\n", lb_number );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
728 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
729 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
730
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
731 return DVDinput_read( device->dev, (char *) data,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
732 (int) block_count, encrypted );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
733 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
734
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
735 /* This is using a single input and starting from 'dvd_file->lb_start' offset.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
736 *
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
737 * Reads 'block_count' blocks from 'dvd_file' at block offset 'offset'
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
738 * into the buffer located at 'data' and if 'encrypted' is set
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
739 * descramble the data if it's encrypted. Returning either an
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
740 * negative error or the number of blocks read. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
741 static int DVDReadBlocksUDF( dvd_file_t *dvd_file, uint32_t offset,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
742 size_t block_count, unsigned char *data,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
743 int encrypted )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
744 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
745 return DVDReadBlocksUDFRaw( dvd_file->dvd, dvd_file->lb_start + offset,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
746 block_count, data, encrypted );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
747 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
748
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
749 /* This is using possibly several inputs and starting from an offset of '0'.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
750 *
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
751 * Reads 'block_count' blocks from 'dvd_file' at block offset 'offset'
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
752 * into the buffer located at 'data' and if 'encrypted' is set
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
753 * descramble the data if it's encrypted. Returning either an
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
754 * negative error or the number of blocks read. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
755 static int DVDReadBlocksPath( dvd_file_t *dvd_file, unsigned int offset,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
756 size_t block_count, unsigned char *data,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
757 int encrypted )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
758 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
759 int i;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
760 int ret, ret2, off;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
761
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
762 ret = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
763 ret2 = 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
764 for( i = 0; i < 9; ++i ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
765 if( !dvd_file->title_sizes[ i ] ) return 0; /* Past end of file */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
766
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
767 if( offset < dvd_file->title_sizes[ i ] ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
768 if( ( offset + block_count ) <= dvd_file->title_sizes[ i ] ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
769 off = DVDinput_seek( dvd_file->title_devs[ i ],
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
770 (int)offset, DVDINPUT_NOFLAGS );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
771 if( off < 0 || off != (int)offset ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
772 fprintf( stderr, "libdvdread: Can't seek to block %d\n",
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
773 offset );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
774 return off < 0 ? off : 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
775 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
776 ret = DVDinput_read( dvd_file->title_devs[ i ], data,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
777 (int)block_count, encrypted );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
778 break;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
779 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
780 size_t part1_size = dvd_file->title_sizes[ i ] - offset;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
781 /* FIXME: Really needs to be a while loop.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
782 * (This is only true if you try and read >1GB at a time) */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
783
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
784 /* Read part 1 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
785 off = DVDinput_seek( dvd_file->title_devs[ i ],
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
786 (int)offset, DVDINPUT_NOFLAGS );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
787 if( off < 0 || off != (int)offset ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
788 fprintf( stderr, "libdvdread: Can't seek to block %d\n",
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
789 offset );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
790 return off < 0 ? off : 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
791 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
792 ret = DVDinput_read( dvd_file->title_devs[ i ], data,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
793 (int)part1_size, encrypted );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
794 if( ret < 0 ) return ret;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
795 /* FIXME: This is wrong if i is the last file in the set.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
796 * also error from this read will not show in ret. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
797
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
798 /* Read part 2 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
799 off = DVDinput_seek( dvd_file->title_devs[ i + 1 ],
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
800 0, DVDINPUT_NOFLAGS );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
801 if( off < 0 || off != 0 ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
802 fprintf( stderr, "libdvdread: Can't seek to block %d\n",
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
803 0 );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
804 return off < 0 ? off : 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
805 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
806 ret2 = DVDinput_read( dvd_file->title_devs[ i + 1 ],
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
807 data + ( part1_size
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
808 * (int64_t)DVD_VIDEO_LB_LEN ),
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
809 (int)(block_count - part1_size),
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
810 encrypted );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
811 if( ret2 < 0 ) return ret2;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
812 break;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
813 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
814 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
815 offset -= dvd_file->title_sizes[ i ];
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
816 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
817 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
818
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
819 return ret + ret2;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
820 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
821
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
822 /* This is broken reading more than 2Gb at a time is ssize_t is 32-bit. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
823 ssize_t DVDReadBlocks( dvd_file_t *dvd_file, int offset,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
824 size_t block_count, unsigned char *data )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
825 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
826 int ret;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
827
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
828 /* Hack, and it will still fail for multiple opens in a threaded app ! */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
829 if( dvd_file->dvd->css_title != dvd_file->css_title ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
830 dvd_file->dvd->css_title = dvd_file->css_title;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
831 if( dvd_file->dvd->isImageFile ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
832 DVDinput_title( dvd_file->dvd->dev, (int)dvd_file->lb_start );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
833 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
834 DVDinput_title( dvd_file->title_devs[ 0 ], (int)dvd_file->lb_start );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
835 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
836 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
837
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
838 if( dvd_file->dvd->isImageFile ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
839 ret = DVDReadBlocksUDF( dvd_file, (uint32_t)offset,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
840 block_count, data, DVDINPUT_READ_DECRYPT );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
841 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
842 ret = DVDReadBlocksPath( dvd_file, (unsigned int)offset,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
843 block_count, data, DVDINPUT_READ_DECRYPT );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
844 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
845
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
846 return (ssize_t)ret;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
847 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
848
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
849 int32_t DVDFileSeek( dvd_file_t *dvd_file, int32_t offset )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
850 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
851 if( offset > dvd_file->filesize * DVD_VIDEO_LB_LEN ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
852 return -1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
853 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
854 dvd_file->seek_pos = (uint32_t) offset;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
855 return offset;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
856 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
857
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
858 ssize_t DVDReadBytes( dvd_file_t *dvd_file, void *data, size_t byte_size )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
859 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
860 unsigned char *secbuf;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
861 unsigned int numsec, seek_sector, seek_byte;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
862 int ret;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
863
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
864 seek_sector = dvd_file->seek_pos / DVD_VIDEO_LB_LEN;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
865 seek_byte = dvd_file->seek_pos % DVD_VIDEO_LB_LEN;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
866
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
867 numsec = ( ( seek_byte + byte_size ) / DVD_VIDEO_LB_LEN ) + 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
868 secbuf = (unsigned char *) malloc( numsec * DVD_VIDEO_LB_LEN );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
869 if( !secbuf ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
870 fprintf( stderr, "libdvdread: Can't allocate memory "
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
871 "for file read!\n" );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
872 return 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
873 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
874
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
875 if( dvd_file->dvd->isImageFile ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
876 ret = DVDReadBlocksUDF( dvd_file, (uint32_t) seek_sector,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
877 (size_t) numsec, secbuf, DVDINPUT_NOFLAGS );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
878 } else {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
879 ret = DVDReadBlocksPath( dvd_file, seek_sector,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
880 (size_t) numsec, secbuf, DVDINPUT_NOFLAGS );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
881 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
882
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
883 if( ret != (int) numsec ) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
884 free( secbuf );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
885 return ret < 0 ? ret : 0;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
886 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
887
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
888 memcpy( data, &(secbuf[ seek_byte ]), byte_size );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
889 free( secbuf );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
890
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
891 dvd_file->seek_pos += byte_size;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
892 return byte_size;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
893 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
894
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
895 ssize_t DVDFileSize( dvd_file_t *dvd_file )
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
896 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
897 return dvd_file->filesize;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
898 }