~ubuntu-branches/debian/wheezy/vlc/wheezy

« back to all changes in this revision

Viewing changes to plugins/dvd/dvd.c

Tags: upstream-0.7.2.final
ImportĀ upstreamĀ versionĀ 0.7.2.final

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 * dvd.c : DVD input module for vlc
3
 
 *****************************************************************************
4
 
 * Copyright (C) 2000-2001 VideoLAN
5
 
 * $Id: dvd.c,v 1.15 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 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 "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.1",
108
 
                             "./libdvdcss.so.1",
109
 
                             "./lib/libdvdcss.so.1",
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.1 not present" );
131
 
    }
132
 
    else
133
 
    {
134
 
        dvdcss_open = dlsym( p_libdvdcss, "dvdcss_open" );
135
 
        dvdcss_close = dlsym( p_libdvdcss, "dvdcss_close" );
136
 
        dvdcss_title = dlsym( p_libdvdcss, "dvdcss_title" );
137
 
        dvdcss_seek = dlsym( p_libdvdcss, "dvdcss_seek" );
138
 
        dvdcss_read = dlsym( p_libdvdcss, "dvdcss_read" );
139
 
        dvdcss_readv = dlsym( p_libdvdcss, "dvdcss_readv" );
140
 
        dvdcss_error = dlsym( p_libdvdcss, "dvdcss_error" );
141
 
 
142
 
        if( dvdcss_open == NULL || dvdcss_close == NULL
143
 
             || dvdcss_title == NULL || dvdcss_seek == NULL
144
 
             || dvdcss_read == NULL || dvdcss_readv == NULL
145
 
             || dvdcss_error == NULL )
146
 
        {
147
 
            intf_ErrMsg( "dvd warning: missing symbols in libdvdcss.so.1, "
148
 
                         "this shouldn't happen !" );
149
 
            dlclose( p_libdvdcss );
150
 
            p_libdvdcss = NULL;
151
 
        }
152
 
    }
153
 
 
154
 
    /* If libdvdcss was not found or was not valid, use the dummy
155
 
     * replacement functions. */
156
 
    if( p_libdvdcss == NULL )
157
 
    {
158
 
        intf_ErrMsg( "dvd warning: no valid libdvdcss found, "
159
 
                     "I will only play unencrypted DVDs" );
160
 
        intf_ErrMsg( "dvd warning: get libdvdcss at "
161
 
                     "http://www.videolan.org/libdvdcss/" );
162
 
 
163
 
        dvdcss_open = dummy_dvdcss_open;
164
 
        dvdcss_close = dummy_dvdcss_close;
165
 
        dvdcss_title = dummy_dvdcss_title;
166
 
        dvdcss_seek = dummy_dvdcss_seek;
167
 
        dvdcss_read = dummy_dvdcss_read;
168
 
        dvdcss_readv = dummy_dvdcss_readv;
169
 
        dvdcss_error = dummy_dvdcss_error;
170
 
    }
171
 
}
172
 
 
173
 
/*****************************************************************************
174
 
 * UnprobeLibDVDCSS: free resources allocated by ProbeLibDVDCSS, if any.
175
 
 *****************************************************************************/
176
 
static void UnprobeLibDVDCSS( void )
177
 
{
178
 
    if( p_libdvdcss != NULL )
179
 
    {
180
 
        dlclose( p_libdvdcss );
181
 
        p_libdvdcss = NULL;
182
 
    }
183
 
}
184
 
#endif
185