Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
SAT>IP client: implement tvhweight passing
  • Loading branch information
perexg committed Nov 30, 2015
1 parent 1461c64 commit bed9b61
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/input/mpegts/satip/satip.c
Expand Up @@ -475,6 +475,8 @@ satip_device_hack( satip_device_t *sd )
sd->sd_pids_max = 128;
sd->sd_pids_len = 2048;
sd->sd_no_univ_lnb = 1;
if (strcmp(sd->sd_info.modelnum ?: "", "1.0"))
sd->sd_can_weight = 1;
} else if (strstr(sd->sd_info.manufacturer, "AVM Berlin") &&
strstr(sd->sd_info.modelname, "FRITZ!")) {
sd->sd_fullmux_ok = 0;
Expand Down
73 changes: 63 additions & 10 deletions src/input/mpegts/satip/satip_frontend.c
Expand Up @@ -174,6 +174,13 @@ const idclass_t satip_frontend_class =
.opts = PO_ADVANCED,
.off = offsetof(satip_frontend_t, sf_teardown_delay),
},
{
.type = PT_BOOL,
.id = "pass_weight",
.name = N_("Pass weight"),
.opts = PO_ADVANCED,
.off = offsetof(satip_frontend_t, sf_pass_weight),
},
{
.type = PT_STR,
.id = "tunerbindaddr",
Expand Down Expand Up @@ -512,6 +519,11 @@ satip_frontend_start_mux

mpegts_pid_init(&tr->sf_pids);
mpegts_pid_init(&tr->sf_pids_tuned);
if (lfe->sf_device->sd_can_weight) {
pthread_mutex_lock(&mi->mi_output_lock);
tr->sf_weight = mpegts_mux_instance_weight(mmi);
pthread_mutex_unlock(&mi->mi_output_lock);
}

pthread_mutex_lock(&lfe->sf_dvr_lock);
lfe->sf_req = tr;
Expand Down Expand Up @@ -570,6 +582,28 @@ satip_frontend_update_pids
tvh_write(lfe->sf_dvr_pipe.wr, "c", 1);
}

static void
satip_frontend_open_service ( mpegts_input_t *mi, mpegts_service_t *s, int flags, int init )
{
satip_frontend_t *lfe = (satip_frontend_t*)mi;
satip_tune_req_t *tr;

mpegts_input_open_service(mi, s, flags, init);

if (!lfe->sf_device->sd_can_weight)
return;

pthread_mutex_lock(&lfe->sf_dvr_lock);
if ((tr = lfe->sf_req) != NULL && tr->sf_mmi != NULL) {
pthread_mutex_lock(&mi->mi_output_lock);
tr->sf_weight = mpegts_mux_instance_weight(tr->sf_mmi);
pthread_mutex_unlock(&mi->mi_output_lock);
}
pthread_mutex_unlock(&lfe->sf_dvr_lock);

tvh_write(lfe->sf_dvr_pipe.wr, "c", 1);
}

static idnode_set_t *
satip_frontend_network_list ( mpegts_input_t *mi )
{
Expand Down Expand Up @@ -750,9 +784,10 @@ satip_frontend_pid_changed( http_client_t *rtsp,
tr->sf_pids_tuned.all = 1;
pthread_mutex_unlock(&lfe->sf_dvr_lock);
if (i)
return 0;
goto skip;

r = satip_rtsp_play(rtsp, "all", NULL, NULL, max_pids_len);
tr->sf_weight_tuned = tr->sf_weight;
r = satip_rtsp_play(rtsp, "all", NULL, NULL, max_pids_len, tr->sf_weight);
r = r == 0 ? 1 : r;

} else if (!lfe->sf_device->sd_pids_deladd ||
Expand All @@ -771,9 +806,10 @@ satip_frontend_pid_changed( http_client_t *rtsp,
mpegts_pid_done(&wpid);

if (!j || add[0] == '\0')
return 0;
goto skip;

r = satip_rtsp_play(rtsp, add, NULL, NULL, max_pids_len);
tr->sf_weight_tuned = tr->sf_weight;
r = satip_rtsp_play(rtsp, add, NULL, NULL, max_pids_len, tr->sf_weight);
r = r == 0 ? 1 : r;

} else {
Expand Down Expand Up @@ -811,15 +847,23 @@ satip_frontend_pid_changed( http_client_t *rtsp,
mpegts_pid_done(&pdel);

if (add[0] == '\0' && del[0] == '\0')
return 0;
goto skip;

r = satip_rtsp_play(rtsp, NULL, add, del, max_pids_len);
tr->sf_weight_tuned = tr->sf_weight;
r = satip_rtsp_play(rtsp, NULL, add, del, max_pids_len, tr->sf_weight);
r = r == 0 ? 1 : r;
}

if (r < 0)
tvherror("satip", "%s - failed to modify pids: %s", name, strerror(-r));
return r;

skip:
if (tr->sf_weight_tuned != tr->sf_weight) {
tr->sf_weight_tuned = tr->sf_weight;
r = satip_rtsp_play(rtsp, NULL, NULL, NULL, 0, tr->sf_weight);
}
return 0;
}

static void
Expand Down Expand Up @@ -1328,11 +1372,14 @@ satip_frontend_input_thread ( void *aux )
rtsp_flags |= SATIP_SETUP_PIDS21;
r = -12345678;
pthread_mutex_lock(&lfe->sf_dvr_lock);
if (lfe->sf_req == lfe->sf_req_thread)
if (lfe->sf_req == lfe->sf_req_thread) {
lfe->sf_req->sf_weight_tuned = lfe->sf_req->sf_weight;
r = satip_rtsp_setup(rtsp,
position, lfe->sf_number,
rtp_port, &lm->lm_tuning,
rtsp_flags);
rtsp_flags,
lfe->sf_req->sf_weight);
}
pthread_mutex_unlock(&lfe->sf_dvr_lock);
if (r < 0) {
if (r != -12345678)
Expand Down Expand Up @@ -1445,10 +1492,13 @@ satip_frontend_input_thread ( void *aux )
if (lfe->sf_play2) {
r = -12345678;
pthread_mutex_lock(&lfe->sf_dvr_lock);
if (lfe->sf_req == lfe->sf_req_thread)
if (lfe->sf_req == lfe->sf_req_thread) {
lfe->sf_req->sf_weight_tuned = lfe->sf_req->sf_weight;
r = satip_rtsp_setup(rtsp, position, lfe->sf_number,
rtp_port, &lm->lm_tuning,
rtsp_flags | SATIP_SETUP_PLAY);
rtsp_flags | SATIP_SETUP_PLAY,
lfe->sf_req->sf_weight);
}
pthread_mutex_unlock(&lfe->sf_dvr_lock);
if (r < 0) {
tvherror("satip", "%s - failed to tune2 (%i)", buf, r);
Expand Down Expand Up @@ -1653,6 +1703,7 @@ satip_frontend_hacks( satip_frontend_t *lfe, int *def_positions )
satip_device_t *sd = lfe->sf_device;

lfe->sf_tdelay = 50; /* should not hurt anything */
lfe->sf_pass_weight = 1;
if (strstr(sd->sd_info.location, ":8888/octonet.xml")) {
if (lfe->sf_type == DVB_TYPE_S)
lfe->sf_play2 = 1;
Expand Down Expand Up @@ -1729,6 +1780,7 @@ satip_frontend_create
lfe->sf_type_v2 = v2;
lfe->sf_master = master;
lfe->sf_type_override = override ? strdup(override) : NULL;
lfe->sf_pass_weight = 1;
satip_frontend_hacks(lfe, &def_positions);
TAILQ_INIT(&lfe->sf_satconf);
pthread_mutex_init(&lfe->sf_dvr_lock, NULL);
Expand Down Expand Up @@ -1761,6 +1813,7 @@ satip_frontend_create
lfe->mi_stop_mux = satip_frontend_stop_mux;
lfe->mi_network_list = satip_frontend_network_list;
lfe->mi_update_pids = satip_frontend_update_pids;
lfe->mi_open_service = satip_frontend_open_service;
lfe->mi_empty_status = mpegts_input_empty_status;

/* Adapter link */
Expand Down
9 changes: 7 additions & 2 deletions src/input/mpegts/satip/satip_private.h
Expand Up @@ -92,6 +92,7 @@ struct satip_device
int sd_pids21;
int sd_pilot_on;
int sd_no_univ_lnb;
int sd_can_weight;
int sd_dbus_allow;
int sd_skip_ts;
int sd_disable_workarounds;
Expand All @@ -103,6 +104,9 @@ struct satip_tune_req {

mpegts_apids_t sf_pids;
mpegts_apids_t sf_pids_tuned;

int sf_weight;
int sf_weight_tuned;
};

struct satip_frontend
Expand All @@ -127,6 +131,7 @@ struct satip_frontend
int sf_play2;
int sf_tdelay;
int sf_teardown_delay;
int sf_pass_weight;
char *sf_tuner_bindaddr;

/*
Expand Down Expand Up @@ -244,11 +249,11 @@ int
satip_rtsp_setup( http_client_t *hc,
int src, int fe, int udp_port,
const dvb_mux_conf_t *dmc,
int flags );
int flags, int weight );

int
satip_rtsp_play( http_client_t *hc, const char *pids,
const char *addpids, const char *delpids,
int max_pids_len );
int max_pids_len, int weight );

#endif /* __TVH_SATIP_PRIVATE_H__ */
11 changes: 8 additions & 3 deletions src/input/mpegts/satip/satip_rtsp.c
Expand Up @@ -69,7 +69,8 @@ satip_rtsp_add_val(const char *name, char *buf, uint32_t val)

int
satip_rtsp_setup( http_client_t *hc, int src, int fe,
int udp_port, const dvb_mux_conf_t *dmc, int flags )
int udp_port, const dvb_mux_conf_t *dmc, int flags,
int weight )
{
static tvh2satip_t msys[] = {
{ .t = DVB_SYS_DVBT, "dvbt" },
Expand Down Expand Up @@ -220,6 +221,8 @@ satip_rtsp_setup( http_client_t *hc, int src, int fe,
ADD(dmc_fe_modulation, mtype,
dmc->dmc_fe_delsys == DVB_SYS_ATSC ? "8vsb" : "64qam");
}
if (weight > 0)
satip_rtsp_add_val("tvhweight", buf, (uint32_t)weight * 1000);
if (flags & SATIP_SETUP_PIDS0) {
strcat(buf, "&pids=0");
if (flags & SATIP_SETUP_PIDS21)
Expand Down Expand Up @@ -260,7 +263,7 @@ satip_rtsp_pids_strip( const char *s, int maxlen )
int
satip_rtsp_play( http_client_t *hc, const char *pids,
const char *addpids, const char *delpids,
int max_pids_len )
int max_pids_len, int weight )
{
htsbuf_queue_t q;
char *stream = NULL;
Expand All @@ -272,7 +275,7 @@ satip_rtsp_play( http_client_t *hc, const char *pids,
addpids = satip_rtsp_pids_strip(addpids, max_pids_len);
delpids = satip_rtsp_pids_strip(delpids, max_pids_len);

if (pids == NULL && addpids == NULL && delpids == NULL)
if (pids == NULL && addpids == NULL && delpids == NULL && weight <= 0)
return -EINVAL;

//printf("pids = '%s' addpids = '%s' delpids = '%s'\n", pids, addpids, delpids);
Expand All @@ -296,6 +299,8 @@ satip_rtsp_play( http_client_t *hc, const char *pids,
htsbuf_qprintf(&q, "addpids=%s", addpids);
}
}
if (weight)
htsbuf_qprintf(&q, "tvhweight=%d", weight);
if (hc->hc_rtsp_stream_id >= 0)
snprintf(stream = _stream, sizeof(_stream), "/stream=%li",
hc->hc_rtsp_stream_id);
Expand Down

0 comments on commit bed9b61

Please sign in to comment.