1 /*****************************************************************************
2 * display.c: display stream output module
3 *****************************************************************************
4 * Copyright (C) 2001-2011 the VideoLAN team
6 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 /*****************************************************************************
25 *****************************************************************************/
31 #include <vlc_common.h>
32 #include <vlc_plugin.h>
33 #include <vlc_input.h>
35 #include <vlc_block.h>
37 /*****************************************************************************
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 (ms)")
45 #define DELAY_LONGTEXT N_( "Introduces a delay in the display of the stream." )
47 static int Open ( vlc_object_t * );
48 static void Close( vlc_object_t * );
50 #define SOUT_CFG_PREFIX "sout-display-"
53 set_shortname( N_("Display"))
54 set_description( N_("Display stream output") )
55 set_capability( "sout stream", 50 )
56 add_shortcut( "display" )
57 set_category( CAT_SOUT )
58 set_subcategory( SUBCAT_SOUT_STREAM )
60 add_bool( SOUT_CFG_PREFIX "audio", true, AUDIO_TEXT,
61 AUDIO_LONGTEXT, true )
62 add_bool( SOUT_CFG_PREFIX "video", true, VIDEO_TEXT,
63 VIDEO_LONGTEXT, true )
64 add_integer( SOUT_CFG_PREFIX "delay", 100, DELAY_TEXT,
65 DELAY_LONGTEXT, true )
66 set_callbacks( Open, Close )
70 /*****************************************************************************
72 *****************************************************************************/
73 static const char *const ppsz_sout_options[] = {
74 "audio", "video", "delay", NULL
77 static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
78 static int Del ( sout_stream_t *, sout_stream_id_t * );
79 static int Send( sout_stream_t *, sout_stream_id_t *, block_t* );
81 struct sout_stream_sys_t
87 input_resource_t *p_resource;
90 /*****************************************************************************
92 *****************************************************************************/
93 static int Open( vlc_object_t *p_this )
95 sout_stream_t *p_stream = (sout_stream_t*)p_this;
96 sout_stream_sys_t *p_sys;
98 p_sys = malloc( sizeof( sout_stream_sys_t ) );
102 p_sys->p_resource = input_resource_New( p_this );
103 if( unlikely(p_sys->p_resource == NULL) )
109 config_ChainParse( p_stream, SOUT_CFG_PREFIX, ppsz_sout_options,
112 p_sys->b_audio = var_GetBool( p_stream, SOUT_CFG_PREFIX"audio" );
113 p_sys->b_video = var_GetBool( p_stream, SOUT_CFG_PREFIX "video" );
114 p_sys->i_delay = var_GetInteger( p_stream, SOUT_CFG_PREFIX "delay" );
115 p_sys->i_delay = p_sys->i_delay * CLOCK_FREQ / 1000;
117 p_stream->pf_add = Add;
118 p_stream->pf_del = Del;
119 p_stream->pf_send = Send;
120 p_stream->p_sys = p_sys;
122 /* update p_sout->i_out_pace_nocontrol */
123 p_stream->p_sout->i_out_pace_nocontrol++;
128 /*****************************************************************************
130 *****************************************************************************/
131 static void Close( vlc_object_t * p_this )
133 sout_stream_t *p_stream = (sout_stream_t*)p_this;
134 sout_stream_sys_t *p_sys = p_stream->p_sys;
136 /* update p_sout->i_out_pace_nocontrol */
137 p_stream->p_sout->i_out_pace_nocontrol--;
139 input_resource_Terminate( p_sys->p_resource );
140 input_resource_Release( p_sys->p_resource );
144 static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
146 sout_stream_sys_t *p_sys = p_stream->p_sys;
148 if( ( p_fmt->i_cat == AUDIO_ES && !p_sys->b_audio )||
149 ( p_fmt->i_cat == VIDEO_ES && !p_sys->b_video ) )
154 decoder_t *p_dec = input_DecoderCreate( VLC_OBJECT(p_stream), p_fmt,
158 msg_Err( p_stream, "cannot create decoder for fcc=`%4.4s'",
159 (char*)&p_fmt->i_codec );
162 return (sout_stream_id_t *)p_dec;
165 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
168 input_DecoderDelete( (decoder_t *)id );
172 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
175 sout_stream_sys_t *p_sys = p_stream->p_sys;
179 block_t *p_next = p_buffer->p_next;
181 p_buffer->p_next = NULL;
183 if( id != NULL && p_buffer->i_buffer > 0 )
185 if( p_buffer->i_dts <= VLC_TS_INVALID )
188 p_buffer->i_dts += p_sys->i_delay;
190 if( p_buffer->i_pts <= VLC_TS_INVALID )
193 p_buffer->i_pts += p_sys->i_delay;
195 input_DecoderDecode( (decoder_t *)id, p_buffer, false );