]> git.sesse.net Git - vlc/blob - plugins/dvd/dummy_dvdcss.c
*) Fixed stupid bug in vout_Manage. It sometimes called SetDSequenceMatrix
[vlc] / plugins / dvd / dummy_dvdcss.c
1 /*****************************************************************************
2  * dummy_dvdcss.c: Dummy libdvdcss with minimal DVD access.
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: dummy_dvdcss.c,v 1.3 2001/11/12 20:16:33 sam Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
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 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include "defs.h"
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <fcntl.h>
32 #include <unistd.h>
33
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <sys/uio.h>                                        /* struct iovec */
37 #include <sys/ioctl.h>
38
39 #ifdef DVD_STRUCT_IN_LINUX_CDROM_H
40 #   include <netinet/in.h>
41 #   include <linux/cdrom.h>
42 #else
43 #   error "building dummy libdvdcss on this system does not make sense !"
44 #endif
45
46 #include "config.h"
47 #include "common.h"
48
49 #include "dummy_dvdcss.h"
50
51 /*****************************************************************************
52  * Local structure
53  *****************************************************************************/
54 struct dvdcss_s
55 {
56     /* File descriptor */
57     int i_fd;
58 };
59
60 /*****************************************************************************
61  * dvdcss_open: initialize library, open a DVD device, crack CSS key
62  *****************************************************************************/
63 extern dvdcss_handle dummy_dvdcss_open ( char *psz_target )
64 {
65     dvdcss_handle dvdcss;
66     dvd_struct    dvd;
67
68     /* Allocate the library structure */
69     dvdcss = malloc( sizeof( struct dvdcss_s ) );
70     if( dvdcss == NULL )
71     {
72         fprintf( stderr, "dvd error: "
73                          "dummy libdvdcss could not allocate memory\n" );
74         return NULL;
75     }
76
77     /* Open the device */
78     dvdcss->i_fd = open( psz_target, 0 );
79     if( dvdcss->i_fd < 0 )
80     {
81         fprintf( stderr, "dvd error: "
82                          "dummy libdvdcss could not open device\n" );
83         free( dvdcss );
84         return NULL;
85     }
86
87     /* Check for encryption or ioctl failure */
88     dvd.type = DVD_STRUCT_COPYRIGHT;
89     dvd.copyright.layer_num = 0;
90     if( ioctl( dvdcss->i_fd, DVD_READ_STRUCT, &dvd ) != 0
91          || dvd.copyright.cpst )
92     {
93         fprintf( stderr, "dvd error: "
94                          "dummy libdvdcss could not decrypt disc\n" );
95         close( dvdcss->i_fd );
96         free( dvdcss );
97         return NULL;
98     }
99
100     return dvdcss;
101 }
102
103 /*****************************************************************************
104  * dvdcss_error: return the last libdvdcss error message
105  *****************************************************************************/
106 extern char * dummy_dvdcss_error ( dvdcss_handle dvdcss )
107 {
108     return "unknown error";
109 }
110
111 /*****************************************************************************
112  * dvdcss_seek: seek into the device
113  *****************************************************************************/
114 extern int dummy_dvdcss_seek ( dvdcss_handle dvdcss, int i_blocks,
115                                                      int i_flags )
116 {
117     off_t i_read;
118
119     i_read = lseek( dvdcss->i_fd,
120                     (off_t)i_blocks * (off_t)DVDCSS_BLOCK_SIZE, SEEK_SET );
121
122     return i_read / DVDCSS_BLOCK_SIZE;
123 }
124
125 /*****************************************************************************
126  * dvdcss_title: crack the current title key if needed
127  *****************************************************************************/
128 extern int dummy_dvdcss_title ( dvdcss_handle dvdcss, int i_block )
129 {
130     return 0;
131 }
132
133 /*****************************************************************************
134  * dvdcss_read: read data from the device, decrypt if requested
135  *****************************************************************************/
136 extern int dummy_dvdcss_read ( dvdcss_handle dvdcss, void *p_buffer,
137                                                      int i_blocks,
138                                                      int i_flags )
139 {
140     int i_bytes;
141
142     i_bytes = read( dvdcss->i_fd, p_buffer,
143                     (size_t)i_blocks * DVDCSS_BLOCK_SIZE );
144
145     return i_bytes / DVDCSS_BLOCK_SIZE;
146 }
147
148 /*****************************************************************************
149  * dvdcss_readv: read data to an iovec structure, decrypt if reaquested
150  *****************************************************************************/
151 extern int dummy_dvdcss_readv ( dvdcss_handle dvdcss, void *p_iovec,
152                                                       int i_blocks,
153                                                       int i_flags )
154 {
155     int i_read;
156
157     i_read = readv( dvdcss->i_fd, (struct iovec*)p_iovec, i_blocks );
158
159     return i_read / DVDCSS_BLOCK_SIZE;
160 }
161
162 /*****************************************************************************
163  * dvdcss_close: close the DVD device and clean up the library
164  *****************************************************************************/
165 extern int dummy_dvdcss_close ( dvdcss_handle dvdcss )
166 {
167     int i_ret;
168
169     i_ret = close( dvdcss->i_fd );
170
171     if( i_ret < 0 )
172     {
173         return i_ret;
174     }
175
176     free( dvdcss );
177
178     return 0;
179 }
180