]> git.sesse.net Git - vlc/blob - modules/stream_out/description.c
Include vlc_plugin.h as needed
[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 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc/vlc.h>
33 #include <vlc_plugin.h>
34 #include <vlc_input.h>
35 #include <vlc_block.h>
36 #include <vlc_sout.h>
37
38 /*****************************************************************************
39  * Exported prototypes
40  *****************************************************************************/
41 static int      Open    ( vlc_object_t * );
42 static void     Close   ( vlc_object_t * );
43
44 static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
45 static int               Del ( sout_stream_t *, sout_stream_id_t * );
46 static int               Send( sout_stream_t *, sout_stream_id_t *, block_t* );
47
48 /*****************************************************************************
49  * Module descriptor
50  *****************************************************************************/
51 vlc_module_begin();
52     set_description( _("Description stream output") );
53     set_capability( "sout stream", 50 );
54     add_shortcut( "description" );
55     set_callbacks( Open, Close );
56 vlc_module_end();
57
58 struct sout_stream_sys_t
59 {
60     int            i_id;
61     input_thread_t *p_input;
62
63     mtime_t i_stream_start;
64 };
65
66 struct sout_stream_id_t
67 {
68     int i_d_u_m_m_y;
69 };
70
71 /*****************************************************************************
72  * Open:
73  *****************************************************************************/
74 static int Open( vlc_object_t *p_this )
75 {
76     sout_stream_t *p_stream = (sout_stream_t*)p_this;
77     sout_stream_sys_t *p_sys;
78
79     p_stream->pf_add  = Add;
80     p_stream->pf_del  = Del;
81     p_stream->pf_send = Send;
82     p_sys = p_stream->p_sys = malloc(sizeof(sout_stream_sys_t));
83
84     p_sys->i_id = 0;
85     p_sys->p_input = NULL;
86
87     p_sys->i_stream_start = 0;
88
89     return VLC_SUCCESS;
90 }
91
92 /*****************************************************************************
93  * Close:
94  *****************************************************************************/
95 static void Close( vlc_object_t *p_this )
96 {
97     sout_stream_t *p_stream = (sout_stream_t *)p_this;
98     sout_stream_sys_t *p_sys = p_stream->p_sys;
99
100     msg_Dbg( p_this, "description: Closing the module" );
101
102     /* It can happen only if buggy */
103     assert( !p_sys->p_input );
104
105     free( p_sys );
106 }
107
108 static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
109 {
110     __msg_Dbg( NULL, "description: Adding a stream" );
111     sout_stream_sys_t *p_sys = p_stream->p_sys;
112     sout_stream_id_t *id;
113     es_format_t *p_fmt_copy;
114     input_item_t *p_item;
115
116     if( !p_sys->p_input )
117         p_sys->p_input = vlc_object_find( p_stream, VLC_OBJECT_INPUT, FIND_PARENT );
118     if( !p_sys->p_input )
119         return NULL;
120  
121     p_item = input_GetItem(p_sys->p_input);
122
123     p_fmt_copy = malloc(sizeof(es_format_t));
124     es_format_Copy( p_fmt_copy, p_fmt );
125
126     vlc_mutex_lock( &p_item->lock );
127     TAB_APPEND( p_item->i_es, p_item->es, p_fmt_copy );
128     vlc_mutex_unlock( &p_item->lock );
129
130     p_sys->i_id++;
131     if( p_sys->i_stream_start <= 0 )
132         p_sys->i_stream_start = mdate();
133
134     id = malloc( sizeof( sout_stream_id_t ) );
135     id->i_d_u_m_m_y = 0;
136     return id;
137 }
138
139 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
140 {
141     sout_stream_sys_t *p_sys = p_stream->p_sys;
142
143     __msg_Dbg( NULL, "description: Removing a stream (id:%d)", p_sys->i_id );
144
145     p_sys->i_id--;
146     if( p_sys->i_id <= 0 )
147     {
148         vlc_object_release( p_sys->p_input );
149         p_sys->p_input = NULL;
150     }
151
152     free( id );
153     return VLC_SUCCESS;
154 }
155
156 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
157                  block_t *p_buffer )
158 {
159     VLC_UNUSED(id);
160     sout_stream_sys_t *p_sys = p_stream->p_sys;
161
162     block_ChainRelease( p_buffer );
163
164     if( p_sys->p_input && p_sys->i_stream_start + 1500000 < mdate() )
165         p_sys->p_input->b_eof = true;
166
167     return VLC_SUCCESS;
168 }