]> 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 912a9f479752ac13d509dd745ad0e408a68aaf83..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 );
 }
 
@@ -621,12 +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_spu->p_text && p_spu->p_text->p_module )
                 {
                     p_region->i_align = p_subpic->i_flags;
-                    p_spu->p_text->pf_render_text( p_spu->p_text,
-                                                   p_region, p_region ); 
+
+                    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 );
@@ -969,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: