1 #include "mvpreceiver.h"
3 MVPReceiver* MVPReceiver::create(cChannel* channel, int priority)
5 bool NeedsDetachReceivers;
6 cDevice* device = cDevice::GetDevice(channel, priority, &NeedsDetachReceivers);
10 Log::getInstance()->log("MVPReceiver", Log::DEBUG, "No device found to receive this channel at this priority");
14 if (NeedsDetachReceivers)
16 Log::getInstance()->log("MVPReceiver", Log::DEBUG, "Needs detach receivers");
18 // Need to detach other receivers or VDR will shut down
21 MVPReceiver* m = new MVPReceiver(channel, device);
25 MVPReceiver::MVPReceiver(cChannel* channel, cDevice* device)
26 #if VDRVERSNUM < 10300
27 : cReceiver(channel->Ca(), 0, 7, channel->Vpid(), channel->Ppid(), channel->Apid1(), channel->Apid2(), channel->Dpid1(), channel->Dpid2(), channel->Tpid())
29 : cReceiver(channel->Ca(), 0, channel->Vpid(), channel->Apids(), channel->Dpids(), channel->Spids())
32 logger = Log::getInstance();
40 // Get the remuxer for audio or video
42 #if VDRVERSNUM < 10300
43 // if ((channel->Vpid() == 0) || (channel->Vpid() == 1) || (channel->Vpid() == 0x1FFF))
45 // remuxer = new cTS2ESRemux(channel->Apid1());
46 // logger->log("MVPReceiver", Log::DEBUG, "Created new < 1.3 TS->ES");
50 remuxer = new cTS2PSRemux(channel->Vpid(), channel->Apid1(), 0, 0, 0, 0);
51 logger->log("MVPReceiver", Log::DEBUG, "Created new < 1.3 TS->PS");
54 // if ((channel->Vpid() == 0) || (channel->Vpid() == 1) || (channel->Vpid() == 0x1FFF))
56 // remuxer = new cTS2ESRemux(channel->Apid(0));
57 // logger->log("MVPReceiver", Log::DEBUG, "Created new > 1.3 TS->ES");
61 remuxer = new cTS2PSRemux(channel->Vpid(), channel->Apid(0), 0, 0, 0, 0);
62 logger->log("MVPReceiver", Log::DEBUG, "Created new > 1.3 TS->PS");
66 unprocessed = new cRingBufferLinear(1000000, TS_SIZE * 2, false);
68 if (!processed.init(1000000)) return;
69 pthread_mutex_init(&processedRingLock, NULL);
71 if (!threadStart()) return;
76 device->SwitchChannel(channel, false);
77 device->AttachReceiver(this);
80 int MVPReceiver::init()
85 MVPReceiver::~MVPReceiver()
88 if (threadIsActive()) threadCancel();
89 if (unprocessed) delete unprocessed;
90 if (remuxer) delete remuxer;
93 void MVPReceiver::Activate(bool on)
96 if (on) logger->log("MVPReceiver", Log::DEBUG, "VDR active");
97 else logger->log("MVPReceiver", Log::DEBUG, "VDR inactive");
100 bool MVPReceiver::isVdrActivated()
105 void MVPReceiver::Receive(UCHAR* data, int length)
107 static int receiveCount = 0;
109 // int p = unprocessed->Put(data, length);
110 // if (p != length) printf("Buffer overrun\n");
112 unprocessed->Put(data, length);
114 if (++receiveCount == 15)
121 void MVPReceiver::threadMethod()
132 threadWaitForSignal();
136 dataGot = unprocessed->Get(amountGot);
137 if (dataGot && (amountGot > 0))
140 remuxTook = amountGot;
141 remuxedData = remuxer->Process(dataGot, remuxTook, outputSize);
142 unprocessed->Del(remuxTook);
144 pthread_mutex_lock(&processedRingLock);
145 processed.put(remuxedData, outputSize);
146 pthread_mutex_unlock(&processedRingLock);
148 // logger->log("MVPReceiver", Log::DEBUG, "Got from unprocessed: %i, Got from remux: %p %i, consumed: %i",
149 // amountGot, remuxedData, outputSize, remuxTook);
159 unsigned long MVPReceiver::getBlock(unsigned char* buffer, unsigned long amount)
161 pthread_mutex_lock(&processedRingLock);
165 while ((unsigned long)processed.getContent() < amount)
167 pthread_mutex_unlock(&processedRingLock);
168 if (++numTries == 30) // 15s
170 logger->log("MVPReceiver", Log::DEBUG, "getBlock timeout");
174 pthread_mutex_lock(&processedRingLock);
177 unsigned long amountReceived = processed.get(buffer, amount);
178 pthread_mutex_unlock(&processedRingLock);
179 return amountReceived;