Commit acf4606c authored by Christophe Massiot's avatar Christophe Massiot
Browse files

* modules/stream_out/switcher.c: New module allowing to replace an MPEG2

  video by a fixed panel (format .uyvy). Specify panel files with
  --sout-switcher-files=toto.uyvy,tata.uyvy,titi.uyvy and the size of
  pictures with --sout-switcher-sizes=720x576,720x576,480x576.
  --sout-switcher-port=4242 opens up a UDP port. echo 1 | nc -u localhost 4242
  switches to panel #1 (0 is the live video, -1 disables all output).
  The audio is blanked out when a panel is active. --sout-switcher-command
  specifies the first command to run on start-up.
* modules/access/fake.c: Fake video input simulating a video at x fps.
  Use it to switch between fixed panels with the switcher when you have
  no video.
parent 9cb4d58c
......@@ -984,7 +984,7 @@ VLC_ADD_PLUGINS([trivial_channel_mixer trivial_mixer])
VLC_ADD_PLUGINS([id3 playlist export sgimb m3u xtag])
VLC_ADD_PLUGINS([i420_rgb rawvideo blend scale image logo])
VLC_ADD_PLUGINS([wav araw subtitle vobsub adpcm a52sys dtssys au voc xa])
VLC_ADD_PLUGINS([access_directory access_file access_udp access_tcp])
VLC_ADD_PLUGINS([access_directory access_file access_udp access_tcp access_fake])
VLC_ADD_PLUGINS([access_http access_mms access_ftp ipv4])
VLC_ADD_PLUGINS([packetizer_mpegvideo packetizer_h264])
VLC_ADD_PLUGINS([packetizer_mpeg4video packetizer_mpeg4audio])
......@@ -1995,8 +1995,8 @@ then
then
AC_CHECK_HEADERS(ffmpeg/avcodec.h)
AC_CHECK_HEADERS(postproc/postprocess.h)
VLC_ADD_PLUGINS([ffmpeg])
VLC_ADD_CFLAGS([ffmpeg],[`${FFMPEG_CONFIG} --cflags`])
VLC_ADD_PLUGINS([ffmpeg stream_out_switcher])
VLC_ADD_CFLAGS([ffmpeg stream_out_switcher],[`${FFMPEG_CONFIG} --cflags`])
VLC_ADD_LDFLAGS([ffmpeg],[`${FFMPEG_CONFIG} --plugin-libs avcodec avformat postproc`])
else
AC_ARG_WITH(ffmpeg-mp3lame,
......@@ -2031,7 +2031,7 @@ then
AC_CHECK_HEADERS(ffmpeg/avcodec.h, [], [AC_MSG_ERROR([Missing header file ffmpeg/avcodec.h.])] )
AC_CHECK_HEADERS(postproc/postprocess.h, [], [AC_MSG_ERROR([Missing header file postproc/postprocess.h.])] )
AC_CHECK_LIB(avcodec, avcodec_init, [
VLC_ADD_BUILTINS([ffmpeg])
VLC_ADD_BUILTINS([ffmpeg stream_out_switcher])
VLC_ADD_LDFLAGS([ffmpeg],[-lavcodec])],
[ AC_MSG_ERROR([Could not find ffmpeg on your system: you may get it from http://ffmpeg.sf.net/ (cvs version is recommended). Alternatively you can use --disable-ffmpeg to disable the ffmpeg plugins.]) ])
AC_CHECK_LIB(avformat, av_open_input_stream, [
......@@ -2096,14 +2096,14 @@ then
VLC_ADD_LDFLAGS([ffmpeg],[-lxvidcore])
fi
VLC_ADD_BUILTINS([ffmpeg])
VLC_ADD_BUILTINS([ffmpeg stream_out_switcher])
VLC_ADD_LDFLAGS([ffmpeg],[-L${real_ffmpeg_tree}/libavcodec ${real_ffmpeg_tree}/libavcodec/libavcodec.a])
VLC_ADD_CPPFLAGS([ffmpeg],[-I${real_ffmpeg_tree}/libavcodec])
VLC_ADD_CPPFLAGS([ffmpeg stream_out_switcher],[-I${real_ffmpeg_tree}/libavcodec])
if test -f "${real_ffmpeg_tree}/libavformat/libavformat.a"; then
AC_DEFINE(HAVE_LIBAVFORMAT, 1, [Define if you have ffmpeg's libavformat.])
VLC_ADD_LDFLAGS([ffmpeg],[-L${real_ffmpeg_tree}/libavformat ${real_ffmpeg_tree}/libavformat/libavformat.a])
VLC_ADD_CPPFLAGS([ffmpeg],[-I${real_ffmpeg_tree}/libavformat])
VLC_ADD_CPPFLAGS([ffmpeg stream_out_switcher],[-I${real_ffmpeg_tree}/libavformat])
fi
fi
fi
......@@ -2146,6 +2146,8 @@ then
VLC_ADD_LDFLAGS([ffmpegaltivec],[-L${real_ffmpeg_tree}/libavformat -lavformataltivec -lz])
VLC_ADD_CPPFLAGS([ffmpegaltivec],[-I${real_ffmpeg_tree}/libavformat])
fi
VLC_ADD_LDFLAGS([stream_out_switcher],[-L${real_ffmpeg_tree}/libavcodec])
VLC_ADD_CPPFLAGS([stream_out_switcher],[-I${real_ffmpeg_tree}/libavcodec -I${real_ffmpeg_tree}/libavformat])
fi
fi
......
......@@ -8,6 +8,7 @@ SOURCES_access_smb = smb.c
SOURCES_dvdnav = dvdnav.c
SOURCES_dvdread = dvdread.c
SOURCES_slp = slp.c
SOURCES_access_fake = fake.c
SOURCES_cdda = \
cdda.c \
vcd/cdrom.c \
......
/*****************************************************************************
* fake.c : Fake video input for VLC
*****************************************************************************
* Copyright (C) 2005 VideoLAN
* $Id$
*
* Author: Christophe Massiot <massiot@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <vlc/vlc.h>
#include <vlc/input.h>
/*****************************************************************************
* Module descriptior
*****************************************************************************/
static int Open ( vlc_object_t * );
static void Close( vlc_object_t * );
#define CACHING_TEXT N_("Caching value in ms")
#define CACHING_LONGTEXT N_( \
"Allows you to modify the default caching value for fake streams. This " \
"value should be set in millisecond units." )
#define FPS_TEXT N_("Framerate")
#define FPS_LONGTEXT N_( \
"Specify the number of frames per second (eg. 24, 25, 29.997, 30).")
vlc_module_begin();
set_shortname( _("Fake") );
set_description( _("Fake input") );
set_category( CAT_INPUT );
set_subcategory( SUBCAT_INPUT_ACCESS );
add_integer( "fake-caching", DEFAULT_PTS_DELAY / 1000, NULL,
CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
add_float( "fake-fps", 25.0, NULL, FPS_TEXT, FPS_LONGTEXT, VLC_TRUE );
add_shortcut( "fake" );
set_capability( "access_demux", 0 );
set_callbacks( Open, Close );
vlc_module_end();
/*****************************************************************************
* Access: local prototypes
*****************************************************************************/
static int Demux ( demux_t * );
static int Control( demux_t *, int, va_list );
struct demux_sys_t
{
float f_fps;
mtime_t i_last_pts; /* only used when f_fps > 0 */
es_out_id_t *p_es_video;
};
/*****************************************************************************
* Open: opens fake device
*****************************************************************************/
static int Open( vlc_object_t *p_this )
{
demux_t *p_demux = (demux_t*)p_this;
demux_sys_t *p_sys;
vlc_value_t val;
es_format_t fmt;
/* Only when selected */
if( *p_demux->psz_access == '\0' )
return VLC_EGENERIC;
/* Set up p_demux */
p_demux->pf_demux = Demux;
p_demux->pf_control = Control;
p_demux->info.i_update = 0;
p_demux->info.i_title = 0;
p_demux->info.i_seekpoint = 0;
p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
memset( p_sys, 0, sizeof( demux_sys_t ) );
var_Create( p_demux, "fake-fps", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
var_Get( p_demux, "fake-fps", &val );
p_sys->f_fps = val.f_float;
p_sys->i_last_pts = 0;
/* Declare elementary stream */
es_format_Init( &fmt, VIDEO_ES, VLC_FOURCC('f', 'a', 'k', 'e') );
p_sys->p_es_video = es_out_Add( p_demux->out, &fmt );
/* Update default_pts to a suitable value for access */
var_Create( p_demux, "fake-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
return VLC_SUCCESS;
}
/*****************************************************************************
* Close: close device, free resources
*****************************************************************************/
static void Close( vlc_object_t *p_this )
{
demux_t *p_demux = (demux_t *)p_this;
demux_sys_t *p_sys = p_demux->p_sys;
free( p_sys );
}
/*****************************************************************************
* Control:
*****************************************************************************/
static int Control( demux_t *p_demux, int i_query, va_list args )
{
demux_sys_t *p_sys = p_demux->p_sys;
vlc_bool_t *pb;
int64_t *pi64;
switch( i_query )
{
/* Special for access_demux */
case DEMUX_CAN_PAUSE:
case DEMUX_SET_PAUSE_STATE:
case DEMUX_CAN_CONTROL_PACE:
pb = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
*pb = VLC_FALSE;
return VLC_SUCCESS;
case DEMUX_GET_PTS_DELAY:
pi64 = (int64_t*)va_arg( args, int64_t * );
*pi64 = (int64_t)var_GetInteger( p_demux, "fake-caching" ) * 1000;
return VLC_SUCCESS;
case DEMUX_GET_TIME:
pi64 = (int64_t*)va_arg( args, int64_t * );
*pi64 = p_sys->i_last_pts;
return VLC_SUCCESS;
/* TODO implement others */
default:
return VLC_EGENERIC;
}
return VLC_EGENERIC;
}
/*****************************************************************************
* Demux:
*****************************************************************************/
static int Demux( demux_t *p_demux )
{
demux_sys_t *p_sys = p_demux->p_sys;
block_t *p_block = block_New( p_demux, 1 );
if ( !p_sys->i_last_pts )
{
p_sys->i_last_pts = mdate();
}
else
{
p_sys->i_last_pts += I64C(1000000) / p_sys->f_fps;
mwait( p_sys->i_last_pts );
}
p_block->i_flags |= BLOCK_FLAG_TYPE_I;
p_block->i_dts = p_block->i_pts = p_sys->i_last_pts;
es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
es_out_Send( p_demux->out, p_sys->p_es_video, p_block );
return 1;
}
......@@ -9,3 +9,4 @@ SOURCES_stream_out_es = es.c
SOURCES_stream_out_display = display.c
SOURCES_stream_out_gather = gather.c
SOURCES_stream_out_rtp = rtp.c
SOURCES_stream_out_switcher = switcher.c
/*****************************************************************************
* switcher.c: MPEG2 video switcher module
*****************************************************************************
* Copyright (C) 2004 VideoLAN
* $Id$
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vlc/vlc.h>
#include <vlc/sout.h>
#include <vlc/vout.h>
#include "network.h"
#define HAVE_MMX
#ifdef HAVE_FFMPEG_AVCODEC_H
# include <ffmpeg/avcodec.h>
#else
# include <avcodec.h>
#endif
#ifdef HAVE_POSTPROC_POSTPROCESS_H
# include <postproc/postprocess.h>
#else
# include <libpostproc/postprocess.h>
#endif
#define SOUT_CFG_PREFIX "sout-switcher-"
#define MAX_PICTURES 12
#define MAX_AUDIO 12
#define AVCODEC_MAX_VIDEO_FRAME_SIZE (3*1024*1024)
#define MAX_THRESHOLD 99999999
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
static sout_stream_id_t *Add( sout_stream_t *, es_format_t * );
static int Del( sout_stream_t *, sout_stream_id_t * );
static int Send( sout_stream_t *, sout_stream_id_t *, block_t * );
static mtime_t Process( sout_stream_t *p_stream, sout_stream_id_t *id,
mtime_t i_max_dts );
static int UnpackFromFile( sout_stream_t *p_stream, const char *psz_file,
int i_width, int i_height,
picture_t *p_pic );
static void NetCommand( sout_stream_t *p_stream );
static mtime_t VideoCommand( sout_stream_t *p_stream, sout_stream_id_t *id );
static block_t *VideoGetBuffer( sout_stream_t *p_stream, sout_stream_id_t *id,
block_t *p_buffer );
static block_t *AudioGetBuffer( sout_stream_t *p_stream, sout_stream_id_t *id,
block_t *p_buffer );
/*****************************************************************************
* Module descriptor
*****************************************************************************/
#define FILES_TEXT N_("Files")
#define FILES_LONGTEXT N_( \
"Full paths of the files separated by colons." )
#define SIZES_TEXT N_("Sizes")
#define SIZES_LONGTEXT N_( \
"List of sizes separated by colons (720x576:480x576)." )
#define PORT_TEXT N_("Command UDP port")
#define PORT_LONGTEXT N_( \
"UDP port to listen to for commands." )
#define COMMAND_TEXT N_("Command")
#define COMMAND_LONGTEXT N_( \
"Initial command to execute." )
#define GOP_TEXT N_("GOP size")
#define GOP_LONGTEXT N_( \
"Number of P frames between two I frames." )
#define QSCALE_TEXT N_("Quantizer scale")
#define QSCALE_LONGTEXT N_( \
"" )
vlc_module_begin();
set_description( _("MPEG2 video switcher stream output") );
set_capability( "sout stream", 50 );
add_shortcut( "switcher" );
set_callbacks( Open, Close );
add_string( SOUT_CFG_PREFIX "files", "", NULL, FILES_TEXT,
FILES_LONGTEXT, VLC_FALSE );
add_string( SOUT_CFG_PREFIX "sizes", "", NULL, SIZES_TEXT,
SIZES_LONGTEXT, VLC_FALSE );
add_integer( SOUT_CFG_PREFIX "port", 5001, NULL,
PORT_TEXT, PORT_LONGTEXT, VLC_TRUE );
add_integer( SOUT_CFG_PREFIX "command", 0, NULL,
COMMAND_TEXT, COMMAND_LONGTEXT, VLC_TRUE );
add_integer( SOUT_CFG_PREFIX "gop", 8, NULL,
GOP_TEXT, GOP_LONGTEXT, VLC_TRUE );
add_integer( SOUT_CFG_PREFIX "qscale", 5, NULL,
QSCALE_TEXT, QSCALE_LONGTEXT, VLC_TRUE );
vlc_module_end();
static const char *ppsz_sout_options[] = {
"files", "sizes", "port", "command", "gop", "qscale", NULL
};
struct sout_stream_sys_t
{
sout_stream_t *p_out;
int i_gop;
int i_qscale;
sout_stream_id_t *pp_audio_ids[MAX_AUDIO];
/* Pictures */
picture_t p_pictures[MAX_PICTURES];
int i_nb_pictures;
/* Command */
int i_fd;
int i_cmd, i_old_cmd;
};
struct sout_stream_id_t
{
void *id;
vlc_bool_t b_switcher_video;
vlc_bool_t b_switcher_audio;
es_format_t f_src;
block_t *p_queued;
/* ffmpeg part */
AVCodec *ff_enc;
AVCodecContext *ff_enc_c;
AVFrame *p_frame;
char *p_buffer_out;
int i_nb_pred;
int16_t *p_samples;
};
/*****************************************************************************
* Open:
*****************************************************************************/
static int Open( vlc_object_t *p_this )
{
sout_stream_t *p_stream = (sout_stream_t*)p_this;
sout_stream_sys_t *p_sys;
vlc_value_t val;
char *psz_files, *psz_sizes;
int i_height = 0, i_width = 0;
p_sys = malloc( sizeof(sout_stream_sys_t) );
memset( p_sys, 0, sizeof(sout_stream_sys_t) );
p_sys->p_out = sout_StreamNew( p_stream->p_sout, p_stream->psz_next );
if( !p_sys->p_out )
{
msg_Err( p_stream, "cannot create chain" );
free( p_sys );
return VLC_EGENERIC;
}
sout_CfgParse( p_stream, SOUT_CFG_PREFIX, ppsz_sout_options,
p_stream->p_cfg );
var_Get( p_stream, SOUT_CFG_PREFIX "files", &val );
psz_files = val.psz_string;
var_Get( p_stream, SOUT_CFG_PREFIX "sizes", &val );
psz_sizes = val.psz_string;
p_sys->i_nb_pictures = 0;
while ( psz_files && *psz_files )
{
char * psz_file = psz_files;
char * psz_size = psz_sizes;
while ( *psz_files && *psz_files != ':' )
psz_files++;
if ( *psz_files == ':' )
*psz_files++ = '\0';
if ( *psz_sizes )
{
while ( *psz_sizes && *psz_sizes != ':' )
psz_sizes++;
if ( *psz_sizes == ':' )
*psz_sizes++ = '\0';
if ( sscanf( psz_size, "%dx%d", &i_width, &i_height ) != 2 )
{
msg_Err( p_stream, "bad size %s for file %s", psz_size,
psz_file );
free( p_sys );
return VLC_EGENERIC;
}
}
if ( UnpackFromFile( p_stream, psz_file, i_width, i_height,
&p_sys->p_pictures[p_sys->i_nb_pictures] ) < 0 )
{
free( p_sys );
return VLC_EGENERIC;
}
p_sys->i_nb_pictures++;
}
var_Get( p_stream, SOUT_CFG_PREFIX "port", &val );
p_sys->i_fd = net_OpenUDP( p_stream, NULL, val.i_int, NULL, 0 );
if ( p_sys->i_fd < 0 )
{
free( p_sys );
return VLC_EGENERIC;
}
var_Get( p_stream, SOUT_CFG_PREFIX "command", &val );
p_sys->i_cmd = val.i_int;
p_sys->i_old_cmd = 0;
var_Get( p_stream, SOUT_CFG_PREFIX "gop", &val );
p_sys->i_gop = val.i_int;
var_Get( p_stream, SOUT_CFG_PREFIX "qscale", &val );
p_sys->i_qscale = val.i_int;
p_stream->pf_add = Add;
p_stream->pf_del = Del;
p_stream->pf_send = Send;
p_stream->p_sys = p_sys;
avcodec_init();
avcodec_register_all();
return VLC_SUCCESS;
}
/*****************************************************************************
* Close:
*****************************************************************************/
static void Close( vlc_object_t * p_this )
{
sout_stream_t *p_stream = (sout_stream_t *)p_this;
sout_stream_sys_t *p_sys = p_stream->p_sys;
sout_StreamDelete( p_sys->p_out );
free( p_sys );
}
/*****************************************************************************
* Add: Add an input elementary stream
*****************************************************************************/
static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
{
sout_stream_sys_t *p_sys = p_stream->p_sys;
sout_stream_id_t *id;
id = malloc( sizeof( sout_stream_id_t ) );
memset( id, 0, sizeof( sout_stream_id_t ) );
id->id = NULL;
if ( p_fmt->i_cat == VIDEO_ES
&& (p_fmt->i_codec == VLC_FOURCC('m', 'p', 'g', 'v')
|| p_fmt->i_codec == VLC_FOURCC('f', 'a', 'k', 'e')) )
{
id->b_switcher_video = VLC_TRUE;
p_fmt->i_codec = VLC_FOURCC('m', 'p', 'g', 'v');
msg_Dbg( p_stream,
"creating video switcher for fcc=`%4.4s'",
(char*)&p_fmt->i_codec );
}
else if ( p_fmt->i_cat == AUDIO_ES
&& p_fmt->i_codec == VLC_FOURCC('m', 'p', 'g', 'a') )
{
int i_ff_codec = CODEC_ID_MP2;
int i;
id->b_switcher_audio = VLC_TRUE;
msg_Dbg( p_stream,
"creating audio switcher for fcc=`%4.4s'",
(char*)&p_fmt->i_codec );
/* Allocate the encoder right now. */
if( i_ff_codec == 0 )
{
msg_Err( p_stream, "cannot find encoder" );
return NULL;
}
id->ff_enc = avcodec_find_encoder( i_ff_codec );
if( !id->ff_enc )
{
msg_Err( p_stream, "cannot find encoder (avcodec)" );
return NULL;
}
id->ff_enc_c = avcodec_alloc_context();
/* Set CPU capabilities */
id->ff_enc_c->dsp_mask = 0;
if( !(p_stream->p_libvlc->i_cpu & CPU_CAPABILITY_MMX) )
{
id->ff_enc_c->dsp_mask |= FF_MM_MMX;
}
if( !(p_stream->p_libvlc->i_cpu & CPU_CAPABILITY_MMXEXT) )
{
id->ff_enc_c->dsp_mask |= FF_MM_MMXEXT;
}
if( !(p_stream->p_libvlc->i_cpu & CPU_CAPABILITY_3DNOW) )
{
id->ff_enc_c->dsp_mask |= FF_MM_3DNOW;
}
if( !(p_stream->p_libvlc->i_cpu & CPU_CAPABILITY_SSE) )
{
id->ff_enc_c->dsp_mask |= FF_MM_SSE;
id->ff_enc_c->dsp_mask |= FF_MM_SSE2;
}
id->ff_enc_c->sample_rate = p_fmt->audio.i_rate;
id->ff_enc_c->channels = p_fmt->audio.i_channels;
id->ff_enc_c->bit_rate = p_fmt->i_bitrate;
if( avcodec_open( id->ff_enc_c, id->ff_enc ) )
{
msg_Err( p_stream, "cannot open encoder" );
return NULL;
}
id->p_buffer_out = malloc( AVCODEC_MAX_AUDIO_FRAME_SIZE * 2 );
id->p_samples = malloc( id->ff_enc_c->frame_size
* p_fmt->audio.i_channels * sizeof(int16_t) );
memset( id->p_samples, 0,
id->ff_enc_c->frame_size * p_fmt->audio.i_channels
* sizeof(int16_t) );
for ( i = 0; i < MAX_AUDIO; i++ )
{
if ( p_sys->pp_audio_ids[i] == NULL )
{
p_sys->pp_audio_ids[i] = id;
break;
}
}
if ( i == MAX_AUDIO )
{
msg_Err( p_stream, "too many audio streams !" );
free( id );
return NULL;
}
}