vdr  2.4.0
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 4.2 2017/12/07 15:00:33 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(transfer = new cTransfer(Channel), true)
72 {
75 }
76 
78 {
79  receiverDevice = NULL;
80  delete transfer;
81 }
unsigned char uchar
Definition: tools.h:31
static cDevice * receiverDevice
Definition: transfer.h:33
void DeviceClear(void)
Definition: player.h:31
virtual void Activate(bool On)
Definition: transfer.c:28
bool IsAttached(void)
Definition: player.h:54
int numLostPackets
Definition: transfer.h:20
static cDevice * ReceiverDevice(void)
Definition: transfer.h:38
#define TRANSFERPRIORITY
Definition: config.h:42
#define esyslog(a...)
Definition: tools.h:35
bool AttachReceiver(cReceiver *Receiver)
Attaches the given receiver to this device.
Definition: device.c:1748
time_t lastErrorReport
Definition: transfer.h:19
void SetChannel(const cChannel *Channel)
Sets the Channel for which the PAT/PMT shall be generated.
Definition: remux.c:621
virtual ~cTransfer()
Definition: transfer.c:22
cTransfer * transfer
Definition: transfer.h:32
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
void Detach(void)
Definition: player.c:34
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
uchar * GetPmt(int &Index)
Returns a pointer to the Index&#39;th TS packet of the PMT section.
Definition: remux.c:636
#define MAXRETRIES
Definition: transfer.c:40
cPatPmtGenerator patPmtGenerator
Definition: transfer.h:21
cTransferControl(cDevice *ReceiverDevice, const cChannel *Channel)
Definition: transfer.c:70
int PlayTs(const uchar *Data, int Length, bool VideoOnly=false)
Definition: player.h:47
#define ERRORDELTA
Definition: transfer.c:42
#define TS_SIZE
Definition: remux.h:34
cTransfer(const cChannel *Channel)
Definition: transfer.c:14
void Detach(void)
Definition: receiver.c:125
#define RETRYWAIT
Definition: transfer.c:41
uchar * GetPat(void)
Returns a pointer to the PAT section, which consists of exactly one TS packet.
Definition: remux.c:630