Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
satip client: fix the satpos network limit
  • Loading branch information
perexg committed May 27, 2016
1 parent 8725137 commit 5f0746b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 30 deletions.
75 changes: 52 additions & 23 deletions src/input/mpegts/satip/satip_frontend.c
Expand Up @@ -479,9 +479,10 @@ satip_frontend_match_satcfg
( satip_frontend_t *lfe2, mpegts_mux_t *mm2, int flags, int weight )
{
satip_frontend_t *lfe_master;
satip_satconf_t *sfc;
mpegts_mux_t *mm1 = NULL;
dvb_mux_conf_t *mc1, *mc2;
int position, weight2, high1, high2;
int weight2, high1, high2;

if (!lfe2->sf_running)
return 0;
Expand All @@ -497,8 +498,8 @@ satip_frontend_match_satcfg
}

mm1 = lfe2->sf_req->sf_mmi->mmi_mux;
position = satip_satconf_get_position(lfe2, mm2, NULL, 0, 0, -1);
if (position <= 0 || lfe_master->sf_position != position)
sfc = satip_satconf_get_position(lfe2, mm2, NULL, 0, 0, -1);
if (!sfc || lfe_master->sf_position != sfc->sfc_position)
return 0;
mc1 = &((dvb_mux_t *)mm1)->lm_tuning;
mc2 = &((dvb_mux_t *)mm2)->lm_tuning;
Expand All @@ -519,16 +520,16 @@ satip_frontend_is_enabled
{
satip_frontend_t *lfe = (satip_frontend_t*)mi;
satip_frontend_t *lfe2;
int position;
satip_satconf_t *sfc;

lock_assert(&global_lock);

if (!mpegts_input_is_enabled(mi, mm, flags, weight)) return 0;
if (lfe->sf_device->sd_dbus_allow <= 0) return 0;
if (lfe->sf_type != DVB_TYPE_S) return 1;
/* check if the position is enabled */
position = satip_satconf_get_position(lfe, mm, NULL, 1, flags, weight);
if (position <= 0)
sfc = satip_satconf_get_position(lfe, mm, NULL, 1, flags, weight);
if (!sfc)
return 0;
/* check if any "blocking" tuner is running */
TAILQ_FOREACH(lfe2, &lfe->sf_device->sd_frontends, sf_link) {
Expand Down Expand Up @@ -581,18 +582,24 @@ satip_frontend_warm_mux
( mpegts_input_t *mi, mpegts_mux_instance_t *mmi )
{
satip_frontend_t *lfe = (satip_frontend_t*)mi;
satip_satconf_t *sfc;
int r;

r = mpegts_input_warm_mux(mi, mmi);
if (r)
return r;

if (lfe->sf_positions > 0) {
lfe->sf_position = satip_satconf_get_position(lfe, mmi->mmi_mux,
&lfe->sf_netposhash,
2, 0, -1);
if (lfe->sf_position <= 0)
sfc = satip_satconf_get_position(lfe, mmi->mmi_mux,
&lfe->sf_netposhash,
2, 0, -1);
if (sfc) {
lfe->sf_position = sfc->sfc_position;
lfe->sf_netgroup = sfc->sfc_network_group;
lfe->sf_netlimit = MAX(1, sfc->sfc_network_limit);
} else {
return SM_CODE_TUNING_FAILED;
}
}

return 0;
Expand Down Expand Up @@ -631,6 +638,8 @@ satip_frontend_start_mux
tr->sf_weight = weight;

tr->sf_netposhash = lfe->sf_netposhash;
tr->sf_netlimit = lfe->sf_netlimit;
tr->sf_netgroup = lfe->sf_netgroup;

pthread_mutex_lock(&lfe->sf_dvr_lock);
lfe->sf_req = tr;
Expand Down Expand Up @@ -987,37 +996,55 @@ satip_frontend_other_is_waiting( satip_frontend_t *lfe )
{
satip_device_t *sd = lfe->sf_device;
satip_frontend_t *lfe2;
int r = 0, hash1, hash2;
int r, i, cont, hash1, hash2, limit0, limit, group, *hashes, count;

if (lfe->sf_type != DVB_TYPE_S)
return 0;

pthread_mutex_lock(&lfe->sf_dvr_lock);
hash1 = lfe->sf_req ? lfe->sf_req->sf_netposhash : 0;
if (lfe->sf_req) {
hash1 = lfe->sf_req->sf_netposhash;
limit = (limit0 = lfe->sf_req->sf_netlimit) - 1;
group = lfe->sf_req->sf_netgroup;
} else {
hash1 = limit0 = limit = group = 0;
}
pthread_mutex_unlock(&lfe->sf_dvr_lock);

if (hash1 == 0)
return 0;

r = count = 0;
pthread_mutex_lock(&sd->sd_tune_mutex);
TAILQ_FOREACH(lfe2, &lfe->sf_device->sd_frontends, sf_link) count++;
hashes = alloca(sizeof(int) * count);
memset(hashes, 0, sizeof(int) * count);
TAILQ_FOREACH(lfe2, &lfe->sf_device->sd_frontends, sf_link) {
if (lfe2 == lfe)
continue;
if ((lfe->sf_master && lfe2->sf_number != lfe->sf_master) ||
(lfe2->sf_master && lfe->sf_number != lfe2->sf_master))
continue;
if (lfe2 == lfe) continue;
pthread_mutex_lock(&lfe2->sf_dvr_lock);
cont = 0;
if (limit0 > 0) {
cont = group > 0 && lfe2->sf_req_thread && group != lfe2->sf_req_thread->sf_netgroup;
} else {
cont = (lfe->sf_master && lfe2->sf_number != lfe->sf_master) ||
(lfe2->sf_master && lfe->sf_number != lfe2->sf_master);
}
hash2 = lfe2->sf_req_thread ? lfe2->sf_req_thread->sf_netposhash : 0;
pthread_mutex_unlock(&lfe2->sf_dvr_lock);
if (hash2 == 0)
continue;
if (cont || hash2 == 0) continue;
if (hash2 != hash1) {
r = 1;
break;
for (i = 0; i < count; i++) {
if (hashes[i] == hash2) break;
if (hashes[i] == 0) {
hashes[i] = hash2;
r++;
break;
}
}
}
}
pthread_mutex_unlock(&sd->sd_tune_mutex);
return r;
return r > limit;
}

static void
Expand All @@ -1040,7 +1067,7 @@ satip_frontend_wake_other_waiting
continue;
pthread_mutex_lock(&lfe2->sf_dvr_lock);
hash2 = lfe2->sf_req ? lfe2->sf_req->sf_netposhash : 0;
if (hash2 != 0 && hash1 == hash2 && lfe2->sf_running)
if (hash2 != 0 && hash1 != hash2 && lfe2->sf_running)
tvh_write(lfe2->sf_dvr_pipe.wr, "o", 1);
pthread_mutex_unlock(&lfe2->sf_dvr_lock);
}
Expand Down Expand Up @@ -2065,6 +2092,8 @@ satip_frontend_create

/* Defaults */
lfe->sf_position = -1;
lfe->sf_netlimit = 1;
lfe->sf_netgroup = 0;

/* Callbacks */
lfe->mi_get_weight = satip_frontend_get_weight;
Expand Down
5 changes: 4 additions & 1 deletion src/input/mpegts/satip/satip_private.h
Expand Up @@ -109,6 +109,8 @@ struct satip_tune_req {
int sf_weight;
int sf_weight_tuned;

int sf_netlimit;
int sf_netgroup;
int sf_netposhash;
};

Expand Down Expand Up @@ -160,6 +162,7 @@ struct satip_frontend
dvb_mux_t *sf_curmux;
time_t sf_last_data_tstamp;
int sf_netlimit;
int sf_netgroup;
int sf_netposhash;

/*
Expand Down Expand Up @@ -256,7 +259,7 @@ int satip_satconf_get_priority
int satip_satconf_get_grace
( satip_frontend_t *lfe, mpegts_mux_t *mm );

int satip_satconf_get_position
satip_satconf_t *satip_satconf_get_position
( satip_frontend_t *lfe, mpegts_mux_t *mm, int *hash,
int check, int flags, int weight );

Expand Down
12 changes: 6 additions & 6 deletions src/input/mpegts/satip/satip_satconf.c
Expand Up @@ -99,7 +99,7 @@ satip_satconf_hash ( mpegts_mux_t *mm, int position )
assert(position <= 0x7fff);
return 1 | (mc->dmc_fe_freq > 11700000 ? 2 : 0) |
((int)mc->u.dmc_fe_qpsk.polarisation << 8) |
(position << 16);
((position & 0xffff) << 16);
}

static int
Expand Down Expand Up @@ -174,7 +174,7 @@ satip_satconf_check_limits
return 0;
}

int
satip_satconf_t *
satip_satconf_get_position
( satip_frontend_t *lfe, mpegts_mux_t *mm, int *hash,
int check, int flags, int weight )
Expand All @@ -185,15 +185,15 @@ satip_satconf_get_position
if (hash)
*hash = sfc->sfc_network_group > 0 ? satip_satconf_hash(mm, sfc->sfc_position) : 0;
if (!check)
return sfc->sfc_position;
return sfc;
if (check > 1) {
satip_satconf_check_limits(lfe, sfc, mm, flags, weight, 1);
return sfc->sfc_position;
return sfc;
} else {
if (sfc->sfc_network_limit <= 0)
return sfc->sfc_position;
return sfc;
if (satip_satconf_check_limits(lfe, sfc, mm, flags, weight, 0))
return sfc->sfc_position;
return sfc;
}
} else {
if (hash)
Expand Down

0 comments on commit 5f0746b

Please sign in to comment.