1 /*****************************************************************************
2 * description.c: description stream output module (gathers ES info)
3 *****************************************************************************
4 * Copyright (C) 2003-2004 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
30 #include <vlc_input.h>
31 #include <vlc_block.h>
34 /*****************************************************************************
36 *****************************************************************************/
37 static int Open ( vlc_object_t * );
38 static void Close ( vlc_object_t * );
40 static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
41 static int Del ( sout_stream_t *, sout_stream_id_t * );
42 static int Send( sout_stream_t *, sout_stream_id_t *, block_t* );
44 /*****************************************************************************
46 *****************************************************************************/
48 set_description( _("Description stream output") );
49 set_capability( "sout stream", 50 );
50 add_shortcut( "description" );
51 set_callbacks( Open, Close );
54 struct sout_stream_sys_t
57 input_thread_t *p_input;
59 mtime_t i_stream_start;
62 struct sout_stream_id_t
67 /*****************************************************************************
69 *****************************************************************************/
70 static int Open( vlc_object_t *p_this )
72 sout_stream_t *p_stream = (sout_stream_t*)p_this;
73 sout_stream_sys_t *p_sys;
75 p_stream->pf_add = Add;
76 p_stream->pf_del = Del;
77 p_stream->pf_send = Send;
78 p_sys = p_stream->p_sys = malloc(sizeof(sout_stream_sys_t));
81 p_sys->p_input = NULL;
83 p_sys->i_stream_start = 0;
88 /*****************************************************************************
90 *****************************************************************************/
91 static void Close( vlc_object_t *p_this )
93 sout_stream_t *p_stream = (sout_stream_t *)p_this;
94 sout_stream_sys_t *p_sys = p_stream->p_sys;
96 /* It can happen only if buggy */
98 vlc_object_release( p_sys->p_input );
102 static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
104 sout_stream_sys_t *p_sys = p_stream->p_sys;
105 sout_stream_id_t *id;
106 es_format_t *p_fmt_copy;
107 input_item_t *p_item;
109 if( !p_sys->p_input )
110 p_sys->p_input = vlc_object_find( p_stream, VLC_OBJECT_INPUT, FIND_PARENT );
111 if( !p_sys->p_input )
114 p_item = input_GetItem(p_sys->p_input);
116 p_fmt_copy = malloc(sizeof(es_format_t));
117 es_format_Copy( p_fmt_copy, p_fmt );
119 vlc_mutex_lock( &p_item->lock );
120 TAB_APPEND( p_item->i_es, p_item->es, p_fmt_copy );
121 vlc_mutex_unlock( &p_item->lock );
124 if( p_sys->i_stream_start <= 0 )
125 p_sys->i_stream_start = mdate();
127 id = malloc( sizeof( sout_stream_id_t ) );
132 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
134 sout_stream_sys_t *p_sys = p_stream->p_sys;
137 if( p_sys->i_id <= 0 )
139 vlc_object_release( p_sys->p_input );
140 p_sys->p_input = NULL;
147 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
150 sout_stream_sys_t *p_sys = p_stream->p_sys;
152 block_ChainRelease( p_buffer );
154 if( p_sys->p_input && p_sys->i_stream_start + 1500000 < mdate() )
155 p_sys->p_input->b_eof = VLC_TRUE;