| 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_input.h> |
|---|
| 35 |
#include <vlc_sout.h> |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
static int Open ( vlc_object_t * ); |
|---|
| 41 |
static void Close ( vlc_object_t * ); |
|---|
| 42 |
|
|---|
| 43 |
vlc_module_begin(); |
|---|
| 44 |
set_description( N_("Gathering stream output") ); |
|---|
| 45 |
set_capability( "sout stream", 50 ); |
|---|
| 46 |
add_shortcut( "gather" ); |
|---|
| 47 |
set_callbacks( Open, Close ); |
|---|
| 48 |
vlc_module_end(); |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * ); |
|---|
| 54 |
static int Del ( sout_stream_t *, sout_stream_id_t * ); |
|---|
| 55 |
static int Send( sout_stream_t *, sout_stream_id_t *, block_t* ); |
|---|
| 56 |
|
|---|
| 57 |
struct sout_stream_id_t |
|---|
| 58 |
{ |
|---|
| 59 |
bool b_used; |
|---|
| 60 |
|
|---|
| 61 |
es_format_t fmt; |
|---|
| 62 |
void *id; |
|---|
| 63 |
}; |
|---|
| 64 |
|
|---|
| 65 |
struct sout_stream_sys_t |
|---|
| 66 |
{ |
|---|
| 67 |
sout_stream_t *p_out; |
|---|
| 68 |
|
|---|
| 69 |
int i_id; |
|---|
| 70 |
sout_stream_id_t **id; |
|---|
| 71 |
}; |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
static int Open( vlc_object_t *p_this ) |
|---|
| 77 |
{ |
|---|
| 78 |
sout_stream_t *p_stream = (sout_stream_t*)p_this; |
|---|
| 79 |
sout_stream_sys_t *p_sys; |
|---|
| 80 |
|
|---|
| 81 |
p_stream->p_sys = p_sys = malloc( sizeof( sout_stream_sys_t ) ); |
|---|
| 82 |
if( p_sys == NULL ) |
|---|
| 83 |
return VLC_EGENERIC; |
|---|
| 84 |
|
|---|
| 85 |
p_sys->p_out = sout_StreamNew( p_stream->p_sout, p_stream->psz_next ); |
|---|
| 86 |
if( p_sys->p_out == NULL ) |
|---|
| 87 |
{ |
|---|
| 88 |
free( p_sys ); |
|---|
| 89 |
return VLC_EGENERIC; |
|---|
| 90 |
} |
|---|
| 91 |
p_stream->pf_add = Add; |
|---|
| 92 |
p_stream->pf_del = Del; |
|---|
| 93 |
p_stream->pf_send = Send; |
|---|
| 94 |
|
|---|
| 95 |
TAB_INIT( p_sys->i_id, p_sys->id ); |
|---|
| 96 |
|
|---|
| 97 |
return VLC_SUCCESS; |
|---|
| 98 |
} |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
static void Close( vlc_object_t * p_this ) |
|---|
| 104 |
{ |
|---|
| 105 |
sout_stream_t *p_stream = (sout_stream_t*)p_this; |
|---|
| 106 |
sout_stream_sys_t *p_sys = p_stream->p_sys; |
|---|
| 107 |
int i; |
|---|
| 108 |
|
|---|
| 109 |
for( i = 0; i < p_sys->i_id; i++ ) |
|---|
| 110 |
{ |
|---|
| 111 |
sout_stream_id_t *id = p_sys->id[i]; |
|---|
| 112 |
|
|---|
| 113 |
sout_StreamIdDel( p_sys->p_out, id->id ); |
|---|
| 114 |
es_format_Clean( &id->fmt ); |
|---|
| 115 |
free( id ); |
|---|
| 116 |
} |
|---|
| 117 |
TAB_CLEAN( p_sys->i_id, p_sys->id ); |
|---|
| 118 |
|
|---|
| 119 |
sout_StreamDelete( p_sys->p_out ); |
|---|
| 120 |
free( p_sys ); |
|---|
| 121 |
} |
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt ) |
|---|
| 127 |
{ |
|---|
| 128 |
sout_stream_sys_t *p_sys = p_stream->p_sys; |
|---|
| 129 |
sout_stream_id_t *id; |
|---|
| 130 |
int i; |
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
for( i = 0; i < p_sys->i_id; i++ ) |
|---|
| 134 |
{ |
|---|
| 135 |
id = p_sys->id[i]; |
|---|
| 136 |
if( id->b_used ) |
|---|
| 137 |
continue; |
|---|
| 138 |
|
|---|
| 139 |
if( id->fmt.i_cat != p_fmt->i_cat || id->fmt.i_codec != p_fmt->i_codec ) |
|---|
| 140 |
continue; |
|---|
| 141 |
|
|---|
| 142 |
if( id->fmt.i_cat == AUDIO_ES ) |
|---|
| 143 |
{ |
|---|
| 144 |
audio_format_t *p_a = &id->fmt.audio; |
|---|
| 145 |
if( p_a->i_rate != p_fmt->audio.i_rate || |
|---|
| 146 |
p_a->i_channels != p_fmt->audio.i_channels || |
|---|
| 147 |
p_a->i_blockalign != p_fmt->audio.i_blockalign ) |
|---|
| 148 |
continue; |
|---|
| 149 |
} |
|---|
| 150 |
else if( id->fmt.i_cat == VIDEO_ES ) |
|---|
| 151 |
{ |
|---|
| 152 |
video_format_t *p_v = &id->fmt.video; |
|---|
| 153 |
if( p_v->i_width != p_fmt->video.i_width || |
|---|
| 154 |
p_v->i_height != p_fmt->video.i_height ) |
|---|
| 155 |
continue; |
|---|
| 156 |
} |
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
msg_Dbg( p_stream, "reusing already opened output" ); |
|---|
| 160 |
id->b_used = true; |
|---|
| 161 |
return id; |
|---|
| 162 |
} |
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
for( i = 0; i < p_sys->i_id; i++ ) |
|---|
| 166 |
{ |
|---|
| 167 |
id = p_sys->id[i]; |
|---|
| 168 |
if( !id->b_used && id->fmt.i_cat == p_fmt->i_cat ) |
|---|
| 169 |
{ |
|---|
| 170 |
TAB_REMOVE( p_sys->i_id, p_sys->id, id ); |
|---|
| 171 |
sout_StreamIdDel( p_sys->p_out, id->id ); |
|---|
| 172 |
es_format_Clean( &id->fmt ); |
|---|
| 173 |
free( id ); |
|---|
| 174 |
|
|---|
| 175 |
i = 0; |
|---|
| 176 |
continue; |
|---|
| 177 |
} |
|---|
| 178 |
} |
|---|
| 179 |
|
|---|
| 180 |
msg_Dbg( p_stream, "creating new output" ); |
|---|
| 181 |
id = malloc( sizeof( sout_stream_id_t ) ); |
|---|
| 182 |
if( id == NULL ) |
|---|
| 183 |
return NULL; |
|---|
| 184 |
es_format_Copy( &id->fmt, p_fmt ); |
|---|
| 185 |
id->b_used = true; |
|---|
| 186 |
id->id = sout_StreamIdAdd( p_sys->p_out, &id->fmt ); |
|---|
| 187 |
if( id->id == NULL ) |
|---|
| 188 |
{ |
|---|
| 189 |
free( id ); |
|---|
| 190 |
return NULL; |
|---|
| 191 |
} |
|---|
| 192 |
TAB_APPEND( p_sys->i_id, p_sys->id, id ); |
|---|
| 193 |
|
|---|
| 194 |
return id; |
|---|
| 195 |
} |
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
static int Del( sout_stream_t *p_stream, sout_stream_id_t *id ) |
|---|
| 201 |
{ |
|---|
| 202 |
VLC_UNUSED(p_stream); |
|---|
| 203 |
id->b_used = false; |
|---|
| 204 |
return VLC_SUCCESS; |
|---|
| 205 |
} |
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
static int Send( sout_stream_t *p_stream, |
|---|
| 211 |
sout_stream_id_t *id, block_t *p_buffer ) |
|---|
| 212 |
{ |
|---|
| 213 |
sout_stream_sys_t *p_sys = p_stream->p_sys; |
|---|
| 214 |
|
|---|
| 215 |
return sout_StreamIdSend( p_sys->p_out, id->id, p_buffer ); |
|---|
| 216 |
} |
|---|