Commit a1d39b55 authored by Laurent Aimar's avatar Laurent Aimar

Separated SRT and USF subtitles decoder.

parent 675a76e9
......@@ -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
......
......@@ -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.
......@@ -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"))
......@@ -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
*****************************************************************************
......@@ -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;
......@@ -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 );
}
......@@ -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
......
/*****************************************************************************
* subsdec.h : text/ASS-SSA/USF subtitles headers
*****************************************************************************
* Copyright (C) 2000-2006 the VideoLAN team
* $Id$
*
* Authors: Gildas Bazin <gbazin@videolan.org>
* Samuel Hocevar <sam@zoy.org>
* Derk-Jan Hartman <hartman at videolan dot org>
* Bernie Purcell <bitmap@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef SUBSDEC_HEADER_H
#define SUBSDEC_HEADER_H
#include <vlc_common.h>
#include <vlc_codec.h>
#include <vlc_input.h>
#include <vlc_filter.h>
#include <vlc_image.h>
#include <vlc_charset.h>
#include <vlc_stream.h>
#include <vlc_xml.h>
#include <string.h>
#define DEFAULT_NAME "Default"
#define MAX_LINE 8192
#define NO_BREAKING_SPACE "&#160;"
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;
/*****************************************************************************
* decoder_sys_t : decoder descriptor
*****************************************************************************/
struct decoder_sys_t
{
int i_original_height;
int i_original_width;
int i_align; /* Subtitles alignment on the vout */
vlc_iconv_t iconv_handle; /* handle to iconv instance */
bool b_autodetect_utf8;
ssa_style_t **pp_ssa_styles;
int i_ssa_styles;
image_attach_t **pp_images;
int i_images;
};
char *GotoNextLine( char *psz_text );
#endif
......@@ -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"))
......@@ -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
*****************************************************************************
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment