Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

display.c

00001 /*****************************************************************************
00002  * display.c: display stream output module
00003  *****************************************************************************
00004  * Copyright (C) 2001, 2002 the VideoLAN team
00005  * $Id: display.c 12581 2005-09-17 13:29:37Z zorglub $
00006  *
00007  * Authors: Laurent Aimar <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <stdlib.h>
00028 #include <string.h>
00029 
00030 #include <vlc/vlc.h>
00031 #include <vlc/input.h>
00032 #include <vlc/sout.h>
00033 
00034 /*****************************************************************************
00035  * Module descriptor
00036  *****************************************************************************/
00037 #define AUDIO_TEXT N_("Enable audio")
00038 #define AUDIO_LONGTEXT N_( "Enable/disable audio rendering." )
00039 #define VIDEO_TEXT N_("Enable video")
00040 #define VIDEO_LONGTEXT N_( "Enable/disable video rendering." )
00041 #define DELAY_TEXT N_("Delay")
00042 #define DELAY_LONGTEXT N_( "Introduces a delay in the display of the stream." )
00043 
00044 static int  Open ( vlc_object_t * );
00045 static void Close( vlc_object_t * );
00046 
00047 #define SOUT_CFG_PREFIX "sout-display-"
00048 
00049 vlc_module_begin();
00050     set_shortname( _("Display"));
00051     set_description( _("Display stream output") );
00052     set_capability( "sout stream", 50 );
00053     add_shortcut( "display" );
00054     set_category( CAT_SOUT );
00055     set_subcategory( SUBCAT_SOUT_STREAM );
00056     add_bool( SOUT_CFG_PREFIX "audio", 1, NULL, AUDIO_TEXT,
00057               AUDIO_LONGTEXT, VLC_TRUE );
00058     add_bool( SOUT_CFG_PREFIX "video", 1, NULL, VIDEO_TEXT,
00059               VIDEO_LONGTEXT, VLC_TRUE );
00060     add_integer( SOUT_CFG_PREFIX "delay", 100, NULL, DELAY_TEXT,
00061                  DELAY_LONGTEXT, VLC_TRUE );
00062     set_callbacks( Open, Close );
00063 vlc_module_end();
00064 
00065 
00066 /*****************************************************************************
00067  * Exported prototypes
00068  *****************************************************************************/
00069 static const char *ppsz_sout_options[] = {
00070     "audio", "video", "delay", NULL
00071 };
00072 
00073 static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
00074 static int               Del ( sout_stream_t *, sout_stream_id_t * );
00075 static int               Send( sout_stream_t *, sout_stream_id_t *, block_t* );
00076 
00077 struct sout_stream_sys_t
00078 {
00079     input_thread_t *p_input;
00080 
00081     vlc_bool_t     b_audio;
00082     vlc_bool_t     b_video;
00083 
00084     mtime_t        i_delay;
00085 };
00086 
00087 /*****************************************************************************
00088  * Open:
00089  *****************************************************************************/
00090 static int Open( vlc_object_t *p_this )
00091 {
00092     sout_stream_t     *p_stream = (sout_stream_t*)p_this;
00093     sout_stream_sys_t *p_sys;
00094     vlc_value_t val;
00095 
00096     sout_CfgParse( p_stream, SOUT_CFG_PREFIX, ppsz_sout_options,
00097                    p_stream->p_cfg );
00098 
00099     p_sys          = malloc( sizeof( sout_stream_sys_t ) );
00100     p_sys->p_input = vlc_object_find( p_stream, VLC_OBJECT_INPUT,
00101                                       FIND_PARENT );
00102     if( !p_sys->p_input )
00103     {
00104         msg_Err( p_stream, "cannot find p_input" );
00105         free( p_sys );
00106         return VLC_EGENERIC;
00107     }
00108 
00109     var_Get( p_stream, SOUT_CFG_PREFIX "audio", &val );
00110     p_sys->b_audio = val.b_bool;
00111 
00112     var_Get( p_stream, SOUT_CFG_PREFIX "video", &val );
00113     p_sys->b_video = val.b_bool;
00114 
00115     var_Get( p_stream, SOUT_CFG_PREFIX "delay", &val );
00116     p_sys->i_delay = (int64_t)val.i_int * 1000;
00117 
00118     p_stream->pf_add    = Add;
00119     p_stream->pf_del    = Del;
00120     p_stream->pf_send   = Send;
00121 
00122     p_stream->p_sys     = p_sys;
00123 
00124     /* update p_sout->i_out_pace_nocontrol */
00125     p_stream->p_sout->i_out_pace_nocontrol++;
00126 
00127     return VLC_SUCCESS;
00128 }
00129 
00130 /*****************************************************************************
00131  * Close:
00132  *****************************************************************************/
00133 static void Close( vlc_object_t * p_this )
00134 {
00135     sout_stream_t     *p_stream = (sout_stream_t*)p_this;
00136     sout_stream_sys_t *p_sys = p_stream->p_sys;
00137 
00138     /* update p_sout->i_out_pace_nocontrol */
00139     p_stream->p_sout->i_out_pace_nocontrol--;
00140 
00141     vlc_object_release( p_sys->p_input );
00142     free( p_sys );
00143 }
00144 
00145 struct sout_stream_id_t
00146 {
00147     decoder_t *p_dec;
00148 };
00149 
00150 static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
00151 {
00152     sout_stream_sys_t *p_sys = p_stream->p_sys;
00153     sout_stream_id_t *id;
00154 
00155     if( ( p_fmt->i_cat == AUDIO_ES && !p_sys->b_audio )||
00156         ( p_fmt->i_cat == VIDEO_ES && !p_sys->b_video ) )
00157     {
00158         return NULL;
00159     }
00160 
00161     id = malloc( sizeof( sout_stream_id_t ) );
00162 
00163     id->p_dec = input_DecoderNew( p_sys->p_input, p_fmt, VLC_TRUE );
00164     if( id->p_dec == NULL )
00165     {
00166         msg_Err( p_stream, "cannot create decoder for fcc=`%4.4s'",
00167                  (char*)&p_fmt->i_codec );
00168         free( id );
00169         return NULL;
00170     }
00171 
00172     return id;
00173 }
00174 
00175 static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
00176 {
00177     input_DecoderDelete( id->p_dec );
00178     free( id );
00179     return VLC_SUCCESS;
00180 }
00181 
00182 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
00183                  block_t *p_buffer )
00184 {
00185     sout_stream_sys_t *p_sys = p_stream->p_sys;
00186 
00187     while( p_buffer )
00188     {
00189         block_t *p_next = p_buffer->p_next;
00190 
00191         p_buffer->p_next = NULL;
00192 
00193         if( id->p_dec && p_buffer->i_buffer > 0 )
00194         {
00195             if( p_buffer->i_dts <= 0 )
00196                 p_buffer->i_dts= 0;
00197             else
00198                 p_buffer->i_dts += p_sys->i_delay;
00199 
00200             if( p_buffer->i_pts <= 0 )
00201                 p_buffer->i_pts= 0;
00202             else
00203                 p_buffer->i_pts += p_sys->i_delay;
00204 
00205             input_DecoderDecode( id->p_dec, p_buffer );
00206         }
00207 
00208         p_buffer = p_next;
00209     }
00210 
00211     return VLC_SUCCESS;
00212 }

Generated on Tue Dec 20 10:14:49 2005 for vlc-0.8.4a by  doxygen 1.4.2