Changeset 7b32ae177048eb0bc36b6f7610b9e8a1fb22fead

Show
Ignore:
Timestamp:
20/10/07 19:56:00 (1 year ago)
Author:
Pierre d'Herbemont <pdherbemont@videolan.org>
git-committer:
Pierre d'Herbemont <pdherbemont@videolan.org> 1192902960 +0000
git-parent:

[bba8b97ecc1c4f5530eeeec1f10363a3665a964c]

git-author:
Pierre d'Herbemont <pdherbemont@videolan.org> 1192902960 +0000
Message:

src/control: (Patch by Enrique Osuna)
* Add the ability to store user data in media_descriptor.
* Duration can now be retrieved from a media_instance
* Can new get the preparsed state of a media_descriptor
* Add callbacks for libvlc_MediaDescriptorDurationChanged/vlc_InputItemDurationChanged and libvlc_MediaDescriptorPreparsedChanged/vlc_InputItemPreparsedChanged.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/vlc/libvlc.h

    r1524a41 r7b32ae1  
    190190                                           libvlc_exception_t * p_e ); 
    191191 
     192VLC_PUBLIC_API vlc_int64_t 
     193   libvlc_media_descriptor_get_duration( libvlc_media_descriptor_t * p_md, 
     194                                         libvlc_exception_t * p_e ); 
     195                                          
     196VLC_PUBLIC_API vlc_bool_t 
     197   libvlc_media_descriptor_is_preparsed( libvlc_media_descriptor_t * p_md, 
     198                                         libvlc_exception_t * p_e ); 
     199 
     200VLC_PUBLIC_API void  
     201    libvlc_media_descriptor_set_user_data( libvlc_media_descriptor_t * p_md, 
     202                                           void * p_new_user_data, 
     203                                           libvlc_exception_t * p_e); 
     204VLC_PUBLIC_API void * 
     205    libvlc_media_descriptor_get_user_data( libvlc_media_descriptor_t * p_md, 
     206                                           libvlc_exception_t * p_e); 
     207 
    192208/** @}*/ 
    193209 
  • include/vlc/libvlc_structures.h

    r145a649 r7b32ae1  
    297297    libvlc_MediaDescriptorMetaChanged, 
    298298    libvlc_MediaDescriptorSubItemAdded, 
     299    libvlc_MediaDescriptorDurationChanged, 
     300    libvlc_MediaDescriptorPreparsedChanged, 
    299301 
    300302    libvlc_MediaInstancePlayed, 
     
    334336            libvlc_media_descriptor_t * new_child; 
    335337        } media_descriptor_subitem_added; 
    336  
     338        struct 
     339        { 
     340            vlc_int64_t new_duration; 
     341        } media_descriptor_duration_changed; 
     342        struct 
     343        { 
     344            int new_status; 
     345        } media_descriptor_preparsed_changed; 
     346             
    337347        /* media instance */ 
    338348        struct 
  • include/vlc_events.h

    r6ee1e19 r7b32ae1  
    115115    vlc_InputItemMetaChanged, 
    116116    vlc_InputItemSubItemAdded, 
     117    vlc_InputItemDurationChanged, 
     118    vlc_InputItemPreparsedChanged, 
    117119 
    118120    /* Service Discovery event */ 
     
    137139            input_item_t * p_new_child; 
    138140        } input_item_subitem_added; 
    139   
     141        struct vlc_input_item_duration_changed 
     142        { 
     143            mtime_t new_duration; 
     144        } input_item_duration_changed; 
     145        struct vlc_input_item_preparsed_changed 
     146        { 
     147            int new_status; 
     148        } input_item_preparsed_changed; 
     149 
    140150        /* Service discovery events */ 
    141151        struct vlc_services_discovery_item_added 
  • include/vlc_input.h

    rf516f42 r7b32ae1  
    121121    vlc_event_manager_register_event_type( &p_i->event_manager, 
    122122        vlc_InputItemSubItemAdded ); 
     123    vlc_event_manager_register_event_type( &p_i->event_manager, 
     124        vlc_InputItemDurationChanged ); 
     125    vlc_event_manager_register_event_type( &p_i->event_manager, 
     126        vlc_InputItemPreparsedChanged ); 
    123127} 
    124128 
     
    303307static inline void input_item_SetDuration( input_item_t * p_i, mtime_t i_duration ) 
    304308{ 
     309    vlc_bool_t send_event = VLC_FALSE; 
     310 
    305311    vlc_mutex_lock( &p_i->lock ); 
    306     p_i->i_duration = i_duration; 
     312    if( p_i->i_duration != i_duration ) 
     313    { 
     314        p_i->i_duration = i_duration; 
     315        send_event = VLC_TRUE; 
     316    } 
    307317    vlc_mutex_unlock( &p_i->lock ); 
     318     
     319    if ( send_event == VLC_TRUE ) 
     320    { 
     321        vlc_event_t event; 
     322        event.type = vlc_InputItemDurationChanged; 
     323        event.u.input_item_duration_changed.new_duration = i_duration; 
     324        vlc_event_send( &p_i->event_manager, &event ); 
     325    } 
     326     
    308327    return; 
    309328} 
     
    311330static inline void input_item_SetPreparsed( input_item_t *p_i, vlc_bool_t preparsed ) 
    312331{ 
     332    vlc_bool_t send_event = VLC_FALSE; 
     333 
    313334    if( !p_i->p_meta ) 
    314335        p_i->p_meta = vlc_meta_New(); 
    315336 
     337    vlc_mutex_lock( &p_i->lock ); 
     338    int new_status; 
    316339    if( preparsed ) 
    317         p_i->p_meta->i_status |= ITEM_PREPARSED; 
     340        new_status = p_i->p_meta->i_status | ITEM_PREPARSED; 
    318341    else 
    319         p_i->p_meta->i_status &= ~ITEM_PREPARSED; 
     342        new_status = p_i->p_meta->i_status & ~ITEM_PREPARSED; 
     343    if ( p_i->p_meta->i_status != new_status ) 
     344    { 
     345        p_i->p_meta->i_status = new_status; 
     346        send_event = VLC_TRUE; 
     347    } 
     348 
     349    vlc_mutex_unlock( &p_i->lock ); 
     350     
     351    if ( send_event == VLC_TRUE ) 
     352    { 
     353        vlc_event_t event; 
     354        event.type = vlc_InputItemPreparsedChanged; 
     355        event.u.input_item_preparsed_changed.new_status = new_status; 
     356        vlc_event_send( &p_i->event_manager, &event ); 
     357    } 
    320358} 
    321359 
  • src/control/libvlc_internal.h

    ra83d27a r7b32ae1  
    8989    struct libvlc_media_list_t *p_subitems; /* A media descriptor can have 
    9090                                           * Sub item */ 
     91    void *p_user_data; /* Allows for VLC.framework to hook into media descriptor without creating a new VLCMedia object. */ 
    9192}; 
    9293 
  • src/control/media_descriptor.c

    r6ee1e19 r7b32ae1  
    125125} 
    126126 
     127/************************************************************************** 
     128 * input_item_duration_changed (Private) (vlc event Callback) 
     129 **************************************************************************/ 
     130static void input_item_duration_changed( const vlc_event_t *p_event, 
     131                                         void * user_data ) 
     132{ 
     133    libvlc_media_descriptor_t * p_md = user_data; 
     134    libvlc_event_t event; 
     135 
     136    /* Construct the event */ 
     137    event.type = libvlc_MediaDescriptorDurationChanged; 
     138    event.u.media_descriptor_duration_changed.new_duration =  
     139        p_event->u.input_item_duration_changed.new_duration; 
     140 
     141    /* Send the event */ 
     142    libvlc_event_send( p_md->p_event_manager, &event ); 
     143} 
     144 
     145/************************************************************************** 
     146 * input_item_preparsed_changed (Private) (vlc event Callback) 
     147 **************************************************************************/ 
     148static void input_item_preparsed_changed( const vlc_event_t *p_event, 
     149                                          void * user_data ) 
     150{ 
     151    libvlc_media_descriptor_t * p_md = user_data; 
     152    libvlc_event_t event; 
     153 
     154    /* Construct the event */ 
     155    event.type = libvlc_MediaDescriptorPreparsedChanged; 
     156    event.u.media_descriptor_preparsed_changed.new_status =  
     157        p_event->u.input_item_preparsed_changed.new_status; 
     158 
     159    /* Send the event */ 
     160    libvlc_event_send( p_md->p_event_manager, &event ); 
     161} 
    127162 
    128163/************************************************************************** 
     
    139174                      input_item_meta_changed, 
    140175                      p_md ); 
     176    vlc_event_attach( &p_md->p_input_item->event_manager, 
     177                      vlc_InputItemDurationChanged, 
     178                      input_item_duration_changed, 
     179                      p_md ); 
     180    vlc_event_attach( &p_md->p_input_item->event_manager, 
     181                      vlc_InputItemPreparsedChanged, 
     182                      input_item_preparsed_changed, 
     183                      p_md ); 
    141184} 
    142185 
     
    153196                      vlc_InputItemMetaChanged, 
    154197                      input_item_meta_changed, 
     198                      p_md ); 
     199    vlc_event_detach( &p_md->p_input_item->event_manager, 
     200                      vlc_InputItemDurationChanged, 
     201                      input_item_duration_changed, 
     202                      p_md ); 
     203    vlc_event_detach( &p_md->p_input_item->event_manager, 
     204                      vlc_InputItemPreparsedChanged, 
     205                      input_item_preparsed_changed, 
    155206                      p_md ); 
    156207} 
     
    198249    p_md->b_preparsed       = VLC_FALSE; 
    199250    p_md->i_refcount        = 1; 
     251    p_md->p_user_data       = NULL; // VLC.framework hook 
    200252 
    201253    /* A media descriptor can be a playlist. When you open a playlist 
     
    210262    libvlc_event_manager_register_event_type( p_md->p_event_manager, 
    211263        libvlc_MediaDescriptorSubItemAdded, p_e ); 
     264    libvlc_event_manager_register_event_type( p_md->p_event_manager, 
     265        libvlc_MediaDescriptorDurationChanged, p_e ); 
    212266 
    213267    vlc_gc_incref( p_md->p_input_item ); 
     
    463517    return p_md->p_event_manager; 
    464518} 
     519 
     520/************************************************************************** 
     521 * Get duration of media_descriptor object. 
     522 **************************************************************************/ 
     523vlc_int64_t 
     524libvlc_media_descriptor_get_duration( libvlc_media_descriptor_t * p_md, 
     525                                      libvlc_exception_t * p_e ) 
     526{ 
     527    if( p_md && p_md->p_input_item) 
     528    { 
     529        return input_item_GetDuration( p_md->p_input_item ); 
     530    } 
     531    else 
     532    { 
     533        return -1; 
     534    } 
     535} 
     536 
     537/************************************************************************** 
     538 * Get preparsed status for media_descriptor object. 
     539 **************************************************************************/ 
     540vlc_bool_t 
     541libvlc_media_descriptor_is_preparsed( libvlc_media_descriptor_t * p_md, 
     542                                       libvlc_exception_t * p_e ) 
     543{ 
     544    if( p_md && p_md->p_input_item) 
     545    { 
     546        return input_item_IsPreparsed( p_md->p_input_item ); 
     547    } 
     548    else 
     549    { 
     550        return VLC_FALSE; 
     551    } 
     552} 
     553 
     554/************************************************************************** 
     555 * Sets media descriptor's user_data. user_data is specialized data  
     556 * accessed by the host application, VLC.framework uses it as a pointer to  
     557 * an native object that references a libvlc_media_descriptor_t pointer 
     558 **************************************************************************/ 
     559void  
     560libvlc_media_descriptor_set_user_data( libvlc_media_descriptor_t * p_md, 
     561                                       void * p_new_user_data, 
     562                                       libvlc_exception_t * p_e ) 
     563{ 
     564    if( p_md ) 
     565    { 
     566        p_md->p_user_data = p_new_user_data; 
     567    } 
     568} 
     569 
     570/************************************************************************** 
     571 * Get media descriptor's user_data. user_data is specialized data  
     572 * accessed by the host application, VLC.framework uses it as a pointer to  
     573 * an native object that references a libvlc_media_descriptor_t pointer 
     574 **************************************************************************/ 
     575void * 
     576libvlc_media_descriptor_get_user_data( libvlc_media_descriptor_t * p_md, 
     577                                       libvlc_exception_t * p_e ) 
     578{ 
     579    if( p_md ) 
     580    { 
     581        return p_md->p_user_data; 
     582    } 
     583    else 
     584    { 
     585        return NULL; 
     586    } 
     587} 
  • src/control/media_instance.c

    r50b8eb2 r7b32ae1  
    308308    { 
    309309        libvlc_event_manager_release( p_mi->p_event_manager ); 
     310        libvlc_exception_clear( &p_e ); 
    310311        free( p_mi ); 
    311312        return; /* no need to worry about no input thread */