annotate libmpdvdkit2/dvd_input.c @ 19261:46512ecfc11e

LRMI has been removed some time ago.
author diego
date Sun, 30 Jul 2006 21:35:15 +0000
parents 0783dd397f74
children e5d97c5f3c32
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) 2002 Samuel Hocevar <sam@zoy.org>,
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 *
14938
25df9508f9a8 Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents: 14607
diff changeset
5 * Modified for use with MPlayer, changes contained in libdvdread_changes.diff.
18783
0783dd397f74 CVS --> Subversion in copyright notices
diego
parents: 17786
diff changeset
6 * detailed changelog at http://svn.mplayerhq.hu/mplayer/trunk/
14938
25df9508f9a8 Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents: 14607
diff changeset
7 * $Id$
25df9508f9a8 Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents: 14607
diff changeset
8 *
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
12 * (at your option) any later version.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
13 *
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
17 * GNU General Public License for more details.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
18 *
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
20 * along with this program; if not, write to the Free Software
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
22 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
23
15874
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
24 #include "config.h"
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
25
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
26 #include <stdio.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
27 #include <stdlib.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
28 #include <fcntl.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
29 #include <unistd.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
30
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
31 #include "dvd_reader.h"
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
32 #include "dvd_input.h"
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
33
15874
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
34 /* The function pointers that is the exported interface of this file. */
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
35 dvd_input_t (*dvdinput_open) (const char *);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
36 int (*dvdinput_close) (dvd_input_t);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
37 int (*dvdinput_seek) (dvd_input_t, int);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
38 int (*dvdinput_title) (dvd_input_t, int);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
39 int (*dvdinput_read) (dvd_input_t, void *, int, int);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
40 char * (*dvdinput_error) (dvd_input_t);
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
41
15874
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
42 #ifdef HAVE_DVDCSS_DVDCSS_H
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
43 /* linking to libdvdcss */
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
44 #include "dvdcss.h"
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
45 #define DVDcss_open(a) dvdcss_open((char*)(a))
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
46 #define DVDcss_close dvdcss_close
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
47 #define DVDcss_seek dvdcss_seek
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
48 #define DVDcss_title dvdcss_title
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
49 #define DVDcss_read dvdcss_read
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
50 #define DVDcss_error dvdcss_error
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
51 #else
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
52 /* dlopening libdvdcss */
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
53 #include <dlfcn.h>
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
54 typedef struct dvdcss_s *dvdcss_handle;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
55 static dvdcss_handle (*DVDcss_open) (const char *);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
56 static int (*DVDcss_close) (dvdcss_handle);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
57 static int (*DVDcss_seek) (dvdcss_handle, int, int);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
58 static int (*DVDcss_title) (dvdcss_handle, int);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
59 static int (*DVDcss_read) (dvdcss_handle, void *, int, int);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
60 static char * (*DVDcss_error) (dvdcss_handle);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
61 #endif
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
62
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
63 /* The DVDinput handle, add stuff here for new input methods. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
64 struct dvd_input_s {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
65 /* libdvdcss handle */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
66 dvdcss_handle dvdcss;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
67
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
68 /* dummy file input */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
69 int fd;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
70 };
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
71
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
72
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
73 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
74 * initialize and open a DVD device or file.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
75 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
76 static dvd_input_t css_open(const char *target)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
77 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
78 dvd_input_t dev;
15874
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
79
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
80 /* Allocate the handle structure */
11776
12615e408fb9 Fix (possible) memory corruption. dvd_input_t is pointer to struct dvd_input_s and not a struct.
lumag
parents: 7033
diff changeset
81 dev = (dvd_input_t) malloc(sizeof(struct dvd_input_s));
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
82 if(dev == NULL) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
83 fprintf(stderr, "libdvdread: Could not allocate memory.\n");
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
84 return NULL;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
85 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
86
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
87 /* Really open it with libdvdcss */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
88 dev->dvdcss = DVDcss_open(target);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
89 if(dev->dvdcss == 0) {
15874
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
90 fprintf(stderr, "libdvdread: Could not open %s with libdvdcss.\n", target);
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
91 free(dev);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
92 return NULL;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
93 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
94
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
95 return dev;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
96 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
97
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
98 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
99 * return the last error message
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
100 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
101 static char *css_error(dvd_input_t dev)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
102 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
103 return DVDcss_error(dev->dvdcss);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
104 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
105
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
106 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
107 * seek into the device.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
108 */
15874
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
109 static int css_seek(dvd_input_t dev, int blocks)
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
110 {
15874
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
111 /* DVDINPUT_NOFLAGS should match the DVDCSS_NOFLAGS value. */
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
112 return DVDcss_seek(dev->dvdcss, blocks, DVDINPUT_NOFLAGS);
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
113 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
114
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
115 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
116 * set the block for the begining of a new title (key).
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
117 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
118 static int css_title(dvd_input_t dev, int block)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
119 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
120 return DVDcss_title(dev->dvdcss, block);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
121 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
122
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
123 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
124 * read data from the device.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
125 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
126 static int css_read(dvd_input_t dev, void *buffer, int blocks, int flags)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
127 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
128 return DVDcss_read(dev->dvdcss, buffer, blocks, flags);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
129 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
130
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
131 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
132 * close the DVD device and clean up the library.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
133 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
134 static int css_close(dvd_input_t dev)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
135 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
136 int ret;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
137
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
138 ret = DVDcss_close(dev->dvdcss);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
139
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
140 if(ret < 0)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
141 return ret;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
142
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
143 free(dev);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
144
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
145 return 0;
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
15874
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
150
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
151
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
152
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
153 /**
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
154 * initialize and open a DVD device or file.
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
155 */
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
156 static dvd_input_t file_open(const char *target)
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
157 {
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
158 dvd_input_t dev;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
159
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
160 /* Allocate the library structure */
17786
f0f54034c7e9 fix another sizeof(dvd_input_t) bug (must be struct dvd_input_s instead)
reimar
parents: 15874
diff changeset
161 dev = (dvd_input_t) malloc(sizeof(struct dvd_input_s));
15874
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
162 if(dev == NULL) {
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
163 fprintf(stderr, "libdvdread: Could not allocate memory.\n");
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
164 return NULL;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
165 }
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
166
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
167 /* Open the device */
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
168 dev->fd = open(target, O_RDONLY);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
169 if(dev->fd < 0) {
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
170 perror("libdvdread: Could not open input");
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
171 free(dev);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
172 return NULL;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
173 }
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
174
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
175 return dev;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
176 }
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
177
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
178 /**
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
179 * return the last error message
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
180 */
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
181 static char *file_error(dvd_input_t dev)
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
182 {
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
183 /* use strerror(errno)? */
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
184 return (char *)"unknown error";
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
185 }
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
186
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
187 /**
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
188 * seek into the device.
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
189 */
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
190 static int file_seek(dvd_input_t dev, int blocks)
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
191 {
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
192 off_t pos;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
193
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
194 pos = lseek(dev->fd, (off_t)blocks * (off_t)DVD_VIDEO_LB_LEN, SEEK_SET);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
195 if(pos < 0) {
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
196 return pos;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
197 }
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
198 /* assert pos % DVD_VIDEO_LB_LEN == 0 */
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
199 return (int) (pos / DVD_VIDEO_LB_LEN);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
200 }
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
201
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
202 /**
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
203 * set the block for the begining of a new title (key).
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
204 */
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
205 static int file_title(dvd_input_t dev, int block)
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
206 {
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
207 return -1;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
208 }
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
209
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
210 /**
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
211 * read data from the device.
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
212 */
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
213 static int file_read(dvd_input_t dev, void *buffer, int blocks, int flags)
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
214 {
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
215 size_t len;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
216 ssize_t ret;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
217
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
218 len = (size_t)blocks * DVD_VIDEO_LB_LEN;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
219
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
220 while(len > 0) {
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
221
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
222 ret = read(dev->fd, buffer, len);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
223
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
224 if(ret < 0) {
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
225 /* One of the reads failed, too bad. We won't even bother
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
226 * returning the reads that went ok, and as in the posix spec
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
227 * the file postition is left unspecified after a failure. */
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
228 return ret;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
229 }
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
230
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
231 if(ret == 0) {
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
232 /* Nothing more to read. Return the whole blocks, if any, that we got.
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
233 and adjust the file possition back to the previous block boundary. */
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
234 size_t bytes = (size_t)blocks * DVD_VIDEO_LB_LEN - len;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
235 off_t over_read = -(bytes % DVD_VIDEO_LB_LEN);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
236 /*off_t pos =*/ lseek(dev->fd, over_read, SEEK_CUR);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
237 /* should have pos % 2048 == 0 */
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
238 return (int) (bytes / DVD_VIDEO_LB_LEN);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
239 }
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
240
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
241 len -= ret;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
242 }
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
243
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
244 return blocks;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
245 }
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
246
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
247 /**
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
248 * close the DVD device and clean up.
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
249 */
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
250 static int file_close(dvd_input_t dev)
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
251 {
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
252 int ret;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
253
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
254 ret = close(dev->fd);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
255
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
256 if(ret < 0)
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
257 return ret;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
258
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
259 free(dev);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
260
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
261 return 0;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
262 }
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
263
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
264
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
265 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
266 * Setup read functions with either libdvdcss or minimal DVD access.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
267 */
15874
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
268 int dvdinput_setup(void)
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
269 {
15874
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
270 void *dvdcss_library = NULL;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
271 char **dvdcss_version = NULL;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
272
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
273 #ifdef HAVE_DVDCSS_DVDCSS_H
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
274 /* linking to libdvdcss */
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
275 dvdcss_library = &dvdcss_library; /* Give it some value != NULL */
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
276 /* the DVDcss_* functions have been #defined at the top */
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
277 dvdcss_version = &dvdcss_interface_2;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
278
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
279 #else
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
280 /* dlopening libdvdcss */
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
281 dvdcss_library = dlopen("libdvdcss.so.2", RTLD_LAZY);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
282
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
283 if(dvdcss_library != NULL) {
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
284 #if defined(__OpenBSD__) && !defined(__ELF__)
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
285 #define U_S "_"
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
286 #else
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
287 #define U_S
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
288 #endif
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
289 DVDcss_open = (dvdcss_handle (*)(const char*))
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
290 dlsym(dvdcss_library, U_S "dvdcss_open");
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
291 DVDcss_close = (int (*)(dvdcss_handle))
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
292 dlsym(dvdcss_library, U_S "dvdcss_close");
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
293 DVDcss_title = (int (*)(dvdcss_handle, int))
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
294 dlsym(dvdcss_library, U_S "dvdcss_title");
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
295 DVDcss_seek = (int (*)(dvdcss_handle, int, int))
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
296 dlsym(dvdcss_library, U_S "dvdcss_seek");
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
297 DVDcss_read = (int (*)(dvdcss_handle, void*, int, int))
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
298 dlsym(dvdcss_library, U_S "dvdcss_read");
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
299 DVDcss_error = (char* (*)(dvdcss_handle))
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
300 dlsym(dvdcss_library, U_S "dvdcss_error");
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
301
15874
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
302 dvdcss_version = (char **)dlsym(dvdcss_library, U_S "dvdcss_interface_2");
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
303
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
304 if(dlsym(dvdcss_library, U_S "dvdcss_crack")) {
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
305 fprintf(stderr,
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
306 "libdvdread: Old (pre-0.0.2) version of libdvdcss found.\n"
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
307 "libdvdread: You should get the latest version from "
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
308 "http://www.videolan.org/\n" );
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
309 dlclose(dvdcss_library);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
310 dvdcss_library = NULL;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
311 } else if(!DVDcss_open || !DVDcss_close || !DVDcss_title || !DVDcss_seek
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
312 || !DVDcss_read || !DVDcss_error || !dvdcss_version) {
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
313 fprintf(stderr, "libdvdread: Missing symbols in libdvdcss.so.2, "
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
314 "this shouldn't happen !\n");
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
315 dlclose(dvdcss_library);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
316 }
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
317 }
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
318 #endif /* HAVE_DVDCSS_DVDCSS_H */
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
319
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
320 if(dvdcss_library != NULL) {
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
321 /*
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
322 char *psz_method = getenv( "DVDCSS_METHOD" );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
323 char *psz_verbose = getenv( "DVDCSS_VERBOSE" );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
324 fprintf(stderr, "DVDCSS_METHOD %s\n", psz_method);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
325 fprintf(stderr, "DVDCSS_VERBOSE %s\n", psz_verbose);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
326 */
15874
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
327 /*
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
328 fprintf(stderr, "libdvdread: Using libdvdcss version %s for DVD access\n",
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
329 *dvdcss_version);
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
330 */
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
331
15874
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
332 /* libdvdcss wrapper functions */
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
333 dvdinput_open = css_open;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
334 dvdinput_close = css_close;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
335 dvdinput_seek = css_seek;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
336 dvdinput_title = css_title;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
337 dvdinput_read = css_read;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
338 dvdinput_error = css_error;
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
339 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
340
15874
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
341 } else {
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
342 fprintf(stderr, "libdvdread: Encrypted DVD support unavailable.\n");
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
343
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
344 /* libdvdcss replacement functions */
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
345 dvdinput_open = file_open;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
346 dvdinput_close = file_close;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
347 dvdinput_seek = file_seek;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
348 dvdinput_title = file_title;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
349 dvdinput_read = file_read;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
350 dvdinput_error = file_error;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
351 return 0;
483e955893b8 update libdvdread to v0.9.4
aurel
parents: 14938
diff changeset
352 }
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
353 }