]> git.sesse.net Git - vlc/blobdiff - src/video_output/vout_subpictures.c
Use playlist_fetcher_t object instead of playlist one.
[vlc] / src / video_output / vout_subpictures.c
index f4b2ad544f9c90841e8d570c340af3e7462c0e52..1dc316ff4acad44e91874373a14d2dc3d887a161 100644 (file)
@@ -36,6 +36,7 @@
 #include <vlc_filter.h>
 #include <vlc_osd.h>
 #include "../libvlc.h"
+#include "vout_internal.h"
 
 #include <assert.h>
 #include <limits.h>
@@ -43,6 +44,9 @@
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
+/* Number of simultaneous subpictures */
+#define VOUT_MAX_SUBPICTURES (VOUT_MAX_PICTURES)
+
 #define VLC_FOURCC_YUVP VLC_FOURCC('Y','U','V','P')
 #define VLC_FOURCC_YUVA VLC_FOURCC('Y','U','V','A')
 #define VLC_FOURCC_RGBA VLC_FOURCC('R','G','B','A')
@@ -86,6 +90,7 @@ struct spu_private_t
     uint8_t palette[4][4];                               /**< forced palette */
 
     /* Subpiture filters */
+    char           *psz_chain_update;
     filter_chain_t *p_chain;
 
     /* */
@@ -156,7 +161,7 @@ static int  CropCallback( vlc_object_t *, char const *,
 
 static int SpuControl( spu_t *, int, va_list );
 
-static void SpuClearChannel( spu_t *p_spu, int i_channel, bool b_locked );
+static void SpuClearChannel( spu_t *p_spu, int i_channel );
 
 /* Buffer allocation for SPU filter (blend, scale, ...) */
 static subpicture_t *spu_new_buffer( filter_t * );
@@ -164,8 +169,6 @@ static void spu_del_buffer( filter_t *, subpicture_t * );
 static picture_t *spu_new_video_buffer( filter_t * );
 static void spu_del_video_buffer( filter_t *, picture_t * );
 
-static int spu_ParseChain( spu_t * );
-
 /* Buffer aloccation fir SUB filter */
 static int SubFilterCallback( vlc_object_t *, char const *,
                               vlc_value_t, vlc_value_t, void * );
@@ -217,6 +220,7 @@ spu_t *__spu_Create( vlc_object_t *p_this )
 
     vlc_object_attach( p_spu, p_this );
 
+    p_sys->psz_chain_update = NULL;
     p_sys->p_chain = filter_chain_New( p_spu, "sub filter", false,
                                        SubFilterAllocationInit,
                                        SubFilterAllocationClean,
@@ -246,27 +250,11 @@ int spu_Init( spu_t *p_spu )
 
     var_Create( p_spu, "sub-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
     var_AddCallback( p_spu, "sub-filter", SubFilterCallback, p_spu );
-
-    spu_ParseChain( p_spu );
+    var_TriggerCallback( p_spu, "sub-filter" );
 
     return VLC_SUCCESS;
 }
 
-int spu_ParseChain( spu_t *p_spu )
-{
-    char *psz_parser = var_GetString( p_spu, "sub-filter" );
-    int i_ret;
-
-    if( !psz_parser )
-        return VLC_EGENERIC;
-
-    i_ret = filter_chain_AppendFromString( p_spu->p->p_chain, psz_parser );
-
-    free( psz_parser );
-
-    return i_ret;
-}
-
 /**
  * Destroy the subpicture unit
  *
@@ -276,6 +264,8 @@ void spu_Destroy( spu_t *p_spu )
 {
     spu_private_t *p_sys = p_spu->p;
 
+    var_DelCallback( p_spu, "sub-filter", SubFilterCallback, p_spu );
+
     if( p_sys->p_blend )
         FilterRelease( p_sys->p_blend );
 
@@ -289,6 +279,7 @@ void spu_Destroy( spu_t *p_spu )
         FilterRelease( p_sys->p_scale );
 
     filter_chain_Delete( p_sys->p_chain );
+    free( p_sys->psz_chain_update );
 
     /* Destroy all remaining subpictures */
     SpuHeapClean( &p_sys->heap );
@@ -339,7 +330,7 @@ void spu_DisplaySubpicture( spu_t *p_spu, subpicture_t *p_subpic )
 
     /* DEFAULT_CHAN always reset itself */
     if( p_subpic->i_channel == DEFAULT_CHAN )
-        SpuClearChannel( p_spu, DEFAULT_CHAN, false );
+        SpuClearChannel( p_spu, DEFAULT_CHAN );
 
     /* p_private is for spu only and cannot be non NULL here */
     for( subpicture_region_t *r = p_subpic->p_region; r != NULL; r = r->p_next )
@@ -363,7 +354,7 @@ void spu_DisplaySubpicture( spu_t *p_spu, subpicture_t *p_subpic )
 void spu_RenderSubpictures( spu_t *p_spu,
                             picture_t *p_pic_dst, const video_format_t *p_fmt_dst,
                             subpicture_t *p_subpic_list,
-                            const video_format_t *p_fmt_src )
+                            const video_format_t *p_fmt_src, bool b_paused )
 {
     spu_private_t *p_sys = p_spu->p;
 
@@ -389,10 +380,10 @@ void spu_RenderSubpictures( spu_t *p_spu,
                 p_subpic = p_subpic->p_next )
     {
         /* */
-        if( p_subpic->pf_pre_render )
+        if( !b_paused && p_subpic->pf_pre_render )
             p_subpic->pf_pre_render( p_spu, p_subpic, p_fmt_dst );
 
-        if( p_subpic->pf_update_regions )
+        if( !b_paused && p_subpic->pf_update_regions )
         {
             video_format_t fmt_org = *p_fmt_dst;
             fmt_org.i_width =
@@ -560,6 +551,21 @@ subpicture_t *spu_SortSubpictures( spu_t *p_spu, mtime_t display_date,
     int i_channel;
     subpicture_t *p_subpic = NULL;
 
+    /* Update sub-filter chain */
+    vlc_mutex_lock( &p_sys->lock );
+    char *psz_chain_update = p_sys->psz_chain_update;
+    p_sys->psz_chain_update = NULL;
+    vlc_mutex_unlock( &p_sys->lock );
+
+    if( psz_chain_update )
+    {
+        filter_chain_Reset( p_sys->p_chain, NULL, NULL );
+
+        filter_chain_AppendFromString( p_spu->p->p_chain, psz_chain_update );
+
+        free( psz_chain_update );
+    }
+
     /* Run subpicture filters */
     filter_chain_SubFilter( p_sys->p_chain, display_date );
 
@@ -655,6 +661,27 @@ subpicture_t *spu_SortSubpictures( spu_t *p_spu, mtime_t display_date,
     return p_subpic;
 }
 
+void spu_OffsetSubtitleDate( spu_t *p_spu, mtime_t i_duration )
+{
+    spu_private_t *p_sys = p_spu->p;
+
+    vlc_mutex_lock( &p_sys->lock );
+    for( int i = 0; i < VOUT_MAX_SUBPICTURES; i++ )
+    {
+        spu_heap_entry_t *p_entry = &p_sys->heap.p_entry[i];
+        subpicture_t *p_current = p_entry->p_subpicture;
+
+        if( p_current && p_current->b_subtitle )
+        {
+            if( p_current->i_start > 0 )
+                p_current->i_start += i_duration;
+            if( p_current->i_stop > 0 )
+                p_current->i_stop += i_duration;
+        }
+    }
+    vlc_mutex_unlock( &p_sys->lock );
+}
+
 /*****************************************************************************
  * subpicture_t allocation
  *****************************************************************************/
@@ -924,7 +951,7 @@ static void SpuRenderUpdateBlend( spu_t *p_spu, int i_out_width, int i_out_heigh
 
     /* */
     if( !p_blend->p_module )
-        p_blend->p_module = module_need( p_blend, "video blending", 0, 0 );
+        p_blend->p_module = module_need( p_blend, "video blending", NULL, false );
 }
 static void SpuRenderCreateAndLoadText( spu_t *p_spu )
 {
@@ -996,7 +1023,7 @@ static filter_t *CreateAndLoadScale( vlc_object_t *p_obj,
     p_scale->pf_vout_buffer_del = spu_del_video_buffer;
 
     vlc_object_attach( p_scale, p_obj );
-    p_scale->p_module = module_need( p_scale, "video filter2", 0, 0 );
+    p_scale->p_module = module_need( p_scale, "video filter2", NULL, false );
 
     return p_scale;
 }
@@ -1439,7 +1466,7 @@ static void SpuRenderRegion( spu_t *p_spu,
         }
 
         /* Scale if needed into cache */
-        if( !p_region->p_private )
+        if( !p_region->p_private && i_dst_width > 0 && i_dst_height > 0 )
         {
             filter_t *p_scale = p_sys->p_scale;
 
@@ -1579,8 +1606,11 @@ exit:
          * pre-rendered state, so the next time through everything is
          * calculated again.
          */
-        picture_Release( p_region->p_picture );
-        p_region->p_picture = NULL;
+        if( p_region->p_picture )
+        {
+            picture_Release( p_region->p_picture );
+            p_region->p_picture = NULL;
+        }
         if( p_region->p_private )
         {
             SpuRegionPrivateDelete( p_region->p_private );
@@ -1633,30 +1663,28 @@ static int SubpictureCmp( const void *s0, const void *s1 )
  * This function destroys the subpictures which belong to the spu channel
  * corresponding to i_channel_id.
  *****************************************************************************/
-static void SpuClearChannel( spu_t *p_spu, int i_channel, bool b_locked )
+static void SpuClearChannel( spu_t *p_spu, int i_channel )
 {
     spu_private_t *p_sys = p_spu->p;
     int          i_subpic;                               /* subpicture index */
 
-    if( !b_locked )
-        vlc_mutex_lock( &p_sys->lock );
-
-    vlc_assert_locked( &p_sys->lock );
+    vlc_mutex_lock( &p_sys->lock );
 
     for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
     {
         spu_heap_entry_t *p_entry = &p_sys->heap.p_entry[i_subpic];
         subpicture_t *p_subpic = p_entry->p_subpicture;
 
-        if( !p_subpic || p_subpic->i_channel != i_channel )
+        if( !p_subpic )
+            continue;
+        if( p_subpic->i_channel != i_channel && ( i_channel != -1 || p_subpic->i_channel == DEFAULT_CHAN ) )
             continue;
 
         /* You cannot delete subpicture outside of spu_SortSubpictures */
         p_entry->b_reject = true;
     }
 
-    if( !b_locked )
-        vlc_mutex_unlock( &p_sys->lock );
+    vlc_mutex_unlock( &p_sys->lock );
 }
 
 /*****************************************************************************
@@ -1679,7 +1707,7 @@ static int SpuControl( spu_t *p_spu, int i_query, va_list args )
 
     case SPU_CHANNEL_CLEAR:
         i = (int)va_arg( args, int );
-        SpuClearChannel( p_spu, i, false );
+        SpuClearChannel( p_spu, i );
         break;
 
     default:
@@ -1820,7 +1848,7 @@ static void SubFilterAllocationClean( filter_t *p_filter )
 {
     filter_owner_sys_t *p_sys = p_filter->p_owner;
 
-    SpuClearChannel( p_sys->p_spu, p_sys->i_channel, true );
+    SpuClearChannel( p_sys->p_spu, p_sys->i_channel );
     free( p_filter->p_owner );
 }
 
@@ -1830,12 +1858,13 @@ static int SubFilterCallback( vlc_object_t *p_object, char const *psz_var,
     spu_t *p_spu = p_data;
     spu_private_t *p_sys = p_spu->p;
 
-    VLC_UNUSED(p_object); VLC_UNUSED(oldval);
-    VLC_UNUSED(newval); VLC_UNUSED(psz_var);
+    VLC_UNUSED(p_object); VLC_UNUSED(oldval); VLC_UNUSED(psz_var);
 
     vlc_mutex_lock( &p_sys->lock );
-    filter_chain_Reset( p_sys->p_chain, NULL, NULL );
-    spu_ParseChain( p_spu );
+
+    free( p_sys->psz_chain_update );
+    p_sys->psz_chain_update = strdup( newval.psz_string );
+
     vlc_mutex_unlock( &p_sys->lock );
     return VLC_SUCCESS;
 }