1 /*****************************************************************************
2 * display.c: display stream output module
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 VideoLAN
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
31 #include <vlc/input.h>
34 /*****************************************************************************
36 *****************************************************************************/
37 static int Open ( vlc_object_t * );
38 static void Close( vlc_object_t * );
40 #define SOUT_CFG_PREFIX "sout-display-"
43 set_description( _("Display stream output") );
44 set_capability( "sout stream", 50 );
45 add_shortcut( "display" );
46 add_bool( SOUT_CFG_PREFIX "audio", 1, NULL, "audio", "", VLC_TRUE );
47 add_bool( SOUT_CFG_PREFIX "video", 1, NULL, "video", "", VLC_TRUE );
48 add_integer( SOUT_CFG_PREFIX "delay", 100, NULL, "delay", "", VLC_TRUE );
49 set_callbacks( Open, Close );
53 /*****************************************************************************
55 *****************************************************************************/
56 static const char *ppsz_sout_options[] = {
57 "audio", "video", "delay", NULL
60 static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
61 static int Del ( sout_stream_t *, sout_stream_id_t * );
62 static int Send( sout_stream_t *, sout_stream_id_t *, block_t* );
64 struct sout_stream_sys_t
66 input_thread_t *p_input;
74 /*****************************************************************************
76 *****************************************************************************/
77 static int Open( vlc_object_t *p_this )
79 sout_stream_t *p_stream = (sout_stream_t*)p_this;
80 sout_stream_sys_t *p_sys;
83 sout_ParseCfg( p_stream, SOUT_CFG_PREFIX, ppsz_sout_options, p_stream->p_cfg );
85 p_sys = malloc( sizeof( sout_stream_sys_t ) );
86 p_sys->p_input = vlc_object_find( p_stream, VLC_OBJECT_INPUT, FIND_ANYWHERE );
89 msg_Err( p_stream, "cannot find p_input" );
94 var_Get( p_stream, SOUT_CFG_PREFIX "audio", &val );
95 p_sys->b_audio = val.b_bool;
97 var_Get( p_stream, SOUT_CFG_PREFIX "video", &val );
98 p_sys->b_video = val.b_bool;
100 var_Get( p_stream, SOUT_CFG_PREFIX "delay", &val );
101 p_sys->i_delay = (int64_t)val.i_int * 1000;
103 p_stream->pf_add = Add;
104 p_stream->pf_del = Del;
105 p_stream->pf_send = Send;
107 p_stream->p_sys = p_sys;
109 /* update p_sout->i_out_pace_nocontrol */
110 p_stream->p_sout->i_out_pace_nocontrol++;
115 /*****************************************************************************
117 *****************************************************************************/
118 static void Close( vlc_object_t * p_this )
120 sout_stream_t *p_stream = (sout_stream_t*)p_this;
121 sout_stream_sys_t *p_sys = p_stream->p_sys;
123 /* update p_sout->i_out_pace_nocontrol */
124 p_stream->p_sout->i_out_pace_nocontrol--;
126 vlc_object_release( p_sys->p_input );
131 struct sout_stream_id_t
133 es_descriptor_t *p_es;
136 static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
138 sout_stream_sys_t *p_sys = p_stream->p_sys;
139 sout_stream_id_t *id;
141 if( ( p_fmt->i_cat == AUDIO_ES && !p_sys->b_audio )||
142 ( p_fmt->i_cat == VIDEO_ES && !p_sys->b_video ) )
147 id = malloc( sizeof( sout_stream_id_t ) );
149 id->p_es = malloc( sizeof( es_descriptor_t ) );
150 memset( id->p_es, 0, sizeof( es_descriptor_t ) );
151 id->p_es->i_cat = p_fmt->i_cat;
152 id->p_es->i_fourcc = p_fmt->i_codec;
153 id->p_es->b_force_decoder = VLC_TRUE;
154 es_format_Copy( &id->p_es->fmt, p_fmt );
156 id->p_es->p_dec = input_RunDecoder( p_sys->p_input, id->p_es );
157 if( id->p_es->p_dec == NULL )
159 msg_Err( p_stream, "cannot create decoder for fcc=`%4.4s'",
160 (char*)&p_fmt->i_codec );
169 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
171 sout_stream_sys_t *p_sys = p_stream->p_sys;
173 input_EndDecoder( p_sys->p_input, id->p_es );
181 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
184 sout_stream_sys_t *p_sys = p_stream->p_sys;
188 block_t *p_next = p_buffer->p_next;
190 p_buffer->p_next = NULL;
192 if( id->p_es->p_dec && p_buffer->i_buffer > 0 )
194 if( p_buffer->i_dts <= 0 )
197 p_buffer->i_dts += p_sys->i_delay;
199 if( p_buffer->i_pts <= 0 )
202 p_buffer->i_pts += p_sys->i_delay;
204 input_DecodeBlock( id->p_es->p_dec, p_buffer );