From 5fe1f5a520fca2fd206b9f88922302115fb5c10e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 3 Feb 2015 20:58:13 +0000 Subject: Extend mock tuner to support basic streaming with sample of BBC One --- p2pvr/devices/Jamfile.jam | 2 ++ p2pvr/devices/mockTuner.cpp | 53 ++++++++++++++++++++++++++++--- p2pvr/devices/mockTuner.h | 6 ++++ p2pvr/devices/sampleSiData/pat.datxz | Bin 0 -> 160 bytes p2pvr/devices/sampleSiData/pmt.datxz | Bin 0 -> 208 bytes p2pvr/devices/sampleStreamData/vid.datxz | Bin 0 -> 2952196 bytes 6 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 p2pvr/devices/sampleSiData/pat.datxz create mode 100644 p2pvr/devices/sampleSiData/pmt.datxz create mode 100644 p2pvr/devices/sampleStreamData/vid.datxz 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 : : lzma boost_system + boost_thread boost_filesystem ../dvb//p2pvrdvb ../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 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 #include +#include 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 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 Binary files /dev/null and b/p2pvr/devices/sampleSiData/pat.datxz differ diff --git a/p2pvr/devices/sampleSiData/pmt.datxz b/p2pvr/devices/sampleSiData/pmt.datxz new file mode 100644 index 0000000..b883c0c Binary files /dev/null and b/p2pvr/devices/sampleSiData/pmt.datxz differ diff --git a/p2pvr/devices/sampleStreamData/vid.datxz b/p2pvr/devices/sampleStreamData/vid.datxz new file mode 100644 index 0000000..ec8ed6e Binary files /dev/null and b/p2pvr/devices/sampleStreamData/vid.datxz differ -- cgit v1.2.3