⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 media_list_view.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * flat_media_list.c: libvlc flat media list functions. (extension to * media_list.c). ***************************************************************************** * Copyright (C) 2007 the VideoLAN team * $Id$ * * Authors: Pierre d'Herbemont <pdherbemont # videolan.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/#include "libvlc_internal.h"#include <vlc/libvlc.h>#include <assert.h>#include "vlc_arrays.h"//#define DEBUG_FLAT_LIST#ifdef DEBUG_FLAT_LIST# define trace( fmt, ... ) printf( "%s(): " fmt, __FUNCTION__, ##__VA_ARGS__ )#else# define trace( ... )#endif/* * Private functions */static voidmedia_list_item_added( const libvlc_event_t * p_event, void * p_user_data );static voidmedia_list_item_removed( const libvlc_event_t * p_event, void * p_user_data );static voidmedia_list_subitem_added( const libvlc_event_t * p_event, void * p_user_data );static voidinstall_md_listener( libvlc_media_list_view_t * p_mlv,                     libvlc_media_t * p_md){    libvlc_media_list_t * p_mlist;    if((p_mlist = libvlc_media_subitems( p_md, NULL )))    {        libvlc_media_list_lock( p_mlist );        int i, count = libvlc_media_list_count( p_mlist, NULL );        for( i = 0; i < count; i++)        {            libvlc_event_t added_event;            libvlc_media_t * p_submd;            p_submd = libvlc_media_list_item_at_index( p_mlist, i, NULL );            /* Install our listeners */            install_md_listener( p_mlv, p_submd );            /* For each item, send a notification to the mlv subclasses */            added_event.u.media_list_item_added.item = p_submd;            added_event.u.media_list_item_added.index = 0;            if( p_mlv->pf_ml_item_added ) p_mlv->pf_ml_item_added( &added_event, p_mlv );            libvlc_media_release( p_submd );        }        libvlc_event_attach( p_mlist->p_event_manager,                             libvlc_MediaListItemAdded,                             media_list_item_added, p_mlv, NULL );        libvlc_event_attach( p_mlist->p_event_manager,                             libvlc_MediaListItemDeleted,                             media_list_item_removed, p_mlv, NULL );        libvlc_media_list_unlock( p_mlist );        libvlc_media_list_release( p_mlist );    }    else    {        /* No mlist, wait for a subitem added event */        libvlc_event_attach( p_md->p_event_manager,                            libvlc_MediaSubItemAdded,                            media_list_subitem_added, p_mlv, NULL );    }}static voiduninstall_md_listener( libvlc_media_list_view_t * p_mlv,                       libvlc_media_t * p_md){    libvlc_media_list_t * p_mlist;    libvlc_exception_t ignored_exception;    libvlc_exception_init( &ignored_exception );    libvlc_event_detach( p_md->p_event_manager,                         libvlc_MediaSubItemAdded,                         media_list_subitem_added, p_mlv, &ignored_exception );    if( libvlc_exception_raised( &ignored_exception ) )        libvlc_exception_clear( &ignored_exception ); /* We don't care if we encounter an exception */    if((p_mlist = libvlc_media_subitems( p_md, NULL )))    {        libvlc_media_list_lock( p_mlist );        libvlc_event_detach( p_mlist->p_event_manager,                             libvlc_MediaListItemAdded,                             media_list_item_added, p_mlv, NULL );        libvlc_event_detach( p_mlist->p_event_manager,                             libvlc_MediaListItemDeleted,                             media_list_item_removed, p_mlv, NULL );        int i, count = libvlc_media_list_count( p_mlist, NULL );        for( i = 0; i < count; i++)        {            libvlc_media_t * p_submd;            p_submd = libvlc_media_list_item_at_index( p_mlist,i, NULL );            uninstall_md_listener( p_mlv, p_submd );            libvlc_media_release( p_submd );        }        libvlc_media_list_unlock( p_mlist );        libvlc_media_list_release( p_mlist );    }}static voidmedia_list_item_added( const libvlc_event_t * p_event, void * p_user_data ){    libvlc_media_list_view_t * p_mlv = p_user_data;    libvlc_media_t * p_md = p_event->u.media_list_item_added.item;    install_md_listener( p_mlv, p_md );    if( p_mlv->pf_ml_item_added ) p_mlv->pf_ml_item_added( p_event, p_mlv );}static voidmedia_list_item_removed( const libvlc_event_t * p_event, void * p_user_data ){    libvlc_media_list_view_t * p_mlv = p_user_data;    libvlc_media_t * p_md = p_event->u.media_list_item_added.item;    uninstall_md_listener( p_mlv, p_md );    if( p_mlv->pf_ml_item_removed ) p_mlv->pf_ml_item_removed( p_event, p_mlv );}static voidmedia_list_subitem_added( const libvlc_event_t * p_event, void * p_user_data ){    libvlc_media_list_t * p_mlist;    libvlc_event_t added_event;    libvlc_media_list_view_t * p_mlv = p_user_data;    libvlc_media_t * p_submd = p_event->u.media_subitem_added.new_child;    libvlc_media_t * p_md = p_event->p_obj;    if((p_mlist = libvlc_media_subitems( p_md, NULL )))    {        /* We have a mlist to which we're going to listen to events         * thus, no need to wait for SubItemAdded events */        libvlc_event_detach( p_md->p_event_manager,                             libvlc_MediaSubItemAdded,                             media_list_subitem_added, p_mlv, NULL );        libvlc_media_list_lock( p_mlist );        libvlc_event_attach( p_mlist->p_event_manager,                             libvlc_MediaListItemAdded,                             media_list_item_added, p_mlv, NULL );        libvlc_event_attach( p_mlist->p_event_manager,                             libvlc_MediaListItemDeleted,                             media_list_item_removed, p_mlv, NULL );        libvlc_media_list_unlock( p_mlist );        libvlc_media_list_release( p_mlist );    }    install_md_listener( p_mlv, p_submd );    added_event.u.media_list_item_added.item = p_submd;    added_event.u.media_list_item_added.index = 0;    if( p_mlv->pf_ml_item_added ) p_mlv->pf_ml_item_added( &added_event, p_mlv );}/* * LibVLC Internal functions *//************************************************************************** *       libvlc_media_list_view_set_ml_notification_callback (Internal) * The mlist lock should be held when entered **************************************************************************/voidlibvlc_media_list_view_set_ml_notification_callback(                libvlc_media_list_view_t * p_mlv,                void (*item_added)(const libvlc_event_t *, libvlc_media_list_view_t *),                void (*item_removed)(const libvlc_event_t *, libvlc_media_list_view_t *) ){    p_mlv->pf_ml_item_added = item_added;    p_mlv->pf_ml_item_removed = item_removed;    libvlc_event_attach( p_mlv->p_mlist->p_event_manager,                         libvlc_MediaListItemAdded,                         media_list_item_added, p_mlv, NULL );    libvlc_event_attach( p_mlv->p_mlist->p_event_manager,                         libvlc_MediaListItemDeleted,                         media_list_item_removed, p_mlv, NULL );    int i, count = libvlc_media_list_count( p_mlv->p_mlist, NULL );    for( i = 0; i < count; i++)    {        libvlc_media_t * p_md;        p_md = libvlc_media_list_item_at_index( p_mlv->p_mlist, i, NULL );        install_md_listener( p_mlv, p_md );        libvlc_media_release( p_md );    }}/************************************************************************** *       libvlc_media_list_view_notify_deletion (Internal) **************************************************************************/voidlibvlc_media_list_view_will_delete_item(                libvlc_media_list_view_t * p_mlv,                libvlc_media_t * p_item,                int index ){    libvlc_event_t event;    /* Construct the event */    event.type = libvlc_MediaListViewWillDeleteItem;    event.u.media_list_view_will_delete_item.item = p_item;    event.u.media_list_view_will_delete_item.index = index;    /* Send the event */    libvlc_event_send( p_mlv->p_event_manager, &event );}/************************************************************************** *       libvlc_media_list_view_item_deleted (Internal) **************************************************************************/voidlibvlc_media_list_view_item_deleted(                libvlc_media_list_view_t * p_mlv,                libvlc_media_t * p_item,                int index ){    libvlc_event_t event;    /* Construct the event */    event.type = libvlc_MediaListViewItemDeleted;    event.u.media_list_view_item_deleted.item = p_item;    event.u.media_list_view_item_deleted.index = index;    /* Send the event */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -