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