]> git.sesse.net Git - vlc/blob - modules/stream_out/bridge.c
Print an error when trying to add more than one ES to the bridge-out module.
[vlc] / modules / stream_out / bridge.c
1 /*****************************************************************************
2  * bridge.c: bridge stream output module
3  *****************************************************************************
4  * Copyright (C) 2005-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Christophe Massiot <massiot@via.ecp.fr>
8  *          Antoine Cellerier <dionoea at videolan dot org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <vlc_common.h>
34 #include <vlc_plugin.h>
35 #include <vlc_sout.h>
36 #include <vlc_block.h>
37
38 /*****************************************************************************
39  * Module descriptor
40  *****************************************************************************/
41 #define ID_TEXT N_("ID")
42 #define ID_LONGTEXT N_( \
43     "Integer identifier for this elementary stream. This will be used to " \
44     "\"find\" this stream later." )
45
46 #define DEST_TEXT N_( "Destination bridge-in name" )
47 #define DEST_LONGTEXT N_( \
48     "Name of the destination bridge-in. If you do not need more " \
49     "than one bridge-in at a time, you can discard this option." )
50
51 #define DELAY_TEXT N_("Delay")
52 #define DELAY_LONGTEXT N_("Pictures coming from the picture video outputs " \
53         "will be delayed according to this value (in milliseconds, should be "\
54         ">= 100 ms). For high values, you will need to raise caching values." )
55
56 #define ID_OFFSET_TEXT N_("ID Offset")
57 #define ID_OFFSET_LONGTEXT N_("Offset to add to the stream IDs specified in " \
58         "bridge_out to obtain the stream IDs bridge_in will register.")
59
60 #define NAME_TEXT N_( "Name of current instance" )
61 #define NAME_LONGTEXT N_( \
62     "Name of this bridge-in instance. If you do not need more " \
63     "than one bridge-in at a time, you can discard this option." )
64
65 #define PLACEHOLDER_TEXT N_( "Fallback to placeholder stream when out of data" )
66 #define PLACEHOLDER_LONGTEXT N_( \
67     "If set to true, the bridge will discard all input elementary streams " \
68     "except if it doesn't receive data from another bridge-in. This can " \
69     "be used to configure a place holder stream when the real source " \
70     "breaks. Source and placeholder streams should have the same format. " )
71
72 #define PLACEHOLDER_DELAY_TEXT N_( "Place holder delay" )
73 #define PLACEHOLDER_DELAY_LONGTEXT N_( \
74     "Delay (in ms) before the place holder kicks in." )
75
76 static int  OpenOut ( vlc_object_t * );
77 static void CloseOut( vlc_object_t * );
78 static int  OpenIn  ( vlc_object_t * );
79 static void CloseIn ( vlc_object_t * );
80
81 #define SOUT_CFG_PREFIX_OUT "sout-bridge-out-"
82 #define SOUT_CFG_PREFIX_IN "sout-bridge-in-"
83
84 vlc_module_begin();
85     set_shortname( N_("Bridge"));
86     set_description( N_("Bridge stream output"));
87     add_submodule();
88     set_section( N_("Bridge out"), NULL );
89     set_capability( "sout stream", 50 );
90     add_shortcut( "bridge-out" );
91     /* Only usable with VLM. No category so not in gui preferences
92     set_category( CAT_SOUT );
93     set_subcategory( SUBCAT_SOUT_STREAM );*/
94     add_integer( SOUT_CFG_PREFIX_OUT "id", 0, NULL, ID_TEXT, ID_LONGTEXT,
95                  false );
96     add_string( SOUT_CFG_PREFIX_OUT "in-name", "default", NULL,
97                 DEST_TEXT, DEST_LONGTEXT, false );
98     set_callbacks( OpenOut, CloseOut );
99
100     add_submodule();
101     set_section( N_("Bridge in"), NULL );
102     set_capability( "sout stream", 50 );
103     add_shortcut( "bridge-in" );
104     /*set_category( CAT_SOUT );
105     set_subcategory( SUBCAT_SOUT_STREAM );*/
106     add_integer( SOUT_CFG_PREFIX_IN "delay", 0, NULL, DELAY_TEXT,
107                  DELAY_LONGTEXT, false );
108     add_integer( SOUT_CFG_PREFIX_IN "id-offset", 8192, NULL, ID_OFFSET_TEXT,
109                  ID_OFFSET_LONGTEXT, false );
110     add_string( SOUT_CFG_PREFIX_IN "name", "default", NULL,
111                 NAME_TEXT, NAME_LONGTEXT, false );
112     add_bool( SOUT_CFG_PREFIX_IN "placeholder", false, NULL,
113               PLACEHOLDER_TEXT, PLACEHOLDER_LONGTEXT, false );
114     add_integer( SOUT_CFG_PREFIX_IN "placeholder-delay", 200, NULL,
115                  PLACEHOLDER_DELAY_TEXT, PLACEHOLDER_DELAY_LONGTEXT, false );
116     set_callbacks( OpenIn, CloseIn );
117
118 vlc_module_end();
119
120
121 /*****************************************************************************
122  * Local prototypes
123  *****************************************************************************/
124 static const char *const ppsz_sout_options_out[] = {
125     "id", "in-name", NULL
126 };
127
128 static const char *const ppsz_sout_options_in[] = {
129     "delay", "id-offset", "name", "placeholder", "placeholder-delay", NULL
130 };
131
132 static sout_stream_id_t *AddOut ( sout_stream_t *, es_format_t * );
133 static int               DelOut ( sout_stream_t *, sout_stream_id_t * );
134 static int               SendOut( sout_stream_t *, sout_stream_id_t *, block_t * );
135
136 static sout_stream_id_t *AddIn ( sout_stream_t *, es_format_t * );
137 static int               DelIn ( sout_stream_t *, sout_stream_id_t * );
138 static int               SendIn( sout_stream_t *, sout_stream_id_t *, block_t * );
139
140 typedef struct bridged_es_t
141 {
142     es_format_t fmt;
143     block_t *p_block;
144     block_t **pp_last;
145     bool b_empty;
146
147     /* bridge in part */
148     sout_stream_id_t *id;
149     mtime_t i_last;
150     bool b_changed;
151 } bridged_es_t;
152
153 typedef struct bridge_t
154 {
155     bridged_es_t **pp_es;
156     int i_es_num;
157 } bridge_t;
158
159 #define GetBridge(a,b) __GetBridge( VLC_OBJECT(a), b )
160 static bridge_t *__GetBridge( vlc_object_t *p_object, const char *psz_name )
161 {
162     bridge_t *p_bridge;
163     vlc_value_t val;
164
165     if( var_Get( p_object->p_libvlc, psz_name, &val ) )
166     {
167         p_bridge = NULL;
168     }
169     else
170     {
171         p_bridge = val.p_address;
172     }
173
174     return p_bridge;
175 }
176
177
178 /*
179  * Bridge out
180  */
181
182 typedef struct out_sout_stream_sys_t
183 {
184     vlc_mutex_t *p_lock;
185     bridged_es_t *p_es;
186     int i_id;
187     bool b_inited;
188
189     char *psz_name;
190 } out_sout_stream_sys_t;
191
192 /*****************************************************************************
193  * OpenOut:
194  *****************************************************************************/
195 static int OpenOut( vlc_object_t *p_this )
196 {
197     sout_stream_t     *p_stream = (sout_stream_t *)p_this;
198     out_sout_stream_sys_t *p_sys;
199     vlc_value_t val;
200
201     config_ChainParse( p_stream, SOUT_CFG_PREFIX_OUT, ppsz_sout_options_out,
202                    p_stream->p_cfg );
203
204     p_sys          = malloc( sizeof( out_sout_stream_sys_t ) );
205     p_sys->b_inited = false;
206
207     var_Create( p_this->p_libvlc, "bridge-lock", VLC_VAR_MUTEX );
208     var_Get( p_this->p_libvlc, "bridge-lock", &val );
209     p_sys->p_lock = val.p_address;
210
211     var_Get( p_stream, SOUT_CFG_PREFIX_OUT "id", &val );
212     p_sys->i_id = val.i_int;
213
214     var_Get( p_stream, SOUT_CFG_PREFIX_OUT "in-name", &val );
215     if( asprintf( &p_sys->psz_name, "bridge-struct-%s", val.psz_string )<0 )
216     {
217         free( val.psz_string );
218         free( p_sys );
219         return VLC_ENOMEM;
220     }
221     free( val.psz_string );
222
223     p_stream->pf_add    = AddOut;
224     p_stream->pf_del    = DelOut;
225     p_stream->pf_send   = SendOut;
226
227     p_stream->p_sys     = (sout_stream_sys_t *)p_sys;
228
229     p_stream->p_sout->i_out_pace_nocontrol++;
230
231     return VLC_SUCCESS;
232 }
233
234 /*****************************************************************************
235  * CloseOut:
236  *****************************************************************************/
237 static void CloseOut( vlc_object_t * p_this )
238 {
239     sout_stream_t     *p_stream = (sout_stream_t*)p_this;
240     out_sout_stream_sys_t *p_sys = (out_sout_stream_sys_t *)p_stream->p_sys;
241
242     p_stream->p_sout->i_out_pace_nocontrol--;
243
244     free( p_sys->psz_name );
245     free( p_sys );
246 }
247
248 static sout_stream_id_t * AddOut( sout_stream_t *p_stream, es_format_t *p_fmt )
249 {
250     out_sout_stream_sys_t *p_sys = (out_sout_stream_sys_t *)p_stream->p_sys;
251     bridge_t *p_bridge;
252     bridged_es_t *p_es;
253     int i;
254
255     if ( p_sys->b_inited )
256     {
257         msg_Err( p_stream, "bridge-out can only handle 1 es at a time." );
258         return NULL;
259     }
260     p_sys->b_inited = true;
261
262     vlc_mutex_lock( p_sys->p_lock );
263
264     p_bridge = GetBridge( p_stream, p_sys->psz_name );
265     if ( p_bridge == NULL )
266     {
267         vlc_object_t *p_libvlc = VLC_OBJECT( p_stream->p_libvlc );
268         vlc_value_t val;
269
270         p_bridge = malloc( sizeof( bridge_t ) );
271
272         var_Create( p_libvlc, p_sys->psz_name, VLC_VAR_ADDRESS );
273         val.p_address = p_bridge;
274         var_Set( p_libvlc, p_sys->psz_name, val );
275
276         p_bridge->i_es_num = 0;
277         p_bridge->pp_es = NULL;
278     }
279
280     for ( i = 0; i < p_bridge->i_es_num; i++ )
281     {
282         if ( p_bridge->pp_es[i]->b_empty && !p_bridge->pp_es[i]->b_changed )
283             break;
284     }
285
286     if ( i == p_bridge->i_es_num )
287     {
288         p_bridge->pp_es = realloc( p_bridge->pp_es,
289                                    (p_bridge->i_es_num + 1)
290                                      * sizeof(bridged_es_t *) );
291         p_bridge->i_es_num++;
292         p_bridge->pp_es[i] = malloc( sizeof(bridged_es_t) );
293     }
294
295     p_sys->p_es = p_es = p_bridge->pp_es[i];
296
297     p_es->fmt = *p_fmt;
298     p_es->fmt.i_id = p_sys->i_id;
299     p_es->p_block = NULL;
300     p_es->pp_last = &p_es->p_block;
301     p_es->b_empty = false;
302
303     p_es->id = NULL;
304     p_es->i_last = 0;
305     p_es->b_changed = true;
306
307     msg_Dbg( p_stream, "bridging out input codec=%4.4s id=%d pos=%d",
308              (char*)&p_es->fmt.i_codec, p_es->fmt.i_id, i );
309
310     vlc_mutex_unlock( p_sys->p_lock );
311
312     return (sout_stream_id_t *)p_sys;
313 }
314
315 static int DelOut( sout_stream_t *p_stream, sout_stream_id_t *id )
316 {
317     VLC_UNUSED(id);
318     out_sout_stream_sys_t *p_sys = (out_sout_stream_sys_t *)p_stream->p_sys;
319     bridged_es_t *p_es;
320
321     if ( !p_sys->b_inited )
322     {
323         return VLC_SUCCESS;
324     }
325
326     vlc_mutex_lock( p_sys->p_lock );
327
328     p_es = p_sys->p_es;
329
330     p_es->b_empty = true;
331     block_ChainRelease( p_es->p_block );
332     p_es->p_block = false;
333
334     p_es->b_changed = true;
335     vlc_mutex_unlock( p_sys->p_lock );
336
337     p_sys->b_inited = false;
338
339     return VLC_SUCCESS;
340 }
341
342 static int SendOut( sout_stream_t *p_stream, sout_stream_id_t *id,
343                     block_t *p_buffer )
344 {
345     out_sout_stream_sys_t *p_sys = (out_sout_stream_sys_t *)p_stream->p_sys;
346     bridged_es_t *p_es;
347
348     if ( (out_sout_stream_sys_t *)id != p_sys )
349     {
350         block_ChainRelease( p_buffer );
351         return VLC_SUCCESS;
352     }
353
354     vlc_mutex_lock( p_sys->p_lock );
355
356     p_es = p_sys->p_es;
357     *p_es->pp_last = p_buffer;
358     while ( p_buffer != NULL )
359     {
360         p_es->pp_last = &p_buffer->p_next;
361         p_buffer = p_buffer->p_next;
362     }
363
364     vlc_mutex_unlock( p_sys->p_lock );
365
366     return VLC_SUCCESS;
367 }
368
369
370 /*
371  * Bridge in
372  */
373
374 typedef struct in_sout_stream_sys_t
375 {
376     sout_stream_t *p_out;
377     vlc_mutex_t *p_lock;
378     int i_id_offset;
379     mtime_t i_delay;
380
381     char *psz_name;
382
383     bool b_placeholder;
384     mtime_t i_placeholder_delay;
385     sout_stream_id_t *id_video;
386     mtime_t i_last_video;
387     sout_stream_id_t *id_audio;
388     mtime_t i_last_audio;
389 } in_sout_stream_sys_t;
390
391 /*****************************************************************************
392  * OpenIn:
393  *****************************************************************************/
394 static int OpenIn( vlc_object_t *p_this )
395 {
396     sout_stream_t     *p_stream = (sout_stream_t*)p_this;
397     in_sout_stream_sys_t *p_sys;
398     vlc_value_t val;
399
400     p_sys          = malloc( sizeof( in_sout_stream_sys_t ) );
401
402     p_sys->p_out = sout_StreamNew( p_stream->p_sout, p_stream->psz_next );
403     if( !p_sys->p_out )
404     {
405         msg_Err( p_stream, "cannot create chain" );
406         free( p_sys );
407         return VLC_EGENERIC;
408     }
409
410     config_ChainParse( p_stream, SOUT_CFG_PREFIX_IN, ppsz_sout_options_in,
411                    p_stream->p_cfg );
412
413     var_Create( p_this->p_libvlc, "bridge-lock", VLC_VAR_MUTEX );
414     var_Get( p_this->p_libvlc, "bridge-lock", &val );
415     p_sys->p_lock = val.p_address;
416
417     var_Get( p_stream, SOUT_CFG_PREFIX_IN "id-offset", &val );
418     p_sys->i_id_offset = val.i_int;
419
420     var_Get( p_stream, SOUT_CFG_PREFIX_IN "delay", &val );
421     p_sys->i_delay = (mtime_t)val.i_int * 1000;
422
423     var_Get( p_stream, SOUT_CFG_PREFIX_IN "name", &val );
424     if( asprintf( &p_sys->psz_name, "bridge-struct-%s", val.psz_string )<0 )
425     {
426         free( val.psz_string );
427         free( p_sys );
428         return VLC_ENOMEM;
429     }
430     free( val.psz_string );
431
432     var_Get( p_stream, SOUT_CFG_PREFIX_IN "placeholder", &val );
433     p_sys->b_placeholder = val.b_bool;
434
435     var_Get( p_stream, SOUT_CFG_PREFIX_IN "placeholder-delay", &val );
436     p_sys->i_placeholder_delay = (mtime_t)val.i_int * 1000;
437
438     p_sys->i_last_video = 0;
439     p_sys->i_last_audio = 0;
440     p_sys->id_video = NULL;
441     p_sys->id_audio = NULL;
442
443     p_stream->pf_add    = AddIn;
444     p_stream->pf_del    = DelIn;
445     p_stream->pf_send   = SendIn;
446
447     p_stream->p_sys     = (sout_stream_sys_t *)p_sys;
448
449     /* update p_sout->i_out_pace_nocontrol */
450     p_stream->p_sout->i_out_pace_nocontrol++;
451
452     return VLC_SUCCESS;
453 }
454
455 /*****************************************************************************
456  * CloseIn:
457  *****************************************************************************/
458 static void CloseIn( vlc_object_t * p_this )
459 {
460     sout_stream_t     *p_stream = (sout_stream_t*)p_this;
461     in_sout_stream_sys_t *p_sys = (in_sout_stream_sys_t *)p_stream->p_sys;
462
463     sout_StreamDelete( p_sys->p_out );
464     p_stream->p_sout->i_out_pace_nocontrol--;
465
466     free( p_sys->psz_name );
467     free( p_sys );
468 }
469
470 struct sout_stream_id_t
471 {
472     sout_stream_id_t *id;
473     int i_cat; /* es category. Used for placeholder option */
474 };
475
476 static sout_stream_id_t * AddIn( sout_stream_t *p_stream, es_format_t *p_fmt )
477 {
478     in_sout_stream_sys_t *p_sys = (in_sout_stream_sys_t *)p_stream->p_sys;
479
480     sout_stream_id_t *id = malloc( sizeof( sout_stream_id_t ) );
481     if( !id ) return NULL;
482
483     id->id = p_sys->p_out->pf_add( p_sys->p_out, p_fmt );
484     if( !id->id )
485     {
486         free( id );
487         return NULL;
488     }
489
490     if( p_sys->b_placeholder )
491     {
492         id->i_cat = p_fmt->i_cat;
493         switch( p_fmt->i_cat )
494         {
495             case VIDEO_ES:
496                 if( p_sys->id_video != NULL )
497                     msg_Err( p_stream, "We already had a video es!" );
498                 p_sys->id_video = id->id;
499                 break;
500             case AUDIO_ES:
501                 if( p_sys->id_audio != NULL )
502                     msg_Err( p_stream, "We already had an audio es!" );
503                 p_sys->id_audio = id->id;
504                 break;
505         }
506     }
507
508     return id;
509 }
510
511 static int DelIn( sout_stream_t *p_stream, sout_stream_id_t *id )
512 {
513     in_sout_stream_sys_t *p_sys = (in_sout_stream_sys_t *)p_stream->p_sys;
514
515     if( id == p_sys->id_video ) p_sys->id_video = NULL;
516     if( id == p_sys->id_audio ) p_sys->id_audio = NULL;
517
518     int ret = p_sys->p_out->pf_del( p_sys->p_out, id->id );
519
520     free( id );
521     return ret;
522 }
523
524 static int SendIn( sout_stream_t *p_stream, sout_stream_id_t *id,
525                    block_t *p_buffer )
526 {
527     in_sout_stream_sys_t *p_sys = (in_sout_stream_sys_t *)p_stream->p_sys;
528     bridge_t *p_bridge;
529     bool b_no_es = true;
530     int i;
531     int i_date = mdate();
532
533     /* First forward the packet for our own ES */
534     if( !p_sys->b_placeholder )
535         p_sys->p_out->pf_send( p_sys->p_out, id->id, p_buffer );
536
537     /* Then check all bridged streams */
538     vlc_mutex_lock( p_sys->p_lock );
539
540     p_bridge = GetBridge( p_stream, p_sys->psz_name );
541
542     if( p_bridge )
543     {
544     for ( i = 0; i < p_bridge->i_es_num; i++ )
545     {
546         if ( !p_bridge->pp_es[i]->b_empty )
547             b_no_es = false;
548
549         while ( p_bridge->pp_es[i]->p_block != NULL
550                  && (p_bridge->pp_es[i]->p_block->i_dts + p_sys->i_delay
551                        < i_date
552                       || p_bridge->pp_es[i]->p_block->i_dts + p_sys->i_delay
553                           < p_bridge->pp_es[i]->i_last) )
554         {
555             block_t *p_block = p_bridge->pp_es[i]->p_block;
556             msg_Dbg( p_stream, "dropping a packet (%"PRId64 ")",
557                      i_date - p_block->i_dts - p_sys->i_delay );
558             p_bridge->pp_es[i]->p_block
559                 = p_bridge->pp_es[i]->p_block->p_next;
560             block_Release( p_block );
561         }
562
563         if ( p_bridge->pp_es[i]->p_block == NULL )
564         {
565             p_bridge->pp_es[i]->pp_last = &p_bridge->pp_es[i]->p_block;
566         }
567
568         if ( p_bridge->pp_es[i]->b_changed )
569         {
570             if ( p_bridge->pp_es[i]->b_empty && p_bridge->pp_es[i]->id != NULL )
571             {
572                 p_sys->p_out->pf_del( p_sys->p_out, p_bridge->pp_es[i]->id );
573             }
574             else
575             {
576                 /* We need at least two packets to enter the mux. */
577                 if ( p_bridge->pp_es[i]->p_block == NULL
578                       || p_bridge->pp_es[i]->p_block->p_next == NULL )
579                 {
580                     continue;
581                 }
582
583                 p_bridge->pp_es[i]->fmt.i_id += p_sys->i_id_offset;
584                 p_bridge->pp_es[i]->id = p_sys->p_out->pf_add(
585                             p_sys->p_out, &p_bridge->pp_es[i]->fmt );
586                 if ( p_bridge->pp_es[i]->id == NULL )
587                 {
588                     msg_Warn( p_stream, "couldn't create chain for id %d",
589                               p_bridge->pp_es[i]->fmt.i_id );
590                 }
591                 msg_Dbg( p_stream, "bridging in input codec=%4.4s id=%d pos=%d",
592                          (char*)&p_bridge->pp_es[i]->fmt.i_codec,
593                          p_bridge->pp_es[i]->fmt.i_id, i );
594             }
595         }
596         p_bridge->pp_es[i]->b_changed = false;
597
598         if ( p_bridge->pp_es[i]->b_empty )
599             continue;
600
601         if ( p_bridge->pp_es[i]->p_block == NULL )
602         {
603             if ( p_bridge->pp_es[i]->id != NULL
604                   && p_bridge->pp_es[i]->i_last < i_date )
605             {
606                 p_sys->p_out->pf_del( p_sys->p_out, p_bridge->pp_es[i]->id );
607                 p_bridge->pp_es[i]->fmt.i_id -= p_sys->i_id_offset;
608                 p_bridge->pp_es[i]->b_changed = true;
609                 p_bridge->pp_es[i]->id = NULL;
610             }
611             continue;
612         }
613
614         if ( p_bridge->pp_es[i]->id != NULL )
615         {
616             block_t *p_block = p_bridge->pp_es[i]->p_block;
617             while ( p_block != NULL )
618             {
619                 p_bridge->pp_es[i]->i_last = p_block->i_dts;
620                 p_block->i_pts += p_sys->i_delay;
621                 p_block->i_dts += p_sys->i_delay;
622                 p_block = p_block->p_next;
623             }
624             sout_stream_id_t *newid = NULL;
625             if( p_sys->b_placeholder )
626             {
627                 switch( p_bridge->pp_es[i]->fmt.i_cat )
628                 {
629                     case VIDEO_ES:
630                         p_sys->i_last_video = i_date;
631                         newid = p_sys->id_video;
632                         break;
633                     case AUDIO_ES:
634                         newid = p_sys->id_audio;
635                         p_sys->i_last_audio = i_date;
636                         break;
637                 }
638             }
639             p_sys->p_out->pf_send( p_sys->p_out,
640                                    newid ? newid : p_bridge->pp_es[i]->id,
641                                    p_bridge->pp_es[i]->p_block );
642         }
643         else
644         {
645             block_ChainRelease( p_bridge->pp_es[i]->p_block );
646         }
647
648         p_bridge->pp_es[i]->p_block = NULL;
649         p_bridge->pp_es[i]->pp_last = &p_bridge->pp_es[i]->p_block;
650     }
651
652     if( b_no_es )
653     {
654         vlc_object_t *p_libvlc = VLC_OBJECT( p_stream->p_libvlc );
655         for ( i = 0; i < p_bridge->i_es_num; i++ )
656             free( p_bridge->pp_es[i] );
657         free( p_bridge->pp_es );
658         free( p_bridge );
659         var_Destroy( p_libvlc, p_sys->psz_name );
660     }
661     }
662
663     if( p_sys->b_placeholder )
664     {
665         switch( id->i_cat )
666         {
667             case VIDEO_ES:
668                 if( p_sys->i_last_video + p_sys->i_placeholder_delay < i_date )
669                     p_sys->p_out->pf_send( p_sys->p_out, id->id, p_buffer );
670                 else
671                     block_Release( p_buffer );
672                 break;
673
674             case AUDIO_ES:
675                 if( p_sys->i_last_audio + p_sys->i_placeholder_delay < i_date )
676                     p_sys->p_out->pf_send( p_sys->p_out, id->id, p_buffer );
677                 else
678                     block_Release( p_buffer );
679                 break;
680
681             default:
682                 block_Release( p_buffer ); /* FIXME: placeholder subs anyone? */
683                 break;
684         }
685     }
686
687     vlc_mutex_unlock( p_sys->p_lock );
688
689     return VLC_SUCCESS;
690 }