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