dvd.c 6.11 KB
Newer Older
Sam Hocevar's avatar
 
Sam Hocevar committed
1
2
3
/*****************************************************************************
 * dvd.c : DVD input module for vlc
 *****************************************************************************
4
 * Copyright (C) 2000-2001 VideoLAN
5
 * $Id: dvd.c,v 1.20 2002/02/26 01:17:13 stef Exp $
Sam Hocevar's avatar
 
Sam Hocevar committed
6
 *
7
 * Authors: Samuel Hocevar <sam@zoy.org>
Sam Hocevar's avatar
 
Sam Hocevar committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
#include <stdlib.h>                                      /* malloc(), free() */
#include <string.h>                                              /* strdup() */

Sam Hocevar's avatar
   
Sam Hocevar committed
30
31
#include <videolan/vlc.h>

Sam Hocevar's avatar
   
Sam Hocevar committed
32
33
34
35
36
#ifdef GOD_DAMN_DMCA
#   include <dlfcn.h>
#   include "dummy_dvdcss.h"
#endif

Sam Hocevar's avatar
 
Sam Hocevar committed
37
38
39
/*****************************************************************************
 * Capabilities defined in the other files.
 *****************************************************************************/
Sam Hocevar's avatar
   
Sam Hocevar committed
40
void _M( input_getfunctions )( function_list_t * p_function_list );
Sam Hocevar's avatar
 
Sam Hocevar committed
41

Sam Hocevar's avatar
   
Sam Hocevar committed
42
43
44
45
46
47
48
49
50
/*****************************************************************************
 * Local prototypes.
 *****************************************************************************/
#ifdef GOD_DAMN_DMCA
static void *p_libdvdcss;
static void ProbeLibDVDCSS  ( void );
static void UnprobeLibDVDCSS( void );
#endif

Sam Hocevar's avatar
 
Sam Hocevar committed
51
/*****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
52
 * Build configuration tree.
Sam Hocevar's avatar
 
Sam Hocevar committed
53
 *****************************************************************************/
Sam Hocevar's avatar
   
Sam Hocevar committed
54
55
56
57
MODULE_CONFIG_START
MODULE_CONFIG_STOP

MODULE_INIT_START
Sam Hocevar's avatar
   
Sam Hocevar committed
58
#ifdef GOD_DAMN_DMCA
Sam Hocevar's avatar
   
Sam Hocevar committed
59
60
    SET_DESCRIPTION( "DVD input module, uses libdvdcss if present" )
    ADD_CAPABILITY( INPUT, 90 )
Sam Hocevar's avatar
   
Sam Hocevar committed
61
#else
Sam Hocevar's avatar
   
Sam Hocevar committed
62
63
    SET_DESCRIPTION( "DVD input module, linked with libdvdcss" )
    ADD_CAPABILITY( INPUT, 100 )
Sam Hocevar's avatar
   
Sam Hocevar committed
64
#endif
Sam Hocevar's avatar
   
Sam Hocevar committed
65
    ADD_SHORTCUT( "dvd" )
Sam Hocevar's avatar
   
Sam Hocevar committed
66
MODULE_INIT_STOP
Sam Hocevar's avatar
 
Sam Hocevar committed
67

Sam Hocevar's avatar
   
Sam Hocevar committed
68
MODULE_ACTIVATE_START
Sam Hocevar's avatar
   
Sam Hocevar committed
69
    _M( input_getfunctions )( &p_module->p_functions->input );
Sam Hocevar's avatar
   
Sam Hocevar committed
70
71
72
#ifdef GOD_DAMN_DMCA
    ProbeLibDVDCSS();
#endif
Sam Hocevar's avatar
   
Sam Hocevar committed
73
MODULE_ACTIVATE_STOP
Sam Hocevar's avatar
 
Sam Hocevar committed
74

Sam Hocevar's avatar
   
Sam Hocevar committed
75
MODULE_DEACTIVATE_START
Sam Hocevar's avatar
   
Sam Hocevar committed
76
77
78
#ifdef GOD_DAMN_DMCA
    UnprobeLibDVDCSS();
#endif
Sam Hocevar's avatar
   
Sam Hocevar committed
79
MODULE_DEACTIVATE_STOP
Sam Hocevar's avatar
 
Sam Hocevar committed
80

Sam Hocevar's avatar
   
Sam Hocevar committed
81
82
83
84
85
86
87
88
89
90
91
92
93

/* Following functions are local */

#ifdef GOD_DAMN_DMCA
/*****************************************************************************
 * ProbeLibDVDCSS: look for a libdvdcss object.
 *****************************************************************************
 * This functions looks for libdvdcss, using dlopen(), and fills function
 * pointers with what it finds. On failure, uses the dummy libdvdcss
 * replacement provided by vlc.
 *****************************************************************************/
static void ProbeLibDVDCSS( void )
{
Sam Hocevar's avatar
   
Sam Hocevar committed
94
95
96
    char *pp_filelist[4] = { "libdvdcss.so.1",
                             "./libdvdcss.so.1",
                             "./lib/libdvdcss.so.1",
Sam Hocevar's avatar
   
Sam Hocevar committed
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
                             NULL };
    char **pp_file = pp_filelist;

    /* Try to open the dynamic object */
    do
    {
        p_libdvdcss = dlopen( *pp_file, RTLD_LAZY );
        if( p_libdvdcss != NULL )
        {
            intf_WarnMsg( 2, "module: builtin module `dvd' found libdvdcss "
                             "in `%s'", *pp_file );
            break;
        }
        pp_file++;

    } while( *pp_file != NULL );

    /* If libdvdcss.so was found, check that it's valid */
    if( p_libdvdcss == NULL )
    {
Sam Hocevar's avatar
   
Sam Hocevar committed
117
        intf_ErrMsg( "dvd warning: libdvdcss.so.1 not present" );
Sam Hocevar's avatar
   
Sam Hocevar committed
118
119
120
    }
    else
    {
Sam Hocevar's avatar
   
Sam Hocevar committed
121
122
123
124
125
126
127
128
129
130
131
132
        ____dvdcss_open = dlsym( p_libdvdcss, "dvdcss_open" );
        ____dvdcss_close = dlsym( p_libdvdcss, "dvdcss_close" );
        ____dvdcss_title = dlsym( p_libdvdcss, "dvdcss_title" );
        ____dvdcss_seek = dlsym( p_libdvdcss, "dvdcss_seek" );
        ____dvdcss_read = dlsym( p_libdvdcss, "dvdcss_read" );
        ____dvdcss_readv = dlsym( p_libdvdcss, "dvdcss_readv" );
        ____dvdcss_error = dlsym( p_libdvdcss, "dvdcss_error" );

        if( ____dvdcss_open == NULL || ____dvdcss_close == NULL
             || ____dvdcss_title == NULL || ____dvdcss_seek == NULL
             || ____dvdcss_read == NULL || ____dvdcss_readv == NULL
             || ____dvdcss_error == NULL )
Sam Hocevar's avatar
   
Sam Hocevar committed
133
        {
Sam Hocevar's avatar
   
Sam Hocevar committed
134
135
            intf_ErrMsg( "dvd warning: missing symbols in libdvdcss.so.1, "
                         "this shouldn't happen !" );
Sam Hocevar's avatar
   
Sam Hocevar committed
136
137
138
139
140
141
142
143
144
145
146
            dlclose( p_libdvdcss );
            p_libdvdcss = NULL;
        }
    }

    /* If libdvdcss was not found or was not valid, use the dummy
     * replacement functions. */
    if( p_libdvdcss == NULL )
    {
        intf_ErrMsg( "dvd warning: no valid libdvdcss found, "
                     "I will only play unencrypted DVDs" );
Sam Hocevar's avatar
   
Sam Hocevar committed
147
148
        intf_ErrMsg( "dvd warning: get libdvdcss at "
                     "http://www.videolan.org/libdvdcss/" );
Sam Hocevar's avatar
   
Sam Hocevar committed
149

Sam Hocevar's avatar
   
Sam Hocevar committed
150
151
152
153
154
155
156
        ____dvdcss_open = dummy_dvdcss_open;
        ____dvdcss_close = dummy_dvdcss_close;
        ____dvdcss_title = dummy_dvdcss_title;
        ____dvdcss_seek = dummy_dvdcss_seek;
        ____dvdcss_read = dummy_dvdcss_read;
        ____dvdcss_readv = dummy_dvdcss_readv;
        ____dvdcss_error = dummy_dvdcss_error;
Sam Hocevar's avatar
   
Sam Hocevar committed
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
    }
}

/*****************************************************************************
 * UnprobeLibDVDCSS: free resources allocated by ProbeLibDVDCSS, if any.
 *****************************************************************************/
static void UnprobeLibDVDCSS( void )
{
    if( p_libdvdcss != NULL )
    {
        dlclose( p_libdvdcss );
        p_libdvdcss = NULL;
    }
}
#endif