annotate dvd_input.c @ 83:bed968b9bd99 src

If the start offset points past the last_byte (outside the region read) stop reading PTTs and adjust nr_of_srpts. Fixes Transformers 3 and Cars 2. Patch by John Stebbins ^stebbins*jetheaddev+com/
author rathann
date Thu, 03 Oct 2013 21:57:48 +0000
parents aa4a7b151801
children 4cbc44b20dfe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
1 /*
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
2 * Copyright (C) 2002 Samuel Hocevar <sam@zoy.org>,
22
447c5319a522 Convert all ISO8859-1 sequences to proper UTF-8.
diego
parents: 21
diff changeset
3 * HÃ¥kan Hjort <d95hjort@dtek.chalmers.se>
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
4 *
21
4aa618ae094f Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents: 20
diff changeset
5 * This file is part of libdvdread.
4aa618ae094f Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents: 20
diff changeset
6 *
4aa618ae094f Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents: 20
diff changeset
7 * libdvdread is free software; you can redistribute it and/or modify
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
10 * (at your option) any later version.
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 19
diff changeset
11 *
21
4aa618ae094f Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents: 20
diff changeset
12 * libdvdread is distributed in the hope that it will be useful,
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
15 * GNU General Public License for more details.
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
16 *
21
4aa618ae094f Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents: 20
diff changeset
17 * You should have received a copy of the GNU General Public License along
4aa618ae094f Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents: 20
diff changeset
18 * with libdvdread; if not, write to the Free Software Foundation, Inc.,
4aa618ae094f Use consistent license headers everywhere: Fix FSF address and boilerplate.
diego
parents: 20
diff changeset
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
20 */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
21
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
22 #include <stdio.h>
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
23 #include <stdlib.h>
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
24 #include <fcntl.h>
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
25 #include <unistd.h>
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
26
39
caef08851d58 Add #include for config.h. Several preprocessor definitions were used without
diego
parents: 38
diff changeset
27 #include "config.h"
33
c743d79f187b Move installed headers into dvdread directory to make them easier to
reimar
parents: 30
diff changeset
28 #include "dvdread/dvd_reader.h"
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
29 #include "dvd_input.h"
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
30
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
31
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
32 /* The function pointers that is the exported interface of this file. */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
33 dvd_input_t (*dvdinput_open) (const char *);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
34 int (*dvdinput_close) (dvd_input_t);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
35 int (*dvdinput_seek) (dvd_input_t, int);
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 19
diff changeset
36 int (*dvdinput_title) (dvd_input_t, int);
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
37 int (*dvdinput_read) (dvd_input_t, void *, int, int);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
38 char * (*dvdinput_error) (dvd_input_t);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
39
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
40 #ifdef HAVE_DVDCSS_DVDCSS_H
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
41 /* linking to libdvdcss */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
42 #include <dvdcss/dvdcss.h>
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
43 #define DVDcss_open(a) dvdcss_open((char*)(a))
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
44 #define DVDcss_close dvdcss_close
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
45 #define DVDcss_seek dvdcss_seek
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
46 #define DVDcss_read dvdcss_read
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
47 #define DVDcss_error dvdcss_error
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
48 #else
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
49
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
50 /* dlopening libdvdcss */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
51 #ifdef HAVE_DLFCN_H
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
52 #include <dlfcn.h>
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
53 #else
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
54 /* Only needed on MINGW at the moment */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
55 #include "../../msvc/contrib/dlfcn.c"
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
56 #endif
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
57
79
dbfcd120bf24 Replace uses of the deprecated dvdcss_handle type by dvdcss_t.
diego
parents: 40
diff changeset
58 typedef struct dvdcss_s *dvdcss_t;
dbfcd120bf24 Replace uses of the deprecated dvdcss_handle type by dvdcss_t.
diego
parents: 40
diff changeset
59 static dvdcss_t (*DVDcss_open) (const char *);
dbfcd120bf24 Replace uses of the deprecated dvdcss_handle type by dvdcss_t.
diego
parents: 40
diff changeset
60 static int (*DVDcss_close) (dvdcss_t);
dbfcd120bf24 Replace uses of the deprecated dvdcss_handle type by dvdcss_t.
diego
parents: 40
diff changeset
61 static int (*DVDcss_seek) (dvdcss_t, int, int);
dbfcd120bf24 Replace uses of the deprecated dvdcss_handle type by dvdcss_t.
diego
parents: 40
diff changeset
62 static int (*DVDcss_read) (dvdcss_t, void *, int, int);
dbfcd120bf24 Replace uses of the deprecated dvdcss_handle type by dvdcss_t.
diego
parents: 40
diff changeset
63 static char * (*DVDcss_error) (dvdcss_t);
82
aa4a7b151801 Add #define for DVDCSS_SEEK_KEY to allow compilation without dvdcss.h.
diego
parents: 81
diff changeset
64 #define DVDCSS_SEEK_KEY (1 << 1)
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
65 #endif
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
66
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
67 /* The DVDinput handle, add stuff here for new input methods. */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
68 struct dvd_input_s {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
69 /* libdvdcss handle */
79
dbfcd120bf24 Replace uses of the deprecated dvdcss_handle type by dvdcss_t.
diego
parents: 40
diff changeset
70 dvdcss_t dvdcss;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 19
diff changeset
71
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
72 /* dummy file input */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
73 int fd;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
74 };
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
75
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
76
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
77 /**
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
78 * initialize and open a DVD device or file.
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
79 */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
80 static dvd_input_t css_open(const char *target)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
81 {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
82 dvd_input_t dev;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 19
diff changeset
83
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
84 /* Allocate the handle structure */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
85 dev = (dvd_input_t) malloc(sizeof(*dev));
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
86 if(dev == NULL) {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
87 fprintf(stderr, "libdvdread: Could not allocate memory.\n");
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
88 return NULL;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
89 }
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 19
diff changeset
90
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
91 /* Really open it with libdvdcss */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
92 dev->dvdcss = DVDcss_open(target);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
93 if(dev->dvdcss == 0) {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
94 fprintf(stderr, "libdvdread: Could not open %s with libdvdcss.\n", target);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
95 free(dev);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
96 return NULL;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
97 }
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 19
diff changeset
98
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
99 return dev;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
100 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
101
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
102 /**
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
103 * return the last error message
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
104 */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
105 static char *css_error(dvd_input_t dev)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
106 {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
107 return DVDcss_error(dev->dvdcss);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
108 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
109
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
110 /**
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
111 * seek into the device.
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
112 */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
113 static int css_seek(dvd_input_t dev, int blocks)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
114 {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
115 /* DVDINPUT_NOFLAGS should match the DVDCSS_NOFLAGS value. */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
116 return DVDcss_seek(dev->dvdcss, blocks, DVDINPUT_NOFLAGS);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
117 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
118
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
119 /**
18
2a219d444297 Comments cleanup: fix spelling and grammar errors.
rathann
parents: 3
diff changeset
120 * set the block for the beginning of a new title (key).
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
121 */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
122 static int css_title(dvd_input_t dev, int block)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
123 {
80
d59aaee50e47 Replace deprecated dvdcss_title() function by dvdcss_seek().
diego
parents: 79
diff changeset
124 return DVDcss_seek(dev->dvdcss, block, DVDCSS_SEEK_KEY);
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
125 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
126
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
127 /**
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
128 * read data from the device.
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
129 */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
130 static int css_read(dvd_input_t dev, void *buffer, int blocks, int flags)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
131 {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
132 return DVDcss_read(dev->dvdcss, buffer, blocks, flags);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
133 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
134
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
135 /**
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
136 * close the DVD device and clean up the library.
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
137 */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
138 static int css_close(dvd_input_t dev)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
139 {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
140 int ret;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
141
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
142 ret = DVDcss_close(dev->dvdcss);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
143
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
144 if(ret < 0)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
145 return ret;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
146
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
147 free(dev);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
148
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
149 return 0;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
150 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
151
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
152 /**
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
153 * initialize and open a DVD device or file.
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
154 */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
155 static dvd_input_t file_open(const char *target)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
156 {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
157 dvd_input_t dev;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 19
diff changeset
158
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
159 /* Allocate the library structure */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
160 dev = (dvd_input_t) malloc(sizeof(*dev));
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
161 if(dev == NULL) {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
162 fprintf(stderr, "libdvdread: Could not allocate memory.\n");
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
163 return NULL;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
164 }
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 19
diff changeset
165
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
166 /* Open the device */
40
ce7056d60f01 in OS/2 the device must be opened in binary mode; patch by KO Myung-Hun - komh chollian net
nicodvb
parents: 39
diff changeset
167 #if !defined(WIN32) && !defined(__OS2__)
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
168 dev->fd = open(target, O_RDONLY);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
169 #else
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
170 dev->fd = open(target, O_RDONLY | O_BINARY);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
171 #endif
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
172 if(dev->fd < 0) {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
173 perror("libdvdread: Could not open input");
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
174 free(dev);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
175 return NULL;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
176 }
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 19
diff changeset
177
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
178 return dev;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
179 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
180
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
181 /**
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
182 * return the last error message
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
183 */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
184 static char *file_error(dvd_input_t dev)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
185 {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
186 /* use strerror(errno)? */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
187 return (char *)"unknown error";
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
188 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
189
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
190 /**
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
191 * seek into the device.
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
192 */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
193 static int file_seek(dvd_input_t dev, int blocks)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
194 {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
195 off_t pos;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
196
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
197 pos = lseek(dev->fd, (off_t)blocks * (off_t)DVD_VIDEO_LB_LEN, SEEK_SET);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
198 if(pos < 0) {
27
98951f8ec89c cosmetics: Sync indentation and similar changes from libdvdread 0.9.5.
diego
parents: 26
diff changeset
199 return pos;
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
200 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
201 /* assert pos % DVD_VIDEO_LB_LEN == 0 */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
202 return (int) (pos / DVD_VIDEO_LB_LEN);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
203 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
204
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
205 /**
18
2a219d444297 Comments cleanup: fix spelling and grammar errors.
rathann
parents: 3
diff changeset
206 * set the block for the beginning of a new title (key).
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
207 */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
208 static int file_title(dvd_input_t dev, int block)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
209 {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
210 return -1;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
211 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
212
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
213 /**
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
214 * read data from the device.
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
215 */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
216 static int file_read(dvd_input_t dev, void *buffer, int blocks, int flags)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
217 {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
218 size_t len;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
219 ssize_t ret;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 19
diff changeset
220
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
221 len = (size_t)blocks * DVD_VIDEO_LB_LEN;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 19
diff changeset
222
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
223 while(len > 0) {
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 19
diff changeset
224
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
225 ret = read(dev->fd, buffer, len);
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 19
diff changeset
226
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
227 if(ret < 0) {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
228 /* One of the reads failed, too bad. We won't even bother
18
2a219d444297 Comments cleanup: fix spelling and grammar errors.
rathann
parents: 3
diff changeset
229 * returning the reads that went OK, and as in the POSIX spec
2a219d444297 Comments cleanup: fix spelling and grammar errors.
rathann
parents: 3
diff changeset
230 * the file position is left unspecified after a failure. */
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
231 return ret;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
232 }
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 19
diff changeset
233
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
234 if(ret == 0) {
18
2a219d444297 Comments cleanup: fix spelling and grammar errors.
rathann
parents: 3
diff changeset
235 /* Nothing more to read. Return all of the whole blocks, if any.
2a219d444297 Comments cleanup: fix spelling and grammar errors.
rathann
parents: 3
diff changeset
236 * Adjust the file position back to the previous block boundary. */
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
237 size_t bytes = (size_t)blocks * DVD_VIDEO_LB_LEN - len;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
238 off_t over_read = -(bytes % DVD_VIDEO_LB_LEN);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
239 /*off_t pos =*/ lseek(dev->fd, over_read, SEEK_CUR);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
240 /* should have pos % 2048 == 0 */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
241 return (int) (bytes / DVD_VIDEO_LB_LEN);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
242 }
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 19
diff changeset
243
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
244 len -= ret;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
245 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
246
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
247 return blocks;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
248 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
249
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
250 /**
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
251 * close the DVD device and clean up.
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
252 */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
253 static int file_close(dvd_input_t dev)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
254 {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
255 int ret;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
256
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
257 ret = close(dev->fd);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
258
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
259 if(ret < 0)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
260 return ret;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
261
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
262 free(dev);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
263
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
264 return 0;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
265 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
266
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
267
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
268 /**
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
269 * Setup read functions with either libdvdcss or minimal DVD access.
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
270 */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
271 int dvdinput_setup(void)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
272 {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
273 void *dvdcss_library = NULL;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
274
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
275 #ifdef HAVE_DVDCSS_DVDCSS_H
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
276 /* linking to libdvdcss */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
277 dvdcss_library = &dvdcss_library; /* Give it some value != NULL */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
278
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
279 #else
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
280 /* dlopening libdvdcss */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
281
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
282 #ifdef __APPLE__
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
283 #define CSS_LIB "libdvdcss.2.dylib"
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
284 #elif defined(WIN32)
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
285 #define CSS_LIB "libdvdcss.dll"
30
80045db7439a OS/2 support by KO Myung-Hun, komh chollian net
diego
parents: 27
diff changeset
286 #elif defined(__OS2__)
80045db7439a OS/2 support by KO Myung-Hun, komh chollian net
diego
parents: 27
diff changeset
287 #define CSS_LIB "dvdcss.dll"
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
288 #else
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
289 #define CSS_LIB "libdvdcss.so.2"
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
290 #endif
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
291 dvdcss_library = dlopen(CSS_LIB, RTLD_LAZY);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
292
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
293 if(dvdcss_library != NULL) {
30
80045db7439a OS/2 support by KO Myung-Hun, komh chollian net
diego
parents: 27
diff changeset
294 #if defined(__OpenBSD__) && !defined(__ELF__) || defined(__OS2__)
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
295 #define U_S "_"
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
296 #else
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
297 #define U_S
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
298 #endif
79
dbfcd120bf24 Replace uses of the deprecated dvdcss_handle type by dvdcss_t.
diego
parents: 40
diff changeset
299 DVDcss_open = (dvdcss_t (*)(const char*))
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
300 dlsym(dvdcss_library, U_S "dvdcss_open");
79
dbfcd120bf24 Replace uses of the deprecated dvdcss_handle type by dvdcss_t.
diego
parents: 40
diff changeset
301 DVDcss_close = (int (*)(dvdcss_t))
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
302 dlsym(dvdcss_library, U_S "dvdcss_close");
79
dbfcd120bf24 Replace uses of the deprecated dvdcss_handle type by dvdcss_t.
diego
parents: 40
diff changeset
303 DVDcss_seek = (int (*)(dvdcss_t, int, int))
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
304 dlsym(dvdcss_library, U_S "dvdcss_seek");
79
dbfcd120bf24 Replace uses of the deprecated dvdcss_handle type by dvdcss_t.
diego
parents: 40
diff changeset
305 DVDcss_read = (int (*)(dvdcss_t, void*, int, int))
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
306 dlsym(dvdcss_library, U_S "dvdcss_read");
79
dbfcd120bf24 Replace uses of the deprecated dvdcss_handle type by dvdcss_t.
diego
parents: 40
diff changeset
307 DVDcss_error = (char* (*)(dvdcss_t))
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
308 dlsym(dvdcss_library, U_S "dvdcss_error");
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 19
diff changeset
309
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
310 if(dlsym(dvdcss_library, U_S "dvdcss_crack")) {
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 19
diff changeset
311 fprintf(stderr,
26
0d82d0f30c98 cosmetics: Convert all tabs to spaces.
diego
parents: 22
diff changeset
312 "libdvdread: Old (pre-0.0.2) version of libdvdcss found.\n"
0d82d0f30c98 cosmetics: Convert all tabs to spaces.
diego
parents: 22
diff changeset
313 "libdvdread: You should get the latest version from "
0d82d0f30c98 cosmetics: Convert all tabs to spaces.
diego
parents: 22
diff changeset
314 "http://www.videolan.org/\n" );
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
315 dlclose(dvdcss_library);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
316 dvdcss_library = NULL;
80
d59aaee50e47 Replace deprecated dvdcss_title() function by dvdcss_seek().
diego
parents: 79
diff changeset
317 } else if(!DVDcss_open || !DVDcss_close || !DVDcss_seek
81
7e9feef7a82d Do not extract libdvdcss version via dvdcss_interface_2.
diego
parents: 80
diff changeset
318 || !DVDcss_read || !DVDcss_error) {
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
319 fprintf(stderr, "libdvdread: Missing symbols in %s, "
26
0d82d0f30c98 cosmetics: Convert all tabs to spaces.
diego
parents: 22
diff changeset
320 "this shouldn't happen !\n", CSS_LIB);
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
321 dlclose(dvdcss_library);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
322 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
323 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
324 #endif /* HAVE_DVDCSS_DVDCSS_H */
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 19
diff changeset
325
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
326 if(dvdcss_library != NULL) {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
327 /*
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
328 char *psz_method = getenv( "DVDCSS_METHOD" );
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
329 char *psz_verbose = getenv( "DVDCSS_VERBOSE" );
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
330 fprintf(stderr, "DVDCSS_METHOD %s\n", psz_method);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
331 fprintf(stderr, "DVDCSS_VERBOSE %s\n", psz_verbose);
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
332 */
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 19
diff changeset
333
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
334 /* libdvdcss wrapper functions */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
335 dvdinput_open = css_open;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
336 dvdinput_close = css_close;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
337 dvdinput_seek = css_seek;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
338 dvdinput_title = css_title;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
339 dvdinput_read = css_read;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
340 dvdinput_error = css_error;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
341 return 1;
20
fce16251755c Remove all trailing whitespace,
rathann
parents: 19
diff changeset
342
3
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
343 } else {
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
344 fprintf(stderr, "libdvdread: Encrypted DVD support unavailable.\n");
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
345
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
346 /* libdvdcss replacement functions */
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
347 dvdinput_open = file_open;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
348 dvdinput_close = file_close;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
349 dvdinput_seek = file_seek;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
350 dvdinput_title = file_title;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
351 dvdinput_read = file_read;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
352 dvdinput_error = file_error;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
353 return 0;
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
354 }
fdbae45c30fc moved to src/ the sources files
nicodvb
parents:
diff changeset
355 }