Mercurial > mplayer.hg
annotate libmpdvdkit2/dvd_input.c @ 15774:ed3fec6506c4
Fix off_t on OSX, thanks to Steven M. Schultz
author | ranma |
---|---|
date | Mon, 20 Jun 2005 00:30:18 +0000 |
parents | 25df9508f9a8 |
children | 483e955893b8 |
rev | line source |
---|---|
7029 | 1 /* |
2 * Copyright (C) 2002 Samuel Hocevar <sam@zoy.org>, | |
3 * Håkan Hjort <d95hjort@dtek.chalmers.se> | |
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. |
25df9508f9a8
Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents:
14607
diff
changeset
|
6 * detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/ |
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 | 9 * This program is free software; you can redistribute it and/or modify |
10 * it under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2 of the License, or | |
12 * (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. | |
22 */ | |
23 | |
24 #include <stdio.h> | |
25 #include <stdlib.h> | |
26 #include <fcntl.h> | |
27 #include <unistd.h> | |
28 | |
29 #include "dvd_reader.h" | |
30 #include "dvd_input.h" | |
31 | |
7033 | 32 #include "dvdcss.h" |
7029 | 33 |
34 dvdcss_handle (*DVDcss_open) (const char *); | |
35 int (*DVDcss_close) (dvdcss_handle); | |
36 int (*DVDcss_seek) (dvdcss_handle, int, int); | |
37 int (*DVDcss_title) (dvdcss_handle, int); | |
38 int (*DVDcss_read) (dvdcss_handle, void *, int, int); | |
39 char * (*DVDcss_error) (dvdcss_handle); | |
40 | |
14607
7a80c6ac5058
several sets of headers declare global variables in them, which causes multiple definition errors with gcc 4.x
iive
parents:
11776
diff
changeset
|
41 dvd_input_t (*DVDinput_open) (const char *); |
7a80c6ac5058
several sets of headers declare global variables in them, which causes multiple definition errors with gcc 4.x
iive
parents:
11776
diff
changeset
|
42 int (*DVDinput_close) (dvd_input_t); |
7a80c6ac5058
several sets of headers declare global variables in them, which causes multiple definition errors with gcc 4.x
iive
parents:
11776
diff
changeset
|
43 int (*DVDinput_seek) (dvd_input_t, int, int); |
7a80c6ac5058
several sets of headers declare global variables in them, which causes multiple definition errors with gcc 4.x
iive
parents:
11776
diff
changeset
|
44 int (*DVDinput_title) (dvd_input_t, int); |
7a80c6ac5058
several sets of headers declare global variables in them, which causes multiple definition errors with gcc 4.x
iive
parents:
11776
diff
changeset
|
45 int (*DVDinput_read) (dvd_input_t, void *, int, int); |
7a80c6ac5058
several sets of headers declare global variables in them, which causes multiple definition errors with gcc 4.x
iive
parents:
11776
diff
changeset
|
46 char * (*DVDinput_error) (dvd_input_t); |
7029 | 47 |
48 /* The DVDinput handle, add stuff here for new input methods. */ | |
49 struct dvd_input_s { | |
50 /* libdvdcss handle */ | |
51 dvdcss_handle dvdcss; | |
52 | |
53 /* dummy file input */ | |
54 int fd; | |
55 }; | |
56 | |
57 | |
58 /** | |
59 * initialize and open a DVD device or file. | |
60 */ | |
61 static dvd_input_t css_open(const char *target) | |
62 { | |
63 dvd_input_t dev; | |
64 | |
65 /* 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
|
66 dev = (dvd_input_t) malloc(sizeof(struct dvd_input_s)); |
7029 | 67 if(dev == NULL) { |
68 fprintf(stderr, "libdvdread: Could not allocate memory.\n"); | |
69 return NULL; | |
70 } | |
71 | |
72 /* Really open it with libdvdcss */ | |
73 dev->dvdcss = DVDcss_open(target); | |
74 if(dev->dvdcss == 0) { | |
75 fprintf(stderr, "libdvdread: Could not open device with libdvdcss.\n"); | |
76 free(dev); | |
77 return NULL; | |
78 } | |
79 | |
80 return dev; | |
81 } | |
82 | |
83 /** | |
84 * return the last error message | |
85 */ | |
86 static char *css_error(dvd_input_t dev) | |
87 { | |
88 return DVDcss_error(dev->dvdcss); | |
89 } | |
90 | |
91 /** | |
92 * seek into the device. | |
93 */ | |
94 static int css_seek(dvd_input_t dev, int blocks, int flags) | |
95 { | |
96 return DVDcss_seek(dev->dvdcss, blocks, flags); | |
97 } | |
98 | |
99 /** | |
100 * set the block for the begining of a new title (key). | |
101 */ | |
102 static int css_title(dvd_input_t dev, int block) | |
103 { | |
104 return DVDcss_title(dev->dvdcss, block); | |
105 } | |
106 | |
107 /** | |
108 * read data from the device. | |
109 */ | |
110 static int css_read(dvd_input_t dev, void *buffer, int blocks, int flags) | |
111 { | |
112 return DVDcss_read(dev->dvdcss, buffer, blocks, flags); | |
113 } | |
114 | |
115 /** | |
116 * close the DVD device and clean up the library. | |
117 */ | |
118 static int css_close(dvd_input_t dev) | |
119 { | |
120 int ret; | |
121 | |
122 ret = DVDcss_close(dev->dvdcss); | |
123 | |
124 if(ret < 0) | |
125 return ret; | |
126 | |
127 free(dev); | |
128 | |
129 return 0; | |
130 } | |
131 | |
132 | |
133 | |
134 /** | |
135 * Setup read functions with either libdvdcss or minimal DVD access. | |
136 */ | |
137 int DVDInputSetup(void) | |
138 { | |
7033 | 139 DVDcss_open = dvdcss_open; |
140 DVDcss_close = dvdcss_close; | |
141 DVDcss_title = dvdcss_title; | |
142 DVDcss_seek = dvdcss_seek; | |
143 DVDcss_read = dvdcss_read; | |
144 DVDcss_error = dvdcss_error; | |
7029 | 145 |
146 /* | |
147 char *psz_method = getenv( "DVDCSS_METHOD" ); | |
148 char *psz_verbose = getenv( "DVDCSS_VERBOSE" ); | |
149 fprintf(stderr, "DVDCSS_METHOD %s\n", psz_method); | |
150 fprintf(stderr, "DVDCSS_VERBOSE %s\n", psz_verbose); | |
151 */ | |
7033 | 152 // fprintf(stderr, "libdvdread: Using libdvdcss version %s for DVD access\n", |
153 // *dvdcss_version); | |
7029 | 154 |
155 /* libdvdcss wraper functions */ | |
156 DVDinput_open = css_open; | |
157 DVDinput_close = css_close; | |
158 DVDinput_seek = css_seek; | |
159 DVDinput_title = css_title; | |
160 DVDinput_read = css_read; | |
161 DVDinput_error = css_error; | |
162 return 1; | |
163 | |
164 } |