Skip to content

Commit 684e26a

Browse files
committed
sync last commits from original minisatip - 1cd36d9.
1 parent 8d16db6 commit 684e26a

16 files changed

+490
-225
lines changed

src/adapter.c

+48-70
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ int a_count;
6262
char disabled[MAX_ADAPTERS]; // disabled adapters
6363
int sock_signal;
6464
char do_dump_pids = 1;
65+
uint64_t source_map[MAX_SOURCES];
6566

6667
SMutex a_mutex;
6768

@@ -97,7 +98,7 @@ adapter *adapter_alloc()
9798
ad->diseqc_multi = opts.diseqc_multi;
9899

99100
/* enable all sources */
100-
ad->debug_pos[0]='\0';
101+
ad->debug_pos[0] = '\0';
101102
ad->debug_src = 0;
102103
int i;
103104
for (i = 0; i <= MAX_SOURCES; i++)
@@ -111,7 +112,6 @@ adapter *adapter_alloc()
111112
ad->diseqc_param.lnb_circular = opts.lnb_circular;
112113
ad->diseqc_param.lnb_switch = opts.lnb_switch;
113114

114-
ad->failed_adapter = 0;
115115
ad->adapter_timeout = opts.adapter_timeout;
116116

117117
ad->strength_multiplier = opts.strength_multiplier;
@@ -234,6 +234,19 @@ int close_adapter_for_socket(sockets *s)
234234
return close_adapter(aid);
235235
}
236236

237+
void adapter_set_dvr(adapter *ad)
238+
{
239+
ad->sock = sockets_add(ad->dvr, NULL, ad->id, TYPE_DVR, (socket_action)read_dmx,
240+
(socket_action)close_adapter_for_socket,
241+
(socket_action)adapter_timeout);
242+
memset(ad->buf, 0, opts.adapter_buffer + 1);
243+
set_socket_buffer(ad->sock, (unsigned char *)ad->buf, opts.adapter_buffer);
244+
if (ad->adapter_timeout > 0)
245+
sockets_timeout(ad->sock, ad->adapter_timeout);
246+
if (opts.th_priority > 0)
247+
set_thread_prio(get_socket_thread(ad->sock), opts.th_priority);
248+
}
249+
237250
int init_complete = 0;
238251
int num_adapters = 0;
239252

@@ -268,12 +281,10 @@ int init_hw(int i)
268281
goto NOK;
269282
}
270283

271-
ad->sock = -1;
272284
ad->id = i;
273285
ad->fe_sock = -1;
274286
ad->sock = -1;
275287
ad->force_close = 0;
276-
ad->restart_needed = 0;
277288
ad->err = 0;
278289
#ifdef GXAPI
279290
ad->gx_ts_config = opts.ts_config & 0x1f;
@@ -336,11 +347,9 @@ int init_hw(int i)
336347
}
337348
memset(ad->buf, 0, opts.adapter_buffer + 1);
338349
init_dvb_parameters(&ad->tp);
339-
if (!ad->failed_adapter)
340-
{
341-
mark_pids_deleted(i, -1, NULL);
342-
update_pids(i);
343-
}
350+
mark_pids_deleted(i, -1, NULL);
351+
update_pids(i);
352+
344353
if (!ad->sys[0])
345354
ad->delsys(i, ad->fe, ad->sys);
346355
ad->master_sid = -1;
@@ -353,19 +362,11 @@ int init_hw(int i)
353362
ad->threshold = opts.udp_threshold;
354363
ad->updating_pids = 0;
355364
ad->wait_new_stream = 0;
356-
ad->failed_adapter = 0;
357365
ad->rtime = getTick();
358-
ad->sock = sockets_add(ad->dvr, NULL, i, TYPE_DVR, (socket_action)read_dmx,
359-
(socket_action)close_adapter_for_socket,
360-
(socket_action)adapter_timeout);
361-
memset(ad->buf, 0, opts.adapter_buffer + 1);
362-
set_socket_buffer(ad->sock, (unsigned char *)ad->buf, opts.adapter_buffer);
363-
if (ad->adapter_timeout > 0)
364-
sockets_timeout(ad->sock, ad->adapter_timeout);
366+
adapter_set_dvr(ad);
365367
snprintf(ad->name, sizeof(ad->name), "AD%d", i);
366-
set_socket_thread(ad->sock, start_new_thread(ad->name));
367-
if (opts.th_priority > 0)
368-
set_thread_prio(get_socket_thread(ad->sock), opts.th_priority);
368+
ad->thread = start_new_thread(ad->name);
369+
set_socket_thread(ad->sock, ad->thread);
369370
#ifndef DISABLE_PMT
370371
pmt_init_device(ad);
371372
#endif
@@ -402,18 +403,6 @@ int init_hw(int i)
402403
return 1;
403404
}
404405

405-
int enable_failed_adapter(int id)
406-
{
407-
if (id < 0 || id >= MAX_ADAPTERS)
408-
return 1;
409-
adapter *ad = a[id];
410-
if (!ad)
411-
return 1;
412-
413-
ad->failed_adapter = 1;
414-
return init_hw(id);
415-
}
416-
417406
int init_all_hw()
418407
{
419408
int i, rv;
@@ -537,7 +526,7 @@ int getAdaptersCount()
537526
// Note: Adapter 0 uses map bit 0, sources_pos ranges from 0..MAX_SOURCES+1 and source_map ranges from 0..SRC-1 (SRC=0 can't be configured)
538527
for (j = 0; j < MAX_SOURCES; j++)
539528
{
540-
ad->sources_pos[j+1] = (source_map[j] >> i) & 1;
529+
ad->sources_pos[j + 1] = (source_map[j] >> i) & 1;
541530
}
542531

543532
if (!opts.force_sadapter && (delsys_match(ad, SYS_DVBS) || delsys_match(ad, SYS_DVBS2)))
@@ -611,7 +600,7 @@ int getAdaptersCount()
611600
for (i = 0; i < MAX_ADAPTERS; i++)
612601
if ((ad = a[i]))
613602
{
614-
ad->debug_pos[0]='\0';
603+
ad->debug_pos[0] = '\0';
615604
ad->debug_src = 0;
616605
lsrc[0] = '\0';
617606
for (j = 1; j <= MAX_SOURCES; j++)
@@ -631,7 +620,7 @@ int getAdaptersCount()
631620
}
632621
}
633622
if (strlen(lsrc) > 0)
634-
lsrc[0]=' ';
623+
lsrc[0] = ' ';
635624
DEBUGM("Adpater %d enabled sources:%s", i, lsrc);
636625
DEBUGM("Adpater %d debug sources: %s (%lu)", i, ad->debug_pos, ad->debug_src);
637626
}
@@ -857,11 +846,10 @@ int set_adapter_for_stream(int sid, int aid)
857846
return 0;
858847
}
859848

860-
void close_adapter_for_stream(int sid, int aid)
849+
void close_adapter_for_stream(int sid, int aid, int close_stream)
861850
{
862851
adapter *ad;
863852
streams *s = get_sid(sid);
864-
int is_slave = 1;
865853
if (!(ad = get_adapter(aid)))
866854
return;
867855

@@ -879,16 +867,14 @@ void close_adapter_for_stream(int sid, int aid)
879867
}
880868
if (ad->sid_cnt > 0)
881869
ad->sid_cnt--;
882-
LOG("closed adapter %d for sid %d m:%d sid_cnt:%d, restart_needed %d", aid, sid, ad->master_sid,
883-
ad->sid_cnt, ad->restart_needed);
870+
LOG("closed adapter %d for sid %d m:%d sid_cnt:%d", aid, sid, ad->master_sid, ad->sid_cnt);
884871
// delete the attached PIDs as well
885872
if (ad->sid_cnt == 0)
886873
{
887-
is_slave = 0;
888874
ad->master_sid = -1;
889875
mark_pids_deleted(aid, -1, NULL);
890876
init_dvb_parameters(&ad->tp);
891-
if (ad->standby)
877+
if (ad->standby && close_stream)
892878
ad->standby(ad);
893879
#ifdef AXE
894880
free_axe_input(ad);
@@ -906,12 +892,6 @@ void close_adapter_for_stream(int sid, int aid)
906892
update_pids(aid);
907893
adapter_update_threshold(ad);
908894
mutex_unlock(&ad->mutex);
909-
if ((ad->restart_needed == 1) && !is_slave)
910-
{
911-
LOG("restarting adapter %d as needed", ad->id);
912-
// request_adapter_close (ad);
913-
close_adapter(ad->id);
914-
}
915895
}
916896

917897
int update_pids(int aid)
@@ -922,7 +902,7 @@ int update_pids(int aid)
922902
if (!ad || ad->updating_pids)
923903
return 1;
924904

925-
if(ad->err)
905+
if (ad->err)
926906
{
927907
LOG("adapter %d in error state %d", aid, ad->err);
928908
return 1;
@@ -970,7 +950,12 @@ int update_pids(int aid)
970950
dp = 0;
971951
if (ad->pids[i].fd <= 0)
972952
{
973-
if ((ad->pids[i].fd = ad->set_pid(ad, ad->pids[i].pid)) < 0)
953+
int pid = ad->pids[i].pid;
954+
// For pids=all emulation add just the PAT pid. process_pmt will add
955+
// the other pids
956+
if (opts.emulate_pids_all && pid == 8192)
957+
pid = 0;
958+
if ((ad->pids[i].fd = ad->set_pid(ad, pid)) < 0)
974959
{
975960
ad->max_pids = ad->max_active_pids - 1;
976961
LOG0("Maximum pid filter reached, lowering the value to %d", opts.max_pids);
@@ -985,6 +970,7 @@ int update_pids(int aid)
985970
ad->pat_processed = 0;
986971
ad->pids[i].packets = 0;
987972
ad->pids[i].cc = -1;
973+
ad->pids[i].cc1 = -1;
988974
ad->pids[i].cc_err = 0;
989975
ad->pids[i].dec_err = 0;
990976
}
@@ -1044,8 +1030,6 @@ int tune(int aid, int sid)
10441030
ad->snr = 0;
10451031
flush_data = 1;
10461032
ad->is_t2mi = 0;
1047-
if (ad->restart_when_tune)
1048-
ad->restart_needed = 1;
10491033
set_socket_pos(ad->sock, 0); // flush the existing buffer
10501034
ad->rlen = 0;
10511035
if (ad->sid_cnt > 1) // the master changed the frequency
@@ -1159,6 +1143,14 @@ void mark_pids_deleted(int aid, int sid, char *pids) //pids==NULL -> delete all
11591143

11601144
LOG("deleting pids on adapter %d, sid %d, pids=%s", aid, sid,
11611145
pids ? pids : "NULL");
1146+
1147+
// If "delpids=all" provided, delete all the pids for this stream
1148+
if (pids && strstr(pids, "all"))
1149+
{
1150+
LOG("deleting all the pids on adapter %d, sid %d, pids=%s", aid, sid, pids);
1151+
pids = NULL;
1152+
}
1153+
11621154
if (pids)
11631155
{
11641156
la = split(arg, pids, ARRAY_SIZE(arg), ',');
@@ -1336,7 +1328,7 @@ int set_adapter_parameters(int aid, int sid, transponder *tp)
13361328
return -1;
13371329
}
13381330
}
1339-
1331+
13401332
if (0 && (ad->tp.apids || ad->tp.pids || ad->tp.dpids))
13411333
dump_pids(aid);
13421334
mutex_unlock(&ad->mutex);
@@ -1389,7 +1381,7 @@ describe_adapter(int sid, int aid, char *dad, int ld)
13891381
ss = get_sid(sid);
13901382

13911383
use_ad = 1;
1392-
if (!(ad = get_adapter(aid)) || (ss && !ss->do_play))
1384+
if (!(ad = get_adapter_nw(aid)) || (ss && !ss->do_play))
13931385
{
13941386
if (aid < 0)
13951387
aid = 0;
@@ -1464,7 +1456,7 @@ describe_adapter(int sid, int aid, char *dad, int ld)
14641456
else
14651457
strlcatf(dad, ld, len, "%s", t->pids ? t->pids : t->apids);
14661458
}
1467-
else if(!use_ad)
1459+
else if (!use_ad)
14681460
strlcatf(dad, ld, len, "%s", "none");
14691461

14701462
LOGM("describe_adapter: sid %d, aid %d => %s", sid, aid, dad);
@@ -1720,7 +1712,7 @@ void set_sources_adapters(char *o)
17201712
goto ERR;
17211713
source_map[i] = all;
17221714
char buf2[128];
1723-
buf2[0]='\0';
1715+
buf2[0] = '\0';
17241716
for (j = 0; j < MAX_ADAPTERS; j++)
17251717
strcat(buf2, "X");
17261718
LOGM(" src=%d using adapters %s (%lu)", i + 1, buf2, (unsigned long)source_map[i]);
@@ -1752,7 +1744,7 @@ void set_sources_adapters(char *o)
17521744
}
17531745
}
17541746
}
1755-
buf2[0]='\0';
1747+
buf2[0] = '\0';
17561748
for (j = 0; j < MAX_ADAPTERS; j++)
17571749
if (source_map[i] & ((unsigned long)1 << j))
17581750
strcat(buf2, "X");
@@ -1769,7 +1761,6 @@ void set_sources_adapters(char *o)
17691761
LOG("Adapter sources format parameter %s, using defaults for all adapters!", strlen(arg[0]) > 0 ? "incorrect" : "missing");
17701762
}
17711763

1772-
17731764
void set_diseqc_multi(char *o)
17741765
{
17751766
int i, la, a_id, position;
@@ -2368,19 +2359,6 @@ char *get_all_delsys(int aid, char *dest, int max_size)
23682359
return dest;
23692360
}
23702361

2371-
void restart_needed_adapters(int aid, int sid)
2372-
{
2373-
adapter *ad = get_adapter(aid);
2374-
if (ad)
2375-
LOGM("starting restart_needed_adapters %d, rn: %d, sc %d, master_sid %d, sid %d", aid, ad->restart_needed, ad->sid_cnt, ad->master_sid, sid);
2376-
2377-
if (ad && ad->enabled && ad->restart_needed && ((ad->sid_cnt == 0 || ad->master_sid == sid)))
2378-
{
2379-
LOG("restart of the adapter %d requested", ad->id);
2380-
close_adapter(ad->id);
2381-
}
2382-
}
2383-
23842362
int get_adapter_ccerrs(int aid)
23852363
{
23862364
int i, cc = 0;

src/adapter.h

+9-7
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,9 @@ typedef struct struct_adapter
6262
int pa, fn;
6363
// flags
6464

65-
char slow_dev, restart_when_tune, restart_needed;
65+
char slow_dev;
6666
char err; // adapter in an error state (initialized but not working correctly)
6767
int adapter_timeout;
68-
char failed_adapter; // is set when the adapter was closed unexpected and needs to be re-enabled
6968
char flush, updating_pids;
7069
// physical adapter, physical frontend number
7170
uint8_t sys[MAX_DELSYS];
@@ -108,12 +107,14 @@ typedef struct struct_adapter
108107
int active_demux_pids;
109108
int is_t2mi;
110109
uint64_t tune_time;
110+
pthread_t thread;
111111
char name[5];
112112
char null_packets;
113113
char drop_encrypted;
114+
char failed_adapter; // failed adapters will not be closed due to timeout nor chosen in get_free_adapters
114115
#ifndef DISABLE_PMT
115116
int transponder_id,
116-
pat_ver, pat_filter, sdt_filter;
117+
pat_ver, pat_filter, sdt_filter;
117118
#endif
118119
#ifdef AXE
119120
int fe2;
@@ -136,7 +137,7 @@ typedef struct struct_adapter
136137
} adapter;
137138

138139
extern adapter *a[MAX_ADAPTERS];
139-
uint64_t source_map[MAX_SOURCES];
140+
extern uint64_t source_map[MAX_SOURCES];
140141
extern int a_count;
141142
extern char do_dump_pids;
142143

@@ -147,7 +148,7 @@ adapter *adapter_alloc();
147148
int close_adapter(int na);
148149
int get_free_adapter(transponder *tp);
149150
int set_adapter_for_stream(int sid, int aid);
150-
void close_adapter_for_stream(int sid, int aid);
151+
void close_adapter_for_stream(int sid, int aid, int close_stream);
151152
int set_adapter_parameters(int aid, int sid, transponder *tp);
152153
void mark_pids_deleted(int aid, int sid, char *pids);
153154
int mark_pids_add(int sid, int aid, char *pids);
@@ -179,14 +180,15 @@ int get_all_pids(adapter *ad, int *pids, int lpids);
179180
char *get_adapter_pids(int aid, char *dest, int max_size);
180181
void adapter_lock1(char *FILE, int line, int aid);
181182
void adapter_unlock1(char *FILE, int line, int aid);
183+
int adapter_timeout(sockets *s);
184+
void adapter_set_dvr(adapter *ad);
182185
char is_adapter_disabled(int i);
183186
void set_adapters_delsys(char *o);
184187
void set_lnb_adapters(char *o);
185188
void set_signal_multiplier(char *o);
186189
int signal_thread(sockets *s);
190+
int close_adapter_for_socket(sockets *s);
187191
int compare_tunning_parameters(int aid, transponder *tp);
188-
void restart_needed_adapters(int aid, int sid);
189-
int enable_failed_adapter(int id);
190192
void request_adapter_close(adapter *ad);
191193
int compare_slave_parameters(adapter *ad, transponder *tp);
192194
#define get_adapter(a) get_adapter1(a, __FILE__, __LINE__)

0 commit comments

Comments
 (0)