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