]> git.sesse.net Git - vlc/blob - modules/stream_out/bridge.c
direct3d11: implement the pixel format fallback
[vlc] / modules / stream_out / bridge.c
1 /*****************************************************************************
2  * bridge.c: bridge stream output module
3  *****************************************************************************
4  * Copyright (C) 2005-2008 VLC authors and VideoLAN
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 it
11  * under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program; if not, write to the Free Software Foundation,
22  * 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_( "Placeholder delay" )
73 #define PLACEHOLDER_DELAY_LONGTEXT N_( \
74     "Delay (in ms) before the placeholder kicks in." )
75
76 #define PLACEHOLDER_IFRAME_TEXT N_( "Wait for I frame before toggling placeholder" )
77 #define PLACEHOLDER_IFRAME_LONGTEXT N_( \
78     "If enabled, switching between the placeholder and the normal stream " \
79     "will only occur on I frames. This will remove artifacts on stream " \
80     "switching at the expense of a slightly longer delay, depending on " \
81     "the frequence of I frames in the streams." )
82
83 static int  OpenOut ( vlc_object_t * );
84 static void CloseOut( vlc_object_t * );
85 static int  OpenIn  ( vlc_object_t * );
86 static void CloseIn ( vlc_object_t * );
87
88 #define SOUT_CFG_PREFIX_OUT "sout-bridge-out-"
89 #define SOUT_CFG_PREFIX_IN "sout-bridge-in-"
90
91 vlc_module_begin ()
92     set_shortname( N_("Bridge"))
93     set_description( N_("Bridge stream output"))
94     add_submodule ()
95     set_section( N_("Bridge out"), NULL )
96     set_capability( "sout stream", 50 )
97     add_shortcut( "bridge-out" )
98     /* Only usable with VLM. No category so not in gui preferences
99     set_category( CAT_SOUT )
100     set_subcategory( SUBCAT_SOUT_STREAM )*/
101     add_integer( SOUT_CFG_PREFIX_OUT "id", 0, ID_TEXT, ID_LONGTEXT,
102                  false )
103     add_string( SOUT_CFG_PREFIX_OUT "in-name", "default",
104                 DEST_TEXT, DEST_LONGTEXT, false )
105     set_callbacks( OpenOut, CloseOut )
106
107     add_submodule ()
108     set_section( N_("Bridge in"), NULL )
109     set_capability( "sout stream", 50 )
110     add_shortcut( "bridge-in" )
111     /*set_category( CAT_SOUT )
112     set_subcategory( SUBCAT_SOUT_STREAM )*/
113     add_integer( SOUT_CFG_PREFIX_IN "delay", 0, DELAY_TEXT,
114                  DELAY_LONGTEXT, false )
115     add_integer( SOUT_CFG_PREFIX_IN "id-offset", 8192, ID_OFFSET_TEXT,
116                  ID_OFFSET_LONGTEXT, false )
117     add_string( SOUT_CFG_PREFIX_IN "name", "default",
118                 NAME_TEXT, NAME_LONGTEXT, false )
119     add_bool( SOUT_CFG_PREFIX_IN "placeholder", false,
120               PLACEHOLDER_TEXT, PLACEHOLDER_LONGTEXT, false )
121     add_integer( SOUT_CFG_PREFIX_IN "placeholder-delay", 200,
122                  PLACEHOLDER_DELAY_TEXT, PLACEHOLDER_DELAY_LONGTEXT, false )
123     add_bool( SOUT_CFG_PREFIX_IN "placeholder-switch-on-iframe", true,
124               PLACEHOLDER_IFRAME_TEXT, PLACEHOLDER_IFRAME_LONGTEXT, false )
125     set_callbacks( OpenIn, CloseIn )
126
127 vlc_module_end ()
128
129
130 /*****************************************************************************
131  * Local prototypes
132  *****************************************************************************/
133 static const char *const ppsz_sout_options_out[] = {
134     "id", "in-name", NULL
135 };
136
137 static const char *const ppsz_sout_options_in[] = {
138     "delay", "id-offset", "name",
139     "placeholder", "placeholder-delay", "placeholder-switch-on-iframe",
140     NULL
141 };
142
143 static sout_stream_id_sys_t *AddOut( sout_stream_t *, const es_format_t * );
144 static void              DelOut ( sout_stream_t *, sout_stream_id_sys_t * );
145 static int               SendOut( sout_stream_t *, sout_stream_id_sys_t *, block_t * );
146
147 static sout_stream_id_sys_t *AddIn( sout_stream_t *, const es_format_t * );
148 static void              DelIn ( sout_stream_t *, sout_stream_id_sys_t * );
149 static int               SendIn( sout_stream_t *, sout_stream_id_sys_t *, block_t * );
150
151 typedef struct bridged_es_t
152 {
153     es_format_t fmt;
154     block_t *p_block;
155     block_t **pp_last;
156     bool b_empty;
157
158     /* bridge in part */
159     sout_stream_id_sys_t *id;
160     mtime_t i_last;
161     bool b_changed;
162 } bridged_es_t;
163
164 typedef struct bridge_t
165 {
166     bridged_es_t **pp_es;
167     int i_es_num;
168 } bridge_t;
169
170 static vlc_mutex_t lock = VLC_STATIC_MUTEX;
171
172 /*
173  * Bridge out
174  */
175
176 typedef struct out_sout_stream_sys_t
177 {
178     bridged_es_t *p_es;
179     int i_id;
180     bool b_inited;
181
182     char *psz_name;
183 } out_sout_stream_sys_t;
184
185 /*****************************************************************************
186  * OpenOut:
187  *****************************************************************************/
188 static int OpenOut( vlc_object_t *p_this )
189 {
190     sout_stream_t     *p_stream = (sout_stream_t *)p_this;
191     out_sout_stream_sys_t *p_sys;
192     vlc_value_t val;
193
194     config_ChainParse( p_stream, SOUT_CFG_PREFIX_OUT, ppsz_sout_options_out,
195                    p_stream->p_cfg );
196
197     p_sys          = malloc( sizeof( out_sout_stream_sys_t ) );
198     if( unlikely( !p_sys ) )
199         return VLC_ENOMEM;
200     p_sys->b_inited = false;
201
202     var_Get( p_stream, SOUT_CFG_PREFIX_OUT "id", &val );
203     p_sys->i_id = val.i_int;
204
205     var_Get( p_stream, SOUT_CFG_PREFIX_OUT "in-name", &val );
206     if( asprintf( &p_sys->psz_name, "bridge-struct-%s", val.psz_string )<0 )
207     {
208         free( val.psz_string );
209         free( p_sys );
210         return VLC_ENOMEM;
211     }
212     free( val.psz_string );
213
214     p_stream->pf_add    = AddOut;
215     p_stream->pf_del    = DelOut;
216     p_stream->pf_send   = SendOut;
217
218     p_stream->p_sys     = (sout_stream_sys_t *)p_sys;
219     p_stream->pace_nocontrol = true;
220
221     return VLC_SUCCESS;
222 }
223
224 /*****************************************************************************
225  * CloseOut:
226  *****************************************************************************/
227 static void CloseOut( vlc_object_t * p_this )
228 {
229     sout_stream_t     *p_stream = (sout_stream_t*)p_this;
230     out_sout_stream_sys_t *p_sys = (out_sout_stream_sys_t *)p_stream->p_sys;
231
232     free( p_sys->psz_name );
233     free( p_sys );
234 }
235
236 static sout_stream_id_sys_t * AddOut( sout_stream_t *p_stream, const es_format_t *p_fmt )
237 {
238     out_sout_stream_sys_t *p_sys = (out_sout_stream_sys_t *)p_stream->p_sys;
239     bridge_t *p_bridge;
240     bridged_es_t *p_es;
241     int i;
242
243     if ( p_sys->b_inited )
244     {
245         msg_Err( p_stream, "bridge-out can only handle 1 es at a time." );
246         return NULL;
247     }
248     p_sys->b_inited = true;
249
250     vlc_mutex_lock( &lock );
251
252     p_bridge = var_GetAddress( p_stream->p_libvlc, p_sys->psz_name );
253     if ( p_bridge == NULL )
254     {
255         p_bridge = xmalloc( sizeof( bridge_t ) );
256
257         var_Create( p_stream->p_libvlc, p_sys->psz_name, VLC_VAR_ADDRESS );
258         var_SetAddress( p_stream->p_libvlc, p_sys->psz_name, p_bridge );
259
260         p_bridge->i_es_num = 0;
261         p_bridge->pp_es = NULL;
262     }
263
264     for ( i = 0; i < p_bridge->i_es_num; i++ )
265     {
266         if ( p_bridge->pp_es[i]->b_empty && !p_bridge->pp_es[i]->b_changed )
267             break;
268     }
269
270     if ( i == p_bridge->i_es_num )
271     {
272         p_bridge->pp_es = xrealloc( p_bridge->pp_es,
273                           (p_bridge->i_es_num + 1) * sizeof(bridged_es_t *) );
274         p_bridge->i_es_num++;
275         p_bridge->pp_es[i] = xmalloc( sizeof(bridged_es_t) );
276     }
277
278     p_sys->p_es = p_es = p_bridge->pp_es[i];
279
280     p_es->fmt = *p_fmt;
281     p_es->fmt.i_id = p_sys->i_id;
282     p_es->p_block = NULL;
283     p_es->pp_last = &p_es->p_block;
284     p_es->b_empty = false;
285
286     p_es->id = NULL;
287     p_es->i_last = VLC_TS_INVALID;
288     p_es->b_changed = true;
289
290     msg_Dbg( p_stream, "bridging out input codec=%4.4s id=%d pos=%d",
291              (char*)&p_es->fmt.i_codec, p_es->fmt.i_id, i );
292
293     vlc_mutex_unlock( &lock );
294
295     return (sout_stream_id_sys_t *)p_sys;
296 }
297
298 static void DelOut( sout_stream_t *p_stream, sout_stream_id_sys_t *id )
299 {
300     VLC_UNUSED(id);
301     out_sout_stream_sys_t *p_sys = (out_sout_stream_sys_t *)p_stream->p_sys;
302     bridged_es_t *p_es;
303
304     if ( !p_sys->b_inited )
305         return;
306
307     vlc_mutex_lock( &lock );
308
309     p_es = p_sys->p_es;
310
311     p_es->b_empty = true;
312     block_ChainRelease( p_es->p_block );
313     p_es->p_block = false;
314
315     p_es->b_changed = true;
316     vlc_mutex_unlock( &lock );
317
318     p_sys->b_inited = false;
319 }
320
321 static int SendOut( sout_stream_t *p_stream, sout_stream_id_sys_t *id,
322                     block_t *p_buffer )
323 {
324     out_sout_stream_sys_t *p_sys = (out_sout_stream_sys_t *)p_stream->p_sys;
325     bridged_es_t *p_es;
326
327     if ( (out_sout_stream_sys_t *)id != p_sys )
328     {
329         block_ChainRelease( p_buffer );
330         return VLC_SUCCESS;
331     }
332
333     vlc_mutex_lock( &lock );
334
335     p_es = p_sys->p_es;
336     *p_es->pp_last = p_buffer;
337     while ( p_buffer != NULL )
338     {
339         p_es->pp_last = &p_buffer->p_next;
340         p_buffer = p_buffer->p_next;
341     }
342
343     vlc_mutex_unlock( &lock );
344
345     return VLC_SUCCESS;
346 }
347
348
349 /*
350  * Bridge in
351  */
352
353 typedef struct in_sout_stream_sys_t
354 {
355     int i_id_offset;
356     mtime_t i_delay;
357
358     char *psz_name;
359
360     bool b_placeholder;
361     bool b_switch_on_iframe;
362     int i_state;
363     mtime_t i_placeholder_delay;
364     sout_stream_id_sys_t *id_video;
365     mtime_t i_last_video;
366     sout_stream_id_sys_t *id_audio;
367     mtime_t i_last_audio;
368 } in_sout_stream_sys_t;
369
370 enum { placeholder_on, placeholder_off };
371
372 /*****************************************************************************
373  * OpenIn:
374  *****************************************************************************/
375 static int OpenIn( vlc_object_t *p_this )
376 {
377     sout_stream_t     *p_stream = (sout_stream_t*)p_this;
378     in_sout_stream_sys_t *p_sys;
379     vlc_value_t val;
380
381     p_sys          = malloc( sizeof( in_sout_stream_sys_t ) );
382     if( unlikely( !p_sys ) )
383         return VLC_ENOMEM;
384
385     if( !p_stream->p_next )
386     {
387         msg_Err( p_stream, "cannot create chain" );
388         free( p_sys );
389         return VLC_EGENERIC;
390     }
391
392     config_ChainParse( p_stream, SOUT_CFG_PREFIX_IN, ppsz_sout_options_in,
393                    p_stream->p_cfg );
394
395     var_Get( p_stream, SOUT_CFG_PREFIX_IN "id-offset", &val );
396     p_sys->i_id_offset = val.i_int;
397
398     var_Get( p_stream, SOUT_CFG_PREFIX_IN "delay", &val );
399     p_sys->i_delay = (mtime_t)val.i_int * 1000;
400
401     var_Get( p_stream, SOUT_CFG_PREFIX_IN "name", &val );
402     if( asprintf( &p_sys->psz_name, "bridge-struct-%s", val.psz_string )<0 )
403     {
404         free( val.psz_string );
405         free( p_sys );
406         return VLC_ENOMEM;
407     }
408     free( val.psz_string );
409
410     var_Get( p_stream, SOUT_CFG_PREFIX_IN "placeholder", &val );
411     p_sys->b_placeholder = val.b_bool;
412
413     var_Get( p_stream, SOUT_CFG_PREFIX_IN "placeholder-switch-on-iframe", &val);
414     p_sys->b_switch_on_iframe = val.b_bool;
415
416     p_sys->i_state = placeholder_on;
417
418     var_Get( p_stream, SOUT_CFG_PREFIX_IN "placeholder-delay", &val );
419     p_sys->i_placeholder_delay = (mtime_t)val.i_int * 1000;
420
421     p_sys->i_last_video = VLC_TS_INVALID;
422     p_sys->i_last_audio = VLC_TS_INVALID;
423     p_sys->id_video = NULL;
424     p_sys->id_audio = NULL;
425
426     p_stream->pf_add    = AddIn;
427     p_stream->pf_del    = DelIn;
428     p_stream->pf_send   = SendIn;
429
430     p_stream->p_sys     = (sout_stream_sys_t *)p_sys;
431     p_stream->pace_nocontrol = true;
432
433     return VLC_SUCCESS;
434 }
435
436 /*****************************************************************************
437  * CloseIn:
438  *****************************************************************************/
439 static void CloseIn( vlc_object_t * p_this )
440 {
441     sout_stream_t     *p_stream = (sout_stream_t*)p_this;
442     in_sout_stream_sys_t *p_sys = (in_sout_stream_sys_t *)p_stream->p_sys;
443
444     free( p_sys->psz_name );
445     free( p_sys );
446 }
447
448 struct sout_stream_id_sys_t
449 {
450     sout_stream_id_sys_t *id;
451     int i_cat; /* es category. Used for placeholder option */
452 };
453
454 static sout_stream_id_sys_t * AddIn( sout_stream_t *p_stream, const es_format_t *p_fmt )
455 {
456     in_sout_stream_sys_t *p_sys = (in_sout_stream_sys_t *)p_stream->p_sys;
457
458     sout_stream_id_sys_t *id = malloc( sizeof( sout_stream_id_sys_t ) );
459     if( !id ) return NULL;
460
461     id->id = p_stream->p_next->pf_add( p_stream->p_next, p_fmt );
462     if( !id->id )
463     {
464         free( id );
465         return NULL;
466     }
467
468     if( p_sys->b_placeholder )
469     {
470         id->i_cat = p_fmt->i_cat;
471         switch( p_fmt->i_cat )
472         {
473             case VIDEO_ES:
474                 if( p_sys->id_video != NULL )
475                     msg_Err( p_stream, "We already had a video es!" );
476                 p_sys->id_video = id->id;
477                 break;
478             case AUDIO_ES:
479                 if( p_sys->id_audio != NULL )
480                     msg_Err( p_stream, "We already had an audio es!" );
481                 p_sys->id_audio = id->id;
482                 break;
483         }
484     }
485
486     return id;
487 }
488
489 static void DelIn( sout_stream_t *p_stream, sout_stream_id_sys_t *id )
490 {
491     in_sout_stream_sys_t *p_sys = (in_sout_stream_sys_t *)p_stream->p_sys;
492
493     if( id == p_sys->id_video ) p_sys->id_video = NULL;
494     if( id == p_sys->id_audio ) p_sys->id_audio = NULL;
495
496     p_stream->p_next->pf_del( p_stream->p_next, id->id );
497     free( id );
498 }
499
500 static int SendIn( sout_stream_t *p_stream, sout_stream_id_sys_t *id,
501                    block_t *p_buffer )
502 {
503     in_sout_stream_sys_t *p_sys = (in_sout_stream_sys_t *)p_stream->p_sys;
504     bridge_t *p_bridge;
505     bool b_no_es = true;
506     int i;
507     int i_date = mdate();
508
509     /* First forward the packet for our own ES */
510     if( !p_sys->b_placeholder )
511         p_stream->p_next->pf_send( p_stream->p_next, id->id, p_buffer );
512
513     /* Then check all bridged streams */
514     vlc_mutex_lock( &lock );
515
516     p_bridge = var_GetAddress( p_stream->p_libvlc, p_sys->psz_name );
517
518     if( p_bridge )
519     {
520     for ( i = 0; i < p_bridge->i_es_num; i++ )
521     {
522         if ( !p_bridge->pp_es[i]->b_empty )
523             b_no_es = false;
524
525         while ( p_bridge->pp_es[i]->p_block != NULL
526                  && (p_bridge->pp_es[i]->p_block->i_dts + p_sys->i_delay
527                        < i_date
528                       || p_bridge->pp_es[i]->p_block->i_dts + p_sys->i_delay
529                           < p_bridge->pp_es[i]->i_last) )
530         {
531             block_t *p_block = p_bridge->pp_es[i]->p_block;
532             msg_Dbg( p_stream, "dropping a packet (%"PRId64 ")",
533                      i_date - p_block->i_dts - p_sys->i_delay );
534             p_bridge->pp_es[i]->p_block
535                 = p_bridge->pp_es[i]->p_block->p_next;
536             block_Release( p_block );
537         }
538
539         if ( p_bridge->pp_es[i]->p_block == NULL )
540         {
541             p_bridge->pp_es[i]->pp_last = &p_bridge->pp_es[i]->p_block;
542         }
543
544         if ( p_bridge->pp_es[i]->b_changed )
545         {
546             if ( p_bridge->pp_es[i]->b_empty && p_bridge->pp_es[i]->id != NULL )
547             {
548                 p_stream->p_next->pf_del( p_stream->p_next, p_bridge->pp_es[i]->id );
549             }
550             else
551             {
552                 /* We need at least two packets to enter the mux. */
553                 if ( p_bridge->pp_es[i]->p_block == NULL
554                       || p_bridge->pp_es[i]->p_block->p_next == NULL )
555                 {
556                     continue;
557                 }
558
559                 p_bridge->pp_es[i]->fmt.i_id += p_sys->i_id_offset;
560                 if( !p_sys->b_placeholder )
561                 {
562                     p_bridge->pp_es[i]->id = p_stream->p_next->pf_add(
563                                 p_stream->p_next, &p_bridge->pp_es[i]->fmt );
564                     if ( p_bridge->pp_es[i]->id == NULL )
565                     {
566                         msg_Warn( p_stream, "couldn't create chain for id %d",
567                                   p_bridge->pp_es[i]->fmt.i_id );
568                     }
569                 }
570                 msg_Dbg( p_stream, "bridging in input codec=%4.4s id=%d pos=%d",
571                          (char*)&p_bridge->pp_es[i]->fmt.i_codec,
572                          p_bridge->pp_es[i]->fmt.i_id, i );
573             }
574         }
575         p_bridge->pp_es[i]->b_changed = false;
576
577         if ( p_bridge->pp_es[i]->b_empty )
578             continue;
579
580         if ( p_bridge->pp_es[i]->p_block == NULL )
581         {
582             if ( p_bridge->pp_es[i]->id != NULL
583                   && p_bridge->pp_es[i]->i_last < i_date )
584             {
585                 if( !p_sys->b_placeholder )
586                     p_stream->p_next->pf_del( p_stream->p_next,
587                                           p_bridge->pp_es[i]->id );
588                 p_bridge->pp_es[i]->fmt.i_id -= p_sys->i_id_offset;
589                 p_bridge->pp_es[i]->b_changed = true;
590                 p_bridge->pp_es[i]->id = NULL;
591             }
592             continue;
593         }
594
595         if ( p_bridge->pp_es[i]->id != NULL || p_sys->b_placeholder)
596         {
597             block_t *p_block = p_bridge->pp_es[i]->p_block;
598             while ( p_block != NULL )
599             {
600                 p_bridge->pp_es[i]->i_last = p_block->i_dts;
601                 p_block->i_pts += p_sys->i_delay;
602                 p_block->i_dts += p_sys->i_delay;
603                 p_block = p_block->p_next;
604             }
605             sout_stream_id_sys_t *newid = NULL;
606             if( p_sys->b_placeholder )
607             {
608                 switch( p_bridge->pp_es[i]->fmt.i_cat )
609                 {
610                     case VIDEO_ES:
611                         p_sys->i_last_video = i_date;
612                         newid = p_sys->id_video;
613                         if( !newid )
614                             break;
615                         if( !p_sys->b_switch_on_iframe ||
616                             p_sys->i_state == placeholder_off ||
617                             ( p_bridge->pp_es[i]->fmt.i_cat == VIDEO_ES &&
618                               p_bridge->pp_es[i]->p_block->i_flags & BLOCK_FLAG_TYPE_I ) )
619                         {
620                             p_stream->p_next->pf_send( p_stream->p_next,
621                                        newid,
622                                        p_bridge->pp_es[i]->p_block );
623                             p_sys->i_state = placeholder_off;
624                         }
625                         break;
626                     case AUDIO_ES:
627                         newid = p_sys->id_audio;
628                         if( !newid )
629                             break;
630                         p_sys->i_last_audio = i_date;
631                     default:
632                         p_stream->p_next->pf_send( p_stream->p_next,
633                                    newid?newid:p_bridge->pp_es[i]->id,
634                                    p_bridge->pp_es[i]->p_block );
635                         break;
636                 }
637             }
638             else /* !b_placeholder */
639                 p_stream->p_next->pf_send( p_stream->p_next,
640                                        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         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_stream->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->b_switch_on_iframe
669                        || p_buffer->i_flags & BLOCK_FLAG_TYPE_I ) )
670                   || p_sys->i_state == placeholder_on )
671                 {
672                     p_stream->p_next->pf_send( p_stream->p_next, id->id, p_buffer );
673                     p_sys->i_state = placeholder_on;
674                 }
675                 else
676                     block_Release( p_buffer );
677                 break;
678
679             case AUDIO_ES:
680                 if( p_sys->i_last_audio + p_sys->i_placeholder_delay < i_date )
681                     p_stream->p_next->pf_send( p_stream->p_next, id->id, p_buffer );
682                 else
683                     block_Release( p_buffer );
684                 break;
685
686             default:
687                 block_Release( p_buffer ); /* FIXME: placeholder subs anyone? */
688                 break;
689         }
690     }
691
692     vlc_mutex_unlock( &lock );
693
694     return VLC_SUCCESS;
695 }