annotate libmpdvdkit2/dvd_input.c @ 15347:18d404eebb28

do not define video_out_macosx if corevideo is not present
author nplourde
date Thu, 05 May 2005 00:17:27 +0000
parents 25df9508f9a8
children 483e955893b8
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.
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
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
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
24 #include <stdio.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
25 #include <stdlib.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
26 #include <fcntl.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
27 #include <unistd.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
28
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
29 #include "dvd_reader.h"
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
30 #include "dvd_input.h"
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
31
7033
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
32 #include "dvdcss.h"
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
33
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
34 dvdcss_handle (*DVDcss_open) (const char *);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
35 int (*DVDcss_close) (dvdcss_handle);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
36 int (*DVDcss_seek) (dvdcss_handle, int, int);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
37 int (*DVDcss_title) (dvdcss_handle, int);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
38 int (*DVDcss_read) (dvdcss_handle, void *, int, int);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
39 char * (*DVDcss_error) (dvdcss_handle);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
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
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
47
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
48 /* The DVDinput handle, add stuff here for new input methods. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
49 struct dvd_input_s {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
50 /* libdvdcss handle */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
51 dvdcss_handle dvdcss;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
52
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
53 /* dummy file input */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
54 int fd;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
55 };
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
56
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
57
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
58 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
59 * initialize and open a DVD device or file.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
60 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
61 static dvd_input_t css_open(const char *target)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
62 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
63 dvd_input_t dev;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
64
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
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
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
67 if(dev == NULL) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
68 fprintf(stderr, "libdvdread: Could not allocate memory.\n");
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
69 return NULL;
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 /* Really open it with libdvdcss */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
73 dev->dvdcss = DVDcss_open(target);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
74 if(dev->dvdcss == 0) {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
75 fprintf(stderr, "libdvdread: Could not open device with libdvdcss.\n");
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
76 free(dev);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
77 return NULL;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
78 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
79
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
80 return dev;
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 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
84 * return the last error message
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
85 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
86 static char *css_error(dvd_input_t dev)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
87 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
88 return DVDcss_error(dev->dvdcss);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
89 }
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
90
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
91 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
92 * seek into the device.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
93 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
94 static int css_seek(dvd_input_t dev, int blocks, int flags)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
95 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
96 return DVDcss_seek(dev->dvdcss, blocks, flags);
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 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
100 * set the block for the begining of a new title (key).
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
101 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
102 static int css_title(dvd_input_t dev, int block)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
103 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
104 return DVDcss_title(dev->dvdcss, block);
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 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
108 * read data from the device.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
109 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
110 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
111 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
112 return DVDcss_read(dev->dvdcss, buffer, blocks, flags);
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 * close the DVD device and clean up the library.
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_close(dvd_input_t dev)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
119 {
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
120 int ret;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
121
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
122 ret = DVDcss_close(dev->dvdcss);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
123
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
124 if(ret < 0)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
125 return ret;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
126
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
127 free(dev);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
128
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
129 return 0;
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
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
133
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
134 /**
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
135 * Setup read functions with either libdvdcss or minimal DVD access.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
136 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
137 int DVDInputSetup(void)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
138 {
7033
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
139 DVDcss_open = dvdcss_open;
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
140 DVDcss_close = dvdcss_close;
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
141 DVDcss_title = dvdcss_title;
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
142 DVDcss_seek = dvdcss_seek;
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
143 DVDcss_read = dvdcss_read;
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
144 DVDcss_error = dvdcss_error;
7029
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 char *psz_method = getenv( "DVDCSS_METHOD" );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
148 char *psz_verbose = getenv( "DVDCSS_VERBOSE" );
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
149 fprintf(stderr, "DVDCSS_METHOD %s\n", psz_method);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
150 fprintf(stderr, "DVDCSS_VERBOSE %s\n", psz_verbose);
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
151 */
7033
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
152 // fprintf(stderr, "libdvdread: Using libdvdcss version %s for DVD access\n",
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
153 // *dvdcss_version);
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
154
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
155 /* libdvdcss wraper functions */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
156 DVDinput_open = css_open;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
157 DVDinput_close = css_close;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
158 DVDinput_seek = css_seek;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
159 DVDinput_title = css_title;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
160 DVDinput_read = css_read;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
161 DVDinput_error = css_error;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
162 return 1;
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
163
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
164 }