transcode: don't init an es_format_t before calling es_format_Copy()
[vlc.git] / modules / stream_out / transcode / transcode.c
blob3eba37a414bcc6d76bbc9afa88bcdd597b30848b
1 /*****************************************************************************
2 * transcode.c: transcoding stream output module
3 *****************************************************************************
4 * Copyright (C) 2003-2009 VLC authors and VideoLAN
5 * $Id$
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>
11 * Ilkka Ollakka <ileoo at videolan dot org>
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU Lesser General Public License as published by
15 * the Free Software Foundation; either version 2.1 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public License
24 * along with this program; if not, write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
28 /*****************************************************************************
29 * Preamble
30 *****************************************************************************/
31 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
35 #include <vlc_common.h>
36 #include <vlc_plugin.h>
38 #include <vlc_spu.h>
40 #include "transcode.h"
42 /*****************************************************************************
43 * Module descriptor
44 *****************************************************************************/
45 #define VENC_TEXT N_("Video encoder")
46 #define VENC_LONGTEXT N_( \
47 "This is the video encoder module that will be used (and its associated "\
48 "options).")
49 #define VCODEC_TEXT N_("Destination video codec")
50 #define VCODEC_LONGTEXT N_( \
51 "This is the video codec that will be used.")
52 #define VB_TEXT N_("Video bitrate")
53 #define VB_LONGTEXT N_( \
54 "Target bitrate of the transcoded video stream." )
55 #define SCALE_TEXT N_("Video scaling")
56 #define SCALE_LONGTEXT N_( \
57 "Scale factor to apply to the video while transcoding (eg: 0.25)")
58 #define FPS_TEXT N_("Video frame-rate")
59 #define FPS_LONGTEXT N_( \
60 "Target output frame rate for the video stream." )
61 #define DEINTERLACE_TEXT N_("Deinterlace video")
62 #define DEINTERLACE_LONGTEXT N_( \
63 "Deinterlace the video before encoding." )
64 #define DEINTERLACE_MODULE_TEXT N_("Deinterlace module")
65 #define DEINTERLACE_MODULE_LONGTEXT N_( \
66 "Specify the deinterlace module to use." )
67 #define WIDTH_TEXT N_("Video width")
68 #define WIDTH_LONGTEXT N_( \
69 "Output video width." )
70 #define HEIGHT_TEXT N_("Video height")
71 #define HEIGHT_LONGTEXT N_( \
72 "Output video height." )
73 #define MAXWIDTH_TEXT N_("Maximum video width")
74 #define MAXWIDTH_LONGTEXT N_( \
75 "Maximum output video width." )
76 #define MAXHEIGHT_TEXT N_("Maximum video height")
77 #define MAXHEIGHT_LONGTEXT N_( \
78 "Maximum output video height." )
79 #define VFILTER_TEXT N_("Video filter")
80 #define VFILTER_LONGTEXT N_( \
81 "Video filters will be applied to the video streams (after overlays " \
82 "are applied). You can enter a colon-separated list of filters." )
84 #define AENC_TEXT N_("Audio encoder")
85 #define AENC_LONGTEXT N_( \
86 "This is the audio encoder module that will be used (and its associated "\
87 "options).")
88 #define ACODEC_TEXT N_("Destination audio codec")
89 #define ACODEC_LONGTEXT N_( \
90 "This is the audio codec that will be used.")
91 #define AB_TEXT N_("Audio bitrate")
92 #define AB_LONGTEXT N_( \
93 "Target bitrate of the transcoded audio stream." )
94 #define ARATE_TEXT N_("Audio sample rate")
95 #define ARATE_LONGTEXT N_( \
96 "Sample rate of the transcoded audio stream (11250, 22500, 44100 or 48000).")
97 #define ALANG_TEXT N_("Audio language")
98 #define ALANG_LONGTEXT N_( \
99 "This is the language of the audio stream.")
100 #define ACHANS_TEXT N_("Audio channels")
101 #define ACHANS_LONGTEXT N_( \
102 "Number of audio channels in the transcoded streams." )
103 #define AFILTER_TEXT N_("Audio filter")
104 #define AFILTER_LONGTEXT N_( \
105 "Audio filters will be applied to the audio streams (after conversion " \
106 "filters are applied). You can enter a colon-separated list of filters." )
108 #define SENC_TEXT N_("Subtitle encoder")
109 #define SENC_LONGTEXT N_( \
110 "This is the subtitle encoder module that will be used (and its " \
111 "associated options)." )
112 #define SCODEC_TEXT N_("Destination subtitle codec")
113 #define SCODEC_LONGTEXT N_( \
114 "This is the subtitle codec that will be used." )
116 #define SFILTER_TEXT N_("Overlays")
117 #define SFILTER_LONGTEXT N_( \
118 "This allows you to add overlays (also known as \"subpictures\" on the "\
119 "transcoded video stream. The subpictures produced by the filters will "\
120 "be overlayed directly onto the video. You can specify a colon-separated "\
121 "list of subpicture modules" )
123 #define THREADS_TEXT N_("Number of threads")
124 #define THREADS_LONGTEXT N_( \
125 "Number of threads used for the transcoding." )
126 #define HP_TEXT N_("High priority")
127 #define HP_LONGTEXT N_( \
128 "Runs the optional encoder thread at the OUTPUT priority instead of " \
129 "VIDEO." )
130 #define POOL_TEXT N_("Picture pool size")
131 #define POOL_LONGTEXT N_( "Defines how many pictures we allow to be in pool "\
132 "between decoder/encoder threads when threads > 0" )
135 static const char *const ppsz_deinterlace_type[] =
137 "deinterlace", "ffmpeg-deinterlace"
140 static int Open ( vlc_object_t * );
141 static void Close( vlc_object_t * );
143 #define SOUT_CFG_PREFIX "sout-transcode-"
145 vlc_module_begin ()
146 set_shortname( N_("Transcode"))
147 set_description( N_("Transcode stream output") )
148 set_capability( "sout stream", 50 )
149 add_shortcut( "transcode" )
150 set_callbacks( Open, Close )
151 set_category( CAT_SOUT )
152 set_subcategory( SUBCAT_SOUT_STREAM )
153 set_section( N_("Video"), NULL )
154 add_module( SOUT_CFG_PREFIX "venc", "encoder", NULL, VENC_TEXT,
155 VENC_LONGTEXT, false )
156 add_string( SOUT_CFG_PREFIX "vcodec", NULL, VCODEC_TEXT,
157 VCODEC_LONGTEXT, false )
158 add_integer( SOUT_CFG_PREFIX "vb", 0, VB_TEXT,
159 VB_LONGTEXT, false )
160 add_float( SOUT_CFG_PREFIX "scale", 0, SCALE_TEXT,
161 SCALE_LONGTEXT, false )
162 add_string( SOUT_CFG_PREFIX "fps", NULL, FPS_TEXT,
163 FPS_LONGTEXT, false )
164 add_obsolete_bool( SOUT_CFG_PREFIX "hurry-up"); /* Since 2.2.0 */
165 add_bool( SOUT_CFG_PREFIX "deinterlace", false, DEINTERLACE_TEXT,
166 DEINTERLACE_LONGTEXT, false )
167 add_string( SOUT_CFG_PREFIX "deinterlace-module", "deinterlace",
168 DEINTERLACE_MODULE_TEXT, DEINTERLACE_MODULE_LONGTEXT,
169 false )
170 change_string_list( ppsz_deinterlace_type, ppsz_deinterlace_type )
171 add_integer( SOUT_CFG_PREFIX "width", 0, WIDTH_TEXT,
172 WIDTH_LONGTEXT, true )
173 add_integer( SOUT_CFG_PREFIX "height", 0, HEIGHT_TEXT,
174 HEIGHT_LONGTEXT, true )
175 add_integer( SOUT_CFG_PREFIX "maxwidth", 0, MAXWIDTH_TEXT,
176 MAXWIDTH_LONGTEXT, true )
177 add_integer( SOUT_CFG_PREFIX "maxheight", 0, MAXHEIGHT_TEXT,
178 MAXHEIGHT_LONGTEXT, true )
179 add_module_list( SOUT_CFG_PREFIX "vfilter", "video filter",
180 NULL, VFILTER_TEXT, VFILTER_LONGTEXT, false )
182 set_section( N_("Audio"), NULL )
183 add_module( SOUT_CFG_PREFIX "aenc", "encoder", NULL, AENC_TEXT,
184 AENC_LONGTEXT, false )
185 add_string( SOUT_CFG_PREFIX "acodec", NULL, ACODEC_TEXT,
186 ACODEC_LONGTEXT, false )
187 add_integer( SOUT_CFG_PREFIX "ab", 96, AB_TEXT,
188 AB_LONGTEXT, false )
189 add_string( SOUT_CFG_PREFIX "alang", NULL, ALANG_TEXT,
190 ALANG_LONGTEXT, true )
191 add_integer( SOUT_CFG_PREFIX "channels", 0, ACHANS_TEXT,
192 ACHANS_LONGTEXT, false )
193 change_integer_range( 0, 9 )
194 add_integer( SOUT_CFG_PREFIX "samplerate", 0, ARATE_TEXT,
195 ARATE_LONGTEXT, true )
196 change_integer_range( 0, 48000 )
197 add_obsolete_bool( SOUT_CFG_PREFIX "audio-sync" ) /*Since 2.2.0 */
198 add_module_list( SOUT_CFG_PREFIX "afilter", "audio filter",
199 NULL, AFILTER_TEXT, AFILTER_LONGTEXT, false )
201 set_section( N_("Overlays/Subtitles"), NULL )
202 add_module( SOUT_CFG_PREFIX "senc", "encoder", NULL, SENC_TEXT,
203 SENC_LONGTEXT, false )
204 add_string( SOUT_CFG_PREFIX "scodec", NULL, SCODEC_TEXT,
205 SCODEC_LONGTEXT, false )
206 add_bool( SOUT_CFG_PREFIX "soverlay", false, SCODEC_TEXT,
207 SCODEC_LONGTEXT, false )
208 add_module_list( SOUT_CFG_PREFIX "sfilter", "spu source",
209 NULL, SFILTER_TEXT, SFILTER_LONGTEXT, false )
211 set_section( N_("Miscellaneous"), NULL )
212 add_integer( SOUT_CFG_PREFIX "threads", 0, THREADS_TEXT,
213 THREADS_LONGTEXT, true )
214 add_integer( SOUT_CFG_PREFIX "pool-size", 10, POOL_TEXT, POOL_LONGTEXT, true )
215 change_integer_range( 1, 1000 )
216 add_bool( SOUT_CFG_PREFIX "high-priority", false, HP_TEXT, HP_LONGTEXT,
217 true )
219 vlc_module_end ()
221 static const char *const ppsz_sout_options[] = {
222 "venc", "vcodec", "vb",
223 "scale", "fps", "width", "height", "vfilter", "deinterlace",
224 "deinterlace-module", "threads", "aenc", "acodec", "ab", "alang",
225 "afilter", "samplerate", "channels", "senc", "scodec", "soverlay",
226 "sfilter", "high-priority", "maxwidth", "maxheight", "pool-size",
227 NULL
230 /*****************************************************************************
231 * Exported prototypes
232 *****************************************************************************/
233 static sout_stream_id_sys_t *Add( sout_stream_t *, const es_format_t * );
234 static void Del ( sout_stream_t *, sout_stream_id_sys_t * );
235 static int Send( sout_stream_t *, sout_stream_id_sys_t *, block_t* );
237 /*****************************************************************************
238 * Open:
239 *****************************************************************************/
240 static int Open( vlc_object_t *p_this )
242 sout_stream_t *p_stream = (sout_stream_t*)p_this;
243 sout_stream_sys_t *p_sys;
244 char *psz_string;
246 if( !p_stream->p_next )
248 msg_Err( p_stream, "cannot create chain" );
249 return VLC_EGENERIC;
251 p_sys = calloc( 1, sizeof( *p_sys ) );
252 p_sys->i_master_drift = 0;
254 config_ChainParse( p_stream, SOUT_CFG_PREFIX, ppsz_sout_options,
255 p_stream->p_cfg );
257 /* Audio transcoding parameters */
258 psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "aenc" );
259 p_sys->psz_aenc = NULL;
260 p_sys->p_audio_cfg = NULL;
261 if( psz_string && *psz_string )
263 char *psz_next;
264 psz_next = config_ChainCreate( &p_sys->psz_aenc, &p_sys->p_audio_cfg,
265 psz_string );
266 free( psz_next );
268 free( psz_string );
270 psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "acodec" );
271 p_sys->i_acodec = 0;
272 if( psz_string && *psz_string )
274 char fcc[5] = " \0";
275 memcpy( fcc, psz_string, __MIN( strlen( psz_string ), 4 ) );
276 p_sys->i_acodec = vlc_fourcc_GetCodecFromString( AUDIO_ES, fcc );
277 msg_Dbg( p_stream, "Checking codec mapping for %s got %4.4s ", fcc, (char*)&p_sys->i_acodec);
279 free( psz_string );
281 p_sys->psz_alang = var_GetNonEmptyString( p_stream, SOUT_CFG_PREFIX "alang" );
283 p_sys->i_abitrate = var_GetInteger( p_stream, SOUT_CFG_PREFIX "ab" );
284 if( p_sys->i_abitrate < 4000 ) p_sys->i_abitrate *= 1000;
286 p_sys->i_sample_rate = var_GetInteger( p_stream, SOUT_CFG_PREFIX "samplerate" );
288 p_sys->i_channels = var_GetInteger( p_stream, SOUT_CFG_PREFIX "channels" );
290 if( p_sys->i_acodec )
292 if( ( p_sys->i_acodec == VLC_CODEC_MP3 ||
293 p_sys->i_acodec == VLC_CODEC_MP2 ||
294 p_sys->i_acodec == VLC_CODEC_MPGA ) && p_sys->i_channels > 2 )
296 msg_Warn( p_stream, "%d channels invalid for mp2/mp3, forcing to 2",
297 p_sys->i_channels );
298 p_sys->i_channels = 2;
300 msg_Dbg( p_stream, "codec audio=%4.4s %dHz %d channels %dKb/s",
301 (char *)&p_sys->i_acodec, p_sys->i_sample_rate,
302 p_sys->i_channels, p_sys->i_abitrate / 1000 );
305 psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "afilter" );
306 if( psz_string && *psz_string )
307 p_sys->psz_af = strdup( psz_string );
308 else
309 p_sys->psz_af = NULL;
310 free( psz_string );
312 /* Video transcoding parameters */
313 psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "venc" );
314 p_sys->psz_venc = NULL;
315 p_sys->p_video_cfg = NULL;
316 if( psz_string && *psz_string )
318 char *psz_next;
319 psz_next = config_ChainCreate( &p_sys->psz_venc, &p_sys->p_video_cfg,
320 psz_string );
321 free( psz_next );
323 free( psz_string );
325 psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "vcodec" );
326 p_sys->i_vcodec = 0;
327 if( psz_string && *psz_string )
329 char fcc[5] = " \0";
330 memcpy( fcc, psz_string, __MIN( strlen( psz_string ), 4 ) );
331 p_sys->i_vcodec = vlc_fourcc_GetCodecFromString( VIDEO_ES, fcc );
332 msg_Dbg( p_stream, "Checking video codec mapping for %s got %4.4s ", fcc, (char*)&p_sys->i_vcodec);
334 free( psz_string );
336 p_sys->i_vbitrate = var_GetInteger( p_stream, SOUT_CFG_PREFIX "vb" );
337 if( p_sys->i_vbitrate < 16000 ) p_sys->i_vbitrate *= 1000;
339 p_sys->f_scale = var_GetFloat( p_stream, SOUT_CFG_PREFIX "scale" );
341 p_sys->b_master_sync = var_InheritURational( p_stream, &p_sys->fps_num, &p_sys->fps_den, SOUT_CFG_PREFIX "fps" ) == VLC_SUCCESS;
343 p_sys->i_width = var_GetInteger( p_stream, SOUT_CFG_PREFIX "width" );
345 p_sys->i_height = var_GetInteger( p_stream, SOUT_CFG_PREFIX "height" );
347 p_sys->i_maxwidth = var_GetInteger( p_stream, SOUT_CFG_PREFIX "maxwidth" );
349 p_sys->i_maxheight = var_GetInteger( p_stream, SOUT_CFG_PREFIX "maxheight" );
351 psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "vfilter" );
352 if( psz_string && *psz_string )
353 p_sys->psz_vf2 = strdup(psz_string );
354 else
355 p_sys->psz_vf2 = NULL;
356 free( psz_string );
358 if( var_GetBool( p_stream, SOUT_CFG_PREFIX "deinterlace" ) )
359 psz_string = var_GetString( p_stream,
360 SOUT_CFG_PREFIX "deinterlace-module" );
361 else
362 psz_string = NULL;
364 free( config_ChainCreate( &p_sys->psz_deinterlace,
365 &p_sys->p_deinterlace_cfg, psz_string ) );
366 free( psz_string );
368 p_sys->i_threads = var_GetInteger( p_stream, SOUT_CFG_PREFIX "threads" );
369 p_sys->pool_size = var_GetInteger( p_stream, SOUT_CFG_PREFIX "pool-size" );
370 p_sys->b_high_priority = var_GetBool( p_stream, SOUT_CFG_PREFIX "high-priority" );
372 if( p_sys->i_vcodec )
374 msg_Dbg( p_stream, "codec video=%4.4s %dx%d scaling: %f %dkb/s",
375 (char *)&p_sys->i_vcodec, p_sys->i_width, p_sys->i_height,
376 p_sys->f_scale, p_sys->i_vbitrate / 1000 );
379 /* Subpictures transcoding parameters */
380 p_sys->p_spu = NULL;
381 p_sys->p_spu_blend = NULL;
382 p_sys->psz_senc = NULL;
383 p_sys->p_spu_cfg = NULL;
384 p_sys->i_scodec = 0;
386 psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "senc" );
387 if( psz_string && *psz_string )
389 char *psz_next;
390 psz_next = config_ChainCreate( &p_sys->psz_senc, &p_sys->p_spu_cfg,
391 psz_string );
392 free( psz_next );
394 free( psz_string );
396 psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "scodec" );
397 if( psz_string && *psz_string )
399 char fcc[5] = " \0";
400 memcpy( fcc, psz_string, __MIN( strlen( psz_string ), 4 ) );
401 p_sys->i_scodec = vlc_fourcc_GetCodecFromString( SPU_ES, fcc );
402 msg_Dbg( p_stream, "Checking spu codec mapping for %s got %4.4s ", fcc, (char*)&p_sys->i_scodec);
404 free( psz_string );
406 if( p_sys->i_scodec )
408 msg_Dbg( p_stream, "codec spu=%4.4s", (char *)&p_sys->i_scodec );
411 p_sys->b_soverlay = var_GetBool( p_stream, SOUT_CFG_PREFIX "soverlay" );
413 psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "sfilter" );
414 if( psz_string && *psz_string )
416 p_sys->p_spu = spu_Create( p_stream, NULL );
417 if( p_sys->p_spu )
418 spu_ChangeSources( p_sys->p_spu, psz_string );
420 free( psz_string );
422 p_stream->pf_add = Add;
423 p_stream->pf_del = Del;
424 p_stream->pf_send = Send;
425 p_stream->p_sys = p_sys;
427 return VLC_SUCCESS;
430 /*****************************************************************************
431 * Close:
432 *****************************************************************************/
433 static void Close( vlc_object_t * p_this )
435 sout_stream_t *p_stream = (sout_stream_t*)p_this;
436 sout_stream_sys_t *p_sys = p_stream->p_sys;
438 free( p_sys->psz_af );
440 config_ChainDestroy( p_sys->p_audio_cfg );
441 free( p_sys->psz_aenc );
442 free( p_sys->psz_alang );
444 free( p_sys->psz_vf2 );
446 config_ChainDestroy( p_sys->p_video_cfg );
447 free( p_sys->psz_venc );
449 config_ChainDestroy( p_sys->p_deinterlace_cfg );
450 free( p_sys->psz_deinterlace );
452 config_ChainDestroy( p_sys->p_spu_cfg );
453 free( p_sys->psz_senc );
455 if( p_sys->p_spu ) spu_Destroy( p_sys->p_spu );
456 if( p_sys->p_spu_blend ) filter_DeleteBlend( p_sys->p_spu_blend );
458 free( p_sys );
461 static void DeleteSoutStreamID( sout_stream_id_sys_t *id )
463 if( id )
465 if( id->p_decoder )
467 es_format_Clean( &id->p_encoder->fmt_in );
468 es_format_Clean( &id->p_encoder->fmt_out );
469 vlc_object_release( id->p_decoder );
472 if( id->p_encoder )
474 es_format_Clean( &id->p_encoder->fmt_in );
475 es_format_Clean( &id->p_encoder->fmt_out );
476 vlc_object_release( id->p_encoder );
479 vlc_mutex_destroy(&id->fifo.lock);
480 free( id );
484 static sout_stream_id_sys_t *Add( sout_stream_t *p_stream,
485 const es_format_t *p_fmt )
487 sout_stream_sys_t *p_sys = p_stream->p_sys;
488 sout_stream_id_sys_t *id;
490 id = calloc( 1, sizeof( sout_stream_id_sys_t ) );
491 if( !id )
492 goto error;
494 vlc_mutex_init(&id->fifo.lock);
495 id->id = NULL;
496 id->p_decoder = NULL;
497 id->p_encoder = NULL;
499 /* Create decoder object */
500 id->p_decoder = vlc_object_create( p_stream, sizeof( decoder_t ) );
501 if( !id->p_decoder )
502 goto error;
503 id->p_decoder->p_module = NULL;
504 es_format_Init( &id->p_decoder->fmt_out, p_fmt->i_cat, 0 );
505 es_format_Copy( &id->p_decoder->fmt_in, p_fmt );
506 id->p_decoder->b_frame_drop_allowed = false;
508 /* Create encoder object */
509 id->p_encoder = sout_EncoderCreate( p_stream );
510 if( !id->p_encoder )
511 goto error;
512 id->p_encoder->p_module = NULL;
514 /* Create destination format */
515 es_format_Init( &id->p_encoder->fmt_in, p_fmt->i_cat, 0 );
516 es_format_Init( &id->p_encoder->fmt_out, p_fmt->i_cat, 0 );
517 id->p_encoder->fmt_out.i_id = p_fmt->i_id;
518 id->p_encoder->fmt_out.i_group = p_fmt->i_group;
520 if( p_sys->psz_alang )
521 id->p_encoder->fmt_out.psz_language = strdup( p_sys->psz_alang );
522 else if( p_fmt->psz_language )
523 id->p_encoder->fmt_out.psz_language = strdup( p_fmt->psz_language );
525 bool success;
527 if( p_fmt->i_cat == AUDIO_ES && p_sys->i_acodec )
528 success = transcode_audio_add(p_stream, p_fmt, id);
529 else if( p_fmt->i_cat == VIDEO_ES && p_sys->i_vcodec )
530 success = transcode_video_add(p_stream, p_fmt, id);
531 else if( ( p_fmt->i_cat == SPU_ES ) &&
532 ( p_sys->i_scodec || p_sys->b_soverlay ) )
533 success = transcode_spu_add(p_stream, p_fmt, id);
534 else
536 msg_Dbg( p_stream, "not transcoding a stream (fcc=`%4.4s')",
537 (char*)&p_fmt->i_codec );
538 id->id = sout_StreamIdAdd( p_stream->p_next, p_fmt );
539 id->b_transcode = false;
541 success = id->id;
544 if(!success)
545 goto error;
547 return id;
549 error:
550 DeleteSoutStreamID( id );
551 return NULL;
554 static void Del( sout_stream_t *p_stream, sout_stream_id_sys_t *id )
556 if( id->b_transcode )
558 switch( id->p_decoder->fmt_in.i_cat )
560 case AUDIO_ES:
561 Send( p_stream, id, NULL );
562 transcode_audio_close( id );
563 break;
564 case VIDEO_ES:
565 Send( p_stream, id, NULL );
566 transcode_video_close( p_stream, id );
567 break;
568 case SPU_ES:
569 transcode_spu_close( p_stream, id );
570 break;
574 if( id->id ) sout_StreamIdDel( p_stream->p_next, id->id );
576 DeleteSoutStreamID( id );
579 static int Send( sout_stream_t *p_stream, sout_stream_id_sys_t *id,
580 block_t *p_buffer )
582 block_t *p_out = NULL;
584 if( !id->b_transcode )
586 if( id->id )
587 return sout_StreamIdSend( p_stream->p_next, id->id, p_buffer );
589 block_Release( p_buffer );
590 return VLC_EGENERIC;
593 switch( id->p_decoder->fmt_in.i_cat )
595 case AUDIO_ES:
596 if( transcode_audio_process( p_stream, id, p_buffer, &p_out )
597 != VLC_SUCCESS )
599 return VLC_EGENERIC;
601 break;
603 case VIDEO_ES:
604 if( transcode_video_process( p_stream, id, p_buffer, &p_out )
605 != VLC_SUCCESS )
607 return VLC_EGENERIC;
609 break;
611 case SPU_ES:
612 if ( transcode_spu_process( p_stream, id, p_buffer, &p_out ) !=
613 VLC_SUCCESS )
615 return VLC_EGENERIC;
617 break;
619 default:
620 p_out = NULL;
621 block_Release( p_buffer );
622 break;
625 if( p_out )
626 return sout_StreamIdSend( p_stream->p_next, id->id, p_out );
627 return VLC_SUCCESS;