]> git.sesse.net Git - vlc/blob - plugins/dvd/dvd.c
* ./plugins/mga/mga.c: removed the mgammx module and put the code in
[vlc] / plugins / dvd / dvd.c
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 $
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 <stdlib.h>                                      /* malloc(), free() */
28 #include <string.h>                                              /* strdup() */
29
30 #include <videolan/vlc.h>
31
32 #ifdef GOD_DAMN_DMCA
33 #   include <dlfcn.h>
34 #   include "dummy_dvdcss.h"
35 #endif
36
37 /*****************************************************************************
38  * Capabilities defined in the other files.
39  *****************************************************************************/
40 void _M( input_getfunctions )( function_list_t * p_function_list );
41
42 /*****************************************************************************
43  * Local prototypes.
44  *****************************************************************************/
45 #ifdef GOD_DAMN_DMCA
46 static void *p_libdvdcss;
47 static void ProbeLibDVDCSS  ( void );
48 static void UnprobeLibDVDCSS( void );
49 #endif
50
51 /*****************************************************************************
52  * Build configuration tree.
53  *****************************************************************************/
54 MODULE_CONFIG_START
55 MODULE_CONFIG_STOP
56
57 MODULE_INIT_START
58 #ifdef GOD_DAMN_DMCA
59     SET_DESCRIPTION( "DVD input module, uses libdvdcss if present" )
60     ADD_CAPABILITY( INPUT, 90 )
61 #else
62     SET_DESCRIPTION( "DVD input module, linked with libdvdcss" )
63     ADD_CAPABILITY( INPUT, 100 )
64 #endif
65     ADD_SHORTCUT( "dvd" )
66 MODULE_INIT_STOP
67
68 MODULE_ACTIVATE_START
69     _M( input_getfunctions )( &p_module->p_functions->input );
70 #ifdef GOD_DAMN_DMCA
71     ProbeLibDVDCSS();
72 #endif
73 MODULE_ACTIVATE_STOP
74
75 MODULE_DEACTIVATE_START
76 #ifdef GOD_DAMN_DMCA
77     UnprobeLibDVDCSS();
78 #endif
79 MODULE_DEACTIVATE_STOP
80
81
82 /* Following functions are local */
83
84 #ifdef GOD_DAMN_DMCA
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 )
93 {
94     char *pp_filelist[4] = { "libdvdcss.so.1",
95                              "./libdvdcss.so.1",
96                              "./lib/libdvdcss.so.1",
97                              NULL };
98     char **pp_file = pp_filelist;
99
100     /* Try to open the dynamic object */
101     do
102     {
103         p_libdvdcss = dlopen( *pp_file, RTLD_LAZY );
104         if( p_libdvdcss != NULL )
105         {
106             intf_WarnMsg( 2, "module: builtin module `dvd' found libdvdcss "
107                              "in `%s'", *pp_file );
108             break;
109         }
110         pp_file++;
111
112     } while( *pp_file != NULL );
113
114     /* If libdvdcss.so was found, check that it's valid */
115     if( p_libdvdcss == NULL )
116     {
117         intf_ErrMsg( "dvd warning: libdvdcss.so.1 not present" );
118     }
119     else
120     {
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" );
128
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 )
133         {
134             intf_ErrMsg( "dvd warning: missing symbols in libdvdcss.so.1, "
135                          "this shouldn't happen !" );
136             dlclose( p_libdvdcss );
137             p_libdvdcss = NULL;
138         }
139     }
140
141     /* If libdvdcss was not found or was not valid, use the dummy
142      * replacement functions. */
143     if( p_libdvdcss == NULL )
144     {
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/" );
149
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;
157     }
158 }
159
160 /*****************************************************************************
161  * UnprobeLibDVDCSS: free resources allocated by ProbeLibDVDCSS, if any.
162  *****************************************************************************/
163 static void UnprobeLibDVDCSS( void )
164 {
165     if( p_libdvdcss != NULL )
166     {
167         dlclose( p_libdvdcss );
168         p_libdvdcss = NULL;
169     }
170 }
171 #endif
172