1 /*****************************************************************************
2 * dummy_dvdcss.c: Dummy libdvdcss with minimal DVD access.
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: dummy_dvdcss.c,v 1.5 2001/12/30 07:09:55 sam Exp $
7 * Authors: Samuel Hocevar <sam@zoy.org>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
32 #include <videolan/vlc.h>
34 #include <sys/types.h>
36 #include <sys/uio.h> /* struct iovec */
37 #include <sys/ioctl.h>
39 #ifdef DVD_STRUCT_IN_LINUX_CDROM_H
40 # include <netinet/in.h>
41 # include <linux/cdrom.h>
43 # error "building dummy libdvdcss on this system does not make sense !"
46 #include "dummy_dvdcss.h"
48 /*****************************************************************************
50 *****************************************************************************/
57 /*****************************************************************************
58 * dvdcss_open: initialize library, open a DVD device, crack CSS key
59 *****************************************************************************/
60 extern dvdcss_handle dummy_dvdcss_open ( char *psz_target )
65 /* Allocate the library structure */
66 dvdcss = malloc( sizeof( struct dvdcss_s ) );
69 fprintf( stderr, "dvd error: "
70 "dummy libdvdcss could not allocate memory\n" );
75 dvdcss->i_fd = open( psz_target, 0 );
76 if( dvdcss->i_fd < 0 )
78 fprintf( stderr, "dvd error: "
79 "dummy libdvdcss could not open device\n" );
84 /* Check for encryption or ioctl failure */
85 dvd.type = DVD_STRUCT_COPYRIGHT;
86 dvd.copyright.layer_num = 0;
87 if( ioctl( dvdcss->i_fd, DVD_READ_STRUCT, &dvd ) != 0
88 || dvd.copyright.cpst )
90 fprintf( stderr, "dvd error: "
91 "dummy libdvdcss could not decrypt disc\n" );
92 close( dvdcss->i_fd );
100 /*****************************************************************************
101 * dvdcss_error: return the last libdvdcss error message
102 *****************************************************************************/
103 extern char * dummy_dvdcss_error ( dvdcss_handle dvdcss )
105 return "unknown error";
108 /*****************************************************************************
109 * dvdcss_seek: seek into the device
110 *****************************************************************************/
111 extern int dummy_dvdcss_seek ( dvdcss_handle dvdcss, int i_blocks,
116 i_read = lseek( dvdcss->i_fd,
117 (off_t)i_blocks * (off_t)DVDCSS_BLOCK_SIZE, SEEK_SET );
119 return i_read / DVDCSS_BLOCK_SIZE;
122 /*****************************************************************************
123 * dvdcss_title: crack the current title key if needed
124 *****************************************************************************/
125 extern int dummy_dvdcss_title ( dvdcss_handle dvdcss, int i_block )
130 /*****************************************************************************
131 * dvdcss_read: read data from the device, decrypt if requested
132 *****************************************************************************/
133 extern int dummy_dvdcss_read ( dvdcss_handle dvdcss, void *p_buffer,
139 i_bytes = read( dvdcss->i_fd, p_buffer,
140 (size_t)i_blocks * DVDCSS_BLOCK_SIZE );
142 return i_bytes / DVDCSS_BLOCK_SIZE;
145 /*****************************************************************************
146 * dvdcss_readv: read data to an iovec structure, decrypt if reaquested
147 *****************************************************************************/
148 extern int dummy_dvdcss_readv ( dvdcss_handle dvdcss, void *p_iovec,
154 i_read = readv( dvdcss->i_fd, (struct iovec*)p_iovec, i_blocks );
156 return i_read / DVDCSS_BLOCK_SIZE;
159 /*****************************************************************************
160 * dvdcss_close: close the DVD device and clean up the library
161 *****************************************************************************/
162 extern int dummy_dvdcss_close ( dvdcss_handle dvdcss )
166 i_ret = close( dvdcss->i_fd );