]> git.sesse.net Git - vlc/blobdiff - src/video_output/vout_subpictures.c
MKV USF subtitles support and other Subtitles improvements.
[vlc] / src / video_output / vout_subpictures.c
index 6bc5039ace5157d4bd29c6a9ca03f03ef16cbcf9..d16716859575539d79a6fd0cdc4ca7b8a4ba1c70 100644 (file)
 #include <string.h>                                            /* strerror() */
 
 #include <vlc/vlc.h>
-
-#include "vlc_block.h"
-#include "vlc_video.h"
-#include "video_output.h"
-#include "vlc_spu.h"
-#include "vlc_filter.h"
+#include <vlc_vout.h>
+#include <vlc_block.h>
+#include <vlc_filter.h>
+#include <vlc_osd.h>
 
 /*****************************************************************************
  * Local prototypes
@@ -98,7 +96,7 @@ spu_t *__spu_Create( vlc_object_t *p_this )
  */
 int spu_Init( spu_t *p_spu )
 {
-    char *psz_filter, *psz_filter_orig;
+    char *psz_parser;
     vlc_value_t val;
 
     /* If the user requested a sub margin, we force the position. */
@@ -108,21 +106,27 @@ int spu_Init( spu_t *p_spu )
 
     var_Create( p_spu, "sub-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
     var_Get( p_spu, "sub-filter", &val );
-    psz_filter = psz_filter_orig = val.psz_string;
-    while( psz_filter && *psz_filter )
+
+    psz_parser = val.psz_string;
+
+    while( psz_parser && *psz_parser )
     {
-        char *psz_parser = strchr( psz_filter, ':' );
+        config_chain_t *p_cfg; /* Do we ever need to free this ? */
+        char *psz_name;
+
+        psz_parser = config_ChainCreate( &psz_name, &p_cfg, psz_parser );
 
-        if( psz_parser ) *psz_parser++ = 0;
+        msg_Dbg( p_spu, "adding sub-filter: %s", psz_name );
 
         p_spu->pp_filter[p_spu->i_filter] =
             vlc_object_create( p_spu, VLC_OBJECT_FILTER );
         vlc_object_attach( p_spu->pp_filter[p_spu->i_filter], p_spu );
         p_spu->pp_filter[p_spu->i_filter]->pf_sub_buffer_new = sub_new_buffer;
         p_spu->pp_filter[p_spu->i_filter]->pf_sub_buffer_del = sub_del_buffer;
+        p_spu->pp_filter[p_spu->i_filter]->p_cfg = p_cfg;;
         p_spu->pp_filter[p_spu->i_filter]->p_module =
             module_Need( p_spu->pp_filter[p_spu->i_filter],
-                         "sub filter", psz_filter, 0 );
+                         "sub filter", psz_name, 0 );
         if( p_spu->pp_filter[p_spu->i_filter]->p_module )
         {
             filter_owner_sys_t *p_sys = malloc( sizeof(filter_owner_sys_t) );
@@ -143,9 +147,9 @@ int spu_Init( spu_t *p_spu )
             msg_Dbg( p_spu, "can't add anymore filters" );
         }
 
-        psz_filter = psz_parser;
+        free( psz_name );
     }
-    if( psz_filter_orig ) free( psz_filter_orig );
+    if( val.psz_string ) free( val.psz_string );
 
     return VLC_EGENERIC;
 }
@@ -325,6 +329,10 @@ void __spu_DestroyRegion( vlc_object_t *p_this, subpicture_region_t *p_region )
         p_region->picture.pf_release( &p_region->picture );
     if( p_region->fmt.p_palette ) free( p_region->fmt.p_palette );
     if( p_region->p_cache ) __spu_DestroyRegion( p_this, p_region->p_cache );
+
+    if( p_region->psz_text )
+        free( p_region->psz_text );
+    //free( p_region->p_style ); FIXME --fenrir plugin does not allocate the memory for it. I think it might lead to segfault, video renderer can live longer than the decoder
     free( p_region );
 }
 
@@ -401,6 +409,7 @@ subpicture_t *spu_CreateSubpicture( spu_t *p_spu )
     memset( p_subpic, 0, sizeof(subpicture_t) );
     p_subpic->i_status   = RESERVED_SUBPICTURE;
     p_subpic->b_absolute = VLC_TRUE;
+    p_subpic->b_pausable = VLC_FALSE;
     p_subpic->b_fade     = VLC_FALSE;
     p_subpic->i_alpha    = 0xFF;
     p_subpic->p_region   = 0;
@@ -412,7 +421,7 @@ subpicture_t *spu_CreateSubpicture( spu_t *p_spu )
     p_subpic->pf_create_region = __spu_CreateRegion;
     p_subpic->pf_make_region = __spu_MakeRegion;
     p_subpic->pf_destroy_region = __spu_DestroyRegion;
-    
+
     return p_subpic;
 }
 
@@ -497,7 +506,7 @@ void spu_RenderSubpictures( spu_t *p_spu, video_format_t *p_fmt,
         }
 
         /* Load the text rendering module */
-        if( !p_spu->p_text && p_region )
+        if( !p_spu->p_text && p_region && p_region->fmt.i_chroma == VLC_FOURCC('T','E','X','T') )
         {
             char *psz_modulename = NULL;
 
@@ -527,7 +536,7 @@ void spu_RenderSubpictures( spu_t *p_spu, video_format_t *p_fmt,
             }
             if( psz_modulename ) free( psz_modulename );
         }
-        else if( p_region )
+        if( p_spu->p_text )
         {
             if( p_subpic->i_original_picture_height > 0 &&
                 p_subpic->i_original_picture_width  > 0 )
@@ -620,13 +629,20 @@ void spu_RenderSubpictures( spu_t *p_spu, video_format_t *p_fmt,
 
             if( p_region->fmt.i_chroma == VLC_FOURCC('T','E','X','T') )
             {
-                if( p_spu->p_text && p_spu->p_text->p_module &&
-                    p_spu->p_text->pf_render_text )
-                {/*
-                    if( p_region->p_style )
-                        p_region->p_style->i_text_align = p_subpic->i_flags & 0x3; */
-                    p_spu->p_text->pf_render_text( p_spu->p_text,
-                                                   p_region, p_region ); 
+                if( p_spu->p_text && p_spu->p_text->p_module )
+                {
+                    p_region->i_align = p_subpic->i_flags;
+
+                    if( p_spu->p_text->pf_render_html && p_region->psz_html )
+                    {
+                        p_spu->p_text->pf_render_html( p_spu->p_text,
+                                                       p_region, p_region );
+                    }
+                    else if( p_spu->p_text->pf_render_text )
+                    {
+                        p_spu->p_text->pf_render_text( p_spu->p_text,
+                                                       p_region, p_region ); 
+                    }
                 }
             }
 
@@ -727,6 +743,9 @@ void spu_RenderSubpictures( spu_t *p_spu, video_format_t *p_fmt,
                     p_subpic->i_y * i_scale_height / 1000;
 
             }
+            
+            i_x_offset = __MAX( i_x_offset, 0 );
+            i_y_offset = __MAX( i_y_offset, 0 );
 
             if( p_spu->i_margin != 0 && p_spu->b_force_crop == VLC_FALSE )
             {
@@ -800,6 +819,9 @@ void spu_RenderSubpictures( spu_t *p_spu, video_format_t *p_fmt,
                 }
             }
 
+            i_x_offset = __MAX( i_x_offset, 0 );
+            i_y_offset = __MAX( i_y_offset, 0 );
+
             p_spu->p_blend->pf_video_blend( p_spu->p_blend, p_pic_dst,
                 p_pic_src, &p_region->picture, i_x_offset, i_y_offset,
                 i_fade_alpha * p_subpic->i_alpha / 255 );
@@ -824,7 +846,8 @@ void spu_RenderSubpictures( spu_t *p_spu, video_format_t *p_fmt,
  * to be removed if a newer one is available), which makes it a lot
  * more difficult to guess if a subpicture has to be rendered or not.
  *****************************************************************************/
-subpicture_t *spu_SortSubpictures( spu_t *p_spu, mtime_t display_date )
+subpicture_t *spu_SortSubpictures( spu_t *p_spu, mtime_t display_date,
+                                   vlc_bool_t b_paused )
 {
     int i_index, i_channel;
     subpicture_t *p_subpic = NULL;
@@ -870,7 +893,9 @@ subpicture_t *spu_SortSubpictures( spu_t *p_spu, mtime_t display_date )
             if( display_date > p_spu->p_subpicture[i_index].i_stop &&
                 ( !p_spu->p_subpicture[i_index].b_ephemer ||
                   p_spu->p_subpicture[i_index].i_stop >
-                  p_spu->p_subpicture[i_index].i_start ) )
+                  p_spu->p_subpicture[i_index].i_start ) &&
+                !( p_spu->p_subpicture[i_index].b_pausable &&
+                   b_paused ) )
             {
                 /* Too late, destroy the subpic */
                 spu_DestroySubpicture( p_spu, &p_spu->p_subpicture[i_index] );
@@ -966,8 +991,6 @@ static int spu_vaControlDefault( spu_t *p_spu, int i_query, va_list args )
     case SPU_CHANNEL_REGISTER:
         pi = (int *)va_arg( args, int * );
         if( pi ) *pi = p_spu->i_channel++;
-        msg_Dbg( p_spu, "Registering subpicture channel, ID: %i",
-                 p_spu->i_channel - 1 );
         break;
 
     case SPU_CHANNEL_CLEAR: