Commit 354c7ab9 authored by Derk-Jan Hartman's avatar Derk-Jan Hartman

Please test if this has any regressions

* include/codecs.h:
  - created a subtitle_data_t to be used by subtitle demuxers
    and decoders to pass information.
  - ToDo: access/dvd/es.c and spudec need to be fixed to use the palette field
    of this new struct.
* modules/codec/subsdec.c:
  - moved the decoding of ssa textlines to here.
  - ToDo: support for any tags is lacking atm., but now possible.
* modules/demux/mkv.cpp:
  - ssa is now passed undecoded to ssa subsdec.
  - ssa headers are passed to ssa subsdec via subtitle_data_t
  - ToDo: decode idx header info and fill the subtitle_data_t
  - ToDo: support for compressed vobsubs.
* modules/demux/util/sub.?:
  - moved ssa decoding out of here.
  - ToDo: add support for multiple tracks
  - ToDo: implement reading vobsub .sub files (not .idx)
parent ed6c9819
......@@ -2,7 +2,7 @@
* codecs.h: codec related structures needed by the demuxers and decoders
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
* $Id: codecs.h,v 1.6 2003/10/19 23:12:16 hartman Exp $
* $Id: codecs.h,v 1.7 2003/11/05 00:17:50 hartman Exp $
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
*
......@@ -142,6 +142,31 @@ static inline void wf_tag_to_fourcc( uint16_t i_tag,
}
}
/**
* Structure to hold information concerning subtitles.
* Used between demuxers and decoders of subtitles.
*/
typedef struct es_sys_t
{
char *psz_header; /* for 'ssa ' and 'subt' */
/* for spudec */
unsigned int i_orig_height;
unsigned int i_orig_width;
unsigned int i_origin_x;
unsigned int i_origin_y;
unsigned int i_scale_h;
unsigned int i_scale_v;
unsigned int i_alpha;
vlc_bool_t b_smooth;
mtime_t i_fade_in;
mtime_t i_fade_out;
unsigned int i_align;
mtime_t i_time_offset;
vlc_bool_t b_forced_subs;
unsigned int palette[16];
unsigned int colors[4];
} subtitle_data_t;
#endif /* "codecs.h" */
......@@ -2,7 +2,7 @@
* subsdec.c : text subtitles decoder
*****************************************************************************
* Copyright (C) 2000-2001 VideoLAN
* $Id: subsdec.c,v 1.3 2003/10/11 14:08:58 hartman Exp $
* $Id: subsdec.c,v 1.4 2003/11/05 00:17:50 hartman Exp $
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
* Samuel Hocevar <sam@zoy.org>
......@@ -32,6 +32,7 @@
#include <vlc/vout.h>
#include <vlc/decoder.h>
#include <osd.h>
#include <codecs.h>
#if defined(HAVE_ICONV)
#include <iconv.h>
......@@ -118,7 +119,8 @@ static int OpenDecoder( vlc_object_t *p_this )
{
decoder_t *p_dec = (decoder_t*)p_this;
if( p_dec->p_fifo->i_fourcc != VLC_FOURCC('s','u','b','t') )
if( p_dec->p_fifo->i_fourcc != VLC_FOURCC('s','u','b','t') &&
p_dec->p_fifo->i_fourcc != VLC_FOURCC('s','s','a',' ') )
{
return VLC_EGENERIC;
}
......@@ -144,6 +146,7 @@ static int OpenDecoder( vlc_object_t *p_this )
static int InitDecoder( decoder_t *p_dec )
{
decoder_sys_t *p_sys = p_dec->p_sys;
subtitle_data_t *p_demux_data = (subtitle_data_t *)p_dec->p_fifo->p_demux_data;
vlc_value_t val;
var_Create( p_dec, "subsdec-align", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
......@@ -176,6 +179,11 @@ static int InitDecoder( decoder_t *p_dec )
msg_Dbg( p_dec, "No iconv support available" );
#endif
#if 1
if( p_demux_data )
msg_Dbg( p_dec, p_demux_data->psz_header );
#endif
return VLC_SUCCESS;
}
......@@ -250,6 +258,7 @@ static void ParseText( decoder_t *p_dec, block_t *p_block,
{
decoder_sys_t *p_sys = p_dec->p_sys;
char *psz_subtitle;
int i_align_h, i_align_v;
/* We cannot display a subpicture with no date */
if( p_block->i_pts == 0 )
......@@ -268,6 +277,9 @@ static void ParseText( decoder_t *p_dec, block_t *p_block,
/* Should be resiliant against bad subtitles */
psz_subtitle = strndup( p_block->p_buffer, p_block->i_buffer );
i_align_h = p_sys->i_align ? 20 : 0;
i_align_v = 10;
#if defined(HAVE_ICONV)
if( p_sys->iconv_handle != (iconv_t)-1 )
{
......@@ -297,9 +309,64 @@ static void ParseText( decoder_t *p_dec, block_t *p_block,
}
#endif
if( p_dec->p_fifo->i_fourcc == VLC_FOURCC('s','s','a',' ') )
{
/* Decode SSA strings */
/* We expect: ReadOrder, Layer, Style, Name, MarginL, MarginR, MarginV, Effect, Text */
char *psz_new_subtitle;
char *psz_buffer_sub;
int i_comma;
int i_text;
psz_buffer_sub = psz_subtitle;
for( ;; )
{
i_comma = 0;
while( i_comma < 8 &&
*psz_buffer_sub != '\0' )
{
if( *psz_buffer_sub == ',' )
{
i_comma++;
}
psz_buffer_sub++;
}
psz_new_subtitle = malloc( strlen( psz_buffer_sub ) + 1);
i_text = 0;
while( psz_buffer_sub[0] != '\0' )
{
if( psz_buffer_sub[0] == '\\' && ( psz_buffer_sub[1] =='n' || psz_buffer_sub[1] =='N' ) )
{
psz_new_subtitle[i_text] = '\n';
i_text++;
psz_buffer_sub += 2;
}
else if( psz_buffer_sub[0] == '{' && psz_buffer_sub[1] == '\\' )
{
/* SSA control code */
while( psz_buffer_sub[0] != '\0' && psz_buffer_sub[0] != '}' )
{
psz_buffer_sub++;
}
psz_buffer_sub++;
}
else
{
psz_new_subtitle[i_text] = psz_buffer_sub[0];
i_text++;
psz_buffer_sub++;
}
}
psz_new_subtitle[i_text] = '\0';
free( psz_subtitle );
psz_subtitle = psz_new_subtitle;
break;
}
}
vout_ShowTextAbsolute( p_vout, psz_subtitle, NULL,
OSD_ALIGN_BOTTOM | p_sys->i_align,
p_sys->i_align ? 20 : 0, 10,
i_align_h, i_align_v,
p_block->i_pts, p_block->i_dts );
free( psz_subtitle );
......
......@@ -2,7 +2,7 @@
* mkv.cpp : matroska demuxer
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: mkv.cpp,v 1.35 2003/11/02 18:03:45 sigmunau Exp $
* $Id: mkv.cpp,v 1.36 2003/11/05 00:17:50 hartman Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
......@@ -1248,7 +1248,9 @@ static int Open( vlc_object_t * p_this )
!strcmp( tk.psz_codec, "S_SSA" ) ||
!strcmp( tk.psz_codec, "S_ASS" ))
{
tk.i_codec = VLC_FOURCC( 's', 'u', 'b', 't' );
tk.i_codec = VLC_FOURCC( 's', 's', 'a', ' ' );
tk.p_es->p_demux_data = malloc( sizeof( subtitle_data_t ) );
tk.p_es->p_demux_data->psz_header = strdup( (char *)tk.p_extra_data );
}
else if( !strcmp( tk.psz_codec, "S_VOBSUB" ) )
{
......@@ -1627,8 +1629,7 @@ static void BlockDecode( input_thread_t *p_input, KaxBlock *block, mtime_t i_pts
{
if( i_duration > 0 )
{
/* FIXME not sure about that */
p_pes->i_dts += i_duration * 1000;// * (mtime_t) 1000 / p_sys->i_timescale;
p_pes->i_dts += i_duration * 1000;
}
else
{
......@@ -1639,49 +1640,6 @@ static void BlockDecode( input_thread_t *p_input, KaxBlock *block, mtime_t i_pts
{
p_pes->p_first->p_payload_end[0] = '\0';
}
if( !strcmp( tk.psz_codec, "S_TEXT/SSA" ) ||
!strcmp( tk.psz_codec, "S_SSA" ) ||
!strcmp( tk.psz_codec, "S_ASS" ))
{
/* remove all fields before text for now */
char *start = (char*)p_pes->p_first->p_payload_start;
char *src, *dst;
int i_comma = 0;
while( *start && i_comma < 8 )
{
if( *start++ == ',' )
{
i_comma++;
}
}
memmove( p_pes->p_first->p_payload_start, start,
strlen( start) + 1 );
/* Fix the SSA string */
src = dst = (char*)p_pes->p_first->p_payload_start;
while( *src )
{
if( src[0] == '\\' && ( src[1] == 'n' || src[1] == 'N' ) )
{
dst[0] = '\n'; dst++; src += 2;
}
else if( src[0] == '{' && src[1] == '\\' )
{
while( *src && src[0] != '}' )
{
src++;
}
src++;
}
else
{
dst[0] = src[0]; dst++; src++;
}
}
dst++;
dst[0] = '\0';
}
}
input_DecodePES( tk.p_es->p_decoder_fifo, p_pes );
......
This diff is collapsed.
......@@ -2,7 +2,7 @@
* sub.h
*****************************************************************************
* Copyright (C) 2001-2003 VideoLAN
* $Id: sub.h,v 1.9 2003/10/31 22:46:19 hartman Exp $
* $Id: sub.h,v 1.10 2003/11/05 00:17:50 hartman Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
......@@ -43,6 +43,7 @@ typedef struct subtitle_s
typedef struct subtitle_track_s
{
int i_track_id;
char *psz_header;
int i_subtitle;
int i_subtitles;
subtitle_t *subtitle;
......@@ -73,11 +74,12 @@ typedef struct subtitle_demux_s
input_thread_t *p_input;
int i_sub_type;
int i_previously_selected; /* to make pf_seek */
char *psz_header;
int i_subtitle;
int i_subtitles;
subtitle_t *subtitle;
es_descriptor_t *p_es;
int i_previously_selected; /* to make pf_seek */
/*unsigned int i_tracks;
subtitle_track_t *p_tracks
......
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