]> git.sesse.net Git - vlc/blobdiff - modules/codec/subtitles/subsusf.c
Fixed subtitle duration when rate != default.
[vlc] / modules / codec / subtitles / subsusf.c
index 82ad2d10a13df03c168c78252c76fecc45d429e6..6e074d712d0ca362fd15a06ade8cbb24201ced1c 100644 (file)
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include "subsdec.h"
+#include <vlc_plugin.h>
 
 /*****************************************************************************
  * Local prototypes
@@ -44,6 +48,8 @@ static subpicture_region_t *LoadEmbeddedImage( decoder_t *p_dec, subpicture_t *p
 
 vlc_module_begin();
     set_capability( "decoder", 40 );
+    set_shortname( N_("USFSubs"));
+    set_description( N_("USF subtitles decoder") );
     set_callbacks( OpenDecoder, CloseDecoder );
     set_category( CAT_INPUT );
     set_subcategory( SUBCAT_INPUT_SCODEC );
@@ -73,14 +79,13 @@ static int OpenDecoder( vlc_object_t *p_this )
     if( ( p_dec->p_sys = p_sys =
           (decoder_sys_t *)calloc(1, sizeof(decoder_sys_t)) ) == NULL )
     {
-        msg_Err( p_dec, "out of memory" );
         return VLC_ENOMEM;
     }
 
     /* Unused fields of p_sys - not needed for USF decoding */
-    p_sys->b_ass = VLC_FALSE;
+    p_sys->b_ass = false;
     p_sys->iconv_handle = (vlc_iconv_t)-1;
-    p_sys->b_autodetect_utf8 = VLC_FALSE;
+    p_sys->b_autodetect_utf8 = false;
 
     /* init of p_sys */
     p_sys->i_align = 0;
@@ -113,13 +118,19 @@ static int OpenDecoder( vlc_object_t *p_this )
  ****************************************************************************/
 static subpicture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 {
-    subpicture_t *p_spu = NULL;
+    subpicture_t *p_spu;
+    block_t *p_block;
+
+    if( !pp_block || *pp_block == NULL )
+        return NULL;
 
-    if( !pp_block || *pp_block == NULL ) return NULL;
+    p_block = *pp_block;
+    if( p_block->i_rate != 0 )
+        p_block->i_length = p_block->i_length * p_block->i_rate / INPUT_RATE_DEFAULT;
 
-    p_spu = ParseText( p_dec, *pp_block );
+    p_spu = ParseText( p_dec, p_block );
 
-    block_Release( *pp_block );
+    block_Release( p_block );
     *pp_block = NULL;
 
     return p_spu;
@@ -141,12 +152,9 @@ static void CloseDecoder( vlc_object_t *p_this )
             if( !p_sys->pp_ssa_styles[i] )
                 continue;
 
-            if( p_sys->pp_ssa_styles[i]->psz_stylename )
-                free( p_sys->pp_ssa_styles[i]->psz_stylename );
-            if( p_sys->pp_ssa_styles[i]->font_style.psz_fontname )
-                free( p_sys->pp_ssa_styles[i]->font_style.psz_fontname );
-            if( p_sys->pp_ssa_styles[i] )
-                free( p_sys->pp_ssa_styles[i] );
+            free( p_sys->pp_ssa_styles[i]->psz_stylename );
+            free( p_sys->pp_ssa_styles[i]->font_style.psz_fontname );
+            free( p_sys->pp_ssa_styles[i] );
         }
         TAB_CLEAN( p_sys->i_ssa_styles, p_sys->pp_ssa_styles );
     }
@@ -159,9 +167,8 @@ static void CloseDecoder( vlc_object_t *p_this )
                 continue;
 
             if( p_sys->pp_images[i]->p_pic )
-                p_sys->pp_images[i]->p_pic->pf_release( p_sys->pp_images[i]->p_pic );
-            if( p_sys->pp_images[i]->psz_filename )
-                free( p_sys->pp_images[i]->psz_filename );
+                picture_Release( p_sys->pp_images[i]->p_pic );
+            free( p_sys->pp_images[i]->psz_filename );
 
             free( p_sys->pp_images[i] );
         }
@@ -214,11 +221,11 @@ static subpicture_t *ParseText( decoder_t *p_dec, block_t *p_block )
     if( !p_spu )
     {
         msg_Warn( p_dec, "can't get spu buffer" );
-        if( psz_subtitle ) free( psz_subtitle );
+        free( psz_subtitle );
         return NULL;
     }
 
-    p_spu->b_pausable = VLC_TRUE;
+    p_spu->b_pausable = true;
 
     /* Decode USF strings */
     p_spu->p_region = ParseUSFString( p_dec, psz_subtitle, p_spu );
@@ -226,11 +233,11 @@ static subpicture_t *ParseText( decoder_t *p_dec, block_t *p_block )
     p_spu->i_start = p_block->i_pts;
     p_spu->i_stop = p_block->i_pts + p_block->i_length;
     p_spu->b_ephemer = (p_block->i_length == 0);
-    p_spu->b_absolute = VLC_FALSE;
+    p_spu->b_absolute = false;
     p_spu->i_original_picture_width = p_sys->i_original_width;
     p_spu->i_original_picture_height = p_sys->i_original_height;
 
-    if( psz_subtitle ) free( psz_subtitle );
+    free( psz_subtitle );
 
     return p_spu;
 }
@@ -398,7 +405,6 @@ static subpicture_region_t *CreateTextRegion( decoder_t *p_dec,
         p_text_region->psz_html = strndup( psz_subtitle, i_len );
         if( ! p_text_region->psz_html )
         {
-            msg_Err( p_dec, "out of memory" );
             p_spu->pf_destroy_region( VLC_OBJECT(p_dec), p_text_region );
             return NULL;
         }
@@ -632,8 +638,8 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
                             else if( !strcasecmp( "y", psz_name ) )
                                 p_sys->i_original_height = atoi( psz_value );
                         }
-                        if( psz_name )  free( psz_name );
-                        if( psz_value ) free( psz_value );
+                        free( psz_name );
+                        free( psz_value );
                     }
                 }
                 else if( !strcasecmp( "styles", psz_node ) && (i_style_level == 0) )
@@ -647,7 +653,6 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
                     p_style = calloc( 1, sizeof(ssa_style_t) );
                     if( ! p_style )
                     {
-                        msg_Err( p_dec, "out of memory" );
                         free( psz_node );
                         break;
                     }
@@ -679,8 +684,8 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
                             if( !strcasecmp( "name", psz_name ) )
                                 p_style->psz_stylename = strdup( psz_value);
                         }
-                        if( psz_name )  free( psz_name );
-                        if( psz_value ) free( psz_value );
+                        free( psz_name );
+                        free( psz_value );
                     }
                 }
                 else if( !strcasecmp( "fontstyle", psz_node ) && (i_style_level == 2) )
@@ -694,8 +699,7 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
                         {
                             if( !strcasecmp( "face", psz_name ) )
                             {
-                                if( p_style->font_style.psz_fontname )
-                                    free( p_style->font_style.psz_fontname );
+                                free( p_style->font_style.psz_fontname );
                                 p_style->font_style.psz_fontname = strdup( psz_value );
                             }
                             else if( !strcasecmp( "size", psz_name ) )
@@ -785,8 +789,8 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
                                 p_style->font_style.i_spacing = atoi( psz_value );
                             }
                         }
-                        if( psz_name )  free( psz_name );
-                        if( psz_value ) free( psz_value );
+                        free( psz_name );
+                        free( psz_value );
                     }
                 }
                 else if( !strcasecmp( "position", psz_node ) && (i_style_level == 2) )
@@ -846,8 +850,8 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
                                 }
                             }
                         }
-                        if( psz_name )  free( psz_name );
-                        if( psz_value ) free( psz_value );
+                        free( psz_name );
+                        free( psz_value );
                     }
                 }
 
@@ -855,7 +859,7 @@ static void ParseUSFHeaderTags( decoder_t *p_dec, xml_reader_t *p_xml_reader )
                 break;
         }
     }
-    if( p_style ) free( p_style );
+    free( p_style );
 }
 
 
@@ -1031,7 +1035,7 @@ static void ParseUSFHeader( decoder_t *p_dec )
     p_sub = stream_MemoryNew( VLC_OBJECT(p_dec),
                               p_dec->fmt_in.p_extra,
                               p_dec->fmt_in.i_extra,
-                              VLC_TRUE );
+                              true );
     if( !p_sub )
         return;