Exemplo n.º 1
0
// avoid adapter close unless all the adapters can be closed
int adapter_timeout(sockets *s)
{
	int do_close = 1, i, max_close = 0;
	int rtime = getTick();
	adapter *ad = get_adapter(s->sid);
	if (!ad)
		return 1;

	if (ad->force_close)
		return 1;

	if (get_streams_for_adapter(ad->id) > 0)
	{
		ad->rtime = getTick();
		s->rtime = ad->rtime;
		LOG("Keeping the adapter %d open as there are active streams", ad->id);
		return 0;
	}
	for (i = 0; i < MAX_ADAPTERS; i++)
		if ((ad = get_adapter_nw(i)))
		{
			if (rtime - ad->rtime < s->close_sec)
				do_close = 0;
			if (ad && max_close < ad->rtime)
				max_close = ad->rtime;

		}
	LOG("Requested adapter %d close due to timeout, result %d max_rtime %d",
			s->sid, do_close, max_close);
	if (!do_close)
		s->rtime = max_close;

	return do_close;
}
Exemplo n.º 2
0
int get_free_adapter(int freq, int pol, int msys, int src)
{
	int i;
	adapter *ad;
	init_all_hw();

	i = (src > 0) ? src - 1 : 0;
	ad = get_adapter(i);
	if (ad)
		LOG("get free adapter %d - a[%d] => e:%d m:%d sid_cnt:%d f:%d pol=%d",
				src - 1, i, ad->enabled, ad->master_sid, ad->sid_cnt,
				ad->tp.freq, ad->tp.pol)
	else
		LOG("get free adapter %d msys %s", i, get_delsys(i));

	if (src > 0)
	{
		if (ad)
		{
			if (ad->sid_cnt == 0 && delsys_match(ad, msys))
				return i;
			if (ad->tp.freq == freq && delsys_match(ad, msys))
				return i;
		}
	}
	for (i = 0; i < MAX_ADAPTERS; i++)
		//first free adapter that has the same msys
		if ((ad = get_adapter_nw(i)) && ad->sid_cnt == 0
				&& delsys_match(ad, msys))
			return i;

	for (i = 0; i < MAX_ADAPTERS; i++)
		if ((ad = get_adapter_nw(i)) && a[i]->tp.freq == freq
				&& delsys_match(ad, msys))
		{
			if ((msys == SYS_DVBS2 || msys == SYS_DVBS) && ad->tp.pol == pol)
				return i;
			else
				return i;
		}
	LOG("no adapter found for f:%d pol:%d msys:%d", freq, pol, msys);
	dump_adapters();
	return -1;
}
Exemplo n.º 3
0
void dump_adapters()
{
	int i;
	adapter *ad;
	if (!opts.log)
		return;
	LOG("Dumping adapters:");
	for (i = 0; i < MAX_ADAPTERS; i++)
		if ((ad = get_adapter_nw(i)))
			LOG("%d|f: %d sid_cnt:%d master_sid:%d del_sys: %s %s %s", i,
					ad->tp.freq, ad->sid_cnt, ad->master_sid,
					get_delsys(ad->sys[0]), get_delsys(ad->sys[1]),
					get_delsys(ad->sys[2]));
	dump_streams();

}
Exemplo n.º 4
0
void close_adapter(int na)
{
	adapter *ad;
	init_complete = 0;

	ad = get_adapter_nw(na);
	if (!ad)
		return;
	mutex_lock(&ad->mutex);
	if (!ad->enabled)
	{
		mutex_unlock(&ad->mutex);
		return;
	}
	LOG("closing adapter %d  -> fe:%d dvr:%d", na, ad->fe, ad->dvr);
	ad->enabled = 0;
	if (ad->close)
		ad->close(ad);
	//close all streams attached to this adapter
//	close_streams_for_adapter (na, -1);
	mark_pids_deleted(na, -1, NULL);
	update_pids(na);
	//      if(ad->dmx>0)close(ad->dmx);
	if (ad->fe > 0)
		close(ad->fe);
	if (ad->sock > 0)
		sockets_del(ad->sock);
	if (ad->ca_mask > 0)
		tables_close_device(ad);
	ad->ca_mask = 0;
	ad->fe = 0;
	ad->dvr = 0;
	ad->strength = 0;
	ad->snr = 0;
	mutex_unlock(&ad->mutex);
	mutex_destroy(&ad->mutex);
	//      if(a[na]->buf)free1(a[na]->buf);a[na]->buf=NULL;
	LOG("done closing adapter %d", na);
}
Exemplo n.º 5
0
int getAdaptersCount()
{
	int i;
	adapter *ad;
	tuner_s2 = tuner_c2 = tuner_t2 = tuner_c = tuner_t = 0;
	if (opts.force_sadapter)
		tuner_s2 = opts.force_sadapter;
	if (opts.force_tadapter)
		tuner_t = opts.force_tadapter;
	if (opts.force_cadapter)
		tuner_c = opts.force_cadapter;
	for (i = 0; i < MAX_ADAPTERS; i++)
		if ((ad = get_adapter_nw(i)))
		{
			if (!opts.force_sadapter
					&& (delsys_match(ad, SYS_DVBS)
							|| delsys_match(ad, SYS_DVBS2)))
				tuner_s2++;

			if (!opts.force_tadapter && delsys_match(ad, SYS_DVBT)
					&& !delsys_match(ad, SYS_DVBT2))
				tuner_t++;

			if (!opts.force_cadapter && delsys_match(ad, SYS_DVBC_ANNEX_A)
					&& !delsys_match(ad, SYS_DVBC2))
				tuner_c++;

			if (delsys_match(ad, SYS_DVBT2))
				tuner_t2++;

			if (delsys_match(ad, SYS_DVBC2))
				tuner_c2++;
		}

	return tuner_s2 + tuner_c2 + tuner_t2 + tuner_c + tuner_t;
}
Exemplo n.º 6
0
void del_ca(SCA *c)
{
	int i, j, k, eq, mask = 1;
	adapter *ad;
	mutex_lock(&ca_mutex);

	for (i = 0; i < MAX_CA; i++)
	{
		if (ca[i].enabled)
		{
			eq = 1;
			for (j = 0; j < sizeof(ca[0].action) / sizeof(ca_action); j++)
				if (ca[i].action[j] != c->action[j])
					eq = 0;
			if (eq)
			{
				ca[i].enabled = 0;
				for (k = 0; k < MAX_ADAPTERS; k++)
				{
					if ((ad = get_adapter_nw(k)))
						ad->ca_mask &= ~mask;
				}
			}
		}
		mask = mask << 1;
	}
	i = MAX_CA;
	while (--i >= 0 && !ca[i].enabled)
		;
	nca = i + 1;

//	if (nca == 1)
//		nca = 0;

	mutex_unlock(&ca_mutex);
}