summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--p2pvr/lib/serviceStreamer.cpp76
-rw-r--r--p2pvr/lib/serviceStreamer.h31
-rw-r--r--p2pvr/lib/serviceStreamerCore.cpp78
-rw-r--r--p2pvr/lib/serviceStreamerCore.h45
4 files changed, 135 insertions, 95 deletions
diff --git a/p2pvr/lib/serviceStreamer.cpp b/p2pvr/lib/serviceStreamer.cpp
index bd7c04c..db1ad50 100644
--- a/p2pvr/lib/serviceStreamer.cpp
+++ b/p2pvr/lib/serviceStreamer.cpp
@@ -1,29 +1,15 @@
#include <pch.hpp>
#include "serviceStreamer.h"
-#include <boost/bind.hpp>
-#include "bindSiParserHandler.h"
ServiceStreamer::ServiceStreamer(int sid, P2PVR::RawDataClientPrx t, const Ice::CommunicatorPtr & ic, const Ice::ObjectAdapterPtr & a) :
- adapter(a),
- devs(P2PVR::DevicesPrx::checkedCast(adapter->createProxy(ic->stringToIdentity("GlobalDevices")))),
- si(P2PVR::SIPrx::checkedCast(adapter->createProxy(ic->stringToIdentity("SI")))),
- target(t),
- patParser(adapter, new BindSiParserHandler<ProgramAssociationMapPtr, SiProgramAssociationParser>(boost::bind(&ServiceStreamer::HandlePAT, this, _1))),
- pmtParser(adapter, new BindSiParserHandler<DVBSI::ProgramMapPtr, SiProgramMapParser>(boost::bind(&ServiceStreamer::HandlePMT, this, _1))),
- serviceId(sid),
- patHandle(0), pmtStream(0), pmtHandle(0), serviceHandle(0)
+ ServiceStreamerCore(sid, t, t, t, P2PVR::DevicesPrx::checkedCast(adapter->createProxy(ic->stringToIdentity("GlobalDevices"))), a),
+ si(P2PVR::SIPrx::checkedCast(adapter->createProxy(ic->stringToIdentity("SI"))))
{
}
ServiceStreamer::ServiceStreamer(int sid, P2PVR::RawDataClientPrx t, const P2PVR::DevicesPrx & d, const P2PVR::SIPrx & s, const Ice::ObjectAdapterPtr & a) :
- adapter(a),
- devs(d),
- si(s),
- target(t),
- patParser(adapter, new BindSiParserHandler<ProgramAssociationMapPtr, SiProgramAssociationParser>(boost::bind(&ServiceStreamer::HandlePAT, this, _1))),
- pmtParser(adapter, new BindSiParserHandler<DVBSI::ProgramMapPtr, SiProgramMapParser>(boost::bind(&ServiceStreamer::HandlePMT, this, _1))),
- serviceId(sid),
- patHandle(0), pmtStream(0), pmtHandle(0), serviceHandle(0)
+ ServiceStreamerCore(sid, t, t, t, d, a),
+ si(s)
{
}
@@ -31,63 +17,17 @@ ServiceStreamer::~ServiceStreamer()
{
}
-bool
-ServiceStreamer::HandlePAT(ProgramAssociationMapPtr pam)
-{
- const auto p = pam->find(serviceId);
- if (p != pam->end() && p->second != pmtStream) {
- pmtStream = p->second;
- Logger()->messagef(LOG_DEBUG, "%s: Got ProgramAssociationMap, pmtStream now = %d", __PRETTY_FUNCTION__, pmtStream);
- stopHandle(pmtHandle);
- pmtHandle = tuner->StartSendingSection(pmtStream, pmtParser);
- }
- target->NewData(patParser.Get()->CurrentRawData());
- return false;
-}
-
-bool
-ServiceStreamer::HandlePMT(DVBSI::ProgramMapPtr pmp)
-{
- Streams strms;
- for (const auto & s : pmp->Streams) {
- if (s->Type >= 2 && s->Type <= 5) {
- strms.insert(s->Id);
- }
- }
- if (strms != streams) {
- streams = strms;
- Logger()->messagebf(LOG_DEBUG, "%s: Got ProgramMap, switching to %d streams", __PRETTY_FUNCTION__, streams.size());
- stopHandle(serviceHandle);
- serviceHandle = tuner->StartSendingTS(P2PVR::PacketIds(streams.begin(), streams.end()), target);
- }
- target->NewData(pmtParser.Get()->CurrentRawData());
- return false;
-}
-
void
-ServiceStreamer::Start()
+ServiceStreamerCore::Start(DVBSI::DeliveryPtr transport)
{
- const auto transport = si->GetDeliveryForService(serviceId);
tuner = devs->GetTunerSpecific(transport);
patHandle = tuner->StartSendingSection(0, patParser);
}
void
-ServiceStreamer::Stop()
-{
- stopHandle(serviceHandle);
- stopHandle(patHandle);
- stopHandle(pmtHandle);
- devs->ReleaseTuner(tuner);
- tuner = NULL;
-}
-
-void
-ServiceStreamer::stopHandle(int & handle)
+ServiceStreamer::Start()
{
- if (handle) {
- tuner->StopSending(handle);
- handle = 0;
- }
+ const auto transport = si->GetDeliveryForService(serviceId);
+ ServiceStreamerCore::Start(transport);
}
diff --git a/p2pvr/lib/serviceStreamer.h b/p2pvr/lib/serviceStreamer.h
index 9a7250f..bff14ec 100644
--- a/p2pvr/lib/serviceStreamer.h
+++ b/p2pvr/lib/serviceStreamer.h
@@ -1,43 +1,20 @@
#ifndef SERVICESTREAMER_H
#define SERVICESTREAMER_H
-#include <Ice/Communicator.h>
-#include <Ice/ObjectAdapter.h>
-#include "siParsers/programAssociation.h"
-#include "siParsers/programMap.h"
-#include "temporaryIceAdapterObject.h"
-#include <p2pvr.h>
-#include <set>
+#include "serviceStreamerCore.h"
-class ServiceStreamer {
+class ServiceStreamer : public ServiceStreamerCore {
public:
ServiceStreamer(int sid, P2PVR::RawDataClientPrx, const Ice::CommunicatorPtr & ic, const Ice::ObjectAdapterPtr & a);
ServiceStreamer(int sid, P2PVR::RawDataClientPrx, const P2PVR::DevicesPrx & d, const P2PVR::SIPrx & s, const Ice::ObjectAdapterPtr & a);
~ServiceStreamer();
- bool HandlePAT(ProgramAssociationMapPtr pam);
- bool HandlePMT(DVBSI::ProgramMapPtr pmp);
void Start();
- void Stop();
- private:
- void stopHandle(int & handle);
- const Ice::ObjectAdapterPtr & adapter;
- P2PVR::DevicesPrx devs;
+ private:
P2PVR::SIPrx si;
- P2PVR::TunerPrx tuner;
- P2PVR::RawDataClientPrx target;
- TemporaryIceAdapterObject<SiTableParserBase> patParser;
- TemporaryIceAdapterObject<SiTableParserBase> pmtParser;
-
- int serviceId;
- int patHandle;
- int pmtStream;
- int pmtHandle;
- typedef std::set<int> Streams;
- Streams streams;
- int serviceHandle;
};
+
typedef boost::shared_ptr<ServiceStreamer> ServiceStreamerPtr;
#endif
diff --git a/p2pvr/lib/serviceStreamerCore.cpp b/p2pvr/lib/serviceStreamerCore.cpp
new file mode 100644
index 0000000..3328088
--- /dev/null
+++ b/p2pvr/lib/serviceStreamerCore.cpp
@@ -0,0 +1,78 @@
+#include <pch.hpp>
+#include "serviceStreamerCore.h"
+#include <boost/bind.hpp>
+#include "bindSiParserHandler.h"
+
+ServiceStreamerCore::ServiceStreamerCore(int sid, P2PVR::RawDataClientPrx pat, P2PVR::RawDataClientPrx pmt, P2PVR::RawDataClientPrx ser,
+ P2PVR::DevicesPrx d, Ice::ObjectAdapterPtr a) :
+ adapter(a),
+ devs(d),
+ patTarget(pat),
+ pmtTarget(pmt),
+ serTarget(ser),
+ patParser(adapter, new BindSiParserHandler<ProgramAssociationMapPtr, SiProgramAssociationParser>(boost::bind(&ServiceStreamerCore::HandlePAT, this, _1))),
+ pmtParser(adapter, new BindSiParserHandler<DVBSI::ProgramMapPtr, SiProgramMapParser>(boost::bind(&ServiceStreamerCore::HandlePMT, this, _1))),
+ serviceId(sid),
+ patHandle(0), pmtStream(0), pmtHandle(0), serviceHandle(0)
+{
+
+}
+
+ServiceStreamerCore::~ServiceStreamerCore()
+{
+}
+
+bool
+ServiceStreamerCore::HandlePAT(ProgramAssociationMapPtr pam)
+{
+ const auto p = pam->find(serviceId);
+ if (p != pam->end() && p->second != pmtStream) {
+ pmtStream = p->second;
+ Logger()->messagef(LOG_DEBUG, "%s: Got ProgramAssociationMap, pmtStream now = %d", __PRETTY_FUNCTION__, pmtStream);
+ stopHandle(pmtHandle);
+ pmtHandle = tuner->StartSendingSection(pmtStream, pmtParser);
+ }
+ Logger()->messagef(LOG_DEBUG, "%s: forward", __PRETTY_FUNCTION__);
+ patTarget->NewData(patParser.Get()->CurrentRawData());
+ Logger()->messagef(LOG_DEBUG, "%s: forwarded", __PRETTY_FUNCTION__);
+ return false;
+}
+
+bool
+ServiceStreamerCore::HandlePMT(DVBSI::ProgramMapPtr pmp)
+{
+ Streams strms;
+ for (const auto & s : pmp->Streams) {
+ if (s->Type >= 2 && s->Type <= 5) {
+ strms.insert(s->Id);
+ }
+ }
+ if (strms != streams) {
+ streams = strms;
+ Logger()->messagebf(LOG_DEBUG, "%s: Got ProgramMap, switching to %d streams", __PRETTY_FUNCTION__, streams.size());
+ stopHandle(serviceHandle);
+ serviceHandle = tuner->StartSendingTS(P2PVR::PacketIds(streams.begin(), streams.end()), serTarget);
+ }
+ pmtTarget->NewData(pmtParser.Get()->CurrentRawData());
+ return false;
+}
+
+void
+ServiceStreamerCore::Stop()
+{
+ stopHandle(serviceHandle);
+ stopHandle(patHandle);
+ stopHandle(pmtHandle);
+ devs->ReleaseTuner(tuner);
+ tuner = NULL;
+}
+
+void
+ServiceStreamerCore::stopHandle(int & handle)
+{
+ if (handle) {
+ tuner->StopSending(handle);
+ handle = 0;
+ }
+}
+
diff --git a/p2pvr/lib/serviceStreamerCore.h b/p2pvr/lib/serviceStreamerCore.h
new file mode 100644
index 0000000..4af422a
--- /dev/null
+++ b/p2pvr/lib/serviceStreamerCore.h
@@ -0,0 +1,45 @@
+#ifndef SERVICESTREAMERCORE_H
+#define SERVICESTREAMERCORE_H
+
+#include <Ice/Communicator.h>
+#include <Ice/ObjectAdapter.h>
+#include "siParsers/programAssociation.h"
+#include "siParsers/programMap.h"
+#include "temporaryIceAdapterObject.h"
+#include <p2pvr.h>
+#include <set>
+
+class ServiceStreamerCore {
+ public:
+ ServiceStreamerCore(int sid, P2PVR::RawDataClientPrx, P2PVR::RawDataClientPrx, P2PVR::RawDataClientPrx,
+ P2PVR::DevicesPrx, Ice::ObjectAdapterPtr);
+ virtual ~ServiceStreamerCore();
+
+ void Start(DVBSI::DeliveryPtr);
+ void Stop();
+
+ protected:
+ bool HandlePAT(ProgramAssociationMapPtr pam);
+ bool HandlePMT(DVBSI::ProgramMapPtr pmp);
+ void stopHandle(int & handle);
+
+ const Ice::ObjectAdapterPtr & adapter;
+ P2PVR::DevicesPrx devs;
+ P2PVR::RawDataClientPrx patTarget;
+ P2PVR::RawDataClientPrx pmtTarget;
+ P2PVR::RawDataClientPrx serTarget;
+ TemporaryIceAdapterObject<SiTableParserBase> patParser;
+ TemporaryIceAdapterObject<SiTableParserBase> pmtParser;
+ P2PVR::TunerPrx tuner;
+
+ int serviceId;
+ int patHandle;
+ int pmtStream;
+ int pmtHandle;
+ typedef std::set<int> Streams;
+ Streams streams;
+ int serviceHandle;
+};
+
+#endif
+