1 #include "mvpreceiver.h"
3 MVPReceiver* MVPReceiver::create(cChannel* channel, int priority)
6 bool NeedsDetachReceivers;
7 cDevice* device = cDevice::GetDevice(channel, priority, &NeedsDetachReceivers);
9 cDevice* device = cDevice::GetDevice(channel, priority, true); // last param is live-view
14 Log::getInstance()->log("MVPReceiver", Log::DEBUG, "No device found to receive this channel at this priority");
18 #if VDRVERSNUM < 10500
19 if (NeedsDetachReceivers)
21 Log::getInstance()->log("MVPReceiver", Log::DEBUG, "Needs detach receivers");
23 // Need to detach other receivers or VDR will shut down??
27 MVPReceiver* m = new MVPReceiver(channel, device);
31 MVPReceiver::MVPReceiver(cChannel* channel, cDevice* device)
32 #if VDRVERSNUM < 10300
33 : cReceiver(channel->Ca(), 0, 7, channel->Vpid(), channel->Ppid(), channel->Apid1(), channel->Apid2(), channel->Dpid1(), channel->Dpid2(), channel->Tpid())
34 #elif VDRVERSNUM < 10500
35 : cReceiver(channel->Ca(), 0, channel->Vpid(), channel->Apids(), channel->Dpids(), channel->Spids())
37 : cReceiver(channel->GetChannelID(), 0, channel->Vpid(), channel->Apids(), channel->Dpids(), channel->Spids())
40 logger = Log::getInstance();
46 // logger->log("MVPReceiver", Log::DEBUG, "Channel has VPID %i APID %i", channel->Vpid(), channel->Apid(0));
48 if (!processed.init(1000000)) return;
49 pthread_mutex_init(&processedRingLock, NULL);
54 device->SwitchChannel(channel, false);
55 device->AttachReceiver(this);
58 int MVPReceiver::init(TCP* ttcp, ULONG tstreamID)
65 MVPReceiver::~MVPReceiver()
71 void MVPReceiver::Activate(bool on)
76 logger->log("MVPReceiver", Log::DEBUG, "VDR active");
81 logger->log("MVPReceiver", Log::DEBUG, "VDR inactive");
86 bool MVPReceiver::isVdrActivated()
91 void MVPReceiver::Receive(UCHAR* data, int length)
93 pthread_mutex_lock(&processedRingLock);
94 processed.put(data, length);
95 if (processed.getContent() > streamChunkSize) threadSignal();
96 pthread_mutex_unlock(&processedRingLock);
99 void MVPReceiver::threadMethod()
101 UCHAR buffer[streamChunkSize + 12];
104 // threadSetKillable(); ??
108 threadWaitForSignal();
113 pthread_mutex_lock(&processedRingLock);
114 amountReceived = processed.get(buffer+12, streamChunkSize);
115 pthread_mutex_unlock(&processedRingLock);
117 *(ULONG*)&buffer[0] = htonl(2); // stream channel
118 *(ULONG*)&buffer[4] = htonl(streamID);
119 *(ULONG*)&buffer[8] = htonl(amountReceived);
120 tcp->sendPacket(buffer, amountReceived + 12);
121 } while(processed.getContent() >= streamChunkSize);
125 ULONG MVPReceiver::getBlock(unsigned char* buffer, unsigned long amount)
128 pthread_mutex_lock(&processedRingLock);
132 while ((unsigned long)processed.getContent() < amount)
134 pthread_mutex_unlock(&processedRingLock);
135 if (++numTries == 30) // 15s
137 logger->log("MVPReceiver", Log::DEBUG, "getBlock timeout");
141 pthread_mutex_lock(&processedRingLock);
144 unsigned long amountReceived = processed.get(buffer, amount);
145 pthread_mutex_unlock(&processedRingLock);
146 return amountReceived;