Esempio n. 1
0
/**************************************************************************
 *       libvlc_media_list_release (Public)
 *
 * Release an object.
 **************************************************************************/
void libvlc_media_list_release( libvlc_media_list_t * p_mlist )
{
    libvlc_media_t * p_md;
    int i;

    vlc_mutex_lock( &p_mlist->refcount_lock );
    p_mlist->i_refcount--;
    if( p_mlist->i_refcount > 0 )
    {
        vlc_mutex_unlock( &p_mlist->refcount_lock );
        return;
    }
    vlc_mutex_unlock( &p_mlist->refcount_lock );

    /* Refcount null, time to free */

    libvlc_event_manager_release( p_mlist->p_event_manager );

    libvlc_media_release( p_mlist->p_md );

    for ( i = 0; i < vlc_array_count( &p_mlist->items ); i++ )
    {
        p_md = vlc_array_item_at_index( &p_mlist->items, i );
        libvlc_media_release( p_md );
    }

    vlc_mutex_destroy( &p_mlist->object_lock );
    vlc_array_clear( &p_mlist->items );

    free( p_mlist );
}
Esempio n. 2
0
int
stream_extractor_AttachParsed( stream_t** source, char const* data,
                               char const** out_extra )
{
    vlc_array_t identifiers;

    if( mrl_FragmentSplit( &identifiers, out_extra, data ) )
        return VLC_EGENERIC;

    size_t count = vlc_array_count( &identifiers );
    size_t idx = 0;

    while( idx < count )
    {
        char* id = vlc_array_item_at_index( &identifiers, idx );

        if( vlc_stream_extractor_Attach( source, id, NULL ) )
            break;

        ++idx;
    }

    for( size_t i = 0; i < count; ++i )
        free( vlc_array_item_at_index( &identifiers, i ) );
    vlc_array_clear( &identifiers );

    return idx == count ? VLC_SUCCESS : VLC_EGENERIC;
}
Esempio n. 3
0
/*****************************************************************************
 * Run :
 *****************************************************************************/
static void cancelRun( void * p_arg )
{
    fingerprinter_sys_t *p_sys = ( fingerprinter_sys_t * ) p_arg;
    if ( vlc_array_count( p_sys->processing.queue ) )
        vlc_array_clear( p_sys->processing.queue );
    if ( p_sys->psz_uri )
        free( p_sys->psz_uri );
}
Esempio n. 4
0
void libvlc_event_manager_destroy(libvlc_event_manager_t *em)
{
    vlc_mutex_destroy(&em->lock);

    for (size_t i = 0; i < vlc_array_count(&em->listeners); i++)
        free(vlc_array_item_at_index(&em->listeners, i));

    vlc_array_clear(&em->listeners);
}
Esempio n. 5
0
static void CleanSys( fingerprinter_sys_t *p_sys )
{
    for ( size_t i = 0; i < vlc_array_count( &p_sys->incoming.queue ); i++ )
        fingerprint_request_Delete( vlc_array_item_at_index( &p_sys->incoming.queue, i ) );
    vlc_array_clear( &p_sys->incoming.queue );
    vlc_mutex_destroy( &p_sys->incoming.lock );

    for ( size_t i = 0; i < vlc_array_count( &p_sys->processing.queue ); i++ )
        fingerprint_request_Delete( vlc_array_item_at_index( &p_sys->processing.queue, i ) );
    vlc_array_clear( &p_sys->processing.queue );
    vlc_mutex_destroy( &p_sys->processing.lock );
    vlc_cond_destroy( &p_sys->processing.cond );

    for ( size_t i = 0; i < vlc_array_count( &p_sys->results.queue ); i++ )
        fingerprint_request_Delete( vlc_array_item_at_index( &p_sys->results.queue, i ) );
    vlc_array_clear( &p_sys->results.queue );
    vlc_mutex_destroy( &p_sys->results.lock );
}
Esempio n. 6
0
static void Run( fingerprinter_thread_t *p_fingerprinter )
{
    fingerprinter_sys_t *p_sys = p_fingerprinter->p_sys;

    /* main loop */
    for (;;)
    {
        vlc_mutex_lock( &p_sys->processing.lock );
        mutex_cleanup_push( &p_sys->processing.lock );
        vlc_cond_timedwait( &p_sys->incoming_queue_filled, &p_sys->processing.lock, mdate() + 1000000 );
        vlc_cleanup_run();

        QueueIncomingRequests( p_sys );

        vlc_mutex_lock( &p_sys->processing.lock ); // L0
        mutex_cleanup_push( &p_sys->processing.lock );
        vlc_cleanup_push( cancelRun, p_sys ); // C1
//**
        for ( p_sys->i = 0 ; p_sys->i < vlc_array_count( p_sys->processing.queue ); p_sys->i++ )
        {
            fingerprint_request_t *p_data = vlc_array_item_at_index( p_sys->processing.queue, p_sys->i );
            acoustid_fingerprint_t acoustid_print;
            memset( &acoustid_print , 0, sizeof(acoustid_fingerprint_t) );
            vlc_cleanup_push( clearPrint, &acoustid_print ); // C2
            p_sys->psz_uri = input_item_GetURI( p_data->p_item );
            if ( p_sys->psz_uri )
            {
                /* overwrite with hint, as in this case, fingerprint's session will be truncated */
                if ( p_data->i_duration ) acoustid_print.i_duration = p_data->i_duration;

                DoFingerprint( VLC_OBJECT(p_fingerprinter), p_sys, &acoustid_print );

                DoAcoustIdWebRequest( VLC_OBJECT(p_fingerprinter), &acoustid_print );
                fill_metas_with_results( p_data, &acoustid_print );
                FREENULL( p_sys->psz_uri );
            }
            vlc_cleanup_run( ); // C2

            /* copy results */
            vlc_mutex_lock( &p_sys->results.lock );
            vlc_array_append( p_sys->results.queue, p_data );
            vlc_mutex_unlock( &p_sys->results.lock );

            vlc_testcancel();
        }

        if ( vlc_array_count( p_sys->processing.queue ) )
        {
            var_TriggerCallback( p_fingerprinter, "results-available" );
            vlc_array_clear( p_sys->processing.queue );
        }
        vlc_cleanup_pop( ); // C1
//**
        vlc_cleanup_run(); // L0
    }
}
Esempio n. 7
0
void background_worker_Delete( struct background_worker* worker )
{
    BackgroundWorkerCancel( worker, NULL );
    vlc_array_clear( &worker->tail.data );
    vlc_mutex_destroy( &worker->lock );
    vlc_cond_destroy( &worker->head.wait );
    vlc_cond_destroy( &worker->head.worker_wait );
    vlc_cond_destroy( &worker->tail.wait );
    free( worker );
}
Esempio n. 8
0
/**************************************************************************
 *       libvlc_event_manager_release (internal) :
 *
 * Release an object's event manager.
 **************************************************************************/
void libvlc_event_manager_release( libvlc_event_manager_t * p_em )
{
    vlc_mutex_destroy(&p_em->lock);

    for (int i = 0; i < vlc_array_count(&p_em->listeners); i++)
        free(vlc_array_item_at_index(&p_em->listeners, i));

    vlc_array_clear(&p_em->listeners);
    free( p_em );
}
Esempio n. 9
0
static void QueueIncomingRequests( fingerprinter_sys_t *p_sys )
{
    vlc_mutex_lock( &p_sys->incoming.lock );
    size_t i = vlc_array_count( &p_sys->incoming.queue );

    while( i )
        vlc_array_append( &p_sys->processing.queue,
                          vlc_array_item_at_index( &p_sys->incoming.queue, --i ) );
    vlc_array_clear( &p_sys->incoming.queue );
    vlc_mutex_unlock(&p_sys->incoming.lock);
}
Esempio n. 10
0
void vlc_http_cookies_destroy( vlc_http_cookie_jar_t * p_jar )
{
    if ( !p_jar )
        return;

    int i;
    for( i = 0; i < vlc_array_count( &p_jar->cookies ); i++ )
        cookie_destroy( vlc_array_item_at_index( &p_jar->cookies, i ) );

    vlc_array_clear( &p_jar->cookies );
    vlc_mutex_destroy( &p_jar->lock );

    free( p_jar );
}
Esempio n. 11
0
File: event.c Progetto: AsamQi/vlc
/**************************************************************************
 *       libvlc_event_manager_release (internal) :
 *
 * Release an object's event manager.
 **************************************************************************/
void libvlc_event_manager_release( libvlc_event_manager_t * p_em )
{
    libvlc_event_listeners_group_t * p_lg;
    int i,j ;

    libvlc_event_async_fini(p_em);

    vlc_mutex_destroy( &p_em->event_sending_lock );
    vlc_mutex_destroy( &p_em->object_lock );

    for( i = 0; i < vlc_array_count(&p_em->listeners_groups); i++)
    {
        p_lg = vlc_array_item_at_index( &p_em->listeners_groups, i );

        for( j = 0; j < vlc_array_count(&p_lg->listeners); j++)
            free( vlc_array_item_at_index( &p_lg->listeners, j ) );

        vlc_array_clear( &p_lg->listeners );
        free( p_lg );
    }
    vlc_array_clear( &p_em->listeners_groups );
    libvlc_release( p_em->p_libvlc_instance );
    free( p_em );
}
Esempio n. 12
0
int main (void)
{
    for (size_t i = 0; i < ARRAY_SIZE(testcase); ++i)
    {
        vlc_array_t out;
        const char *extra = NULL;
        int ret = mrl_FragmentSplit(&out, &extra, testcase[i].payload);
        if (testcase[i].success)
        {
            assert(ret == VLC_SUCCESS);
            if (extra != NULL)
                assert(strcmp(extra, testcase[i].extra) == 0);
            else
                assert(testcase[i].extra == NULL);

            const char *p = testcase[i].payload + 2;
            for (size_t j = 0; testcase[i].results[j] != NULL; ++j)
            {
                assert(j < vlc_array_count(&out) && j < MAX_RESULT);
                char *res = vlc_array_item_at_index(&out, j);

                assert(strcmp(testcase[i].results[j], res) == 0);

                char *res_escaped = NULL;
                ret = mrl_EscapeFragmentIdentifier(&res_escaped, res);
                assert(ret == VLC_SUCCESS && res_escaped != NULL);
                assert(strncmp(p, res_escaped, strlen(res_escaped)) == 0);
                p += strlen(res_escaped) + 2;

                free(res_escaped);
                free(res);
            }
            vlc_array_clear(&out);
        }
        else
        {
            assert(ret != VLC_SUCCESS);
        }
    }
    return 0;
}
Esempio n. 13
0
/**************************************************************************
 *       flat_media_list_view_release (private)
 * (called by media_list_view_release)
 **************************************************************************/
static void
flat_media_list_view_release( libvlc_media_list_view_t * p_mlv )
{
    vlc_array_clear( &p_mlv->p_this_view_data->array );
    free( p_mlv->p_this_view_data );
}
Esempio n. 14
0
/* Creates a complete "stream_out" modules chain
 *
 *  chain format: module1{option=*:option=*}[:module2{option=*:...}]
 *
 *  The modules are created starting from the last one and linked together
 *  A pointer to the last module created is stored if pp_last isn't NULL, to
 *  make sure sout_StreamChainDelete doesn't delete modules created in another
 *  place.
 *
 *  Returns a pointer to the first module.
 */
sout_stream_t *sout_StreamChainNew(sout_instance_t *p_sout, const char *psz_chain,
                                sout_stream_t *p_next, sout_stream_t **pp_last)
{
    if(!psz_chain || !*psz_chain)
    {
        if(pp_last) *pp_last = NULL;
        return p_next;
    }

    char *psz_parser = strdup(psz_chain);
    if(!psz_parser)
        return NULL;

    vlc_array_t cfg, name;
    vlc_array_init(&cfg);
    vlc_array_init(&name);

    /* parse chain */
    while(psz_parser)
    {
        config_chain_t *p_cfg;
        char *psz_name;
        char *psz_rest_chain = config_ChainCreate( &psz_name, &p_cfg, psz_parser );
        free( psz_parser );
        psz_parser = psz_rest_chain;

        vlc_array_append(&cfg, p_cfg);
        vlc_array_append(&name, psz_name);
    }

    int i = vlc_array_count(&name);
    vlc_array_t module;
    vlc_array_init(&module);
    while(i--)
    {
        p_next = sout_StreamNew( p_sout, vlc_array_item_at_index(&name, i),
            vlc_array_item_at_index(&cfg, i), p_next);

        if(!p_next)
            goto error;

        if(i == vlc_array_count(&name) - 1 && pp_last)
            *pp_last = p_next;   /* last module created in the chain */

        vlc_array_append(&module, p_next);
    }

    vlc_array_clear(&name);
    vlc_array_clear(&cfg);
    vlc_array_clear(&module);

    return p_next;

error:

    i++;    /* last module couldn't be created */

    /* destroy all modules created, starting with the last one */
    int modules = vlc_array_count(&module);
    while(modules--)
        sout_StreamDelete(vlc_array_item_at_index(&module, modules));
    vlc_array_clear(&module);

    /* then destroy all names and config which weren't destroyed by
     * sout_StreamDelete */
    while(i--)
    {
        free(vlc_array_item_at_index(&name, i));
        config_ChainDestroy(vlc_array_item_at_index(&cfg, i));
    }
    vlc_array_clear(&name);
    vlc_array_clear(&cfg);

    return NULL;
}
Esempio n. 15
0
/*****************************************************************************
 * Run :
 *****************************************************************************/
static void *Run( void *opaque )
{
    fingerprinter_thread_t *p_fingerprinter = opaque;
    fingerprinter_sys_t *p_sys = p_fingerprinter->p_sys;

    vlc_mutex_lock( &p_sys->processing.lock );
    mutex_cleanup_push( &p_sys->processing.lock );

    /* main loop */
    for (;;)
    {
        msleep( CLOCK_FREQ );

        QueueIncomingRequests( p_sys );

        vlc_testcancel();

        for ( size_t i = 0 ; i < vlc_array_count( &p_sys->processing.queue ); i++ )
        {
            int canc = vlc_savecancel();
            fingerprint_request_t *p_data = vlc_array_item_at_index( &p_sys->processing.queue, i );

            char *psz_uri = input_item_GetURI( p_data->p_item );
            if ( psz_uri != NULL )
            {
                 acoustid_fingerprint_t acoustid_print;

                 memset( &acoustid_print , 0, sizeof (acoustid_print) );
                /* overwrite with hint, as in this case, fingerprint's session will be truncated */
                if ( p_data->i_duration )
                     acoustid_print.i_duration = p_data->i_duration;

                DoFingerprint( p_fingerprinter, &acoustid_print, psz_uri );
                free( psz_uri );

                DoAcoustIdWebRequest( VLC_OBJECT(p_fingerprinter), &acoustid_print );
                fill_metas_with_results( p_data, &acoustid_print );

                for( unsigned j = 0; j < acoustid_print.results.count; j++ )
                     free_acoustid_result_t( &acoustid_print.results.p_results[j] );
                if( acoustid_print.results.count )
                    free( acoustid_print.results.p_results );
                free( acoustid_print.psz_fingerprint );
            }
            vlc_restorecancel(canc);

            /* copy results */
            vlc_mutex_lock( &p_sys->results.lock );
            vlc_array_append( &p_sys->results.queue, p_data );
            vlc_mutex_unlock( &p_sys->results.lock );

            vlc_testcancel();
        }

        if ( vlc_array_count( &p_sys->processing.queue ) )
        {
            var_TriggerCallback( p_fingerprinter, "results-available" );
            vlc_array_clear( &p_sys->processing.queue );
        }
    }

    vlc_cleanup_pop();
    vlc_assert_unreachable();
}