コード例 #1
0
ファイル: ml_model.cpp プロジェクト: AsamQi/vlc
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();
}
コード例 #2
0
ファイル: sql_monitor.c プロジェクト: CSRedRat/vlc
/**
 * @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;
}
コード例 #3
0
/* Little helper */
static void
import_mlist_rec( libvlc_media_list_view_t * p_mlv,
                  libvlc_media_list_t * p_mlist,
                  libvlc_exception_t * p_e )
{
    int i, count;
    count = libvlc_media_list_count( p_mlist, p_e );
    for( i = 0; i < count; i++ )
    {
        libvlc_media_t * p_md;
        libvlc_media_list_t * p_submlist;
        p_md = libvlc_media_list_item_at_index( p_mlist, i, p_e );
        vlc_array_append( &p_mlv->p_this_view_data->array, p_md );
        p_submlist = libvlc_media_subitems( p_md );
        if( p_submlist )
        {
            libvlc_media_list_lock( p_submlist );
            import_mlist_rec( p_mlv, p_submlist, p_e );
            libvlc_media_list_unlock( p_submlist );
            libvlc_media_list_release( p_submlist );
        }
        /* No need to release the md, as we want to retain it, as it is
         * stored in our array */
    }
}
コード例 #4
0
ファイル: fingerprinter.c プロジェクト: IAPark/vlc
static void EnqueueRequest( fingerprinter_thread_t *f, fingerprint_request_t *r )
{
    fingerprinter_sys_t *p_sys = f->p_sys;
    vlc_mutex_lock( &p_sys->incoming.lock );
    vlc_array_append( &p_sys->incoming.queue, r );
    vlc_mutex_unlock( &p_sys->incoming.lock );
}
コード例 #5
0
ファイル: fingerprinter.c プロジェクト: Kubink/vlc
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
    }
}
コード例 #6
0
ファイル: dbus.c プロジェクト: etix/vlc
// Get all the callbacks
static int AllCallback( vlc_object_t *p_this, const char *psz_var,
                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
    intf_thread_t *p_intf = p_data;
    callback_info_t info = { .signal = SIGNAL_NONE };

    // Wich event is it ?
    if( !strcmp( "input-current", psz_var ) )
        info.signal = SIGNAL_ITEM_CURRENT;
    else if( !strcmp( "volume", psz_var ) )
    {
        if( oldval.f_float != newval.f_float )
            info.signal = SIGNAL_VOLUME_CHANGE;
    }
    else if( !strcmp( "mute", psz_var ) )
    {
        if( oldval.b_bool != newval.b_bool )
            info.signal = SIGNAL_VOLUME_MUTED;
    }
    else if( !strcmp( "playlist-item-append", psz_var ) )
        info.signal = SIGNAL_PLAYLIST_ITEM_APPEND;
    else if( !strcmp( "playlist-item-deleted", psz_var ) )
        info.signal = SIGNAL_PLAYLIST_ITEM_DELETED;
    else if( !strcmp( "random", psz_var ) )
        info.signal = SIGNAL_RANDOM;
    else if( !strcmp( "fullscreen", psz_var ) )
        info.signal = SIGNAL_FULLSCREEN;
    else if( !strcmp( "repeat", psz_var ) )
        info.signal = SIGNAL_REPEAT;
    else if( !strcmp( "loop", psz_var ) )
        info.signal = SIGNAL_LOOP;
    else if( !strcmp( "can-seek", psz_var ) )
        info.signal = SIGNAL_CAN_SEEK;
    else if( !strcmp( "can-pause", psz_var ) )
        info.signal = SIGNAL_CAN_PAUSE;
    else
        vlc_assert_unreachable();

    if( info.signal == SIGNAL_NONE )
        return VLC_SUCCESS;

    callback_info_t *p_info = malloc( sizeof( *p_info ) );
    if( unlikely(p_info == NULL) )
        return VLC_ENOMEM;

    // Append the event
    *p_info = info;
    vlc_mutex_lock( &p_intf->p_sys->lock );
    vlc_array_append( p_intf->p_sys->p_events, p_info );
    vlc_mutex_unlock( &p_intf->p_sys->lock );

    wakeup_main_loop( p_intf );
    (void) p_this;
    return VLC_SUCCESS;
}
コード例 #7
0
ファイル: fingerprinter.c プロジェクト: IAPark/vlc
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);
}
コード例 #8
0
ファイル: media_list.c プロジェクト: Aakash-729/vlc
/* LibVLC internal version */
void libvlc_media_list_internal_add_media( libvlc_media_list_t * p_mlist,
                                           libvlc_media_t * p_md )
{
    libvlc_media_retain( p_md );

    notify_item_addition( p_mlist, p_md, vlc_array_count( &p_mlist->items ),
                          EventWillHappen );
    vlc_array_append( &p_mlist->items, p_md );
    notify_item_addition( p_mlist, p_md, vlc_array_count( &p_mlist->items )-1,
                          EventDidHappen );
}
コード例 #9
0
ファイル: dbus.c プロジェクト: etix/vlc
static dbus_bool_t add_watch( DBusWatch *p_watch, void *p_data )
{
    intf_thread_t *p_intf = (intf_thread_t*) p_data;
    intf_sys_t    *p_sys  = (intf_sys_t*) p_intf->p_sys;

    vlc_mutex_lock( &p_sys->lock );
    vlc_array_append( p_sys->p_watches, p_watch );
    vlc_mutex_unlock( &p_sys->lock );

    return TRUE;
}
コード例 #10
0
/**************************************************************************
 *       ml_item_added  (private) (Callback from media_list_view item_added)
 **************************************************************************/
static void
ml_item_added( const libvlc_event_t * p_event, libvlc_media_list_view_t * p_mlv )
{
    int index = vlc_array_count( &p_mlv->p_this_view_data->array );
    libvlc_media_t * p_md = p_event->u.media_list_item_added.item;
    libvlc_media_retain( p_md );
    trace("appending item at index %d\n", index);

    libvlc_media_list_view_will_add_item( p_mlv, p_md, index );
    vlc_array_append( &p_mlv->p_this_view_data->array, p_md );
    libvlc_media_list_view_item_added( p_mlv, p_md, index );
}
コード例 #11
0
// Get all the callbacks
static int AllCallback( vlc_object_t *p_this, const char *psz_var,
                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
    (void)p_this;
    (void)oldval;
    intf_thread_t *p_intf = (intf_thread_t*)p_data;

    callback_info_t *info = malloc( sizeof( callback_info_t ) );
    if( !info )
        return VLC_ENOMEM;

    vlc_mutex_lock( &p_intf->p_sys->lock );

    // Wich event is it ?
    if( !strcmp( "item-current", psz_var ) )
        info->signal = SIGNAL_ITEM_CURRENT;
    else if( !strcmp( "intf-change", psz_var ) )
        info->signal = SIGNAL_INTF_CHANGE;
    else if( !strcmp( "playlist-item-append", psz_var ) )
    {
        info->signal = SIGNAL_PLAYLIST_ITEM_APPEND;
        info->i_node = ((playlist_add_t*)newval.p_address)->i_node;
    }
    else if( !strcmp( "playlist-item-deleted", psz_var ) )
        info->signal = SIGNAL_PLAYLIST_ITEM_DELETED;
    else if( !strcmp( "random", psz_var ) )
        info->signal = SIGNAL_RANDOM;
    else if( !strcmp( "repeat", psz_var ) )
        info->signal = SIGNAL_REPEAT;
    else if( !strcmp( "loop", psz_var ) )
        info->signal = SIGNAL_LOOP;
    else if( !strcmp( "intf-event", psz_var ) )
    {
        dbus_int32_t state;
        state = (var_GetInteger(p_this, "state") == PAUSE_S) ? 1 : 0;

        if( state == p_intf->p_sys->i_playing_state )
            goto end;

        p_intf->p_sys->i_playing_state = state;
        info->signal = SIGNAL_STATE;
    }
    else
        assert(0);

    // Append the event
    vlc_array_append( p_intf->p_sys->p_events, info );

end:
    vlc_mutex_unlock( &p_intf->p_sys->lock );
    return VLC_SUCCESS;
}
コード例 #12
0
ファイル: event.c プロジェクト: AsamQi/vlc
/**************************************************************************
 *       libvlc_event_manager_register_event_type (internal) :
 *
 * Init an object's event manager.
 **************************************************************************/
void libvlc_event_manager_register_event_type(
        libvlc_event_manager_t * p_em,
        libvlc_event_type_t event_type )
{
    libvlc_event_listeners_group_t * listeners_group;
    listeners_group = xmalloc(sizeof(libvlc_event_listeners_group_t));
    listeners_group->event_type = event_type;
    vlc_array_init( &listeners_group->listeners );

    vlc_mutex_lock( &p_em->object_lock );
    vlc_array_append( &p_em->listeners_groups, listeners_group );
    vlc_mutex_unlock( &p_em->object_lock );
}
コード例 #13
0
ファイル: media_list.c プロジェクト: Kafay/vlc
/* LibVLC internal version */
void _libvlc_media_list_add_media(
                                   libvlc_media_list_t * p_mlist,
                                   libvlc_media_t * p_md,
                                   libvlc_exception_t * p_e )
{
    VLC_UNUSED(p_e);
    libvlc_media_retain( p_md );

    notify_item_addition( p_mlist, p_md, vlc_array_count( &p_mlist->items ),
                          EventWillHappen );
    vlc_array_append( &p_mlist->items, p_md );
    notify_item_addition( p_mlist, p_md, vlc_array_count( &p_mlist->items )-1,
                          EventDidHappen );
}
コード例 #14
0
chunk_t *chunk_New( sms_stream_t* sms, uint64_t duration,\
        uint64_t start_time )
{
    chunk_t *chunk = (chunk_t *)calloc( 1, sizeof( chunk_t ) );			// sunqueen modify
    if( unlikely( chunk == NULL ) )
        return NULL;

    chunk->duration = duration;
    chunk->start_time = start_time;
    chunk->type = UNKNOWN_ES;
    chunk->sequence = vlc_array_count( sms->chunks );
    vlc_array_append( sms->chunks, chunk );
    return chunk;
}
コード例 #15
0
ファイル: sd.c プロジェクト: ToBeStrong/vlc
static void entry_item_append( services_discovery_t *p_sd,
                               netbios_ns_entry *p_entry,
                               input_item_t *p_item )
{
    services_discovery_sys_t *p_sys = p_sd->p_sys;
    struct entry_item *p_entry_item = calloc(1, sizeof(struct entry_item));

    if( !p_entry_item )
        return;
    p_entry_item->p_entry = p_entry;
    p_entry_item->p_item = p_item;
    vlc_gc_incref( p_item );
    vlc_array_append( p_sys->p_entry_item_list, p_entry_item );
    services_discovery_AddItem( p_sd, p_item, NULL );
}
コード例 #16
0
ファイル: event.c プロジェクト: 42TheAnswerToLife/vlc
/**************************************************************************
 *       libvlc_event_attach (public) :
 *
 * Add a callback for an event.
 **************************************************************************/
int libvlc_event_attach(libvlc_event_manager_t *em, libvlc_event_type_t type,
                        libvlc_callback_t callback, void *opaque)
{
    libvlc_event_listener_t *listener = malloc(sizeof (*listener));
    if (unlikely(listener == NULL))
        return ENOMEM;

    listener->event_type = type;
    listener->p_user_data = opaque;
    listener->pf_callback = callback;

    vlc_mutex_lock(&em->lock);
    vlc_array_append(&em->listeners, listener);
    vlc_mutex_unlock(&em->lock);
    return 0;
}
コード例 #17
0
ファイル: dialog.c プロジェクト: IAPark/vlc
static vlc_dialog_id *
dialog_add_locked(vlc_dialog_provider *p_provider, enum dialog_type i_type)
{
    vlc_dialog_id *p_id = calloc(1, sizeof(*p_id));

    if (p_id == NULL)
        return NULL;
    vlc_mutex_init(&p_id->lock);
    vlc_cond_init(&p_id->wait);

    p_id->i_type = i_type;
    p_id->i_refcount = 2; /* provider and callbacks */

    vlc_array_append(&p_provider->dialog_array, p_id);
    return p_id;
}
コード例 #18
0
ファイル: dbus.c プロジェクト: etix/vlc
static dbus_bool_t add_timeout(DBusTimeout *to, void *data)
{
    intf_thread_t *intf = data;
    intf_sys_t *sys = intf->p_sys;

    mtime_t *expiry = malloc(sizeof (*expiry));
    if (unlikely(expiry == NULL))
        return FALSE;

    dbus_timeout_set_data(to, expiry, free);

    vlc_mutex_lock(&sys->lock);
    vlc_array_append(sys->p_timeouts, to);
    vlc_mutex_unlock(&sys->lock);

    return TRUE;
}
コード例 #19
0
ファイル: dbus.c プロジェクト: iamnpc/myfaplayer
static dbus_bool_t add_timeout( DBusTimeout *p_timeout, void *p_data )
{
    intf_thread_t *p_intf = (intf_thread_t*) p_data;
    intf_sys_t    *p_sys  = (intf_sys_t*) p_intf->p_sys;

    timeout_info_t *p_info = calloc( 1, sizeof( timeout_info_t ) );
    p_info->i_remaining = dbus_timeout_get_interval( p_timeout ) * 1000;/* µs */
    p_info->p_timeout = p_timeout;

    dbus_timeout_set_data( p_timeout, p_info, free );

    vlc_mutex_lock( &p_sys->lock );
    vlc_array_append( p_sys->p_timeouts, p_timeout );
    vlc_mutex_unlock( &p_sys->lock );

    return TRUE;
}
コード例 #20
0
ファイル: httpcookies.c プロジェクト: 0xheart0/vlc
bool vlc_http_cookies_store(vlc_http_cookie_jar_t *p_jar, const char *cookies,
                            bool secure, const char *host, const char *path)
{
    assert(host != NULL);
    assert(path != NULL);

    int i;

    http_cookie_t *cookie = cookie_parse(cookies, host, path);
    if (cookie == NULL)
        return false;
    if (!cookie_is_valid(cookie, secure, host, path))
    {
        cookie_destroy(cookie);
        return false;
    }

    vlc_mutex_lock( &p_jar->lock );

    for( i = 0; i < vlc_array_count( &p_jar->cookies ); i++ )
    {
        http_cookie_t *iter = vlc_array_item_at_index( &p_jar->cookies, i );

        assert( iter->psz_name );
        assert( iter->psz_domain );
        assert( iter->psz_path );

        bool domains_match =
            vlc_ascii_strcasecmp( cookie->psz_domain, iter->psz_domain ) == 0;
        bool paths_match = strcmp( cookie->psz_path, iter->psz_path ) == 0;
        bool names_match = strcmp( cookie->psz_name, iter->psz_name ) == 0;
        if( domains_match && paths_match && names_match )
        {
            /* Remove previous value for this cookie */
            vlc_array_remove( &p_jar->cookies, i );
            cookie_destroy(iter);
            break;
        }
    }
    vlc_array_append( &p_jar->cookies, cookie );

    vlc_mutex_unlock( &p_jar->lock );

    return true;
}
コード例 #21
0
ファイル: fingerprinter.c プロジェクト: IAPark/vlc
static void fill_metas_with_results( fingerprint_request_t *p_r, acoustid_fingerprint_t *p_f )
{
    for( unsigned int i=0 ; i < p_f->results.count; i++ )
    {
        acoustid_result_t *p_result = & p_f->results.p_results[ i ];
        for ( unsigned int j=0 ; j < p_result->recordings.count; j++ )
        {
            musicbrainz_recording_t *p_record = & p_result->recordings.p_recordings[ j ];
            vlc_meta_t *p_meta = vlc_meta_New();
            if ( p_meta )
            {
                vlc_meta_Set( p_meta, vlc_meta_Title, p_record->psz_title );
                vlc_meta_Set( p_meta, vlc_meta_Artist, p_record->psz_artist );
                vlc_meta_AddExtra( p_meta, "musicbrainz-id", p_record->s_musicbrainz_id );
                vlc_array_append( & p_r->results.metas_array, p_meta );
            }
        }
    }
}
コード例 #22
0
ファイル: sql_monitor.c プロジェクト: CSRedRat/vlc
/**
 * @brief Get the list of the monitored directories
 * @param p_ml A media library object
 * @param p_array An initialized array where the list will be put in
 * @return VLC_SUCCESS or VLC_EGENERIC
 */
int ListMonitoredDirs( media_library_t *p_ml, vlc_array_t *p_array )
{
    char **pp_results;
    int i_cols, i_rows;
    int i;

    if( Query( p_ml, &pp_results, &i_rows, &i_cols,
            "SELECT uri AS directory_uri FROM directories WHERE recursive=0" )
        != VLC_SUCCESS )
        return VLC_EGENERIC;

    for( i = 1; i <= i_rows; i++ )
    {
        vlc_array_append( p_array, strdup( pp_results[i] ) );
    }
    FreeSQLResult( p_ml, pp_results );

    return VLC_SUCCESS;
}
コード例 #23
0
ファイル: dbus.c プロジェクト: iamnpc/myfaplayer
static dbus_bool_t add_watch( DBusWatch *p_watch, void *p_data )
{
    intf_thread_t *p_intf = (intf_thread_t*) p_data;
    intf_sys_t    *p_sys  = (intf_sys_t*) p_intf->p_sys;
    int            i_fd   = dbus_watch_get_unix_fd( p_watch );

    msg_Dbg( p_intf, "Adding dbus watch on fd %d", i_fd );

    if( dbus_watch_get_flags( p_watch ) & DBUS_WATCH_READABLE )
        msg_Dbg( p_intf, "Watching fd %d for readability", i_fd );

    if( dbus_watch_get_flags( p_watch ) & DBUS_WATCH_WRITABLE )
        msg_Dbg( p_intf, "Watching fd %d for writeability", i_fd );

    vlc_mutex_lock( &p_sys->lock );
    vlc_array_append( p_sys->p_watches, p_watch );
    vlc_mutex_unlock( &p_sys->lock );

    return TRUE;
}
コード例 #24
0
ファイル: event.c プロジェクト: AsamQi/vlc
/**************************************************************************
 *       event_attach (internal) :
 *
 * Add a callback for an event.
 **************************************************************************/
static
int event_attach( libvlc_event_manager_t * p_event_manager,
                  libvlc_event_type_t event_type,
                  libvlc_callback_t pf_callback, void *p_user_data,
                  bool is_asynchronous )
{
    libvlc_event_listeners_group_t * listeners_group;
    libvlc_event_listener_t * listener;
    int i;

    listener = malloc(sizeof(libvlc_event_listener_t));
    if( unlikely(listener == NULL) )
        return ENOMEM;

    listener->event_type = event_type;
    listener->p_user_data = p_user_data;
    listener->pf_callback = pf_callback;
    listener->is_asynchronous = is_asynchronous;

    vlc_mutex_lock( &p_event_manager->object_lock );
    for( i = 0; i < vlc_array_count(&p_event_manager->listeners_groups); i++ )
    {
        listeners_group = vlc_array_item_at_index(&p_event_manager->listeners_groups, i);
        if( listeners_group->event_type == listener->event_type )
        {
            vlc_array_append( &listeners_group->listeners, listener );
            vlc_mutex_unlock( &p_event_manager->object_lock );
            return 0;
        }
    }
    vlc_mutex_unlock( &p_event_manager->object_lock );

    free(listener);
    fprintf( stderr, "This object event manager doesn't know about '%s' events",
             libvlc_event_type_name(event_type) );
    assert(0);
    return -1;
}
コード例 #25
0
ファイル: event.c プロジェクト: sailfish009/vlc
/**************************************************************************
 *       libvlc_event_attach (public) :
 *
 * Add a callback for an event.
 **************************************************************************/
int libvlc_event_attach(libvlc_event_manager_t *em, libvlc_event_type_t type,
                        libvlc_callback_t callback, void *opaque)
{
    libvlc_event_listener_t *listener = malloc(sizeof (*listener));
    if (unlikely(listener == NULL))
        return ENOMEM;

    listener->event_type = type;
    listener->p_user_data = opaque;
    listener->pf_callback = callback;

    int i_ret;
    vlc_mutex_lock(&em->lock);
    if(vlc_array_append(&em->listeners, listener) != 0)
    {
        i_ret = VLC_EGENERIC;
        free(listener);
    }
    else
        i_ret = VLC_SUCCESS;
    vlc_mutex_unlock(&em->lock);
    return i_ret;
}
コード例 #26
0
ファイル: background_worker.c プロジェクト: tguillem/vlc
int background_worker_Push( struct background_worker* worker, void* entity,
                        void* id, int timeout )
{
    struct bg_queued_item* item = malloc( sizeof( *item ) );

    if( unlikely( !item ) )
        return VLC_EGENERIC;

    item->id = id;
    item->entity = entity;
    item->timeout = timeout < 0 ? worker->conf.default_timeout : timeout;

    vlc_mutex_lock( &worker->lock );
    int i_ret = vlc_array_append( &worker->tail.data, item );
    vlc_cond_signal( &worker->tail.wait );
    if( i_ret != 0 )
    {
        free( item );
        return VLC_EGENERIC;
    }

    if( worker->head.active == false )
    {
        worker->head.probe_request = false;
        worker->head.active =
            !vlc_clone_detach( NULL, Thread, worker, VLC_THREAD_PRIORITY_LOW );
    }

    if( worker->head.active )
        worker->conf.pf_hold( item->entity );

    int ret = worker->head.active ? VLC_SUCCESS : VLC_EGENERIC;
    vlc_mutex_unlock( &worker->lock );

    return ret;
}
コード例 #27
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;
}
コード例 #28
0
ファイル: zipstream.c プロジェクト: qdk0901/vlc
/** **************************************************************************
 * \brief List files in zip and append their names to p_array
 * \param p_this
 * \param file Opened zip file
 * \param p_array vlc_array_t which will receive all filenames
 *
 * In case of error, returns VLC_EGENERIC.
 * In case of success, returns number of files found, and goes back to first file.
 *****************************************************************************/
static int GetFilesInZip( stream_t *p_this, unzFile file,
                          vlc_array_t *p_filenames, vlc_array_t *p_fileinfos )
{
    if( !p_filenames || !p_this )
        return VLC_EGENERIC;

    int i_ret = 0;

    /* Get global info */
    unz_global_info info;

    if( unzGetGlobalInfo( file, &info ) != UNZ_OK )
    {
        msg_Warn( p_this, "this is not a valid zip archive" );
        return VLC_EGENERIC;
    }

    /* Go to first file in archive */
    unzGoToFirstFile( file );

    /* Get info about each file */
    for( unsigned long i = 0; i < info.number_entry; i++ )
    {
        char *psz_fileName = calloc( ZIP_FILENAME_LEN, 1 );
        unz_file_info *p_fileInfo = calloc( 1, sizeof( unz_file_info ) );

        if( !p_fileInfo || !psz_fileName )
        {
            free( psz_fileName );
            free( p_fileInfo );
            return VLC_ENOMEM;
        }

        if( unzGetCurrentFileInfo( file, p_fileInfo, psz_fileName,
                                   ZIP_FILENAME_LEN, NULL, 0, NULL, 0 )
            != UNZ_OK )
        {
            msg_Warn( p_this, "can't get info about file in zip" );
            free( psz_fileName );
            free( p_fileInfo );
            return VLC_EGENERIC;
        }

        if( p_filenames )
            vlc_array_append( p_filenames, strdup( psz_fileName ) );
        free( psz_fileName );

        if( p_fileinfos )
            vlc_array_append( p_fileinfos, p_fileInfo );
        else
            free( p_fileInfo );

        if( i < ( info.number_entry - 1 ) )
        {
            /* Go the next file in the archive */
            if( unzGoToNextFile( file ) != UNZ_OK )
            {
                msg_Warn( p_this, "can't go to next file in zip" );
                return VLC_EGENERIC;
            }
        }

        i_ret++;
    }

    /* i_ret should be equal to info.number_entry */
    unzGoToFirstFile( file );
    return i_ret;
}
コード例 #29
0
ファイル: smooth.c プロジェクト: BloodExecutioner/vlc
static int Open( vlc_object_t *p_this )
{
    stream_t *s = (stream_t*)p_this;
    stream_sys_t *p_sys;

    if( !isSmoothStreaming( s ) )
        return VLC_EGENERIC;

    msg_Info( p_this, "Smooth Streaming (%s)", s->psz_path );

    s->p_sys = p_sys = calloc( 1, sizeof(*p_sys ) );
    if( unlikely( p_sys == NULL ) )
        return VLC_ENOMEM;

    char *uri = NULL;
    if( unlikely( asprintf( &uri, "%s://%s", s->psz_access, s->psz_path ) < 0 ) )
    {
        free( p_sys );
        return VLC_ENOMEM;
    }

    /* remove the last part of the url */
    char *pos = strrchr( uri, '/');
    *pos = '\0';
    p_sys->base_url = uri;

    /* XXX I don't know wether or not we should allow caching */
    p_sys->b_cache = false;

    p_sys->sms_streams = vlc_array_new();
    p_sys->selected_st = vlc_array_new();
    p_sys->download.chunks = vlc_array_new();
    p_sys->init_chunks = vlc_array_new();
    if( unlikely( !p_sys->sms_streams || !p_sys->download.chunks ||
                  !p_sys->selected_st || !p_sys->init_chunks ) )
    {
        free( p_sys );
        return VLC_ENOMEM;
    }

    /* Parse SMS ismc content. */
    if( parse_Manifest( s ) != VLC_SUCCESS )
    {
        free( p_sys );
        return VLC_EGENERIC;
    }

    if( !p_sys->vod_duration )
       p_sys->b_live = true;

    p_sys->i_tracks = vlc_array_count( p_sys->sms_streams );

    /* Choose first video / audio / subtitle stream available */
    sms_stream_t *tmp = NULL, *selected = NULL;
    for( unsigned i = 0; i < p_sys->i_tracks; i++ )
    {
        tmp = vlc_array_item_at_index( p_sys->sms_streams, i );
        selected = SMS_GET_SELECTED_ST( tmp->type );
        if( !selected )
            vlc_array_append( p_sys->selected_st, tmp );
    }

    /* Choose lowest quality for the first chunks */
    quality_level_t *wanted, *qlvl;
    sms_stream_t *sms = NULL;

    for( unsigned i = 0; i < p_sys->i_tracks; i++ )
    {
        wanted = qlvl = NULL;
        sms = vlc_array_item_at_index( p_sys->sms_streams, i );
        wanted = vlc_array_item_at_index( sms->qlevels, 0 );
        for( unsigned i=1; i < sms->qlevel_nb; i++ )
        {
            qlvl = vlc_array_item_at_index( sms->qlevels, i );
            if( qlvl->Bitrate < wanted->Bitrate )
                wanted = qlvl;
        }
        sms->download_qlvl = wanted->id;
    }

    vlc_mutex_init( &p_sys->download.lock_wait );
    vlc_cond_init( &p_sys->download.wait );

    /* */
    s->pf_read = Read;
    s->pf_peek = Peek;
    s->pf_control = Control;

    if( vlc_clone( &p_sys->thread, sms_Thread, s, VLC_THREAD_PRIORITY_INPUT ) )
    {
        free( p_sys );
        vlc_mutex_destroy( &p_sys->download.lock_wait );
        vlc_cond_destroy( &p_sys->download.wait );
        return VLC_EGENERIC;
    }

    return VLC_SUCCESS;
}
コード例 #30
0
ファイル: dbus.c プロジェクト: iamnpc/myfaplayer
// Get all the callbacks
static int AllCallback( vlc_object_t *p_this, const char *psz_var,
                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
    (void)p_this;
    (void)oldval;

    intf_thread_t *p_intf = (intf_thread_t*)p_data;
    callback_info_t *info = calloc( 1, sizeof( callback_info_t ) );

    if( !info )
        return VLC_ENOMEM;

    vlc_mutex_lock( &p_intf->p_sys->lock );

    // Wich event is it ?
    if( !strcmp( "item-current", psz_var ) )
        info->signal = SIGNAL_ITEM_CURRENT;

    else if( !strcmp( "intf-change", psz_var ) )
        info->signal = SIGNAL_INTF_CHANGE;

    else if( !strcmp( "playlist-item-append", psz_var ) )
    {
        info->signal = SIGNAL_PLAYLIST_ITEM_APPEND;
        info->i_node = ((playlist_add_t*)newval.p_address)->i_node;
    }

    else if( !strcmp( "playlist-item-deleted", psz_var ) )
        info->signal = SIGNAL_PLAYLIST_ITEM_DELETED;

    else if( !strcmp( "random", psz_var ) )
        info->signal = SIGNAL_RANDOM;

    else if( !strcmp( "repeat", psz_var ) )
        info->signal = SIGNAL_REPEAT;

    else if( !strcmp( "loop", psz_var ) )
        info->signal = SIGNAL_LOOP;

    else if( !strcmp( "intf-event", psz_var ) )
    {
        int i_res;
        i_res = InputIntfEventCallback( p_intf, p_this, newval.i_int, info );

        if( VLC_SUCCESS != i_res )
        {
            vlc_mutex_unlock( &p_intf->p_sys->lock );
            free( info );

            return i_res;
        }
    }

    else
        assert(0);

    // Append the event
    vlc_array_append( p_intf->p_sys->p_events, info );
    vlc_mutex_unlock( &p_intf->p_sys->lock );

    msg_Dbg( p_intf,
             "Got a VLC event on %s. The main loop needs to wake up "
             "in order to process it", psz_var );

    wakeup_main_loop( p_intf );

    return VLC_SUCCESS;
}