]> git.sesse.net Git - vlc/blob - plugins/dvdread/dvdread.c
* Added error checking in pthread wrapper ; as a result, intf_msg.h must
[vlc] / plugins / dvdread / dvdread.c
1 /*****************************************************************************
2  * dvdread.c : DvdRead input module for vlc
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: dvdread.c,v 1.2 2001/11/28 15:08:05 massiot 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 #define MODULE_NAME dvdread
25 #include "modules_inner.h"
26
27 /*****************************************************************************
28  * Preamble
29  *****************************************************************************/
30 #include "defs.h"
31
32 #include <stdlib.h>                                      /* malloc(), free() */
33 #include <string.h>                                              /* strdup() */
34
35 #ifdef GOD_DAMN_DMCA
36 #   include <dlfcn.h>
37 #   include "dummy_dvdcss.h"
38 #endif
39
40 #include "config.h"
41 #include "common.h"                                     /* boolean_t, byte_t */
42 #include "intf_msg.h"
43 #include "threads.h"
44 #include "mtime.h"
45
46 #include "modules.h"
47 #include "modules_export.h"
48
49 /*****************************************************************************
50  * Capabilities defined in the other files.
51  *****************************************************************************/
52 void _M( input_getfunctions )( function_list_t * p_function_list );
53
54 /*****************************************************************************
55  * Local prototypes.
56  *****************************************************************************/
57 #ifdef GOD_DAMN_DMCA
58 static void *p_libdvdcss;
59 static void ProbeLibDVDCSS  ( void );
60 static void UnprobeLibDVDCSS( void );
61 #endif
62
63 /*****************************************************************************
64  * Build configuration tree.
65  *****************************************************************************/
66 MODULE_CONFIG_START
67 ADD_WINDOW( "Configuration for DVD module" )
68     ADD_COMMENT( "foobar !" )
69 MODULE_CONFIG_STOP
70
71 MODULE_INIT_START
72     p_module->i_capabilities = MODULE_CAPABILITY_NULL
73                                 | MODULE_CAPABILITY_INPUT;
74 #ifdef GOD_DAMN_DMCA
75     p_module->psz_longname = "DVD input module, uses libdvdcss if present";
76 #else
77     p_module->psz_longname = "DVD input module, linked with libdvdcss";
78 #endif
79 MODULE_INIT_STOP
80
81 MODULE_ACTIVATE_START
82     _M( input_getfunctions )( &p_module->p_functions->input );
83 #ifdef GOD_DAMN_DMCA
84     ProbeLibDVDCSS();
85 #endif
86 MODULE_ACTIVATE_STOP
87
88 MODULE_DEACTIVATE_START
89 #ifdef GOD_DAMN_DMCA
90     UnprobeLibDVDCSS();
91 #endif
92 MODULE_DEACTIVATE_STOP
93
94
95 /* Following functions are local */
96
97 #ifdef GOD_DAMN_DMCA
98 /*****************************************************************************
99  * ProbeLibDVDCSS: look for a libdvdcss object.
100  *****************************************************************************
101  * This functions looks for libdvdcss, using dlopen(), and fills function
102  * pointers with what it finds. On failure, uses the dummy libdvdcss
103  * replacement provided by vlc.
104  *****************************************************************************/
105 static void ProbeLibDVDCSS( void )
106 {
107     char *pp_filelist[4] = { "libdvdcss.so.0",
108                              "./libdvdcss.so.0",
109                              "./lib/libdvdcss.so.0",
110                              NULL };
111     char **pp_file = pp_filelist;
112
113     /* Try to open the dynamic object */
114     do
115     {
116         p_libdvdcss = dlopen( *pp_file, RTLD_LAZY );
117         if( p_libdvdcss != NULL )
118         {
119             intf_WarnMsg( 2, "module: builtin module `dvd' found libdvdcss "
120                              "in `%s'", *pp_file );
121             break;
122         }
123         pp_file++;
124
125     } while( *pp_file != NULL );
126
127     /* If libdvdcss.so was found, check that it's valid */
128     if( p_libdvdcss == NULL )
129     {
130         intf_ErrMsg( "dvd warning: libdvdcss.so.0 not present" );
131     }
132     else
133     {
134         /* Check for libdvdcss 0.0.1 */
135         if( dlsym( p_libdvdcss, "dvdcss_crack" ) != NULL )
136         {
137             intf_ErrMsg( "dvd warning: libdvdcss.so.0 has deprecated symbol "
138                          "dvdcss_crack(), please upgrade" );
139             dlclose( p_libdvdcss );
140             p_libdvdcss = NULL;
141         }
142         else
143         {
144             dvdcss_open = dlsym( p_libdvdcss, "dvdcss_open" );
145             dvdcss_close = dlsym( p_libdvdcss, "dvdcss_close" );
146             dvdcss_title = dlsym( p_libdvdcss, "dvdcss_title" );
147             dvdcss_seek = dlsym( p_libdvdcss, "dvdcss_seek" );
148             dvdcss_read = dlsym( p_libdvdcss, "dvdcss_read" );
149             dvdcss_readv = dlsym( p_libdvdcss, "dvdcss_readv" );
150             dvdcss_error = dlsym( p_libdvdcss, "dvdcss_error" );
151
152             if( dvdcss_open == NULL || dvdcss_close == NULL
153                  || dvdcss_title == NULL || dvdcss_seek == NULL
154                  || dvdcss_read == NULL || dvdcss_readv == NULL
155                  || dvdcss_error == NULL )
156             {
157                 intf_ErrMsg( "dvd warning: missing symbols in libdvdcss.so.0, "
158                              "please upgrade libdvdcss or vlc" );
159                 dlclose( p_libdvdcss );
160                 p_libdvdcss = NULL;
161             }
162         }
163     }
164
165     /* If libdvdcss was not found or was not valid, use the dummy
166      * replacement functions. */
167     if( p_libdvdcss == NULL )
168     {
169         intf_ErrMsg( "dvd warning: no valid libdvdcss found, "
170                      "I will only play unencrypted DVDs" );
171         intf_ErrMsg( "dvd warning: get libdvdcss at "
172                      "http://www.videolan.org/libdvdcss/" );
173
174         dvdcss_open = dummy_dvdcss_open;
175         dvdcss_close = dummy_dvdcss_close;
176         dvdcss_title = dummy_dvdcss_title;
177         dvdcss_seek = dummy_dvdcss_seek;
178         dvdcss_read = dummy_dvdcss_read;
179         dvdcss_readv = dummy_dvdcss_readv;
180         dvdcss_error = dummy_dvdcss_error;
181     }
182 }
183
184 /*****************************************************************************
185  * UnprobeLibDVDCSS: free resources allocated by ProbeLibDVDCSS, if any.
186  *****************************************************************************/
187 static void UnprobeLibDVDCSS( void )
188 {
189     if( p_libdvdcss != NULL )
190     {
191         dlclose( p_libdvdcss );
192         p_libdvdcss = NULL;
193     }
194 }
195 #endif
196