~ubuntu-branches/ubuntu/natty/vlc/natty

« back to all changes in this revision

Viewing changes to bin/vlc.c

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2010-06-25 01:09:16 UTC
  • mfrom: (1.1.30 upstream)
  • Revision ID: james.westby@ubuntu.com-20100625010916-asxhep2mutg6g6pd
Tags: 1.1.0-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - build and install the libx264 plugin
  - add Xb-Npp header to vlc package
  - Add apport hook to include more vlc dependencies in bug reports
* Drop xulrunner patches.
* Drop 502_xulrunner_191.diff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * vlc.c: the VLC player
3
3
 *****************************************************************************
4
4
 * Copyright (C) 1998-2008 the VideoLAN team
5
 
 * $Id: 8917ff4f5284ca86d006dccf885a8be44f56aabe $
 
5
 * $Id: 5b2259dffddde3a4792d1b7cc0b15596c4d25a77 $
6
6
 *
7
7
 * Authors: Vincent Seguin <seguin@via.ecp.fr>
8
8
 *          Samuel Hocevar <sam@zoy.org>
34
34
#include <stdlib.h>
35
35
#include <locale.h>
36
36
 
 
37
#ifdef __APPLE__
 
38
#include <string.h>
 
39
#endif
 
40
 
37
41
 
38
42
/* Explicit HACK */
39
43
extern void LocaleFree (const char *);
40
44
extern char *FromLocale (const char *);
 
45
extern void vlc_enable_override (void);
41
46
 
42
47
#include <signal.h>
43
48
#include <time.h>
44
49
#include <pthread.h>
45
50
#include <unistd.h>
 
51
#include <dlfcn.h>
 
52
 
 
53
#ifdef HAVE_MAEMO
 
54
static void dummy_handler (int signum)
 
55
{
 
56
    (void) signum;
 
57
}
 
58
#endif
46
59
 
47
60
/*****************************************************************************
48
61
 * main: parse command line, start interface and spawn threads.
49
62
 *****************************************************************************/
50
63
int main( int i_argc, const char *ppsz_argv[] )
51
64
{
52
 
    int i_ret;
 
65
    /* The so-called POSIX-compliant MacOS X reportedly processes SIGPIPE even
 
66
     * if it is blocked in all thread. Also some libraries want SIGPIPE blocked
 
67
     * as they have no clue about signal masks.
 
68
     * Note: this is NOT an excuse for not protecting against SIGPIPE. If
 
69
     * LibVLC runs outside of VLC, we cannot rely on this code snippet. */
 
70
    signal (SIGPIPE, SIG_IGN);
 
71
    /* Restore default for SIGCHLD in case parent ignores it. */
 
72
    signal (SIGCHLD, SIG_DFL);
 
73
 
 
74
#ifdef HAVE_SETENV
 
75
# ifndef NDEBUG
 
76
    /* Activate malloc checking routines to detect heap corruptions. */
 
77
    setenv ("MALLOC_CHECK_", "2", 1);
 
78
 
 
79
    /* Disable the ugly Gnome crash dialog so that we properly segfault */
 
80
    setenv ("GNOME_DISABLE_CRASH_DIALOG", "1", 1);
 
81
# endif
 
82
 
 
83
    /* Clear the X.Org startup notification ID. Otherwise the UI might try to
 
84
     * change the environment while the process is multi-threaded. That could
 
85
     * crash. Screw you X.Org. Next time write a thread-safe specification. */
 
86
    unsetenv ("DESKTOP_STARTUP_ID");
 
87
#endif
53
88
 
54
89
#ifndef ALLOW_RUN_AS_ROOT
55
90
    if (geteuid () == 0)
66
101
 
67
102
#ifndef __APPLE__
68
103
    /* This clutters OSX GUI error logs */
69
 
    fprintf( stderr, "VLC media player %s\n", libvlc_get_version() );
70
 
#endif
71
 
 
72
 
#ifdef HAVE_PUTENV
73
 
#   ifndef NDEBUG
74
 
    /* Activate malloc checking routines to detect heap corruptions. */
75
 
    putenv( (char*)"MALLOC_CHECK_=2" );
76
 
 
77
 
    /* Disable the ugly Gnome crash dialog so that we properly segfault */
78
 
    putenv( (char *)"GNOME_DISABLE_CRASH_DIALOG=1" );
79
 
#   endif
 
104
    fprintf( stderr, "VLC media player %s (revision %s)\n",
 
105
             libvlc_get_version(), libvlc_get_changeset() );
80
106
#endif
81
107
 
82
108
    /* Synchronously intercepted POSIX signals.
83
109
     *
84
110
     * In a threaded program such as VLC, the only sane way to handle signals
85
 
     * is to block them in all thread but one - this is the only way to
 
111
     * is to block them in all threads but one - this is the only way to
86
112
     * predict which thread will receive them. If any piece of code depends
87
113
     * on delivery of one of this signal it is intrinsically not thread-safe
88
114
     * and MUST NOT be used in VLC, whether we like it or not.
110
136
    sigemptyset (&set);
111
137
    for (unsigned i = 0; i < sizeof (sigs) / sizeof (sigs[0]); i++)
112
138
        sigaddset (&set, sigs[i]);
 
139
#ifdef HAVE_MAEMO
 
140
    sigaddset (&set, SIGRTMIN);
 
141
    {
 
142
        struct sigaction act = { .sa_handler = dummy_handler, };
 
143
        sigaction (SIGRTMIN, &act, NULL);
 
144
    }
 
145
#endif
113
146
 
114
147
    /* Block all these signals */
115
148
    pthread_sigmask (SIG_BLOCK, &set, NULL);
117
150
    sigdelset (&set, SIGCHLD);
118
151
 
119
152
    /* Note that FromLocale() can be used before libvlc is initialized */
120
 
    const char *argv[i_argc + 3];
 
153
    const char *argv[i_argc + 4];
121
154
    int argc = 0;
122
155
 
 
156
    argv[argc++] = "--no-ignore-config";
 
157
    argv[argc++] = "--user-agent=\"VLC media player\"";
123
158
#ifdef TOP_BUILDDIR
124
159
    argv[argc++] = FromLocale ("--plugin-path="TOP_BUILDDIR"/modules");
125
160
#endif
126
161
#ifdef TOP_SRCDIR
127
 
# ifdef ENABLE_HTTPD
128
 
    argv[argc++] = FromLocale ("--http-src="TOP_SRCDIR"/share/http");
129
 
# endif
 
162
    argv[argc++] = FromLocale ("--data-path="TOP_SRCDIR"/share");
130
163
#endif
131
164
 
132
 
    for (int i = 1; i < i_argc; i++)
 
165
    int i = 1;
 
166
#ifdef __APPLE__
 
167
    /* When VLC.app is run by double clicking in Mac OS X, the 2nd arg
 
168
     * is the PSN - process serial number (a unique PID-ish thingie)
 
169
     * still ok for real Darwin & when run from command line
 
170
     * for example -psn_0_9306113 */
 
171
    if(i_argc >= 2 && !strncmp( ppsz_argv[1] , "-psn" , 4 ))
 
172
        i = 2;
 
173
#endif
 
174
    for (; i < i_argc; i++)
133
175
        if ((argv[argc++] = FromLocale (ppsz_argv[i])) == NULL)
134
176
            return 1; // BOOM!
 
177
    argv[argc] = NULL;
135
178
 
136
 
    libvlc_exception_t ex, dummy;
137
 
    libvlc_exception_init (&ex);
138
 
    libvlc_exception_init (&dummy);
 
179
    vlc_enable_override ();
139
180
 
140
181
    /* Initialize libvlc */
141
 
    libvlc_instance_t *vlc = libvlc_new (argc, argv, &ex);
 
182
    libvlc_instance_t *vlc = libvlc_new (argc, argv);
142
183
 
143
184
    if (vlc != NULL)
144
185
    {
145
 
        libvlc_add_intf (vlc, "signals", &ex);
146
 
        if (libvlc_exception_raised (&ex))
 
186
        if (libvlc_add_intf (vlc, "signals"))
 
187
            pthread_sigmask (SIG_UNBLOCK, &set, NULL);
 
188
#if !defined (HAVE_MAEMO)
 
189
        libvlc_add_intf (vlc, "globalhotkeys,none");
 
190
#endif
 
191
        if (libvlc_add_intf (vlc, NULL) == 0)
147
192
        {
148
 
            libvlc_exception_clear (&ex);
149
 
            pthread_sigmask (SIG_UNBLOCK, &set, NULL);
 
193
            libvlc_playlist_play (vlc, -1, 0, NULL);
 
194
            libvlc_wait (vlc);
150
195
        }
151
 
        libvlc_add_intf (vlc, "globalhotkeys,none", &ex);
152
 
        libvlc_exception_clear (&ex);
153
 
        libvlc_add_intf (vlc, NULL, &ex);
154
 
        libvlc_playlist_play (vlc, -1, 0, NULL, &dummy);
155
 
        libvlc_wait (vlc);
156
196
        libvlc_release (vlc);
157
197
    }
158
 
    i_ret = libvlc_exception_raised (&ex);
159
 
    if( i_ret )
160
 
        fprintf( stderr, "%s\n", libvlc_exception_get_message( &ex));
161
 
 
162
 
    libvlc_exception_clear (&ex);
163
 
    libvlc_exception_clear (&dummy);
164
 
 
165
 
    for (int i = 0; i < argc; i++)
 
198
 
 
199
    for (int i = 2; i < argc; i++)
166
200
        LocaleFree (argv[i]);
167
201
 
168
 
    return i_ret;
 
202
    return 0;
169
203
}