]> git.sesse.net Git - vlc/blob - modules/stream_out/display.c
Use var_InheritString for --decklink-video-connection.
[vlc] / modules / stream_out / display.c
1 /*****************************************************************************
2  * display.c: display stream output module
3  *****************************************************************************
4  * Copyright (C) 2001, 2002 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
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_sout.h>
36 #include <vlc_block.h>
37
38 /*****************************************************************************
39  * Module descriptor
40  *****************************************************************************/
41 #define AUDIO_TEXT N_("Enable audio")
42 #define AUDIO_LONGTEXT N_( "Enable/disable audio rendering." )
43 #define VIDEO_TEXT N_("Enable video")
44 #define VIDEO_LONGTEXT N_( "Enable/disable video rendering." )
45 #define DELAY_TEXT N_("Delay")
46 #define DELAY_LONGTEXT N_( "Introduces a delay in the display of the stream." )
47
48 static int  Open ( vlc_object_t * );
49 static void Close( vlc_object_t * );
50
51 #define SOUT_CFG_PREFIX "sout-display-"
52
53 vlc_module_begin ()
54     set_shortname( N_("Display"))
55     set_description( N_("Display stream output") )
56     set_capability( "sout stream", 50 )
57     add_shortcut( "display" )
58     set_category( CAT_SOUT )
59     set_subcategory( SUBCAT_SOUT_STREAM )
60     add_bool( SOUT_CFG_PREFIX "audio", true, NULL, AUDIO_TEXT,
61               AUDIO_LONGTEXT, true )
62     add_bool( SOUT_CFG_PREFIX "video", true, NULL, VIDEO_TEXT,
63               VIDEO_LONGTEXT, true )
64     add_integer( SOUT_CFG_PREFIX "delay", 100, NULL, DELAY_TEXT,
65                  DELAY_LONGTEXT, true )
66     set_callbacks( Open, Close )
67 vlc_module_end ()
68
69
70 /*****************************************************************************
71  * Exported prototypes
72  *****************************************************************************/
73 static const char *const ppsz_sout_options[] = {
74     "audio", "video", "delay", NULL
75 };
76
77 static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
78 static int               Del ( sout_stream_t *, sout_stream_id_t * );
79 static int               Send( sout_stream_t *, sout_stream_id_t *, block_t* );
80
81 struct sout_stream_sys_t
82 {
83     input_thread_t *p_input;
84     unsigned        i_es;
85
86     bool     b_audio;
87     bool     b_video;
88
89     mtime_t        i_delay;
90 };
91
92 /*****************************************************************************
93  * Open:
94  *****************************************************************************/
95 static int Open( vlc_object_t *p_this )
96 {
97     sout_stream_t     *p_stream = (sout_stream_t*)p_this;
98     sout_stream_sys_t *p_sys;
99
100     p_sys = malloc( sizeof( sout_stream_sys_t ) );
101     if( p_sys == NULL )
102         return VLC_ENOMEM;
103
104     config_ChainParse( p_stream, SOUT_CFG_PREFIX, ppsz_sout_options,
105                    p_stream->p_cfg );
106
107     p_sys->p_input = NULL;
108     p_sys->i_es    = 0;
109     p_sys->b_audio = var_GetBool( p_stream, SOUT_CFG_PREFIX"audio" );
110     p_sys->b_video = var_GetBool( p_stream, SOUT_CFG_PREFIX "video" );
111     p_sys->i_delay = var_GetInteger( p_stream, SOUT_CFG_PREFIX "delay" );
112     p_sys->i_delay *= 1000;
113
114     p_stream->pf_add    = Add;
115     p_stream->pf_del    = Del;
116     p_stream->pf_send   = Send;
117     p_stream->p_sys     = p_sys;
118
119     /* update p_sout->i_out_pace_nocontrol */
120     p_stream->p_sout->i_out_pace_nocontrol++;
121
122     return VLC_SUCCESS;
123 }
124
125 /*****************************************************************************
126  * Close:
127  *****************************************************************************/
128 static void Close( vlc_object_t * p_this )
129 {
130     sout_stream_t     *p_stream = (sout_stream_t*)p_this;
131     sout_stream_sys_t *p_sys = p_stream->p_sys;
132
133     /* update p_sout->i_out_pace_nocontrol */
134     p_stream->p_sout->i_out_pace_nocontrol--;
135
136     free( p_sys );
137 }
138
139 struct sout_stream_id_t
140 {
141     decoder_t *p_dec;
142 };
143
144 static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
145 {
146     sout_stream_sys_t *p_sys = p_stream->p_sys;
147     sout_stream_id_t *id;
148
149     if( ( p_fmt->i_cat == AUDIO_ES && !p_sys->b_audio )||
150         ( p_fmt->i_cat == VIDEO_ES && !p_sys->b_video ) )
151     {
152         return NULL;
153     }
154
155     id = malloc( sizeof( sout_stream_id_t ) );
156     if( id == NULL )
157         return NULL;
158
159     if( p_sys->i_es == 0 )
160     {
161         p_sys->p_input = vlc_object_find( p_stream, VLC_OBJECT_INPUT,
162                                           FIND_PARENT );
163         if( p_sys->p_input == NULL )
164         {
165             msg_Err( p_stream, "cannot find input" );
166             free( id );
167             return NULL;
168         }
169     }
170
171     id->p_dec = input_DecoderNew( p_sys->p_input, p_fmt, NULL, NULL );
172     if( id->p_dec == NULL )
173     {
174         msg_Err( p_stream, "cannot create decoder for fcc=`%4.4s'",
175                  (char*)&p_fmt->i_codec );
176         free( id );
177         if( p_sys->i_es == 0 )
178             vlc_object_release( p_sys->p_input );
179         return NULL;
180     }
181
182     p_sys->i_es++;
183     return id;
184 }
185
186 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
187 {
188     input_DecoderDelete( id->p_dec );
189     if( --p_stream->p_sys->i_es == 0)
190         vlc_object_release( p_stream->p_sys->p_input );
191
192     free( id );
193     return VLC_SUCCESS;
194 }
195
196 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
197                  block_t *p_buffer )
198 {
199     sout_stream_sys_t *p_sys = p_stream->p_sys;
200
201     while( p_buffer )
202     {
203         block_t *p_next = p_buffer->p_next;
204
205         p_buffer->p_next = NULL;
206
207         if( id->p_dec && p_buffer->i_buffer > 0 )
208         {
209             if( p_buffer->i_dts <= VLC_TS_INVALID )
210                 p_buffer->i_dts = 0;
211             else
212                 p_buffer->i_dts += p_sys->i_delay;
213
214             if( p_buffer->i_pts <= VLC_TS_INVALID )
215                 p_buffer->i_pts = 0;
216             else
217                 p_buffer->i_pts += p_sys->i_delay;
218
219             input_DecoderDecode( id->p_dec, p_buffer, false );
220         }
221
222         p_buffer = p_next;
223     }
224
225     return VLC_SUCCESS;
226 }