-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathemulate.c
1074 lines (1005 loc) · 51.6 KB
/
emulate.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <ctype.h>
#include <sys/errno.h>
#include "emulate.h"
#include "dump-vdr.h" // debugging transponder.
#include "dump-xine.h" // debugging transponder.
#include "dvbscan.h" // debugging transponder.
#include "tools.h" // hexdump
#define Hz 1
#define kHz (1000 * Hz)
#define MHz (1000 * kHz)
//#define EM_INFO(msg...) info(msg)
#define EM_INFO(msg...)
/* this struct stores the contents (DVB SI data) of an section buffer,
* alltogether with the current tuning state of the dvb device.
*/
typedef struct {
/*----------------------------*/
void * prev;
void * next;
uint32_t index;
/*----------------------------*/
uint16_t pid;
uint16_t table_id;
uint16_t table_id_ext;
uint16_t original_network_id;
uint16_t network_id;
uint16_t transport_stream_id;
uint16_t service_id;
uint16_t len;
struct transponder t;
unsigned char buf[SECTION_BUF_SIZE];
} sidata_t;
/*
* list of DVB SI data and list of running demux filters.
*/
cList __em_buf1, * em_runningfilters = &__em_buf1;
cList __em_buf2, * em_sidata = &__em_buf2;
/*
* drivers DVB API.
* NOTE:
* - API defaults to 5.3
* - if not overwritten from log -> bug.
*/
struct {
unsigned major;
unsigned minor;
} em_api = {5, 3};
/*
* The emulated DVB device.
* NOTE:
* - state is set by em_setproperty and returned by em_getproperty
* - not to be exposed outside this file.
*/
static struct {
unsigned w_scan_version;
uint32_t w_scan_flags;
fe_delivery_system_t delsys;
uint32_t frequency;
uint32_t bandwidth_hz;
uint32_t symbolrate;
uint8_t stream_id;
fe_spectral_inversion_t inversion;
fe_modulation_t modulation;
fe_code_rate_t fec;
fe_pilot_t pilot;
fe_rolloff_t rolloff;
fe_transmit_mode_t transmission;
fe_guard_interval_t guard;
fe_hierarchy_t hierarchy;
fe_polarization_t polarization;
struct dvb_frontend_info fe_info;
fe_delivery_system_t delsystems[32];
uint8_t ndelsystems;
scantype_t scantype;
bool T2_delsys_bug;
bool highband;
uint32_t lnb_low;
uint32_t lnb_high;
} em_device;
#define EM_OLD_DELSYSLIST (((uint32_t)1) << 1)
#define EM_OLD_APIDISP (((uint32_t)1) << 2)
#define EM_HEXDUMP_BUG (((uint32_t)1) << 3)
#define EM_OLD_SI_HEADER (((uint32_t)1) << 4)
/*
* forward declarations.
*/
static int parse_logfile(const char * log);
// Declare parse_xyz in scan.h? Hmm..
extern void parse_pat (const unsigned char * buf, uint16_t section_length, uint16_t transport_stream_id, uint32_t flags);
extern void parse_pmt (const unsigned char * buf, uint16_t section_length, uint16_t service_id);
extern void parse_nit (const unsigned char * buf, uint16_t section_length, uint8_t table_id, uint16_t network_id, uint32_t section_flags);
extern void parse_sdt (const unsigned char * buf, uint16_t section_length, uint16_t transport_stream_id);
extern void parse_psip_vct(const unsigned char * buf, uint16_t section_length, uint8_t table_id, uint16_t transport_stream_id);
/*
* initializes emulated dvb device and fills in data by parsing logfile.
*/
void em_init(const char * log) {
NewList(em_runningfilters, "em_runningfilters");
NewList(em_sidata, "em_sidata");
memset(&em_device, 0, sizeof(em_device));
parse_logfile(log);
}
/*
* let 'frontend_fd' be any non-negative int to pass validity checks.
*/
void em_open(int * frontend_fd) {
*frontend_fd = 1;
}
/*
* replaces FE_GET_INFO ioctl.
*/
void em_info(struct dvb_frontend_info * fe_info) {
memcpy(fe_info, &em_device.fe_info, sizeof(struct dvb_frontend_info));
}
/*
* replaces DTV_API_VERSION ioctl.
*/
void em_dvbapi(uint16_t * flags) {
*flags = (em_api.major << 8) | em_api.minor;
}
/*
* replaces FE_SET_PROPERTY ioctl.
*/
int em_setproperty(struct dtv_properties * cmdseq) {
uint8_t i;
for (i=0; i<cmdseq->num; i++) {
switch(cmdseq->props[i].cmd) {
case DTV_DELIVERY_SYSTEM: em_device.delsys = cmdseq->props[i].u.data; break;
case DTV_FREQUENCY: em_device.frequency = cmdseq->props[i].u.data; break;
case DTV_INVERSION: em_device.inversion = cmdseq->props[i].u.data; break;
case DTV_MODULATION: em_device.modulation = cmdseq->props[i].u.data; break;
case DTV_SYMBOL_RATE: em_device.symbolrate = cmdseq->props[i].u.data; break;
case DTV_INNER_FEC: em_device.fec = cmdseq->props[i].u.data; break;
case DTV_PILOT: em_device.pilot = cmdseq->props[i].u.data; break;
case DTV_ROLLOFF: em_device.rolloff = cmdseq->props[i].u.data; break;
case DTV_STREAM_ID: em_device.stream_id = cmdseq->props[i].u.data; break;
case DTV_BANDWIDTH_HZ: em_device.bandwidth_hz = cmdseq->props[i].u.data; break;
case DTV_CODE_RATE_HP: em_device.fec = cmdseq->props[i].u.data; break;
case DTV_TRANSMISSION_MODE: em_device.transmission = cmdseq->props[i].u.data; break;
case DTV_GUARD_INTERVAL: em_device.guard = cmdseq->props[i].u.data; break;
case DTV_HIERARCHY: em_device.hierarchy = cmdseq->props[i].u.data; break;
case DTV_CLEAR: break; // what to do with clear?
default:;
}
}
return 0; // no err.
}
/*
* replaces FE_GET_PROPERTY ioctl.
*/
int em_getproperty(struct dtv_properties * cmdseq) {
uint8_t i;
int j,k;
for (i=0; i<cmdseq->num; i++) {
switch(cmdseq->props[i].cmd) {
case DTV_DELIVERY_SYSTEM: cmdseq->props[i].u.data = em_device.delsys ; break;
case DTV_FREQUENCY: cmdseq->props[i].u.data = em_device.frequency ; break;
case DTV_INVERSION: cmdseq->props[i].u.data = em_device.inversion ; break;
case DTV_MODULATION: cmdseq->props[i].u.data = em_device.modulation ; break;
case DTV_SYMBOL_RATE: cmdseq->props[i].u.data = em_device.symbolrate ; break;
case DTV_INNER_FEC: cmdseq->props[i].u.data = em_device.fec ; break;
case DTV_PILOT: cmdseq->props[i].u.data = em_device.pilot ; break;
case DTV_ROLLOFF: cmdseq->props[i].u.data = em_device.rolloff ; break;
case DTV_STREAM_ID: cmdseq->props[i].u.data = em_device.stream_id ; break;
case DTV_BANDWIDTH_HZ: cmdseq->props[i].u.data = em_device.bandwidth_hz ; break;
case DTV_CODE_RATE_HP: cmdseq->props[i].u.data = em_device.fec ; break;
case DTV_TRANSMISSION_MODE: cmdseq->props[i].u.data = em_device.transmission ; break;
case DTV_GUARD_INTERVAL: cmdseq->props[i].u.data = em_device.guard ; break;
case DTV_HIERARCHY: cmdseq->props[i].u.data = em_device.hierarchy ; break;
case DTV_ENUM_DELSYS: cmdseq->props[i].u.buffer.len = em_device.ndelsystems;
for(j = 0, k = em_device.ndelsystems - 1; j < em_device.ndelsystems; j++, k--)
cmdseq->props[i].u.buffer.data[k] = em_device.delsystems[j];
break;
default:;
}
}
return 0; // no err.
}
void em_lnb(int high_band, uint32_t high_val, uint32_t low_val) {
em_device.highband = high_band;
em_device.lnb_low = low_val;
em_device.lnb_high = high_val;
}
void em_polarization(uint8_t p) {
em_device.polarization = p & 0x3;
}
/*
* INTERNAL USE ONLY. DONT EXPOSE THIS FUNC OUTSIDE THIS FILE.
*/
static int has_lock(fe_delivery_system_t em_delsys, struct transponder * t) {
uint32_t tp_if = 0;
switch(em_delsys) {
case SYS_DVBT:
case SYS_DVBT2:
if (t->frequency != em_device.frequency) return 0;
EM_INFO("%s: f=%u B%uC%dD0M%dT%dG%dY%dS%d\n"
" f=%u B%dC%dD0M%dT%dG%dY%dS%d\n",
__FUNCTION__,
freq_scale(em_device.frequency, 1e-3), freq_scale(em_device.bandwidth_hz, 1e-6), em_device.fec, em_device.modulation , em_device.transmission, em_device.guard, em_device.hierarchy, em_device.delsys==SYS_DVBT2,
freq_scale(t->frequency , 1e-3), freq_scale(t->bandwidth , 1e-6), t->coderate , t->modulation , t->transmission , t->guard , t->hierarchy , t->delsys==SYS_DVBT2
);
if (t->bandwidth != em_device.bandwidth_hz)
return 0;
if ((t->coderate != em_device.fec) && (t->coderate != FEC_AUTO))
return 0;
if ((t->modulation != em_device.modulation) && (t->modulation != QAM_AUTO))
return 0;
if ((t->transmission != em_device.transmission) && (t->transmission != TRANSMISSION_MODE_AUTO))
return 0;
if ((t->guard != em_device.guard) && (t->guard != GUARD_INTERVAL_AUTO))
return 0;
if ((t->hierarchy != em_device.hierarchy) && (t->hierarchy != HIERARCHY_AUTO))
return 0;
if (! em_device.T2_delsys_bug) {
// any dvb driver here, except CXD2820R
if (t->delsys != em_device.delsys)
return 0;
}
else {
// CXD2820R only: driver silently changes delsys.
em_device.delsys = t->delsys;
}
return 0x1F;
break;
case SYS_DVBC_ANNEX_A:
case SYS_DVBC_ANNEX_C:
if (t->frequency != em_device.frequency) return 0;
if ((t->delsys != SYS_DVBC_ANNEX_A) && (t->delsys != SYS_DVBC_ANNEX_C))
return 0;
if ((t->modulation != em_device.modulation) && (em_device.modulation != QAM_AUTO))
return 0;
if (t->symbolrate != em_device.symbolrate)
return 0;
return 0x1F;
break;
case SYS_DVBS2:
if ((t->rolloff != em_device.rolloff) && (em_device.rolloff != ROLLOFF_35) && (em_device.rolloff != ROLLOFF_AUTO)) {
EM_INFO("wrong rolloff: %d != %d\n", t->rolloff, em_device.rolloff);
return 0;
}
if ((t->pilot != em_device.pilot) && (em_device.pilot != PILOT_AUTO)) {
EM_INFO("wrong pilot: %d != %d\n", t->pilot, em_device.pilot);
return 0;
}
/* fall trough. */
case SYS_DVBS:
if (em_device.highband)
tp_if = abs(t->frequency - em_device.lnb_high);
else
tp_if = abs(t->frequency - em_device.lnb_low);
if (abs(tp_if - em_device.frequency) > 2000) {
EM_INFO("t->frequency = %u: tp_if = %u <-> em_device.frequency = %u\n", t->frequency, tp_if, em_device.frequency);
return 0;
}
if (t->delsys != em_device.delsys) {
EM_INFO("wrong delsys\n");
return 0;
}
if (t->polarization != em_device.polarization) {
EM_INFO("wrong polarization\n");
return 0;
}
if ((t->coderate != em_device.fec) && (em_device.fec != FEC_AUTO)) {
EM_INFO("wrong coderate\n");
return 0;
}
if (t->symbolrate != em_device.symbolrate) {
EM_INFO("wrong symbolrate\n");
return 0;
}
if (t->modulation != em_device.modulation) {
EM_INFO("wrong modulation\n");
return 0;
}
return 0x1F;
break;
case SYS_ATSC:
if (t->frequency != em_device.frequency) return 0;
if (t->delsys != em_device.delsys)
return 0;
if (t->modulation != em_device.modulation)
return 0;
return 0x1F;
break;
default:
fatal("unsupported del sys.\n");
}
return 0;
}
/*
* replaces FE_READ_STATUS ioctl.
*/
int em_status(fe_status_t * status) {
sidata_t * s;
*status = 0;
for(s=em_sidata->first; s; s=s->next) {
//char b[256];
//print_transponder(b, &s->t);
//info("%s: try %s (current: %d lo %d highband=%d)\n",__FUNCTION__,b, em_device.frequency, em_device.highband?em_device.lnb_high:em_device.lnb_low, em_device.highband);
if (has_lock(em_device.delsys, &s->t)) {
*status = 0x1F; // sync && lock.
break;
}
}
return 0;
}
/*----------------------------------------------------------------------------------------------------------------------
* DEMUX related.
*---------------------------------------------------------------------------------------------------------------------*/
static const char * table_name(uint16_t id) {
switch(id) {
case TABLE_PAT: return "PAT";
case TABLE_PMT: return "PMT";
case TABLE_NIT_ACT: return "NIT(ACT)";
case TABLE_NIT_OTH: return "NIT(OTH)";
case TABLE_SDT_ACT: return "SDT(ACT)";
case TABLE_SDT_OTH: return "SDT(OTH)";
case TABLE_VCT_TERR: return "VCT(TERR)";
case TABLE_VCT_CABLE: return "VCT(CABLE)";
default: return "???";
}
}
void em_addfilter(struct section_buf * s) {
EM_INFO("%s: %s pid=%d\n", __FUNCTION__, table_name(s->table_id), s->pid);
AddItem(em_runningfilters, s);
}
void em_readfilters(int * result) {
sidata_t * sidata;
struct section_buf * filter;
int maxiter = 10000;
while ((filter = em_runningfilters->first)) {
bool data_found = false;
if (! maxiter--) fatal("%s: max iterations.\n", __FUNCTION__);
for(sidata = em_sidata->first; sidata; sidata = sidata->next) {
if (filter->table_id != sidata->table_id) {
// info("(filter->table_id = %d != table_id = %d), table_id_ext = %d, pid = %d\n", filter->table_id, sidata->table_id, sidata->table_id_ext, sidata->pid);
continue;
}
EM_INFO("f=%-6d: searching %-10s: table_id_ext = %d, pid = %d\n", freq_scale(em_device.frequency, 1e-3), table_name(filter->table_id), filter->table_id_ext, filter->pid);
if (! has_lock(em_device.delsys, &sidata->t)) {
EM_INFO(" -> no lock @ %d\n", freq_scale(sidata->t.frequency, 1e-3));
continue;
}
if ((filter->pid != sidata->pid) && (filter->table_id == TABLE_PMT)) {
EM_INFO(" -> wrong pid %d\n", sidata->pid);
continue;
}
if ((filter->table_id_ext != sidata->table_id_ext) && (filter->table_id_ext > -1)){
EM_INFO(" -> wrong table_id_ext = %d\n", sidata->table_id_ext);
continue;
}
EM_INFO(" -> OK.\n");
data_found = true;
switch(filter->table_id) {
case TABLE_PAT: parse_pat(sidata->buf, sidata->len, sidata->transport_stream_id, filter->flags);
break;
case TABLE_NIT_ACT:
case TABLE_NIT_OTH: parse_nit(sidata->buf, sidata->len, filter->table_id, sidata->network_id, filter->flags);
break;
case TABLE_PMT: verbose("PMT %d (0x%04x) for service %d (0x%04x)\n",
sidata->pid, sidata->pid, sidata->service_id, sidata->service_id);
parse_pmt(sidata->buf, sidata->len, sidata->service_id);
break;
case TABLE_SDT_ACT:
case TABLE_SDT_OTH: verbose("SDT(%s TS, transport_stream_id %d (0x%04x) )\n",
filter->table_id == 0x42 ? "actual":"other",
sidata->transport_stream_id, sidata->transport_stream_id);
parse_sdt(sidata->buf, sidata->len, sidata->transport_stream_id);
break;
case TABLE_VCT_TERR:
case TABLE_VCT_CABLE: verbose("ATSC VCT, table_id %d, table_id_ext %d\n",
sidata->table_id, sidata->table_id_ext);
parse_psip_vct(sidata->buf, sidata->len, filter->table_id, sidata->table_id_ext);
break;
default: fatal("%s %d: unhandled table_id %d\n", __FUNCTION__, __LINE__, filter->table_id);
}
//if (filter->run_once) /* probably i would have to check version nums here. */
// break;
}
if (! data_found) {
const char * intro = " Info: no data from ";
// timeout waiting for data.
switch(filter->table_id) {
case TABLE_PAT:
case TABLE_PMT:
case TABLE_NIT_ACT:
case TABLE_NIT_OTH:
case TABLE_SDT_ACT:
case TABLE_SDT_OTH:
case TABLE_VCT_TERR:
case TABLE_VCT_CABLE: info("%s%s after %lld seconds\n", intro, table_name(filter->table_id), (long long) filter->timeout);
break;
default: info("%spid %u after %lld seconds\n", intro, filter->pid, (long long) filter->timeout);
}
*result = 0;
}
UnlinkItem(em_runningfilters, filter, filter->flags & SECTION_FLAG_FREE ? true:false);
}
*result = 1;
return;
}
static int parse_tp(const char * str) {
uint32_t args[8];
char mbuf[64], fecbuf[5], robuf[5];
char c;
char * p = strchr(str, '(');
if (p && *p) *p=0; // cut '(ONID:NID:SID)'
switch(em_device.scantype) {
case SCAN_TERRESTRIAL:
p = strchr(str, 'P');
if (p) {
em_device.delsys = SYS_DVBT2;
sscanf(p + 1, "%u", &args[0]);
em_device.stream_id = args[0];
}
else {
em_device.delsys = SYS_DVBT;
em_device.stream_id = 0;
}
sscanf(str, "%8s f = %6d kHz I%uB%uC%uD%uT%uG%uY%u",
mbuf, &args[0], &args[1], &args[2], &args[3], &args[4], &args[5], &args[6], &args[7]);
if (strncmp(mbuf, "QPSK" , 4) == 0) em_device.modulation = QPSK;
else if (strncmp(mbuf, "QAM_16" , 6) == 0) em_device.modulation = QAM_16;
else if (strncmp(mbuf, "QAM_64" , 6) == 0) em_device.modulation = QAM_64;
else if (strncmp(mbuf, "QAM_256" , 7) == 0) em_device.modulation = QAM_256;
else em_device.modulation = QAM_AUTO;
em_device.frequency = 1000 * args[0];
switch(args[1]) {
case 0: em_device.inversion = INVERSION_OFF; break;
case 1: em_device.inversion = INVERSION_ON; break;
default: em_device.inversion = INVERSION_AUTO;
}
switch(args[2]) {
case 5 ... 10: em_device.bandwidth_hz = args[2] * MHz; break;
case 1712: em_device.bandwidth_hz = args[2] * kHz; break;
default: em_device.bandwidth_hz = 8 * MHz;
}
switch(args[3]) {
case 0: em_device.fec = FEC_NONE; break;
case 12: em_device.fec = FEC_1_2; break;
case 23: em_device.fec = FEC_2_3; break;
case 34: em_device.fec = FEC_3_4; break;
case 45: em_device.fec = FEC_4_5; break;
case 56: em_device.fec = FEC_5_6; break;
case 67: em_device.fec = FEC_6_7; break;
case 78: em_device.fec = FEC_7_8; break;
case 89: em_device.fec = FEC_8_9; break;
case 35: em_device.fec = FEC_3_5; break;
case 910: em_device.fec = FEC_9_10; break;
default: em_device.fec = FEC_AUTO; break;
}
switch(args[5]) {
case 2: em_device.transmission = TRANSMISSION_MODE_2K; break;
case 8: em_device.transmission = TRANSMISSION_MODE_8K; break;
case 4: em_device.transmission = TRANSMISSION_MODE_4K; break;
case 1: em_device.transmission = TRANSMISSION_MODE_1K; break;
case 16: em_device.transmission = TRANSMISSION_MODE_16K; break;
case 32: em_device.transmission = TRANSMISSION_MODE_32K; break;
default: em_device.transmission = TRANSMISSION_MODE_AUTO; break;
}
switch(args[6]) {
case 32: em_device.guard = GUARD_INTERVAL_1_32; break;
case 16: em_device.guard = GUARD_INTERVAL_1_16; break;
case 8: em_device.guard = GUARD_INTERVAL_1_8; break;
case 4: em_device.guard = GUARD_INTERVAL_1_4; break;
case 128: em_device.guard = GUARD_INTERVAL_1_128; break;
case 19128: em_device.guard = GUARD_INTERVAL_19_128; break;
case 19256: em_device.guard = GUARD_INTERVAL_19_256; break;
default: em_device.guard = GUARD_INTERVAL_AUTO; break;
}
switch(args[7]) {
case 0: em_device.hierarchy = HIERARCHY_NONE; break;
case 1: em_device.hierarchy = HIERARCHY_1; break;
case 2: em_device.hierarchy = HIERARCHY_2; break;
case 4: em_device.hierarchy = HIERARCHY_4; break;
default: em_device.hierarchy = HIERARCHY_AUTO; break;
}
if (em_device.delsys == SYS_DVBT2)
sprintf(mbuf, "P%d", em_device.stream_id);
else
mbuf[0]=0;
//EM_INFO("%s: '%-55s' -> %-8s f = %6d kHz I%sB%sC%sD%sT%sG%sY%s%s\n", \
// __FUNCTION__, str, \
// xine_modulation_name(em_device.modulation), \
// freq_scale(em_device.frequency, 1e-3), \
// vdr_inversion_name(em_device.inversion), \
// vdr_bandwidth_name(em_device.bandwidth_hz), \
// vdr_fec_name(em_device.fec), \
// vdr_fec_name(FEC_NONE), \
// vdr_transmission_mode_name(em_device.transmission), \
// vdr_guard_name(em_device.guard), \
// vdr_hierarchy_name(em_device.hierarchy), \
// mbuf);
break;
case SCAN_TERRCABLE_ATSC:
sscanf(str, "%8s f=%u kHz ", mbuf, &args[0]);
if (strncmp(mbuf, "QAM64" , 5) == 0) em_device.modulation = QAM_64;
else if (strncmp(mbuf, "QAM256" , 6) == 0) em_device.modulation = QAM_256;
else if (strncmp(mbuf, "8VSB" , 4) == 0) em_device.modulation = VSB_8;
else if (strncmp(mbuf, "16VSB" , 5) == 0) em_device.modulation = VSB_16;
else em_device.modulation = QAM_AUTO;
em_device.frequency = 1000 * args[0];
//EM_INFO("%s: '%-55s' -> %-8s f=%d kHz\n", \
// __FUNCTION__, str, \
// atsc_mod_to_txt(em_device.modulation), \
// freq_scale(em_device.frequency, 1e-3));
break;
case SCAN_CABLE:
sscanf(str, "%8s f = %u kHz S%uC%u ", mbuf, &args[0], &args[1], &args[2]);
if (strncmp(mbuf, "QAM_16" , 6) == 0) em_device.modulation = QAM_16;
else if (strncmp(mbuf, "QAM_32" , 6) == 0) em_device.modulation = QAM_32;
else if (strncmp(mbuf, "QAM_64" , 6) == 0) em_device.modulation = QAM_64;
else if (strncmp(mbuf, "QAM_128" , 7) == 0) em_device.modulation = QAM_128;
else if (strncmp(mbuf, "QAM_256" , 7) == 0) em_device.modulation = QAM_256;
else em_device.modulation = QAM_AUTO;
em_device.frequency = 1000 * args[0];
em_device.symbolrate = 1000 * args[1];
em_device.fec = FEC_NONE;
//EM_INFO("%s: '%-55s' -> %-8s f = %d kHz S%dC%s\n", \
// __FUNCTION__, str, \
// xine_modulation_name(em_device.modulation), \
// freq_scale(em_device.frequency, 1e-3), \
// freq_scale(em_device.symbol_rate, 1e-3), \
// vdr_fec_name(FEC_NONE));
break;
case SCAN_SATELLITE:
em_device.delsys = SYS_DVBS;
em_device.rolloff = ROLLOFF_AUTO;
em_device.pilot = PILOT_AUTO;
if (strlen(str) > 2)
if (str[1] == '2') em_device.delsys = SYS_DVBS2;
p = strchr(str, 'f');
if (!p || !*p) return 0;
sscanf(p, "f = %u kHz %c SR = %5d %4s 0,%s %5s ", &args[0], &c, &args[1], fecbuf, robuf, mbuf);
em_device.frequency = 1000 * args[0];
if (c == 'V') em_device.polarization = POLARIZATION_VERTICAL;
else if (c == 'R') em_device.polarization = POLARIZATION_CIRCULAR_RIGHT;
else if (c == 'L') em_device.polarization = POLARIZATION_CIRCULAR_LEFT;
else em_device.polarization = POLARIZATION_HORIZONTAL;
em_device.symbolrate = 1000 * args[1];
if (strncmp(fecbuf, "NONE" , 4) == 0) em_device.fec = FEC_NONE;
else if (strncmp(fecbuf, "1/2" , 3) == 0) em_device.fec = FEC_1_2;
else if (strncmp(fecbuf, "2/3" , 3) == 0) em_device.fec = FEC_2_3;
else if (strncmp(fecbuf, "3/4" , 3) == 0) em_device.fec = FEC_3_4;
else if (strncmp(fecbuf, "4/5" , 3) == 0) em_device.fec = FEC_4_5;
else if (strncmp(fecbuf, "5/6" , 3) == 0) em_device.fec = FEC_5_6;
else if (strncmp(fecbuf, "6/7" , 3) == 0) em_device.fec = FEC_6_7;
else if (strncmp(fecbuf, "7/8" , 3) == 0) em_device.fec = FEC_7_8;
else if (strncmp(fecbuf, "8/9" , 3) == 0) em_device.fec = FEC_8_9;
else if (strncmp(fecbuf, "3/5" , 3) == 0) em_device.fec = FEC_3_5;
else if (strncmp(fecbuf, "9/10" , 4) == 0) em_device.fec = FEC_9_10;
else if (strncmp(fecbuf, "AUTO" , 4) == 0) em_device.fec = FEC_AUTO;
else em_device.fec = FEC_AUTO;
if (strncmp(robuf, "35" , 2) == 0) em_device.rolloff = ROLLOFF_35;
else if (strncmp(robuf, "25" , 2) == 0) em_device.rolloff = ROLLOFF_25;
else if (strncmp(robuf, "20" , 2) == 0) em_device.rolloff = ROLLOFF_20;
else if (strncmp(robuf, "AUTO" , 4) == 0) em_device.rolloff = ROLLOFF_35;
else em_device.rolloff = ROLLOFF_35;
if (strncmp(mbuf, "QPSK" , 4) == 0) em_device.modulation = QPSK;
else if (strncmp(mbuf, "8PSK" , 4) == 0) em_device.modulation = PSK_8;
else if (strncmp(mbuf, "16APSK" , 6) == 0) em_device.modulation = APSK_16;
else if (strncmp(mbuf, "32APSK" , 6) == 0) em_device.modulation = APSK_32;
else em_device.modulation = QPSK;
EM_INFO("%s: '%-55s' -> %-2s f = %d kHz %s SR = %5d %4s 0,%s %5s\n", \
__FUNCTION__, str, \
sat_delivery_system_to_txt(em_device.delsys), \
freq_scale(em_device.frequency, 1e-3), \
sat_pol_to_txt(em_device.polarization), \
freq_scale(em_device.symbolrate, 1e-3), \
sat_fec_to_txt(em_device.fec), \
sat_rolloff_to_txt(em_device.rolloff), \
sat_mod_to_txt(em_device.modulation));
break;
default:
fatal("could not find scan type for '%s'\n", str);
}
return 1; //success.
}
static void parse_intro(uint16_t table_id, const char * str, uint16_t * i1, uint16_t * i2) {
unsigned tmp;
switch(table_id) {
case TABLE_PAT: sscanf(str, "PAT (xxxx:xxxx:%hu)", i1); break;
case TABLE_NIT_ACT: sscanf(str, "NIT(act): (xxxx:%hu:xxxx)", i1); break;
case TABLE_NIT_OTH: sscanf(str, "NIT(oth): (xxxx:%hu:xxxx)", i1); break;
case TABLE_SDT_ACT: sscanf(str, "SDT(actual TS, transport_stream_id %hu ", i1); break;
case TABLE_SDT_OTH: sscanf(str, "SDT(other TS, transport_stream_id %hu ", i1); break;
case TABLE_PMT: sscanf(str, "PMT %hu (0x%04x) for service %hu ", i1, &tmp, i2); break;
default:;
}
//EM_INFO("table_id = %x -> %d %d\n", table_id, *i1, i2?*i2:-1);
}
static int parse_logfile(const char * log) {
FILE * logfile = NULL;
char * line = (char *) calloc(1, 256);
char * p;
int pid = 0, table_id = -1, len = 0, line_no = 0;
uint16_t original_network_id = 0, network_id = 0, transport_stream_id = 0;
uint16_t service_id = 0, pmt_pid = 0;
int dev_props = 0;
sidata_t * sidata = NULL;
bool delsys_list = false;
em_device.scantype = SCAN_UNDEFINED;
em_device.w_scan_version = em_device.w_scan_flags = 0; // logging w_scan's version.
if (!log || !*log) {
free(line);
error("could not open logfile: invalid file name.\n");
return 0; // err
}
logfile = fopen(log, "r");
if (!logfile) {
free(line);
fatal("cannot open '%s': error %d %s\n", log, errno, strerror(errno));
return 0; // err
}
while (fgets(line, 256, logfile) != NULL) {
bool is_tp=false;
line_no++;
// --- get logging w_scan's version -------------------------------------------------------------------------------
if (!em_device.w_scan_version) {
sscanf(line, "w_scan version %u (compiled for DVB API 5.xx)", &em_device.w_scan_version);
EM_INFO("detected w_scan version %u\n", em_device.w_scan_version);
if (em_device.w_scan_version && (em_device.w_scan_version < 20140614)) {
EM_INFO("using flag EM_OLD_DELSYSLIST\n");
em_device.w_scan_flags |= EM_OLD_DELSYSLIST;
}
if (em_device.w_scan_version && (em_device.w_scan_version < 20140529)) {
EM_INFO("using flag EM_OLD_SI_HEADER\n");
em_device.w_scan_flags |= EM_OLD_SI_HEADER;
}
if (em_device.w_scan_version && (em_device.w_scan_version < 20140423)) {
EM_INFO("using flag EM_OLD_APIDISP\n");
em_device.w_scan_flags |= EM_OLD_APIDISP;
EM_INFO("using flag EM_OLD_APIDISP\n");
em_device.w_scan_flags |= EM_HEXDUMP_BUG;
}
continue;
}
// --- end logging w_scan's version -------------------------------------------------------------------------------
// --- get scan type ----------------------------------------------------------------------------------------------
if (em_device.scantype == SCAN_UNDEFINED) {
if (strstr(line, "scan type")) {
if (strstr(line, "CABLE")) em_device.scantype = SCAN_CABLE;
else if (strstr(line, "SATELLITE")) em_device.scantype = SCAN_SATELLITE;
else if (strstr(line, "TERRCABLE_ATSC")) em_device.scantype = SCAN_TERRCABLE_ATSC;
else if (strstr(line, "TERRESTRIAL")) em_device.scantype = SCAN_TERRESTRIAL;
else fatal("cannot read scan type from '%s'\n", line);
}
continue; // anything else is meaningless until this is known.
}
// --- end scan type ----------------------------------------------------------------------------------------------
// --- get the properties of dvb device ---------------------------------------------------------------------------
if (dev_props < 2) {
float fmin, fmax;
if (strstr(line, "-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_")) { dev_props = 2; continue; }
if (strstr(line, "-_-_-_-_ Getting frontend capabilities-_-_-_-_")) { dev_props = 1; continue; }
if (dev_props != 1) continue;
// used DVB API
if (strstr(line, "Using DVB API ")) {
if (em_device.w_scan_flags & EM_OLD_APIDISP) {
sscanf(line, "Using DVB API %x.%x", &em_api.major, &em_api.minor);
}
else {
sscanf(line, "Using DVB API %u.%u", &em_api.major, &em_api.minor);
}
continue;
}
// capabilities: frontend name
if ((p = strstr(line, "frontend ")) && strstr(line, " supports")) {
char * pEnd;
p += 10;
pEnd = strchr(p, 39); *pEnd = 0;
strncpy(&em_device.fe_info.name[0], p, 128);
em_device.T2_delsys_bug = strstr(em_device.fe_info.name, "CXD2820R") != NULL;
continue;
}
// all other capabilities.
if (em_device.scantype == SCAN_TERRESTRIAL) {
if (strstr(line, "DVB-T2")) em_device.fe_info.caps |= FE_CAN_2G_MODULATION;
if (strstr(line, "INVERSION_AUTO") && (strstr(line, "not supported") == NULL)) em_device.fe_info.caps |= FE_CAN_INVERSION_AUTO;
if (strstr(line, "QAM_AUTO") && (strstr(line, "not supported") == NULL)) em_device.fe_info.caps |= FE_CAN_QAM_AUTO;
if (strstr(line, "TRANSMISSION_MODE_AUTO") && (strstr(line, "not supported") == NULL)) em_device.fe_info.caps |= FE_CAN_TRANSMISSION_MODE_AUTO;
if (strstr(line, "GUARD_INTERVAL_AUTO") && (strstr(line, "not supported") == NULL)) em_device.fe_info.caps |= FE_CAN_GUARD_INTERVAL_AUTO;
if (strstr(line, "HIERARCHY_AUTO") && (strstr(line, "not supported") == NULL)) em_device.fe_info.caps |= FE_CAN_HIERARCHY_AUTO;
if (strstr(line, "FEC_AUTO") && (strstr(line, "not supported") == NULL)) em_device.fe_info.caps |= FE_CAN_FEC_AUTO;
if (sscanf(line, "FREQ (%fMHz ... %fMHz)", &fmin, &fmax) == 2) {
em_device.fe_info.frequency_min=(0.5 + fmin * MHz);
em_device.fe_info.frequency_max=(0.5 + fmax * MHz);
}
continue;
}
else if (em_device.scantype == SCAN_CABLE) {
if (strstr(line, "DVB-C2")) em_device.fe_info.caps |= FE_CAN_2G_MODULATION;
if (strstr(line, "INVERSION_AUTO") && (strstr(line, "not supported") == NULL)) em_device.fe_info.caps |= FE_CAN_INVERSION_AUTO;
if (strstr(line, "QAM_AUTO") && (strstr(line, "not supported") == NULL)) em_device.fe_info.caps |= FE_CAN_QAM_AUTO;
if (strstr(line, "FEC_AUTO") && (strstr(line, "not supported") == NULL)) em_device.fe_info.caps |= FE_CAN_FEC_AUTO;
if (sscanf(line, "FREQ (%fMHz ... %fMHz)", &fmin, &fmax) == 2) {
em_device.fe_info.frequency_min =(0.5 + fmin * MHz);
em_device.fe_info.frequency_max =(0.5 + fmax * MHz);
}
if (sscanf(line, "SRATE (%fMSym/s ... %fMSym/s)", &fmin, &fmax) == 2) {
em_device.fe_info.symbol_rate_min=(0.5 + fmin * MHz);
em_device.fe_info.symbol_rate_max=(0.5 + fmax * MHz);
}
continue;
}
else if (em_device.scantype == SCAN_TERRCABLE_ATSC) {
if (strstr(line, "INVERSION_AUTO") && (strstr(line, "not supported") == NULL)) em_device.fe_info.caps |= FE_CAN_INVERSION_AUTO;
if (strstr(line, "8VSB")) em_device.fe_info.caps |= FE_CAN_8VSB;
if (strstr(line, "16VSB")) em_device.fe_info.caps |= FE_CAN_16VSB;
if (strstr(line, "QAM_64")) em_device.fe_info.caps |= FE_CAN_QAM_64;
if (strstr(line, "QAM_256")) em_device.fe_info.caps |= FE_CAN_QAM_256;
if (sscanf(line, "FREQ (%fMHz ... %fMHz)", &fmin, &fmax) == 2) {
em_device.fe_info.frequency_min=(0.5 + fmin * MHz);
em_device.fe_info.frequency_max=(0.5 + fmax * MHz);
}
continue;
}
else if (em_device.scantype == SCAN_SATELLITE) {
if (strstr(line, "QAM_AUTO") && (strstr(line, "not supported") == NULL)) em_device.fe_info.caps |= FE_CAN_QAM_AUTO;
if (strstr(line, "DVB-S2") && (strstr(line, "not supported") == NULL)) em_device.fe_info.caps |= FE_CAN_2G_MODULATION;
if (strstr(line, "DVB-S") && (strstr(line, "not supported") == NULL)) em_device.fe_info.caps |= FE_CAN_QPSK;
if (sscanf(line, "FREQ (%fGHz ... %fGHz)", &fmin, &fmax) == 2) {
em_device.fe_info.frequency_min = (0.5 + fmin * MHz);
em_device.fe_info.frequency_max = (0.5 + fmax * MHz);
}
if (sscanf(line, "SRATE (%fMSym/s ... %fMSym/s)", &fmin, &fmax) == 2) {
em_device.fe_info.symbol_rate_min=(0.5 + fmin * MHz);
em_device.fe_info.symbol_rate_max=(0.5 + fmax * MHz);
}
continue;
}
else
fatal("unsupported frontend type, cannot parse '%s'\n", line);
}
if (em_device.w_scan_flags & EM_OLD_DELSYSLIST) {
EM_INFO("%d: lookup oldstyle delsys hex array\n", line_no);
if (strstr(line, "=====================") == NULL) {
info("skip line %d: '%s'\n", line_no, line);
}
else {
int len = 0;
unsigned tmp, args[16];
//EM_INFO("lookup oldstyle delsys hex array: started\n");
while(fgets(line, 256, logfile) != NULL) {
EM_INFO("checking line '%s'", line);
line_no++;
if (strstr(line, " ======================"))
continue;
if (!len) {
sscanf(line, " len = %d", &len);
continue;
}
if (len) {
int i;
int nitems = sscanf(line, " 0x%X: %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X :",
&tmp,
&args[0], &args[1], &args[2], &args[3], &args[4], &args[5], &args[6], &args[7],
&args[8], &args[9], &args[10], &args[11], &args[12], &args[13], &args[14], &args[15]);
EM_INFO("nitems = %d\n", nitems);
if (!nitems)
continue;
for(i=0; i<len; i++)
em_device.delsystems[em_device.ndelsystems++] = (fe_delivery_system_t) args[i];
//for(i=0; i<em_device.ndelsystems; i++)
// info("delsys %d\n", em_device.delsystems[i]);
break;
}
}
em_device.w_scan_flags &= ~EM_OLD_DELSYSLIST;
}
continue;
}
if ((p = strstr(line, " check ")) != NULL) {
delsys_list=true;
continue;
}
if (delsys_list) {
const char * dname[] = {
"UNDEFINED", "DVB-C ann.A", "DVB-C ann.B", "DVB-T", "DSS", "DVB-S", "DVB-S2", "DVB-H", "ISDB-T", "ISDB-S",
"ISDB-C", "ATSC", "ATSC/MH", "DTMB", "CMMB", "DAB", "DVB-T2", "TURBO-FEC", "DVB-C ann.C"};
uint8_t i = 0;
bool delsys = false;
p = strchr(line, '\n');
if (p) *p = 0;
p = line;
while(p && isspace(*p)) p++;
for(i=0; i<sizeof(dname)/sizeof(dname[0]); i++) {
//EM_INFO("'%s' = '%s'?\n",p,dname[i]);
if (strncmp(p, dname[i], strlen(p)) == 0) {
em_device.delsystems[em_device.ndelsystems++] = (fe_delivery_system_t) i;
delsys = true;
break;
}
}
if (delsys)
continue;
else
delsys_list = false;
}
if (dev_props != 2) continue; // continue only after frontend reading.
// --- end of dvb device ------------------------------------------------------------------------------------------
// --- we tuned to a new transponder. all si data belongs to this new tp ------------------------------------------
if (strncmp(line, " signal ok: ", 19) == 0) is_tp=true; // ' signal ok: <FOOBAR>'
if (strncmp(line, "tune to: " , 9) == 0) is_tp=true; // 'tune to: <FOOBAR>'
if (strncmp(line, "signal ok:", 10) == 0) {
if (fgets(line, 256, logfile) != NULL) {
*line=':';
}
line_no++;
is_tp=true;
}
if (is_tp) {
char * p = strchr(line, ':'); p++;
while(isspace(*p)) p++;
parse_tp(p);
table_id = -1;
continue;
}
// --- end of tp reading ------------------------------------------------------------------------------------------
// --- we got data from demux. first: intro with table_id_ext -----------------------------------------------------
if (strstr(line, "no data from")) continue;
if ((p = strstr(line, "PAT (xxxx:xxxx:")) != NULL) { table_id = TABLE_PAT; parse_intro(table_id, p, &transport_stream_id, 0); pid = PID_PAT; continue; }
if ((p = strstr(line, "NIT(act): (xxxx:")) != NULL) { table_id = TABLE_NIT_ACT; parse_intro(table_id, p, &network_id, 0); pid = PID_NIT_ST; continue; }
if ((p = strstr(line, "NIT(oth): (xxxx:")) != NULL) { table_id = TABLE_NIT_OTH; parse_intro(table_id, p, &network_id, 0); pid = PID_NIT_ST; continue; }
if ((p = strstr(line, "SDT(act")) != NULL) { table_id = TABLE_SDT_ACT; parse_intro(table_id, p, &transport_stream_id,0); pid = PID_SDT_BAT_ST; continue; }
if ((p = strstr(line, "SDT(oth")) != NULL) { table_id = TABLE_SDT_OTH; parse_intro(table_id, p, &transport_stream_id,0); pid = PID_SDT_BAT_ST; continue; }
if ((p = strstr(line, "PMT ")) != NULL) { table_id = TABLE_PMT; parse_intro(table_id, p, &pmt_pid, &service_id); pid = pmt_pid; continue; }
if ((em_device.w_scan_flags & EM_OLD_SI_HEADER) && !strncmp(line, "parse_section", 13)) {
unsigned args[9];
int nargs, tmp;
// parse_section:1376: pid 0x10 tid 0x40 table_id_ext 0x0056, 2/3 (version 16)
// parse_section:1376: pid 17 (0x11), tid 66 (0x42), table_id_ext 30 (0x001e), section_number 0, last_section_number 0, version 3\n"
nargs = sscanf(line, "parse_section:%d: pid %x tid %x table_id_ext %x, %i/%i (version %i)",//",
&tmp,&args[0],&args[1],&args[2],&args[3],&args[4],&args[5]);//);
if (nargs != 7)
nargs = sscanf(line, "parse_section:%d: pid %d (%x), tid %d (%x), table_id_ext %d (%x), section_number %i, last_section_number %i, version %i\n",
&tmp,&args[0],&args[1],&args[2],&args[3],&args[4],&args[5],&args[6],&args[7],&args[8]);
//if (nargs) info("found %d args---------\n", nargs);
if ((nargs == 7) || (nargs == 10)) {
EM_INFO("found table. nargs = %d\n", nargs);
table_id = (nargs == 7) ? (int)args[1]: (nargs == 10)? (int)args[2]: table_id;
switch(table_id) {
case TABLE_PAT :
transport_stream_id = (nargs == 7) ? (int)args[2]: (nargs == 10)? (int)args[4]: transport_stream_id;
break;
case TABLE_NIT_ACT:
case TABLE_NIT_OTH:
network_id = (nargs == 7) ? (int)args[2]: (nargs == 10)? (int)args[4]: network_id;
break;
case TABLE_SDT_ACT:
case TABLE_SDT_OTH:
transport_stream_id = (nargs == 7) ? (int)args[2]: (nargs == 10)? (int)args[4]: transport_stream_id;
break;
case TABLE_PMT :
pmt_pid = ((nargs == 7) || (nargs == 10))? (int)args[0]: pmt_pid;
service_id = (nargs == 7) ? (int)args[2]: (nargs == 10)? (int)args[4]: service_id;
break;
default:
info("invalid table id %d\n", table_id);
}
if (fgets(line, 256, logfile) != NULL) { EM_INFO("next: %s\n", line); } line_no++; //"NIT (act"
if (fgets(line, 256, logfile) != NULL) { EM_INFO("next: %s\n", line); } line_no++; //" ===================== parse_"
if (fgets(line, 256, logfile) != NULL) { EM_INFO("next: %s\n", line); } line_no++; //" len = "
}
}
if (strstr(line, "========================================================================")) {
table_id = -1;
continue;
}
if (table_id < 0) continue; // we found something, which we cannot assign to any table.
if (strstr(line, " len = ")) {
sscanf(line, " len = %d", &len);
if (len > 0) {
sidata = (sidata_t *) calloc(1, sizeof(sidata_t));
sidata->t.frequency = em_device.frequency;
sidata->t.inversion = em_device.inversion;
switch(em_device.delsys) {
case SYS_DVBT:
case SYS_DVBT2:
sidata->t.type = SCAN_TERRESTRIAL;
sidata->t.bandwidth = em_device.bandwidth_hz;
sidata->t.coderate = em_device.fec;
sidata->t.coderate_LP = FEC_AUTO;
sidata->t.modulation = em_device.modulation;
sidata->t.transmission = em_device.transmission;
sidata->t.guard = em_device.guard;
sidata->t.hierarchy = em_device.hierarchy;
sidata->t.delsys = em_device.delsys;
break;
case SYS_DVBC_ANNEX_A:
case SYS_DVBC_ANNEX_C:
sidata->t.type = SCAN_CABLE;
sidata->t.delsys = em_device.delsys;
sidata->t.modulation = em_device.modulation;
sidata->t.symbolrate = em_device.symbolrate;
break;
case SYS_DVBS:
case SYS_DVBS2:
sidata->t.type = SCAN_SATELLITE;
sidata->t.rolloff = em_device.rolloff;
sidata->t.pilot = em_device.pilot;
sidata->t.delsys = em_device.delsys;
sidata->t.polarization = em_device.polarization;
sidata->t.coderate = em_device.fec;
sidata->t.symbolrate = em_device.symbolrate;
sidata->t.modulation = em_device.modulation;
break;
case SYS_ATSC:
sidata->t.type = SCAN_TERRCABLE_ATSC;
default:
fatal("unsupported del sys.\n");
}
sidata->pid = pid;
sidata->table_id = table_id;
sidata->original_network_id = original_network_id;
sidata->network_id = network_id;
sidata->transport_stream_id = transport_stream_id;
sidata->service_id = service_id;
switch (table_id) {
case TABLE_PAT: sidata->table_id_ext = transport_stream_id;
break;
case TABLE_PMT: sidata->table_id_ext = service_id;
sidata->pid = pmt_pid;
break;
case TABLE_NIT_ACT:
case TABLE_NIT_OTH: sidata->table_id_ext = network_id;
break;
case TABLE_SDT_ACT:
case TABLE_SDT_OTH: sidata->table_id_ext = transport_stream_id;
break;
default: info("%s: no table id.\n", __FUNCTION__);
}