demux: mp4: avoid audio cuts on seek
[vlc.git] / modules / codec / t140.c
bloba4f186b1e71e55488f87d11f4e88ddedb9bfb888
1 /*****************************************************************************
2 * t140.c : trivial T.140 text encoder
3 *****************************************************************************
4 * Copyright © 2007 Rémi Denis-Courmont
5 * $Id$
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
20 *****************************************************************************/
22 #ifdef HAVE_CONFIG_H
23 # include "config.h"
24 #endif
26 #define VLC_MODULE_LICENSE VLC_LICENSE_GPL_2_PLUS
27 #include <vlc_common.h>
28 #include <vlc_plugin.h>
29 #include <vlc_codec.h>
30 #include <vlc_sout.h>
32 static int Open ( vlc_object_t * );
33 static void Close( vlc_object_t * );
35 vlc_module_begin ()
36 set_description( N_("T.140 text encoder") )
37 set_capability( "encoder", 100 )
38 set_callbacks( Open, Close )
39 vlc_module_end ()
42 static block_t *Encode ( encoder_t *, subpicture_t * );
45 static int Open( vlc_object_t *p_this )
47 encoder_t *p_enc = (encoder_t *)p_this;
49 switch( p_enc->fmt_out.i_codec )
51 case VLC_CODEC_SUBT:
52 if( ( p_enc->fmt_out.subs.psz_encoding != NULL )
53 && strcasecmp( p_enc->fmt_out.subs.psz_encoding, "utf8" )
54 && strcasecmp( p_enc->fmt_out.subs.psz_encoding, "UTF-8" ) )
56 msg_Err( p_this, "Only UTF-8 encoding supported" );
57 return VLC_EGENERIC;
59 case VLC_CODEC_ITU_T140:
60 break;
62 default:
63 if( !p_enc->obj.force )
64 return VLC_EGENERIC;
66 p_enc->fmt_out.i_codec = VLC_CODEC_ITU_T140;
69 p_enc->p_sys = NULL;
71 p_enc->pf_encode_sub = Encode;
72 p_enc->fmt_out.i_cat = SPU_ES;
73 return VLC_SUCCESS;
77 static void Close( vlc_object_t *p_this )
79 (void)p_this;
83 static block_t *Encode( encoder_t *p_enc, subpicture_t *p_spu )
85 VLC_UNUSED( p_enc );
87 subpicture_region_t *p_region;
88 block_t *p_block;
89 size_t len;
91 if( p_spu == NULL )
92 return NULL;
94 p_region = p_spu->p_region;
95 if( ( p_region == NULL )
96 || ( p_region->fmt.i_chroma != VLC_CODEC_TEXT )
97 || ( p_region->p_text == NULL )
98 || ( p_region->p_text->psz_text == NULL) )
99 return NULL;
101 /* This should already be UTF-8 encoded, so not much effort... */
102 len = strlen( p_region->p_text->psz_text );
103 p_block = block_Alloc( len );
104 memcpy( p_block->p_buffer, p_region->p_text->psz_text, len );
106 p_block->i_pts = p_block->i_dts = p_spu->i_start;
107 if( !p_spu->b_ephemer && ( p_spu->i_stop > p_spu->i_start ) )
108 p_block->i_length = p_spu->i_stop - p_spu->i_start;
110 return p_block;