summaryrefslogtreecommitdiff
path: root/p2pvr/lib/tuner.h
blob: 4efde20e5f830d992beaa720c7e9a06b5ff427e8 (plain)
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
#ifndef P2PVR_TUNER_H
#define P2PVR_TUNER_H

#include <p2pvr.h>
#include <boost/filesystem/path.hpp>
#include "frontend.h"
#include <map>
#include <thread>
#include <mutex>
#include <boost/bind.hpp>

class Tuner : public P2PVR::PrivateTuner {
	public:
		Tuner(const boost::filesystem::path & deviceFrontend);
		~Tuner();

		void TuneTo(const DVBSI::DeliveryPtr &, const Ice::Current&);
		int GetStatus(const Ice::Current&);
		std::string Device() const;

		void ScanAndSendNetworkInformation(const P2PVR::RawDataClientPrx & client, const Ice::Current&);
		void SendNetworkInformation(const P2PVR::RawDataClientPrx & client, const Ice::Current&);
		void SendBouquetAssociations(const P2PVR::RawDataClientPrx & client, const Ice::Current&);
		void SendServiceDescriptions(const P2PVR::RawDataClientPrx & client, const Ice::Current&);
		void SendProgramMap(Ice::Int pid, const P2PVR::RawDataClientPrx & client, const Ice::Current&);
		void SendProgramAssociationTable(const P2PVR::RawDataClientPrx & client, const Ice::Current&);
		void SendEventInformation(const P2PVR::RawDataClientPrx & client, const Ice::Current&);

		int StartSendingTS(const P2PVR::PacketIds & pids, const P2PVR::RawDataClientPrx & client, const Ice::Current &);
		void StopSendingTS(int handle, const Ice::Current &);

	private:
		static bool crc32(const P2PVR::Data &);
		int OpenDemux() const;
		uint64_t SendPID(int pid, const P2PVR::RawDataClientPrx & client, const Ice::Current &) const;
		uint64_t ReadDemuxAndSend(int fd, const P2PVR::RawDataClientPrx & client) const;
		void startSenderThread();
		void senderThread();

		const boost::filesystem::path deviceFrontend;
		const boost::filesystem::path deviceRoot;
		const int timeout;
		typedef std::map<int, P2PVR::RawDataClientPrx> BackgroundClients;
		BackgroundClients backgroundClients;
		std::thread * backgroundThread;
		std::mutex lock;

		FrontendPtr frontend;
};

#endif