]> git.sesse.net Git - vlc/blob - modules/stream_out/bridge.c
Add placeholder feature to bridge module ("No Signal" anyone?)
[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         return NULL;
258     }
259     p_sys->b_inited = true;
260
261     vlc_mutex_lock( p_sys->p_lock );
262
263     p_bridge = GetBridge( p_stream, p_sys->psz_name );
264     if ( p_bridge == NULL )
265     {
266         vlc_object_t *p_libvlc = VLC_OBJECT( p_stream->p_libvlc );
267         vlc_value_t val;
268
269         p_bridge = malloc( sizeof( bridge_t ) );
270
271         var_Create( p_libvlc, p_sys->psz_name, VLC_VAR_ADDRESS );
272         val.p_address = p_bridge;
273         var_Set( p_libvlc, p_sys->psz_name, val );
274
275         p_bridge->i_es_num = 0;
276         p_bridge->pp_es = NULL;
277     }
278
279     for ( i = 0; i < p_bridge->i_es_num; i++ )
280     {
281         if ( p_bridge->pp_es[i]->b_empty && !p_bridge->pp_es[i]->b_changed )
282             break;
283     }
284
285     if ( i == p_bridge->i_es_num )
286     {
287         p_bridge->pp_es = realloc( p_bridge->pp_es,
288                                    (p_bridge->i_es_num + 1)
289                                      * sizeof(bridged_es_t *) );
290         p_bridge->i_es_num++;
291         p_bridge->pp_es[i] = malloc( sizeof(bridged_es_t) );
292     }
293
294     p_sys->p_es = p_es = p_bridge->pp_es[i];
295
296     p_es->fmt = *p_fmt;
297     p_es->fmt.i_id = p_sys->i_id;
298     p_es->p_block = NULL;
299     p_es->pp_last = &p_es->p_block;
300     p_es->b_empty = false;
301
302     p_es->id = NULL;
303     p_es->i_last = 0;
304     p_es->b_changed = true;
305
306     msg_Dbg( p_stream, "bridging out input codec=%4.4s id=%d pos=%d",
307              (char*)&p_es->fmt.i_codec, p_es->fmt.i_id, i );
308
309     vlc_mutex_unlock( p_sys->p_lock );
310
311     return (sout_stream_id_t *)p_sys;
312 }
313
314 static int DelOut( sout_stream_t *p_stream, sout_stream_id_t *id )
315 {
316     VLC_UNUSED(id);
317     out_sout_stream_sys_t *p_sys = (out_sout_stream_sys_t *)p_stream->p_sys;
318     bridged_es_t *p_es;
319
320     if ( !p_sys->b_inited )
321     {
322         return VLC_SUCCESS;
323     }
324
325     vlc_mutex_lock( p_sys->p_lock );
326
327     p_es = p_sys->p_es;
328
329     p_es->b_empty = true;
330     block_ChainRelease( p_es->p_block );
331     p_es->p_block = false;
332
333     p_es->b_changed = true;
334     vlc_mutex_unlock( p_sys->p_lock );
335
336     p_sys->b_inited = false;
337
338     return VLC_SUCCESS;
339 }
340
341 static int SendOut( sout_stream_t *p_stream, sout_stream_id_t *id,
342                     block_t *p_buffer )
343 {
344     out_sout_stream_sys_t *p_sys = (out_sout_stream_sys_t *)p_stream->p_sys;
345     bridged_es_t *p_es;
346
347     if ( (out_sout_stream_sys_t *)id != p_sys )
348     {
349         block_ChainRelease( p_buffer );
350         return VLC_SUCCESS;
351     }
352
353     vlc_mutex_lock( p_sys->p_lock );
354
355     p_es = p_sys->p_es;
356     *p_es->pp_last = p_buffer;
357     while ( p_buffer != NULL )
358     {
359         p_es->pp_last = &p_buffer->p_next;
360         p_buffer = p_buffer->p_next;
361     }
362
363     vlc_mutex_unlock( p_sys->p_lock );
364
365     return VLC_SUCCESS;
366 }
367
368
369 /*
370  * Bridge in
371  */
372
373 typedef struct in_sout_stream_sys_t
374 {
375     sout_stream_t *p_out;
376     vlc_mutex_t *p_lock;
377     int i_id_offset;
378     mtime_t i_delay;
379
380     char *psz_name;
381
382     bool b_placeholder;
383     mtime_t i_placeholder_delay;
384     sout_stream_id_t *id_video;
385     mtime_t i_last_video;
386     sout_stream_id_t *id_audio;
387     mtime_t i_last_audio;
388 } in_sout_stream_sys_t;
389
390 /*****************************************************************************
391  * OpenIn:
392  *****************************************************************************/
393 static int OpenIn( vlc_object_t *p_this )
394 {
395     sout_stream_t     *p_stream = (sout_stream_t*)p_this;
396     in_sout_stream_sys_t *p_sys;
397     vlc_value_t val;
398
399     p_sys          = malloc( sizeof( in_sout_stream_sys_t ) );
400
401     p_sys->p_out = sout_StreamNew( p_stream->p_sout, p_stream->psz_next );
402     if( !p_sys->p_out )
403     {
404         msg_Err( p_stream, "cannot create chain" );
405         free( p_sys );
406         return VLC_EGENERIC;
407     }
408
409     config_ChainParse( p_stream, SOUT_CFG_PREFIX_IN, ppsz_sout_options_in,
410                    p_stream->p_cfg );
411
412     var_Create( p_this->p_libvlc, "bridge-lock", VLC_VAR_MUTEX );
413     var_Get( p_this->p_libvlc, "bridge-lock", &val );
414     p_sys->p_lock = val.p_address;
415
416     var_Get( p_stream, SOUT_CFG_PREFIX_IN "id-offset", &val );
417     p_sys->i_id_offset = val.i_int;
418
419     var_Get( p_stream, SOUT_CFG_PREFIX_IN "delay", &val );
420     p_sys->i_delay = (mtime_t)val.i_int * 1000;
421
422     var_Get( p_stream, SOUT_CFG_PREFIX_IN "name", &val );
423     if( asprintf( &p_sys->psz_name, "bridge-struct-%s", val.psz_string )<0 )
424     {
425         free( val.psz_string );
426         free( p_sys );
427         return VLC_ENOMEM;
428     }
429     free( val.psz_string );
430
431     var_Get( p_stream, SOUT_CFG_PREFIX_IN "placeholder", &val );
432     p_sys->b_placeholder = val.b_bool;
433
434     var_Get( p_stream, SOUT_CFG_PREFIX_IN "placeholder-delay", &val );
435     p_sys->i_placeholder_delay = (mtime_t)val.i_int * 1000;
436
437     p_sys->i_last_video = 0;
438     p_sys->i_last_audio = 0;
439     p_sys->id_video = NULL;
440     p_sys->id_audio = NULL;
441
442     p_stream->pf_add    = AddIn;
443     p_stream->pf_del    = DelIn;
444     p_stream->pf_send   = SendIn;
445
446     p_stream->p_sys     = (sout_stream_sys_t *)p_sys;
447
448     /* update p_sout->i_out_pace_nocontrol */
449     p_stream->p_sout->i_out_pace_nocontrol++;
450
451     return VLC_SUCCESS;
452 }
453
454 /*****************************************************************************
455  * CloseIn:
456  *****************************************************************************/
457 static void CloseIn( vlc_object_t * p_this )
458 {
459     sout_stream_t     *p_stream = (sout_stream_t*)p_this;
460     in_sout_stream_sys_t *p_sys = (in_sout_stream_sys_t *)p_stream->p_sys;
461
462     sout_StreamDelete( p_sys->p_out );
463     p_stream->p_sout->i_out_pace_nocontrol--;
464
465     free( p_sys->psz_name );
466     free( p_sys );
467 }
468
469 struct sout_stream_id_t
470 {
471     sout_stream_id_t *id;
472     int i_cat; /* es category. Used for placeholder option */
473 };
474
475 static sout_stream_id_t * AddIn( sout_stream_t *p_stream, es_format_t *p_fmt )
476 {
477     in_sout_stream_sys_t *p_sys = (in_sout_stream_sys_t *)p_stream->p_sys;
478
479     sout_stream_id_t *id = malloc( sizeof( sout_stream_id_t ) );
480     if( !id ) return NULL;
481
482     id->id = p_sys->p_out->pf_add( p_sys->p_out, p_fmt );
483     if( !id->id )
484     {
485         free( id );
486         return NULL;
487     }
488
489     if( p_sys->b_placeholder )
490     {
491         id->i_cat = p_fmt->i_cat;
492         switch( p_fmt->i_cat )
493         {
494             case VIDEO_ES:
495                 if( p_sys->id_video != NULL )
496                     msg_Err( p_stream, "We already had a video es!" );
497                 p_sys->id_video = id->id;
498                 break;
499             case AUDIO_ES:
500                 if( p_sys->id_audio != NULL )
501                     msg_Err( p_stream, "We already had an audio es!" );
502                 p_sys->id_audio = id->id;
503                 break;
504         }
505     }
506
507     return id;
508 }
509
510 static int DelIn( sout_stream_t *p_stream, sout_stream_id_t *id )
511 {
512     in_sout_stream_sys_t *p_sys = (in_sout_stream_sys_t *)p_stream->p_sys;
513
514     if( id == p_sys->id_video ) p_sys->id_video = NULL;
515     if( id == p_sys->id_audio ) p_sys->id_audio = NULL;
516
517     int ret = p_sys->p_out->pf_del( p_sys->p_out, id->id );
518
519     free( id );
520     return ret;
521 }
522
523 static int SendIn( sout_stream_t *p_stream, sout_stream_id_t *id,
524                    block_t *p_buffer )
525 {
526     in_sout_stream_sys_t *p_sys = (in_sout_stream_sys_t *)p_stream->p_sys;
527     bridge_t *p_bridge;
528     bool b_no_es = true;
529     int i;
530     int i_date = mdate();
531
532     /* First forward the packet for our own ES */
533     if( !p_sys->b_placeholder )
534         p_sys->p_out->pf_send( p_sys->p_out, id->id, p_buffer );
535
536     /* Then check all bridged streams */
537     vlc_mutex_lock( p_sys->p_lock );
538
539     p_bridge = GetBridge( p_stream, p_sys->psz_name );
540
541     if( p_bridge )
542     {
543     for ( i = 0; i < p_bridge->i_es_num; i++ )
544     {
545         if ( !p_bridge->pp_es[i]->b_empty )
546             b_no_es = false;
547
548         while ( p_bridge->pp_es[i]->p_block != NULL
549                  && (p_bridge->pp_es[i]->p_block->i_dts + p_sys->i_delay
550                        < i_date
551                       || p_bridge->pp_es[i]->p_block->i_dts + p_sys->i_delay
552                           < p_bridge->pp_es[i]->i_last) )
553         {
554             block_t *p_block = p_bridge->pp_es[i]->p_block;
555             msg_Dbg( p_stream, "dropping a packet (%"PRId64 ")",
556                      i_date - p_block->i_dts - p_sys->i_delay );
557             p_bridge->pp_es[i]->p_block
558                 = p_bridge->pp_es[i]->p_block->p_next;
559             block_Release( p_block );
560         }
561
562         if ( p_bridge->pp_es[i]->p_block == NULL )
563         {
564             p_bridge->pp_es[i]->pp_last = &p_bridge->pp_es[i]->p_block;
565         }
566
567         if ( p_bridge->pp_es[i]->b_changed )
568         {
569             if ( p_bridge->pp_es[i]->b_empty && p_bridge->pp_es[i]->id != NULL )
570             {
571                 p_sys->p_out->pf_del( p_sys->p_out, p_bridge->pp_es[i]->id );
572             }
573             else
574             {
575                 /* We need at least two packets to enter the mux. */
576                 if ( p_bridge->pp_es[i]->p_block == NULL
577                       || p_bridge->pp_es[i]->p_block->p_next == NULL )
578                 {
579                     continue;
580                 }
581
582                 p_bridge->pp_es[i]->fmt.i_id += p_sys->i_id_offset;
583                 p_bridge->pp_es[i]->id = p_sys->p_out->pf_add(
584                             p_sys->p_out, &p_bridge->pp_es[i]->fmt );
585                 if ( p_bridge->pp_es[i]->id == NULL )
586                 {
587                     msg_Warn( p_stream, "couldn't create chain for id %d",
588                               p_bridge->pp_es[i]->fmt.i_id );
589                 }
590                 msg_Dbg( p_stream, "bridging in input codec=%4.4s id=%d pos=%d",
591                          (char*)&p_bridge->pp_es[i]->fmt.i_codec,
592                          p_bridge->pp_es[i]->fmt.i_id, i );
593             }
594         }
595         p_bridge->pp_es[i]->b_changed = false;
596
597         if ( p_bridge->pp_es[i]->b_empty )
598             continue;
599
600         if ( p_bridge->pp_es[i]->p_block == NULL )
601         {
602             if ( p_bridge->pp_es[i]->id != NULL
603                   && p_bridge->pp_es[i]->i_last < i_date )
604             {
605                 p_sys->p_out->pf_del( p_sys->p_out, p_bridge->pp_es[i]->id );
606                 p_bridge->pp_es[i]->fmt.i_id -= p_sys->i_id_offset;
607                 p_bridge->pp_es[i]->b_changed = true;
608                 p_bridge->pp_es[i]->id = NULL;
609             }
610             continue;
611         }
612
613         if ( p_bridge->pp_es[i]->id != NULL )
614         {
615             block_t *p_block = p_bridge->pp_es[i]->p_block;
616             while ( p_block != NULL )
617             {
618                 p_bridge->pp_es[i]->i_last = p_block->i_dts;
619                 p_block->i_pts += p_sys->i_delay;
620                 p_block->i_dts += p_sys->i_delay;
621                 p_block = p_block->p_next;
622             }
623             sout_stream_id_t *newid = NULL;
624             if( p_sys->b_placeholder )
625             {
626                 switch( p_bridge->pp_es[i]->fmt.i_cat )
627                 {
628                     case VIDEO_ES:
629                         p_sys->i_last_video = i_date;
630                         newid = p_sys->id_video;
631                         break;
632                     case AUDIO_ES:
633                         newid = p_sys->id_audio;
634                         p_sys->i_last_audio = i_date;
635                         break;
636                 }
637             }
638             p_sys->p_out->pf_send( p_sys->p_out,
639                                    newid ? newid : p_bridge->pp_es[i]->id,
640                                    p_bridge->pp_es[i]->p_block );
641         }
642         else
643         {
644             block_ChainRelease( p_bridge->pp_es[i]->p_block );
645         }
646
647         p_bridge->pp_es[i]->p_block = NULL;
648         p_bridge->pp_es[i]->pp_last = &p_bridge->pp_es[i]->p_block;
649     }
650
651     if( b_no_es )
652     {
653         vlc_object_t *p_libvlc = VLC_OBJECT( p_stream->p_libvlc );
654         for ( i = 0; i < p_bridge->i_es_num; i++ )
655             free( p_bridge->pp_es[i] );
656         free( p_bridge->pp_es );
657         free( p_bridge );
658         var_Destroy( p_libvlc, p_sys->psz_name );
659     }
660     }
661
662     if( p_sys->b_placeholder )
663     {
664         switch( id->i_cat )
665         {
666             case VIDEO_ES:
667                 if( p_sys->i_last_video + p_sys->i_placeholder_delay < i_date )
668                     p_sys->p_out->pf_send( p_sys->p_out, id->id, p_buffer );
669                 else
670                     block_Release( p_buffer );
671                 break;
672
673             case AUDIO_ES:
674                 if( p_sys->i_last_audio + p_sys->i_placeholder_delay < i_date )
675                     p_sys->p_out->pf_send( p_sys->p_out, id->id, p_buffer );
676                 else
677                     block_Release( p_buffer );
678                 break;
679
680             default:
681                 block_Release( p_buffer ); /* FIXME: placeholder subs anyone? */
682                 break;
683         }
684     }
685
686     vlc_mutex_unlock( p_sys->p_lock );
687
688     return VLC_SUCCESS;
689 }