Changeset 12c291f038deb29afafc050b67b81df6786fc2b9

Show
Ignore:
Timestamp:
20/05/07 01:11:39 (2 years ago)
Author:
Filippo Carone <littlejohn@videolan.org>
git-committer:
Filippo Carone <littlejohn@videolan.org> 1179616299 +0000
git-parent:

[6baab07ed0743c12a0e72e61560de031bc5e6fc6]

git-author:
Filippo Carone <littlejohn@videolan.org> 1179616299 +0000
Message:

Initial callback support in libvlc + example on how to use in the java bindings

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • bindings/java/VLCExample.java

    r6a84cf1 r12c291f  
    22import org.videolan.jvlc.JVLC; 
    33import org.videolan.jvlc.VLCException; 
     4import org.videolan.jvlc.VolumeListener; 
    45 
    56 
     
    8485 
    8586            } 
     87            jvlc.audio.addVolumeListener(new VolumeListener() 
     88            { 
     89                public void volumeChanged() { 
     90                    System.out.println("====> From the listener: volume changed"); 
     91                } 
     92            }); 
     93 
    8694            System.out.print("Muting..."); 
    8795            jvlc.audio.setMute(true); 
  • bindings/java/includes/Audio.h

    r8b8a684 r12c291f  
    8080  (JNIEnv *, jobject, jint); 
    8181 
     82/* 
     83 * Class:     org_videolan_jvlc_Audio 
     84 * Method:    _install_callback 
     85 * Signature: ()V 
     86 */ 
     87JNIEXPORT void JNICALL Java_org_videolan_jvlc_Audio__1install_1callback 
     88  (JNIEnv *, jobject); 
     89 
    8290#ifdef __cplusplus 
    8391} 
  • bindings/java/org/videolan/jvlc/Audio.java

    rd959364 r12c291f  
    11package org.videolan.jvlc; 
    22 
     3import java.util.HashMap; 
     4import java.util.HashSet; 
     5import java.util.Iterator; 
     6import java.util.Map; 
     7import java.util.Set; 
     8 
    39public class Audio implements AudioIntf { 
    4      
     10 
    511    private long libvlcInstance; 
    612 
    7     private native int      _getTrack(); 
    8     private native void     _setTrack(int track); 
    9     private native int      _getChannel(); 
    10     private native void     _setChannel(int channel); 
    11     private native boolean  _getMute(); 
    12     private native void     _setMute( boolean value ); 
    13     private native void     _toggleMute(); 
    14     private native int      _getVolume(); 
    15     private native void     _setVolume( int volume ); 
    16      
    17     public Audio( long instance ) { 
    18         this.libvlcInstance = instance; 
    19     } 
    20      
     13    private native int _getTrack(); 
     14 
     15    private native void _setTrack(int track); 
     16 
     17    private native int _getChannel(); 
     18 
     19    private native void _setChannel(int channel); 
     20 
     21    private native boolean _getMute(); 
     22 
     23    private native void _setMute(boolean value); 
     24 
     25    private native void _toggleMute(); 
     26 
     27    private native int _getVolume(); 
     28 
     29    private native void _setVolume(int volume); 
     30 
     31    private native void _install_callback(); 
     32 
     33    private static Map objListeners = new HashMap(); 
     34 
     35    public Audio(long instance) { 
     36        this.libvlcInstance = instance; 
     37        install_callaback(); 
     38    } 
     39 
     40    private void install_callaback() { 
     41        objListeners.put(this, new HashSet()); 
     42        _install_callback(); 
     43    } 
     44 
    2145    public int getTrack() throws VLCException { 
    2246        return _getTrack(); 
    2347    } 
    2448 
    25     public void setTrack( int track ) throws VLCException { 
     49    public void setTrack(int track) throws VLCException { 
    2650        _setTrack(track); 
    2751    } 
     
    3155    } 
    3256 
    33     public void setChannel( int channel ) throws VLCException { 
     57    public void setChannel(int channel) throws VLCException { 
    3458        _setChannel(channel); 
    35     }     
    36      
    37     public boolean getMute() throws VLCException { 
    38         return _getMute(); 
    39     } 
     59    } 
    4060 
    41     public void setMute( boolean value ) throws VLCException { 
    42         _setMute( value ); 
    43          
    44     } 
    45      
    46     public void toggleMute() throws VLCException { 
    47         _toggleMute(); 
    48     } 
     61    public boolean getMute() throws VLCException { 
     62        return _getMute(); 
     63    } 
    4964 
    50     public int getVolume() throws VLCException { 
    51         return _getVolume();         
    52     } 
     65    public void setMute(boolean value) throws VLCException { 
     66        _setMute(value); 
    5367 
    54     public void setVolume(int volume) throws VLCException { 
    55         _setVolume( volume ); 
    56          
    57     } 
    58      
     68    } 
     69 
     70    public void toggleMute() throws VLCException { 
     71        _toggleMute(); 
     72    } 
     73 
     74    public int getVolume() throws VLCException { 
     75        return _getVolume(); 
     76    } 
     77 
     78    public void setVolume(int volume) throws VLCException { 
     79        _setVolume(volume); 
     80    } 
     81 
     82    public boolean addVolumeListener(VolumeListener listener) { 
     83        HashSet listeners = (HashSet) objListeners.get(this); 
     84        return listeners.add(listener); 
     85    } 
     86 
     87    public boolean removeVolumeListener(VolumeListener listener) { 
     88        HashSet listeners = (HashSet) objListeners.get(this); 
     89        return listeners.remove(listener); 
     90    } 
     91 
     92    // this method is invoked natively 
     93    private static void wakeupListeners() { 
     94        Set audioObjects = objListeners.keySet(); 
     95        Iterator audioObjectsIterator = audioObjects.iterator(); 
     96         
     97        while (audioObjectsIterator.hasNext()) { 
     98            Audio audioObject = (Audio) audioObjectsIterator.next(); 
     99            HashSet listeners = (HashSet) objListeners.get(audioObject); 
     100 
     101            Iterator listenerIterator = listeners.iterator(); 
     102            while (listenerIterator.hasNext()) { 
     103                VolumeListener listener = (VolumeListener) listenerIterator.next(); 
     104                listener.volumeChanged(); 
     105            } 
     106        } 
     107    } 
     108 
    59109    public long getInstance() { 
    60110        return libvlcInstance; 
  • bindings/java/src/Makefile.am

    rcab9f4b r12c291f  
    88    utils.h \ 
    99    video-jni.cc \ 
    10     vlm-jni.cc 
     10    vlm-jni.cc \ 
     11    callback-jni.cc 
     12 
    1113libjvlc_la_CPPFLAGS = `$(VLC_CONFIG) --cflags pic` $(JINCLUDES) 
    1214libjvlc_la_LIBADD = ../../../src/libvlc-control.la $(LIBJINCLUDES) 
  • bindings/java/src/core-jni.cc

    r52fbb24 r12c291f  
    7171 
    7272    free( exception ); 
    73   
     73 
    7474    return res; 
    7575 
  • include/vlc/libvlc.h

    r3b41ca7 r12c291f  
    804804 * \param p_instance the libvlc instance 
    805805 * \param i_event_type the desired event mask to which we want to listen 
    806  * \param pf_callback function the function to call when an_Event occurs 
     806 * \param f_callback the function to call when i_event_type occurs 
     807 * \param user_data user provided data to carry with the event 
    807808 * \param p_e an initialized exception pointer 
    808809 */ 
    809 /* void libvlc_callback_register_for_eventtype( libvlc_instance_t *p_instance, */ 
    810 /*                                              libvlc_event_type_t i_event_type, */ 
    811 /*                                              libvlc_callback_t pf_callback, */ 
    812 /*                                              libvlc_exception_t *p_e ); */ 
     810VLC_PUBLIC_API void libvlc_callback_register_for_event( libvlc_instance_t *p_instance, 
     811                                                        libvlc_event_type_t i_event_type, 
     812                                                        libvlc_callback_t f_callback, 
     813                                                        void *user_data, 
     814                                                        libvlc_exception_t *p_e ); 
    813815 
    814816/** 
     
    816818 * \param p_instance the libvlc instance 
    817819 * \param i_event_type the desired event mask to which we want to unregister 
    818  * \param pf_function the function to call when an_Event occurs 
     820 * \param f_callback the function to call when i_event_type occurs 
    819821 * \param p_e an initialized exception pointer 
    820822 */ 
    821 /* void libvlc_callback_unregister_for_eventtype( libvlc_instance_t *p_instance, */ 
    822 /*                                                libvlc_event_type_t i_event_type, */ 
    823 /*                                                libvlc_callback_t pf_function, */ 
    824 /*                                                libvlc_exception_t *p_e ); */ 
    825  
     823VLC_PUBLIC_API void libvlc_callback_unregister_for_event( libvlc_instance_t *p_instance, 
     824                                                          libvlc_event_type_t i_event_type, 
     825                                                          libvlc_callback_t f_callback, 
     826                                                          libvlc_exception_t *p_e ); 
    826827 
    827828/** @} */ 
  • include/vlc/libvlc_structures.h

    r3c5ed2f r12c291f  
    155155    char reserved[8]; /* For future use */ 
    156156} libvlc_event_t; 
    157    
    158 typedef void ( *libvlc_callback_t )( struct libvlc_instance_t *, libvlc_event_t * ); 
     157 
     158/** 
     159 * Callback function notification 
     160 * \param p_instance the libvlc instance 
     161 * \param p_event the event triggering the callback 
     162 * \param p_user_data user provided data 
     163 */ 
     164 
     165typedef void ( *libvlc_callback_t )( struct libvlc_instance_t *, libvlc_event_t *, void * ); 
    159166 
    160167/**@} */ 
  • src/Makefile.am

    rc43bae3 r12c291f  
    2525    ../include/vlc/vlc.h \ 
    2626    ../include/vlc/libvlc.h \ 
     27    ../include/vlc/libvlc_structures.h \ 
    2728    ../include/vlc/mediacontrol.h \ 
    2829    ../include/vlc/mediacontrol_structures.h \ 
     
    327328    control/video.c \ 
    328329    control/audio.c \ 
     330    control/callback.c \ 
    329331    control/mediacontrol_internal.h \ 
    330332    control/mediacontrol_core.c \ 
  • src/control/core.c

    r3c5ed2f r12c291f  
    112112    while( p_listitem ) 
    113113    { 
    114         struct libvlc_callback_entry_list *p_nextlistitem = p_listitem->next; 
     114        struct libvlc_callback_entry_list_t *p_nextlistitem = p_listitem->next; 
    115115        free( p_listitem ); 
    116116        p_listitem = p_nextlistitem; 
  • src/control/libvlc_internal.h

    r3c5ed2f r12c291f  
    5050struct libvlc_callback_entry_t 
    5151{ 
    52     libvlc_callback_t callback; 
    53     libvlc_event_type_t eventType; 
     52    libvlc_instance_t *p_instance; 
     53    libvlc_callback_t f_callback; 
     54    libvlc_event_type_t i_event_type; 
    5455    void *p_user_data; 
    5556}; 
     
    7879}; 
    7980 
     81 
     82static inline void add_callback_entry( struct libvlc_callback_entry_t *entry, 
     83                                       struct libvlc_callback_entry_list_t **list ) 
     84{ 
     85    struct libvlc_callback_entry_list_t *new_listitem; 
     86    new_listitem = malloc( sizeof( struct libvlc_callback_entry_list_t ) ); 
     87    new_listitem->elmt = entry; 
     88    new_listitem->next = *list; 
     89    new_listitem->prev = NULL; 
     90 
     91    if(*list) 
     92        (*list)->prev = new_listitem; 
     93 
     94    *list = new_listitem; 
     95} 
     96 
    8097#define RAISENULL( psz,a... ) { libvlc_exception_raise( p_e, psz,##a ); \ 
    8198                                return NULL; }