Commit 369b343e authored by Jean-Paul Saman's avatar Jean-Paul Saman

modules/stream_out: select.c and setid.c

Replace an existing ES with another without disrupting the client. It
can be used in combination with VLM. Here is an example vlm command file:

  # VLC media player VLM command batch
  # http://www.videolan.org/vlc/

  # MPEG-TS stream
  new ts broadcast enabled
  setup ts input "file:///<path_to_some_file_to_play>"
  setup ts output #duplicate{dst=bridge-out{id=1},select=video,dst=bridge-out{id=0xa3},select=audio}
  setup ts loop

  # Mic input
  new mic broadcast enabled
  setup mic input "alsa://"
  setup mic output #transcode{acodec=mpga,ab=192,channels=2}:bridge-in{id-offset=0}:select{disable=0}:setid{id=0,newid=0xa3}:autodel:std{access=udp,mux=ts,dst=127.0.0.1:1234}

  # Fire it up
  control ts play
  control mic play
parent 623f6fcf
......@@ -14,6 +14,8 @@ SOURCES_stream_out_autodel = autodel.c
SOURCES_stream_out_record = record.c
SOURCES_stream_out_raop = raop.c
SOURCES_stream_out_smem = smem.c
SOURCES_stream_out_setid = setid.c
SOURCES_stream_out_select = select.c
libvlc_LTLIBRARIES += \
libstream_out_dummy_plugin.la \
......@@ -28,6 +30,8 @@ libvlc_LTLIBRARIES += \
libstream_out_autodel_plugin.la \
libstream_out_record_plugin.la \
libstream_out_smem_plugin.la \
libstream_out_setid_plugin.la \
libstream_out_select_plugin.la \
$(NULL)
# RTP plugin
......
/*****************************************************************************
* autodel.c: monitor mux inputs and automatically add/delete streams
*****************************************************************************
* Copyright (C) 2006-2011 the VideoLAN team
* $Id$
*
* Authors: Jean-Paul Saman <jpsaman@videolan.org>
* Based upon autodel.c written by: 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
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_sout.h>
#include <vlc_block.h>
#include <vlc_network.h>
/*****************************************************************************
* Module descriptor
*****************************************************************************/
static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
#define PORT_TEXT N_("Command UDP port")
#define PORT_LONGTEXT N_( \
"UDP port to listen to for commands (show | enable <pid> | disable <pid>)." )
#define DISABLE_TEXT N_("Disable ES id")
#define DISABLE_LONGTEXT N_( \
"Disable ES id at startup." )
#define SOUT_CFG_PREFIX "sout-select-"
vlc_module_begin ()
set_shortname(N_("Select"))
set_description(N_("Select individual ES-es from stream"))
set_capability("sout stream", 50 )
add_integer(SOUT_CFG_PREFIX "port", 5001, NULL,
PORT_TEXT, PORT_LONGTEXT, true)
add_integer(SOUT_CFG_PREFIX "disable", -1, NULL,
DISABLE_TEXT, DISABLE_LONGTEXT, false)
add_shortcut("select")
set_callbacks(Open, Close)
vlc_module_end ()
/*****************************************************************************
* Local prototypes
*****************************************************************************/
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 void* Command(vlc_object_t *);
struct sout_stream_id_t
{
sout_stream_id_t *id;
es_format_t fmt;
bool b_error;
bool b_enabled;
};
struct sout_stream_sys_t
{
sout_stream_id_t **pp_es;
int i_es_num;
vlc_mutex_t es_lock;
int i_fd;
int i_id_disable;
};
static const char *const ppsz_sout_options[] = {
"disable", "port", NULL
};
/*****************************************************************************
* 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;
p_sys = malloc(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);
int port = var_CreateGetInteger(p_stream, SOUT_CFG_PREFIX "port");
p_sys->i_fd = net_ListenUDP1(VLC_OBJECT(p_stream), NULL, port);
if (p_sys->i_fd < 0)
{
free( p_sys );
return VLC_EGENERIC;
}
p_sys->i_id_disable = var_CreateGetInteger(p_stream, SOUT_CFG_PREFIX "disable");
p_sys->pp_es = NULL;
p_sys->i_es_num = 0;
p_stream->pf_add = Add;
p_stream->pf_del = Del;
p_stream->pf_send = Send;
p_stream->p_sys = p_sys;
vlc_mutex_init(&p_sys->es_lock);
if (vlc_thread_create(p_stream, "ES Select Command Thread",
Command, VLC_THREAD_PRIORITY_LOW))
{
vlc_mutex_destroy(&p_sys->es_lock);
free(p_sys);
return VLC_EGENERIC;
}
/* update p_sout->i_out_pace_nocontrol */
p_stream->p_sout->i_out_pace_nocontrol++;
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 = (sout_stream_sys_t *)p_stream->p_sys;
net_Close( p_sys->i_fd );
p_sys->i_fd = -1;
vlc_thread_join(p_stream);
vlc_mutex_destroy(&p_sys->es_lock);
p_stream->p_sout->i_out_pace_nocontrol--;
free(p_sys);
}
/****************************************************************************
* Command Thread:
****************************************************************************/
static void* Command(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;
int canc = vlc_savecancel();
while (vlc_object_alive(p_stream))
{
if (p_sys->i_fd < 0)
break;
char psz_buffer[20];
int i_len = recv(p_sys->i_fd, psz_buffer, sizeof(psz_buffer)-1, 0);
if (i_len < 4)
continue;
psz_buffer[i_len] = '\0';
msg_Info( p_stream, "command: %s", psz_buffer );
if (strncmp(psz_buffer, "show", 4) == 0)
{
vlc_mutex_lock(&p_sys->es_lock);
for (int i = 0; i < p_sys->i_es_num; i++)
{
i_len = snprintf(psz_buffer, sizeof(psz_buffer), "%.4s : %d",
(char *)&p_sys->pp_es[i]->fmt.i_codec,
p_sys->pp_es[i]->fmt.i_id);
psz_buffer[i_len] = '\0';
msg_Info(p_stream, psz_buffer);
}
vlc_mutex_unlock(&p_sys->es_lock);
}
else
{
bool b_apply = false;
bool b_select = false;
int i_pid = 0x1FFF;
if (strncmp(psz_buffer, "enable", 6) == 0)
{
i_pid = atol(psz_buffer+7);
b_select = true;
b_apply = true;
}
else if (strncmp(psz_buffer, "disable", 7) == 0)
{
i_pid = atol(psz_buffer+8);
b_apply = true;
}
if (b_apply)
{
vlc_mutex_lock(&p_sys->es_lock);
for (int i = 0; i < p_sys->i_es_num; i++)
{
msg_Info(p_stream, "elementary stream pid %d",
p_sys->pp_es[i]->fmt.i_id);
if (p_sys->pp_es[i]->fmt.i_id == i_pid)
{
p_sys->pp_es[i]->b_enabled = b_select;
msg_Info(p_stream, "%s: %d", b_select ? "enable" : "disable", i_pid);
}
}
vlc_mutex_unlock(&p_sys->es_lock);
}
}
}
vlc_restorecancel(canc);
return NULL;
}
static sout_stream_id_t *Add(sout_stream_t *p_stream, es_format_t *p_fmt)
{
sout_stream_sys_t *p_sys = (sout_stream_sys_t *)p_stream->p_sys;
sout_stream_id_t *p_es = malloc(sizeof(sout_stream_id_t));
if( !p_es )
return NULL;
p_es->fmt = *p_fmt;
p_es->id = NULL;
p_es->b_error = false;
p_es->b_enabled = (p_es->fmt.i_id == p_sys->i_id_disable) ? false : true;
vlc_mutex_lock(&p_sys->es_lock);
TAB_APPEND(p_sys->i_es_num, p_sys->pp_es, p_es);
vlc_mutex_unlock(&p_sys->es_lock);
return p_es;
}
static int Del(sout_stream_t *p_stream, sout_stream_id_t *p_es)
{
sout_stream_sys_t *p_sys = (sout_stream_sys_t *)p_stream->p_sys;
sout_stream_id_t *id = p_es->id;
vlc_mutex_lock(&p_sys->es_lock);
TAB_REMOVE(p_sys->i_es_num, p_sys->pp_es, p_es);
vlc_mutex_unlock(&p_sys->es_lock);
free(p_es);
if (id != NULL)
return p_stream->p_next->pf_del(p_stream->p_next, id);
else
return VLC_SUCCESS;
}
static int Send(sout_stream_t *p_stream, sout_stream_id_t *p_es,
block_t *p_buffer)
{
if (p_es->id == NULL && p_es->b_error != true)
{
p_es->id = p_stream->p_next->pf_add(p_stream->p_next, &p_es->fmt);
if (p_es->id == NULL)
{
p_es->b_error = true;
msg_Err(p_stream, "couldn't create chain for id %d",
p_es->fmt.i_id);
}
}
if ((p_es->b_error != true) && p_es->b_enabled)
p_stream->p_next->pf_send(p_stream->p_next, p_es->id, p_buffer);
else
block_ChainRelease(p_buffer);
return VLC_SUCCESS;
}
/*****************************************************************************
* setid.c: set ID/lang on a stream
*****************************************************************************
* Copyright (C) 2009-2011 VideoLAN and AUTHORS
*
* 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 Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 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
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#include <string.h>
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_sout.h>
/*****************************************************************************
* Module descriptor
*****************************************************************************/
#define ID_TEXT N_("Elementary Stream ID")
#define ID_LONGTEXT N_( \
"Specify an identifier integer for this elementary stream" )
#define NEWID_TEXT N_("New ES ID")
#define NEWID_LONGTEXT N_( \
"Specify an new identifier integer for this elementary stream" )
#define LANG_TEXT N_("Language")
#define LANG_LONGTEXT N_( \
"Specify an ISO-639 code (three characters) for this elementary stream" )
static int OpenId ( vlc_object_t * );
static int OpenLang ( vlc_object_t * );
static void Close ( vlc_object_t * );
#define SOUT_CFG_PREFIX_ID "sout-setid-"
#define SOUT_CFG_PREFIX_LANG "sout-setlang-"
vlc_module_begin()
set_shortname( N_("Set ID"))
set_section( N_("Set ES id"), NULL )
set_description( N_("Change the id of an elementary stream"))
set_capability( "sout stream", 50 )
add_shortcut( "setid" )
set_category( CAT_SOUT )
set_subcategory( SUBCAT_SOUT_STREAM )
set_callbacks( OpenId, Close )
add_integer( SOUT_CFG_PREFIX_ID "id", 0, NULL, ID_TEXT, ID_LONGTEXT, false )
add_integer( SOUT_CFG_PREFIX_ID "new-id", 0, NULL, NEWID_TEXT, NEWID_LONGTEXT,
false )
add_submodule ()
set_section( N_("Set ES Lang"), NULL )
set_shortname( N_("Set Lang"))
set_description( N_("Change the language of an elementary stream"))
set_capability( "sout stream", 50 )
add_shortcut( "setlang" );
set_callbacks( OpenLang, Close )
add_integer( SOUT_CFG_PREFIX_LANG "id", 0, NULL, ID_TEXT, ID_LONGTEXT, false )
add_string( SOUT_CFG_PREFIX_LANG "lang", "eng", NULL, LANG_TEXT, LANG_LONGTEXT,
false );
vlc_module_end()
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static const char *ppsz_sout_options_id[] = {
"id", "new-id", NULL
};
static const char *ppsz_sout_options_lang[] = {
"id", "lang", NULL
};
static sout_stream_id_t *AddId ( sout_stream_t *, es_format_t * );
static sout_stream_id_t *AddLang ( 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 * );
struct sout_stream_sys_t
{
int i_id;
int i_new_id;
char *psz_language;
};
/*****************************************************************************
* Open:
*****************************************************************************/
static int OpenCommon( vlc_object_t *p_this )
{
sout_stream_t *p_stream = (sout_stream_t*)p_this;
sout_stream_sys_t *p_sys;
if( !p_stream->p_next )
{
msg_Err( p_stream, "cannot create chain" );
return VLC_EGENERIC;
}
p_sys = malloc( sizeof( sout_stream_sys_t ) );
if( unlikely( !p_sys ) )
return VLC_ENOMEM;
p_stream->pf_del = Del;
p_stream->pf_send = Send;
p_stream->p_sys = p_sys;
return VLC_SUCCESS;
}
static int OpenId( vlc_object_t *p_this )
{
int i_ret = OpenCommon( p_this );
if( i_ret != VLC_SUCCESS )
return i_ret;
sout_stream_t *p_stream = (sout_stream_t*)p_this;
config_ChainParse( p_stream, SOUT_CFG_PREFIX_ID, ppsz_sout_options_id,
p_stream->p_cfg );
p_stream->p_sys->i_id = var_GetInteger( p_stream, SOUT_CFG_PREFIX_ID "id" );
p_stream->p_sys->i_new_id = var_GetInteger( p_stream, SOUT_CFG_PREFIX_ID "new-id" );
p_stream->p_sys->psz_language = NULL;
p_stream->pf_add = AddId;
return VLC_SUCCESS;
}
static int OpenLang( vlc_object_t *p_this )
{
int i_ret = OpenCommon( p_this );
if( i_ret != VLC_SUCCESS )
return i_ret;
sout_stream_t *p_stream = (sout_stream_t*)p_this;
config_ChainParse( p_stream, SOUT_CFG_PREFIX_LANG, ppsz_sout_options_lang,
p_stream->p_cfg );
p_stream->p_sys->i_id = var_GetInteger( p_stream, SOUT_CFG_PREFIX_LANG "id" );
p_stream->p_sys->i_new_id = -1;
p_stream->p_sys->psz_language = var_GetString( p_stream, SOUT_CFG_PREFIX_LANG "lang" );
p_stream->pf_add = AddLang;
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 = (sout_stream_sys_t *)p_stream->p_sys;
free( p_sys->psz_language );
free( p_sys );
}
static sout_stream_id_t * AddId( sout_stream_t *p_stream, es_format_t *p_fmt )
{
sout_stream_sys_t *p_sys = (sout_stream_sys_t *)p_stream->p_sys;
if ( p_fmt->i_id == p_sys->i_id )
{
msg_Dbg( p_stream, "turning ID %d to %d",
p_sys->i_id, p_sys->i_new_id );
p_fmt->i_id = p_sys->i_new_id;
}
return p_stream->p_next->pf_add( p_stream->p_next, p_fmt );
}
static sout_stream_id_t * AddLang( sout_stream_t *p_stream, es_format_t *p_fmt )
{
sout_stream_sys_t *p_sys = (sout_stream_sys_t *)p_stream->p_sys;
if ( p_fmt->i_id == p_sys->i_id )
{
msg_Dbg( p_stream, "turning language %s of ID %d to %s",
p_fmt->psz_language ? p_fmt->psz_language : "unk",
p_sys->i_id, p_sys->psz_language );
p_fmt->psz_language = strdup( p_sys->psz_language );
}
return p_stream->p_next->pf_add( p_stream->p_next, p_fmt );
}
static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
{
return p_stream->p_next->pf_del( p_stream->p_next, id );
}
static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
block_t *p_buffer )
{
return p_stream->p_next->pf_send( p_stream->p_next, id, p_buffer );
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment