]> git.sesse.net Git - vlc/blobdiff - modules/access/dvdnav.c
Fixed a segfault after iso639_lang_t p_languages API breakage.
[vlc] / modules / access / dvdnav.c
index 86feaee752befd7ba5533fe9f25f526a70f18791..8aa8353747627091aaf94e5abf4029507d0ca5b0 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * dvdnav.c: DVD module using the dvdnav library.
  *****************************************************************************
- * Copyright (C) 2004 the VideoLAN team
+ * Copyright (C) 2004-2009 the VideoLAN team
  * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
@@ -108,20 +108,6 @@ vlc_module_end ()
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-typedef struct
-{
-    VLC_COMMON_MEMBERS
-
-    demux_t        *p_demux;
-    vlc_mutex_t     lock;
-
-    bool      b_still;
-    int64_t         i_still_end;
-
-} event_thread_t;
-
-static void* EventThread( vlc_object_t * );
-
 struct demux_sys_t
 {
     dvdnav_t    *dvdnav;
@@ -129,6 +115,14 @@ struct demux_sys_t
     /* */
     bool        b_reset_pcr;
 
+    struct
+    {
+        bool         b_created;
+        bool         b_enabled;
+        vlc_mutex_t  lock;
+        vlc_timer_t  timer;
+    } still;
+
     /* track */
     ps_track_t  tk[PS_TK_COUNT];
     int         i_mux_rate;
@@ -138,7 +132,6 @@ struct demux_sys_t
 
     /* event */
     vlc_object_t *p_vout;
-    event_thread_t *p_ev;
 
     /* palette for menus */
     uint32_t clut[16];
@@ -170,6 +163,8 @@ static char *DemuxGetLanguageCode( demux_t *p_demux, const char *psz_var );
 
 static int ControlInternal( demux_t *, int, ... );
 
+static void StillTimer( void * );
+
 static int EventKey( vlc_object_t *, char const *,
                      vlc_value_t, vlc_value_t, void * );
 static int EventMouse( vlc_object_t *, char const *,
@@ -317,7 +312,7 @@ static int Open( vlc_object_t *p_this )
         if( dvdnav_title_play( p_sys->dvdnav, 1 ) != DVDNAV_STATUS_OK )
         {
             msg_Err( p_demux, "cannot set title (can't decrypt DVD?)" );
-            dialog_Fatal( p_demux, _("Playback failure"),
+            dialog_Fatal( p_demux, _("Playback failure"), "%s",
                             _("VLC cannot set the DVD's title. It possibly "
                               "cannot decrypt the entire disc.") );
             dvdnav_close( p_sys->dvdnav );
@@ -354,19 +349,15 @@ static int Open( vlc_object_t *p_this )
     var_Create( p_sys->p_input, "highlight", VLC_VAR_BOOL );
     var_Create( p_sys->p_input, "highlight-mutex", VLC_VAR_MUTEX );
 
-    /* Now create our event thread catcher */
-    p_sys->p_ev = vlc_object_create( p_demux, sizeof( event_thread_t ) );
-    p_sys->p_ev->p_demux = p_demux;
-    vlc_mutex_init( &p_sys->p_ev->lock );
-    p_sys->p_ev->b_still   = false;
-
     /* catch all key event */
     var_AddCallback( p_demux->p_libvlc, "key-action", EventKey, p_demux );
     /* catch vout creation event */
     var_AddCallback( p_sys->p_input, "intf-event", EventIntf, p_demux );
 
-    vlc_thread_create( p_sys->p_ev, "dvdnav event thread handler", EventThread,
-                       VLC_THREAD_PRIORITY_LOW );
+    p_sys->still.b_enabled = false;
+    vlc_mutex_init( &p_sys->still.lock );
+    if( !vlc_timer_create( &p_sys->still.timer, StillTimer, p_sys ) )
+        p_sys->still.b_created = true;
 
     return VLC_SUCCESS;
 }
@@ -380,6 +371,7 @@ static void Close( vlc_object_t *p_this )
     demux_sys_t *p_sys = p_demux->p_sys;
     int i;
 
+    /* Stop vout event handler */
     var_DelCallback( p_sys->p_input, "intf-event", EventIntf, p_demux );
     if( p_sys->p_vout != NULL )
     {   /* Should not happen, but better be safe than sorry. */
@@ -388,12 +380,13 @@ static void Close( vlc_object_t *p_this )
         var_DelCallback( p_sys->p_vout, "mouse-clicked", EventMouse, p_demux );
     }
 
-    /* stop the event handler */
-    vlc_object_kill( p_sys->p_ev );
+    /* Stop key event handler (FIXME: should really be per-vout too) */
     var_DelCallback( p_demux->p_libvlc, "key-action", EventKey, p_demux );
-    vlc_thread_join( p_sys->p_ev );
-    vlc_mutex_destroy( &p_sys->p_ev->lock );
-    vlc_object_release( p_sys->p_ev );
+
+    /* Stop still image handler */
+    if( p_sys->still.b_created )
+        vlc_timer_destroy( &p_sys->still.timer );
+    vlc_mutex_destroy( &p_sys->still.lock );
 
     var_Destroy( p_sys->p_input, "highlight-mutex" );
     var_Destroy( p_sys->p_input, "highlight" );
@@ -644,7 +637,9 @@ static int Demux( demux_t *p_demux )
     switch( i_event )
     {
     case DVDNAV_BLOCK_OK:   /* mpeg block */
-        p_sys->p_ev->b_still = false;
+        vlc_mutex_lock( &p_sys->still.lock );
+        p_sys->still.b_enabled = false;
+        vlc_mutex_unlock( &p_sys->still.lock );
         if( p_sys->b_reset_pcr )
         {
             es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
@@ -662,20 +657,22 @@ static int Demux( demux_t *p_demux )
         dvdnav_still_event_t *event = (dvdnav_still_event_t*)packet;
         bool b_still_init = false;
 
-        vlc_mutex_lock( &p_sys->p_ev->lock );
-        if( !p_sys->p_ev->b_still )
+        vlc_mutex_lock( &p_sys->still.lock );
+        if( !p_sys->still.b_enabled )
         {
             msg_Dbg( p_demux, "DVDNAV_STILL_FRAME" );
             msg_Dbg( p_demux, "     - length=0x%x", event->length );
-            p_sys->p_ev->b_still = true;
+            p_sys->still.b_enabled = true;
+
+            if( event->length != 0xff && p_sys->still.b_created )
+            {
+                mtime_t delay = event->length * CLOCK_FREQ;
+                vlc_timer_schedule( &p_sys->still.timer, false, delay, 0 );
+            }
+
             b_still_init = true;
-            if( event->length == 0xff )
-                p_sys->p_ev->i_still_end = 0;
-            else
-                p_sys->p_ev->i_still_end = mdate() +
-                                           event->length * INT64_C(1000000);
         }
-        vlc_mutex_unlock( &p_sys->p_ev->lock );
+        vlc_mutex_unlock( &p_sys->still.lock );
 
         if( b_still_init )
         {
@@ -914,7 +911,7 @@ static char *DemuxGetLanguageCode( demux_t *p_demux, const char *psz_var )
     if( ( p = strchr( psz_lang, ',' ) ) )
         *p = '\0';
 
-    for( pl = p_languages; pl->psz_iso639_1 != NULL; pl++ )
+    for( pl = p_languages; pl->psz_eng_name != NULL; pl++ )
     {
         if( *psz_lang == '\0' )
             continue;
@@ -928,8 +925,8 @@ static char *DemuxGetLanguageCode( demux_t *p_demux, const char *psz_var )
 
     free( psz_lang );
 
-    if( pl->psz_iso639_1 != NULL )
-        return strdup( pl->psz_iso639_1 );
+    if( pl->psz_eng_name != NULL )
+        return strdup( pl->psz_eng_name );
 
     return strdup(LANGUAGE_DEFAULT);
 }
@@ -1044,15 +1041,14 @@ static void ButtonUpdate( demux_t *p_demux, bool b_mode )
             }
 
             vlc_mutex_lock( p_mutex );
-            val.i_int = hl.sx; var_Set( p_sys->p_input, "x-start", val );
-            val.i_int = hl.ex; var_Set( p_sys->p_input, "x-end", val );
-            val.i_int = hl.sy; var_Set( p_sys->p_input, "y-start", val );
-            val.i_int = hl.ey; var_Set( p_sys->p_input, "y-end", val );
+            var_SetInteger( p_sys->p_input, "x-start", hl.sx );
+            var_SetInteger( p_sys->p_input, "x-end",  hl.ex );
+            var_SetInteger( p_sys->p_input, "y-start", hl.sy );
+            var_SetInteger( p_sys->p_input, "y-end", hl.ey );
 
-            val.p_address = (void *)p_sys->palette;
-            var_Set( p_sys->p_input, "menu-palette", val );
+            var_SetAddress( p_sys->p_input, "menu-palette", p_sys->palette );
 
-            val.b_bool = true; var_Set( p_sys->p_input, "highlight", val );
+            var_SetBool( p_sys->p_input, "highlight", true );
             vlc_mutex_unlock( p_mutex );
 
             msg_Dbg( p_demux, "buttonUpdate %d", i_button );
@@ -1064,8 +1060,7 @@ static void ButtonUpdate( demux_t *p_demux, bool b_mode )
 
             /* Show all */
             vlc_mutex_lock( p_mutex );
-            val.b_bool = false;
-            var_Set( p_sys->p_input, "highlight", val );
+            var_SetBool( p_sys->p_input, "highlight", false );
             vlc_mutex_unlock( p_mutex );
         }
     }
@@ -1301,37 +1296,17 @@ static void ESNew( demux_t *p_demux, int i_id )
 }
 
 /*****************************************************************************
- * Event handler code
+ * Still image end
  *****************************************************************************/
-static void* EventThread( vlc_object_t *p_this )
+static void StillTimer( void *p_data )
 {
-    event_thread_t *p_ev = (event_thread_t*)p_this;
-    demux_sys_t    *p_sys = p_ev->p_demux->p_sys;
-    int canc = vlc_savecancel ();
-
-    /* main loop */
-    while( vlc_object_alive( p_ev ) )
-    {
-        vlc_mutex_lock( &p_ev->lock );
-        /* VOUT part */
-
-        /* Still part */
-        if( p_ev->b_still )
-        {
-            if( p_ev->i_still_end > 0 && p_ev->i_still_end < mdate() )
-            {
-                p_ev->b_still = false;
-                dvdnav_still_skip( p_sys->dvdnav );
-            }
-        }
-        vlc_mutex_unlock( &p_ev->lock );
-
-        /* Wait a bit */
-        msleep( 10000 );
-    }
-    vlc_restorecancel (canc);
+    demux_sys_t    *p_sys = p_data;
 
-    return NULL;
+    vlc_mutex_lock( &p_sys->still.lock );
+    assert( p_sys->still.b_enabled );
+    p_sys->still.b_enabled = false;
+    dvdnav_still_skip( p_sys->dvdnav );
+    vlc_mutex_unlock( &p_sys->still.lock );
 }
 
 static int EventMouse( vlc_object_t *p_vout, char const *psz_var,