]> git.sesse.net Git - vlc/blob - modules/stream_out/description.c
Removes trailing spaces. Removes tabs.
[vlc] / modules / stream_out / description.c
1 /*****************************************************************************
2  * description.c: description stream output module (gathers ES info)
3  *****************************************************************************
4  * Copyright (C) 2003-2004 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27
28 #include <vlc/vlc.h>
29 #include <vlc_input.h>
30 #include <vlc_block.h>
31 #include <vlc_sout.h>
32
33 /*****************************************************************************
34  * Exported prototypes
35  *****************************************************************************/
36 static int      Open    ( vlc_object_t * );
37 static void     Close   ( vlc_object_t * );
38
39 static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
40 static int               Del ( sout_stream_t *, sout_stream_id_t * );
41 static int               Send( sout_stream_t *, sout_stream_id_t *, block_t* );
42
43 /*****************************************************************************
44  * Module descriptor
45  *****************************************************************************/
46 vlc_module_begin();
47     set_description( _("Description stream output") );
48     set_capability( "sout stream", 50 );
49     add_shortcut( "description" );
50     set_callbacks( Open, Close );
51 vlc_module_end();
52
53 struct sout_stream_sys_t
54 {
55     int            i_id;
56     input_thread_t *p_input;
57
58     mtime_t i_stream_start;
59 };
60
61 struct sout_stream_id_t
62 {
63     int i_d_u_m_m_y;
64 };
65
66 /*****************************************************************************
67  * Open:
68  *****************************************************************************/
69 static int Open( vlc_object_t *p_this )
70 {
71     sout_stream_t *p_stream = (sout_stream_t*)p_this;
72     sout_stream_sys_t *p_sys;
73
74     p_stream->pf_add  = Add;
75     p_stream->pf_del  = Del;
76     p_stream->pf_send = Send;
77     p_sys = p_stream->p_sys = malloc(sizeof(sout_stream_sys_t));
78
79     p_sys->i_id = 0;
80     p_sys->p_input = NULL;
81
82     p_sys->i_stream_start = 0;
83
84     return VLC_SUCCESS;
85 }
86
87 /*****************************************************************************
88  * Close:
89  *****************************************************************************/
90 static void Close( vlc_object_t *p_this )
91 {
92     sout_stream_t *p_stream = (sout_stream_t *)p_this;
93     sout_stream_sys_t *p_sys = p_stream->p_sys;
94
95     /* It can happen only if buggy */
96     if( p_sys->p_input )
97         vlc_object_release( p_sys->p_input );
98     free( p_sys );
99 }
100
101 static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
102 {
103     sout_stream_sys_t *p_sys = p_stream->p_sys;
104     sout_stream_id_t *id;
105     es_format_t *p_fmt_copy;
106     input_item_t *p_item;
107
108     if( !p_sys->p_input )
109         p_sys->p_input = vlc_object_find( p_stream, VLC_OBJECT_INPUT, FIND_PARENT );
110     if( !p_sys->p_input )
111         return NULL;
112  
113     p_item = input_GetItem(p_sys->p_input);
114
115     p_fmt_copy = malloc(sizeof(es_format_t));
116     es_format_Copy( p_fmt_copy, p_fmt );
117
118     vlc_mutex_lock( &p_item->lock );
119     TAB_APPEND( p_item->i_es, p_item->es, p_fmt_copy );
120     vlc_mutex_unlock( &p_item->lock );
121
122     p_sys->i_id++;
123     if( p_sys->i_stream_start <= 0 )
124         p_sys->i_stream_start = mdate();
125
126     id = malloc( sizeof( sout_stream_id_t ) );
127     id->i_d_u_m_m_y = 0;
128     return id;
129 }
130
131 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
132 {
133     sout_stream_sys_t *p_sys = p_stream->p_sys;
134
135     p_sys->i_id--;
136     if( p_sys->i_id <= 0 )
137     {
138         vlc_object_release( p_sys->p_input );
139         p_sys->p_input = NULL;
140     }
141
142     free( id );
143     return VLC_SUCCESS;
144 }
145
146 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
147                  block_t *p_buffer )
148 {
149     sout_stream_sys_t *p_sys = p_stream->p_sys;
150
151     block_ChainRelease( p_buffer );
152
153     if( p_sys->p_input && p_sys->i_stream_start + 1500000 < mdate() )
154         p_sys->p_input->b_eof = VLC_TRUE;
155
156     return VLC_SUCCESS;
157 }