2014-03-08 12:07:47 +01:00
|
|
|
/*
|
|
|
|
* tuner.c: SAT>IP plugin for the Video Disk Recorder
|
|
|
|
*
|
|
|
|
* See the README file for copyright information and how to reach the author.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-12-07 19:17:30 +01:00
|
|
|
#define __STDC_FORMAT_MACROS // Required for format specifiers
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
2014-03-08 12:07:47 +01:00
|
|
|
#include "common.h"
|
|
|
|
#include "config.h"
|
2014-03-13 17:23:55 +01:00
|
|
|
#include "discover.h"
|
2014-12-05 22:14:40 +01:00
|
|
|
#include "log.h"
|
2014-11-11 19:23:41 +01:00
|
|
|
#include "poller.h"
|
2014-03-08 12:07:47 +01:00
|
|
|
#include "tuner.h"
|
|
|
|
|
|
|
|
cSatipTuner::cSatipTuner(cSatipDeviceIf &deviceP, unsigned int packetLenP)
|
2014-12-14 20:39:13 +01:00
|
|
|
: cThread(cString::sprintf("SATIP#%d tuner", deviceP.GetId())),
|
2014-03-08 12:07:47 +01:00
|
|
|
sleepM(),
|
|
|
|
deviceM(&deviceP),
|
2014-11-10 22:31:30 +01:00
|
|
|
deviceIdM(deviceP.GetId()),
|
2014-11-16 15:39:20 +01:00
|
|
|
rtspM(*this),
|
2014-12-13 22:15:58 +01:00
|
|
|
rtpM(*this),
|
|
|
|
rtcpM(*this),
|
2014-03-08 12:07:47 +01:00
|
|
|
streamAddrM(""),
|
|
|
|
streamParamM(""),
|
2015-02-16 16:21:00 +01:00
|
|
|
currentServerM(NULL, deviceP.GetId(), 0),
|
|
|
|
nextServerM(NULL, deviceP.GetId(), 0),
|
2014-03-08 12:07:47 +01:00
|
|
|
mutexM(),
|
2014-11-16 14:38:23 +01:00
|
|
|
reConnectM(),
|
2014-03-08 12:07:47 +01:00
|
|
|
keepAliveM(),
|
2014-11-05 20:55:40 +01:00
|
|
|
statusUpdateM(),
|
2014-03-08 12:07:47 +01:00
|
|
|
pidUpdateCacheM(),
|
2014-05-14 21:14:59 +02:00
|
|
|
sessionM(""),
|
2014-11-17 21:59:01 +01:00
|
|
|
currentStateM(tsIdle),
|
2014-11-23 21:22:38 +01:00
|
|
|
internalStateM(),
|
|
|
|
externalStateM(),
|
2014-03-31 21:07:15 +02:00
|
|
|
timeoutM(eMinKeepAliveIntervalMs),
|
2014-03-08 12:07:47 +01:00
|
|
|
hasLockM(false),
|
|
|
|
signalStrengthM(-1),
|
|
|
|
signalQualityM(-1),
|
2015-01-19 23:35:46 +01:00
|
|
|
frontendIdM(-1),
|
2014-03-08 12:07:47 +01:00
|
|
|
streamIdM(-1),
|
2015-01-05 23:58:35 +01:00
|
|
|
pmtPidM(-1),
|
2014-04-19 16:27:47 +02:00
|
|
|
addPidsM(),
|
|
|
|
delPidsM(),
|
2014-03-08 12:07:47 +01:00
|
|
|
pidsM()
|
|
|
|
{
|
2014-12-07 16:27:53 +01:00
|
|
|
debug1("%s (, %d) [device %d]", __PRETTY_FUNCTION__, packetLenP, deviceIdM);
|
2014-11-09 11:51:52 +01:00
|
|
|
|
|
|
|
// Open sockets
|
|
|
|
int i = 100;
|
|
|
|
while (i-- > 0) {
|
2014-11-16 15:39:20 +01:00
|
|
|
if (rtpM.Open(0) && rtcpM.Open(rtpM.Port() + 1))
|
2014-11-09 11:51:52 +01:00
|
|
|
break;
|
2014-11-16 15:39:20 +01:00
|
|
|
rtpM.Close();
|
|
|
|
rtcpM.Close();
|
2014-11-09 11:51:52 +01:00
|
|
|
}
|
2014-11-16 15:39:20 +01:00
|
|
|
if ((rtpM.Port() <= 0) || (rtcpM.Port() <= 0)) {
|
2014-11-09 11:51:52 +01:00
|
|
|
error("Cannot open required RTP/RTCP ports [device %d]", deviceIdM);
|
|
|
|
}
|
2014-11-11 19:23:41 +01:00
|
|
|
// Must be done after socket initialization!
|
2014-11-16 15:39:20 +01:00
|
|
|
cSatipPoller::GetInstance()->Register(rtpM);
|
|
|
|
cSatipPoller::GetInstance()->Register(rtcpM);
|
2014-11-09 19:32:08 +01:00
|
|
|
|
2014-03-08 12:07:47 +01:00
|
|
|
// Start thread
|
|
|
|
Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
cSatipTuner::~cSatipTuner()
|
|
|
|
{
|
2014-12-06 16:02:45 +01:00
|
|
|
debug1("%s [device %d]", __PRETTY_FUNCTION__, deviceIdM);
|
2014-11-14 21:28:27 +01:00
|
|
|
|
2014-03-08 12:07:47 +01:00
|
|
|
// Stop thread
|
|
|
|
sleepM.Signal();
|
|
|
|
if (Running())
|
|
|
|
Cancel(3);
|
|
|
|
Close();
|
2014-11-23 21:22:38 +01:00
|
|
|
currentStateM = tsIdle;
|
|
|
|
internalStateM.Clear();
|
|
|
|
externalStateM.Clear();
|
2014-11-09 11:51:52 +01:00
|
|
|
|
|
|
|
// Close the listening sockets
|
2014-11-16 15:39:20 +01:00
|
|
|
cSatipPoller::GetInstance()->Unregister(rtcpM);
|
|
|
|
cSatipPoller::GetInstance()->Unregister(rtpM);
|
|
|
|
rtcpM.Close();
|
|
|
|
rtpM.Close();
|
2014-03-08 12:07:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cSatipTuner::Action(void)
|
|
|
|
{
|
2014-12-06 16:02:45 +01:00
|
|
|
debug1("%s Entering [device %d]", __PRETTY_FUNCTION__, deviceIdM);
|
2015-05-23 14:28:37 +02:00
|
|
|
|
|
|
|
bool lastIdleStatus = false;
|
|
|
|
cTimeMs idleCheck(eIdleCheckTimeoutMs);
|
2015-08-16 00:10:52 +02:00
|
|
|
cTimeMs tuning(eTuningTimeoutMs);
|
2014-11-16 14:38:23 +01:00
|
|
|
reConnectM.Set(eConnectTimeoutMs);
|
2014-03-08 12:07:47 +01:00
|
|
|
// Do the thread loop
|
2014-11-11 19:23:41 +01:00
|
|
|
while (Running()) {
|
2014-11-23 21:22:38 +01:00
|
|
|
UpdateCurrentState();
|
2014-11-17 21:59:01 +01:00
|
|
|
switch (currentStateM) {
|
2014-11-15 19:15:00 +01:00
|
|
|
case tsIdle:
|
2014-12-06 16:02:45 +01:00
|
|
|
debug4("%s: tsIdle [device %d]", __PRETTY_FUNCTION__, deviceIdM);
|
2014-11-15 19:15:00 +01:00
|
|
|
break;
|
|
|
|
case tsRelease:
|
2014-12-06 16:02:45 +01:00
|
|
|
debug4("%s: tsRelease [device %d]", __PRETTY_FUNCTION__, deviceIdM);
|
2014-11-15 19:15:00 +01:00
|
|
|
Disconnect();
|
2014-11-23 21:22:38 +01:00
|
|
|
RequestState(tsIdle, smInternal);
|
2014-11-15 19:15:00 +01:00
|
|
|
break;
|
|
|
|
case tsSet:
|
2014-12-06 16:02:45 +01:00
|
|
|
debug4("%s: tsSet [device %d]", __PRETTY_FUNCTION__, deviceIdM);
|
2014-11-15 19:15:00 +01:00
|
|
|
if (Connect()) {
|
2015-08-16 00:10:52 +02:00
|
|
|
tuning.Set(eTuningTimeoutMs);
|
2014-11-23 21:22:38 +01:00
|
|
|
RequestState(tsTuned, smInternal);
|
2014-11-15 19:15:00 +01:00
|
|
|
UpdatePids(true);
|
|
|
|
}
|
2014-12-16 21:35:49 +01:00
|
|
|
else
|
2014-12-03 00:42:33 +01:00
|
|
|
Disconnect();
|
2014-11-15 19:15:00 +01:00
|
|
|
break;
|
|
|
|
case tsTuned:
|
2014-12-06 16:02:45 +01:00
|
|
|
debug4("%s: tsTuned [device %d]", __PRETTY_FUNCTION__, deviceIdM);
|
2014-11-16 14:38:23 +01:00
|
|
|
reConnectM.Set(eConnectTimeoutMs);
|
2015-05-23 14:28:37 +02:00
|
|
|
idleCheck.Set(eIdleCheckTimeoutMs);
|
|
|
|
lastIdleStatus = false;
|
2014-11-22 19:06:56 +01:00
|
|
|
// Read reception statistics via DESCRIBE and RTCP
|
|
|
|
if (hasLockM || ReadReceptionStatus()) {
|
|
|
|
// Quirk for devices without valid reception data
|
2015-01-15 22:33:51 +01:00
|
|
|
if (currentServerM.IsQuirk(cSatipServer::eSatipQuirkForceLock)) {
|
2014-11-22 19:06:56 +01:00
|
|
|
hasLockM = true;
|
|
|
|
signalStrengthM = eDefaultSignalStrength;
|
|
|
|
signalQualityM = eDefaultSignalQuality;
|
|
|
|
}
|
|
|
|
if (hasLockM)
|
2014-11-23 21:22:38 +01:00
|
|
|
RequestState(tsLocked, smInternal);
|
2014-11-15 19:15:00 +01:00
|
|
|
}
|
2015-08-16 00:10:52 +02:00
|
|
|
else if (tuning.TimedOut()) {
|
|
|
|
error("Tuning timeout - retuning [device %d]", deviceIdM);
|
|
|
|
RequestState(tsSet, smInternal);
|
|
|
|
}
|
2014-11-15 19:15:00 +01:00
|
|
|
break;
|
|
|
|
case tsLocked:
|
2014-12-06 16:02:45 +01:00
|
|
|
debug4("%s: tsLocked [device %d]", __PRETTY_FUNCTION__, deviceIdM);
|
2014-11-15 19:15:00 +01:00
|
|
|
if (!UpdatePids()) {
|
2014-12-03 00:42:33 +01:00
|
|
|
error("Pid update failed - retuning [device %d]", deviceIdM);
|
2014-11-23 21:22:38 +01:00
|
|
|
RequestState(tsSet, smInternal);
|
2014-11-15 19:15:00 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!KeepAlive()) {
|
2014-12-03 00:42:33 +01:00
|
|
|
error("Keep-alive failed - retuning [device %d]", deviceIdM);
|
2014-11-23 21:22:38 +01:00
|
|
|
RequestState(tsSet, smInternal);
|
2014-11-15 19:15:00 +01:00
|
|
|
break;
|
|
|
|
}
|
2014-11-16 14:38:23 +01:00
|
|
|
if (reConnectM.TimedOut()) {
|
2014-12-03 00:42:33 +01:00
|
|
|
error("Connection timeout - retuning [device %d]", deviceIdM);
|
2014-11-23 21:22:38 +01:00
|
|
|
RequestState(tsSet, smInternal);
|
2014-11-15 19:15:00 +01:00
|
|
|
break;
|
|
|
|
}
|
2015-05-23 14:28:37 +02:00
|
|
|
if (idleCheck.TimedOut()) {
|
|
|
|
bool currentIdleStatus = deviceM->IsIdle();
|
|
|
|
if (lastIdleStatus && currentIdleStatus) {
|
2015-05-22 21:42:11 +02:00
|
|
|
info("Idle timeout - releasing [device %d]", deviceIdM);
|
|
|
|
RequestState(tsRelease, smInternal);
|
|
|
|
}
|
2015-05-23 14:28:37 +02:00
|
|
|
lastIdleStatus = currentIdleStatus;
|
|
|
|
idleCheck.Set(eIdleCheckTimeoutMs);
|
2015-05-22 21:42:11 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-11-15 19:15:00 +01:00
|
|
|
break;
|
|
|
|
default:
|
2014-11-17 21:59:01 +01:00
|
|
|
error("Unknown tuner status %d [device %d]", currentStateM, deviceIdM);
|
2014-11-15 19:15:00 +01:00
|
|
|
break;
|
|
|
|
}
|
2014-11-19 20:01:45 +01:00
|
|
|
if (!StateRequested())
|
|
|
|
sleepM.Wait(eSleepTimeoutMs); // to avoid busy loop and reduce cpu load
|
2014-03-08 12:07:47 +01:00
|
|
|
}
|
2014-12-06 16:02:45 +01:00
|
|
|
debug1("%s Exiting [device %d]", __PRETTY_FUNCTION__, deviceIdM);
|
2014-03-08 12:07:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cSatipTuner::Open(void)
|
|
|
|
{
|
2014-11-15 19:15:00 +01:00
|
|
|
cMutexLock MutexLock(&mutexM);
|
2014-12-06 16:02:45 +01:00
|
|
|
debug1("%s [device %d]", __PRETTY_FUNCTION__, deviceIdM);
|
2014-11-17 21:59:01 +01:00
|
|
|
|
2014-11-23 21:22:38 +01:00
|
|
|
RequestState(tsSet, smExternal);
|
2014-11-17 21:59:01 +01:00
|
|
|
|
|
|
|
// return always true
|
2014-11-15 19:15:00 +01:00
|
|
|
return true;
|
2014-03-08 12:07:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cSatipTuner::Close(void)
|
|
|
|
{
|
2014-11-15 19:15:00 +01:00
|
|
|
cMutexLock MutexLock(&mutexM);
|
2014-12-06 16:02:45 +01:00
|
|
|
debug1("%s [device %d]", __PRETTY_FUNCTION__, deviceIdM);
|
2014-11-17 21:59:01 +01:00
|
|
|
|
2014-11-23 21:22:38 +01:00
|
|
|
RequestState(tsRelease, smExternal);
|
2014-11-17 21:59:01 +01:00
|
|
|
|
|
|
|
// return always true
|
2014-11-15 19:15:00 +01:00
|
|
|
return true;
|
2014-03-08 12:07:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cSatipTuner::Connect(void)
|
|
|
|
{
|
|
|
|
cMutexLock MutexLock(&mutexM);
|
2014-12-06 16:02:45 +01:00
|
|
|
debug1("%s [device %d]", __PRETTY_FUNCTION__, deviceIdM);
|
2014-03-08 12:07:47 +01:00
|
|
|
|
2014-11-09 11:51:52 +01:00
|
|
|
if (!isempty(*streamAddrM)) {
|
2014-12-03 00:42:33 +01:00
|
|
|
cString connectionUri = cString::sprintf("rtsp://%s/", *streamAddrM);
|
2014-03-08 12:07:47 +01:00
|
|
|
// Just retune
|
2014-11-17 21:59:01 +01:00
|
|
|
if (streamIdM >= 0) {
|
2014-12-03 00:42:33 +01:00
|
|
|
cString uri = cString::sprintf("%sstream=%d?%s", *connectionUri, streamIdM, *streamParamM);
|
2014-12-06 16:02:45 +01:00
|
|
|
debug1("%s Retuning [device %d]", __PRETTY_FUNCTION__, deviceIdM);
|
2014-12-02 22:17:35 +01:00
|
|
|
if (rtspM.Play(*uri)) {
|
2014-11-22 22:17:32 +01:00
|
|
|
keepAliveM.Set(timeoutM);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (rtspM.Options(*connectionUri)) {
|
2014-12-03 00:42:33 +01:00
|
|
|
cString uri = cString::sprintf("%s?%s", *connectionUri, *streamParamM);
|
2014-03-08 12:07:47 +01:00
|
|
|
// Flush any old content
|
2015-02-20 19:51:31 +01:00
|
|
|
//rtpM.Flush();
|
|
|
|
//rtcpM.Flush();
|
2014-11-16 15:39:20 +01:00
|
|
|
if (rtspM.Setup(*uri, rtpM.Port(), rtcpM.Port())) {
|
2014-11-22 22:17:32 +01:00
|
|
|
keepAliveM.Set(timeoutM);
|
2015-01-15 22:33:51 +01:00
|
|
|
if (nextServerM.IsValid()) {
|
2014-11-09 19:32:08 +01:00
|
|
|
currentServerM = nextServerM;
|
2015-01-15 22:33:51 +01:00
|
|
|
nextServerM.Reset();
|
2014-11-09 19:32:08 +01:00
|
|
|
}
|
2015-02-16 16:21:00 +01:00
|
|
|
currentServerM.Attach();
|
2014-11-15 19:15:00 +01:00
|
|
|
return true;
|
2014-11-15 21:05:46 +01:00
|
|
|
}
|
2014-11-05 20:55:40 +01:00
|
|
|
}
|
2015-06-04 17:49:03 +02:00
|
|
|
rtspM.Reset();
|
2014-11-22 13:56:20 +01:00
|
|
|
streamIdM = -1;
|
2014-11-15 21:05:46 +01:00
|
|
|
error("Connect failed [device %d]", deviceIdM);
|
2014-03-08 12:07:47 +01:00
|
|
|
}
|
|
|
|
|
2014-11-15 19:15:00 +01:00
|
|
|
return false;
|
2014-03-08 12:07:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cSatipTuner::Disconnect(void)
|
|
|
|
{
|
|
|
|
cMutexLock MutexLock(&mutexM);
|
2014-12-06 16:02:45 +01:00
|
|
|
debug1("%s [device %d]", __PRETTY_FUNCTION__, deviceIdM);
|
2014-03-08 12:07:47 +01:00
|
|
|
|
2014-11-17 21:59:01 +01:00
|
|
|
if (!isempty(*streamAddrM) && (streamIdM >= 0)) {
|
2014-11-09 11:51:52 +01:00
|
|
|
cString uri = cString::sprintf("rtsp://%s/stream=%d", *streamAddrM, streamIdM);
|
2014-11-16 15:39:20 +01:00
|
|
|
rtspM.Teardown(*uri);
|
2015-01-05 19:11:41 +01:00
|
|
|
// some devices requires a teardown for TCP connection also
|
|
|
|
rtspM.Reset();
|
2014-11-22 23:13:15 +01:00
|
|
|
streamIdM = -1;
|
2014-03-08 12:07:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reset signal parameters
|
|
|
|
hasLockM = false;
|
|
|
|
signalStrengthM = -1;
|
|
|
|
signalQualityM = -1;
|
2015-01-19 23:35:46 +01:00
|
|
|
frontendIdM = -1;
|
2014-03-08 12:07:47 +01:00
|
|
|
|
2015-02-16 16:21:00 +01:00
|
|
|
currentServerM.Detach();
|
2014-11-05 20:55:40 +01:00
|
|
|
statusUpdateM.Set(0);
|
2014-03-31 21:07:15 +02:00
|
|
|
timeoutM = eMinKeepAliveIntervalMs;
|
2015-01-05 23:58:35 +01:00
|
|
|
pmtPidM = -1;
|
2014-04-19 16:27:47 +02:00
|
|
|
addPidsM.Clear();
|
|
|
|
delPidsM.Clear();
|
2014-03-08 12:07:47 +01:00
|
|
|
|
2014-11-05 20:55:40 +01:00
|
|
|
// return always true
|
2014-03-08 12:07:47 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-16 14:38:23 +01:00
|
|
|
void cSatipTuner::ProcessVideoData(u_char *bufferP, int lengthP)
|
|
|
|
{
|
2014-12-14 16:45:55 +01:00
|
|
|
debug16("%s (, %d) [device %d]", __PRETTY_FUNCTION__, lengthP, deviceIdM);
|
2014-11-16 15:30:45 +01:00
|
|
|
if (lengthP > 0) {
|
2014-12-07 19:17:30 +01:00
|
|
|
uint64_t elapsed;
|
|
|
|
cTimeMs processing(0);
|
|
|
|
|
2014-11-16 15:30:45 +01:00
|
|
|
AddTunerStatistic(lengthP);
|
2014-12-07 19:17:30 +01:00
|
|
|
elapsed = processing.Elapsed();
|
|
|
|
if (elapsed > 1)
|
|
|
|
debug6("%s AddTunerStatistic() took %" PRIu64 " ms [device %d]", __PRETTY_FUNCTION__, elapsed, deviceIdM);
|
|
|
|
|
|
|
|
processing.Set(0);
|
2014-11-16 14:38:23 +01:00
|
|
|
deviceM->WriteData(bufferP, lengthP);
|
2014-12-07 19:17:30 +01:00
|
|
|
elapsed = processing.Elapsed();
|
|
|
|
if (elapsed > 1)
|
|
|
|
debug6("%s WriteData() took %" PRIu64 " ms [device %d]", __FUNCTION__, elapsed, deviceIdM);
|
2014-11-16 15:30:45 +01:00
|
|
|
}
|
2014-11-16 14:38:23 +01:00
|
|
|
reConnectM.Set(eConnectTimeoutMs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cSatipTuner::ProcessApplicationData(u_char *bufferP, int lengthP)
|
2014-03-08 12:07:47 +01:00
|
|
|
{
|
2014-12-14 16:45:55 +01:00
|
|
|
debug16("%s (%d) [device %d]", __PRETTY_FUNCTION__, lengthP, deviceIdM);
|
2014-03-08 12:07:47 +01:00
|
|
|
// DVB-S2:
|
|
|
|
// ver=<major>.<minor>;src=<srcID>;tuner=<feID>,<level>,<lock>,<quality>,<frequency>,<polarisation>,<system>,<type>,<pilots>,<roll_off>,<symbol_rate>,<fec_inner>;pids=<pid0>,...,<pidn>
|
|
|
|
// DVB-T2:
|
|
|
|
// ver=1.1;tuner=<feID>,<level>,<lock>,<quality>,<freq>,<bw>,<msys>,<tmode>,<mtype>,<gi>,<fec>,<plp>,<t2id>,<sm>;pids=<pid0>,...,<pidn>
|
2014-11-20 21:30:18 +01:00
|
|
|
// DVB-C2:
|
|
|
|
// ver=1.2;tuner=<feID>,<level>,<lock>,<quality>,<freq>,<bw>,<msys>,<mtype>,<sr>,<c2tft>,<ds>,<plp>,<specinv>;pids=<pid0>,...,<pidn>
|
2014-11-14 21:28:27 +01:00
|
|
|
if (lengthP > 0) {
|
2014-11-29 19:16:59 +01:00
|
|
|
char s[lengthP];
|
|
|
|
memcpy(s, (char *)bufferP, lengthP);
|
2014-12-14 18:22:52 +01:00
|
|
|
debug10("%s (%s) [device %d]", __PRETTY_FUNCTION__, s, deviceIdM);
|
2014-03-08 12:07:47 +01:00
|
|
|
char *c = strstr(s, ";tuner=");
|
|
|
|
if (c) {
|
|
|
|
int value;
|
|
|
|
|
2015-01-19 23:35:46 +01:00
|
|
|
// feID:
|
|
|
|
frontendIdM = atoi(c + 7);
|
|
|
|
|
2014-03-08 12:07:47 +01:00
|
|
|
// level:
|
|
|
|
// Numerical value between 0 and 255
|
|
|
|
// An incoming L-band satellite signal of
|
|
|
|
// -25dBm corresponds to 224
|
|
|
|
// -65dBm corresponds to 32
|
|
|
|
// No signal corresponds to 0
|
|
|
|
c = strstr(c, ",");
|
2015-01-12 22:58:30 +01:00
|
|
|
value = min(atoi(++c), 255);
|
2014-03-08 12:07:47 +01:00
|
|
|
// Scale value to 0-100
|
|
|
|
signalStrengthM = (value >= 0) ? (value * 100 / 255) : -1;
|
|
|
|
|
|
|
|
// lock:
|
|
|
|
// lock Set to one of the following values:
|
|
|
|
// "0" the frontend is not locked
|
|
|
|
// "1" the frontend is locked
|
|
|
|
c = strstr(c, ",");
|
2014-11-10 22:31:30 +01:00
|
|
|
hasLockM = !!atoi(++c);
|
2014-03-08 12:07:47 +01:00
|
|
|
|
|
|
|
// quality:
|
|
|
|
// Numerical value between 0 and 15
|
|
|
|
// Lowest value corresponds to highest error rate
|
|
|
|
// The value 15 shall correspond to
|
|
|
|
// -a BER lower than 2x10-4 after Viterbi for DVB-S
|
|
|
|
// -a PER lower than 10-7 for DVB-S2
|
|
|
|
c = strstr(c, ",");
|
2015-01-12 22:58:30 +01:00
|
|
|
value = min(atoi(++c), 15);
|
2014-03-08 12:07:47 +01:00
|
|
|
// Scale value to 0-100
|
|
|
|
signalQualityM = (hasLockM && (value >= 0)) ? (value * 100 / 15) : 0;
|
|
|
|
}
|
|
|
|
}
|
2014-11-28 21:52:32 +01:00
|
|
|
reConnectM.Set(eConnectTimeoutMs);
|
2014-03-08 12:07:47 +01:00
|
|
|
}
|
|
|
|
|
2014-03-16 18:58:09 +01:00
|
|
|
void cSatipTuner::SetStreamId(int streamIdP)
|
|
|
|
{
|
|
|
|
cMutexLock MutexLock(&mutexM);
|
2014-12-07 16:27:53 +01:00
|
|
|
debug1("%s (%d) [device %d]", __PRETTY_FUNCTION__, streamIdP, deviceIdM);
|
2014-03-16 18:58:09 +01:00
|
|
|
streamIdM = streamIdP;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cSatipTuner::SetSessionTimeout(const char *sessionP, int timeoutP)
|
2014-03-08 12:07:47 +01:00
|
|
|
{
|
|
|
|
cMutexLock MutexLock(&mutexM);
|
2014-12-07 16:27:53 +01:00
|
|
|
debug1("%s (%s, %d) [device %d]", __PRETTY_FUNCTION__, sessionP, timeoutP, deviceIdM);
|
2014-03-16 18:58:09 +01:00
|
|
|
sessionM = sessionP;
|
2015-01-15 22:33:51 +01:00
|
|
|
if (nextServerM.IsQuirk(cSatipServer::eSatipQuirkSessionId) && !isempty(*sessionM) && startswith(*sessionM, "0"))
|
2014-12-07 20:58:06 +01:00
|
|
|
rtspM.SetSession(SkipZeroes(*sessionM));
|
2014-03-31 21:07:15 +02:00
|
|
|
timeoutM = (timeoutP > eMinKeepAliveIntervalMs) ? timeoutP : eMinKeepAliveIntervalMs;
|
2014-03-08 12:07:47 +01:00
|
|
|
}
|
|
|
|
|
2014-11-09 11:51:52 +01:00
|
|
|
int cSatipTuner::GetId(void)
|
|
|
|
{
|
2014-12-14 16:45:55 +01:00
|
|
|
debug16("%s [device %d]", __PRETTY_FUNCTION__, deviceIdM);
|
2014-11-09 11:51:52 +01:00
|
|
|
return deviceIdM;
|
|
|
|
}
|
|
|
|
|
2015-01-15 22:33:51 +01:00
|
|
|
bool cSatipTuner::SetSource(cSatipServer *serverP, const int transponderP, const char *parameterP, const int indexP)
|
2014-03-08 12:07:47 +01:00
|
|
|
{
|
2015-01-15 22:33:51 +01:00
|
|
|
debug1("%s (%d, %s, %d) [device %d]", __PRETTY_FUNCTION__, transponderP, parameterP, indexP, deviceIdM);
|
2014-03-13 17:23:55 +01:00
|
|
|
cMutexLock MutexLock(&mutexM);
|
2014-11-03 20:55:54 +01:00
|
|
|
if (serverP) {
|
2015-01-15 22:33:51 +01:00
|
|
|
nextServerM.Set(serverP, transponderP);
|
|
|
|
if (!isempty(*nextServerM.GetAddress()) && !isempty(parameterP)) {
|
2014-11-03 20:55:54 +01:00
|
|
|
// Update stream address and parameter
|
2015-01-15 22:33:51 +01:00
|
|
|
streamAddrM = rtspM.RtspUnescapeString(*nextServerM.GetAddress());
|
2014-11-16 15:39:20 +01:00
|
|
|
streamParamM = rtspM.RtspUnescapeString(parameterP);
|
2014-12-03 00:42:33 +01:00
|
|
|
// Reconnect
|
|
|
|
RequestState(tsSet, smExternal);
|
2014-11-03 20:55:54 +01:00
|
|
|
}
|
2014-03-08 12:07:47 +01:00
|
|
|
}
|
2014-11-23 21:22:38 +01:00
|
|
|
else {
|
|
|
|
streamAddrM = "";
|
|
|
|
streamParamM = "";
|
|
|
|
}
|
2014-11-17 21:59:01 +01:00
|
|
|
|
2014-03-08 12:07:47 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cSatipTuner::SetPid(int pidP, int typeP, bool onP)
|
|
|
|
{
|
2014-12-14 16:45:55 +01:00
|
|
|
debug16("%s (%d, %d, %d) [device %d]", __PRETTY_FUNCTION__, pidP, typeP, onP, deviceIdM);
|
2014-03-08 12:07:47 +01:00
|
|
|
cMutexLock MutexLock(&mutexM);
|
2014-04-19 16:27:47 +02:00
|
|
|
if (onP) {
|
2014-11-09 01:32:50 +01:00
|
|
|
pidsM.AddPid(pidP);
|
|
|
|
addPidsM.AddPid(pidP);
|
|
|
|
delPidsM.RemovePid(pidP);
|
2014-04-19 16:27:47 +02:00
|
|
|
}
|
|
|
|
else {
|
2014-11-09 01:32:50 +01:00
|
|
|
pidsM.RemovePid(pidP);
|
|
|
|
delPidsM.AddPid(pidP);
|
|
|
|
addPidsM.RemovePid(pidP);
|
2014-04-19 16:27:47 +02:00
|
|
|
}
|
2015-01-15 19:03:35 +01:00
|
|
|
debug12("%s (%d, %d, %d) pids=%s [device %d]", __PRETTY_FUNCTION__, pidP, typeP, onP, *pidsM.ListPids(), deviceIdM);
|
2014-11-11 19:23:41 +01:00
|
|
|
sleepM.Signal();
|
2014-11-17 21:59:01 +01:00
|
|
|
|
2014-03-08 12:07:47 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-04-19 16:27:47 +02:00
|
|
|
bool cSatipTuner::UpdatePids(bool forceP)
|
2014-03-08 12:07:47 +01:00
|
|
|
{
|
2014-12-14 16:45:55 +01:00
|
|
|
debug16("%s (%d) tunerState=%s [device %d]", __PRETTY_FUNCTION__, forceP, TunerStateString(currentStateM), deviceIdM);
|
2014-12-14 21:08:54 +01:00
|
|
|
cMutexLock MutexLock(&mutexM);
|
2014-04-19 16:27:47 +02:00
|
|
|
if (((forceP && pidsM.Size()) || (pidUpdateCacheM.TimedOut() && (addPidsM.Size() || delPidsM.Size()))) &&
|
2014-11-17 21:59:01 +01:00
|
|
|
!isempty(*streamAddrM) && (streamIdM > 0)) {
|
2014-04-19 16:27:47 +02:00
|
|
|
cString uri = cString::sprintf("rtsp://%s/stream=%d", *streamAddrM, streamIdM);
|
2015-01-25 23:21:55 +01:00
|
|
|
bool useci = (SatipConfig.GetCIExtension() && currentServerM.HasCI());
|
2015-01-15 22:33:51 +01:00
|
|
|
bool usedummy = currentServerM.IsQuirk(cSatipServer::eSatipQuirkPlayPids);
|
2014-11-05 20:55:40 +01:00
|
|
|
if (forceP || usedummy) {
|
2014-12-14 16:54:37 +01:00
|
|
|
if (pidsM.Size())
|
|
|
|
uri = cString::sprintf("%s?pids=%s", *uri, *pidsM.ListPids());
|
2014-11-05 20:55:40 +01:00
|
|
|
if (usedummy && (pidsM.Size() == 1) && (pidsM[0] < 0x20))
|
|
|
|
uri = cString::sprintf("%s,%d", *uri, eDummyPid);
|
2014-04-19 16:27:47 +02:00
|
|
|
}
|
|
|
|
else {
|
2014-12-14 16:54:37 +01:00
|
|
|
if (addPidsM.Size())
|
|
|
|
uri = cString::sprintf("%s?addpids=%s", *uri, *addPidsM.ListPids());
|
|
|
|
if (delPidsM.Size())
|
|
|
|
uri = cString::sprintf("%s%sdelpids=%s", *uri, addPidsM.Size() ? "&" : "?", *delPidsM.ListPids());
|
2014-04-19 16:27:47 +02:00
|
|
|
}
|
2015-01-09 14:42:03 +01:00
|
|
|
if (useci) {
|
2015-01-07 16:45:48 +01:00
|
|
|
// CI extension parameters:
|
|
|
|
// - x_pmt : specifies the PMT of the service you want the CI to decode
|
|
|
|
// - x_ci : specfies which CI slot (1..n) to use
|
|
|
|
// value 0 releases the CI slot
|
|
|
|
// CI slot released automatically if the stream is released,
|
|
|
|
// but not when used retuning to another channel
|
2015-01-05 23:58:35 +01:00
|
|
|
int pid = deviceM->GetPmtPid();
|
2015-01-09 14:42:03 +01:00
|
|
|
if ((pid > 0) && (pid != pmtPidM)) {
|
|
|
|
int slot = deviceM->GetCISlot();
|
2015-01-05 23:58:35 +01:00
|
|
|
uri = cString::sprintf("%s&x_pmt=%d", *uri, pid);
|
2015-01-09 14:42:03 +01:00
|
|
|
if (slot > 0)
|
|
|
|
uri = cString::sprintf("%s&x_ci=%d", *uri, slot);
|
|
|
|
}
|
2015-01-05 23:58:35 +01:00
|
|
|
pmtPidM = pid;
|
|
|
|
}
|
2015-01-09 18:56:43 +01:00
|
|
|
pidUpdateCacheM.Set(ePidUpdateIntervalMs);
|
2014-11-16 15:39:20 +01:00
|
|
|
if (!rtspM.Play(*uri))
|
2014-11-15 19:15:00 +01:00
|
|
|
return false;
|
|
|
|
addPidsM.Clear();
|
|
|
|
delPidsM.Clear();
|
2014-03-08 12:07:47 +01:00
|
|
|
}
|
|
|
|
|
2014-11-15 19:15:00 +01:00
|
|
|
return true;
|
2014-03-08 12:07:47 +01:00
|
|
|
}
|
|
|
|
|
2014-11-15 19:15:00 +01:00
|
|
|
bool cSatipTuner::KeepAlive(bool forceP)
|
2014-03-08 12:07:47 +01:00
|
|
|
{
|
2014-12-14 16:45:55 +01:00
|
|
|
debug16("%s (%d) tunerState=%s [device %d]", __PRETTY_FUNCTION__, forceP, TunerStateString(currentStateM), deviceIdM);
|
2014-03-08 12:07:47 +01:00
|
|
|
cMutexLock MutexLock(&mutexM);
|
2014-11-15 19:15:00 +01:00
|
|
|
if (keepAliveM.TimedOut()) {
|
2014-11-09 19:32:08 +01:00
|
|
|
keepAliveM.Set(timeoutM);
|
2014-11-15 19:15:00 +01:00
|
|
|
forceP = true;
|
|
|
|
}
|
2014-11-22 13:56:20 +01:00
|
|
|
if (forceP && !isempty(*streamAddrM)) {
|
|
|
|
cString uri = cString::sprintf("rtsp://%s/", *streamAddrM);
|
2014-11-16 15:39:20 +01:00
|
|
|
if (!rtspM.Options(*uri))
|
2014-11-15 19:15:00 +01:00
|
|
|
return false;
|
2014-03-08 12:07:47 +01:00
|
|
|
}
|
|
|
|
|
2014-11-15 19:15:00 +01:00
|
|
|
return true;
|
2014-03-08 12:07:47 +01:00
|
|
|
}
|
|
|
|
|
2014-11-15 19:15:00 +01:00
|
|
|
bool cSatipTuner::ReadReceptionStatus(bool forceP)
|
2014-11-05 20:55:40 +01:00
|
|
|
{
|
2014-12-14 16:45:55 +01:00
|
|
|
debug16("%s (%d) tunerState=%s [device %d]", __PRETTY_FUNCTION__, forceP, TunerStateString(currentStateM), deviceIdM);
|
2014-11-05 20:55:40 +01:00
|
|
|
cMutexLock MutexLock(&mutexM);
|
2014-11-15 19:15:00 +01:00
|
|
|
if (statusUpdateM.TimedOut()) {
|
|
|
|
statusUpdateM.Set(eStatusUpdateTimeoutMs);
|
|
|
|
forceP = true;
|
|
|
|
}
|
|
|
|
if (forceP && !isempty(*streamAddrM) && (streamIdM > 0)) {
|
2014-11-05 20:55:40 +01:00
|
|
|
cString uri = cString::sprintf("rtsp://%s/stream=%d", *streamAddrM, streamIdM);
|
2014-11-16 15:39:20 +01:00
|
|
|
if (rtspM.Describe(*uri))
|
2014-11-09 11:51:52 +01:00
|
|
|
return true;
|
2014-11-05 20:55:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-23 21:22:38 +01:00
|
|
|
void cSatipTuner::UpdateCurrentState(void)
|
|
|
|
{
|
2014-12-14 16:45:55 +01:00
|
|
|
debug16("%s [device %d]", __PRETTY_FUNCTION__, deviceIdM);
|
2014-11-23 21:22:38 +01:00
|
|
|
cMutexLock MutexLock(&mutexM);
|
|
|
|
eTunerState state = currentStateM;
|
|
|
|
|
|
|
|
if (internalStateM.Size()) {
|
|
|
|
state = internalStateM.At(0);
|
|
|
|
internalStateM.Remove(0);
|
|
|
|
}
|
|
|
|
else if (externalStateM.Size()) {
|
|
|
|
state = externalStateM.At(0);
|
|
|
|
externalStateM.Remove(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentStateM != state) {
|
2014-12-07 16:27:53 +01:00
|
|
|
debug1("%s: Switching from %s to %s [device %d]", __PRETTY_FUNCTION__, TunerStateString(currentStateM), TunerStateString(state), deviceIdM);
|
2014-11-23 21:22:38 +01:00
|
|
|
currentStateM = state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-19 20:01:45 +01:00
|
|
|
bool cSatipTuner::StateRequested(void)
|
|
|
|
{
|
|
|
|
cMutexLock MutexLock(&mutexM);
|
2014-12-14 16:45:55 +01:00
|
|
|
debug16("%s current=%s internal=%d external=%d [device %d]", __PRETTY_FUNCTION__, TunerStateString(currentStateM), internalStateM.Size(), externalStateM.Size(), deviceIdM);
|
2014-11-19 20:01:45 +01:00
|
|
|
|
2014-11-23 21:22:38 +01:00
|
|
|
return (internalStateM.Size() || externalStateM.Size());
|
2014-11-19 20:01:45 +01:00
|
|
|
}
|
|
|
|
|
2014-11-23 21:22:38 +01:00
|
|
|
bool cSatipTuner::RequestState(eTunerState stateP, eStateMode modeP)
|
2014-11-15 19:15:00 +01:00
|
|
|
{
|
2014-11-17 21:59:01 +01:00
|
|
|
cMutexLock MutexLock(&mutexM);
|
2014-12-07 16:27:53 +01:00
|
|
|
debug1("%s (%s, %s) current=%s internal=%d external=%d [device %d]", __PRETTY_FUNCTION__, TunerStateString(stateP), StateModeString(modeP), TunerStateString(currentStateM), internalStateM.Size(), externalStateM.Size(), deviceIdM);
|
2014-11-23 21:22:38 +01:00
|
|
|
|
|
|
|
if (modeP == smExternal)
|
|
|
|
externalStateM.Append(stateP);
|
|
|
|
else if (modeP == smInternal) {
|
|
|
|
eTunerState state = internalStateM.Size() ? internalStateM.At(internalStateM.Size() - 1) : currentStateM;
|
|
|
|
|
|
|
|
// validate legal state changes
|
|
|
|
switch (state) {
|
|
|
|
case tsIdle:
|
|
|
|
if (stateP == tsRelease)
|
|
|
|
return false;
|
|
|
|
case tsRelease:
|
|
|
|
case tsSet:
|
|
|
|
case tsLocked:
|
|
|
|
case tsTuned:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
internalStateM.Append(stateP);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
2014-11-22 20:32:55 +01:00
|
|
|
|
2014-11-23 21:22:38 +01:00
|
|
|
return true;
|
|
|
|
}
|
2014-11-22 23:13:15 +01:00
|
|
|
|
2014-11-23 21:22:38 +01:00
|
|
|
const char *cSatipTuner::StateModeString(eStateMode modeP)
|
|
|
|
{
|
|
|
|
switch (modeP) {
|
|
|
|
case smInternal:
|
|
|
|
return "smInternal";
|
|
|
|
case smExternal:
|
|
|
|
return "smExternal";
|
|
|
|
default:
|
2014-11-22 20:32:55 +01:00
|
|
|
break;
|
|
|
|
}
|
2014-11-17 21:59:01 +01:00
|
|
|
|
2014-11-23 21:22:38 +01:00
|
|
|
return "---";
|
2014-11-17 21:59:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *cSatipTuner::TunerStateString(eTunerState stateP)
|
|
|
|
{
|
|
|
|
switch (stateP) {
|
2014-11-15 19:15:00 +01:00
|
|
|
case tsIdle:
|
|
|
|
return "tsIdle";
|
|
|
|
case tsRelease:
|
|
|
|
return "tsRelease";
|
|
|
|
case tsSet:
|
|
|
|
return "tsSet";
|
|
|
|
case tsLocked:
|
|
|
|
return "tsLocked";
|
|
|
|
case tsTuned:
|
|
|
|
return "tsTuned";
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-11-17 21:59:01 +01:00
|
|
|
|
2014-11-15 19:15:00 +01:00
|
|
|
return "---";
|
|
|
|
}
|
|
|
|
|
2015-01-19 23:35:46 +01:00
|
|
|
int cSatipTuner::FrontendId(void)
|
|
|
|
{
|
|
|
|
debug16("%s [device %d]", __PRETTY_FUNCTION__, deviceIdM);
|
|
|
|
return frontendIdM;
|
|
|
|
}
|
|
|
|
|
2014-03-08 12:07:47 +01:00
|
|
|
int cSatipTuner::SignalStrength(void)
|
|
|
|
{
|
2014-12-14 16:45:55 +01:00
|
|
|
debug16("%s [device %d]", __PRETTY_FUNCTION__, deviceIdM);
|
2014-03-08 12:07:47 +01:00
|
|
|
return signalStrengthM;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cSatipTuner::SignalQuality(void)
|
|
|
|
{
|
2014-12-14 16:45:55 +01:00
|
|
|
debug16("%s [device %d]", __PRETTY_FUNCTION__, deviceIdM);
|
2014-03-08 12:07:47 +01:00
|
|
|
return signalQualityM;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cSatipTuner::HasLock(void)
|
|
|
|
{
|
2014-12-14 16:45:55 +01:00
|
|
|
debug16("%s [device %d]", __PRETTY_FUNCTION__, deviceIdM);
|
2014-11-17 21:59:01 +01:00
|
|
|
return (currentStateM >= tsTuned) && hasLockM;
|
2014-03-08 12:07:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cString cSatipTuner::GetSignalStatus(void)
|
|
|
|
{
|
2014-12-14 16:45:55 +01:00
|
|
|
debug16("%s [device %d]", __PRETTY_FUNCTION__, deviceIdM);
|
2015-01-19 23:35:46 +01:00
|
|
|
return cString::sprintf("lock=%d strength=%d quality=%d frontend=%d", HasLock(), SignalStrength(), SignalQuality(), FrontendId());
|
2014-03-08 12:07:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cString cSatipTuner::GetInformation(void)
|
|
|
|
{
|
2014-12-14 16:45:55 +01:00
|
|
|
debug16("%s [device %d]", __PRETTY_FUNCTION__, deviceIdM);
|
2014-11-17 21:59:01 +01:00
|
|
|
return (currentStateM >= tsTuned) ? cString::sprintf("rtsp://%s/?%s [stream=%d]", *streamAddrM, *streamParamM, streamIdM) : "connection failed";
|
2014-03-08 12:07:47 +01:00
|
|
|
}
|