qt: playlist: use item title if available
[vlc.git] / modules / codec / t140.c
blobbb99290ec9ff0e02298cdab6e66d3b3b698d2546
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 *****************************************************************************/
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
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>
29 #include <vlc_sout.h>
31 static int Open ( vlc_object_t * );
33 vlc_module_begin ()
34 set_description( N_("T.140 text encoder") )
35 set_capability( "encoder", 100 )
36 set_callback( Open )
37 vlc_module_end ()
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 )
49 case VLC_CODEC_SUBT:
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" );
55 return VLC_EGENERIC;
57 case VLC_CODEC_ITU_T140:
58 break;
60 default:
61 if( !p_enc->obj.force )
62 return VLC_EGENERIC;
64 p_enc->fmt_out.i_codec = VLC_CODEC_ITU_T140;
67 p_enc->p_sys = NULL;
69 p_enc->pf_encode_sub = Encode;
70 p_enc->fmt_out.i_cat = SPU_ES;
71 return VLC_SUCCESS;
75 static block_t *Encode( encoder_t *p_enc, subpicture_t *p_spu )
77 VLC_UNUSED( p_enc );
79 subpicture_region_t *p_region;
80 block_t *p_block;
81 size_t len = 0;
83 if( p_spu == NULL )
84 return NULL;
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) )
91 return 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 )
98 continue;
99 len += strlen( p_segment->psz_text );
102 p_block = block_Alloc( len + 1 );
103 if( !p_block )
104 return NULL;
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 )
111 continue;
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;
123 return p_block;