Mercurial > mplayer.hg
annotate libmpdvdkit2/dvd_input.c @ 13394:455a5056801f
New generic 'portable anymap' video output driver. It supports portable
pixmaps and graymaps in both raw and ASCII mode. Besides PPM and PGM, it
can also output PGMYUV files which are PGM files with the U and V plane
appended to the bottom of the Y image (bottom left and bottom right). All
files can be written to the current directory, to a specified output directory
or to multiple subdirectories if the filesystem can't handle the amount of
files in one directory anymore.
Note: This driver is not yet activated and will not be compiled and linked
to libvo. A separate patch will take care of that. This is just for adding
the file to the repository.
author | ivo |
---|---|
date | Mon, 20 Sep 2004 00:54:57 +0000 |
parents | 12615e408fb9 |
children | 7a80c6ac5058 |
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 | |
37 | |
38 /* The DVDinput handle, add stuff here for new input methods. */ | |
39 struct dvd_input_s { | |
40 /* libdvdcss handle */ | |
41 dvdcss_handle dvdcss; | |
42 | |
43 /* dummy file input */ | |
44 int fd; | |
45 }; | |
46 | |
47 | |
48 /** | |
49 * initialize and open a DVD device or file. | |
50 */ | |
51 static dvd_input_t css_open(const char *target) | |
52 { | |
53 dvd_input_t dev; | |
54 | |
55 /* 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
|
56 dev = (dvd_input_t) malloc(sizeof(struct dvd_input_s)); |
7029 | 57 if(dev == NULL) { |
58 fprintf(stderr, "libdvdread: Could not allocate memory.\n"); | |
59 return NULL; | |
60 } | |
61 | |
62 /* Really open it with libdvdcss */ | |
63 dev->dvdcss = DVDcss_open(target); | |
64 if(dev->dvdcss == 0) { | |
65 fprintf(stderr, "libdvdread: Could not open device with libdvdcss.\n"); | |
66 free(dev); | |
67 return NULL; | |
68 } | |
69 | |
70 return dev; | |
71 } | |
72 | |
73 /** | |
74 * return the last error message | |
75 */ | |
76 static char *css_error(dvd_input_t dev) | |
77 { | |
78 return DVDcss_error(dev->dvdcss); | |
79 } | |
80 | |
81 /** | |
82 * seek into the device. | |
83 */ | |
84 static int css_seek(dvd_input_t dev, int blocks, int flags) | |
85 { | |
86 return DVDcss_seek(dev->dvdcss, blocks, flags); | |
87 } | |
88 | |
89 /** | |
90 * set the block for the begining of a new title (key). | |
91 */ | |
92 static int css_title(dvd_input_t dev, int block) | |
93 { | |
94 return DVDcss_title(dev->dvdcss, block); | |
95 } | |
96 | |
97 /** | |
98 * read data from the device. | |
99 */ | |
100 static int css_read(dvd_input_t dev, void *buffer, int blocks, int flags) | |
101 { | |
102 return DVDcss_read(dev->dvdcss, buffer, blocks, flags); | |
103 } | |
104 | |
105 /** | |
106 * close the DVD device and clean up the library. | |
107 */ | |
108 static int css_close(dvd_input_t dev) | |
109 { | |
110 int ret; | |
111 | |
112 ret = DVDcss_close(dev->dvdcss); | |
113 | |
114 if(ret < 0) | |
115 return ret; | |
116 | |
117 free(dev); | |
118 | |
119 return 0; | |
120 } | |
121 | |
122 | |
123 | |
124 /** | |
125 * Setup read functions with either libdvdcss or minimal DVD access. | |
126 */ | |
127 int DVDInputSetup(void) | |
128 { | |
7033 | 129 DVDcss_open = dvdcss_open; |
130 DVDcss_close = dvdcss_close; | |
131 DVDcss_title = dvdcss_title; | |
132 DVDcss_seek = dvdcss_seek; | |
133 DVDcss_read = dvdcss_read; | |
134 DVDcss_error = dvdcss_error; | |
7029 | 135 |
136 /* | |
137 char *psz_method = getenv( "DVDCSS_METHOD" ); | |
138 char *psz_verbose = getenv( "DVDCSS_VERBOSE" ); | |
139 fprintf(stderr, "DVDCSS_METHOD %s\n", psz_method); | |
140 fprintf(stderr, "DVDCSS_VERBOSE %s\n", psz_verbose); | |
141 */ | |
7033 | 142 // fprintf(stderr, "libdvdread: Using libdvdcss version %s for DVD access\n", |
143 // *dvdcss_version); | |
7029 | 144 |
145 /* libdvdcss wraper functions */ | |
146 DVDinput_open = css_open; | |
147 DVDinput_close = css_close; | |
148 DVDinput_seek = css_seek; | |
149 DVDinput_title = css_title; | |
150 DVDinput_read = css_read; | |
151 DVDinput_error = css_error; | |
152 return 1; | |
153 | |
154 } |