vdr 2.8.4
transfer.c
Go to the documentation of this file.
1/*
2 * transfer.c: Transfer mode
3 *
4 * See the main source file 'vdr.c' for copyright information and
5 * how to reach the author.
6 *
7 * $Id: transfer.c 5.3 2026/10/26 19:25:55 kls Exp $
8 */
9
10#include "transfer.h"
11
12// --- cTransfer -------------------------------------------------------------
13
15
18{
19 activated = false;
23}
24
30
32{
33 cMutexLock MutexLock(&TransferMutex);
34 if (On) {
35 if (cPlayer::IsAttached()) {
37 int Index = 0;
38 while (uchar *pmt = patPmtGenerator.GetPmt(Index))
39 PlayTs(pmt, TS_SIZE);
40 activated = true;
41 }
42 }
43 else {
44 activated = false;
46 }
47}
48
49#define MAXRETRIES 20 // max. number of retries for a single TS packet
50#define RETRYWAIT 5 // time (in ms) between two retries
51#define ERRORDELTA 60 // seconds before reporting lost TS packets again
52
53void cTransfer::Receive(const uchar *Data, int Length)
54{
55 cMutexLock MutexLock(&TransferMutex);
56 if (activated) {
57 // Transfer Mode means "live tv", so there's no point in doing any additional
58 // buffering here. The TS packets *must* get through here! However, every
59 // now and then there may be conditions where the packet just can't be
60 // handled when offered the first time, so that's why we try several times:
61 for (int i = 0; i < MAXRETRIES; i++) {
62 if (PlayTs(Data, Length) > 0)
63 return;
65 }
68 if (time(NULL) - lastErrorReport > ERRORDELTA) {
69 esyslog("ERROR: %d TS packet(s) not accepted in Transfer Mode", numLostPackets);
71 lastErrorReport = time(NULL);
72 }
73 }
74}
75
76// --- cTransferControl ------------------------------------------------------
77
78std::atomic<cDevice *> cTransferControl::receiverDevice(NULL);
79
88
static void SleepMs(int TimeoutMs)
Creates a cCondWait object and uses it to sleep for TimeoutMs milliseconds, immediately giving up the...
Definition thread.c:73
void SetPlayer(cPlayer *Player)
Definition player.h:115
cControl(cPlayer *Player, bool Hidden=false)
Definition player.c:45
bool AttachReceiver(cReceiver *Receiver)
Attaches the given receiver to this device.
Definition device.c:1939
uchar * GetPmt(int &Index)
Returns a pointer to the Index'th TS packet of the PMT section.
Definition remux.c:599
void SetChannel(const cChannel *Channel)
Sets the Channel for which the PAT/PMT shall be generated.
Definition remux.c:587
uchar * GetPat(void)
Returns a pointer to the PAT section, which consists of exactly one TS packet.
Definition remux.c:593
void Detach(void)
Definition player.c:34
int PlayTs(const uchar *Data, int Length, bool VideoOnly=false)
Definition player.h:50
bool IsAttached(void)
Definition player.h:57
void DeviceClear(void)
Definition player.h:33
void Detach(void)
Definition receiver.c:125
cReceiver(const cChannel *Channel=NULL, int Priority=MINPRIORITY)
Creates a new receiver for the given Channel with the given Priority.
Definition receiver.c:14
static cDevice * ReceiverDevice(void)
Definition transfer.h:39
cTransfer * transfer
Definition transfer.h:33
cTransferControl(cDevice *ReceiverDevice, const cChannel *Channel)
Definition transfer.c:80
static std::atomic< cDevice * > receiverDevice
Definition transfer.h:34
time_t lastErrorReport
Definition transfer.h:20
virtual void Receive(const uchar *Data, int Length) override
This function is called from the cDevice we are attached to, and delivers one TS packet from the set ...
Definition transfer.c:53
cTransfer(const cChannel *Channel)
Definition transfer.c:16
bool activated
Definition transfer.h:19
virtual ~cTransfer() override
Definition transfer.c:25
virtual void Activate(bool On) override
This function is called just before the cReceiver gets attached to (On == true) and right after it ge...
Definition transfer.c:31
int numLostPackets
Definition transfer.h:21
cPatPmtGenerator patPmtGenerator
Definition transfer.h:22
#define TRANSFERPRIORITY
Definition config.h:44
#define TS_SIZE
Definition remux.h:34
unsigned char uchar
Definition tools.h:31
#define esyslog(a...)
Definition tools.h:35
#define MAXRETRIES
Definition transfer.c:49
#define RETRYWAIT
Definition transfer.c:50
static cMutex TransferMutex
Definition transfer.c:14
#define ERRORDELTA
Definition transfer.c:51