1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
#define BOOST_TEST_MODULE CreateSamples
#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/Initialize.h>
#include <Ice/Service.h>
#include <linux/dvb/frontend.h>
#include "serviceStreamerCore.h"
#include "bindDataHandler.h"
#include <definedDirs.h>
namespace P2PVR {
namespace Testing {
static 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"))
{
adapter->activate();
devs = Ice::checkedCast<TunersPrx>(ic->stringToProxy("Devices:tcp -h defiant -p 10000"));
BOOST_REQUIRE(devs);
devs->ice_ping();
}
~Core()
{
ic->destroy();
}
TunersPrxPtr devs;
Ice::CommunicatorPtr ic;
Ice::ObjectAdapterPtr adapter;
};
class Sampler {
public:
Sampler(int sid, TunersPrxPtr d, Ice::ObjectAdapterPtr a) :
patp(a, std::make_shared<DVBSI::BindDataHandler>(boost::bind(&Sampler::Handle, this, _1, boost::ref(pat)))),
pmtp(a, std::make_shared<DVBSI::BindDataHandler>(boost::bind(&Sampler::Handle, this, _1, boost::ref(pmt)))),
vidp(a, std::make_shared<DVBSI::BindDataHandler>(boost::bind(&Sampler::Handle, this, _1, boost::ref(vid)))),
ss(sid, patp, pmtp, vidp, d, a)
{
}
TemporaryIceAdapterObject<RawDataClient> patp;
TemporaryIceAdapterObject<RawDataClient> pmtp;
TemporaryIceAdapterObject<RawDataClient> vidp;
ServiceStreamerCore ss;
typedef std::list<Data> Sampled;
Sampled pat, pmt, vid;
bool Handle(const 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)
{
Ice::OutputStream out(ic);
out.write(s);
Ice::ByteSeq buf;
out.finished(buf);
BOOST_TEST_MESSAGE(rootDir);
auto outFile = fopen((rootDir / 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, P2PVR::Testing::Core )
BOOST_AUTO_TEST_CASE( broadcast_sample )
{
DVBSI::TerrestrialDeliveryPtr transport = std::make_shared<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_TEST_CHECKPOINT("Create sampler");
P2PVR::Testing::Sampler sampler(4170, devs, adapter);
BOOST_TEST_CHECKPOINT("Start stream");
sampler.Start(transport);
sleep(10);
BOOST_TEST_CHECKPOINT("Stop stream");
sampler.Stop();
BOOST_TEST_MESSAGE("PAT packets: " << sampler.pat.size());
BOOST_TEST_MESSAGE("PMT packets: " << sampler.pmt.size());
BOOST_TEST_MESSAGE("Vid packets: " << sampler.vid.size());
BOOST_TEST_CHECKPOINT("Save samples");
sampler.Save(ic);
}
BOOST_AUTO_TEST_SUITE_END();
|