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 * );
41 set_description( _("Display stream output") );
42 set_capability( "sout stream", 50 );
43 add_shortcut( "display" );
44 set_callbacks( Open, Close );
48 /*****************************************************************************
50 *****************************************************************************/
51 static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
52 static int Del ( sout_stream_t *, sout_stream_id_t * );
53 static int Send( sout_stream_t *, sout_stream_id_t *, block_t* );
55 struct sout_stream_sys_t
57 input_thread_t *p_input;
65 /*****************************************************************************
67 *****************************************************************************/
68 static int Open( vlc_object_t *p_this )
70 sout_stream_t *p_stream = (sout_stream_t*)p_this;
71 sout_stream_sys_t *p_sys;
73 p_sys = malloc( sizeof( sout_stream_sys_t ) );
74 p_sys->p_input = vlc_object_find( p_stream, VLC_OBJECT_INPUT, FIND_ANYWHERE );
77 msg_Err( p_stream, "cannot find p_input" );
82 p_sys->b_audio = VLC_TRUE;
83 p_sys->b_video = VLC_TRUE;
84 p_sys->i_delay = 100*1000;
85 if( sout_cfg_find( p_stream->p_cfg, "noaudio" ) )
87 p_sys->b_audio = VLC_FALSE;
89 if( sout_cfg_find( p_stream->p_cfg, "novideo" ) )
91 p_sys->b_video = VLC_FALSE;
93 if( ( val = sout_cfg_find_value( p_stream->p_cfg, "delay" ) ) )
95 p_sys->i_delay = (mtime_t)atoi( val ) * (mtime_t)1000;
98 p_stream->pf_add = Add;
99 p_stream->pf_del = Del;
100 p_stream->pf_send = Send;
102 p_stream->p_sys = p_sys;
104 /* update p_sout->i_out_pace_nocontrol */
105 p_stream->p_sout->i_out_pace_nocontrol++;
110 /*****************************************************************************
112 *****************************************************************************/
113 static void Close( vlc_object_t * p_this )
115 sout_stream_t *p_stream = (sout_stream_t*)p_this;
116 sout_stream_sys_t *p_sys = p_stream->p_sys;
118 /* update p_sout->i_out_pace_nocontrol */
119 p_stream->p_sout->i_out_pace_nocontrol--;
121 vlc_object_release( p_sys->p_input );
126 struct sout_stream_id_t
128 es_descriptor_t *p_es;
131 static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
133 sout_stream_sys_t *p_sys = p_stream->p_sys;
134 sout_stream_id_t *id;
136 if( ( p_fmt->i_cat == AUDIO_ES && !p_sys->b_audio )||
137 ( p_fmt->i_cat == VIDEO_ES && !p_sys->b_video ) )
142 id = malloc( sizeof( sout_stream_id_t ) );
144 id->p_es = malloc( sizeof( es_descriptor_t ) );
145 memset( id->p_es, 0, sizeof( es_descriptor_t ) );
146 id->p_es->i_cat = p_fmt->i_cat;
147 id->p_es->i_fourcc = p_fmt->i_codec;
148 id->p_es->b_force_decoder = VLC_TRUE;
149 es_format_Copy( &id->p_es->fmt, p_fmt );
151 id->p_es->p_dec = input_RunDecoder( p_sys->p_input, id->p_es );
152 if( id->p_es->p_dec == NULL )
154 msg_Err( p_stream, "cannot create decoder for fcc=`%4.4s'",
155 (char*)&p_fmt->i_codec );
164 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
166 sout_stream_sys_t *p_sys = p_stream->p_sys;
168 input_EndDecoder( p_sys->p_input, id->p_es );
176 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
179 sout_stream_sys_t *p_sys = p_stream->p_sys;
183 block_t *p_next = p_buffer->p_next;
185 p_buffer->p_next = NULL;
187 if( id->p_es->p_dec && p_buffer->i_buffer > 0 )
189 if( p_buffer->i_dts <= 0 )
192 p_buffer->i_dts += p_sys->i_delay;
194 if( p_buffer->i_pts <= 0 )
197 p_buffer->i_pts += p_sys->i_delay;
199 input_DecodeBlock( id->p_es->p_dec, p_buffer );