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())
28 #elif VDRVERSNUM < 10500
29 : cReceiver(channel->Ca(), 0, channel->Vpid(), channel->Apids(), channel->Dpids(), channel->Spids())
31 : cReceiver(channel->GetChannelID(), 0, channel->Vpid(), channel->Apids(), channel->Dpids(), channel->Spids())
34 logger = Log::getInstance();
40 // logger->log("MVPReceiver", Log::DEBUG, "Channel has VPID %i APID %i", channel->Vpid(), channel->Apid(0));
42 if (!processed.init(1000000)) return;
43 pthread_mutex_init(&processedRingLock, NULL);
48 device->SwitchChannel(channel, false);
49 device->AttachReceiver(this);
52 int MVPReceiver::init(TCP* ttcp, ULONG tstreamID)
59 MVPReceiver::~MVPReceiver()
65 void MVPReceiver::Activate(bool on)
70 logger->log("MVPReceiver", Log::DEBUG, "VDR active");
75 logger->log("MVPReceiver", Log::DEBUG, "VDR inactive");
80 bool MVPReceiver::isVdrActivated()
85 void MVPReceiver::Receive(UCHAR* data, int length)
87 pthread_mutex_lock(&processedRingLock);
88 processed.put(data, length);
89 if (processed.getContent() > streamChunkSize) threadSignal();
90 pthread_mutex_unlock(&processedRingLock);
93 void MVPReceiver::threadMethod()
95 UCHAR buffer[streamChunkSize + 12];
98 // threadSetKillable(); ??
102 threadWaitForSignal();
107 pthread_mutex_lock(&processedRingLock);
108 amountReceived = processed.get(buffer+12, streamChunkSize);
109 pthread_mutex_unlock(&processedRingLock);
111 *(ULONG*)&buffer[0] = htonl(2); // stream channel
112 *(ULONG*)&buffer[4] = htonl(streamID);
113 *(ULONG*)&buffer[8] = htonl(amountReceived);
114 tcp->sendPacket(buffer, amountReceived + 12);
115 } while(processed.getContent());
119 ULONG MVPReceiver::getBlock(unsigned char* buffer, unsigned long amount)
122 pthread_mutex_lock(&processedRingLock);
126 while ((unsigned long)processed.getContent() < amount)
128 pthread_mutex_unlock(&processedRingLock);
129 if (++numTries == 30) // 15s
131 logger->log("MVPReceiver", Log::DEBUG, "getBlock timeout");
135 pthread_mutex_lock(&processedRingLock);
138 unsigned long amountReceived = processed.get(buffer, amount);
139 pthread_mutex_unlock(&processedRingLock);
140 return amountReceived;