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");
15 if (NeedsDetachReceivers)
17 // can't really happen since we stream with priority zero. if a rec has pri zero maybe
18 Log::getInstance()->log("MVPReceiver", Log::DEBUG, "Needs detach receivers");
23 // What should we do if NeedsDetachReceivers is true?
25 MVPReceiver* m = new MVPReceiver(channel, device);
29 MVPReceiver::MVPReceiver(cChannel* channel, cDevice* device)
30 #if VDRVERSNUM < 10300
31 : cReceiver(channel->Ca(), 0, 7, channel->Vpid(), channel->Ppid(), channel->Apid1(), channel->Apid2(), channel->Dpid1(), channel->Dpid2(), channel->Tpid())
33 : cReceiver(channel->Ca(), 0, channel->Vpid(), channel->Apids(), channel->Dpids(), channel->Spids())
36 logger = Log::getInstance();
44 // Get the remuxer for audio or video
46 #if VDRVERSNUM < 10300
47 // if ((channel->Vpid() == 0) || (channel->Vpid() == 1) || (channel->Vpid() == 0x1FFF))
49 // remuxer = new cTS2ESRemux(channel->Apid1());
50 // logger->log("MVPReceiver", Log::DEBUG, "Created new < 1.3 TS->ES");
54 remuxer = new cTS2PSRemux(channel->Vpid(), channel->Apid1(), 0, 0, 0, 0);
55 logger->log("MVPReceiver", Log::DEBUG, "Created new < 1.3 TS->PS");
58 // if ((channel->Vpid() == 0) || (channel->Vpid() == 1) || (channel->Vpid() == 0x1FFF))
60 // remuxer = new cTS2ESRemux(channel->Apid(0));
61 // logger->log("MVPReceiver", Log::DEBUG, "Created new > 1.3 TS->ES");
65 remuxer = new cTS2PSRemux(channel->Vpid(), channel->Apid(0), 0, 0, 0, 0);
66 logger->log("MVPReceiver", Log::DEBUG, "Created new > 1.3 TS->PS");
70 unprocessed = new cRingBufferLinear(1000000, TS_SIZE * 2, false);
72 if (!processed.init(1000000)) return;
73 pthread_mutex_init(&processedRingLock, NULL);
75 if (!threadStart()) return;
80 device->SwitchChannel(channel, false);
81 device->AttachReceiver(this);
84 int MVPReceiver::init()
89 MVPReceiver::~MVPReceiver()
92 if (threadIsActive()) threadCancel();
93 if (unprocessed) delete unprocessed;
94 if (remuxer) delete remuxer;
97 void MVPReceiver::Activate(bool on)
100 if (on) logger->log("MVPReceiver", Log::DEBUG, "VDR active");
101 else logger->log("MVPReceiver", Log::DEBUG, "VDR inactive");
104 bool MVPReceiver::isVdrActivated()
109 void MVPReceiver::Receive(UCHAR* data, int length)
111 static int receiveCount = 0;
113 // int p = unprocessed->Put(data, length);
114 // if (p != length) printf("Buffer overrun\n");
116 unprocessed->Put(data, length);
118 if (++receiveCount == 15)
125 void MVPReceiver::threadMethod()
136 threadWaitForSignal();
140 dataGot = unprocessed->Get(amountGot);
141 if (dataGot && (amountGot > 0))
144 remuxTook = amountGot;
145 remuxedData = remuxer->Process(dataGot, remuxTook, outputSize);
146 unprocessed->Del(remuxTook);
148 pthread_mutex_lock(&processedRingLock);
149 processed.put(remuxedData, outputSize);
150 pthread_mutex_unlock(&processedRingLock);
152 // logger->log("MVPReceiver", Log::DEBUG, "Got from unprocessed: %i, Got from remux: %p %i, consumed: %i",
153 // amountGot, remuxedData, outputSize, remuxTook);
163 unsigned long MVPReceiver::getBlock(unsigned char* buffer, unsigned long amount)
165 pthread_mutex_lock(&processedRingLock);
169 while ((unsigned long)processed.getContent() < amount)
171 pthread_mutex_unlock(&processedRingLock);
172 if (++numTries == 10) // 5s
174 logger->log("MVPReceiver", Log::DEBUG, "getBlock timeout");
178 pthread_mutex_lock(&processedRingLock);
181 unsigned long amountReceived = processed.get(buffer, amount);
182 pthread_mutex_unlock(&processedRingLock);
183 return amountReceived;