1 /*****************************************************************************
2 * spu.c: transcoding stream output module (spu)
3 *****************************************************************************
4 * Copyright (C) 2003-2009 VLC authors and VideoLAN
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * Gildas Bazin <gbazin@videolan.org>
9 * Jean-Paul Saman <jpsaman #_at_# m2x dot nl>
10 * Antoine Cellerier <dionoea at videolan dot org>
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU Lesser General Public License as published by
14 * the Free Software Foundation; either version 2.1 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public License
23 * along with this program; if not, write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
31 #include "transcode.h"
35 #include <vlc_modules.h>
38 static subpicture_t *spu_new_buffer( decoder_t *p_dec,
39 const subpicture_updater_t *p_upd )
42 subpicture_t *p_subpicture = subpicture_New( p_upd );
43 if( likely(p_subpicture != NULL) )
44 p_subpicture->b_subtitle = true;
48 static void spu_del_buffer( decoder_t *p_dec, subpicture_t *p_subpic )
51 subpicture_Delete( p_subpic );
53 int transcode_spu_new( sout_stream_t *p_stream, sout_stream_id_sys_t *id )
55 sout_stream_sys_t *p_sys = p_stream->p_sys;
61 /* Initialization of decoder structures */
62 id->p_decoder->pf_decode_sub = NULL;
63 id->p_decoder->pf_spu_buffer_new = spu_new_buffer;
64 id->p_decoder->pf_spu_buffer_del = spu_del_buffer;
65 id->p_decoder->p_owner = (decoder_owner_sys_t *)p_stream;
66 /* id->p_decoder->p_cfg = p_sys->p_spu_cfg; */
68 id->p_decoder->p_module =
69 module_need( id->p_decoder, "decoder", "$codec", false );
71 if( !id->p_decoder->p_module )
73 msg_Err( p_stream, "cannot find spu decoder" );
77 if( !p_sys->b_soverlay )
80 /* Initialization of encoder format structures */
81 es_format_Init( &id->p_encoder->fmt_in, id->p_decoder->fmt_in.i_cat,
82 id->p_decoder->fmt_in.i_codec );
84 id->p_encoder->p_cfg = p_sys->p_spu_cfg;
86 id->p_encoder->p_module =
87 module_need( id->p_encoder, "encoder", p_sys->psz_senc, true );
89 if( !id->p_encoder->p_module )
91 module_unneed( id->p_decoder, id->p_decoder->p_module );
92 msg_Err( p_stream, "cannot find spu encoder (%s)", p_sys->psz_senc );
98 p_sys->p_spu = spu_Create( p_stream );
103 void transcode_spu_close( sout_stream_t *p_stream, sout_stream_id_sys_t *id)
105 sout_stream_sys_t *p_sys = p_stream->p_sys;
107 if( id->p_decoder->p_module )
108 module_unneed( id->p_decoder, id->p_decoder->p_module );
109 if( id->p_decoder->p_description )
110 vlc_meta_Delete( id->p_decoder->p_description );
113 if( id->p_encoder->p_module )
114 module_unneed( id->p_encoder, id->p_encoder->p_module );
118 spu_Destroy( p_sys->p_spu );
123 int transcode_spu_process( sout_stream_t *p_stream,
124 sout_stream_id_sys_t *id,
125 block_t *in, block_t **out )
127 sout_stream_sys_t *p_sys = p_stream->p_sys;
128 subpicture_t *p_subpic;
131 p_subpic = id->p_decoder->pf_decode_sub( id->p_decoder, &in );
134 /* We just don't have anything to handle now, go own*/
138 if( p_sys->b_master_sync && p_sys->i_master_drift )
140 p_subpic->i_start -= p_sys->i_master_drift;
141 if( p_subpic->i_stop ) p_subpic->i_stop -= p_sys->i_master_drift;
144 if( p_sys->b_soverlay )
146 spu_PutSubpicture( p_sys->p_spu, p_subpic );
153 p_block = id->p_encoder->pf_encode_sub( id->p_encoder, p_subpic );
154 spu_del_buffer( id->p_decoder, p_subpic );
157 block_ChainAppend( out, p_block );
165 bool transcode_spu_add( sout_stream_t *p_stream, es_format_t *p_fmt,
166 sout_stream_id_sys_t *id )
168 sout_stream_sys_t *p_sys = p_stream->p_sys;
170 if( p_sys->i_scodec )
172 msg_Dbg( p_stream, "creating subtitle transcoding from fcc=`%4.4s' "
173 "to fcc=`%4.4s'", (char*)&p_fmt->i_codec,
174 (char*)&p_sys->i_scodec );
176 /* Complete destination format */
177 id->p_encoder->fmt_out.i_codec = p_sys->i_scodec;
179 /* build decoder -> filter -> encoder */
180 if( transcode_spu_new( p_stream, id ) )
182 msg_Err( p_stream, "cannot create subtitle chain" );
186 /* open output stream */
187 id->id = sout_StreamIdAdd( p_stream->p_next, &id->p_encoder->fmt_out );
188 id->b_transcode = true;
192 transcode_spu_close( p_stream, id );
198 assert( p_sys->b_soverlay );
199 msg_Dbg( p_stream, "subtitle (fcc=`%4.4s') overlaying",
200 (char*)&p_fmt->i_codec );
202 id->b_transcode = true;
204 /* Build decoder -> filter -> overlaying chain */
205 if( transcode_spu_new( p_stream, id ) )
207 msg_Err( p_stream, "cannot create subtitle chain" );