1 /*****************************************************************************
2 * display.c: display stream output module
3 *****************************************************************************
4 * Copyright (C) 2001-2011 VLC authors and VideoLAN
6 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * 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_sys_t
*Add ( sout_stream_t
*, es_format_t
* );
78 static int Del ( sout_stream_t
*, sout_stream_id_sys_t
* );
79 static int Send( sout_stream_t
*, sout_stream_id_sys_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
;
121 p_stream
->pace_nocontrol
= true;
126 /*****************************************************************************
128 *****************************************************************************/
129 static void Close( vlc_object_t
* p_this
)
131 sout_stream_t
*p_stream
= (sout_stream_t
*)p_this
;
132 sout_stream_sys_t
*p_sys
= p_stream
->p_sys
;
134 input_resource_Terminate( p_sys
->p_resource
);
135 input_resource_Release( p_sys
->p_resource
);
139 static sout_stream_id_sys_t
* Add( sout_stream_t
*p_stream
, es_format_t
*p_fmt
)
141 sout_stream_sys_t
*p_sys
= p_stream
->p_sys
;
143 if( ( p_fmt
->i_cat
== AUDIO_ES
&& !p_sys
->b_audio
)||
144 ( p_fmt
->i_cat
== VIDEO_ES
&& !p_sys
->b_video
) )
149 decoder_t
*p_dec
= input_DecoderCreate( VLC_OBJECT(p_stream
), p_fmt
,
153 msg_Err( p_stream
, "cannot create decoder for fcc=`%4.4s'",
154 (char*)&p_fmt
->i_codec
);
157 return (sout_stream_id_sys_t
*)p_dec
;
160 static int Del( sout_stream_t
*p_stream
, sout_stream_id_sys_t
*id
)
163 input_DecoderDelete( (decoder_t
*)id
);
167 static int Send( sout_stream_t
*p_stream
, sout_stream_id_sys_t
*id
,
170 sout_stream_sys_t
*p_sys
= p_stream
->p_sys
;
174 block_t
*p_next
= p_buffer
->p_next
;
176 p_buffer
->p_next
= NULL
;
178 if( id
!= NULL
&& p_buffer
->i_buffer
> 0 )
180 if( p_buffer
->i_dts
<= VLC_TS_INVALID
)
183 p_buffer
->i_dts
+= p_sys
->i_delay
;
185 if( p_buffer
->i_pts
<= VLC_TS_INVALID
)
188 p_buffer
->i_pts
+= p_sys
->i_delay
;
190 input_DecoderDecode( (decoder_t
*)id
, p_buffer
, false );