Пример #1
0
/**************************************************************************
 * release (Public)
 **************************************************************************/
void
libvlc_media_discoverer_release( libvlc_media_discoverer_t * p_mdis )
{
    int i;

    vlc_event_detach( services_discovery_EventManager( p_mdis->p_sd ),
                     vlc_ServicesDiscoveryItemAdded,
                     services_discovery_item_added,
                     p_mdis );
    vlc_event_detach( services_discovery_EventManager( p_mdis->p_sd ),
                     vlc_ServicesDiscoveryItemRemoved,
                     services_discovery_item_removed,
                     p_mdis );
    vlc_event_detach( services_discovery_EventManager( p_mdis->p_sd ),
                     vlc_ServicesDiscoveryStarted,
                     services_discovery_started,
                     p_mdis );
    vlc_event_detach( services_discovery_EventManager( p_mdis->p_sd ),
                     vlc_ServicesDiscoveryEnded,
                     services_discovery_ended,
                     p_mdis );
    vlc_event_detach( services_discovery_EventManager( p_mdis->p_sd ),
                     vlc_ServicesDiscoveryItemRemoveAll,
                     services_discovery_removeall,
                     p_mdis );

    libvlc_media_list_release( p_mdis->p_mlist );

    if( p_mdis->running )
        vlc_sd_Stop( p_mdis->p_sd );

    vlc_sd_Destroy( p_mdis->p_sd );

    /* Free catname_to_submedialist and all the mlist */
    char ** all_keys = vlc_dictionary_all_keys( &p_mdis->catname_to_submedialist );
    for( i = 0; all_keys[i]; i++ )
    {
        libvlc_media_list_t * p_catmlist = vlc_dictionary_value_for_key( &p_mdis->catname_to_submedialist, all_keys[i] );
        libvlc_media_list_release( p_catmlist );
        free( all_keys[i] );
    }
    free( all_keys );

    vlc_dictionary_clear( &p_mdis->catname_to_submedialist, NULL, NULL );
    libvlc_event_manager_release( p_mdis->p_event_manager );
    libvlc_release( p_mdis->p_libvlc_instance );

    free( p_mdis );
}
Пример #2
0
static void
media_list_subitem_added( const libvlc_event_t * p_event, void * p_user_data )
{
    libvlc_media_list_t * p_mlist;
    libvlc_event_t added_event;
    libvlc_media_list_view_t * p_mlv = p_user_data;
    libvlc_media_t * p_submd = p_event->u.media_subitem_added.new_child;
    libvlc_media_t * p_md = p_event->p_obj;

    if((p_mlist = libvlc_media_subitems( p_md )))
    {
        /* We have a mlist to which we're going to listen to events
         * thus, no need to wait for SubItemAdded events */
        libvlc_event_detach( p_md->p_event_manager,
                             libvlc_MediaSubItemAdded,
                             media_list_subitem_added, p_mlv, NULL );
        libvlc_media_list_lock( p_mlist );

        libvlc_event_attach( p_mlist->p_event_manager,
                             libvlc_MediaListItemAdded,
                             media_list_item_added, p_mlv, NULL );
        libvlc_event_attach( p_mlist->p_event_manager,
                             libvlc_MediaListItemDeleted,
                             media_list_item_removed, p_mlv, NULL );
        libvlc_media_list_unlock( p_mlist );
        libvlc_media_list_release( p_mlist );
    }

    install_md_listener( p_mlv, p_submd );

    added_event.u.media_list_item_added.item = p_submd;
    added_event.u.media_list_item_added.index = 0;
    if( p_mlv->pf_ml_item_added ) p_mlv->pf_ml_item_added( &added_event, p_mlv );
}
Пример #3
0
static int expand_media_internal(JNIEnv *env, libvlc_instance_t* p_instance, jobject arrayList, libvlc_media_t* p_md) {
    if(!p_md) {
        return -1;
    }
    libvlc_media_list_t* p_subitems = libvlc_media_subitems(p_md);
    libvlc_media_release(p_md);
    if(p_subitems) {
        // Expand any subitems if needed
        int subitem_count = libvlc_media_list_count(p_subitems);
        if(subitem_count > 0) {
            LOGD("Found %d subitems, expanding", subitem_count);
            jclass arrayListClass; jmethodID methodAdd;
            arrayListGetIDs(env, &arrayListClass, &methodAdd, NULL);

            for(int i = subitem_count - 1; i >= 0; i--) {
                libvlc_media_t* p_subitem = libvlc_media_list_item_at_index(p_subitems, i);
                char* p_subitem_uri = libvlc_media_get_mrl(p_subitem);
                arrayListStringAdd(env, arrayListClass, methodAdd, arrayList, p_subitem_uri);
                free(p_subitem_uri);
            }
        }
        libvlc_media_list_release(p_subitems);
        if(subitem_count > 0) {
            return 0;
        } else {
            return -1;
        }
    } else {
        return -1;
    }
}
/**************************************************************************
 *       flat_media_list_view_item_at_index  (private)
 * (called by flat_media_list_view_item_at_index)
 **************************************************************************/
static libvlc_media_t *
hierarch_node_media_list_view_item_at_index( libvlc_media_list_view_t * p_mlv,
                                        int index,
                                        libvlc_exception_t * p_e )
{
    /* FIXME: we may want to cache that */
    libvlc_media_t * p_md;
    libvlc_media_list_t * p_submlist;
    trace("%d\n", index);
    int i, current_index, count = libvlc_media_list_count( p_mlv->p_mlist, p_e );
    current_index = -1;
    for( i = 0; i < count; i++ )
    {
        p_md = libvlc_media_list_item_at_index( p_mlv->p_mlist, i, p_e );
        if( !p_md ) continue;
        p_submlist = libvlc_media_subitems( p_md );
        if( !p_submlist ) continue;
        libvlc_media_list_release( p_submlist );
        current_index++;
        if( current_index == index )
            return p_md;
        libvlc_media_release( p_md );
    }

    libvlc_exception_raise( p_e );
    libvlc_printerr( "Index out of bound in Media List View" );
    return NULL;
}
Пример #5
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 );
    }
}
Пример #6
0
/* Little helper */
static void
import_mlist_rec( libvlc_media_list_view_t * p_mlv,
                  libvlc_media_list_t * p_mlist,
                  libvlc_exception_t * p_e )
{
    int i, count;
    count = libvlc_media_list_count( p_mlist, p_e );
    for( i = 0; i < count; i++ )
    {
        libvlc_media_t * p_md;
        libvlc_media_list_t * p_submlist;
        p_md = libvlc_media_list_item_at_index( p_mlist, i, p_e );
        vlc_array_append( &p_mlv->p_this_view_data->array, p_md );
        p_submlist = libvlc_media_subitems( p_md );
        if( p_submlist )
        {
            libvlc_media_list_lock( p_submlist );
            import_mlist_rec( p_mlv, p_submlist, p_e );
            libvlc_media_list_unlock( p_submlist );
            libvlc_media_list_release( p_submlist );
        }
        /* No need to release the md, as we want to retain it, as it is
         * stored in our array */
    }
}
Пример #7
0
VideoSource::~VideoSource()
{ 

    // media list and media list player
    libvlc_media_list_player_stop(mediaListPlayer);
    libvlc_media_list_player_release(mediaListPlayer);
    libvlc_media_list_release(mediaList);

    // media player
    libvlc_video_set_callbacks(mediaPlayer, nullptr, nullptr, nullptr, nullptr);
    libvlc_media_player_stop(mediaPlayer);
        

    delete audioOutputStreamHandler;
    audioOutputStreamHandler = nullptr;


    libvlc_media_player_release(mediaPlayer);

    if (pixelData) {
        free(pixelData);
        pixelData = nullptr;
    }

    if (texture) {
        delete texture;
        texture = nullptr;
    }

    delete config;
    config = nullptr;

    DeleteCriticalSection(&textureLock);
}
Пример #8
0
/**************************************************************************
 *       load (Public)
 *
 * It doesn't yet load the playlists
 **************************************************************************/
int libvlc_media_library_load( libvlc_media_library_t * p_mlib )
{
    char *psz_datadir = config_GetUserDir( VLC_DATA_DIR );
    char * psz_uri;

    if( psz_datadir == NULL
            || asprintf( &psz_uri, "file/xspf-open://%s" DIR_SEP "ml.xsp",
                         psz_datadir ) == -1 )
        psz_uri = NULL;
    free( psz_datadir );

    if( psz_uri == NULL )
    {
        libvlc_printerr( "Not enough memory" );
        return -1;
    }

    if( p_mlib->p_mlist )
        libvlc_media_list_release( p_mlib->p_mlist );

    p_mlib->p_mlist = libvlc_media_list_new( p_mlib->p_libvlc_instance );

    int ret = libvlc_media_list_add_file_content( p_mlib->p_mlist, psz_uri );
    free( psz_uri );
    return ret;
}
Пример #9
0
/**************************************************************************
 * Delete a media descriptor object
 **************************************************************************/
void libvlc_media_release( libvlc_media_t *p_md )
{
    if (!p_md)
        return;

    p_md->i_refcount--;

    if( p_md->i_refcount > 0 )
        return;

    if( p_md->p_subitems )
        libvlc_media_list_release( p_md->p_subitems );

    uninstall_input_item_observer( p_md );
    vlc_gc_decref( p_md->p_input_item );

    vlc_cond_destroy( &p_md->parsed_cond );
    vlc_mutex_destroy( &p_md->parsed_lock );

    /* Construct the event */
    libvlc_event_t event;
    event.type = libvlc_MediaFreed;
    event.u.media_freed.md = p_md;

    /* Send the event */
    libvlc_event_send( p_md->p_event_manager, &event );

    libvlc_event_manager_release( p_md->p_event_manager );

    free( p_md );
}
Пример #10
0
VlcMediaList::~VlcMediaList()
{
    foreach(VlcMedia *m, _list)
        delete m;

    removeCoreConnections();

    libvlc_media_list_release(_vlcMediaList);

    VlcError::errmsg();
}
static bool
item_is_already_added( libvlc_media_t * p_md )
{
    libvlc_media_list_t * p_submlist;

    p_submlist = libvlc_media_subitems( p_md );
    if( !p_submlist ) return false;
    int count = libvlc_media_list_count( p_submlist, NULL );
    libvlc_media_list_release( p_submlist );
    return count > 1;
}
Пример #12
0
VlcPlugin::~VlcPlugin()
{
    free(psz_baseURL);
    free(psz_target);
    free(psz_text);

    if( libvlc_media_player )
        libvlc_media_player_release( libvlc_media_player );
    if( libvlc_media_list )
        libvlc_media_list_release( libvlc_media_list );
    if( libvlc_instance )
        libvlc_release(libvlc_instance);
}
Пример #13
0
/**************************************************************************
 * release (Public)
 **************************************************************************/
void
libvlc_media_discoverer_release( libvlc_media_discoverer_t * p_mdis )
{
    int i;

    libvlc_media_list_release( p_mdis->p_mlist );
    services_discovery_Destroy( p_mdis->p_sd );

    /* Free catname_to_submedialist and all the mlist */
    char ** all_keys = vlc_dictionary_all_keys( &p_mdis->catname_to_submedialist );
    for( i = 0; all_keys[i]; i++ )
    {
        libvlc_media_list_t * p_catmlist = vlc_dictionary_value_for_key( &p_mdis->catname_to_submedialist, all_keys[i] );
        libvlc_media_list_release( p_catmlist );
        free( all_keys[i] );
    }
    free( all_keys );

    vlc_dictionary_clear( &p_mdis->catname_to_submedialist );

    free( p_mdis );
}
Пример #14
0
static void
test_media_has_slaves_from_parent(libvlc_instance_t *p_vlc,
                                  libvlc_media_slave_t *p_expected_slaves,
                                  unsigned i_expected_slaves)
{
    libvlc_media_t *p_m = libvlc_media_new_path(p_vlc, SLAVES_DIR);
    assert(p_m != NULL);

    printf("Parse media dir to get subitems\n");
    media_parse_sync(p_m);

    char *psz_main_media_mrl = path_to_mrl(p_vlc, MAIN_MEDIA_PATH);
    assert(psz_main_media_mrl != NULL);
    printf("Main media mrl: '%s'\n", psz_main_media_mrl);

    printf("Fetch main media from subitems\n");
    libvlc_media_list_t *p_ml = libvlc_media_subitems(p_m);
    assert(p_ml != NULL);
    libvlc_media_list_lock(p_ml);
    int i_count = libvlc_media_list_count(p_ml);
    assert(i_count > 0);
    libvlc_media_t *p_subm = NULL;
    for (int i = 0; i < i_count; ++i)
    {
        p_subm = libvlc_media_list_item_at_index(p_ml, i);
        assert(p_subm != NULL);
        char *psz_mrl = libvlc_media_get_mrl(p_subm);
        assert(psz_mrl != NULL);
        if (strcmp(psz_main_media_mrl, psz_mrl) == 0)
        {
            printf("Found main media\n");
            free(psz_mrl);
            break;
        }
        free(psz_mrl);
        libvlc_media_release(p_subm);
        p_subm = NULL;
    }
    free(psz_main_media_mrl);
    libvlc_media_list_unlock(p_ml);
    libvlc_media_list_release(p_ml);

    assert(p_subm != NULL);
    test_expected_slaves(p_subm, p_expected_slaves, i_expected_slaves);
    libvlc_media_release(p_subm);

    libvlc_media_release(p_m);
}
Пример #15
0
void
libvlc_media_discoverer_release( libvlc_media_discoverer_t * p_mdis )
{
    if( p_mdis->p_sd != NULL )
        libvlc_media_discoverer_stop( p_mdis );

    libvlc_media_list_release( p_mdis->p_mlist );

    vlc_dictionary_clear( &p_mdis->catname_to_submedialist,
        MediaListDictValueRelease, NULL );

    libvlc_event_manager_destroy( &p_mdis->event_manager );
    libvlc_release( p_mdis->p_libvlc_instance );

    free( p_mdis );
}
Пример #16
0
/**************************************************************************
 *       libvlc_media_list_view_children_for_item (Public)
 **************************************************************************/
libvlc_media_list_view_t *
libvlc_media_list_view_children_for_item( libvlc_media_list_view_t * p_mlv,
                                          libvlc_media_t * p_md,
                                          libvlc_exception_t * p_e)
{
    (void)p_e;
    libvlc_media_list_t * p_mlist;
    libvlc_media_list_view_t * ret;

    p_mlist = libvlc_media_subitems(p_md);
    if(!p_mlist) return NULL;

    ret = p_mlv->pf_constructor( p_mlist, p_e );
    libvlc_media_list_release( p_mlist );

    return ret;
}
Пример #17
0
/**************************************************************************
 *       set_media_list (Public)
 **************************************************************************/
void libvlc_media_list_player_set_media_list(libvlc_media_list_player_t * p_mlp, libvlc_media_list_t * p_mlist)
{
    assert (p_mlist);

    lock(p_mlp);
    if (p_mlp->p_mlist)
    {
        uninstall_playlist_observer(p_mlp);
        libvlc_media_list_release(p_mlp->p_mlist);
    }
    libvlc_media_list_retain(p_mlist);
    p_mlp->p_mlist = p_mlist;

    install_playlist_observer(p_mlp);

    unlock(p_mlp);
}
Пример #18
0
/**************************************************************************
 *       set_media_list (Public)
 **************************************************************************/
void libvlc_media_list_player_set_media_list(libvlc_media_list_player_t * p_mlp, libvlc_media_list_t * p_mlist, libvlc_exception_t * p_e)
{
    VLC_UNUSED( p_e );
    assert (p_mlist);

    lock(p_mlp);
    if (p_mlp->p_mlist)
    {
        uninstall_playlist_observer(p_mlp);
        libvlc_media_list_release(p_mlp->p_mlist);
    }
    libvlc_media_list_retain(p_mlist);
    p_mlp->p_mlist = p_mlist;
 
    install_playlist_observer(p_mlp);

    unlock(p_mlp);
}
Пример #19
0
/**************************************************************************
 *       flat_media_list_view_item_at_index  (private)
 * (called by flat_media_list_view_item_at_index)
 **************************************************************************/
static libvlc_media_list_view_t *
hierarch_media_list_view_children_at_index( libvlc_media_list_view_t * p_mlv,
                                        int index,
                                        libvlc_exception_t * p_e )
{
    libvlc_media_t * p_md;
    libvlc_media_list_t * p_submlist;
    libvlc_media_list_view_t * p_ret;
    p_md = libvlc_media_list_item_at_index( p_mlv->p_mlist, index, p_e );
    if( !p_md ) return NULL;
    p_submlist = libvlc_media_subitems( p_md, p_e );
    libvlc_media_release( p_md );
    if( !p_submlist ) return NULL;
    p_ret = libvlc_media_list_hierarchical_view( p_submlist, p_e );
    libvlc_media_list_release( p_submlist );

    return p_ret;
}
Пример #20
0
/**************************************************************************
 *       libvlc_media_list_view_release (Public)
 **************************************************************************/
void
libvlc_media_list_view_release( libvlc_media_list_view_t * p_mlv )
{
    vlc_mutex_lock( &p_mlv->object_lock );
    p_mlv->i_refcount--;
    if( p_mlv->i_refcount > 0 )
    {
        vlc_mutex_unlock( &p_mlv->object_lock );
        return;
    }
    vlc_mutex_unlock( &p_mlv->object_lock );

    /* Refcount null, time to free */
    libvlc_media_list_lock( p_mlv->p_mlist );

    if( p_mlv->pf_ml_item_added )
    {
        libvlc_event_detach( p_mlv->p_mlist->p_event_manager,
                            libvlc_MediaListItemAdded,
                            media_list_item_added, p_mlv, NULL );
    }
    if( p_mlv->pf_ml_item_removed )
    {
        libvlc_event_detach( p_mlv->p_mlist->p_event_manager,
                            libvlc_MediaListItemDeleted,
                            media_list_item_removed, p_mlv, NULL );
    }
    int i, count = libvlc_media_list_count( p_mlv->p_mlist, NULL );
    for( i = 0; i < count; i++)
    {
        libvlc_media_t * p_md;
        p_md = libvlc_media_list_item_at_index( p_mlv->p_mlist, i, NULL );
        uninstall_md_listener( p_mlv, p_md );
        libvlc_media_release( p_md );
    }
    libvlc_media_list_unlock( p_mlv->p_mlist );

    libvlc_event_manager_release( p_mlv->p_event_manager );

    if( p_mlv->pf_release ) p_mlv->pf_release( p_mlv );
    libvlc_media_list_release( p_mlv->p_mlist );
    vlc_mutex_destroy( &p_mlv->object_lock );
}
Пример #21
0
static PP_Bool remove_instance(instance_t* instance) {
  assert(instance != NULL);
  assert(g_instances != NULL && g_instances->count > 0);

  const size_t new_bytes = sizeof(instance_t) * (g_instances->count - 1);
  instances_t* new_instances = malloc(new_bytes + sizeof(instances_t));
  CHECKMALLOC("malloc new_instances", new_instances, PP_FALSE);

  new_instances->count = g_instances->count - 1;

  instance_t* cur_array = get_instances_array(g_instances);
  instance_t* new_array = get_instances_array(new_instances);

  if(new_instances->count != 0) {
    const size_t slice_start = (size_t)(instance - cur_array);
    const size_t slice_end   = slice_start + 1;
    memmove(new_array, cur_array, (size_t)(instance - cur_array));
    memmove((uint8_t*)new_array + slice_start,
            (uint8_t*)cur_array + slice_end,
            new_bytes - slice_end);
  }

  instances_t* old_instances = g_instances;
  g_instances = new_instances;

  if(instance->vlc != NULL) {
    libvlc_release(instance->vlc);
  }
  if(instance->media_player != NULL) {
    libvlc_media_player_release(instance->media_player);
  }
  if(instance->media_list_player != NULL) {
    libvlc_media_list_player_release(instance->media_list_player);
  }
  if(instance->playlist != NULL) {
    libvlc_media_list_release(instance->playlist);
  }

  free(old_instances);

  return PP_OK;
}
Пример #22
0
static void
install_md_listener( libvlc_media_list_view_t * p_mlv,
                     libvlc_media_t * p_md)
{
    libvlc_media_list_t * p_mlist;
    if((p_mlist = libvlc_media_subitems( p_md )))
    {
        libvlc_media_list_lock( p_mlist );
        int i, count = libvlc_media_list_count( p_mlist, NULL );
        for( i = 0; i < count; i++)
        {
            libvlc_event_t added_event;
            libvlc_media_t * p_submd;
            p_submd = libvlc_media_list_item_at_index( p_mlist, i, NULL );

            /* Install our listeners */
            install_md_listener( p_mlv, p_submd );

            /* For each item, send a notification to the mlv subclasses */
            added_event.u.media_list_item_added.item = p_submd;
            added_event.u.media_list_item_added.index = 0;
            if( p_mlv->pf_ml_item_added ) p_mlv->pf_ml_item_added( &added_event, p_mlv );
            libvlc_media_release( p_submd );
        }
        libvlc_event_attach( p_mlist->p_event_manager,
                             libvlc_MediaListItemAdded,
                             media_list_item_added, p_mlv, NULL );
        libvlc_event_attach( p_mlist->p_event_manager,
                             libvlc_MediaListItemDeleted,
                             media_list_item_removed, p_mlv, NULL );
        libvlc_media_list_unlock( p_mlist );
        libvlc_media_list_release( p_mlist );
    }
    else
    {
        /* No mlist, wait for a subitem added event */
        libvlc_event_attach( p_md->p_event_manager,
                            libvlc_MediaSubItemAdded,
                            media_list_subitem_added, p_mlv, NULL );
    }
}
Пример #23
0
/**************************************************************************
 *         release (Public)
 **************************************************************************/
void libvlc_media_list_player_release(libvlc_media_list_player_t * p_mlp)
{
    if (!p_mlp)
        return;

    lock(p_mlp);
    p_mlp->i_refcount--;
    if (p_mlp->i_refcount > 0)
    {
        unlock(p_mlp);
        return;
    }
    assert(p_mlp->i_refcount == 0);
    unlock(p_mlp);

    vlc_cancel(p_mlp->thread);
    vlc_join(p_mlp->thread, NULL);

    lock(p_mlp);
    /* Keep the lock(), because the uninstall functions
     * check for it. That's convenient. */
    uninstall_media_player_observer(p_mlp);
    libvlc_media_player_release(p_mlp->p_mi);

    if (p_mlp->p_mlist)
    {
        uninstall_playlist_observer(p_mlp);
        libvlc_media_list_release(p_mlp->p_mlist);
    }

    unlock(p_mlp);

    libvlc_event_manager_destroy(&p_mlp->event_manager);
    vlc_cond_destroy(&p_mlp->seek_pending);
    vlc_mutex_destroy(&p_mlp->mp_callback_lock);
    vlc_mutex_destroy(&p_mlp->object_lock);

    free(p_mlp->current_playing_item_path);
    free(p_mlp);
}
/* Helper */
static int
index_of_item( libvlc_media_list_view_t * p_mlv, libvlc_media_t * p_md )
{
    libvlc_media_t * p_iter_md;
    libvlc_media_list_t * p_submlist;

    int i, current_index, count = libvlc_media_list_count( p_mlv->p_mlist, NULL );
    current_index = -1;
    for( i = 0; i < count; i++ )
    {
        p_iter_md = libvlc_media_list_item_at_index( p_mlv->p_mlist, i, NULL );
        if( !p_iter_md ) continue;
        p_submlist = libvlc_media_subitems( p_iter_md );
        if( !p_submlist ) continue;
        libvlc_media_list_release( p_submlist );
        libvlc_media_release( p_iter_md );
        current_index++;
        if( p_md == p_iter_md )
            return current_index;
    }
    return -1;
}
/**************************************************************************
 *       flat_media_list_view_count  (private)
 * (called by media_list_view_count)
 **************************************************************************/
static int
hierarch_node_media_list_view_count( libvlc_media_list_view_t * p_mlv,
                                libvlc_exception_t * p_e )
{
    /* FIXME: we may want to cache that */
    int i, ret, count = libvlc_media_list_count( p_mlv->p_mlist, p_e );
    libvlc_media_t * p_md;
    libvlc_media_list_t * p_submlist;
    ret = 0;
    trace("\n");
    for( i = 0; i < count; i++ )
    {
        p_md = libvlc_media_list_item_at_index( p_mlv->p_mlist, i, p_e );
        if( !p_md ) continue;
        p_submlist = libvlc_media_subitems( p_md );
        if( !p_submlist ) continue;
        libvlc_media_release( p_md );
        libvlc_media_list_release( p_submlist );
        ret++;
    }
    return ret;
}
Пример #26
0
/**************************************************************************
 *       find_last_item (private)
 *
 *  Returns the path of the last descendant of a given item path.
 *  Note: Due to the recursive nature of the function and the need to free
 *        media list paths, paths passed in may be freed if they are replaced.
          Recommended usage is to set return value to the same path that was 
          passed to the function (i.e. item = find_last_item(list, item); )
 **************************************************************************/
static libvlc_media_list_path_t
find_last_item( libvlc_media_list_t * p_mlist, libvlc_media_list_path_t current_item )
{
    libvlc_media_list_t * p_sublist = libvlc_media_list_sublist_at_path(p_mlist, current_item);
    libvlc_media_list_path_t last_item_path = current_item;

    if(p_sublist)
    {
        int i_count = libvlc_media_list_count(p_sublist, NULL);
        if(i_count > 0)
        {
            /* Add the last sublist item to the path. */
            last_item_path = libvlc_media_list_path_copy_by_appending(current_item, i_count - 1);
            free(current_item);
            /* Check that sublist item for more descendants. */
            last_item_path = find_last_item(p_mlist, last_item_path);
        }

        libvlc_media_list_release(p_sublist);
    }    

    return last_item_path;
}
Пример #27
0
/**************************************************************************
 *       get_previous_path (private)
 *
 *  Returns the path to the preceding item in the list.  
 *  If looping is specified and the current item is the first list item in
 *  the list it will return the last descendant of the last item in the list.
 **************************************************************************/
static libvlc_media_list_path_t
get_previous_path(libvlc_media_list_player_t * p_mlp, bool b_loop)
{
    assert_locked(p_mlp);

    /* We are entered with libvlc_media_list_lock(p_mlp->p_list) */
    libvlc_media_list_path_t ret;
    libvlc_media_list_t * p_parent_of_playing_item;

    if (!p_mlp->current_playing_item_path)
    {
        if (!libvlc_media_list_count(p_mlp->p_mlist, NULL))
            return NULL;
        return libvlc_media_list_path_with_root_index(0);
    }
    
    /* Try to catch parent element */
    p_parent_of_playing_item = libvlc_media_list_parentlist_at_path(
                                            p_mlp->p_mlist,
                                            p_mlp->current_playing_item_path);

    int depth = libvlc_media_list_path_depth(p_mlp->current_playing_item_path);
    if (depth < 1 || !p_parent_of_playing_item)
        return NULL;

    /* Set the return path to the current path */
    ret = libvlc_media_list_path_copy(p_mlp->current_playing_item_path);

    /* Change the return path to the previous list entry */
    ret[depth - 1]--; /* set to previous element */
    ret[depth] = -1;

    /* Is the return path is beyond the start of the current list? */
    if(ret[depth - 1] < 0)
    {
        /* Move to parent of current item */
        depth--;

        /* Are we at the root level of the tree? */
        if (depth <= 0)
        {
            // Is looping enabled?
            if(b_loop)
            {
                int i_count = libvlc_media_list_count(p_parent_of_playing_item, NULL);

                /* Set current play item to the last element in the list */
                ret[0] = i_count - 1;
                ret[1] = -1;

                /* Set the return path to the last descendant item of the current item */
                ret = find_last_item(p_mlp->p_mlist, ret);
            }
            else
            {
                /* No looping so return empty path. */
                free(ret);
                ret = NULL;
            }
        }
        else
        {
            /* This is the case of moving backward from the beginning of the
            *  subitem list to its parent item.
            *  This ensures that current path is properly terminated to
            *  use that parent.
            */
            ret[depth] = -1;
        }
    }
    else
    {
        ret = find_last_item(p_mlp->p_mlist, ret);
    }

    libvlc_media_list_release(p_parent_of_playing_item);
    return ret;
}
Пример #28
0
/**************************************************************************
 *       get_next_path (private)
 *
 *  Returns the path to the next item in the list.  
 *  If looping is specified and the current item is the last list item in
 *  the list it will return the first item in the list.
 **************************************************************************/
static libvlc_media_list_path_t
get_next_path(libvlc_media_list_player_t * p_mlp, bool b_loop)
{
    assert_locked(p_mlp);

    /* We are entered with libvlc_media_list_lock(p_mlp->p_list) */
    libvlc_media_list_path_t ret;
    libvlc_media_list_t * p_parent_of_playing_item;
    libvlc_media_list_t * p_sublist_of_playing_item;

    if (!p_mlp->current_playing_item_path)
    {
        if (!libvlc_media_list_count(p_mlp->p_mlist, NULL))
            return NULL;
        return libvlc_media_list_path_with_root_index(0);
    }
    
    p_sublist_of_playing_item = libvlc_media_list_sublist_at_path(
                            p_mlp->p_mlist,
                            p_mlp->current_playing_item_path);
 
    /* If item just gained a sublist just play it */
    if (p_sublist_of_playing_item)
    {
        libvlc_media_list_release(p_sublist_of_playing_item);
        return libvlc_media_list_path_copy_by_appending(p_mlp->current_playing_item_path, 0);
    }

    /* Try to catch parent element */
    p_parent_of_playing_item = libvlc_media_list_parentlist_at_path(p_mlp->p_mlist,
                            p_mlp->current_playing_item_path);

    int depth = libvlc_media_list_path_depth(p_mlp->current_playing_item_path);
    if (depth < 1 || !p_parent_of_playing_item)
        return NULL;

    ret = libvlc_media_list_path_copy(p_mlp->current_playing_item_path);
    ret[depth - 1]++; /* set to next element */

    /* If this goes beyond the end of the list */
    while(ret[depth-1] >= libvlc_media_list_count(p_parent_of_playing_item, NULL))
    {
        depth--;
        if (depth <= 0)
        {
            if(b_loop)
            {
                ret[0] = 0;
                ret[1] = -1;
                break;
            }
            else
            {
                free(ret);
                libvlc_media_list_release(p_parent_of_playing_item);
                return NULL;
            }
        }
        ret[depth] = -1;
        ret[depth-1]++;
        p_parent_of_playing_item  = libvlc_media_list_parentlist_at_path(
                                        p_mlp->p_mlist,
                                        ret);
    }

    libvlc_media_list_release(p_parent_of_playing_item);
    return ret;
}
Пример #29
0
static void test_media_list (const char ** argv, int argc)
{
    libvlc_instance_t *vlc;
    libvlc_media_t *md, *md1, *md2, *md3, *md4;
    libvlc_media_list_t *ml;
    int ret;

    log ("Testing media_list\n");

    vlc = libvlc_new (argc, argv);
    assert (vlc != NULL);

    ml = libvlc_media_list_new (vlc);
    assert (ml != NULL);

    md1 = libvlc_media_new_path (vlc, "/dev/null");
    assert (md1 != NULL);
    md2 = libvlc_media_new_path (vlc, "/dev/null");
    assert (md2 != NULL);
    md3 = libvlc_media_new_path (vlc, "/dev/null");
    assert (md3 != NULL);

    ret = libvlc_media_list_add_media (ml, md1);
    assert (!ret);
    ret = libvlc_media_list_add_media (ml, md2);
    assert (!ret);

    assert( libvlc_media_list_count (ml) == 2 );
    assert( libvlc_media_list_index_of_item (ml, md1) == 0 );
    assert( libvlc_media_list_index_of_item (ml, md2) == 1 );

    ret = libvlc_media_list_remove_index (ml, 0);  /* removing first item */
    assert (!ret);

    /* test if second item was moved on first place */
    assert( libvlc_media_list_index_of_item (ml, md2) == 0 );
    ret = libvlc_media_list_add_media (ml, md1); /* add 2 items */
    assert (!ret);
    ret = libvlc_media_list_add_media (ml, md1);
    assert (!ret);

    /* there should be 3 pieces */
    assert( libvlc_media_list_count (ml) == 3 );

    ret = libvlc_media_list_insert_media (ml, md3, 2);
    assert (!ret);

    /* there should be 4 pieces */
    assert( libvlc_media_list_count (ml) == 4 );

    /* test inserting on right place */
    assert( libvlc_media_list_index_of_item (ml, md3) == 2 );

    /* test right returning descriptor*/
    md = libvlc_media_list_item_at_index (ml, 0);
    assert(md == md2);
    libvlc_media_release(md);

    md = libvlc_media_list_item_at_index (ml, 2);
    assert(md == md3);
    libvlc_media_release(md);

    /* test if give errors, when it should */
    /* have 4 items, so index 4 should give error */
    ret = libvlc_media_list_remove_index (ml, 4);
    assert (ret == -1);

    ret = libvlc_media_list_remove_index (ml, 100);
    assert (ret == -1);

    ret = libvlc_media_list_remove_index (ml, -1);
    assert (ret == -1);

    /* getting non valid items */
    libvlc_media_t * p_non_exist =
        libvlc_media_list_item_at_index (ml, 4);
    assert (p_non_exist == NULL);

    p_non_exist = libvlc_media_list_item_at_index (ml, 100);
    assert (p_non_exist == NULL);

    p_non_exist = libvlc_media_list_item_at_index (ml, -1);
    assert (p_non_exist == NULL);

    md4 = libvlc_media_new_path (vlc, "/dev/null");
    assert (md4 != NULL);

    /* try to find non inserted item */
    int i_non_exist = 0;
    i_non_exist = libvlc_media_list_index_of_item (ml, md4);
    assert ( i_non_exist == -1 );

    libvlc_media_release (md1);
    libvlc_media_release (md2);
    libvlc_media_release (md3);
    libvlc_media_release (md4);

    libvlc_media_list_release (ml);

    libvlc_release (vlc);
}
Пример #30
0
/**************************************************************************
 *       new (Public)
 *
 * Init an object.
 **************************************************************************/
libvlc_media_discoverer_t *
libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
                                       const char * psz_name,
                                       libvlc_exception_t * p_e )
{
    libvlc_media_discoverer_t * p_mdis;

    p_mdis = malloc(sizeof(libvlc_media_discoverer_t));
    if( !p_mdis )
    {
        libvlc_exception_raise( p_e, "Not enough memory" );
        return NULL;
    }

    p_mdis->p_libvlc_instance = p_inst;
    p_mdis->p_mlist = libvlc_media_list_new( p_inst, NULL );
    p_mdis->p_mlist->b_read_only = true;
    p_mdis->running = false;

    vlc_dictionary_init( &p_mdis->catname_to_submedialist, 0 );

    p_mdis->p_event_manager = libvlc_event_manager_new( p_mdis,
            p_inst, NULL );

    libvlc_event_manager_register_event_type( p_mdis->p_event_manager,
            libvlc_MediaDiscovererStarted, NULL );
    libvlc_event_manager_register_event_type( p_mdis->p_event_manager,
            libvlc_MediaDiscovererEnded, NULL );

    p_mdis->p_sd = services_discovery_Create( (vlc_object_t*)p_inst->p_libvlc_int, psz_name );

    if( !p_mdis->p_sd )
    {
        libvlc_exception_raise( p_e, "Can't find the services_discovery module named '%s'", psz_name );
        libvlc_media_list_release( p_mdis->p_mlist );
        free( p_mdis );
        return NULL;
    }

    vlc_event_attach( services_discovery_EventManager( p_mdis->p_sd ),
                      vlc_ServicesDiscoveryItemAdded,
                      services_discovery_item_added,
                      p_mdis );
    vlc_event_attach( services_discovery_EventManager( p_mdis->p_sd ),
                      vlc_ServicesDiscoveryItemRemoved,
                      services_discovery_item_removed,
                      p_mdis );
    vlc_event_attach( services_discovery_EventManager( p_mdis->p_sd ),
                      vlc_ServicesDiscoveryStarted,
                      services_discovery_started,
                      p_mdis );
    vlc_event_attach( services_discovery_EventManager( p_mdis->p_sd ),
                      vlc_ServicesDiscoveryEnded,
                      services_discovery_ended,
                      p_mdis );

    services_discovery_Start( p_mdis->p_sd );

    /* Here we go */

    return p_mdis;
}