1 /*****************************************************************************
2 * dvd.c : DVD input module for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: dvd.c,v 1.18 2002/01/07 02:12:29 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 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <string.h> /* strdup() */
30 #include <videolan/vlc.h>
34 # include "dummy_dvdcss.h"
37 /*****************************************************************************
38 * Capabilities defined in the other files.
39 *****************************************************************************/
40 void _M( input_getfunctions )( function_list_t * p_function_list );
42 /*****************************************************************************
44 *****************************************************************************/
46 static void *p_libdvdcss;
47 static void ProbeLibDVDCSS ( void );
48 static void UnprobeLibDVDCSS( void );
51 /*****************************************************************************
52 * Build configuration tree.
53 *****************************************************************************/
59 SET_DESCRIPTION( "DVD input module, uses libdvdcss if present" )
60 ADD_CAPABILITY( INPUT, 90 )
62 SET_DESCRIPTION( "DVD input module, linked with libdvdcss" )
63 ADD_CAPABILITY( INPUT, 100 )
69 _M( input_getfunctions )( &p_module->p_functions->input );
75 MODULE_DEACTIVATE_START
79 MODULE_DEACTIVATE_STOP
82 /* Following functions are local */
85 /*****************************************************************************
86 * ProbeLibDVDCSS: look for a libdvdcss object.
87 *****************************************************************************
88 * This functions looks for libdvdcss, using dlopen(), and fills function
89 * pointers with what it finds. On failure, uses the dummy libdvdcss
90 * replacement provided by vlc.
91 *****************************************************************************/
92 static void ProbeLibDVDCSS( void )
94 char *pp_filelist[4] = { "libdvdcss.so.1",
96 "./lib/libdvdcss.so.1",
98 char **pp_file = pp_filelist;
100 /* Try to open the dynamic object */
103 p_libdvdcss = dlopen( *pp_file, RTLD_LAZY );
104 if( p_libdvdcss != NULL )
106 intf_WarnMsg( 2, "module: builtin module `dvd' found libdvdcss "
107 "in `%s'", *pp_file );
112 } while( *pp_file != NULL );
114 /* If libdvdcss.so was found, check that it's valid */
115 if( p_libdvdcss == NULL )
117 intf_ErrMsg( "dvd warning: libdvdcss.so.1 not present" );
121 ____dvdcss_open = dlsym( p_libdvdcss, "dvdcss_open" );
122 ____dvdcss_close = dlsym( p_libdvdcss, "dvdcss_close" );
123 ____dvdcss_title = dlsym( p_libdvdcss, "dvdcss_title" );
124 ____dvdcss_seek = dlsym( p_libdvdcss, "dvdcss_seek" );
125 ____dvdcss_read = dlsym( p_libdvdcss, "dvdcss_read" );
126 ____dvdcss_readv = dlsym( p_libdvdcss, "dvdcss_readv" );
127 ____dvdcss_error = dlsym( p_libdvdcss, "dvdcss_error" );
129 if( ____dvdcss_open == NULL || ____dvdcss_close == NULL
130 || ____dvdcss_title == NULL || ____dvdcss_seek == NULL
131 || ____dvdcss_read == NULL || ____dvdcss_readv == NULL
132 || ____dvdcss_error == NULL )
134 intf_ErrMsg( "dvd warning: missing symbols in libdvdcss.so.1, "
135 "this shouldn't happen !" );
136 dlclose( p_libdvdcss );
141 /* If libdvdcss was not found or was not valid, use the dummy
142 * replacement functions. */
143 if( p_libdvdcss == NULL )
145 intf_ErrMsg( "dvd warning: no valid libdvdcss found, "
146 "I will only play unencrypted DVDs" );
147 intf_ErrMsg( "dvd warning: get libdvdcss at "
148 "http://www.videolan.org/libdvdcss/" );
150 ____dvdcss_open = dummy_dvdcss_open;
151 ____dvdcss_close = dummy_dvdcss_close;
152 ____dvdcss_title = dummy_dvdcss_title;
153 ____dvdcss_seek = dummy_dvdcss_seek;
154 ____dvdcss_read = dummy_dvdcss_read;
155 ____dvdcss_readv = dummy_dvdcss_readv;
156 ____dvdcss_error = dummy_dvdcss_error;
160 /*****************************************************************************
161 * UnprobeLibDVDCSS: free resources allocated by ProbeLibDVDCSS, if any.
162 *****************************************************************************/
163 static void UnprobeLibDVDCSS( void )
165 if( p_libdvdcss != NULL )
167 dlclose( p_libdvdcss );