⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 services_discovery.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 2 页
字号:
    msg_Dbg( p_playlist, "Adding %s in %s",                p_input->psz_name ? p_input->psz_name : "(null)",                psz_cat ? psz_cat : "(null)" );    PL_LOCK;    /* If p_parent is in root category (this is clearly a hack) and we have a cat */    if( !EMPTY_STR(psz_cat) &&        p_parent->p_parent == p_playlist->p_root_category )    {        /* */        playlist_item_t * p_cat;        p_cat = playlist_ChildSearchName( p_parent, psz_cat );        if( !p_cat )        {            p_cat = playlist_NodeCreate( p_playlist, psz_cat,                                         p_parent, 0, NULL );            p_cat->i_flags &= ~PLAYLIST_SKIP_FLAG;        }        p_parent = p_cat;    }    p_new_item = playlist_NodeAddInput( p_playlist, p_input, p_parent,                                        PLAYLIST_APPEND, PLAYLIST_END, pl_Locked );    if( p_new_item )    {        p_new_item->i_flags &= ~PLAYLIST_SKIP_FLAG;        p_new_item->i_flags &= ~PLAYLIST_SAVE_FLAG;    }    PL_UNLOCK;} /* A new item has been removed from a certain sd */static void playlist_sd_item_removed( const vlc_event_t * p_event, void * user_data ){    input_item_t * p_input = p_event->u.services_discovery_item_removed.p_item;    playlist_item_t * p_parent = user_data;    playlist_item_t * p_pl_item;    /* First make sure that if item is a node it will be deleted.     * XXX: Why don't we have a function to ensure that in the playlist code ? */    vlc_object_lock( p_parent->p_playlist );    p_pl_item = playlist_ItemFindFromInputAndRoot( p_parent->p_playlist,            p_input->i_id, p_parent, false );    if( p_pl_item && p_pl_item->i_children > -1 )    {        playlist_NodeDelete( p_parent->p_playlist, p_pl_item, true, false );        vlc_object_unlock( p_parent->p_playlist );        return;    }    /* Delete the non-node item normally */    playlist_DeleteFromInputInParent( p_parent->p_playlist, p_input->i_id,                                      p_parent, pl_Locked );    vlc_object_unlock( p_parent->p_playlist );}int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist,  const char *psz_modules ){    const char *psz_parser = psz_modules ?: "";    int retval = VLC_SUCCESS;    for (;;)    {        struct playlist_services_discovery_support_t * p_sds;        playlist_item_t * p_cat;        playlist_item_t * p_one;        while( *psz_parser == ' ' || *psz_parser == ':' || *psz_parser == ',' )            psz_parser++;        if( *psz_parser == '\0' )            break;        const char *psz_next = strchr( psz_parser, ':' );        if( psz_next == NULL )            psz_next = psz_parser + strlen( psz_parser );        char psz_plugin[psz_next - psz_parser + 1];        memcpy (psz_plugin, psz_parser, sizeof (psz_plugin) - 1);        psz_plugin[sizeof (psz_plugin) - 1] = '\0';        psz_parser = psz_next;        /* Perform the addition */        msg_Dbg( p_playlist, "Add services_discovery %s", psz_plugin );        services_discovery_t *p_sd;        p_sd = services_discovery_Create( (vlc_object_t*)p_playlist, psz_plugin );        if( !p_sd )            continue;        char * psz = services_discovery_GetLocalizedName( p_sd );        assert( psz );        PL_LOCK;        playlist_NodesPairCreate( p_playlist, psz,                &p_cat, &p_one, false );        PL_UNLOCK;        free( psz );        vlc_event_attach( services_discovery_EventManager( p_sd ),                          vlc_ServicesDiscoveryItemAdded,                          playlist_sd_item_added,                          p_one );        vlc_event_attach( services_discovery_EventManager( p_sd ),                          vlc_ServicesDiscoveryItemAdded,                          playlist_sd_item_added,                          p_cat );        vlc_event_attach( services_discovery_EventManager( p_sd ),                          vlc_ServicesDiscoveryItemRemoved,                          playlist_sd_item_removed,                          p_one );        vlc_event_attach( services_discovery_EventManager( p_sd ),                          vlc_ServicesDiscoveryItemRemoved,                          playlist_sd_item_removed,                          p_cat );        services_discovery_Start( p_sd );        /* Free in playlist_ServicesDiscoveryRemove */        p_sds = malloc( sizeof(struct playlist_services_discovery_support_t) );        if( !p_sds )            return VLC_ENOMEM;        /* We want tree-view for service directory */        p_one->p_input->b_prefers_tree = true;        p_sds->p_sd = p_sd;        p_sds->p_one = p_one;        p_sds->p_cat = p_cat;        PL_LOCK;        TAB_APPEND( p_playlist->i_sds, p_playlist->pp_sds, p_sds );        PL_UNLOCK;    }    return retval;}int playlist_ServicesDiscoveryRemove( playlist_t * p_playlist,                                       const char *psz_module ){    struct playlist_services_discovery_support_t * p_sds = NULL;    int i;    PL_LOCK;    for( i = 0 ; i< p_playlist->i_sds ; i ++ )    {        if( !strcmp( psz_module, p_playlist->pp_sds[i]->p_sd->psz_module ) )        {            p_sds = p_playlist->pp_sds[i];            REMOVE_ELEM( p_playlist->pp_sds, p_playlist->i_sds, i );            break;        }    }    PL_UNLOCK;    if( !p_sds || !p_sds->p_sd )    {        msg_Warn( p_playlist, "module %s is not loaded", psz_module );        return VLC_EGENERIC;    }    services_discovery_Stop( p_sds->p_sd );    vlc_event_detach( services_discovery_EventManager( p_sds->p_sd ),                        vlc_ServicesDiscoveryItemAdded,                        playlist_sd_item_added,                        p_sds->p_one );    vlc_event_detach( services_discovery_EventManager( p_sds->p_sd ),                        vlc_ServicesDiscoveryItemAdded,                        playlist_sd_item_added,                        p_sds->p_cat );    vlc_event_detach( services_discovery_EventManager( p_sds->p_sd ),                        vlc_ServicesDiscoveryItemRemoved,                        playlist_sd_item_removed,                        p_sds->p_one );    vlc_event_detach( services_discovery_EventManager( p_sds->p_sd ),                        vlc_ServicesDiscoveryItemRemoved,                        playlist_sd_item_removed,                        p_sds->p_cat );    /* Remove the sd playlist node if it exists */    PL_LOCK;    if( p_sds->p_cat != p_playlist->p_root_category &&        p_sds->p_one != p_playlist->p_root_onelevel )    {        playlist_NodeDelete( p_playlist, p_sds->p_cat, true, false );        playlist_NodeDelete( p_playlist, p_sds->p_one, true, false );    }    PL_UNLOCK;    services_discovery_Destroy( p_sds->p_sd );    free( p_sds );    return VLC_SUCCESS;}bool playlist_IsServicesDiscoveryLoaded( playlist_t * p_playlist,                                              const char *psz_module ){    int i;    PL_LOCK;    for( i = 0 ; i< p_playlist->i_sds ; i ++ )    {        if( !strcmp( psz_module, p_playlist->pp_sds[i]->p_sd->psz_module ) )        {            PL_UNLOCK;            return true;        }    }    PL_UNLOCK;    return false;}void playlist_ServicesDiscoveryKillAll( playlist_t *p_playlist ){    while( p_playlist->i_sds > 0 )        playlist_ServicesDiscoveryRemove( p_playlist,                                     p_playlist->pp_sds[0]->p_sd->psz_module );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -