summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--p2pvr/dvb/bindDataHandler.cpp12
-rw-r--r--p2pvr/dvb/bindDataHandler.h19
-rw-r--r--p2pvr/dvb/unittests/Jamfile.jam16
-rw-r--r--p2pvr/dvb/unittests/createBroadcast.cpp136
4 files changed, 183 insertions, 0 deletions
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 <boost/function.hpp>
+#include <dvb.h>
+
+class BindDataHandler : public P2PVR::RawDataClient {
+ public:
+ typedef boost::function<bool(const P2PVR::Data &)> 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 :
<define>ROOT=\"$(me)\"
;
+exe createBroadcast :
+ createBroadcast.cpp
+ :
+ <define>BOOST_TEST_DYN_LINK
+ <library>..//p2pvrdvb
+ <library>../../lib//p2pvrlib
+ <library>../../ice//p2pvrice
+ <library>IceUtil
+ <library>Ice
+ <library>boost_system
+ <library>boost_filesystem
+ <library>../..//boost_utf
+ <library>../..//p2ut
+ <define>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 <testOptionsSource.h>
+#include <boost/test/unit_test.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <boost/function.hpp>
+#include <boost/bind.hpp>
+#include <boost/tuple/tuple.hpp>
+#include <Ice/ObjectAdapter.h>
+#include <Ice/Service.h>
+#include <scopeObject.h>
+#include <linux/dvb/frontend.h>
+#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<P2PVR::RawDataClient> patp;
+ TemporaryIceAdapterObject<P2PVR::RawDataClient> pmtp;
+ TemporaryIceAdapterObject<P2PVR::RawDataClient> vidp;
+ ServiceStreamerCore ss;
+
+ typedef std::list<P2PVR::Data> 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();
+