| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
#ifdef HAVE_CONFIG_H |
|---|
| 29 |
# include "config.h" |
|---|
| 30 |
#endif |
|---|
| 31 |
|
|---|
| 32 |
#include <vlc_common.h> |
|---|
| 33 |
#include <vlc_plugin.h> |
|---|
| 34 |
#include <vlc_sout.h> |
|---|
| 35 |
#include <vlc_block.h> |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
static int Open ( vlc_object_t * ); |
|---|
| 41 |
static void Close ( vlc_object_t * ); |
|---|
| 42 |
|
|---|
| 43 |
#define SOUT_CFG_PREFIX "sout-autodel-" |
|---|
| 44 |
|
|---|
| 45 |
vlc_module_begin(); |
|---|
| 46 |
set_shortname( N_("Autodel")); |
|---|
| 47 |
set_description( N_("Automatically add/delete input streams")); |
|---|
| 48 |
set_capability( "sout stream", 50 ); |
|---|
| 49 |
add_shortcut( "autodel" ); |
|---|
| 50 |
set_callbacks( Open, Close ); |
|---|
| 51 |
vlc_module_end(); |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * ); |
|---|
| 58 |
static int Del ( sout_stream_t *, sout_stream_id_t * ); |
|---|
| 59 |
static int Send ( sout_stream_t *, sout_stream_id_t *, block_t * ); |
|---|
| 60 |
|
|---|
| 61 |
struct sout_stream_id_t |
|---|
| 62 |
{ |
|---|
| 63 |
sout_stream_id_t *id; |
|---|
| 64 |
es_format_t fmt; |
|---|
| 65 |
mtime_t i_last; |
|---|
| 66 |
bool b_error; |
|---|
| 67 |
}; |
|---|
| 68 |
|
|---|
| 69 |
struct sout_stream_sys_t |
|---|
| 70 |
{ |
|---|
| 71 |
sout_stream_t *p_out; |
|---|
| 72 |
sout_stream_id_t **pp_es; |
|---|
| 73 |
int i_es_num; |
|---|
| 74 |
}; |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
static int Open( vlc_object_t *p_this ) |
|---|
| 80 |
{ |
|---|
| 81 |
sout_stream_t *p_stream = (sout_stream_t*)p_this; |
|---|
| 82 |
sout_stream_sys_t *p_sys; |
|---|
| 83 |
|
|---|
| 84 |
p_sys = malloc( sizeof( sout_stream_sys_t ) ); |
|---|
| 85 |
|
|---|
| 86 |
p_sys->p_out = sout_StreamNew( p_stream->p_sout, p_stream->psz_next ); |
|---|
| 87 |
if( !p_sys->p_out ) |
|---|
| 88 |
{ |
|---|
| 89 |
msg_Err( p_stream, "cannot create chain" ); |
|---|
| 90 |
free( p_sys ); |
|---|
| 91 |
return VLC_EGENERIC; |
|---|
| 92 |
} |
|---|
| 93 |
p_sys->pp_es = NULL; |
|---|
| 94 |
p_sys->i_es_num = 0; |
|---|
| 95 |
|
|---|
| 96 |
p_stream->pf_add = Add; |
|---|
| 97 |
p_stream->pf_del = Del; |
|---|
| 98 |
p_stream->pf_send = Send; |
|---|
| 99 |
|
|---|
| 100 |
p_stream->p_sys = p_sys; |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
p_stream->p_sout->i_out_pace_nocontrol++; |
|---|
| 104 |
|
|---|
| 105 |
return VLC_SUCCESS; |
|---|
| 106 |
} |
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
static void Close( vlc_object_t * p_this ) |
|---|
| 112 |
{ |
|---|
| 113 |
sout_stream_t *p_stream = (sout_stream_t*)p_this; |
|---|
| 114 |
sout_stream_sys_t *p_sys = (sout_stream_sys_t *)p_stream->p_sys; |
|---|
| 115 |
|
|---|
| 116 |
sout_StreamDelete( p_sys->p_out ); |
|---|
| 117 |
p_stream->p_sout->i_out_pace_nocontrol--; |
|---|
| 118 |
|
|---|
| 119 |
free( p_sys ); |
|---|
| 120 |
} |
|---|
| 121 |
|
|---|
| 122 |
static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt ) |
|---|
| 123 |
{ |
|---|
| 124 |
sout_stream_sys_t *p_sys = (sout_stream_sys_t *)p_stream->p_sys; |
|---|
| 125 |
sout_stream_id_t *p_es = malloc( sizeof(sout_stream_id_t) ); |
|---|
| 126 |
|
|---|
| 127 |
p_es->fmt = *p_fmt; |
|---|
| 128 |
p_es->id = NULL; |
|---|
| 129 |
p_es->i_last = 0; |
|---|
| 130 |
p_es->b_error = false; |
|---|
| 131 |
TAB_APPEND( p_sys->i_es_num, p_sys->pp_es, p_es ); |
|---|
| 132 |
|
|---|
| 133 |
return p_es; |
|---|
| 134 |
} |
|---|
| 135 |
|
|---|
| 136 |
static int Del( sout_stream_t *p_stream, sout_stream_id_t *p_es ) |
|---|
| 137 |
{ |
|---|
| 138 |
sout_stream_sys_t *p_sys = (sout_stream_sys_t *)p_stream->p_sys; |
|---|
| 139 |
sout_stream_id_t *id = p_es->id; |
|---|
| 140 |
|
|---|
| 141 |
TAB_REMOVE( p_sys->i_es_num, p_sys->pp_es, p_es ); |
|---|
| 142 |
free( p_es ); |
|---|
| 143 |
|
|---|
| 144 |
if ( id != NULL ) |
|---|
| 145 |
return p_sys->p_out->pf_del( p_sys->p_out, id ); |
|---|
| 146 |
else |
|---|
| 147 |
return VLC_SUCCESS; |
|---|
| 148 |
} |
|---|
| 149 |
|
|---|
| 150 |
static int Send( sout_stream_t *p_stream, sout_stream_id_t *p_es, |
|---|
| 151 |
block_t *p_buffer ) |
|---|
| 152 |
{ |
|---|
| 153 |
sout_stream_sys_t *p_sys = (sout_stream_sys_t *)p_stream->p_sys; |
|---|
| 154 |
mtime_t i_current = mdate(); |
|---|
| 155 |
int i; |
|---|
| 156 |
|
|---|
| 157 |
p_es->i_last = p_buffer->i_dts; |
|---|
| 158 |
if ( p_es->id == NULL && p_es->b_error != true ) |
|---|
| 159 |
{ |
|---|
| 160 |
p_es->id = p_sys->p_out->pf_add( p_sys->p_out, &p_es->fmt ); |
|---|
| 161 |
if ( p_es->id == NULL ) |
|---|
| 162 |
{ |
|---|
| 163 |
p_es->b_error = true; |
|---|
| 164 |
msg_Err( p_stream, "couldn't create chain for id %d", |
|---|
| 165 |
p_es->fmt.i_id ); |
|---|
| 166 |
} |
|---|
| 167 |
} |
|---|
| 168 |
|
|---|
| 169 |
if ( p_es->b_error != true ) |
|---|
| 170 |
p_sys->p_out->pf_send( p_sys->p_out, p_es->id, p_buffer ); |
|---|
| 171 |
else |
|---|
| 172 |
block_ChainRelease( p_buffer ); |
|---|
| 173 |
|
|---|
| 174 |
for ( i = 0; i < p_sys->i_es_num; i++ ) |
|---|
| 175 |
{ |
|---|
| 176 |
if ( p_sys->pp_es[i]->id != NULL |
|---|
| 177 |
&& (p_sys->pp_es[i]->fmt.i_cat == VIDEO_ES |
|---|
| 178 |
|| p_sys->pp_es[i]->fmt.i_cat == AUDIO_ES) |
|---|
| 179 |
&& p_sys->pp_es[i]->i_last < i_current ) |
|---|
| 180 |
{ |
|---|
| 181 |
p_sys->p_out->pf_del( p_sys->p_out, p_sys->pp_es[i]->id ); |
|---|
| 182 |
p_sys->pp_es[i]->id = NULL; |
|---|
| 183 |
} |
|---|
| 184 |
} |
|---|
| 185 |
|
|---|
| 186 |
return VLC_SUCCESS; |
|---|
| 187 |
} |
|---|