1 /*****************************************************************************
2 * t140.c : trivial T.140 text encoder
3 *****************************************************************************
4 * Copyright © 2007 Rémi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
25 #define VLC_MODULE_LICENSE VLC_LICENSE_GPL_2_PLUS
26 #include <vlc_common.h>
27 #include <vlc_plugin.h>
28 #include <vlc_codec.h>
31 static int Open ( vlc_object_t
* );
34 set_description( N_("T.140 text encoder") )
35 set_capability( "encoder", 100 )
40 static block_t
*Encode ( encoder_t
*, subpicture_t
* );
43 static int Open( vlc_object_t
*p_this
)
45 encoder_t
*p_enc
= (encoder_t
*)p_this
;
47 switch( p_enc
->fmt_out
.i_codec
)
50 if( ( p_enc
->fmt_out
.subs
.psz_encoding
!= NULL
)
51 && strcasecmp( p_enc
->fmt_out
.subs
.psz_encoding
, "utf8" )
52 && strcasecmp( p_enc
->fmt_out
.subs
.psz_encoding
, "UTF-8" ) )
54 msg_Err( p_this
, "Only UTF-8 encoding supported" );
57 case VLC_CODEC_ITU_T140
:
61 if( !p_enc
->obj
.force
)
64 p_enc
->fmt_out
.i_codec
= VLC_CODEC_ITU_T140
;
69 p_enc
->pf_encode_sub
= Encode
;
70 p_enc
->fmt_out
.i_cat
= SPU_ES
;
75 static block_t
*Encode( encoder_t
*p_enc
, subpicture_t
*p_spu
)
79 subpicture_region_t
*p_region
;
86 p_region
= p_spu
->p_region
;
87 if( ( p_region
== NULL
)
88 || ( p_region
->fmt
.i_chroma
!= VLC_CODEC_TEXT
)
89 || ( p_region
->p_text
== NULL
)
90 || ( p_region
->p_text
->psz_text
== NULL
) )
93 /* This should already be UTF-8 encoded, so not much effort... */
94 for( const text_segment_t
*p_segment
= p_region
->p_text
;
95 p_segment
; p_segment
= p_segment
->p_next
)
97 if( p_segment
->psz_text
== NULL
)
99 len
+= strlen( p_segment
->psz_text
);
102 p_block
= block_Alloc( len
+ 1 );
106 p_block
->i_buffer
= 0;
107 for( const text_segment_t
*p_segment
= p_region
->p_text
;
108 p_segment
; p_segment
= p_segment
->p_next
)
110 if( p_segment
->psz_text
== NULL
)
112 len
= strlen( p_segment
->psz_text
);
113 memcpy( &p_block
->p_buffer
[p_block
->i_buffer
],
114 p_segment
->psz_text
, len
);
115 p_block
->i_buffer
+= len
;
117 p_block
->p_buffer
[p_block
->i_buffer
] = 0;
119 p_block
->i_pts
= p_block
->i_dts
= p_spu
->i_start
;
120 if( !p_spu
->b_ephemer
&& ( p_spu
->i_stop
> p_spu
->i_start
) )
121 p_block
->i_length
= p_spu
->i_stop
- p_spu
->i_start
;