]> git.sesse.net Git - vlc/blobdiff - src/input/vlm.c
Extended input_GetPcrSystem to also return the current delay.
[vlc] / src / input / vlm.c
index bc8157fac53fbaa9e0d88c2dde50194381c9f492..b48352695ed871a9bd08e329a46ef42bd0a80493 100644 (file)
@@ -90,6 +90,7 @@ static int InputEvent( vlc_object_t *p_this, char const *psz_cmd,
     VLC_UNUSED(oldval);
     input_thread_t *p_input = (input_thread_t *)p_this;
     vlm_t *p_vlm = libvlc_priv( p_input->p_libvlc )->p_vlm;
+    assert( p_vlm );
     vlm_media_sys_t *p_media = p_data;
     const char *psz_instance_name = NULL;
 
@@ -111,25 +112,22 @@ static int InputEvent( vlc_object_t *p_this, char const *psz_cmd,
 /*****************************************************************************
  * vlm_New:
  *****************************************************************************/
+static vlc_mutex_t vlm_mutex = VLC_STATIC_MUTEX;
+
 vlm_t *__vlm_New ( vlc_object_t *p_this )
 {
-    vlc_value_t lockval;
     vlm_t *p_vlm = NULL, **pp_vlm = &(libvlc_priv (p_this->p_libvlc)->p_vlm);
     char *psz_vlmconf;
     static const char vlm_object_name[] = "vlm daemon";
 
     /* Avoid multiple creation */
-    if( var_Create( p_this->p_libvlc, "vlm_mutex", VLC_VAR_MUTEX ) ||
-        var_Get( p_this->p_libvlc, "vlm_mutex", &lockval ) )
-        return NULL;
-
-    vlc_mutex_lock( lockval.p_address );
+    vlc_mutex_lock( &vlm_mutex );
 
     p_vlm = *pp_vlm;
     if( p_vlm )
     {   /* VLM already exists */
         vlc_object_hold( p_vlm );
-        vlc_mutex_unlock( lockval.p_address );
+        vlc_mutex_unlock( &vlm_mutex );
         return p_vlm;
     }
 
@@ -139,7 +137,7 @@ vlm_t *__vlm_New ( vlc_object_t *p_this )
                                vlm_object_name );
     if( !p_vlm )
     {
-        vlc_mutex_unlock( lockval.p_address );
+        vlc_mutex_unlock( &vlm_mutex );
         return NULL;
     }
 
@@ -156,9 +154,12 @@ vlm_t *__vlm_New ( vlc_object_t *p_this )
     {
         vlc_mutex_destroy( &p_vlm->lock );
         vlc_object_release( p_vlm );
+        vlc_mutex_unlock( &vlm_mutex );
         return NULL;
     }
 
+    *pp_vlm = p_vlm; /* for future reference */
+
     /* Load our configuration file */
     psz_vlmconf = var_CreateGetString( p_vlm, "vlm-conf" );
     if( psz_vlmconf && *psz_vlmconf )
@@ -180,8 +181,7 @@ vlm_t *__vlm_New ( vlc_object_t *p_this )
     free( psz_vlmconf );
 
     vlc_object_set_destructor( p_vlm, (vlc_destructor_t)vlm_Destructor );
-    *pp_vlm = p_vlm; /* for future reference */
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( &vlm_mutex );
 
     return p_vlm;
 }
@@ -191,15 +191,12 @@ vlm_t *__vlm_New ( vlc_object_t *p_this )
  *****************************************************************************/
 void vlm_Delete( vlm_t *p_vlm )
 {
-    vlc_value_t lockval;
-
     /* vlm_Delete() is serialized against itself, and against vlm_New().
      * This way, vlm_Destructor () (called from vlc_objet_release() above)
      * is serialized against setting libvlc_priv->p_vlm from vlm_New(). */
-    var_Get( p_vlm->p_libvlc, "vlm_mutex", &lockval );
-    vlc_mutex_lock( lockval.p_address );
+    vlc_mutex_lock( &vlm_mutex );
     vlc_object_release( p_vlm );
-    vlc_mutex_unlock( lockval.p_address );
+    vlc_mutex_unlock( &vlm_mutex );
 }
 
 /*****************************************************************************
@@ -569,7 +566,7 @@ static int vlm_OnMediaUpdate( vlm_t *p_vlm, vlm_media_sys_t *p_media )
             if( asprintf( &psz_header, _("Media: %s"), p_cfg->psz_name ) == -1 )
                 psz_header = NULL;
 
-            p_input = input_Create( p_vlm->p_libvlc, p_media->vod.p_item, psz_header, NULL );
+            p_input = input_Create( p_vlm->p_vod, p_media->vod.p_item, psz_header, NULL );
             if( p_input )
             {
                 vlc_sem_t sem_preparse;
@@ -669,7 +666,6 @@ static int vlm_ControlMediaAdd( vlm_t *p_vlm, vlm_media_t *p_cfg, int64_t *p_id
         if( !p_vlm->p_vod->p_module )
         {
             msg_Err( p_vlm, "cannot find vod server" );
-            vlc_object_detach( p_vlm->p_vod );
             vlc_object_release( p_vlm->p_vod );
             p_vlm->p_vod = NULL;
             return VLC_EGENERIC;
@@ -730,15 +726,16 @@ static int vlm_ControlMediaDel( vlm_t *p_vlm, int64_t id )
 
     vlc_gc_decref( p_media->vod.p_item );
 
-    TAB_REMOVE( p_vlm->i_media, p_vlm->media, p_media );
+    if( p_media->vod.p_media )
+        p_vlm->p_vod->pf_media_del( p_vlm->p_vod, p_media->vod.p_media );
 
+    TAB_REMOVE( p_vlm->i_media, p_vlm->media, p_media );
     free( p_media );
 
     /* Check if we need to unload the VOD server */
     if( p_vlm->p_vod && p_vlm->i_vod <= 0 )
     {
         module_unneed( p_vlm->p_vod, p_vlm->p_vod->p_module );
-        vlc_object_detach( p_vlm->p_vod );
         vlc_object_release( p_vlm->p_vod );
         p_vlm->p_vod = NULL;
     }
@@ -935,7 +932,10 @@ static int vlm_ControlMediaInstanceStart( vlm_t *p_vlm, int64_t id, const char *
 
     if( asprintf( &psz_log, _("Media: %s"), p_media->cfg.psz_name ) != -1 )
     {
-        p_instance->p_input = input_Create( p_vlm->p_libvlc, p_instance->p_item,
+        vlc_object_t *p_parent = p_media->cfg.b_vod ?
+                                     VLC_OBJECT(p_vlm->p_vod) :
+                                     VLC_OBJECT(p_vlm->p_libvlc);
+        p_instance->p_input = input_Create( p_parent, p_instance->p_item,
                                             psz_log, p_instance->p_input_resource );
         if( p_instance->p_input )
         {
@@ -1062,7 +1062,8 @@ static int vlm_ControlMediaInstanceGets( vlm_t *p_vlm, int64_t id, vlm_media_ins
             p_idsc->d_position = var_GetFloat( p_instance->p_input, "position" );
             if( var_GetInteger( p_instance->p_input, "state" ) == PAUSE_S )
                 p_idsc->b_paused = true;
-            p_idsc->i_rate = var_GetInteger( p_instance->p_input, "rate" );
+            p_idsc->i_rate = INPUT_RATE_DEFAULT
+                             / var_GetFloat( p_instance->p_input, "rate" );
         }
 
         TAB_APPEND( i_idsc, pp_idsc, p_idsc );