vdr 2.6.7
device.c
Go to the documentation of this file.
1/*
2 * device.c: The basic device interface
3 *
4 * See the main source file 'vdr.c' for copyright information and
5 * how to reach the author.
6 *
7 * $Id: device.c 5.13 2024/03/29 21:46:50 kls Exp $
8 */
9
10#include "device.h"
11#include <errno.h>
12#include <math.h>
13#include <sys/ioctl.h>
14#include <sys/mman.h>
15#include "audio.h"
16#include "channels.h"
17#include "i18n.h"
18#include "player.h"
19#include "receiver.h"
20#include "status.h"
21#include "transfer.h"
22
23// --- cLiveSubtitle ---------------------------------------------------------
24
25class cLiveSubtitle : public cReceiver {
26protected:
27 virtual void Receive(const uchar *Data, int Length);
28public:
29 cLiveSubtitle(int SPid);
30 virtual ~cLiveSubtitle();
31 };
32
34{
35 AddPid(SPid);
36}
37
42
43void cLiveSubtitle::Receive(const uchar *Data, int Length)
44{
46 cDevice::PrimaryDevice()->PlayTs(Data, Length);
47}
48
49// --- cDeviceHook -----------------------------------------------------------
50
55
56bool cDeviceHook::DeviceProvidesTransponder(const cDevice *Device, const cChannel *Channel) const
57{
58 return true;
59}
60
61bool cDeviceHook::DeviceProvidesEIT(const cDevice *Device) const
62{
63 return true;
64}
65
66// --- cDevice ---------------------------------------------------------------
67
68// The minimum number of unknown PS1 packets to consider this a "pre 1.3.19 private stream":
69#define MIN_PRE_1_3_19_PRIVATESTREAM 10
70
72int cDevice::useDevice = 0;
78
80:patPmtParser(true)
81{
83 dsyslog("new device number %d (card index %d)", numDevices + 1, CardIndex() + 1);
84
85 SetDescription("device %d receiver", numDevices + 1);
86
87 mute = false;
89
90 sectionHandler = NULL;
91 eitFilter = NULL;
92 patFilter = NULL;
93 sdtFilter = NULL;
94 nitFilter = NULL;
95
96 camSlot = NULL;
97
98 occupiedFrom = 0;
101
102 player = NULL;
103 isPlayingVideo = false;
104 keepTracks = false; // used in ClrAvailableTracks()!
109 liveSubtitle = NULL;
112
113 for (int i = 0; i < MAXRECEIVERS; i++)
114 receiver[i] = NULL;
115
117 device[numDevices++] = this;
118 else
119 esyslog("ERROR: too many devices!");
120}
121
123{
124 Detach(player);
126 delete liveSubtitle;
128 if (this == primaryDevice)
129 primaryDevice = NULL;
130 Cancel(3);
131}
132
134{
135 for (time_t t0 = time(NULL); time(NULL) - t0 < Timeout; ) {
136 bool ready = true;
137 for (int i = 0; i < numDevices; i++) {
138 if (device[i] && !device[i]->Ready()) {
139 ready = false;
141 }
142 }
143 if (ready)
144 return true;
145 }
146 return false;
147}
148
150{
151 if (n < MAXDEVICES)
152 useDevice |= (1 << n);
153}
154
156{
157 if (n > 0) {
158 nextCardIndex += n;
160 esyslog("ERROR: nextCardIndex too big (%d)", nextCardIndex);
161 }
162 else if (n < 0)
163 esyslog("ERROR: invalid value in nextCardIndex(%d)", n);
164 return nextCardIndex;
165}
166
168{
169 for (int i = 0; i < numDevices; i++) {
170 if (device[i] == this)
171 return i;
172 }
173 return -1;
174}
175
177{
178 return "";
179}
180
182{
183 return "";
184}
185
187{
188 if (!On) {
191 }
192}
193
195{
196 n--;
197 if (0 <= n && n < numDevices && device[n]) {
198 isyslog("setting primary device to %d", n + 1);
199 if (primaryDevice)
205 Setup.PrimaryDVB = n + 1;
206 return true;
207 }
208 esyslog("ERROR: invalid primary device number: %d", n + 1);
209 return false;
210}
211
212bool cDevice::HasDecoder(void) const
213{
214 return false;
215}
216
218{
219 return NULL;
220}
221
223{
225 if (!d)
226 d = PrimaryDevice();
227 return d;
228}
229
231{
232 return (0 <= Index && Index < numDevices) ? device[Index] : NULL;
233}
234
235static int GetClippedNumProvidedSystems(int AvailableBits, cDevice *Device)
236{
237 int MaxNumProvidedSystems = (1 << AvailableBits) - 1;
238 int NumProvidedSystems = Device->NumProvidedSystems();
239 if (NumProvidedSystems > MaxNumProvidedSystems) {
240 esyslog("ERROR: device %d supports %d modulation systems but cDevice::GetDevice() currently only supports %d delivery systems which should be fixed", Device->DeviceNumber() + 1, NumProvidedSystems, MaxNumProvidedSystems);
241 NumProvidedSystems = MaxNumProvidedSystems;
242 }
243 else if (NumProvidedSystems <= 0) {
244 esyslog("ERROR: device %d reported an invalid number (%d) of supported delivery systems - assuming 1", Device->DeviceNumber() + 1, NumProvidedSystems);
245 NumProvidedSystems = 1;
246 }
247 return NumProvidedSystems;
248}
249
250cDevice *cDevice::GetDevice(const cChannel *Channel, int Priority, bool LiveView, bool Query)
251{
252 // Collect the current priorities of all CAM slots that can decrypt the channel:
253 int NumCamSlots = CamSlots.Count();
254 int SlotPriority[NumCamSlots + 1]; // +1 to avoid a zero sized array in case there are no CAM slots
255 int NumUsableSlots = 0;
256 bool InternalCamNeeded = false;
257 if (Channel->Ca() >= CA_ENCRYPTED_MIN) {
259 SlotPriority[CamSlot->Index()] = MAXPRIORITY + 1; // assumes it can't be used
260 if (CamSlot->ModuleStatus() == msReady) {
261 if (CamSlot->ProvidesCa(Channel->Caids())) {
263 SlotPriority[CamSlot->Index()] = CamSlot->MtdActive() ? IDLEPRIORITY : CamSlot->Priority(); // we don't need to take the priority into account here for MTD CAM slots, because they can be used with several devices in parallel
264 NumUsableSlots++;
265 }
266 }
267 }
268 }
269 if (!NumUsableSlots)
270 InternalCamNeeded = true; // no CAM is able to decrypt this channel
271 }
272
273 bool NeedsDetachReceivers = false;
274 cDevice *d = NULL;
275 cCamSlot *s = NULL;
276
277 uint32_t Impact = 0xFFFFFFFF; // we're looking for a device with the least impact
278 for (int j = 0; j < NumCamSlots || !NumUsableSlots; j++) {
279 if (NumUsableSlots && SlotPriority[j] > MAXPRIORITY)
280 continue; // there is no CAM available in this slot
281 for (int i = 0; i < numDevices; i++) {
282 if (Channel->Ca() && Channel->Ca() <= CA_DVB_MAX && Channel->Ca() != device[i]->DeviceNumber() + 1)
283 continue; // a specific card was requested, but not this one
285 if (InternalCamNeeded && !HasInternalCam)
286 continue; // no CAM is able to decrypt this channel and the device uses vdr handled CAMs
287 if (NumUsableSlots && !HasInternalCam && !CamSlots.Get(j)->Assign(device[i], true))
288 continue; // CAM slot can't be used with this device
289 bool ndr = false;
290 bool TunedToTransponder = device[i]->IsTunedToTransponder(Channel);
291 if (TunedToTransponder || device[i]->ProvidesChannel(Channel, Priority, &ndr)) { // this device is basically able to do the job
292 bool OccupiedOtherTransponder = !TunedToTransponder && device[i]->Occupied();
293 if (OccupiedOtherTransponder)
294 ndr = true;
295 if (NumUsableSlots && !HasInternalCam) {
296 if (cCamSlot *csi = device[i]->CamSlot()) {
297 cCamSlot *csj = CamSlots.Get(j);
298 if ((csj->MtdActive() ? csi->MasterSlot() : csi) != csj)
299 ndr = true; // using a different CAM slot requires detaching receivers
300 }
301 }
302 // Put together an integer number that reflects the "impact" using
303 // this device would have on the overall system. Each condition is represented
304 // by one bit in the number (or several bits, if the condition is actually
305 // a numeric value). The sequence in which the conditions are listed corresponds
306 // to their individual severity, where the one listed first will make the most
307 // difference, because it results in the most significant bit of the result.
308 uint32_t imp = 0;
309 imp <<= 1; imp |= (LiveView && NumUsableSlots && !HasInternalCam) ? !ChannelCamRelations.CamDecrypt(Channel->GetChannelID(), CamSlots.Get(j)->MasterSlotNumber()) || ndr : 0; // prefer CAMs that are known to decrypt this channel for live viewing, if we don't need to detach existing receivers
310 imp <<= 1; imp |= LiveView ? !device[i]->IsPrimaryDevice() || ndr : 0; // prefer the primary device for live viewing if we don't need to detach existing receivers
311 imp <<= 1; imp |= !device[i]->Receiving() && (device[i] != cTransferControl::ReceiverDevice() || device[i]->IsPrimaryDevice()) || ndr; // use receiving devices if we don't need to detach existing receivers, but avoid primary device in local transfer mode
312 imp <<= 1; imp |= device[i]->Receiving() || OccupiedOtherTransponder; // avoid devices that are receiving
313 imp <<= 5; imp |= GetClippedNumProvidedSystems(5, device[i]) - 1; // avoid cards which support multiple delivery systems
314 imp <<= 8; imp |= device[i]->Priority() - IDLEPRIORITY; // use the device with the lowest priority (- IDLEPRIORITY to assure that values -100..99 can be used)
315 imp <<= 1; imp |= device[i] == cTransferControl::ReceiverDevice(); // avoid the Transfer Mode receiver device
316 imp <<= 8; imp |= ((NumUsableSlots && !HasInternalCam) ? SlotPriority[j] : IDLEPRIORITY) - IDLEPRIORITY;// use the CAM slot with the lowest priority (- IDLEPRIORITY to assure that values -100..99 can be used)
317 imp <<= 1; imp |= ndr; // avoid devices if we need to detach existing receivers
318 imp <<= 1; imp |= (NumUsableSlots || InternalCamNeeded) ? 0 : device[i]->HasCi(); // avoid cards with Common Interface for FTA channels
319 imp <<= 1; imp |= device[i]->AvoidRecording(); // avoid SD full featured cards
320 imp <<= 1; imp |= (NumUsableSlots && !HasInternalCam) ? !ChannelCamRelations.CamDecrypt(Channel->GetChannelID(), CamSlots.Get(j)->MasterSlotNumber()) : 0; // prefer CAMs that are known to decrypt this channel
321 imp <<= 1; imp |= device[i]->IsPrimaryDevice(); // avoid the primary device
322 if (imp < Impact) {
323 // This device has less impact than any previous one, so we take it.
324 Impact = imp;
325 d = device[i];
326 NeedsDetachReceivers = ndr;
327 if (NumUsableSlots && !HasInternalCam)
328 s = CamSlots.Get(j);
329 }
330 //dsyslog("device %d provides channel %d prio %d ndr %d imp %.8X", device[i]->DeviceNumber() + 1, Channel->Number(), Priority, ndr, imp);
331 }
332 }
333 if (!NumUsableSlots)
334 break; // no CAM necessary, so just one loop over the devices
335 }
336 if (d) {
337 if (!Query && NeedsDetachReceivers)
339 if (s) {
340 // Some of the following statements could probably be combined, but let's keep them
341 // explicit so we can clearly see every single aspect of the decisions made here.
342 if (d->CamSlot()) {
343 if (s->MtdActive()) {
344 if (s == d->CamSlot()->MasterSlot()) {
345 // device d already has a proper CAM slot, so nothing to do here
346 }
347 else {
348 // device d has a CAM slot, but it's not the right one
349 if (!Query) {
350 d->CamSlot()->Assign(NULL);
351 s = s->MtdSpawn();
352 s->Assign(d);
353 }
354 }
355 }
356 else {
357 if (s->Device()) {
358 if (s->Device() != d) {
359 // CAM slot s is currently assigned to a different device than d
360 if (Priority > s->Priority()) {
361 if (!Query) {
362 d->CamSlot()->Assign(NULL);
363 s->Assign(d);
364 }
365 }
366 else {
367 d = NULL;
368 s = NULL;
369 }
370 }
371 else {
372 // device d already has a proper CAM slot, so nothing to do here
373 }
374 }
375 else {
376 if (s != d->CamSlot()) {
377 // device d has a CAM slot, but it's not the right one
378 if (!Query) {
379 d->CamSlot()->Assign(NULL);
380 s->Assign(d);
381 }
382 }
383 else {
384 // device d already has a proper CAM slot, so nothing to do here
385 }
386 }
387 }
388 }
389 else {
390 // device d has no CAM slot, ...
391 if (s->MtdActive()) {
392 // ... so we assign s with MTD support
393 if (!Query) {
394 s = s->MtdSpawn();
395 s->Assign(d);
396 }
397 }
398 else {
399 // CAM slot s has no MTD support ...
400 if (s->Device()) {
401 // ... but it is assigned to a different device, so we reassign it to d
402 if (Priority > s->Priority()) {
403 if (!Query) {
405 s->Assign(d);
406 }
407 }
408 else {
409 d = NULL;
410 s = NULL;
411 }
412 }
413 else {
414 // ... and is not assigned to any device, so we just assign it to d
415 if (!Query)
416 s->Assign(d);
417 }
418 }
419 }
420 }
421 else if (d->CamSlot() && !d->CamSlot()->IsDecrypting())
422 d->CamSlot()->Assign(NULL);
423 }
424 return d;
425}
426
428{
429 cDevice *Device = NULL;
430 for (int i = 0; i < cDevice::NumDevices(); i++) {
431 if (cDevice *d = cDevice::GetDevice(i)) {
432 if (d->IsTunedToTransponder(Channel))
433 return d; // if any device is tuned to the transponder, we're done
434 if (d->ProvidesTransponder(Channel)) {
435 if (d->MaySwitchTransponder(Channel))
436 return d; // this device may switch to the transponder without disturbing any receiver or live view
437 else if (!d->Occupied(Priority) && !d->IsBonded() && d->Priority(true) < LIVEPRIORITY) { // MaySwitchTransponder() implicitly calls Occupied()
438 // we select only devices with priority < LIVEPRIORITY, so device can be switched without impact on recordings or live viewing
439 if (d->Priority() < Priority && (!Device || d->Priority() < Device->Priority()))
440 Device = d; // use this one only if no other with less impact can be found
441 }
442 }
443 }
444 }
445 return Device;
446}
447
449{
451 camSlot->Assign(NULL);
452}
453
455{
456 return false;
457}
458
460{
463}
464
466{
468 for (int i = 0; i < numDevices; i++) {
469 delete device[i];
470 device[i] = NULL;
471 }
472}
473
474uchar *cDevice::GrabImage(int &Size, bool Jpeg, int Quality, int SizeX, int SizeY)
475{
476 return NULL;
477}
478
479bool cDevice::GrabImageFile(const char *FileName, bool Jpeg, int Quality, int SizeX, int SizeY)
480{
481 int result = 0;
482 int fd = open(FileName, O_WRONLY | O_CREAT | O_NOFOLLOW | O_TRUNC, DEFFILEMODE);
483 if (fd >= 0) {
484 int ImageSize;
485 uchar *Image = GrabImage(ImageSize, Jpeg, Quality, SizeX, SizeY);
486 if (Image) {
487 if (safe_write(fd, Image, ImageSize) == ImageSize)
488 isyslog("grabbed image to %s", FileName);
489 else {
490 LOG_ERROR_STR(FileName);
491 result |= 1;
492 }
493 free(Image);
494 }
495 else
496 result |= 1;
497 close(fd);
498 }
499 else {
500 LOG_ERROR_STR(FileName);
501 result |= 1;
502 }
503 return result == 0;
504}
505
507{
508 cSpuDecoder *spuDecoder = GetSpuDecoder();
509 if (spuDecoder) {
510 if (Setup.VideoFormat)
512 else {
513 switch (VideoDisplayFormat) {
514 case vdfPanAndScan:
516 break;
517 case vdfLetterBox:
519 break;
520 case vdfCenterCutOut:
522 break;
523 default: esyslog("ERROR: invalid value for VideoDisplayFormat '%d'", VideoDisplayFormat);
524 }
525 }
526 }
527}
528
529void cDevice::SetVideoFormat(bool VideoFormat16_9)
530{
531}
532
533void cDevice::GetVideoSize(int &Width, int &Height, double &VideoAspect)
534{
535 Width = 0;
536 Height = 0;
537 VideoAspect = 1.0;
538}
539
540void cDevice::GetOsdSize(int &Width, int &Height, double &PixelAspect)
541{
542 Width = 720;
543 Height = 480;
544 PixelAspect = 1.0;
545}
546
547//#define PRINTPIDS(s) { char b[500]; char *q = b; q += sprintf(q, "%d %s ", DeviceNumber() + 1, s); for (int i = 0; i < MAXPIDHANDLES; i++) q += sprintf(q, " %s%4d %d", i == ptOther ? "* " : "", pidHandles[i].pid, pidHandles[i].used); dsyslog("%s", b); }
548#define PRINTPIDS(s)
549
550bool cDevice::HasPid(int Pid) const
551{
552 cMutexLock MutexLock(&mutexPids);
553 for (int i = 0; i < MAXPIDHANDLES; i++) {
554 if (pidHandles[i].pid == Pid)
555 return true;
556 }
557 return false;
558}
559
560bool cDevice::AddPid(int Pid, ePidType PidType, int StreamType)
561{
562 cMutexLock MutexLock(&mutexPids);
563 if (Pid || PidType == ptPcr) {
564 int n = -1;
565 int a = -1;
566 if (PidType != ptPcr) { // PPID always has to be explicit
567 for (int i = 0; i < MAXPIDHANDLES; i++) {
568 if (i != ptPcr) {
569 if (pidHandles[i].pid == Pid)
570 n = i;
571 else if (a < 0 && i >= ptOther && !pidHandles[i].used)
572 a = i;
573 }
574 }
575 }
576 if (n >= 0) {
577 // The Pid is already in use
578 if (++pidHandles[n].used == 2 && n <= ptTeletext) {
579 // It's a special PID that may have to be switched into "tap" mode
580 PRINTPIDS("A");
581 if (!SetPid(&pidHandles[n], n, true)) {
582 esyslog("ERROR: can't set PID %d on device %d", Pid, DeviceNumber() + 1);
583 if (PidType <= ptTeletext)
584 DetachAll(Pid);
585 DelPid(Pid, PidType);
586 return false;
587 }
588 if (camSlot)
589 camSlot->SetPid(Pid, true);
590 }
591 PRINTPIDS("a");
592 return true;
593 }
594 else if (PidType < ptOther) {
595 // The Pid is not yet in use and it is a special one
596 n = PidType;
597 }
598 else if (a >= 0) {
599 // The Pid is not yet in use and we have a free slot
600 n = a;
601 }
602 else {
603 esyslog("ERROR: no free slot for PID %d on device %d", Pid, DeviceNumber() + 1);
604 return false;
605 }
606 if (n >= 0) {
607 pidHandles[n].pid = Pid;
608 pidHandles[n].streamType = StreamType;
609 pidHandles[n].used = 1;
610 PRINTPIDS("C");
611 if (!SetPid(&pidHandles[n], n, true)) {
612 esyslog("ERROR: can't set PID %d on device %d", Pid, DeviceNumber() + 1);
613 if (PidType <= ptTeletext)
614 DetachAll(Pid);
615 DelPid(Pid, PidType);
616 return false;
617 }
618 if (camSlot)
619 camSlot->SetPid(Pid, true);
620 }
621 }
622 return true;
623}
624
625void cDevice::DelPid(int Pid, ePidType PidType)
626{
627 cMutexLock MutexLock(&mutexPids);
628 if (Pid || PidType == ptPcr) {
629 int n = -1;
630 if (PidType == ptPcr)
631 n = PidType; // PPID always has to be explicit
632 else {
633 for (int i = 0; i < MAXPIDHANDLES; i++) {
634 if (pidHandles[i].pid == Pid) {
635 n = i;
636 break;
637 }
638 }
639 }
640 if (n >= 0 && pidHandles[n].used) {
641 PRINTPIDS("D");
642 if (--pidHandles[n].used < 2) {
643 SetPid(&pidHandles[n], n, false);
644 if (pidHandles[n].used == 0) {
645 pidHandles[n].handle = -1;
646 pidHandles[n].pid = 0;
647 if (camSlot)
648 camSlot->SetPid(Pid, false);
649 }
650 }
651 PRINTPIDS("E");
652 }
653 }
654}
655
656bool cDevice::SetPid(cPidHandle *Handle, int Type, bool On)
657{
658 return false;
659}
660
662{
663 cMutexLock MutexLock(&mutexPids);
664 for (int i = ptAudio; i < ptOther; i++) {
665 if (pidHandles[i].pid)
666 DelPid(pidHandles[i].pid, ePidType(i));
667 }
668}
669
680
682{
683 if (sectionHandler) {
684 delete sectionHandler; // automatically detaches filters
685 delete nitFilter;
686 delete sdtFilter;
687 delete patFilter;
688 delete eitFilter;
689 nitFilter = NULL;
690 sdtFilter = NULL;
691 patFilter = NULL;
692 eitFilter = NULL;
693 sectionHandler = NULL;
694 }
695}
696
697int cDevice::OpenFilter(u_short Pid, u_char Tid, u_char Mask)
698{
699 return -1;
700}
701
702int cDevice::ReadFilter(int Handle, void *Buffer, size_t Length)
703{
704 return safe_read(Handle, Buffer, Length);
705}
706
707void cDevice::CloseFilter(int Handle)
708{
709 close(Handle);
710}
711
713{
714 if (sectionHandler)
715 sectionHandler->Attach(Filter);
716}
717
719{
720 if (sectionHandler)
721 sectionHandler->Detach(Filter);
722}
723
724bool cDevice::ProvidesSource(int Source) const
725{
726 return false;
727}
728
730{
731 cDeviceHook *Hook = deviceHooks.First();
732 while (Hook) {
733 if (!Hook->DeviceProvidesTransponder(this, Channel))
734 return false;
735 Hook = deviceHooks.Next(Hook);
736 }
737 return true;
738}
739
741{
742 cDeviceHook *Hook = deviceHooks.First();
743 while (Hook) {
744 if (!Hook->DeviceProvidesEIT(this))
745 return false;
746 Hook = deviceHooks.Next(Hook);
747 }
748 return true;
749}
750
751bool cDevice::ProvidesTransponder(const cChannel *Channel) const
752{
753 return false;
754}
755
757{
758 for (int i = 0; i < numDevices; i++) {
759 if (device[i] && device[i] != this && device[i]->ProvidesTransponder(Channel))
760 return false;
761 }
762 return true;
763}
764
765bool cDevice::ProvidesChannel(const cChannel *Channel, int Priority, bool *NeedsDetachReceivers) const
766{
767 return false;
768}
769
770bool cDevice::ProvidesEIT(void) const
771{
772 return false;
773}
774
776{
777 return 0;
778}
779
781{
782 return NULL;
783}
784
785bool cDevice::SignalStats(int &Valid, double *Strength, double *Cnr, double *BerPre, double *BerPost, double *Per, int *Status) const
786{
787 return false;
788}
789
791{
792 return -1;
793}
794
796{
797 return -1;
798}
799
801{
802 return NULL;
803}
804
805bool cDevice::IsTunedToTransponder(const cChannel *Channel) const
806{
807 return false;
808}
809
810bool cDevice::MaySwitchTransponder(const cChannel *Channel) const
811{
813}
814
815bool cDevice::SwitchChannel(const cChannel *Channel, bool LiveView)
816{
817 if (LiveView) {
818 isyslog("switching to channel %d %s (%s)", Channel->Number(), *Channel->GetChannelID().ToString(), Channel->Name());
819 cControl::Shutdown(); // prevents old channel from being shown too long if GetDevice() takes longer
820 // and, if decrypted, this removes the now superfluous PIDs from the CAM, too
821 }
822 for (int i = 3; i--;) {
823 switch (SetChannel(Channel, LiveView)) {
824 case scrOk: return true;
825 case scrNotAvailable: Skins.QueueMessage(mtInfo, tr("Channel not available!"));
826 return false;
827 case scrNoTransfer: Skins.QueueMessage(mtError, tr("Can't start Transfer Mode!"));
828 return false;
829 case scrFailed: break; // loop will retry
830 default: esyslog("ERROR: invalid return value from SetChannel");
831 }
832 esyslog("retrying");
833 }
834 return false;
835}
836
837bool cDevice::SwitchChannel(int Direction)
838{
839 bool result = false;
840 Direction = sgn(Direction);
841 if (Direction) {
842 cControl::Shutdown(); // prevents old channel from being shown too long if GetDevice() takes longer
843 // and, if decrypted, this removes the now superfluous PIDs from the CAM, too
844 int n = CurrentChannel() + Direction;
845 int first = n;
847 const cChannel *Channel;
848 while ((Channel = Channels->GetByNumber(n, Direction)) != NULL) {
849 // try only channels which are currently available
850 if (GetDevice(Channel, LIVEPRIORITY, true, true))
851 break;
852 n = Channel->Number() + Direction;
853 }
854 if (Channel) {
855 int d = n - first;
856 if (abs(d) == 1)
857 dsyslog("skipped channel %d", first);
858 else if (d)
859 dsyslog("skipped channels %d..%d", first, n - sgn(d));
860 if (PrimaryDevice()->SwitchChannel(Channel, true))
861 result = true;
862 }
863 else if (n != first)
864 Skins.QueueMessage(mtError, tr("Channel not available!"));
865 }
866 return result;
867}
868
869eSetChannelResult cDevice::SetChannel(const cChannel *Channel, bool LiveView)
870{
871 cMutexLock MutexLock(&mutexChannel); // to avoid a race between SVDRP CHAN and HasProgramme()
872 cStatus::MsgChannelSwitch(this, 0, LiveView);
873
874 if (LiveView) {
875 if (IsPrimaryDevice() && !Replaying() && !Transferring()) { // this is only for FF DVB cards!
877 if (const cChannel *ch = Channels->GetByNumber(currentChannel)) {
878 if (patFilter)
879 patFilter->Release(ch->Sid());
880 }
881 }
882 StopReplay();
885 }
886
887 cDevice *Device = (LiveView && IsPrimaryDevice(false)) ? GetDevice(Channel, LIVEPRIORITY, true) : this;
888
889 bool NeedsTransferMode = LiveView && Device != PrimaryDevice();
890 // If the CAM slot wants the TS data, we need to switch to Transfer Mode:
891 if (!NeedsTransferMode && LiveView && IsPrimaryDevice() && CamSlot() && CamSlot()->WantsTsData())
892 NeedsTransferMode = true;
893
894 eSetChannelResult Result = scrOk;
895
896 // If this DVB card can't receive this channel, let's see if we can
897 // use the card that actually can receive it and transfer data from there:
898
899 if (NeedsTransferMode) {
900 if (Device && PrimaryDevice()->CanReplay()) {
901 if (Device->SetChannel(Channel, false) == scrOk) // calling SetChannel() directly, not SwitchChannel()!
902 cControl::Launch(new cTransferControl(Device, Channel));
903 else
904 Result = scrNoTransfer;
905 }
906 else
907 Result = scrNotAvailable;
908 }
909 else {
910 // Stop section handling:
911 if (sectionHandler) {
914 }
915 // Tell the camSlot about the channel switch and add all PIDs of this
916 // channel to it, for possible later decryption:
917 if (camSlot)
918 camSlot->AddChannel(Channel);
919 if (SetChannelDevice(Channel, LiveView)) {
920 // Start section handling:
921 if (sectionHandler) {
922 sectionHandler->SetChannel(Channel);
924 }
925 // Start decrypting any PIDs that might have been set in SetChannelDevice():
926 if (camSlot)
928 }
929 else
930 Result = scrFailed;
931 }
932
933 if (Result == scrOk) {
934 if (LiveView) {
935 if (IsPrimaryDevice(false))
936 currentChannel = Channel->Number();
937 if (IsPrimaryDevice()) {
938 if (patFilter) // this is only for FF DVB cards!
939 patFilter->Request(Channel->Sid());
940 // Set the available audio tracks:
942 for (int i = 0; i < MAXAPIDS; i++)
943 SetAvailableTrack(ttAudio, i, Channel->Apid(i), Channel->Alang(i));
945 for (int i = 0; i < MAXDPIDS; i++)
946 SetAvailableTrack(ttDolby, i, Channel->Dpid(i), Channel->Dlang(i));
947 }
948 for (int i = 0; i < MAXSPIDS; i++)
949 SetAvailableTrack(ttSubtitle, i, Channel->Spid(i), Channel->Slang(i));
950 if (!NeedsTransferMode)
951 EnsureAudioTrack(true);
953 }
954 }
955 cStatus::MsgChannelSwitch(this, Channel->Number(), LiveView); // only report status if channel switch successful
956 }
957
958 return Result;
959}
960
962{
965 if (const cChannel *Channel = Channels->GetByNumber(CurrentChannel()))
966 SetChannelDevice(Channel, false); // this implicitly starts Transfer Mode
967 }
968}
969
970int cDevice::Occupied(int Priority) const
971{
973 return 0;
974 int Seconds = occupiedTimeout - time(NULL);
975 return Seconds > 0 ? Seconds : 0;
976}
977
978void cDevice::SetOccupied(int Seconds, int Priority, time_t From)
979{
980 if (Seconds < 0)
981 return;
982 if (From == 0)
983 From = time(NULL);
984 if (From == occupiedFrom)
986 else {
988 occupiedFrom = From;
989 }
990 occupiedTimeout = From + min(Seconds, MAXOCCUPIEDTIMEOUT);
991}
992
993bool cDevice::SetChannelDevice(const cChannel *Channel, bool LiveView)
994{
995 return false;
996}
997
998bool cDevice::HasLock(int TimeoutMs) const
999{
1000 return true;
1001}
1002
1004{
1005 cMutexLock MutexLock(&mutexChannel); // to avoid a race between SVDRP CHAN and HasProgramme()
1007}
1008
1010{
1011 return 0;
1012}
1013
1015{
1016}
1017
1019{
1020}
1021
1023{
1024}
1025
1029
1033
1035{
1036 int OldVolume = volume;
1037 mute = !mute;
1038 //XXX why is it necessary to use different sequences???
1039 if (mute) {
1040 SetVolume(0, true);
1041 Audios.MuteAudio(mute); // Mute external audio after analog audio
1042 }
1043 else {
1044 Audios.MuteAudio(mute); // Enable external audio before analog audio
1045 SetVolume(OldVolume, true);
1046 }
1047 volume = OldVolume;
1048 return mute;
1049}
1050
1052{
1053 int c = GetAudioChannelDevice();
1054 return (0 <= c && c <= 2) ? c : 0;
1055}
1056
1057void cDevice::SetAudioChannel(int AudioChannel)
1058{
1059 if (0 <= AudioChannel && AudioChannel <= 2)
1060 SetAudioChannelDevice(AudioChannel);
1061}
1062
1063void cDevice::SetVolume(int Volume, bool Absolute)
1064{
1065 int OldVolume = volume;
1066 double VolumeDelta = double(MAXVOLUME) / Setup.VolumeSteps;
1067 double VolumeLinearize = (Setup.VolumeLinearize >= 0) ? (Setup.VolumeLinearize / 10.0 + 1.0) : (1.0 / ((-Setup.VolumeLinearize / 10.0) + 1.0));
1068 volume = constrain(int(floor((Absolute ? Volume : volume + Volume) / VolumeDelta + 0.5) * VolumeDelta), 0, MAXVOLUME);
1069 SetVolumeDevice(MAXVOLUME - int(pow(1.0 - pow(double(volume) / MAXVOLUME, VolumeLinearize), 1.0 / VolumeLinearize) * MAXVOLUME));
1070 Absolute |= mute;
1071 cStatus::MsgSetVolume(Absolute ? volume : volume - OldVolume, Absolute);
1072 if (volume > 0) {
1073 mute = false;
1075 }
1076}
1077
1078void cDevice::ClrAvailableTracks(bool DescriptionsOnly, bool IdsOnly)
1079{
1080 if (keepTracks)
1081 return;
1082 if (DescriptionsOnly) {
1083 for (int i = ttNone; i < ttMaxTrackTypes; i++)
1085 }
1086 else {
1087 if (IdsOnly) {
1088 for (int i = ttNone; i < ttMaxTrackTypes; i++)
1089 availableTracks[i].id = 0;
1090 }
1091 else
1092 memset(availableTracks, 0, sizeof(availableTracks));
1094 SetAudioChannel(0); // fall back to stereo
1098 }
1099}
1100
1101bool cDevice::SetAvailableTrack(eTrackType Type, int Index, uint16_t Id, const char *Language, const char *Description)
1102{
1103 eTrackType t = eTrackType(Type + Index);
1104 if (Type == ttAudio && IS_AUDIO_TRACK(t) ||
1105 Type == ttDolby && IS_DOLBY_TRACK(t) ||
1106 Type == ttSubtitle && IS_SUBTITLE_TRACK(t)) {
1107 if (Language)
1108 strn0cpy(availableTracks[t].language, Language, sizeof(availableTracks[t].language));
1109 if (Description)
1111 if (Id) {
1112 availableTracks[t].id = Id; // setting 'id' last to avoid the need for extensive locking
1113 if (Type == ttAudio || Type == ttDolby) {
1114 int numAudioTracks = NumAudioTracks();
1115 if (!availableTracks[currentAudioTrack].id && numAudioTracks && currentAudioTrackMissingCount++ > numAudioTracks * 10)
1117 else if (t == currentAudioTrack)
1119 }
1122 }
1123 return true;
1124 }
1125 else
1126 esyslog("ERROR: SetAvailableTrack called with invalid Type/Index (%d/%d)", Type, Index);
1127 return false;
1128}
1129
1131{
1132 return (ttNone < Type && Type < ttMaxTrackTypes) ? &availableTracks[Type] : NULL;
1133}
1134
1135int cDevice::NumTracks(eTrackType FirstTrack, eTrackType LastTrack) const
1136{
1137 int n = 0;
1138 for (int i = FirstTrack; i <= LastTrack; i++) {
1139 if (availableTracks[i].id)
1140 n++;
1141 }
1142 return n;
1143}
1144
1146{
1148}
1149
1151{
1153}
1154
1156{
1157 if (ttNone < Type && Type <= ttDolbyLast) {
1159 if (IS_DOLBY_TRACK(Type))
1161 currentAudioTrack = Type;
1162 if (player)
1164 else
1166 if (IS_AUDIO_TRACK(Type))
1167 SetDigitalAudioDevice(false);
1168 return true;
1169 }
1170 return false;
1171}
1172
1174{
1175 if (Type == ttNone || IS_SUBTITLE_TRACK(Type)) {
1176 currentSubtitleTrack = Type;
1180 if (Type == ttNone && dvbSubtitleConverter) {
1183 }
1185 if (player)
1187 else
1190 const tTrackId *TrackId = GetTrack(currentSubtitleTrack);
1191 if (TrackId && TrackId->id) {
1192 liveSubtitle = new cLiveSubtitle(TrackId->id);
1194 }
1195 }
1196 return true;
1197 }
1198 return false;
1199}
1200
1202{
1203 if (keepTracks)
1204 return;
1205 if (Force || !availableTracks[currentAudioTrack].id) {
1206 eTrackType PreferredTrack = ttAudioFirst;
1207 int PreferredAudioChannel = 0;
1208 int LanguagePreference = -1;
1209 int StartCheck = Setup.CurrentDolby ? ttDolbyFirst : ttAudioFirst;
1210 int EndCheck = ttDolbyLast;
1211 for (int i = StartCheck; i <= EndCheck; i++) {
1212 const tTrackId *TrackId = GetTrack(eTrackType(i));
1213 int pos = 0;
1214 if (TrackId && TrackId->id && I18nIsPreferredLanguage(Setup.AudioLanguages, TrackId->language, LanguagePreference, &pos)) {
1215 PreferredTrack = eTrackType(i);
1216 PreferredAudioChannel = pos;
1217 }
1218 if (Setup.CurrentDolby && i == ttDolbyLast) {
1219 i = ttAudioFirst - 1;
1220 EndCheck = ttAudioLast;
1221 }
1222 }
1223 // Make sure we're set to an available audio track:
1224 const tTrackId *Track = GetTrack(GetCurrentAudioTrack());
1225 if (Force || !Track || !Track->id || PreferredTrack != GetCurrentAudioTrack()) {
1226 if (!Force) // only log this for automatic changes
1227 dsyslog("setting audio track to %d (%d)", PreferredTrack, PreferredAudioChannel);
1228 SetCurrentAudioTrack(PreferredTrack);
1229 SetAudioChannel(PreferredAudioChannel);
1230 }
1231 }
1232}
1233
1235{
1236 if (keepTracks)
1237 return;
1238 if (Setup.DisplaySubtitles) {
1239 eTrackType PreferredTrack = ttNone;
1240 int LanguagePreference = INT_MAX; // higher than the maximum possible value
1241 for (int i = ttSubtitleFirst; i <= ttSubtitleLast; i++) {
1242 const tTrackId *TrackId = GetTrack(eTrackType(i));
1243 if (TrackId && TrackId->id && (I18nIsPreferredLanguage(Setup.SubtitleLanguages, TrackId->language, LanguagePreference) ||
1244 (i == ttSubtitleFirst + 8 && !*TrackId->language && LanguagePreference == INT_MAX))) // compatibility mode for old subtitles plugin
1245 PreferredTrack = eTrackType(i);
1246 }
1247 // Make sure we're set to an available subtitle track:
1248 const tTrackId *Track = GetTrack(GetCurrentSubtitleTrack());
1249 if (!Track || !Track->id || PreferredTrack != GetCurrentSubtitleTrack())
1250 SetCurrentSubtitleTrack(PreferredTrack);
1251 }
1252 else
1254}
1255
1256bool cDevice::CanReplay(void) const
1257{
1258 return HasDecoder();
1259}
1260
1262{
1263 return false;
1264}
1265
1266int64_t cDevice::GetSTC(void)
1267{
1268 return -1;
1269}
1270
1271void cDevice::TrickSpeed(int Speed, bool Forward)
1272{
1273}
1274
1276{
1280}
1281
1283{
1287}
1288
1290{
1291 Audios.MuteAudio(true);
1294}
1295
1297{
1298 Audios.MuteAudio(true);
1299}
1300
1301void cDevice::StillPicture(const uchar *Data, int Length)
1302{
1303 if (Data[0] == 0x47) {
1304 // TS data
1305 cTsToPes TsToPes;
1306 uchar *buf = NULL;
1307 int Size = 0;
1308 while (Length >= TS_SIZE) {
1309 int Pid = TsPid(Data);
1310 if (Pid == PATPID)
1312 else if (patPmtParser.IsPmtPid(Pid))
1314 else if (Pid == patPmtParser.Vpid()) {
1315 if (TsPayloadStart(Data)) {
1316 int l;
1317 while (const uchar *p = TsToPes.GetPes(l)) {
1318 int Offset = Size;
1319 int NewSize = Size + l;
1320 if (uchar *NewBuffer = (uchar *)realloc(buf, NewSize)) {
1321 Size = NewSize;
1322 buf = NewBuffer;
1323 memcpy(buf + Offset, p, l);
1324 }
1325 else {
1326 LOG_ERROR_STR("out of memory");
1327 free(buf);
1328 return;
1329 }
1330 }
1331 TsToPes.Reset();
1332 }
1333 TsToPes.PutTs(Data, TS_SIZE);
1334 }
1335 Length -= TS_SIZE;
1336 Data += TS_SIZE;
1337 }
1338 int l;
1339 while (const uchar *p = TsToPes.GetPes(l)) {
1340 int Offset = Size;
1341 int NewSize = Size + l;
1342 if (uchar *NewBuffer = (uchar *)realloc(buf, NewSize)) {
1343 Size = NewSize;
1344 buf = NewBuffer;
1345 memcpy(buf + Offset, p, l);
1346 }
1347 else {
1348 esyslog("ERROR: out of memory");
1349 free(buf);
1350 return;
1351 }
1352 }
1353 if (buf) {
1354 StillPicture(buf, Size);
1355 free(buf);
1356 }
1357 }
1358}
1359
1360bool cDevice::Replaying(void) const
1361{
1362 return player != NULL;
1363}
1364
1366{
1367 return cTransferControl::ReceiverDevice() != NULL;
1368}
1369
1371{
1372 if (CanReplay()) {
1373 if (player)
1374 Detach(player);
1378 player = Player;
1379 if (!Transferring())
1380 ClrAvailableTracks(false, true);
1382 player->device = this;
1383 player->Activate(true);
1384 return true;
1385 }
1386 return false;
1387}
1388
1390{
1391 if (Player && player == Player) {
1392 cPlayer *p = player;
1393 player = NULL; // avoids recursive calls to Detach()
1394 p->Activate(false);
1395 p->device = NULL;
1397 delete dvbSubtitleConverter;
1398 dvbSubtitleConverter = NULL;
1401 PlayTs(NULL, 0);
1404 isPlayingVideo = false;
1405 }
1406}
1407
1409{
1410 if (player) {
1411 Detach(player);
1412 if (IsPrimaryDevice())
1414 }
1415}
1416
1417bool cDevice::Poll(cPoller &Poller, int TimeoutMs)
1418{
1419 return false;
1420}
1421
1422bool cDevice::Flush(int TimeoutMs)
1423{
1424 return true;
1425}
1426
1427int cDevice::PlayVideo(const uchar *Data, int Length)
1428{
1429 return -1;
1430}
1431
1432int cDevice::PlayAudio(const uchar *Data, int Length, uchar Id)
1433{
1434 return -1;
1435}
1436
1437int cDevice::PlaySubtitle(const uchar *Data, int Length)
1438{
1441 return dvbSubtitleConverter->ConvertFragments(Data, Length);
1442}
1443
1444int cDevice::PlayPesPacket(const uchar *Data, int Length, bool VideoOnly)
1445{
1446 bool FirstLoop = true;
1447 uchar c = Data[3];
1448 const uchar *Start = Data;
1449 const uchar *End = Start + Length;
1450 while (Start < End) {
1451 int d = End - Start;
1452 int w = d;
1453 switch (c) {
1454 case 0xBE: // padding stream, needed for MPEG1
1455 case 0xE0 ... 0xEF: // video
1456 isPlayingVideo = true;
1457 w = PlayVideo(Start, d);
1458 break;
1459 case 0xC0 ... 0xDF: // audio
1460 SetAvailableTrack(ttAudio, c - 0xC0, c);
1461 if ((!VideoOnly || HasIBPTrickSpeed()) && c == availableTracks[currentAudioTrack].id) {
1462 w = PlayAudio(Start, d, c);
1463 if (FirstLoop)
1464 Audios.PlayAudio(Data, Length, c);
1465 }
1466 break;
1467 case 0xBD: { // private stream 1
1468 int PayloadOffset = Data[8] + 9;
1469
1470 // Compatibility mode for old subtitles plugin:
1471 if ((Data[7] & 0x01) && (Data[PayloadOffset - 3] & 0x81) == 0x01 && Data[PayloadOffset - 2] == 0x81)
1472 PayloadOffset--;
1473
1474 uchar SubStreamId = Data[PayloadOffset];
1475 uchar SubStreamType = SubStreamId & 0xF0;
1476 uchar SubStreamIndex = SubStreamId & 0x1F;
1477
1478 // Compatibility mode for old VDR recordings, where 0xBD was only AC3:
1479pre_1_3_19_PrivateStreamDetected:
1481 SubStreamId = c;
1482 SubStreamType = 0x80;
1483 SubStreamIndex = 0;
1484 }
1485 else if (pre_1_3_19_PrivateStream)
1486 pre_1_3_19_PrivateStream--; // every known PS1 packet counts down towards 0 to recover from glitches...
1487 switch (SubStreamType) {
1488 case 0x20: // SPU
1489 case 0x30: // SPU
1490 SetAvailableTrack(ttSubtitle, SubStreamIndex, SubStreamId);
1491 if ((!VideoOnly || HasIBPTrickSpeed()) && currentSubtitleTrack != ttNone && SubStreamId == availableTracks[currentSubtitleTrack].id)
1492 w = PlaySubtitle(Start, d);
1493 break;
1494 case 0x80: // AC3 & DTS
1495 if (Setup.UseDolbyDigital) {
1496 SetAvailableTrack(ttDolby, SubStreamIndex, SubStreamId);
1497 if ((!VideoOnly || HasIBPTrickSpeed()) && SubStreamId == availableTracks[currentAudioTrack].id) {
1498 w = PlayAudio(Start, d, SubStreamId);
1499 if (FirstLoop)
1500 Audios.PlayAudio(Data, Length, SubStreamId);
1501 }
1502 }
1503 break;
1504 case 0xA0: // LPCM
1505 SetAvailableTrack(ttAudio, SubStreamIndex, SubStreamId);
1506 if ((!VideoOnly || HasIBPTrickSpeed()) && SubStreamId == availableTracks[currentAudioTrack].id) {
1507 w = PlayAudio(Start, d, SubStreamId);
1508 if (FirstLoop)
1509 Audios.PlayAudio(Data, Length, SubStreamId);
1510 }
1511 break;
1512 default:
1513 // Compatibility mode for old VDR recordings, where 0xBD was only AC3:
1515 dsyslog("unknown PS1 packet, substream id = %02X (counter is at %d)", SubStreamId, pre_1_3_19_PrivateStream);
1516 pre_1_3_19_PrivateStream += 2; // ...and every unknown PS1 packet counts up (the very first one counts twice, but that's ok)
1518 dsyslog("switching to pre 1.3.19 Dolby Digital compatibility mode - substream id = %02X", SubStreamId);
1521 goto pre_1_3_19_PrivateStreamDetected;
1522 }
1523 }
1524 }
1525 }
1526 break;
1527 default:
1528 ;//esyslog("ERROR: unexpected packet id %02X", c);
1529 }
1530 if (w > 0)
1531 Start += w;
1532 else {
1533 if (Start != Data)
1534 esyslog("ERROR: incomplete PES packet write!");
1535 return Start == Data ? w : Start - Data;
1536 }
1537 FirstLoop = false;
1538 }
1539 return Length;
1540}
1541
1542int cDevice::PlayPes(const uchar *Data, int Length, bool VideoOnly)
1543{
1544 if (!Data) {
1547 return 0;
1548 }
1549 int i = 0;
1550 while (i <= Length - 6) {
1551 if (Data[i] == 0x00 && Data[i + 1] == 0x00 && Data[i + 2] == 0x01) {
1552 int l = PesLength(Data + i);
1553 if (i + l > Length) {
1554 esyslog("ERROR: incomplete PES packet!");
1555 return Length;
1556 }
1557 int w = PlayPesPacket(Data + i, l, VideoOnly);
1558 if (w > 0)
1559 i += l;
1560 else
1561 return i == 0 ? w : i;
1562 }
1563 else
1564 i++;
1565 }
1566 if (i < Length)
1567 esyslog("ERROR: leftover PES data!");
1568 return Length;
1569}
1570
1571int cDevice::PlayTsVideo(const uchar *Data, int Length)
1572{
1573 // Video PES has no explicit length, so we can only determine the end of
1574 // a PES packet when the next TS packet that starts a payload comes in:
1575 if (TsPayloadStart(Data)) {
1576 int l;
1577 while (const uchar *p = tsToPesVideo.GetPes(l)) {
1578 int w = PlayVideo(p, l);
1579 if (w <= 0) {
1581 return w;
1582 }
1583 }
1585 }
1586 tsToPesVideo.PutTs(Data, Length);
1587 return Length;
1588}
1589
1590int cDevice::PlayTsAudio(const uchar *Data, int Length)
1591{
1592 // Audio PES always has an explicit length and consists of single packets:
1593 int l;
1594 if (const uchar *p = tsToPesAudio.GetPes(l)) {
1595 int w = PlayAudio(p, l, p[3]);
1596 if (w <= 0) {
1598 return w;
1599 }
1601 }
1602 tsToPesAudio.PutTs(Data, Length);
1603 return Length;
1604}
1605
1606int cDevice::PlayTsSubtitle(const uchar *Data, int Length)
1607{
1610 tsToPesSubtitle.PutTs(Data, Length);
1611 int l;
1612 if (const uchar *p = tsToPesSubtitle.GetPes(l)) {
1615 }
1616 return Length;
1617}
1618
1619int cDevice::PlayTs(const uchar *Data, int Length, bool VideoOnly)
1620{
1621 int Played = 0;
1622 if (!Data) {
1626 }
1627 else if (Length < TS_SIZE) {
1628 esyslog("ERROR: skipped %d bytes of TS fragment", Length);
1629 return Length;
1630 }
1631 else {
1632 while (Length >= TS_SIZE) {
1633 if (int Skipped = TS_SYNC(Data, Length))
1634 return Played + Skipped;
1635 int Pid = TsPid(Data);
1636 if (TsHasPayload(Data)) { // silently ignore TS packets w/o payload
1637 int PayloadOffset = TsPayloadOffset(Data);
1638 if (PayloadOffset < TS_SIZE) {
1639 if (Pid == PATPID)
1641 else if (patPmtParser.IsPmtPid(Pid))
1643 else if (Pid == patPmtParser.Vpid()) {
1644 isPlayingVideo = true;
1645 int w = PlayTsVideo(Data, TS_SIZE);
1646 if (w < 0)
1647 return Played ? Played : w;
1648 if (w == 0)
1649 break;
1650 }
1651 else if (Pid == availableTracks[currentAudioTrack].id) {
1652 if (!VideoOnly || HasIBPTrickSpeed()) {
1653 int w = PlayTsAudio(Data, TS_SIZE);
1654 if (w < 0)
1655 return Played ? Played : w;
1656 if (w == 0)
1657 break;
1658 Audios.PlayTsAudio(Data, TS_SIZE);
1659 }
1660 }
1661 else if (Pid == availableTracks[currentSubtitleTrack].id) {
1662 if (!VideoOnly || HasIBPTrickSpeed())
1663 PlayTsSubtitle(Data, TS_SIZE);
1664 }
1665 }
1666 }
1667 else if (Pid == patPmtParser.Ppid()) {
1668 int w = PlayTsVideo(Data, TS_SIZE);
1669 if (w < 0)
1670 return Played ? Played : w;
1671 if (w == 0)
1672 break;
1673 }
1674 Played += TS_SIZE;
1675 Length -= TS_SIZE;
1676 Data += TS_SIZE;
1677 }
1678 }
1679 return Played;
1680}
1681
1682int cDevice::Priority(bool IgnoreOccupied) const
1683{
1684 int priority = IDLEPRIORITY;
1685 if (IsPrimaryDevice() && !Replaying() && HasProgramme())
1686 priority = TRANSFERPRIORITY; // we use the same value here, no matter whether it's actual Transfer Mode or real live viewing
1687 if (!IgnoreOccupied && time(NULL) <= occupiedTimeout && occupiedPriority > priority)
1688 priority = occupiedPriority - 1; // so timers with occupiedPriority can start
1689 cMutexLock MutexLock(&mutexReceiver);
1690 for (int i = 0; i < MAXRECEIVERS; i++) {
1691 if (receiver[i])
1692 priority = max(receiver[i]->priority, priority);
1693 }
1694 return priority;
1695}
1696
1698{
1699 return true;
1700}
1701
1702bool cDevice::Receiving(bool Dummy) const
1703{
1704 cMutexLock MutexLock(&mutexReceiver);
1705 for (int i = 0; i < MAXRECEIVERS; i++) {
1706 if (receiver[i])
1707 return true;
1708 }
1709 return false;
1710}
1711
1712#define TS_SCRAMBLING_TIMEOUT 3 // seconds to wait until a TS becomes unscrambled
1713#define TS_SCRAMBLING_TIME_OK 3 // seconds before a Channel/CAM combination is marked as known to decrypt
1714#define EIT_INJECTION_TIME 10 // seconds for which to inject EIT event
1715
1717{
1718 if (Running() && OpenDvr()) {
1719 while (Running()) {
1720 // Read data from the DVR device:
1721 uchar *b = NULL;
1722 if (GetTSPacket(b)) {
1723 if (b) {
1724 // Distribute the packet to all attached receivers:
1725 Lock();
1726 cCamSlot *cs = CamSlot();
1727 if (cs)
1728 cs->TsPostProcess(b);
1729 int Pid = TsPid(b);
1730 bool IsScrambled = TsIsScrambled(b);
1731 for (int i = 0; i < MAXRECEIVERS; i++) {
1732 cMutexLock MutexLock(&mutexReceiver);
1733 cReceiver *Receiver = receiver[i];
1734 if (Receiver && Receiver->WantsPid(Pid)) {
1735 Receiver->Receive(b, TS_SIZE);
1736 // Check whether the TS packet is scrambled:
1737 if (Receiver->startScrambleDetection) {
1738 if (cs) {
1739 int CamSlotNumber = cs->MasterSlotNumber();
1740 if (Receiver->lastScrambledPacket < Receiver->startScrambleDetection)
1741 Receiver->lastScrambledPacket = Receiver->startScrambleDetection;
1742 time_t Now = time(NULL);
1743 if (IsScrambled) {
1744 Receiver->lastScrambledPacket = Now;
1745 if (Now - Receiver->startScrambleDetection > Receiver->scramblingTimeout) {
1746 if (!cs->IsActivating() || Receiver->Priority() >= LIVEPRIORITY) {
1747 if (Receiver->ChannelID().Valid()) {
1748 dsyslog("CAM %d: won't decrypt channel %s, detaching receiver", CamSlotNumber, *Receiver->ChannelID().ToString());
1749 ChannelCamRelations.SetChecked(Receiver->ChannelID(), CamSlotNumber);
1750 }
1751 Detach(Receiver);
1752 }
1753 }
1754 }
1755 else if (Now - Receiver->lastScrambledPacket > TS_SCRAMBLING_TIME_OK) {
1756 if (Receiver->ChannelID().Valid()) {
1757 dsyslog("CAM %d: decrypts channel %s", CamSlotNumber, *Receiver->ChannelID().ToString());
1758 ChannelCamRelations.SetDecrypt(Receiver->ChannelID(), CamSlotNumber);
1759 }
1760 Receiver->startScrambleDetection = 0;
1761 }
1762 }
1763 }
1764 // Inject EIT event to avoid the CAMs parental rating prompt:
1765 if (Receiver->startEitInjection) {
1766 time_t Now = time(NULL);
1767 if (cCamSlot *cs = CamSlot()) {
1768 if (Now != Receiver->lastEitInjection) { // once per second
1769 cs->InjectEit(Receiver->ChannelID().Sid());
1770 Receiver->lastEitInjection = Now;
1771 }
1772 }
1773 if (Now - Receiver->startEitInjection > EIT_INJECTION_TIME)
1774 Receiver->startEitInjection = 0;
1775 }
1776 }
1777 }
1778 Unlock();
1779 }
1780 }
1781 else
1782 break;
1783 }
1784 CloseDvr();
1785 }
1786}
1787
1789{
1790 return false;
1791}
1792
1794{
1795}
1796
1798{
1799 return false;
1800}
1801
1803{
1804 if (!Receiver)
1805 return false;
1806 if (Receiver->device == this)
1807 return true;
1808// activate the following line if you need it - actually the driver should be fixed!
1809//#define WAIT_FOR_TUNER_LOCK
1810#ifdef WAIT_FOR_TUNER_LOCK
1811#define TUNER_LOCK_TIMEOUT 5000 // ms
1812 if (!HasLock(TUNER_LOCK_TIMEOUT)) {
1813 esyslog("ERROR: device %d has no lock, can't attach receiver!", DeviceNumber() + 1);
1814 return false;
1815 }
1816#endif
1817 cMutexLock MutexLock(&mutexReceiver);
1818 for (int i = 0; i < MAXRECEIVERS; i++) {
1819 if (!receiver[i]) {
1820 for (int n = 0; n < Receiver->numPids; n++) {
1821 if (!AddPid(Receiver->pids[n])) {
1822 for ( ; n-- > 0; )
1823 DelPid(Receiver->pids[n]);
1824 return false;
1825 }
1826 }
1827 Receiver->Activate(true);
1828 Receiver->device = this;
1829 receiver[i] = Receiver;
1830 if (camSlot && Receiver->priority > MINPRIORITY) { // priority check to avoid an infinite loop with the CAM slot's caPidReceiver
1832 if (camSlot->WantsTsData()) {
1833 Receiver->lastEitInjection = 0;
1834 Receiver->startEitInjection = time(NULL);
1835 }
1836 if (CamSlots.NumReadyMasterSlots() > 1) { // don't try different CAMs if there is only one
1837 Receiver->startScrambleDetection = time(NULL);
1839 bool KnownToDecrypt = ChannelCamRelations.CamDecrypt(Receiver->ChannelID(), camSlot->MasterSlotNumber());
1840 if (KnownToDecrypt)
1841 Receiver->scramblingTimeout *= 9; // give it time to receive ECM/EMM (must be less than MAXBROKENTIMEOUT in recorder.c!)
1842 if (Receiver->ChannelID().Valid())
1843 dsyslog("CAM %d: %sknown to decrypt channel %s (scramblingTimeout = %ds)", camSlot->MasterSlotNumber(), KnownToDecrypt ? "" : "not ", *Receiver->ChannelID().ToString(), Receiver->scramblingTimeout);
1844 }
1845 }
1846 if (patFilter && Receiver->ChannelID().Valid())
1847 patFilter->Request(Receiver->ChannelID().Sid());
1848 Start();
1849 return true;
1850 }
1851 }
1852 esyslog("ERROR: no free receiver slot!");
1853 return false;
1854}
1855
1856void cDevice::Detach(cReceiver *Receiver, bool ReleaseCam)
1857{
1858 if (!Receiver || Receiver->device != this)
1859 return;
1860 bool receiversLeft = false;
1862 for (int i = 0; i < MAXRECEIVERS; i++) {
1863 if (receiver[i] == Receiver)
1864 receiver[i] = NULL;
1865 else if (receiver[i])
1866 receiversLeft = true;
1867 }
1868 if (patFilter && Receiver->ChannelID().Valid())
1869 patFilter->Release(Receiver->ChannelID().Sid());
1871 Receiver->device = NULL;
1872 Receiver->Activate(false);
1873 for (int n = 0; n < Receiver->numPids; n++)
1874 DelPid(Receiver->pids[n]);
1875 if (camSlot) {
1876 if (Receiver->priority > MINPRIORITY) { // priority check to avoid an infinite loop with the CAM slot's caPidReceiver
1878 if (ReleaseCam)
1880 }
1881 }
1882 if (!receiversLeft)
1883 Cancel(-1);
1884}
1885
1887{
1888 if (Pid) {
1889 cMutexLock MutexLock(&mutexReceiver);
1890 for (int i = 0; i < MAXRECEIVERS; i++) {
1891 cReceiver *Receiver = receiver[i];
1892 if (Receiver && Receiver->WantsPid(Pid))
1893 Detach(Receiver, false);
1894 }
1896 }
1897}
1898
1900{
1901 cMutexLock MutexLock(&mutexReceiver);
1902 for (int i = 0; i < MAXRECEIVERS; i++)
1903 Detach(receiver[i], false);
1905}
1906
1907// --- cTSBuffer -------------------------------------------------------------
1908
1909cTSBuffer::cTSBuffer(int File, int Size, int DeviceNumber)
1910{
1911 SetDescription("device %d TS buffer", DeviceNumber);
1912 f = File;
1913 deviceNumber = DeviceNumber;
1914 delivered = 0;
1915 ringBuffer = new cRingBufferLinear(Size, TS_SIZE, true, "TS");
1916 ringBuffer->SetTimeouts(100, 100);
1918 Start();
1919}
1920
1922{
1923 Cancel(3);
1924 delete ringBuffer;
1925}
1926
1928{
1929 if (ringBuffer) {
1930 bool firstRead = true;
1931 cPoller Poller(f);
1932 while (Running()) {
1933 if (firstRead || Poller.Poll(100)) {
1934 firstRead = false;
1935 int r = ringBuffer->Read(f);
1936 if (r < 0 && FATALERRNO) {
1937 if (errno == EOVERFLOW)
1938 esyslog("ERROR: driver buffer overflow on device %d", deviceNumber);
1939 else {
1940 LOG_ERROR;
1941 break;
1942 }
1943 }
1944 cCondWait::SleepMs(10); // avoids small chunks of data, which cause high CPU usage, esp. on ARM CPUs
1945 }
1946 }
1947 }
1948}
1949
1950uchar *cTSBuffer::Get(int *Available, bool CheckAvailable)
1951{
1952 int Count = 0;
1953 if (delivered) {
1955 delivered = 0;
1956 }
1957 if (CheckAvailable && ringBuffer->Available() < TS_SIZE)
1958 return NULL;
1959 uchar *p = ringBuffer->Get(Count);
1960 if (p && Count >= TS_SIZE) {
1961 if (*p != TS_SYNC_BYTE) {
1962 for (int i = 1; i < Count; i++) {
1963 if (p[i] == TS_SYNC_BYTE) {
1964 Count = i;
1965 break;
1966 }
1967 }
1968 ringBuffer->Del(Count);
1969 esyslog("ERROR: skipped %d bytes to sync on TS packet on device %d", Count, deviceNumber);
1970 return NULL;
1971 }
1973 if (Available)
1974 *Available = Count;
1975 return p;
1976 }
1977 return NULL;
1978}
1979
1980void cTSBuffer::Skip(int Count)
1981{
1982 delivered = Count;
1983}
cAudios Audios
Definition audio.c:27
#define CA_ENCRYPTED_MIN
Definition channels.h:44
#define MAXDPIDS
Definition channels.h:32
#define MAXAPIDS
Definition channels.h:31
#define MAXSPIDS
Definition channels.h:33
#define CA_DVB_MAX
Definition channels.h:41
#define LOCK_CHANNELS_READ
Definition channels.h:270
cChannelCamRelations ChannelCamRelations
Definition ci.c:2947
cCamSlots CamSlots
Definition ci.c:2838
@ msReady
Definition ci.h:170
void PlayAudio(const uchar *Data, int Length, uchar Id)
Definition audio.c:29
void PlayTsAudio(const uchar *Data, int Length)
Definition audio.c:35
void ClearAudio(void)
Definition audio.c:47
void MuteAudio(bool On)
Definition audio.c:41
Definition ci.h:232
bool MtdActive(void)
Returns true if MTD is currently active.
Definition ci.h:288
virtual bool IsDecrypting(void)
Returns true if the CAM in this slot is currently used for decrypting.
Definition ci.c:2795
virtual void InjectEit(int Sid)
Injects a generated EIT with a "present event" for the given Sid into the TS data stream sent to the ...
Definition ci.c:2830
int Priority(void)
Returns the priority of the device this slot is currently assigned to, or IDLEPRIORITY if it is not a...
Definition ci.c:2656
cCamSlot * MasterSlot(void)
Returns this CAM slot's master slot, or a pointer to itself if it is a master slot.
Definition ci.h:309
int MasterSlotNumber(void)
Returns the number of this CAM's master slot within the whole system.
Definition ci.h:347
virtual eModuleStatus ModuleStatus(void)
Returns the status of the CAM in this slot.
Definition ci.c:2431
virtual void AddChannel(const cChannel *Channel)
Adds all PIDs of the given Channel to the current list of PIDs.
Definition ci.c:2720
bool WantsTsData(void) const
Returns true if this CAM slot wants to receive the TS data through its Decrypt() function.
Definition ci.h:338
virtual bool Assign(cDevice *Device, bool Query=false)
Assigns this CAM slot to the given Device, if this is possible.
Definition ci.c:2221
cDevice * Device(void)
Returns the device this CAM slot is currently assigned to.
Definition ci.h:332
virtual void SetPid(int Pid, bool Active)
Sets the given Pid (which has previously been added through a call to AddPid()) to Active.
Definition ci.c:2697
virtual void StartDecrypting(void)
Sends all CA_PMT entries to the CAM that have been modified since the last call to this function.
Definition ci.c:2776
virtual bool IsActivating(void)
Returns true if this CAM slot is currently activating a smart card.
Definition ci.c:2424
virtual bool TsPostProcess(uchar *Data)
If there is a cCiSession that needs to do additional processing on TS packets (after the CAM has done...
Definition ci.c:2820
cCamSlot * MtdSpawn(void)
If this CAM slot can do MTD ("Multi Transponder Decryption"), a call to this function returns a cMtdC...
Definition ci.c:2213
virtual bool ProvidesCa(const int *CaSystemIds)
Returns true if the CAM in this slot provides one of the given CaSystemIds.
Definition ci.c:2664
int NumReadyMasterSlots(void)
Returns the number of master CAM slots in the system that are ready to decrypt.
Definition ci.c:2840
void SetChecked(tChannelID ChannelID, int CamSlotNumber)
Definition ci.c:3011
bool CamDecrypt(tChannelID ChannelID, int CamSlotNumber)
Definition ci.c:3004
bool CamChecked(tChannelID ChannelID, int CamSlotNumber)
Definition ci.c:2997
void SetDecrypt(tChannelID ChannelID, int CamSlotNumber)
Definition ci.c:3019
const char * Slang(int i) const
Definition channels.h:165
int Number(void) const
Definition channels.h:179
const char * Name(void) const
Definition channels.c:121
int Dpid(int i) const
Definition channels.h:161
int Apid(int i) const
Definition channels.h:160
tChannelID GetChannelID(void) const
Definition channels.h:191
int Ca(int Index=0) const
Definition channels.h:173
const char * Dlang(int i) const
Definition channels.h:164
const int * Caids(void) const
Definition channels.h:172
int Spid(int i) const
Definition channels.h:162
const char * Alang(int i) const
Definition channels.h:163
int Sid(void) const
Definition channels.h:176
static void SleepMs(int TimeoutMs)
Creates a cCondWait object and uses it to sleep for TimeoutMs milliseconds, immediately giving up the...
Definition thread.c:72
static void Shutdown(void)
Definition player.c:108
static void Launch(cControl *Control)
Definition player.c:87
virtual bool DeviceProvidesEIT(const cDevice *Device) const
Returns true if the given Device can provide EIT data.
Definition device.c:61
cDeviceHook(void)
Creates a new device hook object.
Definition device.c:51
virtual bool DeviceProvidesTransponder(const cDevice *Device, const cChannel *Channel) const
Returns true if the given Device can provide the given Channel's transponder.
Definition device.c:56
cCamSlot * camSlot
Definition device.h:477
cPlayer * player
Definition device.h:649
static int NextCardIndex(int n=0)
Calculates the next card index.
Definition device.c:155
int Occupied(int Priority=MINPRIORITY) const
Returns the number of seconds this device is still occupied for with a priority >= Priority.
Definition device.c:970
virtual cString DeviceName(void) const
Returns a string identifying the name of this device.
Definition device.c:181
static cList< cDeviceHook > deviceHooks
Definition device.h:246
bool Replaying(void) const
Returns true if we are currently replaying.
Definition device.c:1360
virtual bool Poll(cPoller &Poller, int TimeoutMs=0)
Returns true if the device itself or any of the file handles in Poller is ready for further action.
Definition device.c:1417
int currentAudioTrackMissingCount
Definition device.h:557
void StopSectionHandler(void)
A device that has called StartSectionHandler() must call this function (typically in its destructor) ...
Definition device.c:681
int Priority(bool IgnoreOccupied=false) const
Returns the priority of the current receiving session (-MAXPRIORITY..MAXPRIORITY),...
Definition device.c:1682
virtual bool SignalStats(int &Valid, double *Strength=NULL, double *Cnr=NULL, double *BerPre=NULL, double *BerPost=NULL, double *Per=NULL, int *Status=NULL) const
Returns statistics about the currently received signal (if available).
Definition device.c:785
virtual void SetSubtitleTrackDevice(eTrackType Type)
Sets the current subtitle track to the given value.
Definition device.c:1030
virtual int GetAudioChannelDevice(void)
Gets the current audio channel, which is stereo (0), mono left (1) or mono right (2).
Definition device.c:1009
virtual int PlayVideo(const uchar *Data, int Length)
Plays the given data block as video.
Definition device.c:1427
cSectionHandler * sectionHandler
Definition device.h:439
bool SetCurrentSubtitleTrack(eTrackType Type, bool Manual=false)
Sets the current subtitle track to the given Type.
Definition device.c:1173
virtual bool HasInternalCam(void)
Returns true if this device handles encrypted channels itself without VDR assistance.
Definition device.h:483
virtual uchar * GrabImage(int &Size, bool Jpeg=true, int Quality=-1, int SizeX=-1, int SizeY=-1)
Grabs the currently visible screen image.
Definition device.c:474
virtual void GetVideoSize(int &Width, int &Height, double &VideoAspect)
Returns the Width, Height and VideoAspect ratio of the currently displayed video material.
Definition device.c:533
bool GrabImageFile(const char *FileName, bool Jpeg=true, int Quality=-1, int SizeX=-1, int SizeY=-1)
Calls GrabImage() and stores the resulting image in a file with the given name.
Definition device.c:479
eSetChannelResult SetChannel(const cChannel *Channel, bool LiveView)
Sets the device to the given channel (general setup).
Definition device.c:869
bool mute
Definition device.h:617
virtual bool HasLock(int TimeoutMs=0) const
Returns true if the device has a lock on the requested transponder.
Definition device.c:998
void StartSectionHandler(void)
A derived device that provides section data must call this function (typically in its constructor) to...
Definition device.c:670
@ ptTeletext
Definition device.h:408
@ ptPcr
Definition device.h:408
@ ptOther
Definition device.h:408
@ ptDolby
Definition device.h:408
@ ptAudio
Definition device.h:408
@ ptVideo
Definition device.h:408
cMutex mutexCurrentAudioTrack
Definition device.h:555
virtual const cPositioner * Positioner(void) const
Returns a pointer to the positioner (if any) this device has used to move the satellite dish to the r...
Definition device.c:780
virtual int NumProvidedSystems(void) const
Returns the number of individual "delivery systems" this device provides.
Definition device.c:775
int NumSubtitleTracks(void) const
Returns the number of subtitle tracks that are currently available.
Definition device.c:1150
bool keepTracks
Definition device.h:559
virtual ~cDevice()
Definition device.c:122
virtual int PlayPes(const uchar *Data, int Length, bool VideoOnly=false)
Plays all valid PES packets in Data with the given Length.
Definition device.c:1542
cMutex mutexReceiver
Definition device.h:843
virtual bool ProvidesSource(int Source) const
Returns true if this device can provide the given source.
Definition device.c:724
void ReleaseCamSlot(void)
Releases the CAM slot if it is currently not used.
Definition device.c:448
static int useDevice
Definition device.h:125
cDvbSubtitleConverter * dvbSubtitleConverter
Definition device.h:255
bool HasPid(int Pid) const
Returns true if this device is currently receiving the given PID.
Definition device.c:550
virtual void SetAudioTrackDevice(eTrackType Type)
Sets the current audio track to the given value.
Definition device.c:1026
virtual bool SetPid(cPidHandle *Handle, int Type, bool On)
Does the actual PID setting on this device.
Definition device.c:656
static int nextCardIndex
Definition device.h:188
cTsToPes tsToPesAudio
Definition device.h:652
cNitFilter * nitFilter
Definition device.h:443
bool autoSelectPreferredSubtitleLanguage
Definition device.h:558
static bool WaitForAllDevicesReady(int Timeout=0)
Waits until all devices have become ready, or the given Timeout (seconds) has expired.
Definition device.c:133
void SetCamSlot(cCamSlot *CamSlot)
Sets the given CamSlot to be used with this device.
Definition device.c:459
static cDevice * ActualDevice(void)
Returns the actual receiving device in case of Transfer Mode, or the primary device otherwise.
Definition device.c:222
static cDevice * PrimaryDevice(void)
Returns the primary device.
Definition device.h:148
static void SetUseDevice(int n)
Sets the 'useDevice' flag of the given device.
Definition device.c:149
virtual bool MaySwitchTransponder(const cChannel *Channel) const
Returns true if it is ok to switch to the Channel's transponder on this device, without disturbing an...
Definition device.c:810
eTrackType currentSubtitleTrack
Definition device.h:554
eTrackType GetCurrentSubtitleTrack(void) const
Definition device.h:595
static cDevice * GetDevice(int Index)
Gets the device with the given Index.
Definition device.c:230
static void Shutdown(void)
Closes down all devices.
Definition device.c:465
cPatFilter * patFilter
Definition device.h:441
eTrackType GetCurrentAudioTrack(void) const
Definition device.h:591
cDevice(void)
Definition device.c:79
bool DeviceHooksProvidesEIT(void) const
Definition device.c:740
bool SwitchChannel(const cChannel *Channel, bool LiveView)
Switches the device to the given Channel, initiating transfer mode if necessary.
Definition device.c:815
virtual int PlayTsVideo(const uchar *Data, int Length)
Plays the given data block as video.
Definition device.c:1571
int DeviceNumber(void) const
Returns the number of this device (0 ... numDevices - 1).
Definition device.c:167
cEitFilter * eitFilter
Definition device.h:440
virtual bool ProvidesEIT(void) const
Returns true if this device provides EIT data and thus wants to be tuned to the channels it can recei...
Definition device.c:770
virtual void SetAudioChannelDevice(int AudioChannel)
Sets the audio channel to stereo (0), mono left (1) or mono right (2).
Definition device.c:1014
cReceiver * receiver[MAXRECEIVERS]
Definition device.h:844
void DelPid(int Pid, ePidType PidType=ptOther)
Deletes a PID from the set of PIDs this device shall receive.
Definition device.c:625
bool AttachReceiver(cReceiver *Receiver)
Attaches the given receiver to this device.
Definition device.c:1802
static int CurrentChannel(void)
Returns the number of the current channel on the primary device.
Definition device.h:363
bool IsPrimaryDevice(bool CheckDecoder=true) const
Definition device.h:223
virtual bool AvoidRecording(void) const
Returns true if this device should only be used for recording if no other device is available.
Definition device.h:239
static cDevice * primaryDevice
Definition device.h:127
static bool SetPrimaryDevice(int n)
Sets the primary device to 'n'.
Definition device.c:194
bool Receiving(bool Dummy=false) const
Returns true if we are currently receiving. The parameter has no meaning (for backwards compatibility...
Definition device.c:1702
bool Transferring(void) const
Returns true if we are currently in Transfer Mode.
Definition device.c:1365
virtual int PlayTsAudio(const uchar *Data, int Length)
Plays the given data block as audio.
Definition device.c:1590
time_t occupiedTimeout
Definition device.h:266
void StopReplay(void)
Stops the current replay session (if any).
Definition device.c:1408
virtual void MakePrimaryDevice(bool On)
Informs a device that it will be the primary device.
Definition device.c:186
virtual bool ProvidesTransponderExclusively(const cChannel *Channel) const
Returns true if this is the only device that is able to provide the given channel's transponder.
Definition device.c:756
void DetachAll(int Pid)
Detaches all receivers from this device for this pid.
Definition device.c:1886
virtual bool ProvidesChannel(const cChannel *Channel, int Priority=IDLEPRIORITY, bool *NeedsDetachReceivers=NULL) const
Returns true if this device can provide the given channel.
Definition device.c:765
int cardIndex
Definition device.h:189
virtual int SignalQuality(void) const
Returns the "quality" of the currently received signal.
Definition device.c:795
virtual int SignalStrength(void) const
Returns the "strength" of the currently received signal.
Definition device.c:790
virtual void Play(void)
Sets the device into play mode (after a previous trick mode).
Definition device.c:1282
int GetAudioChannel(void)
Gets the current audio channel, which is stereo (0), mono left (1) or mono right (2).
Definition device.c:1051
cPidHandle pidHandles[MAXPIDHANDLES]
Definition device.h:417
void EnsureAudioTrack(bool Force=false)
Makes sure an audio track is selected that is actually available.
Definition device.c:1201
void Detach(cFilter *Filter)
Detaches the given filter from this device.
Definition device.c:718
cTsToPes tsToPesVideo
Definition device.h:651
eTrackType currentAudioTrack
Definition device.h:553
virtual bool SetPlayMode(ePlayMode PlayMode)
Sets the device into the given play mode.
Definition device.c:1261
virtual bool OpenDvr(void)
Opens the DVR of this device and prepares it to deliver a Transport Stream for use in a cReceiver.
Definition device.c:1788
const tTrackId * GetTrack(eTrackType Type)
Returns a pointer to the given track id, or NULL if Type is not less than ttMaxTrackTypes.
Definition device.c:1130
void SetVolume(int Volume, bool Absolute=false)
Sets the volume to the given value, either absolutely or relative to the current volume.
Definition device.c:1063
virtual void TrickSpeed(int Speed, bool Forward)
Sets the device into a mode where replay is done slower.
Definition device.c:1271
cLiveSubtitle * liveSubtitle
Definition device.h:254
virtual void Mute(void)
Turns off audio while replaying.
Definition device.c:1296
virtual bool HasCi(void)
Returns true if this device has a Common Interface.
Definition device.c:454
virtual cString DeviceType(void) const
Returns a string identifying the type of this device (like "DVB-S").
Definition device.c:176
virtual const cChannel * GetCurrentlyTunedTransponder(void) const
Returns a pointer to the currently tuned transponder.
Definition device.c:800
virtual void Freeze(void)
Puts the device into "freeze frame" mode.
Definition device.c:1289
void SetAudioChannel(int AudioChannel)
Sets the audio channel to stereo (0), mono left (1) or mono right (2).
Definition device.c:1057
static int NumDevices(void)
Returns the total number of devices.
Definition device.h:129
virtual int64_t GetSTC(void)
Gets the current System Time Counter, which can be used to synchronize audio, video and subtitles.
Definition device.c:1266
time_t occupiedFrom
Definition device.h:265
virtual void SetVideoDisplayFormat(eVideoDisplayFormat VideoDisplayFormat)
Sets the video display format to the given one (only useful if this device has an MPEG decoder).
Definition device.c:506
bool isPlayingVideo
Definition device.h:654
virtual bool Flush(int TimeoutMs=0)
Returns true if the device's output buffers are empty, i.
Definition device.c:1422
virtual bool HasDecoder(void) const
Tells whether this device has an MPEG decoder.
Definition device.c:212
virtual int PlayTsSubtitle(const uchar *Data, int Length)
Plays the given data block as a subtitle.
Definition device.c:1606
virtual void SetVideoFormat(bool VideoFormat16_9)
Sets the output video format to either 16:9 or 4:3 (only useful if this device has an MPEG decoder).
Definition device.c:529
virtual void CloseDvr(void)
Shuts down the DVR.
Definition device.c:1793
virtual void CloseFilter(int Handle)
Closes a file handle that has previously been opened by OpenFilter().
Definition device.c:707
virtual bool SetChannelDevice(const cChannel *Channel, bool LiveView)
Sets the device to the given channel (actual physical setup).
Definition device.c:993
bool AttachPlayer(cPlayer *Player)
Attaches the given player to this device.
Definition device.c:1370
void ClrAvailableTracks(bool DescriptionsOnly=false, bool IdsOnly=false)
Clears the list of currently available tracks.
Definition device.c:1078
virtual bool HasProgramme(void) const
Returns true if the device is currently showing any programme to the user, either through replaying o...
Definition device.c:1003
friend class cLiveSubtitle
Definition device.h:120
int volume
Definition device.h:618
void EnsureSubtitleTrack(void)
Makes sure one of the preferred language subtitle tracks is selected.
Definition device.c:1234
virtual void DetachAllReceivers(void)
Detaches all receivers from this device.
Definition device.c:1899
virtual bool IsTunedToTransponder(const cChannel *Channel) const
Returns true if this device is currently tuned to the given Channel's transponder.
Definition device.c:805
virtual bool CanReplay(void) const
Returns true if this device can currently start a replay session.
Definition device.c:1256
int NumTracks(eTrackType FirstTrack, eTrackType LastTrack) const
Returns the number of tracks in the given range that are currently available.
Definition device.c:1135
void AttachFilter(cFilter *Filter)
Attaches the given filter to this device.
Definition device.c:712
virtual cSpuDecoder * GetSpuDecoder(void)
Returns a pointer to the device's SPU decoder (or NULL, if this device doesn't have an SPU decoder).
Definition device.c:217
virtual bool HasIBPTrickSpeed(void)
Returns true if this device can handle all frames in 'fast forward' trick speeds.
Definition device.h:759
virtual bool Ready(void)
Returns true if this device is ready.
Definition device.c:1697
cMutex mutexChannel
Definition device.h:264
static cDevice * GetDeviceForTransponder(const cChannel *Channel, int Priority)
Returns a device that is not currently "occupied" and can be tuned to the transponder of the given Ch...
Definition device.c:427
virtual void GetOsdSize(int &Width, int &Height, double &PixelAspect)
Returns the Width, Height and PixelAspect ratio the OSD should use to best fit the resolution of the ...
Definition device.c:540
tTrackId availableTracks[ttMaxTrackTypes]
Definition device.h:552
virtual bool GetTSPacket(uchar *&Data)
Gets exactly one TS packet from the DVR of this device and returns a pointer to it in Data.
Definition device.c:1797
virtual void Clear(void)
Clears all video and audio data from the device.
Definition device.c:1275
cTsToPes tsToPesSubtitle
Definition device.h:653
int CardIndex(void) const
Returns the card index of this device (0 ... MAXDEVICES - 1).
Definition device.h:224
cCamSlot * CamSlot(void) const
Returns the CAM slot that is currently used with this device, or NULL if no CAM slot is in use.
Definition device.h:491
bool SetAvailableTrack(eTrackType Type, int Index, uint16_t Id, const char *Language=NULL, const char *Description=NULL)
Sets the track of the given Type and Index to the given values.
Definition device.c:1101
void SetOccupied(int Seconds, int Priority=MINPRIORITY, time_t From=0)
Sets the occupied timeout for this device to the given number of Seconds, This can be used to tune a ...
Definition device.c:978
static int numDevices
Definition device.h:124
int NumAudioTracks(void) const
Returns the number of audio tracks that are currently available.
Definition device.c:1145
virtual int PlayPesPacket(const uchar *Data, int Length, bool VideoOnly=false)
Plays the single PES packet in Data with the given Length.
Definition device.c:1444
bool ToggleMute(void)
Turns the volume off or on and returns the new mute state.
Definition device.c:1034
void DelLivePids(void)
Deletes the live viewing PIDs.
Definition device.c:661
static int currentChannel
Definition device.h:269
virtual int PlayTs(const uchar *Data, int Length, bool VideoOnly=false)
Plays the given TS packet.
Definition device.c:1619
cPatPmtParser patPmtParser
Definition device.h:650
bool AddPid(int Pid, ePidType PidType=ptOther, int StreamType=0)
Adds a PID to the set of PIDs this device shall receive.
Definition device.c:560
cMutex mutexCurrentSubtitleTrack
Definition device.h:556
int pre_1_3_19_PrivateStream
Definition device.h:560
bool DeviceHooksProvidesTransponder(const cChannel *Channel) const
Definition device.c:729
virtual int ReadFilter(int Handle, void *Buffer, size_t Length)
Reads data from a handle for the given filter.
Definition device.c:702
virtual int OpenFilter(u_short Pid, u_char Tid, u_char Mask)
Opens a file handle for the given filter data.
Definition device.c:697
cSdtFilter * sdtFilter
Definition device.h:442
static cDevice * device[MAXDEVICES]
Definition device.h:75
int occupiedPriority
Definition device.h:267
void ForceTransferMode(void)
Forces the device into transfermode for the current channel.
Definition device.c:961
virtual int PlayAudio(const uchar *Data, int Length, uchar Id)
Plays the given data block as audio.
Definition device.c:1432
cMutex mutexPids
Definition device.h:405
bool SetCurrentAudioTrack(eTrackType Type)
Sets the current audio track to the given Type.
Definition device.c:1155
virtual void Action(void)
A derived cThread class must implement the code it wants to execute as a separate thread in this func...
Definition device.c:1716
virtual bool ProvidesTransponder(const cChannel *Channel) const
Returns true if this device can provide the transponder of the given Channel (which implies that it c...
Definition device.c:751
virtual void SetDigitalAudioDevice(bool On)
Tells the output device that the current audio track is Dolby Digital.
Definition device.c:1022
virtual void StillPicture(const uchar *Data, int Length)
Displays the given I-frame as a still picture.
Definition device.c:1301
virtual int PlaySubtitle(const uchar *Data, int Length)
Plays the given data block as a subtitle.
Definition device.c:1437
virtual void SetVolumeDevice(int Volume)
Sets the audio volume on this device (Volume = 0...255).
Definition device.c:1018
int Convert(const uchar *Data, int Length)
void Freeze(bool Status)
Definition dvbsubtitle.h:53
int ConvertFragments(const uchar *Data, int Length)
virtual void Clear(void)
Definition tools.c:2291
int Count(void) const
Definition tools.h:640
void Add(cListObject *Object, cListObject *After=NULL)
Definition tools.c:2214
int Index(void) const
Definition tools.c:2134
Definition tools.h:644
const T * First(void) const
Returns the first element in this list, or NULL if the list is empty.
Definition tools.h:656
const T * Next(const T *Object) const
< Returns the element immediately before Object in this list, or NULL if Object is the first element ...
Definition tools.h:663
const T * Get(int Index) const
Returns the list element at the given Index, or NULL if no such element exists.
Definition tools.h:653
virtual ~cLiveSubtitle()
Definition device.c:38
cLiveSubtitle(int SPid)
Definition device.c:33
virtual void Receive(const uchar *Data, int Length)
This function is called from the cDevice we are attached to, and delivers one TS packet from the set ...
Definition device.c:43
void Lock(void)
Definition thread.c:222
void Unlock(void)
Definition thread.c:228
void Request(int Sid)
Definition pat.c:408
void Release(int Sid)
Definition pat.c:431
void Reset(void)
Resets the parser.
Definition remux.c:617
void ParsePat(const uchar *Data, int Length)
Parses the PAT data from the single TS packet in Data.
Definition remux.c:627
void ParsePmt(const uchar *Data, int Length)
Parses the PMT data from the single TS packet in Data.
Definition remux.c:659
bool IsPmtPid(int Pid) const
Returns true if Pid the one of the PMT pids as defined by the current PAT.
Definition remux.h:400
int Ppid(void) const
Returns the PCR pid as defined by the current PMT, or 0 if no PCR pid has been detected,...
Definition remux.h:406
int Vpid(void) const
Returns the video pid as defined by the current PMT, or 0 if no video pid has been detected,...
Definition remux.h:403
virtual void SetAudioTrack(eTrackType Type, const tTrackId *TrackId)
Definition player.h:70
ePlayMode playMode
Definition player.h:20
virtual void Activate(bool On)
Definition player.h:39
virtual void SetSubtitleTrack(eTrackType Type, const tTrackId *TrackId)
Definition player.h:74
cDevice * device
Definition player.h:19
bool Poll(int TimeoutMs=0)
Definition tools.c:1565
A steerable satellite dish generally points to the south on the northern hemisphere,...
Definition positioner.h:31
time_t lastEitInjection
Definition receiver.h:29
int Priority(void)
Definition receiver.h:57
bool WantsPid(int Pid)
Definition receiver.c:114
time_t startEitInjection
Definition receiver.h:28
int pids[MAXRECEIVEPIDS]
Definition receiver.h:23
tChannelID ChannelID(void)
Definition receiver.h:80
void Detach(void)
Definition receiver.c:125
cDevice * device
Definition receiver.h:20
int priority
Definition receiver.h:22
virtual void Receive(const uchar *Data, int Length)=0
This function is called from the cDevice we are attached to, and delivers one TS packet from the set ...
int numPids
Definition receiver.h:24
bool AddPid(int Pid)
Adds the given Pid to the list of PIDs of this receiver.
Definition receiver.c:42
time_t startScrambleDetection
Definition receiver.h:26
time_t lastScrambledPacket
Definition receiver.h:25
int scramblingTimeout
Definition receiver.h:27
virtual void Activate(bool On)
This function is called just before the cReceiver gets attached to (On == true) and right after it ge...
Definition receiver.h:34
void Del(int Count)
Deletes at most Count bytes from the ring buffer.
Definition ringbuffer.c:371
virtual int Available(void)
Definition ringbuffer.c:211
uchar * Get(int &Count)
Gets data from the ring buffer.
Definition ringbuffer.c:346
int Read(int FileHandle, int Max=0)
Reads at most Max bytes from FileHandle and stores them in the ring buffer.
Definition ringbuffer.c:230
void SetTimeouts(int PutTimeout, int GetTimeout)
Definition ringbuffer.c:89
void SetIoThrottle(void)
Definition ringbuffer.c:95
void SetChannel(const cChannel *Channel)
Definition sections.c:140
void SetStatus(bool On)
Definition sections.c:147
void Attach(cFilter *Filter)
Definition sections.c:119
void Detach(cFilter *Filter)
Definition sections.c:130
int VolumeSteps
Definition config.h:368
int VideoDisplayFormat
Definition config.h:325
int CurrentVolume
Definition config.h:367
int SubtitleLanguages[I18N_MAX_LANGUAGES+1]
Definition config.h:294
int DisplaySubtitles
Definition config.h:293
int VolumeLinearize
Definition config.h:369
int AudioLanguages[I18N_MAX_LANGUAGES+1]
Definition config.h:292
int VideoFormat
Definition config.h:326
int PrimaryDVB
Definition config.h:268
int UseDolbyDigital
Definition config.h:328
int CurrentDolby
Definition config.h:370
int QueueMessage(eMessageType Type, const char *s, int Seconds=0, int Timeout=0)
Like Message(), but this function may be called from a background thread.
Definition skins.c:296
@ eSpuPanAndScan
Definition spu.h:21
@ eSpuNormal
Definition spu.h:21
@ eSpuLetterBox
Definition spu.h:21
virtual void setScaleMode(cSpuDecoder::eScaleMode ScaleMode)=0
static void MsgSetVolume(int Volume, bool Absolute)
Definition status.c:62
static void MsgChannelSwitch(const cDevice *Device, int ChannelNumber, bool LiveView)
Definition status.c:38
cTSBuffer(int File, int Size, int DeviceNumber)
Definition device.c:1909
int delivered
Definition device.h:891
virtual void Action(void)
A derived cThread class must implement the code it wants to execute as a separate thread in this func...
Definition device.c:1927
uchar * Get(int *Available=NULL, bool CheckAvailable=false)
Returns a pointer to the first TS packet in the buffer.
Definition device.c:1950
cRingBufferLinear * ringBuffer
Definition device.h:892
void Skip(int Count)
If after a call to Get() more or less than TS_SIZE of the available data has been processed,...
Definition device.c:1980
int deviceNumber
Definition device.h:890
virtual ~cTSBuffer()
Definition device.c:1921
int f
Definition device.h:889
void Unlock(void)
Definition thread.h:95
void bool Start(void)
Sets the description of this thread, which will be used when logging starting or stopping of the thre...
Definition thread.c:304
void SetDescription(const char *Description,...) __attribute__((format(printf
Definition thread.c:267
bool Running(void)
Returns false if a derived cThread object shall leave its Action() function.
Definition thread.h:101
void Lock(void)
Definition thread.h:94
void Cancel(int WaitSeconds=0)
Cancels the thread by first setting 'running' to false, so that the Action() loop can finish in an or...
Definition thread.c:354
char * description
Definition thread.h:87
static cDevice * ReceiverDevice(void)
Definition transfer.h:38
void PutTs(const uchar *Data, int Length)
Puts the payload data of the single TS packet at Data into the converter.
Definition remux.c:1046
void SetRepeatLast(void)
Makes the next call to GetPes() return exactly the same data as the last one (provided there was no c...
Definition remux.c:1123
const uchar * GetPes(int &Length)
Gets a pointer to the complete PES packet, or NULL if the packet is not complete yet.
Definition remux.c:1075
void Reset(void)
Resets the converter.
Definition remux.c:1128
cSetup Setup
Definition config.c:372
#define MINPRIORITY
Definition config.h:44
#define TRANSFERPRIORITY
Definition config.h:46
#define MAXPRIORITY
Definition config.h:43
#define IDLEPRIORITY
Definition config.h:47
#define LIVEPRIORITY
Definition config.h:45
#define EIT_INJECTION_TIME
Definition device.c:1714
static int GetClippedNumProvidedSystems(int AvailableBits, cDevice *Device)
Definition device.c:235
#define PRINTPIDS(s)
Definition device.c:548
#define TS_SCRAMBLING_TIMEOUT
Definition device.c:1712
#define MIN_PRE_1_3_19_PRIVATESTREAM
Definition device.c:69
#define TS_SCRAMBLING_TIME_OK
Definition device.c:1713
#define MAXVOLUME
Definition device.h:32
#define MAXPIDHANDLES
Definition device.h:30
eVideoDisplayFormat
Definition device.h:58
@ vdfLetterBox
Definition device.h:59
@ vdfCenterCutOut
Definition device.h:60
@ vdfPanAndScan
Definition device.h:58
ePlayMode
Definition device.h:39
@ pmNone
Definition device.h:39
#define MAXDEVICES
Definition device.h:29
#define MAXOCCUPIEDTIMEOUT
Definition device.h:34
#define IS_AUDIO_TRACK(t)
Definition device.h:76
eTrackType
Definition device.h:63
@ ttSubtitle
Definition device.h:70
@ ttMaxTrackTypes
Definition device.h:73
@ ttDolbyLast
Definition device.h:69
@ ttAudioLast
Definition device.h:66
@ ttDolby
Definition device.h:67
@ ttAudioFirst
Definition device.h:65
@ ttSubtitleLast
Definition device.h:72
@ ttDolbyFirst
Definition device.h:68
@ ttSubtitleFirst
Definition device.h:71
@ ttAudio
Definition device.h:64
@ ttNone
Definition device.h:63
#define MAXRECEIVERS
Definition device.h:31
#define IS_SUBTITLE_TRACK(t)
Definition device.h:78
#define IS_DOLBY_TRACK(t)
Definition device.h:77
eSetChannelResult
Definition device.h:36
@ scrOk
Definition device.h:36
@ scrNotAvailable
Definition device.h:36
@ scrFailed
Definition device.h:36
@ scrNoTransfer
Definition device.h:36
bool I18nIsPreferredLanguage(int *PreferredLanguages, const char *LanguageCode, int &OldPreference, int *Position)
Checks the given LanguageCode (which may be something like "eng" or "eng+deu") against the PreferredL...
Definition i18n.c:317
#define tr(s)
Definition i18n.h:85
int TsPid(const uchar *p)
Definition remux.h:82
bool TsHasPayload(const uchar *p)
Definition remux.h:62
#define PATPID
Definition remux.h:52
bool TsIsScrambled(const uchar *p)
Definition remux.h:93
#define TS_SIZE
Definition remux.h:34
bool TsPayloadStart(const uchar *p)
Definition remux.h:72
#define TS_SYNC(Data, Length)
Definition remux.h:149
int TsPayloadOffset(const uchar *p)
Definition remux.h:108
#define TS_SYNC_BYTE
Definition remux.h:33
int PesLength(const uchar *p)
Definition remux.h:173
cSkins Skins
Definition skins.c:219
@ mtInfo
Definition skins.h:37
@ mtError
Definition skins.h:37
int Sid(void) const
Definition channels.h:64
bool Valid(void) const
Definition channels.h:58
cString ToString(void) const
Definition channels.c:40
char language[MAXLANGCODE2]
Definition device.h:82
uint16_t id
Definition device.h:81
#define LOCK_THREAD
Definition thread.h:167
char * Utf8Strn0Cpy(char *Dest, const char *Src, int n)
Copies at most n character bytes from Src to Dest, making sure that the resulting copy ends with a co...
Definition tools.c:899
ssize_t safe_read(int filedes, void *buffer, size_t size)
Definition tools.c:53
ssize_t safe_write(int filedes, const void *buffer, size_t size)
Definition tools.c:65
char * strn0cpy(char *dest, const char *src, size_t n)
Definition tools.c:131
#define FATALERRNO
Definition tools.h:52
T constrain(T v, T l, T h)
Definition tools.h:70
#define LOG_ERROR_STR(s)
Definition tools.h:40
unsigned char uchar
Definition tools.h:31
#define dsyslog(a...)
Definition tools.h:37
int sgn(T a)
Definition tools.h:68
void DELETENULL(T *&p)
Definition tools.h:49
T min(T a, T b)
Definition tools.h:63
T max(T a, T b)
Definition tools.h:64
#define esyslog(a...)
Definition tools.h:35
#define LOG_ERROR
Definition tools.h:39
#define isyslog(a...)
Definition tools.h:36