Commit e2382750 authored by Rafaël Carré's avatar Rafaël Carré

Remove unmaintained switcher module

parent edb2d3b0
......@@ -89,6 +89,7 @@ Stream Output:
* Livehttp places more accurate segments durations in playlist
* Livehttp allows setting cachin-variable in playlist
* Livehttp stream encryption support
* Unmaintained switcher has been removed
Interfaces:
* configurable password for the HTTP server.
......
......@@ -2390,21 +2390,6 @@ AS_IF([test "${enable_vda}" != "no"], [
])
AM_CONDITIONAL([HAVE_AVCODEC_VDA], [test "${have_avcodec_vda}" = "yes"])
dnl
dnl stream_out switcher needs libavcodec
dnl
AC_ARG_ENABLE(switcher,
[ --enable-switcher Stream-out switcher plugin (default disabled)])
AS_IF([test "${enable_switcher}" = "yes"], [
AS_IF([test "x${have_avcodec}" = "xyes"], [
VLC_ADD_PLUGIN([stream_out_switcher])
VLC_ADD_LIBS([stream_out_switcher],[$AVCODEC_LIBS $AVUTIL_LIBS $LIBM])
VLC_ADD_CFLAGS([stream_out_switcher],[$AVCODEC_CFLAGS $AVUTIL_CFLAGS])
],[AC_MSG_ERROR([Stream_out switcher depends on avcodec])
])
])
dnl
dnl avformat demuxer/muxer plugin
dnl
......
......@@ -1175,7 +1175,6 @@ strfile %buildroot%_gamesdatadir/fortune/vlc %buildroot%_gamesdatadir/fortune/vl
%_vlc_pluginsdir/stream_out/libstream_out_gather_plugin.so*
%_vlc_pluginsdir/stream_out/libstream_out_mosaic_bridge_plugin.so*
%_vlc_pluginsdir/stream_out/libstream_out_rtp_plugin.so*
#%_vlc_pluginsdir/stream_out/libstream_out_switcher_plugin.so*
%_vlc_pluginsdir/stream_out/libstream_out_transcode_plugin.so*
%_vlc_pluginsdir/stream_out/libstream_out_autodel_plugin.so*
......@@ -1374,7 +1373,6 @@ strfile %buildroot%_gamesdatadir/fortune/vlc %buildroot%_gamesdatadir/fortune/vl
%files plugin-ffmpeg
%_vlc_pluginsdir/codec/libffmpeg_plugin.so*
#%_vlc_pluginsdir/stream_out/libstream_out_switcher_plugin.so*
%files plugin-framebuffer
%_vlc_pluginsdir/video_output/libfb_plugin.so*
......
......@@ -328,7 +328,6 @@ $Id$
* stream_out_setid: Set the ID/Lang of an ES when streaming
* stream_out_smem: stream output module to a memory buffer
* stream_out_standard: standard stream output module
* stream_out_switcher: stream output module to display backgrounds
* stream_out_transcode: audio & video transcoder
* subsdec: a codec to output textual subtitles
* subsdelay: subtitles delay filter
......
......@@ -6,8 +6,6 @@ SOURCES_stream_out_duplicate = duplicate.c
SOURCES_stream_out_es = es.c
SOURCES_stream_out_display = display.c
SOURCES_stream_out_gather = gather.c
SOURCES_stream_out_switcher = switcher.c ../codec/avcodec/cpu.c \
../codec/avcodec/avcommon_compat.h ../codec/avcodec/avcommon.h
SOURCES_stream_out_bridge = bridge.c
SOURCES_stream_out_mosaic_bridge = mosaic_bridge.c
SOURCES_stream_out_autodel = autodel.c
......
/*****************************************************************************
* switcher.c: MPEG2 video switcher module
*****************************************************************************
* Copyright (C) 2004 the VideoLAN team
* $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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include <math.h>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_sout.h>
#include <vlc_avcodec.h>
#include <vlc_filter.h>
#include <vlc_cpu.h>
#include <vlc_block.h>
#include <vlc_fs.h>
#include <vlc_network.h>
#define HAVE_MMX
#ifdef HAVE_LIBAVCODEC_AVCODEC_H
# include <libavcodec/avcodec.h>
#elif defined(HAVE_FFMPEG_AVCODEC_H)
# include <ffmpeg/avcodec.h>
#else
# include <avcodec.h>
#endif
#include "../codec/avcodec/avcodec.h"
#include "../codec/avcodec/avcommon.h"
#define SOUT_CFG_PREFIX "sout-switcher-"
#define MAX_PICTURES 10
#define MAX_AUDIO 30
#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 RATIO_TEXT N_("Aspect ratio")
#define RATIO_LONGTEXT N_( \
"Aspect ratio (4:3, 16:9)." )
#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_( \
"Fixed quantizer scale to use." )
#define AUDIO_TEXT N_("Mute audio")
#define AUDIO_LONGTEXT N_( \
"Mute audio when command is not 0." )
vlc_module_begin ()
set_description( N_("MPEG2 video switcher stream output") )
set_capability( "sout stream", 50 )
add_shortcut( "switcher" )
set_callbacks( Open, Close )
add_string( SOUT_CFG_PREFIX "files", "", FILES_TEXT,
FILES_LONGTEXT, false )
add_string( SOUT_CFG_PREFIX "sizes", "", SIZES_TEXT,
SIZES_LONGTEXT, false )
add_string( SOUT_CFG_PREFIX "aspect-ratio", "4:3", RATIO_TEXT,
RATIO_LONGTEXT, false )
add_integer( SOUT_CFG_PREFIX "port", 5001,
PORT_TEXT, PORT_LONGTEXT, true )
add_integer( SOUT_CFG_PREFIX "command", 0,
COMMAND_TEXT, COMMAND_LONGTEXT, true )
add_integer( SOUT_CFG_PREFIX "gop", 8,
GOP_TEXT, GOP_LONGTEXT, true )
add_integer( SOUT_CFG_PREFIX "qscale", 5,
QSCALE_TEXT, QSCALE_LONGTEXT, true )
add_bool( SOUT_CFG_PREFIX "mute-audio", true,
AUDIO_TEXT, AUDIO_LONGTEXT, true )
#if LIBAVCODEC_VERSION_MAJOR >= 54
add_string( SOUT_CFG_PREFIX "options", NULL,
AV_OPTIONS_TEXT, AV_OPTIONS_LONGTEXT, true )
#endif
vlc_module_end ()
static const char *const ppsz_sout_options[] = {
"files", "sizes", "aspect-ratio", "port", "command", "gop", "qscale",
"mute-audio", "options", NULL
};
struct sout_stream_sys_t
{
int i_gop;
int i_qscale;
int i_aspect;
sout_stream_id_t *pp_audio_ids[MAX_AUDIO];
bool b_audio;
/* Pictures */
picture_t p_pictures[MAX_PICTURES];
int i_nb_pictures;
/* Command */
int i_fd;
int i_cmd, i_old_cmd;
#if LIBAVCODEC_VERSION_MAJOR >= 54
AVDictionary *options;
#endif
};
struct sout_stream_id_t
{
void *id;
bool b_switcher_video;
bool b_switcher_audio;
es_format_t f_src;
block_t *p_queued;
/* ffmpeg part */
AVCodec *ff_enc;
AVCodecContext *ff_enc_c;
AVFrame *p_frame;
uint8_t *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;
vlc_init_avcodec();
p_sys = calloc( 1, sizeof(sout_stream_sys_t) );
if( !p_sys )
return VLC_ENOMEM;
if( !p_stream->p_next )
{
msg_Err( p_stream, "cannot create chain" );
free( p_sys );
return VLC_EGENERIC;
}
config_ChainParse( 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 "aspect-ratio", &val );
if ( val.psz_string )
{
char *psz_parser = strchr( val.psz_string, ':' );
if( psz_parser )
{
*psz_parser++ = '\0';
p_sys->i_aspect = atoi( val.psz_string ) * VOUT_ASPECT_FACTOR
/ atoi( psz_parser );
}
else
{
msg_Warn( p_stream, "bad aspect ratio %s", val.psz_string );
p_sys->i_aspect = 4 * VOUT_ASPECT_FACTOR / 3;
}
free( val.psz_string );
}
else
{
p_sys->i_aspect = 4 * VOUT_ASPECT_FACTOR / 3;
}
var_Get( p_stream, SOUT_CFG_PREFIX "port", &val );
p_sys->i_fd = net_ListenUDP1( VLC_OBJECT(p_stream), NULL, val.i_int );
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;
var_Get( p_stream, SOUT_CFG_PREFIX "mute-audio", &val );
p_sys->b_audio = val.b_bool;
p_stream->pf_add = Add;
p_stream->pf_del = Del;
p_stream->pf_send = Send;
p_stream->p_sys = p_sys;
#if LIBAVCODEC_VERSION_MAJOR >= 54
char *psz_opts = var_InheritString( p_stream, SOUT_CFG_PREFIX "options" );
if (psz_opts && *psz_opts) {
p_sys->options = vlc_av_get_options(psz_opts);
} else {
p_sys->options = NULL;
}
free(psz_opts);
#endif
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;
#if LIBAVCODEC_VERSION_MAJOR >= 54
av_dict_free( &p_sys->options );
#endif
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 = calloc( 1, sizeof( sout_stream_id_t ) );
if( !id )
return NULL;
if( p_fmt->i_cat == VIDEO_ES && p_fmt->i_codec == VLC_CODEC_MPGV )
{
id->b_switcher_video = true;
p_fmt->i_codec = VLC_CODEC_MPGV;
msg_Dbg( p_stream, "creating video switcher for fcc=`%4.4s' cmd:%d",
(char*)&p_fmt->i_codec, p_sys->i_cmd );
}
else if ( p_fmt->i_cat == AUDIO_ES &&
p_fmt->i_codec == VLC_CODEC_MPGA &&
p_sys->b_audio )
{
int i_ff_codec = AV_CODEC_ID_MP2;
int i;
id->b_switcher_audio = true;
msg_Dbg( p_stream, "creating audio switcher for fcc=`%4.4s' cmd:%d",
(char*)&p_fmt->i_codec, p_sys->i_cmd );
/* Allocate the encoder right now. */
if( i_ff_codec == 0 )
{
msg_Err( p_stream, "cannot find encoder" );
free( id );
return NULL;
}
id->ff_enc = avcodec_find_encoder( i_ff_codec );
if( !id->ff_enc )
{
msg_Err( p_stream, "cannot find encoder (avcodec)" );
free( id );
return NULL;
}
id->ff_enc_c = avcodec_alloc_context3( id->ff_enc );
id->ff_enc_c->dsp_mask = GetVlcDspMask();
id->ff_enc_c->sample_rate = p_fmt->audio.i_rate;
id->ff_enc_c->time_base.num = 1;
id->ff_enc_c->time_base.den = 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;
int ret;
#if LIBAVCODEC_VERSION_MAJOR >= 54
AVDictionary *options = NULL;
if (p_sys->options)
av_dict_copy(&options, p_sys->options, 0);
vlc_avcodec_lock();
ret = avcodec_open2( id->ff_enc_c, id->ff_enc, options ? &options : NULL );
vlc_avcodec_unlock();
AVDictionaryEntry *t = NULL;
while ((t = av_dict_get(options, "", t, AV_DICT_IGNORE_SUFFIX))) {
msg_Err( p_stream, "Unknown option \"%s\"", t->key );
}
av_dict_free(&options);
#else
vlc_avcodec_lock();
ret = avcodec_open( id->ff_enc_c, id->ff_enc );
vlc_avcodec_unlock();
#endif
if (ret)
{
msg_Err( p_stream, "cannot open encoder" );
av_free( id->ff_enc_c );
free( id );
return NULL;
}
id->p_buffer_out = malloc( AVCODEC_MAX_AUDIO_FRAME_SIZE * 2 );
id->p_samples = calloc( id->ff_enc_c->frame_size * p_fmt->audio.i_channels,
sizeof(int16_t) );
if( !id->p_buffer_out || !id->p_samples )
goto error;
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!" );
goto error;
}
}
else
{
msg_Dbg( p_stream, "do not know what to do when switching (fcc=`%4.4s')",
(char*)&p_fmt->i_codec );
}
/* src format */
memcpy( &id->f_src, p_fmt, sizeof( es_format_t ) );
/* open output stream */
id->id = p_stream->p_next->pf_add( p_stream->p_next, p_fmt );
if( id->id != NULL )
return id;
error:
vlc_avcodec_lock();
avcodec_close( id->ff_enc_c );
vlc_avcodec_unlock();
free( id->p_samples );
free( id->p_buffer_out );
av_free( id->ff_enc_c );
free( id );
return NULL;
}
/*****************************************************************************
* Del: Del an elementary stream
*****************************************************************************/
static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
{
sout_stream_sys_t *p_sys = p_stream->p_sys;
if ( id->b_switcher_audio )
{
int i;
for ( i = 0; i < MAX_AUDIO; i++ )
{
if ( p_sys->pp_audio_ids[i] == id )
{
p_sys->pp_audio_ids[i] = NULL;
break;
}
}
}
if ( id->ff_enc )
{
vlc_avcodec_lock();
avcodec_close( id->ff_enc_c );
vlc_avcodec_unlock();
av_free( id->ff_enc_c );
av_free( id->p_frame );
free( id->p_buffer_out );
}
if ( id->id )
{
p_stream->p_next->pf_del( p_stream->p_next, id->id );
}
free( id );
return VLC_SUCCESS;
}
/*****************************************************************************
* Send: Process an input packet
*****************************************************************************/
static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
block_t *p_buffer )
{
sout_stream_sys_t *p_sys = p_stream->p_sys;
if ( !id->id )
{
block_Release( p_buffer );
return VLC_EGENERIC;
}
if ( !id->b_switcher_video && !id->b_switcher_audio )
{
return p_stream->p_next->pf_send( p_stream->p_next, id->id, p_buffer );
}
block_ChainAppend( &id->p_queued, p_buffer );
if ( id->b_switcher_video )
{
/* Check for commands for every video frame. */
NetCommand( p_stream );
while ( id->p_queued != NULL )
{
mtime_t i_dts = 0;
if ( p_sys->i_old_cmd != p_sys->i_cmd )
{
i_dts = VideoCommand( p_stream, id );
}
i_dts = Process( p_stream, id, i_dts );
for ( int i = 0; i < MAX_AUDIO; i++ )
{
if ( p_sys->pp_audio_ids[i] != NULL )
Process( p_stream, p_sys->pp_audio_ids[i], i_dts );
}
}
}
return VLC_SUCCESS;
}
/*****************************************************************************
* Process: Process and dispatch buffers
*****************************************************************************/
static mtime_t Process( sout_stream_t *p_stream, sout_stream_id_t *id,
mtime_t i_max_dts )
{
sout_stream_sys_t *p_sys = p_stream->p_sys;
mtime_t i_dts = 0;
block_t *p_blocks = NULL;
block_t *p_blocks_out = NULL;
/* Find out the blocks we need. */
while ( id->p_queued != NULL
&& (!i_max_dts || id->p_queued->i_dts <= i_max_dts) )
{
block_t *p_next = id->p_queued->p_next;