forked from OpenViX/enigma2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fcc.patch
3005 lines (2947 loc) · 86.6 KB
/
fcc.patch
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
diff --git a/configure.ac b/configure.ac
index 7ea83f92d3..01b7c9eaab 100644
--- a/configure.ac
+++ b/configure.ac
@@ -626,6 +626,8 @@ lib/python/Plugins/SystemPlugins/DefaultServicesScanner/Makefile
lib/python/Plugins/SystemPlugins/DefaultServicesScanner/meta/Makefile
lib/python/Plugins/SystemPlugins/DiseqcTester/Makefile
lib/python/Plugins/SystemPlugins/DiseqcTester/meta/Makefile
+lib/python/Plugins/SystemPlugins/FastChannelChange/Makefile
+lib/python/Plugins/SystemPlugins/FastChannelChange/meta/Makefile
lib/python/Plugins/SystemPlugins/FastScan/Makefile
lib/python/Plugins/SystemPlugins/FrontprocessorUpgrade/Makefile
lib/python/Plugins/SystemPlugins/FrontprocessorUpgrade/meta/Makefile
diff --git a/lib/dvb/Makefile.inc b/lib/dvb/Makefile.inc
index 96633c0346..5fbdcb7b75 100644
--- a/lib/dvb/Makefile.inc
+++ b/lib/dvb/Makefile.inc
@@ -35,7 +35,9 @@ dvb_libenigma_dvb_a_SOURCES = \
dvb/streamserver.cpp \
dvb/pmtparse.cpp \
dvb/encoder.cpp \
- dvb/atsc.cpp
+ dvb/atsc.cpp \
+ dvb/fcc.cpp \
+ dvb/fccdecoder.cpp
dvbincludedir = $(pkgincludedir)/lib/dvb
dvbinclude_HEADERS = \
@@ -79,4 +81,6 @@ dvbinclude_HEADERS = \
dvb/streamserver.h \
dvb/pmtparse.h \
dvb/encoder.h \
- dvb/atsc.h
+ dvb/atsc.h \
+ dvb/fcc.h \
+ dvb/fccdecoder.h
diff --git a/lib/dvb/decoder.cpp b/lib/dvb/decoder.cpp
index f361a72abc..95f5609dd9 100644
--- a/lib/dvb/decoder.cpp
+++ b/lib/dvb/decoder.cpp
@@ -16,6 +16,8 @@
#include <sys/stat.h>
#include <errno.h>
+#include <lib/dvb/fccdecoder.h>
+
#ifndef VIDEO_SOURCE_HDMI
#define VIDEO_SOURCE_HDMI 2
#endif
@@ -263,8 +265,8 @@ DEFINE_REF(eDVBVideo);
int eDVBVideo::m_close_invalidates_attributes = -1;
-eDVBVideo::eDVBVideo(eDVBDemux *demux, int dev)
- : m_demux(demux), m_dev(dev),
+eDVBVideo::eDVBVideo(eDVBDemux *demux, int dev, bool fcc_enable)
+ : m_demux(demux), m_dev(dev), m_fcc_enable(fcc_enable),
m_width(-1), m_height(-1), m_framerate(-1), m_aspect(-1), m_progressive(-1), m_gamma(-1)
{
char filename[128] = {};
@@ -345,6 +347,9 @@ eDVBVideo::eDVBVideo(eDVBDemux *demux, int dev)
int eDVBVideo::startPid(int pid, int type)
{
+ if (m_fcc_enable)
+ return 0;
+
if (m_fd >= 0)
{
int streamtype = VIDEO_STREAMTYPE_MPEG2;
@@ -440,6 +445,9 @@ int eDVBVideo::startPid(int pid, int type)
void eDVBVideo::stop()
{
+ if (m_fcc_enable)
+ return;
+
if (m_fd_demux >= 0)
{
eDebugNoNewLineStart("[eDVBVideo%d] DEMUX_STOP ", m_dev);
@@ -958,7 +966,7 @@ int eTSMPEGDecoder::setState()
{
if ((m_vpid >= 0) && (m_vpid < 0x1FFF))
{
- m_video = new eDVBVideo(m_demux, m_decoder);
+ m_video = new eDVBVideo(m_demux, m_decoder, m_fcc_enable);
m_video->connectEvent(sigc::mem_fun(*this, &eTSMPEGDecoder::video_event), m_video_event_conn);
if (m_video->startPid(m_vpid, m_vtype))
res = -1;
@@ -1073,7 +1081,8 @@ RESULT eTSMPEGDecoder::setAC3Delay(int delay)
eTSMPEGDecoder::eTSMPEGDecoder(eDVBDemux *demux, int decoder)
: m_demux(demux),
m_vpid(-1), m_vtype(-1), m_apid(-1), m_atype(-1), m_pcrpid(-1), m_textpid(-1),
- m_changed(0), m_decoder(decoder), m_video_clip_fd(-1), m_showSinglePicTimer(eTimer::create(eApp))
+ m_changed(0), m_decoder(decoder), m_video_clip_fd(-1), m_showSinglePicTimer(eTimer::create(eApp)),
+ m_fcc_fd(-1), m_fcc_enable(false), m_fcc_state(fcc_state_stop), m_fcc_feid(-1), m_fcc_vpid(-1), m_fcc_vtype(-1), m_fcc_pcrpid(-1)
{
if (m_demux)
{
@@ -1099,6 +1108,8 @@ eTSMPEGDecoder::~eTSMPEGDecoder()
m_vpid = m_apid = m_pcrpid = m_textpid = pidNone;
m_changed = -1;
setState();
+ fccStop();
+ fccFreeFD();
if (m_demux && m_decoder == 0) // Tuxtxt caching actions only on primary decoder
{
@@ -1456,3 +1467,240 @@ int eTSMPEGDecoder::getVideoGamma()
return m_video->getGamma();
return -1;
}
+
+#define FCC_SET_VPID 100
+#define FCC_SET_APID 101
+#define FCC_SET_PCRPID 102
+#define FCC_SET_VCODEC 103
+#define FCC_SET_ACODEC 104
+#define FCC_SET_FRONTEND_ID 105
+#define FCC_START 106
+#define FCC_STOP 107
+#define FCC_DECODER_START 108
+#define FCC_DECODER_STOP 109
+
+RESULT eTSMPEGDecoder::prepareFCC(int fe_id, int vpid, int vtype, int pcrpid)
+{
+ //eDebug("[eTSMPEGDecoder] prepareFCC vp : %d, vt : %d, pp : %d, fe : %d", vpid, vtype, pcrpid, fe_id);
+
+ if ((fccGetFD() == -1) || (fccSetPids(fe_id, vpid, vtype, pcrpid) < 0) || (fccStart() < 0))
+ {
+ fccFreeFD();
+ return -1;
+ }
+
+ m_fcc_enable = true;
+
+ return 0;
+}
+
+RESULT eTSMPEGDecoder::fccDecoderStart()
+{
+ if (m_fcc_fd == -1)
+ return -1;
+
+ if (m_fcc_state != fcc_state_ready)
+ {
+ eDebug("[eTSMPEGDecoder] FCC decoder is already in decoding state.");
+ return 0;
+ }
+
+ if (ioctl(m_fcc_fd, FCC_DECODER_START) < 0)
+ {
+ eDebug("[eTSMPEGDecoder] ioctl FCC_DECODER_START failed! (%m)");
+ return -1;
+ }
+
+ m_fcc_state = fcc_state_decoding;
+
+ eDebug("[eTSMPEGDecoder] FCC_DECODER_START OK!");
+ return 0;
+}
+
+RESULT eTSMPEGDecoder::fccDecoderStop()
+{
+ if (m_fcc_fd == -1)
+ return -1;
+
+ if (m_fcc_state != fcc_state_decoding)
+ {
+ eDebug("[eTSMPEGDecoder] FCC decoder is not in decoding state.");
+ }
+ else if (ioctl(m_fcc_fd, FCC_DECODER_STOP) < 0)
+ {
+ eDebug("[eTSMPEGDecoder] ioctl FCC_DECODER_STOP failed! (%m)");
+ return -1;
+ }
+
+ m_fcc_state = fcc_state_ready;
+
+ /* stop pcr, video, audio, text */
+ finishShowSinglePic();
+
+ m_vpid = m_apid = m_pcrpid = m_textpid = pidNone;
+ m_changed = -1;
+ setState();
+
+ eDebug("[eTSMPEGDecoder] FCC_DECODER_STOP OK!");
+ return 0;
+}
+
+RESULT eTSMPEGDecoder::fccUpdatePids(int fe_id, int vpid, int vtype, int pcrpid)
+{
+ //eDebug("[eTSMPEGDecoder] vp : %d, vt : %d, pp : %d, fe : %d", vpid, vtype, pcrpid, fe_id);
+
+ if ((fe_id != m_fcc_feid) || (vpid != m_fcc_vpid) || (vtype != m_fcc_vtype) || (pcrpid != m_fcc_pcrpid))
+ {
+ fccStop();
+ if (prepareFCC(fe_id, vpid, vtype, pcrpid))
+ {
+ eDebug("[eTSMPEGDecoder] prepare FCC failed!");
+ return -1;
+ }
+ }
+ return 0;
+}
+
+RESULT eTSMPEGDecoder::fccStart()
+{
+ if (m_fcc_fd == -1)
+ return -1;
+
+ if (m_fcc_state != fcc_state_stop)
+ {
+ eDebug("[eTSMPEGDecoder] FCC is already started!");
+ return 0;
+ }
+ else if (ioctl(m_fcc_fd, FCC_START) < 0)
+ {
+ eDebug("[eTSMPEGDecoder] ioctl FCC_START failed! (%m)");
+ return -1;
+ }
+
+ eDebug("[eTSMPEGDecoder] FCC_START OK!");
+
+ m_fcc_state = fcc_state_ready;
+ return 0;
+}
+
+RESULT eTSMPEGDecoder::fccStop()
+{
+ if (m_fcc_fd == -1)
+ return -1;
+
+ if (m_fcc_state == fcc_state_stop)
+ {
+ eDebug("[eTSMPEGDecoder] FCC is already stopped!");
+ return 0;
+ }
+
+ else if (m_fcc_state == fcc_state_decoding)
+ {
+ fccDecoderStop();
+ }
+
+ if (ioctl(m_fcc_fd, FCC_STOP) < 0)
+ {
+ eDebug("[eTSMPEGDecoder] ioctl FCC_STOP failed! (%m)");
+ return -1;
+ }
+
+ m_fcc_state = fcc_state_stop;
+
+ eDebug("[eTSMPEGDecoder] FCC_STOP OK!");
+ return 0;
+}
+
+RESULT eTSMPEGDecoder::fccSetPids(int fe_id, int vpid, int vtype, int pcrpid)
+{
+ int streamtype = VIDEO_STREAMTYPE_MPEG2;
+
+ if (m_fcc_fd == -1)
+ return -1;
+
+ if (ioctl(m_fcc_fd, FCC_SET_FRONTEND_ID, fe_id) < 0)
+ {
+ eDebug("[eTSMPEGDecoder] FCC_SET_FRONTEND_ID failed! (%m)");
+ return -1;
+ }
+
+ else if(ioctl(m_fcc_fd, FCC_SET_PCRPID, pcrpid) < 0)
+ {
+ eDebug("[eTSMPEGDecoder] FCC_SET_PCRPID failed! (%m)");
+ return -1;
+ }
+
+ else if (ioctl(m_fcc_fd, FCC_SET_VPID, vpid) < 0)
+ {
+ eDebug("[eTSMPEGDecoder] FCC_SET_VPID failed! (%m)");
+ return -1;
+ }
+
+ switch(vtype)
+ {
+ default:
+ case eDVBVideo::MPEG2:
+ break;
+ case eDVBVideo::MPEG4_H264:
+ streamtype = VIDEO_STREAMTYPE_MPEG4_H264;
+ break;
+ case eDVBVideo::MPEG1:
+ streamtype = VIDEO_STREAMTYPE_MPEG1;
+ break;
+ case eDVBVideo::MPEG4_Part2:
+ streamtype = VIDEO_STREAMTYPE_MPEG4_Part2;
+ break;
+ case eDVBVideo::VC1:
+ streamtype = VIDEO_STREAMTYPE_VC1;
+ break;
+ case eDVBVideo::VC1_SM:
+ streamtype = VIDEO_STREAMTYPE_VC1_SM;
+ break;
+ case eDVBVideo::H265_HEVC:
+ streamtype = VIDEO_STREAMTYPE_H265_HEVC;
+ break;
+ }
+
+ if(ioctl(m_fcc_fd, FCC_SET_VCODEC, streamtype) < 0)
+ {
+ eDebug("[eTSMPEGDecoder] FCC_SET_VCODEC failed! (%m)");
+ return -1;
+ }
+
+ m_fcc_feid = fe_id;
+ m_fcc_vpid = vpid;
+ m_fcc_vtype = vtype;
+ m_fcc_pcrpid = pcrpid;
+
+ //eDebug("[eTSMPEGDecoder] SET PIDS OK!");
+ return 0;
+}
+
+RESULT eTSMPEGDecoder::fccGetFD()
+{
+ if (m_fcc_fd == -1)
+ {
+ eFCCDecoder* fcc = eFCCDecoder::getInstance();
+ if (fcc != NULL)
+ {
+ m_fcc_fd = fcc->allocateFcc();
+ }
+ }
+
+ return m_fcc_fd;
+}
+
+RESULT eTSMPEGDecoder::fccFreeFD()
+{
+ if (m_fcc_fd != -1)
+ {
+ eFCCDecoder* fcc = eFCCDecoder::getInstance();
+ if (fcc != NULL)
+ {
+ fcc->freeFcc(m_fcc_fd);
+ m_fcc_fd = -1;
+ }
+ }
+
+ return 0;
+}
diff --git a/lib/dvb/decoder.h b/lib/dvb/decoder.h
index c99644fe9b..05cb4d4ea4 100644
--- a/lib/dvb/decoder.h
+++ b/lib/dvb/decoder.h
@@ -32,6 +32,7 @@ class eDVBVideo: public iObject, public sigc::trackable
private:
ePtr<eDVBDemux> m_demux;
int m_fd, m_fd_demux, m_dev;
+ bool m_fcc_enable;
static int m_close_invalidates_attributes;
int m_is_slow_motion, m_is_fast_forward, m_is_freezed;
ePtr<eSocketNotifier> m_sn;
@@ -41,7 +42,7 @@ private:
static int readApiSize(int fd, int &xres, int &yres, int &aspect);
public:
enum { UNKNOWN = -1, MPEG2, MPEG4_H264, VC1 = 3, MPEG4_Part2, VC1_SM, MPEG1, H265_HEVC, AVS = 16, AVS2 = 40 };
- eDVBVideo(eDVBDemux *demux, int dev);
+ eDVBVideo(eDVBDemux *demux, int dev, bool fcc_enable=false);
void stop();
int startPid(int pid, int type=MPEG2);
void flush();
@@ -121,6 +122,13 @@ private:
sigc::signal<void(struct videoEvent)> m_video_event;
int m_video_clip_fd;
ePtr<eTimer> m_showSinglePicTimer;
+ int m_fcc_fd;
+ bool m_fcc_enable;
+ int m_fcc_state;
+ int m_fcc_feid;
+ int m_fcc_vpid;
+ int m_fcc_vtype;
+ int m_fcc_pcrpid;
void finishShowSinglePic(); // called by timer
public:
enum { pidNone = -1 };
@@ -177,6 +185,23 @@ public:
int getVideoGamma();
static RESULT setHwPCMDelay(int delay);
static RESULT setHwAC3Delay(int delay);
+
+ enum
+ {
+ fcc_state_stop,
+ fcc_state_ready,
+ fcc_state_decoding
+ };
+
+ RESULT prepareFCC(int fe_id, int vpid, int vtype, int pcrpid);
+ RESULT fccStart();
+ RESULT fccStop();
+ RESULT fccDecoderStart();
+ RESULT fccDecoderStop();
+ RESULT fccUpdatePids(int fe_id, int vpid, int vtype, int pcrpid);
+ RESULT fccSetPids(int fe_id, int vpid, int vtype, int pcrpid);
+ RESULT fccGetFD();
+ RESULT fccFreeFD();
};
#endif
diff --git a/lib/dvb/dvb.cpp b/lib/dvb/dvb.cpp
index 135b560c47..254da63d77 100644
--- a/lib/dvb/dvb.cpp
+++ b/lib/dvb/dvb.cpp
@@ -11,6 +11,7 @@
#include <lib/dvb/dvb.h>
#include <lib/dvb/sec.h>
#include <lib/dvb/fbc.h>
+#include <lib/dvb/fcc.h>
#include <lib/dvb/specs.h>
#include "filepush.h"
@@ -20,6 +21,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
+#include <fstream>
#define MIN(a,b) (a < b ? a : b)
#define MAX(a,b) (a > b ? a : b)
@@ -111,6 +113,9 @@ eDVBResourceManager::eDVBResourceManager()
adapter->scanDevices();
addAdapter(adapter, true);
}
+
+ setUsbTuner();
+
eDebug("[eDVBResourceManager] found %zd adapter, %zd frontends(%zd sim) and %zd demux",
m_adapter.size(), m_frontend.size(), m_simulate_frontend.size(), m_demux.size());
m_fbcmng = new eFBCTunerManager(instance);
@@ -682,6 +687,59 @@ void eDVBResourceManager::addAdapter(iDVBAdapter *adapter, bool front)
}
+void eDVBResourceManager::setUsbTuner()
+{
+ std::ifstream in("/proc/bus/nim_sockets");
+ std::string line;
+
+ int res = -1;
+ int fe_idx = -1;
+ int usbtuner_idx[8] = {0};
+ int usbtuner_count = 0;
+
+ if (in.is_open())
+ {
+ while(!in.eof())
+ {
+ getline(in, line);
+ if ((res = sscanf(line.c_str(), "NIM Socket %d:", &fe_idx)) == 1)
+ continue;
+
+ if ((fe_idx != -1) && (line.find("\tName: ") == 0) && (line.find("VTUNER") != std::string::npos))
+ usbtuner_idx[usbtuner_count++] = fe_idx;
+ }
+ in.close();
+ }
+
+ if (usbtuner_count)
+ {
+ for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_frontend.begin()); it != m_frontend.end(); ++it)
+ {
+ int slotid = it->m_frontend->getSlotID();
+ for (int i=0; i < usbtuner_count ; i++)
+ {
+ if (slotid == usbtuner_idx[i])
+ {
+ it->m_frontend->setUSBTuner(true);
+ break;
+ }
+ }
+ }
+ for (eSmartPtrList<eDVBRegisteredFrontend>::iterator it(m_simulate_frontend.begin()); it != m_simulate_frontend.end(); ++it)
+ {
+ int slotid = it->m_frontend->getSlotID();
+ for (int i=0; i < usbtuner_count ; i++)
+ {
+ if (slotid == usbtuner_idx[i])
+ {
+ it->m_frontend->setUSBTuner(true);
+ break;
+ }
+ }
+ }
+ }
+}
+
PyObject *eDVBResourceManager::setFrontendSlotInformations(ePyObject list)
{
if (!PyList_Check(list))
@@ -1407,6 +1465,56 @@ int eDVBResourceManager::canAllocateChannel(const eDVBChannelID &channelid, cons
int *decremented_cached_channel_fe_usecount=NULL,
*decremented_fe_usecount=NULL;
+ /* check FCC channels */
+ std::vector<int*> fcc_decremented_fe_usecounts;
+ std::map<eDVBChannelID, int> fcc_chids;
+ int apply_to_ignore = 0;
+ if (!eFCCServiceManager::getFCCChannelID(fcc_chids))
+ {
+ for (std::map<eDVBChannelID, int>::iterator i(fcc_chids.begin()); i != fcc_chids.end(); ++i)
+ {
+ //eDebug("[eDVBResourceManager::canAllocateChannel] FCC NS : %08x, TSID : %04x, ONID : %04x", i->first.dvbnamespace.get(), i->first.transport_stream_id.get(), i->first.original_network_id.get());
+ if (ignore == i->first)
+ {
+ apply_to_ignore = i->second;
+ continue;
+ }
+ for (std::list<active_channel>::iterator ii(active_channels.begin()); ii != active_channels.end(); ++ii)
+ {
+ eSmartPtrList<eDVBRegisteredFrontend> &frontends = simulate ? m_simulate_frontend : m_frontend;
+ if (ii->m_channel_id == i->first)
+ {
+ eDVBChannel *channel = (eDVBChannel*) &(*ii->m_channel);
+
+ int check_usecount = channel == &(*m_cached_channel) ? 1 : 0;
+ check_usecount += i->second * 2; // one is used in eDVBServicePMTHandler and another is used in eDVBScan.
+ //eDebug("[eDVBResourceManager::canAllocateChannel] channel->getUseCount() : %d , check_usecount : %d (cached : %d)", channel->getUseCount(), check_usecount, channel == &(*m_cached_channel));
+ if (channel->getUseCount() == check_usecount)
+ {
+ ePtr<iDVBFrontend> fe;
+ if (!ii->m_channel->getFrontend(fe))
+ {
+ for (eSmartPtrList<eDVBRegisteredFrontend>::iterator iii(frontends.begin()); iii != frontends.end(); ++iii)
+ {
+ if ( &(*fe) == &(*iii->m_frontend) )
+ {
+ //eDebug("[eDVBResourceManager::canAllocateChannel] fcc : decrease fcc fe use_count! feid : %d (%d -> %d)", iii->m_frontend->getSlotID(), iii->m_inuse, iii->m_inuse-1);
+ --iii->m_inuse;
+ int *tmp_decremented_fe_usecount = &iii->m_inuse;
+ fcc_decremented_fe_usecounts.push_back(tmp_decremented_fe_usecount);
+ if (channel == &(*m_cached_channel))
+ decremented_cached_channel_fe_usecount = tmp_decremented_fe_usecount;
+ break;
+ }
+ }
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
+
for (std::list<active_channel>::iterator i(active_channels.begin()); i != active_channels.end(); ++i)
{
eSmartPtrList<eDVBRegisteredFrontend> &frontends = simulate ? m_simulate_frontend : m_frontend;
@@ -1418,7 +1526,10 @@ int eDVBResourceManager::canAllocateChannel(const eDVBChannelID &channelid, cons
// another on eUsePtr<iDVBChannel> is used in the eDVBScan instance used in eDVBServicePMTHandler (for SDT scan)
// so we must check here if usecount is 3 (when the channel is equal to the cached channel)
// or 2 when the cached channel is not equal to the compared channel
- if (channel == &(*m_cached_channel) ? channel->getUseCount() == 3 : channel->getUseCount() == 2) // channel only used once..
+ int check_usecount = channel == &(*m_cached_channel) ? 1 : 0;
+ check_usecount += (apply_to_ignore+1) * 2; // one is used in eDVBServicePMTHandler and another is used in eDVBScan.
+ //eDebug("[eDVBResourceManager] canAllocateChannel channel->getUseCount() : %d , check_usecount : %d (cached : %d)", channel->getUseCount(), check_usecount, channel == &(*m_cached_channel));
+ if (channel->getUseCount() == check_usecount) // channel only used once..(except fcc)
{
ePtr<iDVBFrontend> fe;
if (!i->m_channel->getFrontend(fe))
@@ -1427,6 +1538,7 @@ int eDVBResourceManager::canAllocateChannel(const eDVBChannelID &channelid, cons
{
if ( &(*fe) == &(*ii->m_frontend) )
{
+ //eDebug("[eDVBResourceManager] canAllocateChannel ignore : decrease fcc fe use_count! feid : %d (%d -> %d)", ii->m_frontend->getSlotID(), ii->m_inuse, ii->m_inuse-1);
--ii->m_inuse;
decremented_fe_usecount = &ii->m_inuse;
if (channel == &(*m_cached_channel))
@@ -1489,6 +1601,14 @@ error:
++(*decremented_fe_usecount);
if (decremented_cached_channel_fe_usecount)
++(*decremented_cached_channel_fe_usecount);
+ if (fcc_decremented_fe_usecounts.size())
+ {
+ for (std::vector<int*>::iterator i(fcc_decremented_fe_usecounts.begin()); i != fcc_decremented_fe_usecounts.end(); ++i)
+ {
+ //eDebug("[eDVBResourceManager] canAllocateChannel fcc : increase fcc fe use_count!");
+ ++(**i);
+ }
+ }
return ret;
}
diff --git a/lib/dvb/dvb.h b/lib/dvb/dvb.h
index f2f2e82404..238c37d302 100644
--- a/lib/dvb/dvb.h
+++ b/lib/dvb/dvb.h
@@ -166,6 +166,7 @@ class eDVBResourceManager: public iObject, public sigc::trackable
eSmartPtrList<eDVBRegisteredDemux> m_demux;
eSmartPtrList<eDVBRegisteredFrontend> m_frontend, m_simulate_frontend;
void addAdapter(iDVBAdapter *adapter, bool front = false);
+ void setUsbTuner();
struct active_channel
{
diff --git a/lib/dvb/fcc.cpp b/lib/dvb/fcc.cpp
new file mode 100644
index 0000000000..4c52613581
--- /dev/null
+++ b/lib/dvb/fcc.cpp
@@ -0,0 +1,378 @@
+#include <lib/dvb/fcc.h>
+#include <lib/nav/core.h>
+#include <lib/base/nconfig.h>
+#include <lib/base/eerror.h>
+#include <lib/python/python.h>
+
+//#define FCC_DEBUG
+
+void FCCServiceChannels::addFCCService(const eServiceReference &service)
+{
+ eDVBChannelID fcc_chid;
+
+ ((const eServiceReferenceDVB&)service).getChannelID(fcc_chid);
+
+ if (m_fcc_chids.find(fcc_chid) != m_fcc_chids.end())
+ m_fcc_chids[fcc_chid] += 1;
+ else
+ m_fcc_chids[fcc_chid] = 1;
+}
+
+void FCCServiceChannels::removeFCCService(const eServiceReference &service)
+{
+ eDVBChannelID fcc_chid;
+ ((const eServiceReferenceDVB&)service).getChannelID(fcc_chid);
+
+ if (m_fcc_chids.find(fcc_chid) != m_fcc_chids.end())
+ {
+ m_fcc_chids[fcc_chid] -= 1;
+
+ if (m_fcc_chids[fcc_chid] == 0)
+ m_fcc_chids.erase(fcc_chid);
+ }
+}
+
+int FCCServiceChannels::getFCCChannelID(std::map<eDVBChannelID, int> &fcc_chids)
+{
+ if (!m_fcc_chids.size()) return -1;
+
+ fcc_chids = m_fcc_chids;
+ return 0;
+}
+
+eFCCServiceManager *eFCCServiceManager::m_instance = (eFCCServiceManager*)0;
+
+eFCCServiceManager* eFCCServiceManager::getInstance()
+{
+ return m_instance;
+}
+
+eFCCServiceManager::eFCCServiceManager(eNavigation *navptr)
+ :m_core(navptr), m_fcc_enable(false)
+{
+ if (!m_instance)
+ {
+ m_instance = this;
+ }
+}
+
+eFCCServiceManager::~eFCCServiceManager()
+{
+ if (m_instance == this)
+ {
+ m_instance = 0;
+ }
+}
+
+RESULT eFCCServiceManager::playFCCService(const eServiceReference &ref, ePtr<iPlayableService> &service)
+{
+ std::map< ePtr<iPlayableService>, FCCServiceElem >::iterator it = m_FCCServices.begin();
+ for (;it != m_FCCServices.end();++it)
+ {
+ ASSERT (ref != it->second.m_service_reference);
+ }
+
+ ASSERT(m_core->m_servicehandler);
+ RESULT res = m_core->m_servicehandler->play(ref, service);
+ if (res)
+ service = 0;
+ else
+ {
+ ePtr<eConnection> conn;
+ service->connectEvent(sigc::mem_fun(*this, &eFCCServiceManager::FCCEvent), conn);
+
+ FCCServiceElem elem = {ref, conn, fcc_state_preparing, false};
+ m_FCCServices[service] = elem;
+
+ res = service->start();
+ }
+
+ printFCCServices();
+
+ return res;
+}
+
+void eFCCServiceManager::FCCEvent(iPlayableService* service, int event)
+{
+ std::map<ePtr<iPlayableService>, FCCServiceElem >::iterator it = m_FCCServices.find(service);
+ if (it == m_FCCServices.end())
+ {
+ eDebug("[eFCCServiceManager] Event for non registered FCC service");
+ return;
+ }
+
+ switch (event)
+ {
+ case iPlayableService::evStart:
+ {
+ m_fccServiceChannels.addFCCService(it->second.m_service_reference);
+ break;
+ }
+ case iPlayableService::evStopped:
+ {
+ m_fccServiceChannels.removeFCCService(it->second.m_service_reference);
+ break;
+ }
+ case iPlayableService::evTuneFailed:
+ case iPlayableService::evFccFailed:
+ {
+ eDebug("[eFCCServiceManager] FCCEvent [%s] set service to state failed.", it->second.m_service_reference.toString().c_str());
+ it->second.m_state = fcc_state_failed;
+ break;
+ }
+ }
+ m_fcc_event(event);
+}
+
+RESULT eFCCServiceManager::cleanupFCCService()
+{
+ if (m_FCCServices.size())
+ {
+ std::map<ePtr<iPlayableService>, FCCServiceElem >::iterator it = m_FCCServices.begin();
+ for (;it != m_FCCServices.end();++it)
+ {
+ eDebug("[eFCCServiceManager] Stop FCC service sref : %s", it->second.m_service_reference.toString().c_str());
+ it->first->stop();
+ }
+
+ m_FCCServices.clear();
+ }
+ return 0;
+}
+
+RESULT eFCCServiceManager::stopFCCService(const eServiceReference &sref)
+{
+ if (m_FCCServices.size())
+ {
+ std::map<ePtr<iPlayableService>, FCCServiceElem >::iterator it = m_FCCServices.begin();
+ for (; it != m_FCCServices.end();)
+ {
+ if (it->second.m_service_reference == sref)
+ {
+ eDebug("[eFCCServiceManager] Stop FCC service sref : %s", it->second.m_service_reference.toString().c_str());
+ it->first->stop();
+ m_FCCServices.erase(it++);
+ }
+ else
+ {
+ ++it;
+ }
+ }
+ printFCCServices();
+ }
+ return 0;
+}
+
+RESULT eFCCServiceManager::stopFCCService()
+{
+ if (m_FCCServices.size())
+ {
+ std::map<ePtr<iPlayableService>, FCCServiceElem >::iterator it = m_FCCServices.begin();
+ for (; it != m_FCCServices.end();)
+ {
+ if (it->second.m_state == fcc_state_failed)
+ {
+ eDebug("[eFCCServiceManager] Stop FCC service sref : %s", it->second.m_service_reference.toString().c_str());
+ it->first->stop();
+ m_FCCServices.erase(it++);
+ }
+ else
+ {
+ ++it;
+ }
+ }
+
+ printFCCServices();
+ }
+ return 0;
+}
+
+RESULT eFCCServiceManager::tryFCCService(const eServiceReference &sref, ePtr<iPlayableService> &service)
+{
+ if (!isEnable())
+ return -1;
+
+ ePtr<iPlayableService> new_service = 0;
+
+ printFCCServices();
+
+ int get_fcc_decoding = 0;
+
+ /* stop previous decoding service */
+ std::map< ePtr<iPlayableService>, FCCServiceElem >::iterator it;
+ for (it = m_FCCServices.begin();it != m_FCCServices.end();++it)
+ {
+ if (it->second.m_state == fcc_state_decoding)
+ {
+ ASSERT(get_fcc_decoding == 0);
+ get_fcc_decoding = 1;
+
+ /* send end event */
+ m_core->m_event(iPlayableService::evEnd);
+
+ /* kill service and event */
+ m_core->m_service_event_conn = 0;
+ m_core->m_runningService = 0;
+
+ if (it->second.m_useNormalDecode)
+ {
+ /* stop service */
+ it->first->stop();
+ m_FCCServices.erase(it++);
+ }
+ else
+ {
+ /* connect to fcc event */
+ ePtr<eConnection> conn;
+ it->first->connectEvent(sigc::mem_fun(*this, &eFCCServiceManager::FCCEvent), conn);
+ it->second.m_service_event_conn = conn;
+ it->second.m_state = fcc_state_preparing;
+
+ /* switch to FCC prepare state */
+ it->first->start();
+
+ /* update FCCServiceChannels */
+ m_fccServiceChannels.addFCCService(it->second.m_service_reference);
+ }
+ break;
+ }
+ }
+
+ /* search new service */
+ for (it = m_FCCServices.begin();it != m_FCCServices.end();++it)
+ {
+ if (it->second.m_service_reference == sref)
+ {
+ eDebug("[eFCCServiceManager] Use FCC service sref : %s", it->second.m_service_reference.toString().c_str());
+ it->second.m_service_event_conn = 0; /* disconnect FCC event */
+ it->second.m_state = fcc_state_decoding;
+ new_service = it->first;
+ m_fccServiceChannels.removeFCCService(it->second.m_service_reference);
+ break;
+ }
+ }
+
+ if (new_service)
+ {
+ service = new_service;
+ }
+
+ else /* If new service is not found in FCC service list, cleanup all FCC prepared services and get new FCC service. */
+ {
+ cleanupFCCService();
+ m_core->stopService();
+ if (eFCCServiceManager::checkAvailable(sref))
+ {
+ ASSERT(m_core->m_servicehandler);
+ m_core->m_servicehandler->play(sref, service);
+
+ if (service)
+ {
+ FCCServiceElem elem = {sref, 0, fcc_state_decoding, false};
+ m_FCCServices[service] = elem;
+ service->start(); // do FCC preparing
+ }
+ }
+ else
+ {
+ return -1;
+ }
+ }
+
+ printFCCServices();
+
+ return 0;
+}
+
+PyObject *eFCCServiceManager::getFCCServiceList()
+{
+ ePyObject dest = PyDict_New();
+ if (dest)
+ {
+ std::map< ePtr<iPlayableService>, FCCServiceElem >::iterator it = m_FCCServices.begin();
+ for (;it != m_FCCServices.end();++it)
+ {
+ ePyObject tplist = PyList_New(0);
+ PyList_Append(tplist, PyLong_FromLong((long)it->second.m_state));
+ PyList_Append(tplist, PyLong_FromLong((long)isLocked(it->first)));
+ PyDict_SetItemString(dest, it->second.m_service_reference.toString().c_str(), tplist);
+ Py_DECREF(tplist);
+ }
+ }
+
+ else
+ Py_RETURN_NONE;
+ return dest;
+}
+
+int eFCCServiceManager::isLocked(ePtr<iPlayableService> service)
+{
+ ePtr<iFrontendInformation> ptr;
+ service->frontendInfo(ptr);
+ return ptr->getFrontendInfo(iFrontendInformation_ENUMS::lockState);
+}
+
+void eFCCServiceManager::printFCCServices()
+{
+#ifdef FCC_DEBUG
+ eDebug("[eFCCServiceManager] printFCCServices [*] total size : %d", m_FCCServices.size());
+
+ std::map< ePtr<iPlayableService>, FCCServiceElem >::iterator it = m_FCCServices.begin();
+ for (;it != m_FCCServices.end();++it)
+ {
+ int isLocked = isLocked(it->first);
+ eDebug("[eFCCServiceManager] printFCCServices [*] sref : %s, state : %d, tune : %d, useNormalDecode : %d", it->second.m_service_reference.toString().c_str(), it->second.m_state, isLocked, it->second.m_useNormalDecode);
+ }
+#else
+ ;
+#endif
+}
+
+int eFCCServiceManager::getFCCChannelID(std::map<eDVBChannelID, int> &fcc_chids)
+{
+ eFCCServiceManager *fcc_mng = eFCCServiceManager::getInstance();
+ if (!fcc_mng) return -1;
+ return fcc_mng->m_fccServiceChannels.getFCCChannelID(fcc_chids);
+}
+
+bool eFCCServiceManager::checkAvailable(const eServiceReference &ref)
+{
+ int serviceType = ref.getData(0);
+ eFCCServiceManager *fcc_mng = eFCCServiceManager::getInstance();
+
+ if ((ref.type == 1) && ref.path.empty() && (serviceType != 2) && (serviceType != 10) && fcc_mng) // no PVR, streaming, radio channel..
+ return fcc_mng->isEnable();
+ return false;
+}
+
+bool eFCCServiceManager::isStateDecoding(iPlayableService* service)
+{
+ std::map<ePtr<iPlayableService>, FCCServiceElem >::iterator it = m_FCCServices.find(service);
+ if (it != m_FCCServices.end())
+ {
+ return (it->second.m_state == fcc_state_decoding);
+ }
+ else
+ {
+ eDebug("[eFCCServiceManager] Non registered FCC service");
+ }
+
+ return false;
+}
+
+void eFCCServiceManager::setNormalDecoding(iPlayableService* service)
+{
+ std::map<ePtr<iPlayableService>, FCCServiceElem >::iterator it = m_FCCServices.find(service);
+ if (it != m_FCCServices.end())
+ {
+ eDebug("[eFCCServiceManager] setNormalDecoding [%s] set to use normal decoding.", it->second.m_service_reference.toString().c_str());
+ it->second.m_useNormalDecode = true;
+ }
+ else
+ {
+ eDebug("[eFCCServiceManager] Non registered FCC service");
+ }
+}
+
+DEFINE_REF(eFCCServiceManager);
+
diff --git a/lib/dvb/fcc.h b/lib/dvb/fcc.h
new file mode 100644
index 0000000000..136526a80f
--- /dev/null
+++ b/lib/dvb/fcc.h
@@ -0,0 +1,70 @@
+#ifndef __dvb_fcc_h
+#define __dvb_fcc_h
+
+#include <lib/dvb/idvb.h>
+#include <lib/base/object.h>
+#include <lib/service/iservice.h>
+#include <connection.h>
+