]> git.sesse.net Git - vlc/blob - modules/stream_out/description.c
0b88fee080b224c80a480322d730dc2d645f669c
[vlc] / modules / stream_out / description.c
1 /*****************************************************************************
2  * description.c: description stream output module (gathers ES info)
3  *****************************************************************************
4  * Copyright (C) 2003-2004 VideoLAN (Centrale Réseaux) and its contributors
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
8  *
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.
13  *
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.
18  *
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>
28 #include <string.h>
29
30 #include <vlc/vlc.h>
31 #include <vlc/input.h>
32 #include <vlc/sout.h>
33
34 /*****************************************************************************
35  * Exported prototypes
36  *****************************************************************************/
37 static int      Open    ( vlc_object_t * );
38 static void     Close   ( vlc_object_t * );
39
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* );
43
44 /*****************************************************************************
45  * Module descriptor
46  *****************************************************************************/
47 vlc_module_begin();
48     set_description( _("Description stream output") );
49     set_capability( "sout stream", 50 );
50     add_shortcut( "description" );
51     set_callbacks( Open, Close );
52 vlc_module_end();
53
54 struct sout_stream_sys_t
55 {
56     input_thread_t *p_input;
57     mtime_t i_stream_start;
58 };
59
60 struct sout_stream_id_t
61 {
62     int i_d_u_m_m_y;
63 };
64
65 /*****************************************************************************
66  * Open:
67  *****************************************************************************/
68 static int Open( vlc_object_t *p_this )
69 {
70     sout_stream_t *p_stream = (sout_stream_t*)p_this;
71     sout_stream_sys_t *p_sys;
72
73     p_stream->pf_add  = Add;
74     p_stream->pf_del  = Del;
75     p_stream->pf_send = Send;
76     p_sys = p_stream->p_sys = malloc(sizeof(sout_stream_sys_t));
77
78     p_sys->p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
79     if( !p_sys->p_input ) return VLC_EGENERIC;
80
81     p_sys->i_stream_start = 0;
82
83     return VLC_SUCCESS;
84 }
85
86 /*****************************************************************************
87  * Close:
88  *****************************************************************************/
89 static void Close( vlc_object_t *p_this )
90 {
91     sout_stream_t *p_stream = (sout_stream_t *)p_this;
92     vlc_object_release( p_stream->p_sys->p_input );
93 }
94
95 static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
96 {
97     sout_stream_sys_t *p_sys = p_stream->p_sys;
98     sout_stream_id_t *id;
99     es_format_t *p_fmt_copy = malloc(sizeof(es_format_t));
100
101     id = malloc( sizeof( sout_stream_id_t ) );
102     id->i_d_u_m_m_y = 0;
103
104     es_format_Copy( p_fmt_copy, p_fmt );
105
106     vlc_mutex_lock( &p_sys->p_input->input.p_item->lock );
107     TAB_APPEND( p_sys->p_input->input.p_item->i_es,
108                 p_sys->p_input->input.p_item->es, p_fmt_copy );
109     vlc_mutex_unlock( &p_sys->p_input->input.p_item->lock );
110
111     if( p_sys->i_stream_start <= 0 ) p_sys->i_stream_start = mdate();
112
113     return id;
114 }
115
116 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
117 {
118     free( id );
119     return VLC_SUCCESS;
120 }
121
122 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
123                  block_t *p_buffer )
124 {
125     sout_stream_sys_t *p_sys = p_stream->p_sys;
126
127     block_ChainRelease( p_buffer );
128
129     if( p_sys->i_stream_start + 1500000 < mdate() )
130     {
131         p_sys->p_input->b_eof = VLC_TRUE;
132     }
133
134     return VLC_SUCCESS;
135 }