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