X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=modules%2Fcodec%2Fspudec%2Fspudec.c;h=f527a9c2b379c0ed5fc6cc6ff48cc353859719ef;hb=b36b614a1469679d21ec24e2f89b95bb89358251;hp=ca8f481595838e342493a865d2fb4f2282df27c6;hpb=11e8ae92009d27accae414feeb8f30c6822b0955;p=vlc diff --git a/modules/codec/spudec/spudec.c b/modules/codec/spudec/spudec.c index ca8f481595..f527a9c2b3 100644 --- a/modules/codec/spudec/spudec.c +++ b/modules/codec/spudec/spudec.c @@ -1,10 +1,10 @@ /***************************************************************************** * spudec.c : SPU decoder thread ***************************************************************************** - * Copyright (C) 2000-2001 VideoLAN + * Copyright (C) 2000-2001, 2006 the VideoLAN team * $Id$ * - * Authors: Samuel Hocevar + * Authors: Sam Hocevar * Laurent Aimar * * This program is free software; you can redistribute it and/or modify @@ -19,15 +19,19 @@ * * 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** * Preamble *****************************************************************************/ -#include -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include #include "spudec.h" @@ -36,29 +40,27 @@ *****************************************************************************/ static int DecoderOpen ( vlc_object_t * ); static int PacketizerOpen( vlc_object_t * ); +static void Close ( vlc_object_t * ); -static void Close ( vlc_object_t * ); - -vlc_module_begin(); - set_description( _("DVD subtitles decoder") ); - set_capability( "decoder", 50 ); - set_callbacks( DecoderOpen, Close ); +vlc_module_begin () + set_description( N_("DVD subtitles decoder") ) + set_capability( "decoder", 50 ) + set_category( CAT_INPUT ) + set_subcategory( SUBCAT_INPUT_SCODEC ) + set_callbacks( DecoderOpen, Close ) - add_submodule(); - set_description( _("DVD subtitles packetizer") ); - set_capability( "packetizer", 50 ); - set_callbacks( PacketizerOpen, Close ); -vlc_module_end(); + add_submodule () + set_description( N_("DVD subtitles packetizer") ) + set_capability( "packetizer", 50 ) + set_callbacks( PacketizerOpen, Close ) +vlc_module_end () /***************************************************************************** * Local prototypes *****************************************************************************/ -static vout_thread_t *FindVout( decoder_t *); - -static block_t *Reassemble( decoder_t *, block_t ** ); - -static void Decode ( decoder_t *, block_t ** ); -static block_t *Packetize( decoder_t *, block_t ** ); +static block_t * Reassemble( decoder_t *, block_t ** ); +static subpicture_t * Decode ( decoder_t *, block_t ** ); +static block_t * Packetize ( decoder_t *, block_t ** ); /***************************************************************************** * DecoderOpen @@ -79,16 +81,15 @@ static int DecoderOpen( vlc_object_t *p_this ) p_dec->p_sys = p_sys = malloc( sizeof( decoder_sys_t ) ); - p_sys->b_packetizer = VLC_FALSE; + p_sys->b_packetizer = false; p_sys->i_spu_size = 0; p_sys->i_spu = 0; p_sys->p_block = NULL; - p_sys->p_vout = NULL; es_format_Init( &p_dec->fmt_out, SPU_ES, VLC_FOURCC( 's','p','u',' ' ) ); p_dec->pf_decode_sub = Decode; - p_dec->pf_packetize = Packetize; + p_dec->pf_packetize = NULL; return VLC_SUCCESS; } @@ -107,7 +108,10 @@ static int PacketizerOpen( vlc_object_t *p_this ) { return VLC_EGENERIC; } - p_dec->p_sys->b_packetizer = VLC_TRUE; + p_dec->pf_packetize = Packetize; + p_dec->p_sys->b_packetizer = true; + es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in ); + p_dec->fmt_out.i_codec = VLC_FOURCC( 's','p','u',' ' ); return VLC_SUCCESS; } @@ -120,28 +124,6 @@ static void Close( vlc_object_t *p_this ) decoder_t *p_dec = (decoder_t*)p_this; decoder_sys_t *p_sys = p_dec->p_sys; - if( !p_sys->b_packetizer ) - { - /* FIXME check if it's ok to not lock vout */ - if( p_sys->p_vout != NULL && p_sys->p_vout->p_subpicture != NULL ) - { - subpicture_t * p_subpic; - int i_subpic; - - for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ ) - { - p_subpic = &p_sys->p_vout->p_subpicture[i_subpic]; - - if( p_subpic != NULL && - ( ( p_subpic->i_status == RESERVED_SUBPICTURE ) || - ( p_subpic->i_status == READY_SUBPICTURE ) ) ) - { - vout_DestroySubPicture( p_sys->p_vout, p_subpic ); - } - } - } - } - if( p_sys->p_block ) { block_ChainRelease( p_sys->p_block ); @@ -153,38 +135,34 @@ static void Close( vlc_object_t *p_this ) /***************************************************************************** * Decode: *****************************************************************************/ -static void Decode( decoder_t *p_dec, block_t **pp_block ) +static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block ) { decoder_sys_t *p_sys = p_dec->p_sys; - block_t *p_spu = Reassemble( p_dec, pp_block ); - vout_thread_t *p_last_vout = p_dec->p_sys->p_vout; + block_t *p_spu_block; + subpicture_t *p_spu; + + p_spu_block = Reassemble( p_dec, pp_block ); - if( p_spu ) + if( ! p_spu_block ) { - p_sys->i_spu = block_ChainExtract( p_spu, p_sys->buffer, 65536 ); - p_sys->i_pts = p_spu->i_pts; - block_ChainRelease( p_spu ); + return NULL; + } - if( ( p_sys->p_vout = FindVout( p_dec ) ) ) - { - if( p_last_vout != p_sys->p_vout ) - { - p_sys->i_subpic_channel = - vout_RegisterOSDChannel( p_sys->p_vout ); - } + /* FIXME: what the, we shouldn’t need to allocate 64k of buffer --sam. */ + p_sys->i_spu = block_ChainExtract( p_spu_block, p_sys->buffer, 65536 ); + p_sys->i_pts = p_spu_block->i_pts; + block_ChainRelease( p_spu_block ); - /* Parse and decode */ - E_(ParsePacket)( p_dec ); + /* Parse and decode */ + p_spu = ParsePacket( p_dec ); - vlc_object_release( p_sys->p_vout ); - } + /* reinit context */ + p_sys->i_spu_size = 0; + p_sys->i_rle_size = 0; + p_sys->i_spu = 0; + p_sys->p_block = NULL; - /* reinit context */ - p_sys->i_spu_size = 0; - p_sys->i_rle_size = 0; - p_sys->i_spu = 0; - p_sys->p_block = NULL; - } + return p_spu; } /***************************************************************************** @@ -195,20 +173,21 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block ) decoder_sys_t *p_sys = p_dec->p_sys; block_t *p_spu = Reassemble( p_dec, pp_block ); - if( p_spu ) + if( ! p_spu ) { - p_spu->i_dts = p_spu->i_pts; - p_spu->i_length = 0; + return NULL; + } - /* reinit context */ - p_sys->i_spu_size = 0; - p_sys->i_rle_size = 0; - p_sys->i_spu = 0; - p_sys->p_block = NULL; + p_spu->i_dts = p_spu->i_pts; + p_spu->i_length = 0; - return block_ChainGather( p_spu ); - } - return NULL; + /* reinit context */ + p_sys->i_spu_size = 0; + p_sys->i_rle_size = 0; + p_sys->i_spu = 0; + p_sys->p_block = NULL; + + return block_ChainGather( p_spu ); } /***************************************************************************** @@ -219,17 +198,16 @@ static block_t *Reassemble( decoder_t *p_dec, block_t **pp_block ) decoder_sys_t *p_sys = p_dec->p_sys; block_t *p_block; - if( pp_block == NULL || *pp_block == NULL ) - { - return NULL; - } + if( pp_block == NULL || *pp_block == NULL ) return NULL; p_block = *pp_block; *pp_block = NULL; - if( p_sys->i_spu_size <= 0 && ( p_block->i_pts <= 0 || p_block->i_buffer < 4 ) ) + if( p_sys->i_spu_size <= 0 && + ( p_block->i_pts <= 0 || p_block->i_buffer < 4 ) ) { msg_Dbg( p_dec, "invalid starting packet (size < 4 or pts <=0)" ); - msg_Dbg( p_dec, "spu size: %d, i_pts: "I64Fd" i_buffer: %d", p_sys->i_spu_size, p_block->i_pts, p_block->i_buffer ); + msg_Dbg( p_dec, "spu size: %d, i_pts: %"PRId64" i_buffer: %zu", + p_sys->i_spu_size, p_block->i_pts, p_block->i_buffer ); block_Release( p_block ); return NULL; } @@ -239,11 +217,14 @@ static block_t *Reassemble( decoder_t *p_dec, block_t **pp_block ) if( p_sys->i_spu_size <= 0 ) { - p_sys->i_spu_size = ( p_block->p_buffer[0] << 8 )| p_block->p_buffer[1]; - p_sys->i_rle_size = ( ( p_block->p_buffer[2] << 8 )| p_block->p_buffer[3] ) - 4; + p_sys->i_spu_size = ( p_block->p_buffer[0] << 8 )| + p_block->p_buffer[1]; + p_sys->i_rle_size = ( ( p_block->p_buffer[2] << 8 )| + p_block->p_buffer[3] ) - 4; /* msg_Dbg( p_dec, "i_spu_size=%d i_rle=%d", p_sys->i_spu_size, p_sys->i_rle_size ); */ + if( p_sys->i_spu_size <= 0 || p_sys->i_rle_size >= p_sys->i_spu_size ) { p_sys->i_spu_size = 0; @@ -259,41 +240,11 @@ static block_t *Reassemble( decoder_t *p_dec, block_t **pp_block ) if( p_sys->i_spu >= p_sys->i_spu_size ) { /* We have a complete sub */ - msg_Dbg( p_dec, "SPU packets size=%d should be %d", - p_sys->i_spu, p_sys->i_spu_size ); + if( p_sys->i_spu > p_sys->i_spu_size ) + msg_Dbg( p_dec, "SPU packets size=%d should be %d", + p_sys->i_spu, p_sys->i_spu_size ); return p_sys->p_block; } return NULL; } - -/* following functions are local */ - -/***************************************************************************** - * FindVout: Find a vout or wait for one to be created. - *****************************************************************************/ -static vout_thread_t *FindVout( decoder_t *p_dec ) -{ - vout_thread_t *p_vout = NULL; - - /* Find an available video output */ - do - { - if( p_dec->b_die || p_dec->b_error ) - { - break; - } - - p_vout = vlc_object_find( p_dec, VLC_OBJECT_VOUT, FIND_ANYWHERE ); - if( p_vout ) - { - break; - } - - msleep( VOUT_OUTMEM_SLEEP ); - } - while( 1 ); - - return p_vout; -} -