Skip to content

Commit

Permalink
Separated SRT and USF subtitles decoder.
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurent Aimar committed Apr 26, 2011
1 parent 675a76e commit a1d39b5
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 182 deletions.
4 changes: 2 additions & 2 deletions modules/codec/Modules.am
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ SOURCES_kate = kate.c
SOURCES_schroedinger = schroedinger.c
SOURCES_libass = libass.c
SOURCES_aes3 = aes3.c
SOURCES_subsdec = subsdec.c subsdec.h
SOURCES_subsusf = subsusf.c subsdec.h
SOURCES_subsdec = subsdec.c
SOURCES_subsusf = subsusf.c
SOURCES_t140 = t140.c
SOURCES_crystalhd = crystalhd.c

Expand Down
90 changes: 24 additions & 66 deletions modules/codec/subsdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,10 @@
# include "config.h"
#endif

#include "subsdec.h"
#include <vlc_common.h>
#include <vlc_plugin.h>

/*****************************************************************************
* Local prototypes
*****************************************************************************/
static int OpenDecoder ( vlc_object_t * );
static void CloseDecoder ( vlc_object_t * );

static subpicture_t *DecodeBlock ( decoder_t *, block_t ** );
static subpicture_t *ParseText ( decoder_t *, block_t * );
static char *StripTags ( char * );
static char *CreateHtmlSubtitle( int *pi_align, char * );

#include <vlc_codec.h>
#include <vlc_charset.h>

/*****************************************************************************
* Module descriptor.
Expand Down Expand Up @@ -178,6 +168,8 @@ static const char *const ppsz_justification_text[] = {
#define FORMAT_LONGTEXT N_("Some subtitle formats allow for text formatting. " \
"VLC partly implements this, but you can choose to disable all formatting.")

static int OpenDecoder ( vlc_object_t * );
static void CloseDecoder ( vlc_object_t * );

vlc_module_begin ()
set_shortname( N_("Subtitles"))
Expand All @@ -199,6 +191,25 @@ vlc_module_begin ()
false )
vlc_module_end ()

/*****************************************************************************
* Local prototypes
*****************************************************************************/
#define NO_BREAKING_SPACE "&#160;"

struct decoder_sys_t
{
int i_align; /* Subtitles alignment on the vout */

vlc_iconv_t iconv_handle; /* handle to iconv instance */
bool b_autodetect_utf8;
};


static subpicture_t *DecodeBlock ( decoder_t *, block_t ** );
static subpicture_t *ParseText ( decoder_t *, block_t * );
static char *StripTags ( char * );
static char *CreateHtmlSubtitle( int *pi_align, char * );

/*****************************************************************************
* OpenDecoder: probe the decoder and return score
*****************************************************************************
Expand Down Expand Up @@ -232,10 +243,6 @@ static int OpenDecoder( vlc_object_t *p_this )
p_sys->i_align = 0;
p_sys->iconv_handle = (vlc_iconv_t)-1;
p_sys->b_autodetect_utf8 = false;
p_sys->i_original_height = -1;
p_sys->i_original_width = -1;
TAB_INIT( p_sys->i_ssa_styles, p_sys->pp_ssa_styles );
TAB_INIT( p_sys->i_images, p_sys->pp_images );

char *psz_charset = NULL;

Expand Down Expand Up @@ -352,37 +359,6 @@ static void CloseDecoder( vlc_object_t *p_this )
if( p_sys->iconv_handle != (vlc_iconv_t)-1 )
vlc_iconv_close( p_sys->iconv_handle );

if( p_sys->pp_ssa_styles )
{
int i;
for( i = 0; i < p_sys->i_ssa_styles; i++ )
{
if( !p_sys->pp_ssa_styles[i] )
continue;

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 );
}
if( p_sys->pp_images )
{
int i;
for( i = 0; i < p_sys->i_images; i++ )
{
if( !p_sys->pp_images[i] )
continue;

if( p_sys->pp_images[i]->p_pic )
picture_Release( p_sys->pp_images[i]->p_pic );
free( p_sys->pp_images[i]->psz_filename );

free( p_sys->pp_images[i] );
}
TAB_CLEAN( p_sys->i_images, p_sys->pp_images );
}

free( p_sys );
}

Expand Down Expand Up @@ -517,24 +493,6 @@ static subpicture_t *ParseText( decoder_t *p_dec, block_t *p_block )
return p_spu;
}

char* GotoNextLine( char *psz_text )
{
char *p_newline = psz_text;

while( p_newline[0] != '\0' )
{
if( p_newline[0] == '\n' || p_newline[0] == '\r' )
{
p_newline++;
while( p_newline[0] == '\n' || p_newline[0] == '\r' )
p_newline++;
break;
}
else p_newline++;
}
return p_newline;
}

/* Function now handles tags with attribute values, and tries
* to deal with &' commands too. It no longer modifies the string
* in place, so that the original text can be reused
Expand Down
94 changes: 0 additions & 94 deletions modules/codec/subsdec.h

This file was deleted.

81 changes: 61 additions & 20 deletions modules/codec/subsusf.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,24 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <assert.h>

#include "subsdec.h"
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_modules.h>
#include <assert.h>
#include <vlc_codec.h>
#include <vlc_input.h>
#include <vlc_charset.h>
#include <vlc_image.h>
#include <vlc_xml.h>
#include <vlc_stream.h>

/*****************************************************************************
* Local prototypes
* Module descriptor.
*****************************************************************************/
static int OpenDecoder ( vlc_object_t * );
static void CloseDecoder ( vlc_object_t * );

static subpicture_t *DecodeBlock ( decoder_t *, block_t ** );
static char *CreatePlainText( char * );
static int ParseImageAttachments( decoder_t *p_dec );

static subpicture_t *ParseText ( decoder_t *, block_t * );
static void ParseUSFHeader( decoder_t * );
static subpicture_region_t *ParseUSFString( decoder_t *, char * );
static subpicture_region_t *LoadEmbeddedImage( decoder_t *p_dec, const char *psz_filename, int i_transparent_color );

/*****************************************************************************
* Module descriptor.
*****************************************************************************/

vlc_module_begin ()
set_capability( "decoder", 40 )
set_shortname( N_("USFSubs"))
Expand All @@ -58,6 +51,58 @@ vlc_module_begin ()
/* We inherit subsdec-align and subsdec-formatted from subsdec.c */
vlc_module_end ()


/*****************************************************************************
* Local prototypes
*****************************************************************************/
enum
{
ATTRIBUTE_ALIGNMENT = (1 << 0),
ATTRIBUTE_X = (1 << 1),
ATTRIBUTE_X_PERCENT = (1 << 2),
ATTRIBUTE_Y = (1 << 3),
ATTRIBUTE_Y_PERCENT = (1 << 4),
};

typedef struct
{
char *psz_filename;
picture_t *p_pic;
} image_attach_t;

typedef struct
{
char * psz_stylename; /* The name of the style, no comma's allowed */
text_style_t font_style;
int i_align;
int i_margin_h;
int i_margin_v;
int i_margin_percent_h;
int i_margin_percent_v;
} ssa_style_t;

struct decoder_sys_t
{
int i_original_height;
int i_original_width;
int i_align; /* Subtitles alignment on the vout */

ssa_style_t **pp_ssa_styles;
int i_ssa_styles;

image_attach_t **pp_images;
int i_images;
};

static subpicture_t *DecodeBlock ( decoder_t *, block_t ** );
static char *CreatePlainText( char * );
static int ParseImageAttachments( decoder_t *p_dec );

static subpicture_t *ParseText ( decoder_t *, block_t * );
static void ParseUSFHeader( decoder_t * );
static subpicture_region_t *ParseUSFString( decoder_t *, char * );
static subpicture_region_t *LoadEmbeddedImage( decoder_t *p_dec, const char *psz_filename, int i_transparent_color );

/*****************************************************************************
* OpenDecoder: probe the decoder and return score
*****************************************************************************
Expand All @@ -80,10 +125,6 @@ static int OpenDecoder( vlc_object_t *p_this )
p_dec->fmt_out.i_cat = SPU_ES;
p_dec->fmt_out.i_codec = 0;

/* Unused fields of p_sys - not needed for USF decoding */
p_sys->iconv_handle = (vlc_iconv_t)-1;
p_sys->b_autodetect_utf8 = false;

/* init of p_sys */
p_sys->i_align = 0;
p_sys->i_original_height = 0;
Expand Down

0 comments on commit a1d39b5

Please sign in to comment.