Exemple #1
0
static void
test_expected_slaves(libvlc_media_t *p_m,
                     libvlc_media_slave_t *p_expected_slaves,
                     unsigned int i_expected_slaves)
{
    printf("Check if slaves are correclty attached to media\n");

    libvlc_media_slave_t **pp_slaves;
    unsigned int i_slave_count = libvlc_media_slaves_get(p_m, &pp_slaves);
    assert(i_expected_slaves == i_slave_count);

    if (i_expected_slaves > 0)
    {
        bool *p_found_list = calloc(i_expected_slaves, sizeof(bool));
        assert(p_found_list != NULL);
        for (unsigned int i = 0; i < i_slave_count; ++i)
        {
            libvlc_media_slave_t *p_slave1 = pp_slaves[i];
            for (unsigned int j = 0; i < i_expected_slaves; ++j)
            {
                libvlc_media_slave_t *p_slave2 = &p_expected_slaves[j];
                if (strcmp(p_slave1->psz_uri, p_slave2->psz_uri) == 0)
                {
                    assert(p_found_list[j] == false);
                    assert(p_slave1->i_type == p_slave2->i_type);
                    assert(p_slave1->i_priority == p_slave2->i_priority);
                    p_found_list[j] = true;
                    break;
                }
            }
        }
        for (unsigned int i = 0; i < i_expected_slaves; ++i)
        {
            printf("Check if slaves[%d] is found\n", i);
            assert(p_found_list[i]);
        }
        free(p_found_list);
    }

    libvlc_media_slaves_release(pp_slaves, i_slave_count);
}
Exemple #2
0
unsigned int libvlc_media_slaves_get( libvlc_media_t *p_md,
                                      libvlc_media_slave_t ***ppp_slaves )
{
    assert( p_md && ppp_slaves );
    input_item_t *p_input_item = p_md->p_input_item;

    vlc_mutex_lock( &p_input_item->lock );

    int i_count = p_input_item->i_slaves;
    if( i_count <= 0 )
        return vlc_mutex_unlock( &p_input_item->lock ), 0;

    libvlc_media_slave_t **pp_slaves = calloc( i_count, sizeof(*pp_slaves) );
    if( pp_slaves == NULL )
        return vlc_mutex_unlock( &p_input_item->lock ), 0;

    for( int i = 0; i < i_count; ++i )
    {
        input_item_slave_t *p_item_slave = p_input_item->pp_slaves[i];
        assert( p_item_slave->i_priority >= SLAVE_PRIORITY_MATCH_NONE );

        libvlc_media_slave_t *p_slave = malloc( sizeof(*p_slave) +
                                                strlen( p_item_slave->psz_uri )
                                                + 1 );

        if( p_slave == NULL )
        {
            libvlc_media_slaves_release(pp_slaves, i);
            return vlc_mutex_unlock( &p_input_item->lock ), 0;
        }
        strcpy( p_slave->psz_uri, p_item_slave->psz_uri );

        switch( p_item_slave->i_type )
        {
        case SLAVE_TYPE_SPU:
            p_slave->i_type = libvlc_media_slave_type_subtitle;
            break;
        case SLAVE_TYPE_AUDIO:
            p_slave->i_type = libvlc_media_slave_type_audio;
            break;
        default:
            vlc_assert_unreachable();
        }

        switch( p_item_slave->i_priority )
        {
        case SLAVE_PRIORITY_MATCH_NONE:
            p_slave->i_priority = 0;
            break;
        case SLAVE_PRIORITY_MATCH_RIGHT:
            p_slave->i_priority = 1;
            break;
        case SLAVE_PRIORITY_MATCH_LEFT:
            p_slave->i_priority = 2;
            break;
        case SLAVE_PRIORITY_MATCH_ALL:
            p_slave->i_priority = 3;
            break;
        case SLAVE_PRIORITY_USER:
            p_slave->i_priority = 4;
            break;
        default:
            vlc_assert_unreachable();
        }
        pp_slaves[i] = p_slave;
    }
    vlc_mutex_unlock( &p_input_item->lock );

    *ppp_slaves = pp_slaves;
    return i_count;
}