summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-02-03 20:58:13 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2015-06-13 17:29:49 +0100
commit5fe1f5a520fca2fd206b9f88922302115fb5c10e (patch)
treedfa6cc4e2dc782b92abd7adfa36a9e370dc2c4fe
parentLog size of data being decompressed as it gives rudimentary clue as to what i... (diff)
downloadp2pvr-5fe1f5a520fca2fd206b9f88922302115fb5c10e.tar.bz2
p2pvr-5fe1f5a520fca2fd206b9f88922302115fb5c10e.tar.xz
p2pvr-5fe1f5a520fca2fd206b9f88922302115fb5c10e.zip
Extend mock tuner to support basic streaming with sample of BBC One
-rw-r--r--p2pvr/devices/Jamfile.jam2
-rw-r--r--p2pvr/devices/mockTuner.cpp53
-rw-r--r--p2pvr/devices/mockTuner.h6
-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/sampleStreamData/vid.datxzbin0 -> 2952196 bytes
6 files changed, 56 insertions, 5 deletions
diff --git a/p2pvr/devices/Jamfile.jam b/p2pvr/devices/Jamfile.jam
index 365fbbd..8e18afa 100644
--- a/p2pvr/devices/Jamfile.jam
+++ b/p2pvr/devices/Jamfile.jam
@@ -2,6 +2,7 @@ import type ;
import generators ;
lib boost_system ;
+lib boost_thread ;
lib boost_filesystem ;
lib lzma ;
@@ -49,6 +50,7 @@ lib p2pvrMockTuner :
:
<library>lzma
<library>boost_system
+ <library>boost_thread
<library>boost_filesystem
<library>../dvb//p2pvrdvb
<library>../ice//p2pvrice
diff --git a/p2pvr/devices/mockTuner.cpp b/p2pvr/devices/mockTuner.cpp
index 1cb1ce3..05a0437 100644
--- a/p2pvr/devices/mockTuner.cpp
+++ b/p2pvr/devices/mockTuner.cpp
@@ -21,6 +21,9 @@ ResourceFile(network);
ResourceFile(services);
ResourceFile(events1);
ResourceFile(events2);
+ResourceFile(pat);
+ResourceFile(pmt);
+ResourceFile(vid);
int MockTuner::eventSet = 0;
@@ -30,6 +33,11 @@ MockTuner::SetEventsSet(int n)
eventSet = n;
}
+MockTuner::MockTuner() :
+ senderId(1)
+{
+}
+
void MockTuner::TuneTo(const DVBSI::DeliveryPtr &, const Ice::Current&)
{
}
@@ -112,18 +120,53 @@ void MockTuner::SendEventInformation(const P2PVR::RawDataClientPrx & client, con
DecompressAndSendPackets(eventSet == 0 ? events1 : events2, client, ice);
}
-int MockTuner::StartSendingTS(const P2PVR::PacketIds &, const P2PVR::RawDataClientPrx &, const Ice::Current &)
+void MockTuner::SendLoop(const P2PVR::RawDataClientPrx & t, const Ice::ByteSeq & dataxz, const Ice::Current & ice) const
{
- return 0;
+ 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::StartSendingSection(Ice::Int, const P2PVR::RawDataClientPrx &, const Ice::Current &)
+
+int MockTuner::StartSendingTS(const P2PVR::PacketIds &, const P2PVR::RawDataClientPrx & t, const Ice::Current & ice)
{
- return 0;
+ 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, const Ice::Current &)
+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&)
diff --git a/p2pvr/devices/mockTuner.h b/p2pvr/devices/mockTuner.h
index 8e0c513..aa51580 100644
--- a/p2pvr/devices/mockTuner.h
+++ b/p2pvr/devices/mockTuner.h
@@ -3,9 +3,12 @@
#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&);
@@ -28,8 +31,11 @@ class MockTuner : public P2PVR::PrivateTuner {
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/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/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