]> git.sesse.net Git - vlc/commitdiff
mozilla: sanity checks
authorJean-Paul Saman <jean-paul.saman@m2x.nl>
Sun, 7 Feb 2010 13:43:46 +0000 (14:43 +0100)
committerJean-Paul Saman <jean-paul.saman@m2x.nl>
Thu, 11 Feb 2010 09:02:35 +0000 (10:02 +0100)
projects/mozilla/vlcplugin.cpp
projects/mozilla/vlcshell.cpp

index bb5849ce2ddb6e70ef22f2c0c4e992d116192482..c0d7dd1e92f836763d7a71f6db4bb7fae2391964 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * vlcplugin.cpp: a VLC plugin for Mozilla
  *****************************************************************************
- * Copyright (C) 2002-2009 the VideoLAN team
+ * Copyright (C) 2002-2010 the VideoLAN team
  * $Id$
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
@@ -455,7 +455,7 @@ int VlcPlugin::playlist_add( const char *mrl )
     libvlc_media_t *p_m = libvlc_media_new(libvlc_instance,mrl);
     if( !p_m )
         return -1;
-
+    assert( libvlc_media_list );
     libvlc_media_list_lock(libvlc_media_list);
     if( !libvlc_media_list_add_media(libvlc_media_list,p_m) )
         item = libvlc_media_list_count(libvlc_media_list)-1;
@@ -469,8 +469,12 @@ int VlcPlugin::playlist_add( const char *mrl )
 int VlcPlugin::playlist_add_extended_untrusted( const char *mrl, const char *name,
                     int optc, const char **optv )
 {
-    libvlc_media_t *p_m = libvlc_media_new(libvlc_instance, mrl);
+    libvlc_media_t *p_m;
     int item = -1;
+
+    assert( libvlc_media_list );
+
+    p_m = libvlc_media_new(libvlc_instance, mrl);
     if( !p_m )
         return -1;
 
@@ -490,10 +494,11 @@ bool VlcPlugin::playlist_select( int idx )
 {
     libvlc_media_t *p_m = NULL;
 
+    assert( libvlc_media_list );
+
     libvlc_media_list_lock(libvlc_media_list);
 
     int count = libvlc_media_list_count(libvlc_media_list);
-
     if( idx<0||idx>=count )
         goto bad_unlock;
 
@@ -507,6 +512,8 @@ bool VlcPlugin::playlist_select( int idx )
 
     if( libvlc_media_player )
     {
+        if( playlist_isplaying() )
+            playlist_stop();
         events.unhook_manager();
         libvlc_media_player_release( libvlc_media_player );
         libvlc_media_player = NULL;
@@ -531,6 +538,8 @@ bad_unlock:
 
 int VlcPlugin::playlist_delete_item( int idx )
 {
+    if( !libvlc_media_list )
+        return -1;
     libvlc_media_list_lock(libvlc_media_list);
     int ret = libvlc_media_list_remove_index(libvlc_media_list,idx);
     libvlc_media_list_unlock(libvlc_media_list);
@@ -547,6 +556,8 @@ void VlcPlugin::playlist_clear()
 int VlcPlugin::playlist_count()
 {
     int items_count = 0;
+    if( !libvlc_media_list )
+        return items_count;
     libvlc_media_list_lock(libvlc_media_list);
     items_count = libvlc_media_list_count(libvlc_media_list);
     libvlc_media_list_unlock(libvlc_media_list);
@@ -558,11 +569,13 @@ void VlcPlugin::toggle_fullscreen()
     if( playlist_isplaying() )
         libvlc_toggle_fullscreen(libvlc_media_player);
 }
-void VlcPlugin::set_fullscreen( int yes)
+
+void VlcPlugin::set_fullscreen( int yes )
 {
     if( playlist_isplaying() )
         libvlc_set_fullscreen(libvlc_media_player,yes);
 }
+
 int  VlcPlugin::get_fullscreen()
 {
     int r = 0;
@@ -886,7 +899,7 @@ void VlcPlugin::redrawToolbar()
     unsigned int i_tb_width, i_tb_height;
 
     /* This method does nothing if toolbar is hidden. */
-    if( !b_toolbar )
+    if( !b_toolbar || !libvlc_media_player )
         return;
 
     const NPWindow& window = getWindow();
@@ -895,7 +908,6 @@ void VlcPlugin::redrawToolbar()
 
     getToolbarSize( &i_tb_width, &i_tb_height );
 
-
     /* get mute info */
     b_mute = libvlc_audio_get_mute( libvlc_media_player );
 
@@ -1001,7 +1013,8 @@ vlc_toolbar_clicked_t VlcPlugin::getToolbarButtonClicked( int i_xpos, int i_ypos
     is_playing = playlist_isplaying();
 
     /* get mute info */
-    b_mute = libvlc_audio_get_mute( libvlc_media_player );
+    if( libvlc_media_player )
+        b_mute = libvlc_audio_get_mute( libvlc_media_player );
 
     /* is Pause of Play button clicked */
     if( (is_playing != 1) &&
@@ -1072,4 +1085,3 @@ bool VlcPlugin::canUseEventListener()
         return true;
     return false;
 }
-
index 9d45abde955e8fce598b3df211c5687b7d0b647b..cd3efa898ef263896f083919b80911f3f54af248 100644 (file)
@@ -408,7 +408,7 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
         libvlc_video_set_viewport(p_vlc, p_plugin->getMD(), &view, &clip);
 #else
 #warning disabled code
-#endif        
+#endif
         /* remember new window */
         p_plugin->setWindow(*window);
     }
@@ -830,7 +830,8 @@ static void ControlHandler( Widget w, XtPointer closure, XEvent *event )
             case clicked_Mute:
             case clicked_Unmute:
             {
-                libvlc_audio_toggle_mute( p_md );
+                if( p_md )
+                    libvlc_audio_toggle_mute( p_md );
             }
             break;