summaryrefslogtreecommitdiff
path: root/p2pvr/devices
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-06-18 00:25:45 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2015-06-18 00:25:45 +0100
commit3d154e756d61d8617bb8023eb552b5e4faab2a74 (patch)
treea887a65f8699e7dbf46e8d50c25b575e50d498b2 /p2pvr/devices
parentMerge branch 'netfs-test-refactor' (diff)
parentCompatibility with AppInstance and ExecContext changes (diff)
downloadp2pvr-3d154e756d61d8617bb8023eb552b5e4faab2a74.tar.bz2
p2pvr-3d154e756d61d8617bb8023eb552b5e4faab2a74.tar.xz
p2pvr-3d154e756d61d8617bb8023eb552b5e4faab2a74.zip
Merge branch 'p2pvr'
Diffstat (limited to 'p2pvr/devices')
-rw-r--r--p2pvr/devices/Jamfile.jam41
-rw-r--r--p2pvr/devices/localDevices.cpp4
-rw-r--r--p2pvr/devices/localDevices.h2
-rw-r--r--p2pvr/devices/mockTuner.cpp176
-rw-r--r--p2pvr/devices/mockTuner.h42
-rw-r--r--p2pvr/devices/pch.hpp1
-rw-r--r--p2pvr/devices/sampleSiData/events1.datxzbin0 -> 1112856 bytes
-rw-r--r--p2pvr/devices/sampleSiData/events2.datxzbin0 -> 1108428 bytes
-rw-r--r--p2pvr/devices/sampleSiData/network.datxzbin0 -> 1244 bytes
-rw-r--r--p2pvr/devices/sampleSiData/pat.datxzbin0 -> 160 bytes
-rw-r--r--p2pvr/devices/sampleSiData/pmt.datxzbin0 -> 208 bytes
-rw-r--r--p2pvr/devices/sampleSiData/services.datxzbin0 -> 2392 bytes
-rw-r--r--p2pvr/devices/sampleStreamData/vid.datxzbin0 -> 2952196 bytes
-rw-r--r--p2pvr/devices/tuner.cpp2
14 files changed, 262 insertions, 6 deletions
diff --git a/p2pvr/devices/Jamfile.jam b/p2pvr/devices/Jamfile.jam
index a3452a4..8e18afa 100644
--- a/p2pvr/devices/Jamfile.jam
+++ b/p2pvr/devices/Jamfile.jam
@@ -1,5 +1,10 @@
+import type ;
+import generators ;
+
lib boost_system ;
+lib boost_thread ;
lib boost_filesystem ;
+lib lzma ;
cpp-pch pch : pch.hpp :
<library>boost_system
@@ -10,7 +15,7 @@ cpp-pch pch : pch.hpp :
lib p2pvrdevices :
pch
- [ glob-tree *.cpp ]
+ [ glob-tree *.cpp : mockTuner.cpp ]
:
<library>boost_system
<library>boost_filesystem
@@ -25,3 +30,37 @@ lib p2pvrdevices :
<library>boost_system
<include>.
;
+
+type.register DATXZ : datxz ;
+
+generators.register-standard datxz.embed.asm : DATXZ : ASM ;
+
+actions datxz.embed.asm
+{
+ m4 -DNAME="$(2:B)" -DPATH="$(2)" "$(root)/embed.m4" > "$(1)"
+}
+
+IMPORT $(__name__) : datxz.embed.asm : : datxz.embed.asm ;
+
+
+lib p2pvrMockTuner :
+ pch
+ mockTuner.cpp
+ [ glob-tree *.datxz ]
+ :
+ <library>lzma
+ <library>boost_system
+ <library>boost_thread
+ <library>boost_filesystem
+ <library>../dvb//p2pvrdvb
+ <library>../ice//p2pvrice
+ <library>../lib//p2pvrlib
+ <library>..//p2common
+ <implicit-dependency>../ice//p2pvrice
+ : :
+ <library>boost_filesystem
+ <implicit-dependency>../ice//p2pvrice
+ <library>boost_system
+ <include>.
+ ;
+
diff --git a/p2pvr/devices/localDevices.cpp b/p2pvr/devices/localDevices.cpp
index 7a43a15..00ec395 100644
--- a/p2pvr/devices/localDevices.cpp
+++ b/p2pvr/devices/localDevices.cpp
@@ -34,7 +34,7 @@ void
LocalDevices::ClientCheck(Ice::ObjectAdapterPtr adapter)
{
std::lock_guard<std::mutex> g(lock);
- BOOST_FOREACH(auto & device, devices) {
+ for (auto & device : devices) {
if (device.second && device.second->tuner->GetLastUsedTime() < time(NULL) - 30) {
Logger()->messagebf(LOG_DEBUG, "%s: Device %s no longer in use", __PRETTY_FUNCTION__, device.first);
auto id = device.second->tuner->ice_getIdentity();
@@ -79,7 +79,7 @@ LocalDevices::GetTunerSpecific(const DVBSI::DeliveryPtr & delivery, const Ice::C
}
P2PVR::TunerPrx
-LocalDevices::GetTunerAny(short , const DVBSI::DeliveryPtr & delivery, const Ice::Current & ice)
+LocalDevices::GetTunerAny(const DVBSI::DeliveryPtr & delivery, const Ice::Current & ice)
{
std::lock_guard<std::mutex> g(lock);
Logger()->messagebf(LOG_DEBUG, "%s: Searching for an open sharable tuner any frequency", __PRETTY_FUNCTION__);
diff --git a/p2pvr/devices/localDevices.h b/p2pvr/devices/localDevices.h
index 5521f8d..3c3d51b 100644
--- a/p2pvr/devices/localDevices.h
+++ b/p2pvr/devices/localDevices.h
@@ -14,7 +14,7 @@ class LocalDevices : public P2PVR::LocalDevices {
~LocalDevices();
P2PVR::TunerPrx GetTunerSpecific(const DVBSI::DeliveryPtr &, const Ice::Current &);
- P2PVR::TunerPrx GetTunerAny(short type, const DVBSI::DeliveryPtr &, const Ice::Current &);
+ P2PVR::TunerPrx GetTunerAny(const DVBSI::DeliveryPtr &, const Ice::Current &);
P2PVR::PrivateTunerPrx GetPrivateTuner(short type, const Ice::Current &);
void ReleaseTuner(const P2PVR::TunerPrx &, const Ice::Current &);
int TunerCount(const Ice::Current &);
diff --git a/p2pvr/devices/mockTuner.cpp b/p2pvr/devices/mockTuner.cpp
new file mode 100644
index 0000000..05a0437
--- /dev/null
+++ b/p2pvr/devices/mockTuner.cpp
@@ -0,0 +1,176 @@
+#include "mockTuner.h"
+#include <Ice/Service.h>
+#include <lzma.h>
+#include <logger.h>
+#include <list>
+
+#define ResourceFile(resource) \
+extern "C" { \
+ extern char resource##_start, resource##_end;\
+ extern unsigned int resource##_len; \
+} \
+static const Ice::ByteSeq resource(&resource##_start, &resource##_end);
+
+#define LZMA_ASSERT(ret_xz) \
+ if (ret_xz != LZMA_OK) { \
+ Logger()->messagebf(LOG_ERR, "%s: LZMA error (%d)", __PRETTY_FUNCTION__, ret_xz); \
+ throw P2PVR::DeviceError("LZMA", "Decompressor error", ret_xz); \
+ }
+
+ResourceFile(network);
+ResourceFile(services);
+ResourceFile(events1);
+ResourceFile(events2);
+ResourceFile(pat);
+ResourceFile(pmt);
+ResourceFile(vid);
+
+int MockTuner::eventSet = 0;
+
+void
+MockTuner::SetEventsSet(int n)
+{
+ eventSet = n;
+}
+
+MockTuner::MockTuner() :
+ senderId(1)
+{
+}
+
+void MockTuner::TuneTo(const DVBSI::DeliveryPtr &, const Ice::Current&)
+{
+}
+
+int MockTuner::GetStatus(const Ice::Current&)
+{
+ return 0;
+}
+
+Ice::ByteSeq MockTuner::Decompress(const Ice::ByteSeq & dataxz)
+{
+ Logger()->messagebf(LOG_DEBUG, "%s: setup", __PRETTY_FUNCTION__);
+ lzma_stream strm = LZMA_STREAM_INIT;
+ const uint32_t flags = LZMA_TELL_UNSUPPORTED_CHECK | LZMA_CONCATENATED;
+ const uint64_t memory_limit = UINT64_MAX;
+ LZMA_ASSERT(lzma_stream_decoder(&strm, memory_limit, flags));
+ strm.next_in = &dataxz.front();
+ strm.avail_in = dataxz.size();
+ uint8_t buf[BUFSIZ];
+
+ Logger()->messagebf(LOG_DEBUG, "%s: decompress %d bytes", __PRETTY_FUNCTION__, dataxz.size());
+ Ice::ByteSeq data;
+ data.reserve(dataxz.size() * 20);
+ do {
+ strm.next_out = buf;
+ strm.avail_out = BUFSIZ;
+ LZMA_ASSERT(lzma_code(&strm, LZMA_RUN));
+ for (auto idx = 0u; idx < BUFSIZ - strm.avail_out; idx += 1) {
+ data.push_back(buf[idx]);
+ }
+ } while (strm.avail_out == 0);
+ data.shrink_to_fit();
+ return data;
+}
+
+void MockTuner::DecompressAndSendPackets(const Ice::ByteSeq & dataxz, const P2PVR::RawDataClientPrx & client, const Ice::Current & ice) const
+{
+ Logger()->messagebf(LOG_DEBUG, "%s: deserialize", __PRETTY_FUNCTION__);
+ std::list<Ice::ByteSeq> packets;
+ auto istrm = Ice::createInputStream(ice.adapter->getCommunicator(), Decompress(dataxz));
+ istrm->read(packets);
+
+ Logger()->messagebf(LOG_DEBUG, "%s: send", __PRETTY_FUNCTION__);
+ for (const auto & packet : packets) {
+ client->NewData(packet);
+ }
+
+ Logger()->messagebf(LOG_DEBUG, "%s: complete", __PRETTY_FUNCTION__);
+}
+
+void MockTuner::ScanAndSendNetworkInformation(const P2PVR::RawDataClientPrx & client, const Ice::Current & ice)
+{
+ DecompressAndSendPackets(network, client, ice);
+}
+
+void MockTuner::SendNetworkInformation(const P2PVR::RawDataClientPrx & client, const Ice::Current & ice)
+{
+ DecompressAndSendPackets(network, client, ice);
+}
+
+void MockTuner::SendBouquetAssociations(const P2PVR::RawDataClientPrx &, const Ice::Current&)
+{
+}
+
+void MockTuner::SendServiceDescriptions(const P2PVR::RawDataClientPrx & client, const Ice::Current & ice)
+{
+ DecompressAndSendPackets(services, client, ice);
+}
+
+void MockTuner::SendProgramMap(Ice::Int, const P2PVR::RawDataClientPrx &, const Ice::Current&)
+{
+}
+
+void MockTuner::SendProgramAssociationTable(const P2PVR::RawDataClientPrx &, const Ice::Current&)
+{
+}
+
+void MockTuner::SendEventInformation(const P2PVR::RawDataClientPrx & client, const Ice::Current & ice)
+{
+ DecompressAndSendPackets(eventSet == 0 ? events1 : events2, client, ice);
+}
+
+void MockTuner::SendLoop(const P2PVR::RawDataClientPrx & t, const Ice::ByteSeq & dataxz, const Ice::Current & ice) const
+{
+ std::list<Ice::ByteSeq> packets;
+ auto istrm = Ice::createInputStream(ice.adapter->getCommunicator(), Decompress(dataxz));
+ istrm->read(packets);
+ Logger()->messagebf(LOG_DEBUG, "%s: loop over %d packets", __PRETTY_FUNCTION__, packets.size());
+ auto p = packets.begin();
+ while (true) {
+ {
+ boost::this_thread::disable_interruption whileSending;
+ t->NewData(*p);
+ }
+ boost::this_thread::interruption_point();
+ p++;
+ if (p == packets.end()) {
+ p = packets.begin();
+ }
+ usleep(100000);
+ }
+}
+
+
+int MockTuner::StartSendingTS(const P2PVR::PacketIds &, const P2PVR::RawDataClientPrx & t, const Ice::Current & ice)
+{
+ return senders.insert({senderId++, new boost::thread(&MockTuner::SendLoop, this, t, vid, ice)}).first->first;
+}
+
+int MockTuner::StartSendingSection(Ice::Int sid, const P2PVR::RawDataClientPrx & t, const Ice::Current & ice)
+{
+ switch (sid) {
+ case 0: // pat
+ return senders.insert({senderId++, new boost::thread(&MockTuner::SendLoop, this, t, pat, ice)}).first->first;
+ case 100: // sample pmt
+ return senders.insert({senderId++, new boost::thread(&MockTuner::SendLoop, this, t, pmt, ice)}).first->first;
+ }
+ throw std::runtime_error("I don't have a sample for that");
+}
+
+void MockTuner::StopSending(int s, const Ice::Current &)
+{
+ Logger()->messagebf(LOG_DEBUG, "%s: stop %d", __PRETTY_FUNCTION__, s);
+ auto sitr = senders.find(s);
+ if (sitr != senders.end()) {
+ sitr->second->interrupt();
+ sitr->second->join();
+ senders.erase(sitr);
+ }
+}
+
+Ice::Long MockTuner::GetLastUsedTime(const Ice::Current&)
+{
+ return time(NULL);
+}
+
diff --git a/p2pvr/devices/mockTuner.h b/p2pvr/devices/mockTuner.h
new file mode 100644
index 0000000..aa51580
--- /dev/null
+++ b/p2pvr/devices/mockTuner.h
@@ -0,0 +1,42 @@
+#ifndef P2PVR_MOCKTUNER_H
+#define P2PVR_MOCKTUNER_H
+
+#include <dvb.h>
+#include <Ice/BuiltinSequences.h>
+#include <boost/thread.hpp>
+
+class MockTuner : public P2PVR::PrivateTuner {
+ public:
+ MockTuner();
+
+ void TuneTo(const DVBSI::DeliveryPtr &, const Ice::Current&);
+ int GetStatus(const Ice::Current&);
+
+ void ScanAndSendNetworkInformation(const P2PVR::RawDataClientPrx & client, const Ice::Current&);
+ void SendNetworkInformation(const P2PVR::RawDataClientPrx & client, const Ice::Current&);
+ void SendBouquetAssociations(const P2PVR::RawDataClientPrx & client, const Ice::Current&);
+ void SendServiceDescriptions(const P2PVR::RawDataClientPrx & client, const Ice::Current&);
+ void SendProgramMap(Ice::Int pid, const P2PVR::RawDataClientPrx & client, const Ice::Current&);
+ void SendProgramAssociationTable(const P2PVR::RawDataClientPrx & client, const Ice::Current&);
+ void SendEventInformation(const P2PVR::RawDataClientPrx & client, const Ice::Current&);
+
+ int StartSendingTS(const P2PVR::PacketIds & pids, const P2PVR::RawDataClientPrx & client, const Ice::Current &);
+ int StartSendingSection(Ice::Int pid, const P2PVR::RawDataClientPrx & client, const Ice::Current &);
+ void StopSending(int handle, const Ice::Current &);
+
+ Ice::Long GetLastUsedTime(const Ice::Current&);
+
+ static void SetEventsSet(int n);
+
+ protected:
+ static Ice::ByteSeq Decompress(const Ice::ByteSeq &);
+ void DecompressAndSendPackets(const Ice::ByteSeq &, const P2PVR::RawDataClientPrx &, const Ice::Current&) const;
+ void SendLoop(const P2PVR::RawDataClientPrx & t, const Ice::ByteSeq & dataxz, const Ice::Current & ice) const;
+
+ static int eventSet;
+ std::map<int, boost::thread *> senders;
+ int senderId;
+};
+
+#endif
+
diff --git a/p2pvr/devices/pch.hpp b/p2pvr/devices/pch.hpp
index 2eeeea5..435ce48 100644
--- a/p2pvr/devices/pch.hpp
+++ b/p2pvr/devices/pch.hpp
@@ -4,7 +4,6 @@
#include <Ice/Ice.h>
#include <boost/bind.hpp>
-#include <boost/foreach.hpp>
#include <boost/function.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/shared_ptr.hpp>
diff --git a/p2pvr/devices/sampleSiData/events1.datxz b/p2pvr/devices/sampleSiData/events1.datxz
new file mode 100644
index 0000000..a84d777
--- /dev/null
+++ b/p2pvr/devices/sampleSiData/events1.datxz
Binary files differ
diff --git a/p2pvr/devices/sampleSiData/events2.datxz b/p2pvr/devices/sampleSiData/events2.datxz
new file mode 100644
index 0000000..b2fa9c2
--- /dev/null
+++ b/p2pvr/devices/sampleSiData/events2.datxz
Binary files differ
diff --git a/p2pvr/devices/sampleSiData/network.datxz b/p2pvr/devices/sampleSiData/network.datxz
new file mode 100644
index 0000000..f2e74cd
--- /dev/null
+++ b/p2pvr/devices/sampleSiData/network.datxz
Binary files differ
diff --git a/p2pvr/devices/sampleSiData/pat.datxz b/p2pvr/devices/sampleSiData/pat.datxz
new file mode 100644
index 0000000..cdbd63b
--- /dev/null
+++ b/p2pvr/devices/sampleSiData/pat.datxz
Binary files differ
diff --git a/p2pvr/devices/sampleSiData/pmt.datxz b/p2pvr/devices/sampleSiData/pmt.datxz
new file mode 100644
index 0000000..b883c0c
--- /dev/null
+++ b/p2pvr/devices/sampleSiData/pmt.datxz
Binary files differ
diff --git a/p2pvr/devices/sampleSiData/services.datxz b/p2pvr/devices/sampleSiData/services.datxz
new file mode 100644
index 0000000..0961e92
--- /dev/null
+++ b/p2pvr/devices/sampleSiData/services.datxz
Binary files differ
diff --git a/p2pvr/devices/sampleStreamData/vid.datxz b/p2pvr/devices/sampleStreamData/vid.datxz
new file mode 100644
index 0000000..ec8ed6e
--- /dev/null
+++ b/p2pvr/devices/sampleStreamData/vid.datxz
Binary files differ
diff --git a/p2pvr/devices/tuner.cpp b/p2pvr/devices/tuner.cpp
index fe90231..ee1625a 100644
--- a/p2pvr/devices/tuner.cpp
+++ b/p2pvr/devices/tuner.cpp
@@ -322,7 +322,7 @@ Tuner::senderThread()
int n = backgroundClients.rbegin()->first + 1;
fd_set rfds;
FD_ZERO(&rfds);
- BOOST_FOREACH(const auto & c, backgroundClients) {
+ for (const auto & c : backgroundClients) {
FD_SET(c.first, &rfds);
}
lock.unlock();