]> git.sesse.net Git - vlc/blob - modules/stream_out/display.c
macosx dialog provider: implement EXTENSION_WIDGET_SPIN_ICON
[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 (ms)")
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
61     add_bool( SOUT_CFG_PREFIX "audio", true, AUDIO_TEXT,
62               AUDIO_LONGTEXT, true )
63     add_bool( SOUT_CFG_PREFIX "video", true, VIDEO_TEXT,
64               VIDEO_LONGTEXT, true )
65     add_integer( SOUT_CFG_PREFIX "delay", 100, DELAY_TEXT,
66                  DELAY_LONGTEXT, true )
67     set_callbacks( Open, Close )
68 vlc_module_end ()
69
70
71 /*****************************************************************************
72  * Exported prototypes
73  *****************************************************************************/
74 static const char *const ppsz_sout_options[] = {
75     "audio", "video", "delay", NULL
76 };
77
78 static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
79 static int               Del ( sout_stream_t *, sout_stream_id_t * );
80 static int               Send( sout_stream_t *, sout_stream_id_t *, block_t* );
81
82 struct sout_stream_sys_t
83 {
84     input_thread_t *p_input;
85     unsigned        i_es;
86
87     bool     b_audio;
88     bool     b_video;
89
90     mtime_t        i_delay;
91 };
92
93 /*****************************************************************************
94  * Open:
95  *****************************************************************************/
96 static int Open( vlc_object_t *p_this )
97 {
98     sout_stream_t     *p_stream = (sout_stream_t*)p_this;
99     sout_stream_sys_t *p_sys;
100
101     p_sys = malloc( sizeof( sout_stream_sys_t ) );
102     if( p_sys == NULL )
103         return VLC_ENOMEM;
104
105     config_ChainParse( p_stream, SOUT_CFG_PREFIX, ppsz_sout_options,
106                    p_stream->p_cfg );
107
108     p_sys->p_input = NULL;
109     p_sys->i_es    = 0;
110     p_sys->b_audio = var_GetBool( p_stream, SOUT_CFG_PREFIX"audio" );
111     p_sys->b_video = var_GetBool( p_stream, SOUT_CFG_PREFIX "video" );
112     p_sys->i_delay = var_GetInteger( p_stream, SOUT_CFG_PREFIX "delay" );
113     p_sys->i_delay = p_sys->i_delay * CLOCK_FREQ / 1000;
114
115     p_stream->pf_add    = Add;
116     p_stream->pf_del    = Del;
117     p_stream->pf_send   = Send;
118     p_stream->p_sys     = p_sys;
119
120     /* update p_sout->i_out_pace_nocontrol */
121     p_stream->p_sout->i_out_pace_nocontrol++;
122
123     return VLC_SUCCESS;
124 }
125
126 /*****************************************************************************
127  * Close:
128  *****************************************************************************/
129 static void Close( vlc_object_t * p_this )
130 {
131     sout_stream_t     *p_stream = (sout_stream_t*)p_this;
132     sout_stream_sys_t *p_sys = p_stream->p_sys;
133
134     /* update p_sout->i_out_pace_nocontrol */
135     p_stream->p_sout->i_out_pace_nocontrol--;
136
137     free( p_sys );
138 }
139
140 struct sout_stream_id_t
141 {
142     decoder_t *p_dec;
143 };
144
145 static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
146 {
147     sout_stream_sys_t *p_sys = p_stream->p_sys;
148     sout_stream_id_t *id;
149
150     if( ( p_fmt->i_cat == AUDIO_ES && !p_sys->b_audio )||
151         ( p_fmt->i_cat == VIDEO_ES && !p_sys->b_video ) )
152     {
153         return NULL;
154     }
155
156     id = malloc( sizeof( sout_stream_id_t ) );
157     if( id == NULL )
158         return NULL;
159
160     if( p_sys->i_es == 0 )
161     {
162         p_sys->p_input = vlc_object_find( p_stream, VLC_OBJECT_INPUT,
163                                           FIND_PARENT );
164         if( p_sys->p_input == NULL )
165         {
166             msg_Err( p_stream, "cannot find input" );
167             free( id );
168             return NULL;
169         }
170     }
171
172     id->p_dec = input_DecoderNew( p_sys->p_input, p_fmt, NULL, NULL );
173     if( id->p_dec == NULL )
174     {
175         msg_Err( p_stream, "cannot create decoder for fcc=`%4.4s'",
176                  (char*)&p_fmt->i_codec );
177         free( id );
178         if( p_sys->i_es == 0 )
179             vlc_object_release( p_sys->p_input );
180         return NULL;
181     }
182
183     p_sys->i_es++;
184     return id;
185 }
186
187 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
188 {
189     input_DecoderDelete( id->p_dec );
190     if( --p_stream->p_sys->i_es == 0)
191         vlc_object_release( p_stream->p_sys->p_input );
192
193     free( id );
194     return VLC_SUCCESS;
195 }
196
197 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
198                  block_t *p_buffer )
199 {
200     sout_stream_sys_t *p_sys = p_stream->p_sys;
201
202     while( p_buffer )
203     {
204         block_t *p_next = p_buffer->p_next;
205
206         p_buffer->p_next = NULL;
207
208         if( id->p_dec && p_buffer->i_buffer > 0 )
209         {
210             if( p_buffer->i_dts <= VLC_TS_INVALID )
211                 p_buffer->i_dts = 0;
212             else
213                 p_buffer->i_dts += p_sys->i_delay;
214
215             if( p_buffer->i_pts <= VLC_TS_INVALID )
216                 p_buffer->i_pts = 0;
217             else
218                 p_buffer->i_pts += p_sys->i_delay;
219
220             input_DecoderDecode( id->p_dec, p_buffer, false );
221         }
222
223         p_buffer = p_next;
224     }
225
226     return VLC_SUCCESS;
227 }