]> git.sesse.net Git - vlc/blob - modules/stream_out/description.c
Use var_InheritString for --decklink-video-connection.
[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_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_input.h>
35 #include <vlc_block.h>
36 #include <vlc_sout.h>
37
38 #include <assert.h>
39
40 /*****************************************************************************
41  * Exported prototypes
42  *****************************************************************************/
43 static int      Open    ( vlc_object_t * );
44 static void     Close   ( vlc_object_t * );
45
46 static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
47 static int               Del ( sout_stream_t *, sout_stream_id_t * );
48 static int               Send( sout_stream_t *, sout_stream_id_t *, block_t* );
49
50 /*****************************************************************************
51  * Module descriptor
52  *****************************************************************************/
53 vlc_module_begin ()
54     set_description( N_("Description stream output") )
55     set_capability( "sout stream", 50 )
56     add_shortcut( "description" )
57     set_callbacks( Open, Close )
58 vlc_module_end ()
59
60 struct sout_stream_sys_t
61 {
62     mtime_t i_stream_start;
63 };
64
65 struct sout_stream_id_t
66 {
67 };
68
69 /*****************************************************************************
70  * Open:
71  *****************************************************************************/
72 static int Open( vlc_object_t *p_this )
73 {
74     sout_stream_t *p_stream = (sout_stream_t*)p_this;
75     sout_stream_sys_t *p_sys;
76
77     p_stream->pf_add  = Add;
78     p_stream->pf_del  = Del;
79     p_stream->pf_send = Send;
80     p_sys = p_stream->p_sys = malloc(sizeof(sout_stream_sys_t));
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     msg_Dbg( p_this, "Closing" );
96
97     free( p_sys );
98 }
99
100 static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
101 {
102     sout_stream_sys_t *p_sys = p_stream->p_sys;
103     sout_stream_id_t *id;
104     es_format_t *p_fmt_copy;
105     input_item_t *p_item;
106     input_thread_t *p_input;
107
108     msg_Dbg( p_stream, "Adding a stream" );
109     p_input = vlc_object_find( p_stream, VLC_OBJECT_INPUT, FIND_PARENT );
110     assert( p_input );
111  
112     p_item = input_GetItem(p_input);
113
114     p_fmt_copy = malloc(sizeof(es_format_t));
115     es_format_Copy( p_fmt_copy, p_fmt );
116
117     vlc_mutex_lock( &p_item->lock );
118     TAB_APPEND( p_item->i_es, p_item->es, p_fmt_copy );
119     vlc_mutex_unlock( &p_item->lock );
120     vlc_object_release( p_input );
121
122     if( p_sys->i_stream_start <= 0 )
123         p_sys->i_stream_start = mdate();
124
125     id = malloc( sizeof( sout_stream_id_t ) );
126     return id;
127 }
128
129 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
130 {
131     msg_Dbg( p_stream, "Removing a stream" );
132
133     free( id );
134     return VLC_SUCCESS;
135 }
136
137 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
138                  block_t *p_buffer )
139 {
140     VLC_UNUSED(id);
141     sout_stream_sys_t *p_sys = p_stream->p_sys;
142
143     block_ChainRelease( p_buffer );
144
145     if( p_sys->i_stream_start + 1500000 < mdate() )
146     {
147         input_thread_t *p_input;
148
149         p_input = vlc_object_find( p_stream, VLC_OBJECT_INPUT, FIND_PARENT );
150         if( p_input )
151         {
152             p_input->b_eof = true;
153             vlc_object_release( p_input );
154         }
155     }
156
157     return VLC_SUCCESS;
158 }