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