2014-03-08 12:07:47 +01:00
|
|
|
/*
|
|
|
|
* tuner.h: SAT>IP plugin for the Video Disk Recorder
|
|
|
|
*
|
|
|
|
* See the README file for copyright information and how to reach the author.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __SATIP_TUNER_H
|
|
|
|
#define __SATIP_TUNER_H
|
|
|
|
|
|
|
|
#include <vdr/thread.h>
|
|
|
|
#include <vdr/tools.h>
|
|
|
|
|
|
|
|
#include "deviceif.h"
|
2015-01-15 22:33:51 +01:00
|
|
|
#include "discover.h"
|
2014-11-14 21:28:27 +01:00
|
|
|
#include "rtp.h"
|
|
|
|
#include "rtcp.h"
|
2014-11-09 11:51:52 +01:00
|
|
|
#include "rtsp.h"
|
2014-03-13 17:23:55 +01:00
|
|
|
#include "server.h"
|
2014-03-08 12:07:47 +01:00
|
|
|
#include "statistics.h"
|
|
|
|
|
2014-11-09 01:32:50 +01:00
|
|
|
class cSatipPid : public cVector<int> {
|
|
|
|
private:
|
2015-01-14 19:51:16 +01:00
|
|
|
static int PidCompare(const void *aPidP, const void *bPidP)
|
|
|
|
{
|
|
|
|
return (*(int*)aPidP - *(int*)bPidP);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2014-11-09 01:32:50 +01:00
|
|
|
void RemovePid(const int &pidP)
|
|
|
|
{
|
2015-01-14 19:51:16 +01:00
|
|
|
if (RemoveElement(pidP))
|
2014-12-14 00:56:21 +01:00
|
|
|
Sort(PidCompare);
|
2014-11-09 01:32:50 +01:00
|
|
|
}
|
|
|
|
void AddPid(int pidP)
|
|
|
|
{
|
2015-01-14 19:51:16 +01:00
|
|
|
if (AppendUnique(pidP))
|
2014-12-14 00:56:21 +01:00
|
|
|
Sort(PidCompare);
|
2014-11-09 01:32:50 +01:00
|
|
|
}
|
2014-12-14 16:54:37 +01:00
|
|
|
cString ListPids(void)
|
|
|
|
{
|
|
|
|
cString list = "";
|
|
|
|
if (Size()) {
|
|
|
|
for (int i = 0; i < Size(); ++i)
|
|
|
|
list = cString::sprintf("%s%d,", *list, At(i));
|
|
|
|
list = list.Truncate(-1);
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
2014-11-09 01:32:50 +01:00
|
|
|
};
|
|
|
|
|
2015-01-15 22:33:51 +01:00
|
|
|
class cSatipTunerServer
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
cSatipServer *serverM;
|
2015-02-16 16:21:00 +01:00
|
|
|
int deviceIdM;
|
2015-01-15 22:33:51 +01:00
|
|
|
int transponderM;
|
|
|
|
|
|
|
|
public:
|
2015-02-16 16:21:00 +01:00
|
|
|
cSatipTunerServer(cSatipServer *serverP, const int deviceIdP, const int transponderP) : serverM(serverP), deviceIdM(deviceIdP), transponderM(transponderP) {}
|
2015-01-15 22:33:51 +01:00
|
|
|
~cSatipTunerServer() {}
|
2015-02-16 16:21:00 +01:00
|
|
|
cSatipTunerServer(const cSatipTunerServer &objP) { serverM = NULL; deviceIdM = -1; transponderM = 0; }
|
|
|
|
cSatipTunerServer& operator= (const cSatipTunerServer &objP) { serverM = objP.serverM; deviceIdM = objP.deviceIdM; transponderM = objP.transponderM; return *this; }
|
2015-01-15 22:33:51 +01:00
|
|
|
bool IsValid(void) { return !!serverM; }
|
|
|
|
bool IsQuirk(int quirkP) { return (serverM && cSatipDiscover::GetInstance()->IsServerQuirk(serverM, quirkP)); }
|
2015-01-25 23:21:55 +01:00
|
|
|
bool HasCI(void) { return (serverM && cSatipDiscover::GetInstance()->HasServerCI(serverM)); }
|
2015-02-16 16:21:00 +01:00
|
|
|
void Attach(void) { if (serverM) cSatipDiscover::GetInstance()->AttachServer(serverM, deviceIdM, transponderM); }
|
|
|
|
void Detach(void) { if (serverM) cSatipDiscover::GetInstance()->DetachServer(serverM, deviceIdM, transponderM); }
|
2015-01-15 22:33:51 +01:00
|
|
|
void Set(cSatipServer *serverP, const int transponderP) { serverM = serverP; transponderM = transponderP; }
|
|
|
|
void Reset(void) { serverM = NULL; transponderM = 0; }
|
|
|
|
cString GetAddress(void) { return serverM ? cSatipDiscover::GetInstance()->GetServerAddress(serverM) : ""; }
|
2015-02-16 16:21:00 +01:00
|
|
|
cString GetInfo(void) { return cString::sprintf("server=%s deviceid=%d transponder=%d", serverM ? "assigned" : "null", deviceIdM, transponderM); }
|
2015-01-15 22:33:51 +01:00
|
|
|
};
|
|
|
|
|
2014-11-14 21:28:27 +01:00
|
|
|
class cSatipTuner : public cThread, public cSatipTunerStatistics, public cSatipTunerIf
|
|
|
|
{
|
2014-03-08 12:07:47 +01:00
|
|
|
private:
|
|
|
|
enum {
|
2014-11-03 20:54:19 +01:00
|
|
|
eDummyPid = 100,
|
|
|
|
eDefaultSignalStrength = 15,
|
|
|
|
eDefaultSignalQuality = 224,
|
2015-01-10 13:14:30 +01:00
|
|
|
eSleepTimeoutMs = 250, // in milliseconds
|
2014-11-05 20:55:40 +01:00
|
|
|
eStatusUpdateTimeoutMs = 1000, // in milliseconds
|
2014-04-15 19:04:01 +02:00
|
|
|
ePidUpdateIntervalMs = 250, // in milliseconds
|
2014-11-15 19:15:00 +01:00
|
|
|
eConnectTimeoutMs = 5000, // in milliseconds
|
2015-05-23 14:28:37 +02:00
|
|
|
eIdleCheckTimeoutMs = 15000, // in milliseconds
|
2015-08-16 00:10:52 +02:00
|
|
|
eTuningTimeoutMs = 20000, // in milliseconds
|
2014-04-02 20:06:37 +02:00
|
|
|
eMinKeepAliveIntervalMs = 30000 // in milliseconds
|
2014-03-08 12:07:47 +01:00
|
|
|
};
|
2014-11-17 21:59:01 +01:00
|
|
|
enum eTunerState { tsIdle, tsRelease, tsSet, tsTuned, tsLocked };
|
2014-11-23 21:22:38 +01:00
|
|
|
enum eStateMode { smInternal, smExternal };
|
2014-03-08 12:07:47 +01:00
|
|
|
|
|
|
|
cCondWait sleepM;
|
|
|
|
cSatipDeviceIf* deviceM;
|
2014-11-09 11:51:52 +01:00
|
|
|
int deviceIdM;
|
2014-11-16 15:39:20 +01:00
|
|
|
cSatipRtsp rtspM;
|
|
|
|
cSatipRtp rtpM;
|
|
|
|
cSatipRtcp rtcpM;
|
2014-03-08 12:07:47 +01:00
|
|
|
cString streamAddrM;
|
|
|
|
cString streamParamM;
|
2015-01-15 22:33:51 +01:00
|
|
|
cSatipTunerServer currentServerM;
|
|
|
|
cSatipTunerServer nextServerM;
|
2014-03-08 12:07:47 +01:00
|
|
|
cMutex mutexM;
|
2014-11-16 14:38:23 +01:00
|
|
|
cTimeMs reConnectM;
|
2014-03-08 12:07:47 +01:00
|
|
|
cTimeMs keepAliveM;
|
2014-11-05 20:55:40 +01:00
|
|
|
cTimeMs statusUpdateM;
|
2014-03-08 12:07:47 +01:00
|
|
|
cTimeMs pidUpdateCacheM;
|
2014-03-16 18:58:09 +01:00
|
|
|
cString sessionM;
|
2014-11-17 21:59:01 +01:00
|
|
|
eTunerState currentStateM;
|
2014-11-23 21:22:38 +01:00
|
|
|
cVector<eTunerState> internalStateM;
|
|
|
|
cVector<eTunerState> externalStateM;
|
2014-03-08 12:07:47 +01:00
|
|
|
int timeoutM;
|
|
|
|
bool hasLockM;
|
|
|
|
int signalStrengthM;
|
|
|
|
int signalQualityM;
|
2015-01-19 23:35:46 +01:00
|
|
|
int frontendIdM;
|
2014-03-08 12:07:47 +01:00
|
|
|
int streamIdM;
|
2015-01-05 23:58:35 +01:00
|
|
|
int pmtPidM;
|
2014-11-09 01:32:50 +01:00
|
|
|
cSatipPid addPidsM;
|
|
|
|
cSatipPid delPidsM;
|
|
|
|
cSatipPid pidsM;
|
2014-03-08 12:07:47 +01:00
|
|
|
|
|
|
|
bool Connect(void);
|
|
|
|
bool Disconnect(void);
|
2014-11-15 19:15:00 +01:00
|
|
|
bool KeepAlive(bool forceP = false);
|
|
|
|
bool ReadReceptionStatus(bool forceP = false);
|
2014-04-19 16:27:47 +02:00
|
|
|
bool UpdatePids(bool forceP = false);
|
2014-11-23 21:22:38 +01:00
|
|
|
void UpdateCurrentState(void);
|
2014-11-19 20:01:45 +01:00
|
|
|
bool StateRequested(void);
|
2014-11-23 21:22:38 +01:00
|
|
|
bool RequestState(eTunerState stateP, eStateMode modeP);
|
|
|
|
const char *StateModeString(eStateMode modeP);
|
2014-11-17 21:59:01 +01:00
|
|
|
const char *TunerStateString(eTunerState stateP);
|
2014-03-08 12:07:47 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void Action(void);
|
|
|
|
|
|
|
|
public:
|
|
|
|
cSatipTuner(cSatipDeviceIf &deviceP, unsigned int packetLenP);
|
|
|
|
virtual ~cSatipTuner();
|
2014-12-07 17:12:08 +01:00
|
|
|
bool IsTuned(void) const { return (currentStateM >= tsTuned); }
|
2015-01-15 22:33:51 +01:00
|
|
|
bool SetSource(cSatipServer *serverP, const int transponderP, const char *parameterP, const int indexP);
|
2014-03-08 12:07:47 +01:00
|
|
|
bool SetPid(int pidP, int typeP, bool onP);
|
|
|
|
bool Open(void);
|
|
|
|
bool Close(void);
|
2015-01-19 23:35:46 +01:00
|
|
|
int FrontendId(void);
|
2014-03-08 12:07:47 +01:00
|
|
|
int SignalStrength(void);
|
|
|
|
int SignalQuality(void);
|
|
|
|
bool HasLock(void);
|
|
|
|
cString GetSignalStatus(void);
|
|
|
|
cString GetInformation(void);
|
2014-11-09 11:51:52 +01:00
|
|
|
|
|
|
|
// for internal tuner interface
|
|
|
|
public:
|
2014-11-16 14:38:23 +01:00
|
|
|
virtual void ProcessVideoData(u_char *bufferP, int lengthP);
|
|
|
|
virtual void ProcessApplicationData(u_char *bufferP, int lengthP);
|
2014-11-09 11:51:52 +01:00
|
|
|
virtual void SetStreamId(int streamIdP);
|
|
|
|
virtual void SetSessionTimeout(const char *sessionP, int timeoutP);
|
|
|
|
virtual int GetId(void);
|
2014-03-08 12:07:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __SATIP_TUNER_H
|