diff options
-rw-r--r-- | p2pvr/lib/frontends/ofdm.cpp | 10 | ||||
-rw-r--r-- | p2pvr/lib/tuner.cpp | 26 | ||||
-rw-r--r-- | p2pvr/lib/tuner.h | 11 |
3 files changed, 37 insertions, 10 deletions
diff --git a/p2pvr/lib/frontends/ofdm.cpp b/p2pvr/lib/frontends/ofdm.cpp index fca94ae..2a219e9 100644 --- a/p2pvr/lib/frontends/ofdm.cpp +++ b/p2pvr/lib/frontends/ofdm.cpp @@ -45,9 +45,9 @@ class Frontend_OFDM : public Frontend { void WaitForLock() const { - fe_status status; - // Wait for something (500ms) - for (int x = 0; x < 50 && (status = GetStatus()) == 0; x += 1) { + fe_status_t status = (fe_status_t)0; + // Wait for something + for (int x = Tuner::TuningTimeout / 10; x > 0 && (status = GetStatus()) == 0; x -= 1) { usleep(10000); } // Was it useful? @@ -55,8 +55,8 @@ class Frontend_OFDM : public Frontend { Logger()->messagebf(LOG_ERR, "Tuning of device %s failed (%s)", tuner->Device(), "No carrier"); throw P2PVR::DeviceError(tuner->Device(), "No carrier", 0); } - // Wait for lock (4000ms) - for (int x = 0; x < 400 && ((status = GetStatus()) & FE_HAS_LOCK) == 0; x += 1) { + // Wait for lock + for (int x = Tuner::LockTimeout / 10; x > 0 && ((status = GetStatus()) & FE_HAS_LOCK) == 0; x -= 1) { usleep(10000); } if (!(status & FE_HAS_LOCK)) { diff --git a/p2pvr/lib/tuner.cpp b/p2pvr/lib/tuner.cpp index b958e31..bfa5a68 100644 --- a/p2pvr/lib/tuner.cpp +++ b/p2pvr/lib/tuner.cpp @@ -22,7 +22,6 @@ class FrontendNotSupported : public NotSupported { Tuner::Tuner(const boost::filesystem::path & df) : deviceFrontend(df), deviceRoot(df.branch_path()), - timeout(20000), backgroundThread(NULL), lastUsedTime(time(NULL)) { @@ -152,7 +151,7 @@ Tuner::SendPID(int pid, const P2PVR::RawDataClientPrx & client, const Ice::Curre void Tuner::RequestPID(int pid, int demux) { - setBufferSize(demux, 409600); + setBufferSize(demux, DemuxTableBufferSize); struct dmx_sct_filter_params sctFilterParams; memset(&sctFilterParams, 0, sizeof(dmx_sct_filter_params)); sctFilterParams.pid = pid; @@ -176,7 +175,7 @@ Tuner::ReadDemuxAndSend(int demux, const P2PVR::RawDataClientPrx & client) const memset(&ufd, 0, sizeof(pollfd)); ufd.fd = demux; ufd.events = POLLIN; - if (poll(&ufd, 1, timeout) < 1) { + if (poll(&ufd, 1, DemuxReadTimeout) < 1) { Logger()->messagebf(LOG_DEBUG, "%s: Timed out waiting for data", __PRETTY_FUNCTION__); break; } @@ -289,7 +288,7 @@ Tuner::StartSendingTS(const P2PVR::PacketIds & pids, const P2PVR::RawDataClientP } } - setBufferSize(demux, 4096000); + setBufferSize(demux, DemuxStreamBufferSize); if (ioctl(demux, DMX_START) < 0) { backgroundClients.erase(demux); Logger()->messagebf(LOG_ERR, "%s: DMX_START failed (%d: %s)", __PRETTY_FUNCTION__, errno, strerror(errno)); @@ -428,3 +427,22 @@ Tuner::crc32(const P2PVR::Data & buf) return crc.checksum() == 0; } +int Tuner::TuningTimeout; +int Tuner::LockTimeout; +int Tuner::DemuxReadTimeout; +int Tuner::DemuxTableBufferSize; +int Tuner::DemuxStreamBufferSize; + +DECLARE_OPTIONS(Tuner, "P2PVR Tuner Options") +("p2pvr.tuner.tuningtimeout", Options::value(&TuningTimeout, 500), + "Timeout for a DVB frontend to tune (ms, default 500ms)") +("p2pvr.tuner.locktimeout", Options::value(&LockTimeout, 2000), + "Timeout for a DVB frontend to acquire lock (ms, default 2000ms)") +("p2pvr.tuner.demuxreadtimeout", Options::value(&DemuxReadTimeout, 20000), + "Timeout when reading from a demux device (ms, default 20s)") +("p2pvr.tuner.demuxtablebuffersize", Options::value(&DemuxTableBufferSize, 256*1024), + "Kernel buffer size for demux table data (bytes, default 256KB)") +("p2pvr.tuner.demuxstreambuffersize", Options::value(&DemuxStreamBufferSize, 1024*1024), + "Kernel buffer size for demux stream data (bytes, default 1MB)") +END_OPTIONS(Tuner); + diff --git a/p2pvr/lib/tuner.h b/p2pvr/lib/tuner.h index 583b892..edd1a92 100644 --- a/p2pvr/lib/tuner.h +++ b/p2pvr/lib/tuner.h @@ -10,6 +10,7 @@ #include <boost/bind.hpp> #include <boost/function.hpp> #include <boost/tuple/tuple.hpp> +#include <options.h> class Tuner : public P2PVR::PrivateTuner { public: @@ -34,6 +35,8 @@ class Tuner : public P2PVR::PrivateTuner { Ice::Long GetLastUsedTime(const Ice::Current&); + INITOPTIONS; + private: static bool crc32(const P2PVR::Data &); int OpenDemux() const; @@ -47,7 +50,6 @@ class Tuner : public P2PVR::PrivateTuner { const boost::filesystem::path deviceFrontend; const boost::filesystem::path deviceRoot; - const int timeout; typedef boost::function<bool(const P2PVR::Data &)> PacketCheckFunction; typedef boost::tuple<P2PVR::RawDataClientPrx, PacketCheckFunction> BackgroundClient; typedef std::map<int, BackgroundClient> BackgroundClients; @@ -57,6 +59,13 @@ class Tuner : public P2PVR::PrivateTuner { mutable time_t lastUsedTime; FrontendPtr frontend; + + public: + static int TuningTimeout; + static int LockTimeout; + static int DemuxReadTimeout; + static int DemuxTableBufferSize; + static int DemuxStreamBufferSize; }; #endif |