]> git.sesse.net Git - vlc/blobdiff - src/input/vlm.c
vlm : call var_DelCallback after input thread is joined.
[vlc] / src / input / vlm.c
index 69f454c6cac8c2897f5144db7ed051740b6e09fb..66dfbf7bf817408a6fcb649006401eee4e2b0fda 100644 (file)
@@ -146,8 +146,8 @@ vlm_t *vlm_New ( vlc_object_t *p_this )
 
     msg_Dbg( p_this, "creating VLM" );
 
-    p_vlm = vlc_custom_create( p_this, sizeof( *p_vlm ), VLC_OBJECT_GENERIC,
-                               vlm_object_name );
+    p_vlm = vlc_custom_create( p_this->p_libvlc, sizeof( *p_vlm ),
+                               VLC_OBJECT_GENERIC, vlm_object_name );
     if( !p_vlm )
     {
         vlc_mutex_unlock( &vlm_mutex );
@@ -163,7 +163,6 @@ vlm_t *vlm_New ( vlc_object_t *p_this )
     TAB_INIT( p_vlm->i_schedule, p_vlm->schedule );
     p_vlm->p_vod = NULL;
     var_Create( p_vlm, "intf-event", VLC_VAR_ADDRESS );
-    vlc_object_attach( p_vlm, p_this->p_libvlc );
 
     if( vlc_clone( &p_vlm->thread, Manage, p_vlm, VLC_THREAD_PRIORITY_LOW ) )
     {
@@ -226,7 +225,7 @@ static void vlm_Destructor( vlm_t *p_vlm )
     TAB_CLEAN( p_vlm->i_media, p_vlm->media );
 
     vlm_ControlInternal( p_vlm, VLM_CLEAR_SCHEDULES );
-    TAB_CLEAN( p_vlm->schedule, p_vlm->schedule );
+    TAB_CLEAN( p_vlm->i_schedule, p_vlm->schedule );
     vlc_mutex_unlock( &p_vlm->lock );
 
     libvlc_priv(p_vlm->p_libvlc)->p_vlm = NULL;
@@ -317,13 +316,40 @@ static int vlm_MediaVodControl( void *p_private, vod_media_t *p_vod_media,
     switch( i_query )
     {
     case VOD_MEDIA_PLAY:
+    {
         psz = (const char *)va_arg( args, const char * );
+        int64_t *i_time = (int64_t *)va_arg( args, int64_t *);
+        bool b_retry = false;
+        if (*i_time < 0)
+        {
+            /* No start time requested: return the current NPT */
+            i_ret = vlm_ControlInternal( vlm, VLM_GET_MEDIA_INSTANCE_TIME, id, psz_id, i_time );
+            /* The instance is not running yet, it will start at 0 */
+            if (i_ret)
+                *i_time = 0;
+        }
+        else
+        {
+            /* We want to seek before unpausing, but it won't
+             * work if the instance is not running yet. */
+            b_retry = vlm_ControlInternal( vlm, VLM_SET_MEDIA_INSTANCE_TIME, id, psz_id, *i_time );
+        }
+
         i_ret = vlm_ControlInternal( vlm, VLM_START_MEDIA_VOD_INSTANCE, id, psz_id, 0, psz );
+
+        if (!i_ret && b_retry)
+            i_ret = vlm_ControlInternal( vlm, VLM_SET_MEDIA_INSTANCE_TIME, id, psz_id, *i_time );
         break;
+    }
 
     case VOD_MEDIA_PAUSE:
+    {
+        int64_t *i_time = (int64_t *)va_arg( args, int64_t *);
         i_ret = vlm_ControlInternal( vlm, VLM_PAUSE_MEDIA_INSTANCE, id, psz_id );
+        if (!i_ret)
+            i_ret = vlm_ControlInternal( vlm, VLM_GET_MEDIA_INSTANCE_TIME, id, psz_id, i_time );
         break;
+    }
 
     case VOD_MEDIA_STOP:
         i_ret = vlm_ControlInternal( vlm, VLM_STOP_MEDIA_INSTANCE, id, psz_id );
@@ -445,7 +471,7 @@ static void* Manage( void* p_object )
         {
             mtime_t i_real_date = vlm->schedule[i]->i_date;
 
-            if( vlm->schedule[i]->b_enabled == true )
+            if( vlm->schedule[i]->b_enabled )
             {
                 if( vlm->schedule[i]->i_date == 0 ) // now !
                 {
@@ -479,7 +505,7 @@ static void* Manage( void* p_object )
                         }
                     }
                 }
-                else
+                else if( i_nextschedule == 0 || i_real_date < i_nextschedule )
                 {
                     i_nextschedule = i_real_date;
                 }
@@ -646,8 +672,7 @@ static int vlm_OnMediaUpdate( vlm_t *p_vlm, vlm_media_sys_t *p_media )
                                  &preparse );
 
                 input_Stop( p_input, true );
-                vlc_thread_join( p_input );
-                vlc_object_release( p_input );
+                input_Close( p_input );
                 vlc_sem_destroy( &sem_preparse );
             }
             free( psz_header );
@@ -735,8 +760,7 @@ static int vlm_ControlMediaAdd( vlm_t *p_vlm, vlm_media_t *p_cfg, int64_t *p_id
     {
         p_vlm->p_vod = vlc_custom_create( VLC_OBJECT(p_vlm), sizeof( vod_t ),
                                           VLC_OBJECT_GENERIC, "vod server" );
-        vlc_object_attach( p_vlm->p_vod, p_vlm->p_libvlc );
-        p_vlm->p_vod->p_module = module_need( p_vlm->p_vod, "vod server", NULL, false );
+        p_vlm->p_vod->p_module = module_need( p_vlm->p_vod, "vod server", "$vod-server", false );
         if( !p_vlm->p_vod->p_module )
         {
             msg_Err( p_vlm, "cannot find vod server" );
@@ -877,7 +901,6 @@ static vlm_media_instance_sys_t *vlm_MediaInstanceNew( vlm_t *p_vlm, const char
     p_instance->i_index = 0;
     p_instance->b_sout_keep = false;
     p_instance->p_parent = vlc_object_create( p_vlm, sizeof (vlc_object_t) );
-    vlc_object_attach( p_instance->p_parent, p_vlm->p_libvlc );
     p_instance->p_input = NULL;
     p_instance->p_input_resource = NULL;
 
@@ -889,10 +912,9 @@ static void vlm_MediaInstanceDelete( vlm_t *p_vlm, int64_t id, vlm_media_instanc
     if( p_input )
     {
         input_Stop( p_input, true );
-        vlc_thread_join( p_input );
-
+        input_Join( p_input );
         var_DelCallback( p_instance->p_input, "intf-event", InputEvent, p_media );
-        vlc_object_release( p_input );
+        input_Release( p_input );
 
         vlm_SendEventMediaInstanceStopped( p_vlm, id, p_media->cfg.psz_name );
     }
@@ -985,10 +1007,9 @@ static int vlm_ControlMediaInstanceStart( vlm_t *p_vlm, int64_t id, const char *
 
 
         input_Stop( p_input, true );
-        vlc_thread_join( p_input );
-
+        input_Join( p_input );
         var_DelCallback( p_instance->p_input, "intf-event", InputEvent, p_media );
-        vlc_object_release( p_input );
+        input_Release( p_input );
 
         if( !p_instance->b_sout_keep )
             input_resource_TerminateSout( p_instance->p_input_resource );