Exemple #1
0
static void
uninstall_md_listener( libvlc_media_list_view_t * p_mlv,
                       libvlc_media_t * p_md)
{
    libvlc_media_list_t * p_mlist;
    libvlc_exception_t ignored_exception;
    libvlc_exception_init( &ignored_exception );
    libvlc_event_detach( p_md->p_event_manager,
                         libvlc_MediaSubItemAdded,
                         media_list_subitem_added, p_mlv, &ignored_exception );
    if( libvlc_exception_raised( &ignored_exception ) )
        libvlc_exception_clear( &ignored_exception ); /* We don't care if we encounter an exception */
    if((p_mlist = libvlc_media_subitems( p_md )))
    {
        libvlc_media_list_lock( p_mlist );
        libvlc_event_detach( p_mlist->p_event_manager,
                             libvlc_MediaListItemAdded,
                             media_list_item_added, p_mlv, NULL );
        libvlc_event_detach( p_mlist->p_event_manager,
                             libvlc_MediaListItemDeleted,
                             media_list_item_removed, p_mlv, NULL );

        int i, count = libvlc_media_list_count( p_mlist, NULL );
        for( i = 0; i < count; i++)
        {
            libvlc_media_t * p_submd;
            p_submd = libvlc_media_list_item_at_index( p_mlist,i, NULL );
            uninstall_md_listener( p_mlv, p_submd );
            libvlc_media_release( p_submd );
        }
        libvlc_media_list_unlock( p_mlist );
        libvlc_media_list_release( p_mlist );
    }
}
Exemple #2
0
void vlcExceptionRaised()
{
    if (libvlc_exception_raised(vlc_exception)) {
        qDebug() << "libvlc exception:" << libvlc_exception_get_message(vlc_exception);
        libvlc_exception_clear(vlc_exception);
    }
}
static void catchError(libvlc_exception_t *ex) {
    if(libvlc_exception_raised(ex)) {
        fprintf(stderr, "exception: %s\n", libvlc_exception_get_message(ex));
        //exit(1);
    }

    libvlc_exception_clear(ex);
}
Exemple #4
0
void checkException()
{
	if( libvlc_exception_raised( p_vlc_exception ) )
	{
		qDebug() << "libvlc exception:" << libvlc_exception_get_message( p_vlc_exception );
		libvlc_exception_clear( p_vlc_exception );
	}
}
Exemple #5
0
static bool catchVLCException( libvlc_exception_t *ex )
{
    if ( libvlc_exception_raised( ex ) )
    {
        qDebug() << libvlc_errmsg();
        libvlc_exception_clear( ex );
        return (true);
    }
    return (false);
}
Exemple #6
0
static void ProcessVLCException(libvlc_exception_t* ex, VLCExceptionHandler eh)
{
    if(libvlc_exception_raised(ex) && eh)
    {
		char szErrorMsg[1024]="";
        sprintf(szErrorMsg, "%s", libvlc_exception_get_message(ex));
        libvlc_exception_clear(ex);
		eh(szErrorMsg);
    }
}
static void
clutter_vlc_catch(libvlc_exception_t* vlc_exception)
{
  /* well this is really bad. Find out another way to handle vlc exceptions
   */

  if (libvlc_exception_raised(vlc_exception))
    {
      fprintf(stderr, "exception: %s\n", libvlc_exception_get_message(vlc_exception));
      exit(1);
    }

  libvlc_exception_clear(vlc_exception);
}
Exemple #8
0
/**************************************************************************
 *       media_player_reached_end (private) (Event Callback)
 **************************************************************************/
static void
media_player_reached_end(const libvlc_event_t * p_event, void * p_user_data)
{
    VLC_UNUSED(p_event);
    libvlc_media_list_player_t * p_mlp = p_user_data;
    libvlc_exception_t e;
    libvlc_exception_init(&e);

    vlc_mutex_lock(&p_mlp->mp_callback_lock);
    if (!p_mlp->are_mp_callback_cancelled)
        set_relative_playlist_position_and_play(p_mlp, 1, &e);
    vlc_mutex_unlock(&p_mlp->mp_callback_lock);

    // There is no point in reporting an error from this callback
    libvlc_exception_clear(&e);
}
Exemple #9
0
/*****************************************************************************
 * main: parse command line, start interface and spawn threads.
 *****************************************************************************/
int main( int i_argc, const char *ppsz_argv[] )
{
#ifdef __APPLE__
    /* The so-called POSIX-compliant MacOS X is not. 
     * SIGPIPE fires even when it is blocked in all threads! */
    signal (SIGPIPE, SIG_IGN);
#endif

#ifndef ALLOW_RUN_AS_ROOT
    if (geteuid () == 0)
    {
        fprintf (stderr, "VLC is not supposed to be run as root. Sorry.\n"
        "If you need to use real-time priorities and/or privileged TCP ports\n"
        "you can use %s-wrapper (make sure it is Set-UID root and\n"
        "cannot be run by non-trusted users first).\n", ppsz_argv[0]);
        return 1;
    }
#endif

    setlocale (LC_ALL, "");

#ifndef __APPLE__
    /* This clutters OSX GUI error logs */
    fprintf( stderr, "VLC media player %s\n", libvlc_get_version() );
#endif

#ifdef HAVE_PUTENV
#   ifndef NDEBUG
    /* Activate malloc checking routines to detect heap corruptions. */
    putenv( (char*)"MALLOC_CHECK_=2" );

    /* Disable the ugly Gnome crash dialog so that we properly segfault */
    putenv( (char *)"GNOME_DISABLE_CRASH_DIALOG=1" );
#   endif
#endif

    /* Synchronously intercepted POSIX signals.
     *
     * In a threaded program such as VLC, the only sane way to handle signals
     * is to block them in all thread but one - this is the only way to
     * predict which thread will receive them. If any piece of code depends
     * on delivery of one of this signal it is intrinsically not thread-safe
     * and MUST NOT be used in VLC, whether we like it or not.
     * There is only one exception: if the signal is raised with
     * pthread_kill() - we do not use this in LibVLC but some pthread
     * implementations use them internally. You should really use conditions
     * for thread synchronization anyway.
     *
     * Signal that request a clean shutdown, and force an unclean shutdown
     * if they are triggered again 2+ seconds later.
     * We have to handle SIGTERM cleanly because of daemon mode.
     * Note that we set the signals after the vlc_create call. */
    static const int sigs[] = {
        SIGINT, SIGHUP, SIGQUIT, SIGTERM,
    /* Signals that cause a no-op:
     * - SIGPIPE might happen with sockets and would crash VLC. It MUST be
     *   blocked by any LibVLC-dependent application, not just VLC.
     * - SIGCHLD comes after exec*() (such as httpd CGI support) and must
     *   be dequeued to cleanup zombie processes.
     */
        SIGPIPE, SIGCHLD
    };

    sigset_t set;
    sigemptyset (&set);
    for (unsigned i = 0; i < sizeof (sigs) / sizeof (sigs[0]); i++)
        sigaddset (&set, sigs[i]);

    /* Block all these signals */
    pthread_sigmask (SIG_BLOCK, &set, NULL);
    sigdelset (&set, SIGPIPE);
    sigdelset (&set, SIGCHLD);

    /* Note that FromLocale() can be used before libvlc is initialized */
    const char *argv[i_argc + 3];
    int argc = 0;

    argv[argc++] = "--no-ignore-config";
#ifdef TOP_BUILDDIR
    argv[argc++] = FromLocale ("--plugin-path="TOP_BUILDDIR"/modules");
#endif
#ifdef TOP_SRCDIR
# ifdef ENABLE_HTTPD
    argv[argc++] = FromLocale ("--http-src="TOP_SRCDIR"/share/http");
# endif
#endif

    for (int i = 1; i < i_argc; i++)
        if ((argv[argc++] = FromLocale (ppsz_argv[i])) == NULL)
            return 1; // BOOM!
    argv[argc] = NULL;

    libvlc_exception_t ex, dummy;
    libvlc_exception_init (&ex);
    libvlc_exception_init (&dummy);

    /* Initialize libvlc */
    libvlc_instance_t *vlc = libvlc_new (argc, argv, &ex);

    if (vlc != NULL)
    {
        libvlc_add_intf (vlc, "signals", &ex);
        if (libvlc_exception_raised (&ex))
        {
            libvlc_exception_clear (&ex);
            pthread_sigmask (SIG_UNBLOCK, &set, NULL);
        }
#if !defined (HAVE_MAEMO)
        libvlc_add_intf (vlc, "globalhotkeys,none", &ex);
#endif
        libvlc_exception_clear (&ex);
        libvlc_add_intf (vlc, NULL, &ex);
        libvlc_playlist_play (vlc, -1, 0, NULL, &dummy);
        libvlc_wait (vlc);

        if (libvlc_exception_raised (&ex))
            fprintf( stderr, "%s\n", libvlc_errmsg() );
        libvlc_release (vlc);
    }

    for (int i = 1; i < argc; i++)
        LocaleFree (argv[i]);

    return vlc == NULL || libvlc_exception_raised (&ex);
}
Exemple #10
0
mediacontrol_StreamInformation *
mediacontrol_get_stream_information( mediacontrol_Instance *self,
                                     mediacontrol_PositionKey a_key,
                                     mediacontrol_Exception *exception )
{
    (void)a_key;
    mediacontrol_StreamInformation *retval = NULL;
    libvlc_media_t * p_media;
    libvlc_exception_t ex;

    libvlc_exception_init( &ex );

    retval = ( mediacontrol_StreamInformation* )
                            malloc( sizeof( mediacontrol_StreamInformation ) );
    if( ! retval )
    {
        RAISE( mediacontrol_InternalException, "Out of memory" );
        return NULL;
    }

    p_media = libvlc_media_player_get_media( self->p_media_player, &ex );
    HANDLE_LIBVLC_EXCEPTION_NULL( &ex );
    if( ! p_media )
    {
        /* No p_media defined */
        retval->streamstatus = mediacontrol_UndefinedStatus;
        retval->url          = strdup( "" );
        retval->position     = 0;
        retval->length       = 0;
    }
    else
    {
        libvlc_state_t state;
        state = libvlc_media_player_get_state( self->p_media_player, &ex );
        HANDLE_LIBVLC_EXCEPTION_NULL( &ex );
        switch( state )
        {
        case libvlc_NothingSpecial:
            retval->streamstatus = mediacontrol_UndefinedStatus;
            break;
        case libvlc_Opening :
            retval->streamstatus = mediacontrol_InitStatus;
            break;
        case libvlc_Buffering:
            retval->streamstatus = mediacontrol_BufferingStatus;
            break;
        case libvlc_Playing:
            retval->streamstatus = mediacontrol_PlayingStatus;
            break;
        case libvlc_Paused:
            retval->streamstatus = mediacontrol_PauseStatus;
            break;
        case libvlc_Stopped:
            retval->streamstatus = mediacontrol_StopStatus;
            break;
        case libvlc_Forward:
            retval->streamstatus = mediacontrol_ForwardStatus;
            break;
        case libvlc_Backward:
            retval->streamstatus = mediacontrol_BackwardStatus;
            break;
        case libvlc_Ended:
            retval->streamstatus = mediacontrol_EndStatus;
            break;
        case libvlc_Error:
            retval->streamstatus = mediacontrol_ErrorStatus;
            break;
        default :
            retval->streamstatus = mediacontrol_UndefinedStatus;
            break;
        }

        retval->url = libvlc_media_get_mrl( p_media, &ex );
	
        retval->position = libvlc_media_player_get_time( self->p_media_player, &ex );
        if( libvlc_exception_raised( &ex ) )
        {
            libvlc_exception_clear( &ex );
            retval->position = 0;
        }

        retval->length = libvlc_media_player_get_length( self->p_media_player, &ex );
        if( libvlc_exception_raised( &ex ) )
        {
            libvlc_exception_clear( &ex );
            retval->length = 0;
        }

    }
    return retval;
}
Exemple #11
0
NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
{
    /* prepare VLC command line */
    const char *ppsz_argv[32];
    int ppsz_argc = 0;

#ifndef NDEBUG
    ppsz_argv[ppsz_argc++] = "--no-plugins-cache";
#endif

    /* locate VLC module path */
#ifdef XP_MACOSX
    ppsz_argv[ppsz_argc++] = "--plugin-path=/Library/Internet\\ Plug-Ins/VLC\\ Plugin.plugin/Contents/MacOS/modules";
    ppsz_argv[ppsz_argc++] = "--vout=minimal_macosx";
#elif defined(XP_WIN)
    HKEY h_key;
    DWORD i_type, i_data = MAX_PATH + 1;
    char p_data[MAX_PATH + 1];
    if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
                      0, KEY_READ, &h_key ) == ERROR_SUCCESS )
    {
         if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
                              (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
         {
             if( i_type == REG_SZ )
             {
                 strcat( p_data, "\\plugins" );
                 ppsz_argv[ppsz_argc++] = "--plugin-path";
                 ppsz_argv[ppsz_argc++] = p_data;
             }
         }
         RegCloseKey( h_key );
    }
    ppsz_argv[ppsz_argc++] = "--no-one-instance";

#endif /* XP_MACOSX */

    /* common settings */
    ppsz_argv[ppsz_argc++] = "-vv";
    ppsz_argv[ppsz_argc++] = "--no-stats";
    ppsz_argv[ppsz_argc++] = "--no-media-library";
    ppsz_argv[ppsz_argc++] = "--intf=dummy";
    ppsz_argv[ppsz_argc++] = "--no-video-title-show";

    const char *progid = NULL;

    /* parse plugin arguments */
    for( int i = 0; (i < argc) && (ppsz_argc < 32); i++ )
    {
       /* fprintf(stderr, "argn=%s, argv=%s\n", argn[i], argv[i]); */

        if( !strcmp( argn[i], "target" )
         || !strcmp( argn[i], "mrl")
         || !strcmp( argn[i], "filename")
         || !strcmp( argn[i], "src") )
        {
            psz_target = argv[i];
        }
        else if( !strcmp( argn[i], "text" ) )
        {
            free( psz_text );
            psz_text = strdup( argv[i] );
        }
        else if( !strcmp( argn[i], "autoplay")
              || !strcmp( argn[i], "autostart") )
        {
            b_autoplay = boolValue(argv[i]);
        }
        else if( !strcmp( argn[i], "fullscreen" ) )
        {
            if( boolValue(argv[i]) )
            {
                ppsz_argv[ppsz_argc++] = "--fullscreen";
            }
            else
            {
                ppsz_argv[ppsz_argc++] = "--no-fullscreen";
            }
        }
        else if( !strcmp( argn[i], "mute" ) )
        {
            if( boolValue(argv[i]) )
            {
                ppsz_argv[ppsz_argc++] = "--volume=0";
            }
        }
        else if( !strcmp( argn[i], "loop")
              || !strcmp( argn[i], "autoloop") )
        {
            if( boolValue(argv[i]) )
            {
                ppsz_argv[ppsz_argc++] = "--loop";
            }
            else
            {
                ppsz_argv[ppsz_argc++] = "--no-loop";
            }
        }
        else if( !strcmp( argn[i], "version")
              || !strcmp( argn[i], "progid") )
        {
            progid = argv[i];
        }
        else if( !strcmp( argn[i], "toolbar" ) )
        {
/* FIXME: Remove this when toolbar functionality has been implemented on
 * MacOS X and Win32 for Firefox/Mozilla/Safari. */
#ifdef XP_UNIX
            b_toolbar = boolValue(argv[i]);
#endif
        }
    }

    libvlc_exception_t ex;
    libvlc_exception_init(&ex);

    libvlc_instance = libvlc_new(ppsz_argc, ppsz_argv, &ex);
    if( libvlc_exception_raised(&ex) )
    {
        libvlc_exception_clear(&ex);
        return NPERR_GENERIC_ERROR;
    }

    libvlc_media_list = libvlc_media_list_new(libvlc_instance,&ex);
    if( libvlc_exception_raised(&ex) )
    {
        libvlc_exception_clear(&ex);
        return NPERR_GENERIC_ERROR;
    }

    /*
    ** fetch plugin base URL, which is the URL of the page containing the plugin
    ** this URL is used for making absolute URL from relative URL that may be
    ** passed as an MRL argument
    */
    NPObject *plugin = NULL;

    if( NPERR_NO_ERROR == NPN_GetValue(p_browser, NPNVWindowNPObject, &plugin) )
    {
        /*
        ** is there a better way to get that info ?
        */
        static const char docLocHref[] = "document.location.href";
        NPString script;
        NPVariant result;

        script.utf8characters = docLocHref;
        script.utf8length = sizeof(docLocHref)-1;

        if( NPN_Evaluate(p_browser, plugin, &script, &result) )
        {
            if( NPVARIANT_IS_STRING(result) )
            {
                NPString &location = NPVARIANT_TO_STRING(result);

                psz_baseURL = (char *) malloc(location.utf8length+1);
                if( psz_baseURL )
                {
                    strncpy(psz_baseURL, location.utf8characters, location.utf8length);
                    psz_baseURL[location.utf8length] = '\0';
                }
            }
            NPN_ReleaseVariantValue(&result);
        }
        NPN_ReleaseObject(plugin);
    }

    if( psz_target )
    {
        // get absolute URL from src
        char *psz_absurl = getAbsoluteURL(psz_target);
        psz_target = psz_absurl ? psz_absurl : strdup(psz_target);
    }

    /* assign plugin script root class */
    /* new APIs */
    p_scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();

    return NPERR_NO_ERROR;
}
Exemple #12
0
RuntimeNPObject::InvokeResult
LibvlcInputNPObject::getProperty(int index, NPVariant &result)
{
    /* is plugin still running */
    if( isPluginRunning() )
    {
        VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
        libvlc_exception_t ex;
        libvlc_exception_init(&ex);

        libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
        if( libvlc_exception_raised(&ex) )
        {
            if( index != ID_input_state )
            {
                NPN_SetException(this, libvlc_exception_get_message(&ex));
                libvlc_exception_clear(&ex);
                return INVOKERESULT_GENERIC_ERROR;
            }
            else
            {
                /* for input state, return CLOSED rather than an exception */
                INT32_TO_NPVARIANT(0, result);
                libvlc_exception_clear(&ex);
                return INVOKERESULT_NO_ERROR;
            }
        }

        switch( index )
        {
            case ID_input_length:
            {
                double val = (double)libvlc_media_player_get_length(p_md, &ex);
                RETURN_ON_EXCEPTION(this,ex);
                DOUBLE_TO_NPVARIANT(val, result);
                return INVOKERESULT_NO_ERROR;
            }
            case ID_input_position:
            {
                double val = libvlc_media_player_get_position(p_md, &ex);
                RETURN_ON_EXCEPTION(this,ex);
                DOUBLE_TO_NPVARIANT(val, result);
                return INVOKERESULT_NO_ERROR;
            }
            case ID_input_time:
            {
                double val = (double)libvlc_media_player_get_time(p_md, &ex);
                RETURN_ON_EXCEPTION(this,ex);
                DOUBLE_TO_NPVARIANT(val, result);
                return INVOKERESULT_NO_ERROR;
            }
            case ID_input_state:
            {
                int val = libvlc_media_player_get_state(p_md, &ex);
                RETURN_ON_EXCEPTION(this,ex);
                INT32_TO_NPVARIANT(val, result);
                return INVOKERESULT_NO_ERROR;
            }
            case ID_input_rate:
            {
                float val = libvlc_media_player_get_rate(p_md, &ex);
                RETURN_ON_EXCEPTION(this,ex);
                DOUBLE_TO_NPVARIANT(val, result);
                return INVOKERESULT_NO_ERROR;
            }
            case ID_input_fps:
            {
                double val = libvlc_media_player_get_fps(p_md, &ex);
                RETURN_ON_EXCEPTION(this,ex);
                DOUBLE_TO_NPVARIANT(val, result);
                return INVOKERESULT_NO_ERROR;
            }
            case ID_input_hasvout:
            {
                bool val = p_plugin->player_has_vout(&ex);
                RETURN_ON_EXCEPTION(this,ex);
                BOOLEAN_TO_NPVARIANT(val, result);
                return INVOKERESULT_NO_ERROR;
            }
            default:
                ;
        }
    }
    return INVOKERESULT_GENERIC_ERROR;
}