void sms_Free( sms_stream_t *sms )
{
    if( sms->qlevels )
    {
        for( int n = 0; n < vlc_array_count( sms->qlevels ); n++ )
        {
            quality_level_t *qlevel = (quality_level_t *)vlc_array_item_at_index( sms->qlevels, n );			// sunqueen modify
            if( qlevel ) ql_Free( qlevel );
        }
        vlc_array_destroy( sms->qlevels );
    }

    if( sms->chunks )
    {
        for( int n = 0; n < vlc_array_count( sms->chunks ); n++ )
        {
            chunk_t *chunk = (chunk_t *)vlc_array_item_at_index( sms->chunks, n );			// sunqueen modify
            if( chunk) chunk_Free( chunk );
        }
        vlc_array_destroy( sms->chunks );
    }

    free( sms->name );
    free( sms->url_template );
    free( sms );
    sms = NULL;
}
Пример #2
0
/*****************************************************************************
 * Close:
 *****************************************************************************/
static void Close(vlc_object_t *p_this)
{
    fingerprinter_thread_t   *p_fingerprinter = (fingerprinter_thread_t*) p_this;
    fingerprinter_sys_t *p_sys = p_fingerprinter->p_sys;

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

    vlc_mutex_destroy( &p_sys->condwait.lock );
    vlc_cond_destroy( &p_sys->condwait.wait );

    for ( int 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_destroy( p_sys->incoming.queue );
    vlc_mutex_destroy( &p_sys->incoming.lock );
    vlc_cond_destroy( &p_sys->incoming_queue_filled );

    for ( int 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_destroy( p_sys->processing.queue );
    vlc_mutex_destroy( &p_sys->processing.lock );

    for ( int 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_destroy( p_sys->results.queue );
    vlc_mutex_destroy( &p_sys->results.lock );

    free( p_sys );
}
Пример #3
0
static void Close   ( vlc_object_t *p_this )
{
    intf_thread_t   *p_intf     = (intf_thread_t*) p_this;
    playlist_t      *p_playlist = pl_Hold( p_intf );;
    input_thread_t  *p_input;

    var_DelCallback( p_playlist, "item-current", AllCallback, p_intf );
    var_DelCallback( p_playlist, "intf-change", AllCallback, p_intf );
    var_DelCallback( p_playlist, "playlist-item-append", AllCallback, p_intf );
    var_DelCallback( p_playlist, "playlist-item-deleted", AllCallback, p_intf );
    var_DelCallback( p_playlist, "random", AllCallback, p_intf );
    var_DelCallback( p_playlist, "repeat", AllCallback, p_intf );
    var_DelCallback( p_playlist, "loop", AllCallback, p_intf );

    p_input = playlist_CurrentInput( p_playlist );
    if ( p_input )
    {
        var_DelCallback( p_input, "state", AllCallback, p_intf );
        vlc_object_release( p_input );
    }

    pl_Release( p_intf );

    dbus_connection_unref( p_intf->p_sys->p_conn );

    // Free the events array
    for( int i = 0; i < vlc_array_count( p_intf->p_sys->p_events ); i++ )
    {
        callback_info_t* info = vlc_array_item_at_index( p_intf->p_sys->p_events, i );
        free( info );
    }
    vlc_mutex_destroy( &p_intf->p_sys->lock );
    vlc_array_destroy( p_intf->p_sys->p_events );
    free( p_intf->p_sys );
}
Пример #4
0
bool MLModel::event( QEvent *event )
{
    if ( event->type() == MLEvent::MediaAdded_Type )
    {
        event->accept();
        MLEvent *e = static_cast<MLEvent *>(event);
        vlc_array_t* p_result = vlc_array_new();
        if ( ml_FindMedia( e->p_ml, p_result, ML_ID, e->ml_media_id ) == VLC_SUCCESS )
        {
            insertResultArray( p_result );
            ml_DestroyResultArray( p_result );
        }
        vlc_array_destroy( p_result );
        return true;
    }
    else if( event->type() == MLEvent::MediaRemoved_Type )
    {
        event->accept();
        MLEvent *e = static_cast<MLEvent *>(event);
        removeRow( getIndexByMLID( e->ml_media_id ).row() );
        return true;
    }
    else if( event->type() == MLEvent::MediaUpdated_Type )
    {
        event->accept();
        /* Never implemented... */
        return true;
    }

    return VLCModel::event( event );
}
Пример #5
0
void MLModel::removeAll()
{
    vlc_array_t* p_where = vlc_array_new();
    if ( !p_where ) return;

    int rows = rowCount();
    if( rows > 0 )
    {
        beginRemoveRows( createIndex( 0, 0 ), 0, rows-1 );

        QList< MLItem* >::iterator it = items.begin();
        ml_element_t p_find[ items.count() ];
        int i = 0;
        while( it != items.end() )
        {
            p_find[i].criteria = ML_ID;
            p_find[i].value.i = (*it)->id( MLMEDIA_ID );
            vlc_array_append( p_where, & p_find[i++] );
            delete *it;
            it++;
        }

        ml_Delete( p_ml, p_where );
        items.clear();
        endRemoveRows();
    }

    vlc_array_destroy( p_where );
    reset();
}
Пример #6
0
/**
 * @brief Remove a directory to monitor
 * @param p_ml A media library object
 * @param psz_dir the directory to remove
 * @return VLC_SUCCESS or VLC_EGENERIC
 */
int RemoveDirToMonitor( media_library_t *p_ml, const char *psz_dir )
{
    assert( p_ml );

    char **pp_results = NULL;
    int i_cols = 0, i_rows = 0, i_ret = VLC_SUCCESS;
    int i;

    bool b_recursive = var_CreateGetBool( p_ml, "ml-recursive-scan" );

    if( b_recursive )
    {
        i_ret = Query( p_ml, &pp_results, &i_rows, &i_cols,
                          "SELECT media.id FROM media JOIN directories ON "
                          "(media.directory_id = directories.id) WHERE "
                          "directories.uri LIKE '%q%%'",
                          psz_dir );
        if( i_ret != VLC_SUCCESS )
        {
            msg_Err( p_ml, "Error occured while making a query to the database" );
            return i_ret;
        }
        QuerySimple( p_ml, "DELETE FROM directories WHERE uri LIKE '%q%%'",
                        psz_dir );
    }
    else
    {
        i_ret = Query( p_ml, &pp_results, &i_rows, &i_cols,
                          "SELECT media.id FROM media JOIN directories ON "
                          "(media.directory_id = directories.id) WHERE "
                          "directories.uri = %Q",
                          psz_dir );
        if( i_ret != VLC_SUCCESS )
        {
            msg_Err( p_ml, "Error occured while making a query to the database" );
            return i_ret;
        }
        QuerySimple( p_ml, "DELETE FROM directories WHERE uri = %Q",
                        psz_dir );
    }

    vlc_array_t *p_where = vlc_array_new();
    for( i = 1; i <= i_rows; i++ )
    {
        int id = atoi( pp_results[i*i_cols] );
        ml_element_t* p_find = ( ml_element_t * ) calloc( 1, sizeof( ml_element_t ) );
        p_find->criteria = ML_ID;
        p_find->value.i = id;
        vlc_array_append( p_where, p_find );
    }
    Delete( p_ml, p_where );

    FreeSQLResult( p_ml, pp_results );
    for( i = 0; i < vlc_array_count( p_where ); i++ )
    {
        free( vlc_array_item_at_index( p_where, i ) );
    }
    vlc_array_destroy( p_where );
    return VLC_SUCCESS;
}
Пример #7
0
void bdsm_SdClose (vlc_object_t *p_this)
{
    services_discovery_t *sd = (services_discovery_t *)p_this;
    services_discovery_sys_t *p_sys = sd->p_sys;

    if( p_sys == NULL )
        return;

    if( p_sys->p_ns )
    {
        netbios_ns_discover_stop( p_sys->p_ns );
        netbios_ns_destroy( p_sys->p_ns );
    }

    if( p_sys->p_entry_item_list )
    {
        for ( int i = 0; i < vlc_array_count( p_sys->p_entry_item_list ); i++ )
        {
            struct entry_item *p_entry_item;

            p_entry_item = vlc_array_item_at_index( p_sys->p_entry_item_list,
                                                    i );
            vlc_gc_decref( p_entry_item->p_item );
            free( p_entry_item );
        }
        vlc_array_destroy( p_sys->p_entry_item_list );
    }

    free( p_sys );
}
Пример #8
0
Файл: dbus.c Проект: etix/vlc
static void Close   ( vlc_object_t *p_this )
{
    intf_thread_t   *p_intf     = (intf_thread_t*) p_this;
    intf_sys_t      *p_sys      = p_intf->p_sys;
    playlist_t      *p_playlist = p_sys->p_playlist;

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

    var_DelCallback( p_playlist, "input-current", AllCallback, p_intf );
    var_DelCallback( p_playlist, "volume", AllCallback, p_intf );
    var_DelCallback( p_playlist, "mute", AllCallback, p_intf );
    var_DelCallback( p_playlist, "playlist-item-append", AllCallback, p_intf );
    var_DelCallback( p_playlist, "playlist-item-deleted", AllCallback, p_intf );
    var_DelCallback( p_playlist, "random", AllCallback, p_intf );
    var_DelCallback( p_playlist, "repeat", AllCallback, p_intf );
    var_DelCallback( p_playlist, "loop", AllCallback, p_intf );
    var_DelCallback( p_playlist, "fullscreen", AllCallback, p_intf );

    if( p_sys->p_input )
    {
        var_DelCallback( p_sys->p_input, "intf-event", InputCallback, p_intf );
        var_DelCallback( p_sys->p_input, "can-pause", AllCallback, p_intf );
        var_DelCallback( p_sys->p_input, "can-seek", AllCallback, p_intf );
        vlc_object_release( p_sys->p_input );
    }

    /* The dbus connection is private, so we are responsible
     * for closing it */
    dbus_connection_close( p_sys->p_conn );
    dbus_connection_unref( p_sys->p_conn );

    // Free the events array
    for( int i = 0; i < vlc_array_count( p_sys->p_events ); i++ )
    {
        callback_info_t* info = vlc_array_item_at_index( p_sys->p_events, i );
        free( info );
    }
    vlc_mutex_destroy( &p_sys->lock );
    vlc_array_destroy( p_sys->p_events );
    vlc_array_destroy( p_sys->p_timeouts );
    vlc_array_destroy( p_sys->p_watches );
    vlc_close( p_sys->p_pipe_fds[1] );
    vlc_close( p_sys->p_pipe_fds[0] );
    free( p_sys );
}
Пример #9
0
static void Close( vlc_object_t *p_this )
{
    stream_t *s = (stream_t*)p_this;
    stream_sys_t *p_sys = s->p_sys;

    vlc_mutex_lock( &p_sys->download.lock_wait );
    p_sys->b_close = true;
    /* Negate the condition variable's predicate */
    for( int i = 0; i < 3; i++ )
        p_sys->download.lead[i] = 0;
    p_sys->playback.toffset = 0;
    vlc_cond_signal(&p_sys->download.wait);
    vlc_mutex_unlock( &p_sys->download.lock_wait );

    vlc_join( p_sys->thread, NULL );
    vlc_mutex_destroy( &p_sys->download.lock_wait );
    vlc_cond_destroy( &p_sys->download.wait );

    /* Free sms streams */
    sms_stream_t *sms;
    for( int i = 0; i < vlc_array_count( p_sys->sms_streams ); i++ )
    {
        sms = vlc_array_item_at_index( p_sys->sms_streams, i );
        if( sms )
            sms_Free( sms );
    }
    /* Free downloaded chunks */
    chunk_t *chunk;
    for( int i = 0; i < vlc_array_count( p_sys->init_chunks ); i++ )
    {
        chunk = vlc_array_item_at_index( p_sys->init_chunks, i );
        chunk_Free( chunk );
    }

    sms_queue_free( p_sys->bws );
    vlc_array_destroy( p_sys->sms_streams );
    vlc_array_destroy( p_sys->selected_st );
    vlc_array_destroy( p_sys->download.chunks );
    vlc_array_destroy( p_sys->init_chunks );

    free( p_sys->base_url );
    free( p_sys );
}
Пример #10
0
static void SysCleanup( stream_sys_t *p_sys )
{
    if ( p_sys->sms_streams )
    {
        for ( int i=0; i< p_sys->sms_streams->i_count ; i++ )
            sms_Free( p_sys->sms_streams->pp_elems[i] );
        vlc_array_destroy( p_sys->sms_streams );
    }
    vlc_array_destroy( p_sys->selected_st );
    vlc_array_destroy( p_sys->download.chunks );
    if ( p_sys->init_chunks )
    {
        for ( int i=0; i< p_sys->init_chunks->i_count ; i++ )
            chunk_Free( p_sys->init_chunks->pp_elems[i] );
        vlc_array_destroy( p_sys->init_chunks );
    }
    sms_queue_free( p_sys->bws );
    free( p_sys->base_url );
}
Пример #11
0
static int mediaAdded( vlc_object_t *p_this, char const *psz_var,
                                  vlc_value_t oldval, vlc_value_t newval,
                                  void *data )
{
    VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );

    int ret = VLC_SUCCESS;
    media_library_t *p_ml = ( media_library_t* )p_this;
    MLModel* p_model = ( MLModel* )data;
    vlc_array_t* p_result = vlc_array_new();
    ret = ml_FindMedia( p_ml, p_result, ML_ID, newval.i_int );
    if( ret != VLC_SUCCESS )
    {
        vlc_array_destroy( p_result );
        return VLC_EGENERIC;
    }
    p_model->insertResultArray( p_result );
    vlc_array_destroy( p_result );
    return VLC_SUCCESS;
}
Пример #12
0
/**
 * @brief Definition of the result item model for the result tree
 * @param parent the parent Qt object
 */
MLModel::MLModel( intf_thread_t* _p_intf, QObject *parent )
        :VLCModel( _p_intf, parent )
{
    p_ml = ml_Get( p_intf );
    if ( !p_ml ) return;

    vlc_array_t *p_result_array = vlc_array_new();
    if ( p_result_array )
    {
        ml_Find( p_ml, p_result_array, ML_MEDIA );
        insertResultArray( p_result_array );
        ml_DestroyResultArray( p_result_array );
        vlc_array_destroy( p_result_array );
    }

    var_AddCallback( p_ml, "media-added", mediaAdded, this );
    var_AddCallback( p_ml, "media-deleted", mediaDeleted, this );
    var_AddCallback( p_ml, "media-meta-change", mediaUpdated, this );
}
Пример #13
0
static int CreatePlaylist( stream_t *s, char **pp_buffer )
{
    stream_sys_t *p_sys = s->p_sys;

    unzFile file = p_sys->zipFile;
    if( !file )
        return -1;

    /* Get some infos about zip archive */
    int i_ret = 0;
    vlc_array_t *p_filenames = vlc_array_new(); /* Will contain char* */

    /* List all file names in Zip archive */
    i_ret = GetFilesInZip( s, file, p_filenames, NULL );
    if( i_ret < 0 )
    {
        i_ret = -1;
        goto exit;
    }

    /* Construct the xspf playlist */
    i_ret = WriteXSPF( pp_buffer, p_filenames, p_sys->psz_path );
    if( i_ret > 0 )
        i_ret = 1;
    else if( i_ret < 0 )
        i_ret = -1;

exit:
    /* Close archive */
    unzClose( file );
    p_sys->zipFile = NULL;

    for( int i = 0; i < vlc_array_count( p_filenames ); i++ )
    {
        free( vlc_array_item_at_index( p_filenames, i ) );
    }
    vlc_array_destroy( p_filenames );
    return i_ret;
}
Пример #14
0
/**
 * @brief Update a ml_media_t
 *
 * @param p_ml the media library object
 * @param p_media media to synchronise in the database
 * @return VLC_SUCCESS or VLC_EGENERIC
 * @note: the media id may be 0, in this case, the update is based
 *        on the url (less powerful). This function is threadsafe
 *
 * This synchronises all non NULL and non zero fields of p_media
 * Synchronization of album and people is TODO
 */
int UpdateMedia( media_library_t *p_ml, ml_media_t *p_media )
{
    assert( p_media->i_id || ( p_media->psz_uri && *p_media->psz_uri ) );
    vlc_array_t *changes = vlc_array_new();
    ml_element_t *find = NULL;
    int i_ret = VLC_EGENERIC;

    ml_LockMedia( p_media );
#define APPEND_ICHANGES( cond, crit ) \
    if( cond ) { \
        find = ( ml_element_t* ) calloc( 1, sizeof( ml_element_t ) ); \
        find->criteria = crit; \
        find->value.i = cond; \
        vlc_array_append( changes, find ); \
    }
#define APPEND_SCHANGES( cond, crit ) \
    if( cond ) { \
        find = ( ml_element_t* ) calloc( 1, sizeof( ml_element_t ) ); \
        find->criteria = crit; \
        find->value.str = cond; \
        vlc_array_append( changes, find ); \
    }

    APPEND_SCHANGES( p_media->psz_title, ML_TITLE );
    APPEND_ICHANGES( p_media->i_type, ML_TYPE );
    APPEND_ICHANGES( p_media->i_duration, ML_DURATION );
    APPEND_SCHANGES( p_media->psz_preview, ML_PREVIEW );
    APPEND_SCHANGES( p_media->psz_cover, ML_COVER );
    APPEND_ICHANGES( p_media->i_disc_number, ML_DISC_NUMBER );
    APPEND_ICHANGES( p_media->i_track_number, ML_TRACK_NUMBER );
    APPEND_ICHANGES( p_media->i_year, ML_YEAR);
    APPEND_SCHANGES( p_media->psz_genre, ML_GENRE );
    APPEND_ICHANGES( p_media->i_album_id, ML_ALBUM_ID );
    APPEND_SCHANGES( p_media->psz_album, ML_ALBUM );
    APPEND_ICHANGES( p_media->i_skipped_count, ML_SKIPPED_COUNT );
    APPEND_ICHANGES( p_media->i_last_skipped, ML_LAST_SKIPPED );
    APPEND_ICHANGES( p_media->i_played_count, ML_PLAYED_COUNT );
    APPEND_ICHANGES( p_media->i_last_played, ML_LAST_PLAYED );
    APPEND_ICHANGES( p_media->i_first_played, ML_FIRST_PLAYED );
    APPEND_ICHANGES( p_media->i_vote, ML_VOTE );
    APPEND_ICHANGES( p_media->i_score, ML_SCORE );
    APPEND_SCHANGES( p_media->psz_comment, ML_COMMENT );
    APPEND_SCHANGES( p_media->psz_extra, ML_EXTRA );
    APPEND_SCHANGES( p_media->psz_language, ML_LANGUAGE );

    if( p_media->psz_uri && p_media->i_id )
    {
        find = ( ml_element_t* ) calloc( 1, sizeof( ml_element_t ) );
        find->criteria = ML_URI;
        find->value.str = p_media->psz_uri;
        vlc_array_append( changes, find );
    }
    /*TODO: implement extended meta */
    /* We're not taking import time! Good */

#undef APPEND_ICHANGES
#undef APPEND_SCHANGES
    ml_person_t* person = p_media->p_people;
    while( person )
    {
        if( person->i_id > 0 )
        {
            find = ( ml_element_t* ) calloc( 1, sizeof( ml_element_t ) );
            find->criteria = ML_PEOPLE_ID;
            find->lvalue.str = person->psz_role;
            find->value.i = person->i_id;
            vlc_array_append( changes, find );
        }
        else if( person->psz_name && *person->psz_name )
        {
            find = ( ml_element_t* ) calloc( 1, sizeof( ml_element_t ) );
            find->criteria = ML_PEOPLE;
            find->lvalue.str = person->psz_role;
            find->value.str = person->psz_name;
            vlc_array_append( changes, find );
        }
        person = person->p_next;
    }

    ml_ftree_t* p_where = NULL;
    ml_ftree_t* p_where_elt = ( ml_ftree_t* ) calloc( 1, sizeof( ml_ftree_t ) );
    if( p_media->i_id )
    {
        p_where_elt->criteria = ML_ID;
        p_where_elt->value.i = p_media->i_id ;
        p_where_elt->comp = ML_COMP_EQUAL;
        p_where = ml_FtreeFastAnd( p_where, p_where_elt );
    }
    else if( p_media->psz_uri )
    {
        p_where_elt->criteria = ML_URI;
        p_where_elt->value.str = p_media->psz_uri;
        p_where_elt->comp = ML_COMP_EQUAL;
        p_where = ml_FtreeFastAnd( p_where, p_where_elt );
    }
    else
    {
        goto quit1;
    }
    i_ret = Update( p_ml, ML_MEDIA, NULL, p_where, changes );

quit1:
    ml_FreeFindTree( p_where );
    for( int i = 0; i < vlc_array_count( changes ); i++ )
        /* Note: DO NOT free the strings because
         * they belong to the ml_media_t object */
        free( vlc_array_item_at_index( changes, i ) );
    vlc_array_destroy( changes );
    ml_UnlockMedia( p_media );
    return i_ret;
}
Пример #15
0
/**
 * @brief Scan files in a particular directory
 */
static void ScanFiles( monitoring_thread_t *p_mon, int i_dir_id,
                       bool b_recursive, stat_list_t *stparent )
{
    int i_rows, i_cols, i_dir_content, i, i_mon_rows, i_mon_cols;
    char **ppsz_monitored_files;
    char **pp_results, *psz_dir;
    char **pp_dir_content;
    bool *pb_processed;
    input_item_t *p_input;
    struct stat s_stat;
    media_library_t *p_ml = (media_library_t *)p_mon->p_ml;

    Query( p_ml, &pp_results, &i_rows, &i_cols,
              "SELECT uri AS directory_uri FROM directories WHERE id = '%d'",
              i_dir_id );
    if( i_rows < 1 )
    {
        msg_Dbg( p_mon, "query returned no directory for dir_id: %d (%s:%d)",
                 i_dir_id, __FILE__, __LINE__ );
        return;
    }
    psz_dir = strdup( pp_results[1] );
    FreeSQLResult( p_ml, pp_results );

    struct stat_list_t stself;

    if( vlc_stat( psz_dir, &stself.st ) == -1 )
    {
        msg_Err( p_ml, "Cannot stat `%s': %m", psz_dir );
        free( psz_dir );
        return;
    }
#ifndef WIN32
    for( stat_list_t *stats = stparent; stats != NULL; stats = stats->parent )
    {
        if( ( stself.st.st_ino == stats->st.st_ino ) &&
            ( stself.st.st_dev == stats->st.st_dev ) )
        {
            msg_Warn( p_ml, "Ignoring infinitely recursive directory `%s'",
                      psz_dir );
            free( psz_dir );
            return;
        }
    }
#else
    /* Windows has st_dev (driver letter - 'A'), but it zeroes st_ino,
     * so that the test above will always incorrectly succeed.
     * Besides, Windows does not have dirfd(). */
#endif
    stself.parent = stparent;

    QuerySimple( p_ml, "UPDATE directories SET timestamp=%d WHERE id = %d",
                    stself.st.st_mtime, i_dir_id );
    Query( p_ml, &ppsz_monitored_files, &i_mon_rows, &i_mon_cols,
              "SELECT id AS media_id, timestamp AS media_ts, uri AS media_uri "
              "FROM media WHERE directory_id = %d",
              i_dir_id );
    pb_processed = malloc(sizeof(bool) * i_mon_rows);
    for( i = 0; i < i_mon_rows ; i++)
        pb_processed[i] = false;

    i_dir_content = vlc_scandir( psz_dir, &pp_dir_content, NULL, Sort );
    if( i_dir_content == -1 )
    {
        msg_Err( p_mon, "Cannot read `%s': %m", psz_dir );
        free( pb_processed );
        free( psz_dir );
        return;
    }
    else if( i_dir_content == 0 )
    {
        msg_Dbg( p_mon, "Nothing in directory `%s'", psz_dir );
        free( pb_processed );
        free( psz_dir );
        return;
    }

    for( i = 0; i < i_dir_content; i++ )
    {
        const char *psz_entry = pp_dir_content[i];

        if( psz_entry[0] != '.' )
        {
            /* 7 is the size of "file://" */
            char psz_uri[strlen(psz_dir) + strlen(psz_entry) + 2 + 7];
            sprintf( psz_uri, "%s/%s", psz_dir, psz_entry );

            if( vlc_stat( psz_uri, &s_stat ) == -1 )
            {
                msg_Err( p_mon, "%s: %m", psz_uri );
                free( pb_processed );
                free( psz_dir );
                return;
            }

            if( S_ISREG( s_stat.st_mode ) )
            {
                const char *psz_dot = strrchr( psz_uri, '.' );
                if( psz_dot++ && *psz_dot )
                {
                    int i_is_media = 0;
                    for( int a = 0; ppsz_MediaExtensions[a]; a++ )
                    {
                        if( !strcasecmp( psz_dot, ppsz_MediaExtensions[a] ) )
                        {
                            i_is_media = 1;
                            break;
                        }
                    }
                    if( !i_is_media )
                    {
                        msg_Dbg( p_mon, "ignoring file %s", psz_uri );
                        continue;
                    }
                }

                char * psz_tmp = encode_URI_component( psz_uri );
                char * psz_encoded_uri = ( char * )calloc( strlen( psz_tmp ) + 9, 1 );
                strcpy( psz_encoded_uri, "file:///" );
                strcat( psz_encoded_uri, psz_tmp );
                free( psz_tmp );

                /* Check if given media is already in DB and it has been updated */
                bool b_skip = false;
                bool b_update = false;
                int j = 1;
                for( j = 1; j <= i_mon_rows; j++ )
                {
                    if( strcasecmp( ppsz_monitored_files[ j * i_mon_cols + 2 ],
                                    psz_encoded_uri ) != 0 )
                        continue;
                    b_update = true;
                    pb_processed[ j - 1 ] = true;
                    if( atoi( ppsz_monitored_files[ j * i_mon_cols + 1 ] )
                        < s_stat.st_mtime )
                    {
                        b_skip = false;
                        break;
                    }
                    else
                    {
                        b_skip = true;
                        break;
                    }
                }
                msg_Dbg( p_ml , "Checking if %s is in DB. Found: %d", psz_encoded_uri,
                         b_skip? 1 : 0 );
                if( b_skip )
                    continue;

                p_input = input_item_New( psz_encoded_uri, psz_entry );

                playlist_t* p_pl = pl_Get( p_mon );
                preparsed_item_t* p_itemobject;
                p_itemobject = malloc( sizeof( preparsed_item_t ) );
                p_itemobject->i_dir_id = i_dir_id;
                p_itemobject->psz_uri = psz_encoded_uri;
                p_itemobject->i_mtime = s_stat.st_mtime;
                p_itemobject->p_mon = p_mon;
                p_itemobject->b_update = b_update;
                p_itemobject->i_update_id = b_update ?
                    atoi( ppsz_monitored_files[ j * i_mon_cols + 0 ] ) : 0 ;

                vlc_event_manager_t *p_em = &p_input->event_manager;
                vlc_event_attach( p_em, vlc_InputItemPreparsedChanged,
                      PreparseComplete, p_itemobject );
                playlist_PreparseEnqueue( p_pl, p_input );
            }
            else if( S_ISDIR( s_stat.st_mode ) && b_recursive )
            {
                Query( p_ml, &pp_results, &i_rows, &i_cols,
                        "SELECT id AS directory_id FROM directories "
                        "WHERE uri=%Q", psz_uri );
                FreeSQLResult( p_ml, pp_results );

                if( i_rows <= 0 )
                {
                    msg_Dbg( p_mon, "New directory `%s' in dir of id %d",
                             psz_uri, i_dir_id );
                    QuerySimple( p_ml,
                                    "INSERT INTO directories (uri, timestamp, "
                                    "recursive) VALUES(%Q, 0, 1)", psz_uri );

                    // We get the id of the directory we've just added
                    Query( p_ml, &pp_results, &i_rows, &i_cols,
                    "SELECT id AS directory_id FROM directories WHERE uri=%Q",
                              psz_uri );
                    if( i_rows <= 0 )
                    {
                        msg_Err( p_mon, "Directory `%s' was not sucessfully"
                                " added to the database", psz_uri );
                        FreeSQLResult( p_ml, pp_results );
                        continue;
                    }

                    ScanFiles( p_mon, atoi( pp_results[1] ), b_recursive,
                               &stself );
                    FreeSQLResult( p_ml, pp_results );
                }
            }
        }
    }

    vlc_array_t* delete_ids = vlc_array_new();
    for( i = 0; i < i_mon_rows; i++ )
    {
       if( !pb_processed[i] )
        {
            /* This file doesn't exist anymore. Let's...urm...delete it. */
            ml_element_t* find = ( ml_element_t* ) calloc( 1, sizeof( ml_element_t ) );
            find->criteria = ML_ID;
            find->value.i = atoi( ppsz_monitored_files[ (i + 1) * i_mon_cols ] );
            vlc_array_append( delete_ids, find );
       }
    }

    /* Delete the unfound media */
    if( Delete( p_ml, delete_ids ) != VLC_SUCCESS )
        msg_Dbg( p_ml, "Something went wrong in multi delete" );

    for( i = 0; i < vlc_array_count( delete_ids ); i++ )
    {
       free( vlc_array_item_at_index( delete_ids, i ) );
    }
    vlc_array_destroy( delete_ids );

    FreeSQLResult( p_ml, ppsz_monitored_files );
    for( i = 0; i < i_dir_content; i++ )
        free( pp_dir_content[i] );
    free( pp_dir_content );
    free( psz_dir );
    free( pb_processed );
}
Пример #16
0
Файл: dbus.c Проект: etix/vlc
static int Open( vlc_object_t *p_this )
{
    intf_thread_t   *p_intf = (intf_thread_t*)p_this;

    /* initialisation of the connection */
    if( !dbus_threads_init_default() )
        return VLC_EGENERIC;

    intf_sys_t *p_sys  = calloc( 1, sizeof( intf_sys_t ) );
    if( unlikely(!p_sys) )
        return VLC_ENOMEM;

    playlist_t      *p_playlist;
    DBusConnection  *p_conn;
    p_sys->i_player_caps   = PLAYER_CAPS_NONE;
    p_sys->i_playing_state = PLAYBACK_STATE_INVALID;

    if( vlc_pipe( p_sys->p_pipe_fds ) )
    {
        free( p_sys );
        msg_Err( p_intf, "Could not create pipe" );
        return VLC_EGENERIC;
    }

    DBusError error;
    dbus_error_init( &error );

    /* connect privately to the session bus
     * the connection will not be shared with other vlc modules which use dbus,
     * thus avoiding a whole class of concurrency issues */
    p_conn = dbus_bus_get_private( DBUS_BUS_SESSION, &error );
    if( !p_conn )
    {
        msg_Err( p_this, "Failed to connect to the D-Bus session daemon: %s",
                error.message );
        dbus_error_free( &error );
        vlc_close( p_sys->p_pipe_fds[1] );
        vlc_close( p_sys->p_pipe_fds[0] );
        free( p_sys );
        return VLC_EGENERIC;
    }

    dbus_connection_set_exit_on_disconnect( p_conn, FALSE );

    /* Register the entry point object path */
    dbus_connection_register_object_path( p_conn, DBUS_MPRIS_OBJECT_PATH,
            &dbus_mpris_vtable, p_this );

    /* Try to register org.mpris.MediaPlayer2.vlc */
    dbus_bus_request_name( p_conn, DBUS_MPRIS_BUS_NAME, 0, &error );
    if( dbus_error_is_set( &error ) )
    {
        msg_Dbg( p_this, "Failed to get service name %s: %s",
                 DBUS_MPRIS_BUS_NAME, error.message );
        dbus_error_free( &error );

        /* Register an instance-specific well known name of the form
         * org.mpris.MediaPlayer2.vlc.instanceXXXX where XXXX is the
         * current Process ID */
        char unique_service[sizeof( DBUS_MPRIS_BUS_NAME ) +
                            sizeof( DBUS_INSTANCE_ID_PREFIX ) + 10];

        snprintf( unique_service, sizeof (unique_service),
                  DBUS_MPRIS_BUS_NAME"."DBUS_INSTANCE_ID_PREFIX"%"PRIu32,
                  (uint32_t)getpid() );

        dbus_bus_request_name( p_conn, unique_service, 0, &error );
        if( dbus_error_is_set( &error ) )
        {
            msg_Err( p_this, "Failed to get service name %s: %s",
                     DBUS_MPRIS_BUS_NAME, error.message );
            dbus_error_free( &error );
        }
        else
            msg_Dbg( p_intf, "listening on dbus as: %s", unique_service );
    }
    else
        msg_Dbg( p_intf, "listening on dbus as: %s", DBUS_MPRIS_BUS_NAME );

    dbus_connection_flush( p_conn );

    p_intf->p_sys = p_sys;
    p_sys->p_conn = p_conn;
    p_sys->p_events = vlc_array_new();
    p_sys->p_timeouts = vlc_array_new();
    p_sys->p_watches = vlc_array_new();
    vlc_mutex_init( &p_sys->lock );

    p_playlist = pl_Get( p_intf );
    p_sys->p_playlist = p_playlist;

    var_AddCallback( p_playlist, "input-current", AllCallback, p_intf );
    var_AddCallback( p_playlist, "volume", AllCallback, p_intf );
    var_AddCallback( p_playlist, "mute", AllCallback, p_intf );
    var_AddCallback( p_playlist, "playlist-item-append", AllCallback, p_intf );
    var_AddCallback( p_playlist, "playlist-item-deleted", AllCallback, p_intf );
    var_AddCallback( p_playlist, "random", AllCallback, p_intf );
    var_AddCallback( p_playlist, "repeat", AllCallback, p_intf );
    var_AddCallback( p_playlist, "loop", AllCallback, p_intf );
    var_AddCallback( p_playlist, "fullscreen", AllCallback, p_intf );

    if( !dbus_connection_set_timeout_functions( p_conn,
                                                add_timeout,
                                                remove_timeout,
                                                toggle_timeout,
                                                p_intf, NULL ) )
        goto error;

    if( !dbus_connection_set_watch_functions( p_conn,
                                              add_watch,
                                              remove_watch,
                                              watch_toggled,
                                              p_intf, NULL ) )
        goto error;

    if( vlc_clone( &p_sys->thread, Run, p_intf, VLC_THREAD_PRIORITY_LOW ) )
        goto error;

    return VLC_SUCCESS;

error:
    /* The dbus connection is private,
     * so we are responsible for closing it
     * XXX: Does this make sense when OOM ? */
    dbus_connection_close( p_sys->p_conn );
    dbus_connection_unref( p_conn );

    vlc_array_destroy( p_sys->p_events );
    vlc_array_destroy( p_sys->p_timeouts );
    vlc_array_destroy( p_sys->p_watches );

    vlc_mutex_destroy( &p_sys->lock );

    vlc_close( p_sys->p_pipe_fds[1] );
    vlc_close( p_sys->p_pipe_fds[0] );
    free( p_sys );
    return VLC_ENOMEM;
}