vdr  2.6.9
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.1 2022/12/05 14:45:51 kls Exp $
8  */
9 
10 #include "transfer.h"
11 
12 // --- cTransfer -------------------------------------------------------------
13 
15 :cReceiver(Channel, TRANSFERPRIORITY)
16 {
17  lastErrorReport = 0;
18  numLostPackets = 0;
19  patPmtGenerator.SetChannel(Channel);
20 }
21 
23 {
26 }
27 
28 void cTransfer::Activate(bool On)
29 {
30  if (On) {
32  int Index = 0;
33  while (uchar *pmt = patPmtGenerator.GetPmt(Index))
34  PlayTs(pmt, TS_SIZE);
35  }
36  else
38 }
39 
40 #define MAXRETRIES 20 // max. number of retries for a single TS packet
41 #define RETRYWAIT 5 // time (in ms) between two retries
42 #define ERRORDELTA 60 // seconds before reporting lost TS packets again
43 
44 void cTransfer::Receive(const uchar *Data, int Length)
45 {
46  if (cPlayer::IsAttached()) {
47  // Transfer Mode means "live tv", so there's no point in doing any additional
48  // buffering here. The TS packets *must* get through here! However, every
49  // now and then there may be conditions where the packet just can't be
50  // handled when offered the first time, so that's why we try several times:
51  for (int i = 0; i < MAXRETRIES; i++) {
52  if (PlayTs(Data, Length) > 0)
53  return;
55  }
56  DeviceClear();
58  if (time(NULL) - lastErrorReport > ERRORDELTA) {
59  esyslog("ERROR: %d TS packet(s) not accepted in Transfer Mode", numLostPackets);
60  numLostPackets = 0;
61  lastErrorReport = time(NULL);
62  }
63  }
64 }
65 
66 // --- cTransferControl ------------------------------------------------------
67 
69 
70 cTransferControl::cTransferControl(cDevice *ReceiverDevice, const cChannel *Channel)
71 :cControl(NULL, true)
72 {
73  transfer = new cTransfer(Channel);
77 }
78 
80 {
81  receiverDevice = NULL;
82  delete transfer;
83 }
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
void SetPlayer(cPlayer *Player)
Definition: player.h:110
bool AttachReceiver(cReceiver *Receiver)
Attaches the given receiver to this device.
Definition: device.c:1815
uchar * GetPmt(int &Index)
Returns a pointer to the Index'th TS packet of the PMT section.
Definition: remux.c:600
void SetChannel(const cChannel *Channel)
Sets the Channel for which the PAT/PMT shall be generated.
Definition: remux.c:585
uchar * GetPat(void)
Returns a pointer to the PAT section, which consists of exactly one TS packet.
Definition: remux.c:594
void Detach(void)
Definition: player.c:34
int PlayTs(const uchar *Data, int Length, bool VideoOnly=false)
Definition: player.h:47
bool IsAttached(void)
Definition: player.h:54
void DeviceClear(void)
Definition: player.h:31
void Detach(void)
Definition: receiver.c:125
cTransfer * transfer
Definition: transfer.h:32
static cDevice * receiverDevice
Definition: transfer.h:33
cTransferControl(cDevice *ReceiverDevice, const cChannel *Channel)
Definition: transfer.c:70
static cDevice * ReceiverDevice(void)
Definition: transfer.h:38
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: transfer.c:44
time_t lastErrorReport
Definition: transfer.h:19
virtual ~cTransfer()
Definition: transfer.c:22
cTransfer(const cChannel *Channel)
Definition: transfer.c:14
virtual void Activate(bool On)
Definition: transfer.c:28
int numLostPackets
Definition: transfer.h:20
cPatPmtGenerator patPmtGenerator
Definition: transfer.h:21
#define TRANSFERPRIORITY
Definition: config.h:46
#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:40
#define RETRYWAIT
Definition: transfer.c:41
#define ERRORDELTA
Definition: transfer.c:42