From c6c618cd72dc7276886105b13f59a6e80c90e822 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 31 Jan 2015 17:42:13 +0000 Subject: Add a test for creating sample video broadcast data --- p2pvr/dvb/bindDataHandler.cpp | 12 +++ p2pvr/dvb/bindDataHandler.h | 19 +++++ p2pvr/dvb/unittests/Jamfile.jam | 16 ++++ p2pvr/dvb/unittests/createBroadcast.cpp | 136 ++++++++++++++++++++++++++++++++ 4 files changed, 183 insertions(+) create mode 100644 p2pvr/dvb/bindDataHandler.cpp create mode 100644 p2pvr/dvb/bindDataHandler.h create mode 100644 p2pvr/dvb/unittests/createBroadcast.cpp diff --git a/p2pvr/dvb/bindDataHandler.cpp b/p2pvr/dvb/bindDataHandler.cpp new file mode 100644 index 0000000..cb4fd69 --- /dev/null +++ b/p2pvr/dvb/bindDataHandler.cpp @@ -0,0 +1,12 @@ +#include "bindDataHandler.h" + +BindDataHandler::BindDataHandler(const Callback & cb) : + callBack(cb) +{ +} + +bool BindDataHandler::NewData(const P2PVR::Data & data, const Ice::Current &) +{ + return callBack(data); +} + diff --git a/p2pvr/dvb/bindDataHandler.h b/p2pvr/dvb/bindDataHandler.h new file mode 100644 index 0000000..3805d7f --- /dev/null +++ b/p2pvr/dvb/bindDataHandler.h @@ -0,0 +1,19 @@ +#ifndef BINDDATAHANDLER_H +#define BINDDATAHANDLER_H + +#include +#include + +class BindDataHandler : public P2PVR::RawDataClient { + public: + typedef boost::function Callback; + BindDataHandler(const Callback & cb); + + bool NewData(const P2PVR::Data & data, const Ice::Current &) override; + + private: + const Callback callBack; +}; + +#endif + diff --git a/p2pvr/dvb/unittests/Jamfile.jam b/p2pvr/dvb/unittests/Jamfile.jam index 6e8cfbf..699cfcd 100644 --- a/p2pvr/dvb/unittests/Jamfile.jam +++ b/p2pvr/dvb/unittests/Jamfile.jam @@ -21,3 +21,19 @@ exe createSamples : ROOT=\"$(me)\" ; +exe createBroadcast : + createBroadcast.cpp + : + BOOST_TEST_DYN_LINK + ..//p2pvrdvb + ../../lib//p2pvrlib + ../../ice//p2pvrice + IceUtil + Ice + boost_system + boost_filesystem + ../..//boost_utf + ../..//p2ut + ROOT=\"$(me)\" + ; + diff --git a/p2pvr/dvb/unittests/createBroadcast.cpp b/p2pvr/dvb/unittests/createBroadcast.cpp new file mode 100644 index 0000000..c65c9ad --- /dev/null +++ b/p2pvr/dvb/unittests/createBroadcast.cpp @@ -0,0 +1,136 @@ +#define BOOST_TEST_MODULE CreateSamples +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "serviceStreamerCore.h" +#include "bindDataHandler.h" + +#define XSTR(s) STR(s) +#define STR(s) #s +const boost::filesystem::path root(XSTR(ROOT)); + +Ice::StringSeq params { + "--Ice.ThreadPool.Client.Size=5", + "--Ice.ThreadPool.Client.SizeMax=10", + "--Ice.ThreadPool.Server.Size=5", + "--Ice.ThreadPool.Server.SizeMax=10" + }; + +class Core { + public: + Core() : + ic(Ice::initialize(params)), + adapter(ic->createObjectAdapterWithEndpoints("Adp", "tcp -p 12003")) + { + TestOptionsSource::LoadTestOptions({ }); + adapter->activate(); + + devs = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy("Devices:tcp -h defiant -p 10000")); + BOOST_REQUIRE(devs); + devs->ice_ping(); + } + + ~Core() + { + ic->destroy(); + } + + P2PVR::DevicesPrx devs; + Ice::CommunicatorPtr ic; + Ice::ObjectAdapterPtr adapter; + +}; + +class Sampler { + public: + Sampler(int sid, P2PVR::DevicesPrx d, Ice::ObjectAdapterPtr a) : + patp(a, new BindDataHandler(boost::bind(&Sampler::Handle, this, _1, boost::ref(pat)))), + pmtp(a, new BindDataHandler(boost::bind(&Sampler::Handle, this, _1, boost::ref(pmt)))), + vidp(a, new BindDataHandler(boost::bind(&Sampler::Handle, this, _1, boost::ref(vid)))), + ss(sid, patp, pmtp, vidp, d, a) + { + } + + TemporaryIceAdapterObject patp; + TemporaryIceAdapterObject pmtp; + TemporaryIceAdapterObject vidp; + ServiceStreamerCore ss; + + typedef std::list Sampled; + Sampled pat, pmt, vid; + + bool Handle(const P2PVR::Data & data, Sampled & rec) + { + rec.push_back(data); + return false; + } + + void Start(DVBSI::DeliveryPtr transport) { ss.Start(transport); } + void Stop() { ss.Stop(); } + + void Save(Ice::CommunicatorPtr ic) + { + Save(ic, pat, "pat.dat"); + Save(ic, pmt, "pmt.dat"); + Save(ic, vid, "vid.dat"); + } + + private: + void Save(Ice::CommunicatorPtr ic, const Sampled & s, const boost::filesystem::path & fileName) + { + auto out = Ice::createOutputStream(ic); + out->write(s); + Ice::ByteSeq buf; + out->finished(buf); + BOOST_MESSAGE(root); + auto outFile = fopen((root / fileName).string().c_str(), "w"); + BOOST_REQUIRE(outFile); + BOOST_REQUIRE_EQUAL(1, fwrite(&buf.front(), buf.size(), 1, outFile)); + BOOST_REQUIRE_EQUAL(0, fclose(outFile)); + } + +}; + +BOOST_FIXTURE_TEST_SUITE( X, Core ) + +BOOST_AUTO_TEST_CASE( broadcast_sample ) +{ + DVBSI::TerrestrialDeliveryPtr transport = new DVBSI::TerrestrialDelivery { + 4170, 682000000, 0, true, true, true, 3, 0, 2, 1, 0, 1, true + }; + BOOST_REQUIRE_EQUAL(transport->Frequency, 682000000); + BOOST_REQUIRE_EQUAL(transport->TransmissionMode, 1); + + BOOST_CHECKPOINT("Acquire device"); + P2PVR::TunerPrx tuner = devs->GetTunerSpecific(transport); + BOOST_REQUIRE(tuner); + tuner->ice_ping(); + + BOOST_CHECKPOINT("Create sampler"); + Sampler sampler(4170, devs, adapter); + + BOOST_CHECKPOINT("Start stream"); + sampler.Start(transport); + + sleep(10); + + BOOST_CHECKPOINT("Stop stream"); + sampler.Stop(); + + BOOST_MESSAGE("PAT packets: " << sampler.pat.size()); + BOOST_MESSAGE("PMT packets: " << sampler.pmt.size()); + BOOST_MESSAGE("Vid packets: " << sampler.vid.size()); + + BOOST_CHECKPOINT("Save samples"); + sampler.Save(ic); +} + +BOOST_AUTO_TEST_SUITE_END(); + -- cgit v1.2.3