Exemple #1
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
    }
}
Exemple #2
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();
}