Exemplo n.º 1
0
/*
 * Get count on media list items
 * The {#lock} should be held upon entering this function.
 *
 * @return [Integer] number of items in media list
 * @todo fixme
 */
static VALUE
rg_count(VALUE self)
{
    return INT2NUM(libvlc_media_list_count(_SELF(self)));
}
Exemplo n.º 2
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))
            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);

                /* 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;
}
Exemplo n.º 3
0
static void test_media_list (const char ** argv, int argc)
{
    libvlc_instance_t *vlc;
    libvlc_media_t *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*/
    assert ( libvlc_media_list_item_at_index (ml, 0) == md2 );

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

    /* 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);
}
Exemplo n.º 4
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))
            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))
    {
        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;
}