Unify libvlc_state_t, input_state_e, mediacontrol_PlayerStatus and libvlc_event_type_t.
authorJean-Paul Saman <jpsaman@videolan.org>
Sat, 14 Jun 2008 13:35:43 +0000 (15:35 +0200)
committerJean-Paul Saman <jpsaman@videolan.org>
Sat, 14 Jun 2008 14:19:23 +0000 (16:19 +0200)
include/vlc/libvlc_events.h
include/vlc/libvlc_structures.h
include/vlc/mediacontrol_structures.h
include/vlc_input.h
projects/mozilla/vlcplugin.cpp
src/control/event.c
src/control/media_list_player.c
src/control/media_player.c
src/control/mediacontrol_core.c
test/libvlc/events.c

index 1f59a1a..024c8ee 100644 (file)
@@ -47,10 +47,14 @@ typedef enum libvlc_event_type_t {
     libvlc_MediaFreed,
     libvlc_MediaStateChanged,
 
-    libvlc_MediaPlayerPlayed,
+    libvlc_MediaPlayerNothingSpecial,
+    libvlc_MediaPlayerOpening,
+    libvlc_MediaPlayerBuffering,
+    libvlc_MediaPlayerPlaying,
     libvlc_MediaPlayerPaused,
     libvlc_MediaPlayerEndReached,
-    libvlc_MediaPlayerStopped,
+    libvlc_MediaPlayerForward,
+    libvlc_MediaPlayerBackward,
     libvlc_MediaPlayerEncounteredError,
     libvlc_MediaPlayerTimeChanged,
     libvlc_MediaPlayerPositionChanged,
index 56e7af7..2b33252 100644 (file)
@@ -119,16 +119,25 @@ typedef struct libvlc_media_t libvlc_media_t;
 
 typedef struct libvlc_media_player_t libvlc_media_player_t;
 
+/**
+ * Note the order of libvlc_state_t enum must match exactly the order of
+ * @see mediacontrol_PlayerStatus and @see input_state_e enums.
+ *
+ * Expected states by web plugins are:
+ * IDLE/CLOSE=0, OPENING=1, BUFFERING=2, PLAYING=3, PAUSED=4,
+ * STOPPING=5, FORWARD=6, BACKWARD=7, ERROR=8
+ */
 typedef enum libvlc_state_t
 {
-    libvlc_NothingSpecial,
-    libvlc_Stopped,
+    libvlc_NothingSpecial=0,
     libvlc_Opening,
     libvlc_Buffering,
-    libvlc_Ended,
-    libvlc_Error,
     libvlc_Playing,
-    libvlc_Paused
+    libvlc_Paused,
+    libvlc_Ended,
+    libvlc_Forward,
+    libvlc_Backward,
+    libvlc_Error
 } libvlc_state_t;
 
 /**@} */
index 9ccf5d9..af46b64 100644 (file)
@@ -62,12 +62,15 @@ typedef enum {
 
 /**
  * Possible player status
+ * Note the order of these enums must match exactly the order of
+ * libvlc_state_t and input_state_e enums.
  */
 typedef enum {
-    mediacontrol_PlayingStatus, mediacontrol_PauseStatus,
-    mediacontrol_ForwardStatus, mediacontrol_BackwardStatus,
-    mediacontrol_InitStatus,    mediacontrol_EndStatus,
-    mediacontrol_UndefinedStatus
+    mediacontrol_UndefinedStatus=0, mediacontrol_InitStatus,
+    mediacontrol_BufferingStatus, mediacontrol_PlayingStatus,
+    mediacontrol_PauseStatus,     mediacontrol_EndStatus,
+    mediacontrol_ForwardStatus,   mediacontrol_BackwardStatus,
+    mediacontrol_ErrorStatus,
 } mediacontrol_PlayerStatus;
 
 /**
index 737d51e..0cec28c 100644 (file)
@@ -527,12 +527,14 @@ static inline void vlc_input_attachment_Delete( input_attachment_t *a )
 /* "state" value */
 enum input_state_e
 {
-    INIT_S,
+    INIT_S = 0,
     OPENING_S,
     BUFFERING_S,
     PLAYING_S,
     PAUSE_S,
     END_S,
+    FORWARD_S,
+    BACKWARD_S,
     ERROR_S
 };
 
index 65d090a..67dbccb 100644 (file)
@@ -172,7 +172,6 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
         }
     }
 
-
     libvlc_exception_t ex;
     libvlc_exception_init(&ex);
 
index 5e35552..c22e22a 100644 (file)
@@ -239,12 +239,18 @@ static const char event_type_to_name[][35] =
     EVENT(libvlc_MediaFreed),
     EVENT(libvlc_MediaStateChanged),
 
-    EVENT(libvlc_MediaPlayerPlayed),
+    EVENT(libvlc_MediaPlayerNothingSpecial),
+    EVENT(libvlc_MediaPlayerOpening),
+    EVENT(libvlc_MediaPlayerBuffering),
+    EVENT(libvlc_MediaPlayerPlaying),
     EVENT(libvlc_MediaPlayerPaused),
     EVENT(libvlc_MediaPlayerEndReached),
-    EVENT(libvlc_MediaPlayerStopped),
+    EVENT(libvlc_MediaPlayerForward),
+    EVENT(libvlc_MediaPlayerBackward),
     EVENT(libvlc_MediaPlayerTimeChanged),
     EVENT(libvlc_MediaPlayerPositionChanged),
+    EVENT(libvlc_MediaPlayerSeekableChanged),
+    EVENT(libvlc_MediaPlayerPausableChanged),
 
     EVENT(libvlc_MediaListItemAdded),
     EVENT(libvlc_MediaListWillAddItem),
index 1055267..0c26244 100644 (file)
@@ -368,6 +368,7 @@ libvlc_media_list_player_is_playing( libvlc_media_list_player_t * p_mlp,
 {
     libvlc_state_t state = libvlc_media_player_get_state( p_mlp->p_mi, p_e );
     return (state == libvlc_Opening) || (state == libvlc_Buffering) ||
+           (state == libvlc_Forward) || (state == libvlc_Backward) ||
            (state == libvlc_Playing);
 }
 
@@ -379,7 +380,7 @@ libvlc_media_list_player_get_state( libvlc_media_list_player_t * p_mlp,
                                     libvlc_exception_t * p_e )
 {
     if( !p_mlp->p_mi )
-        return libvlc_Stopped;
+        return libvlc_Ended;
     return libvlc_media_player_get_state( p_mlp->p_mi, p_e );
 }
 
index dd56f31..689871d 100644 (file)
@@ -51,19 +51,21 @@ input_time_changed( vlc_object_t * p_this, char const * psz_cmd,
 
 static const libvlc_state_t vlc_to_libvlc_state_array[] =
 {
-    [INIT_S]        = libvlc_Opening,
+    [INIT_S]        = libvlc_NothingSpecial,
     [OPENING_S]     = libvlc_Opening,
     [BUFFERING_S]   = libvlc_Buffering,
     [PLAYING_S]     = libvlc_Playing,
     [PAUSE_S]       = libvlc_Paused,
     [END_S]         = libvlc_Ended,
+    [FORWARD_S]     = libvlc_Forward,
+    [BACKWARD_S]    = libvlc_Backward,
     [ERROR_S]       = libvlc_Error,
 };
 
 static inline libvlc_state_t vlc_to_libvlc_state( int vlc_state )
 {
     if( vlc_state < 0 || vlc_state > 6 )
-        return libvlc_Stopped;
+        return libvlc_Ended;
 
     return vlc_to_libvlc_state_array[vlc_state];
 }
@@ -144,22 +146,43 @@ input_state_changed( const vlc_event_t * event, void * p_userdata )
 
     switch ( type )
     {
-        case END_S:
+        case INIT_S:
             libvlc_media_set_state( p_mi->p_md, libvlc_NothingSpecial, NULL);
-            forwarded_event.type = libvlc_MediaPlayerEndReached;
+            forwarded_event.type = libvlc_MediaPlayerNothingSpecial;
             break;
-        case PAUSE_S:
-            libvlc_media_set_state( p_mi->p_md, libvlc_Playing, NULL);
-            forwarded_event.type = libvlc_MediaPlayerPaused;
+        case OPENING_S:
+            libvlc_media_set_state( p_mi->p_md, libvlc_Opening, NULL);
+            forwarded_event.type = libvlc_MediaPlayerOpening;
+            break;
+        case BUFFERING_S:
+            libvlc_media_set_state( p_mi->p_md, libvlc_Buffering, NULL);
+            forwarded_event.type = libvlc_MediaPlayerBuffering;
             break;
         case PLAYING_S:
             libvlc_media_set_state( p_mi->p_md, libvlc_Playing, NULL);
             forwarded_event.type = libvlc_MediaPlayerPlayed;
             break;
+        case PAUSE_S:
+            libvlc_media_set_state( p_mi->p_md, libvlc_Paused, NULL);
+            forwarded_event.type = libvlc_MediaPlayerPaused;
+            break;
+        case END_S:
+            libvlc_media_set_state( p_mi->p_md, libvlc_Ended, NULL);
+            forwarded_event.type = libvlc_MediaPlayerEndReached;
+            break;
+        case FORWARD_S:
+            libvlc_media_set_state( p_mi->p_md, libvlc_Forward, NULL);
+            forwarded_event.type = libvlc_MediaPlayerForward;
+            break;
+        case BACKWARD_S:
+            libvlc_media_set_state( p_mi->p_md, libvlc_Backward, NULL);
+            forwarded_event.type = libvlc_MediaPlayerBackward;
+            break;
         case ERROR_S:
             libvlc_media_set_state( p_mi->p_md, libvlc_Error, NULL);
             forwarded_event.type = libvlc_MediaPlayerEncounteredError;
             break;
+
         default:
             return;
     }
@@ -317,15 +340,24 @@ libvlc_media_player_new( libvlc_instance_t * p_libvlc_instance,
     }
 
     libvlc_event_manager_register_event_type( p_mi->p_event_manager,
-            libvlc_MediaPlayerEndReached, p_e );
+            libvlc_MediaPlayerNothingSpecial, p_e );
     libvlc_event_manager_register_event_type( p_mi->p_event_manager,
-            libvlc_MediaPlayerStopped, p_e );
+            libvlc_MediaPlayerOpening, p_e );
     libvlc_event_manager_register_event_type( p_mi->p_event_manager,
-            libvlc_MediaPlayerEncounteredError, p_e );
+            libvlc_MediaPlayerBuffering, p_e );
+    libvlc_event_manager_register_event_type( p_mi->p_event_manager,
+            libvlc_MediaPlayerPlaying, p_e );
     libvlc_event_manager_register_event_type( p_mi->p_event_manager,
             libvlc_MediaPlayerPaused, p_e );
     libvlc_event_manager_register_event_type( p_mi->p_event_manager,
-            libvlc_MediaPlayerPlayed, p_e );
+            libvlc_MediaPlayerEndReached, p_e );
+    libvlc_event_manager_register_event_type( p_mi->p_event_manager,
+            libvlc_MediaPlayerForward, p_e );
+    libvlc_event_manager_register_event_type( p_mi->p_event_manager,
+            libvlc_MediaPlayerBackward, p_e );
+    libvlc_event_manager_register_event_type( p_mi->p_event_manager,
+            libvlc_MediaPlayerEncounteredError, p_e );
+
     libvlc_event_manager_register_event_type( p_mi->p_event_manager,
             libvlc_MediaPlayerPositionChanged, p_e );
     libvlc_event_manager_register_event_type( p_mi->p_event_manager,
@@ -636,12 +668,11 @@ void libvlc_media_player_stop( libvlc_media_player_t *p_mi,
     if( state == libvlc_Playing || state == libvlc_Paused )
     {
         /* Send a stop notification event only of we are in playing or paused states */
-
-        libvlc_media_set_state( p_mi->p_md, libvlc_Stopped, p_e );
+        libvlc_media_set_state( p_mi->p_md, libvlc_Ended, p_e );
 
         /* Construct and send the event */
         libvlc_event_t event;
-        event.type = libvlc_MediaPlayerStopped;
+        event.type = libvlc_MediaPlayerEndReached;
         libvlc_event_send( p_mi->p_event_manager, &event );
     }
 
@@ -925,7 +956,7 @@ libvlc_state_t libvlc_media_player_get_state(
         /* We do return the right value, no need to throw an exception */
         if( libvlc_exception_raised( p_e ) )
             libvlc_exception_clear( p_e );
-        return libvlc_Stopped;
+        return libvlc_Ended;
     }
 
     var_Get( p_input_thread, "state", &val );
index d628561..dc5390f 100644 (file)
@@ -357,25 +357,37 @@ mediacontrol_get_stream_information( mediacontrol_Instance *self,
     else
     {
         libvlc_state_t state;
-
         state = libvlc_media_player_get_state( self->p_media_player, &ex );
         HANDLE_LIBVLC_EXCEPTION_NULL( &ex );
         switch( state )
         {
-        case libvlc_Playing :
-            retval->streamstatus = mediacontrol_PlayingStatus;
-            break;
-        case libvlc_Paused :
-            retval->streamstatus = mediacontrol_PauseStatus;
+        case libvlc_NothingSpecial:
+            retval->streamstatus = mediacontrol_UndefinedStatus;
             break;
         case libvlc_Opening :
-        case libvlc_Buffering:
             retval->streamstatus = mediacontrol_InitStatus;
             break;
-        case libvlc_Stopped:
+        case libvlc_Buffering:
+            retval->streamstatus = mediacontrol_BufferingStatus;
+            break;
+        case libvlc_Playing:
+            retval->streamstatus = mediacontrol_PlayingStatus;
+            break;
+        case libvlc_Paused:
+            retval->streamstatus = mediacontrol_PauseStatus;
+            break;
         case libvlc_Ended:
             retval->streamstatus = mediacontrol_EndStatus;
             break;
+        case libvlc_Forward:
+            retval->streamstatus = mediacontrol_ForwardStatus;
+            break;
+        case libvlc_Backward:
+            retval->streamstatus = mediacontrol_BackwardStatus;
+            break;
+        case libvlc_Error:
+            retval->streamstatus = mediacontrol_ErrorStatus;
+            break;
         default :
             retval->streamstatus = mediacontrol_UndefinedStatus;
             break;
index 199c61f..622cac4 100644 (file)
@@ -67,7 +67,6 @@ static void test_events (const char ** argv, int argc)
         libvlc_MediaPlayerPlayed,
         libvlc_MediaPlayerPaused,
         libvlc_MediaPlayerEndReached,
-        libvlc_MediaPlayerStopped,
         libvlc_MediaPlayerEncounteredError,
         libvlc_MediaPlayerTimeChanged,
         libvlc_MediaPlayerPositionChanged,