Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
SAT>IP server: add mux handling configuration option
  • Loading branch information
perexg committed Mar 17, 2015
1 parent e424493 commit e1a14df
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 16 deletions.
8 changes: 8 additions & 0 deletions docs/html/config_misc.html
Expand Up @@ -169,6 +169,14 @@
<dd>
Exported DVB-C tuners - streaming instances.

<dt>Muxes Handling
<dd>
When SAT>IP client requests new mux configuration, tvheadend can handle it
in three ways. The auto (0) configuration means that if the mux does not exists,
a temporary mux is created and removed when the client closes the
connection. The keep (1) configuration will remember all successfuly scanned muxes.
The reject (2) configuration will reject unknown muxes.

</dl>

</dl>
Expand Down
20 changes: 15 additions & 5 deletions src/satip/rtsp.c
Expand Up @@ -29,6 +29,10 @@
#define RTP_BUFSIZE (256*1024)
#define RTCP_BUFSIZE (16*1024)

#define MUXCNF_AUTO 0
#define MUXCNF_KEEP 1
#define MUXCNF_REJECT 2

typedef struct slave_subscription {
LIST_ENTRY(slave_subscription) link;
mpegts_service_t *service;
Expand Down Expand Up @@ -64,6 +68,7 @@ static uint16_t stream_id;
static char *rtsp_ip = NULL;
static int rtsp_port = -1;
static int rtsp_descramble = 1;
static int rtsp_muxcnf = MUXCNF_AUTO;
static void *rtsp_server = NULL;
static TAILQ_HEAD(,session) rtsp_sessions;
static pthread_mutex_t rtsp_lock;
Expand Down Expand Up @@ -313,7 +318,8 @@ rtsp_clean(session_t *rs)
}
if (rs->prch.prch_id)
profile_chain_close(&rs->prch);
if (rs->mux && rs->mux_created)
if (rs->mux && rs->mux_created &&
(rtsp_muxcnf != MUXCNF_KEEP || LIST_EMPTY(&rs->mux->mm_services)))
rs->mux->mm_delete((mpegts_mux_t *)rs->mux, 1);
rs->mux = NULL;
rs->mux_created = 0;
Expand Down Expand Up @@ -430,7 +436,8 @@ rtsp_start
if (mux) break;
}
}
if (mux == NULL && mn2) {
if (mux == NULL && mn2 &&
(rtsp_muxcnf == MUXCNF_AUTO || rtsp_muxcnf == MUXCNF_KEEP)) {
dvb_mux_conf_str(&rs->dmc, buf, sizeof(buf));
tvhwarn("satips", "%i/%s/%i: create mux %s",
rs->frontend, rs->session, rs->stream, buf);
Expand All @@ -443,8 +450,9 @@ rtsp_start
}
if (mux == NULL) {
dvb_mux_conf_str(&rs->dmc, buf, sizeof(buf));
tvhwarn("satips", "%i/%s/%i: unable to create mux %s",
rs->frontend, rs->session, rs->stream, buf);
tvhwarn("satips", "%i/%s/%i: unable to create mux %s%s",
rs->frontend, rs->session, rs->stream, buf,
rtsp_muxcnf == MUXCNF_REJECT ? " (configuration)" : "");
goto endclean;
}
if (rs->mux == mux)
Expand Down Expand Up @@ -1314,7 +1322,8 @@ rtsp_close_sessions(void)
/*
*
*/
void satip_server_rtsp_init(const char *bindaddr, int port, int descramble)
void satip_server_rtsp_init
(const char *bindaddr, int port, int descramble, int muxcnf)
{
static tcp_server_ops_t ops = {
.start = rtsp_serve,
Expand All @@ -1340,6 +1349,7 @@ void satip_server_rtsp_init(const char *bindaddr, int port, int descramble)
rtsp_ip = strdup(bindaddr);
rtsp_port = port;
rtsp_descramble = descramble;
rtsp_muxcnf = muxcnf;
if (!rtsp_server)
rtsp_server = tcp_server_create(bindaddr, port, &ops, NULL);
if (reg)
Expand Down
20 changes: 11 additions & 9 deletions src/satip/server.c
Expand Up @@ -491,15 +491,15 @@ static void satips_rtsp_port(int def)
*
*/

static void satip_server_info(const char *prefix, int descramble)
static void satip_server_info(const char *prefix, int descramble, int muxcnf)
{
tvhinfo("satips", "SAT>IP Server %sinitialized "
"(HTTP %s:%d, RTSP %s:%d, "
"descramble %d, DVB-T %d, DVB-S2 %d, DVB-C %d)",
"descramble %d, muxcnf %d, DVB-T %d, DVB-S2 %d, DVB-C %d)",
prefix,
http_server_ip, http_server_port,
http_server_ip, satip_server_rtsp_port,
descramble,
descramble, muxcnf,
config_get_int("satip_dvbt", 0),
config_get_int("satip_dvbs", 0),
config_get_int("satip_dvbc", 0));
Expand All @@ -510,15 +510,16 @@ static void satip_server_info(const char *prefix, int descramble)
*/
void satip_server_config_changed(void)
{
int descramble;
int descramble, muxcnf;

if (!satip_server_rtsp_port_locked) {
satips_rtsp_port(0);
if (satip_server_rtsp_port > 0) {
descramble = config_get_int("satip_descramble", 1);
muxcnf = config_get_int("satip_muxcnf", 0);
pthread_mutex_unlock(&global_lock);
satip_server_rtsp_init(http_server_ip, satip_server_rtsp_port, descramble);
satip_server_info("re", descramble);
satip_server_rtsp_init(http_server_ip, satip_server_rtsp_port, descramble, muxcnf);
satip_server_info("re", descramble, muxcnf);
satips_upnp_send_announce();
pthread_mutex_lock(&global_lock);
} else {
Expand All @@ -539,7 +540,7 @@ void satip_server_init(int rtsp_port)
{
struct sockaddr_storage http;
char http_ip[128];
int descramble;
int descramble, muxcnf;

http_server_ip = NULL;
satip_server_bootid = time(NULL);
Expand All @@ -562,10 +563,11 @@ void satip_server_init(int rtsp_port)
return;

descramble = config_get_int("satip_descramble", 1);
muxcnf = config_get_int("satip_muxcnf", 0);

satip_server_rtsp_init(http_server_ip, satip_server_rtsp_port, descramble);
satip_server_rtsp_init(http_server_ip, satip_server_rtsp_port, descramble, muxcnf);

satip_server_info("", descramble);
satip_server_info("", descramble, muxcnf);
}

void satip_server_register(void)
Expand Down
3 changes: 2 additions & 1 deletion src/satip/server.h
Expand Up @@ -48,7 +48,8 @@ void satip_rtp_close(void *id);
void satip_rtp_init(void);
void satip_rtp_done(void);

void satip_server_rtsp_init(const char *bindaddr, int port, int descramble);
void satip_server_rtsp_init(const char *bindaddr, int port,
int descramble, int muxcnf);
void satip_server_rtsp_register(void);
void satip_server_rtsp_done(void);

Expand Down
2 changes: 2 additions & 0 deletions src/webui/extjs.c
Expand Up @@ -537,6 +537,8 @@ extjs_config(http_connection_t *hc, const char *remain, void *opaque)
ssave |= config_set_int("satip_dvbs", atoi(str));
if ((str = http_arg_get(&hc->hc_req_args, "satip_dvbc")))
ssave |= config_set_int("satip_dvbc", atoi(str));
if ((str = http_arg_get(&hc->hc_req_args, "satip_muxcnf")))
ssave |= config_set_int("satip_muxcnf", atoi(str));
if (save | ssave)
config_save();
if (ssave)
Expand Down
7 changes: 6 additions & 1 deletion src/webui/static/app/config.js
Expand Up @@ -246,13 +246,18 @@ tvheadend.miscconf = function(panel, index) {
name: 'satip_dvbc',
fieldLabel: 'Exported DVB-C Tuners'
});
var muxcnf = new Ext.form.NumberField({
name: 'satip_muxcnf',
fieldLabel: 'Muxes Handling (0 = auto, 1 = keep, 2 = reject)'
});

satipPanel = new Ext.form.FieldSet({
title: 'SAT>IP Server',
width: 700,
autoHeight: true,
collapsible: true,
animCollapse: true,
items: [rtsp, weight, descramble, dvbt, dvbs, dvbc]
items: [rtsp, weight, descramble, dvbt, dvbs, dvbc, muxcnf]
});
}

Expand Down

0 comments on commit e1a14df

Please sign in to comment.