annotate libmpdvdkit2/dvd_input.c @ 7423:ad967766679a

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