1
0
mirror of https://github.com/rofafor/vdr-plugin-satip.git synced 2023-10-10 13:37:42 +02:00
vdr-plugin-satip/tuner.h

146 lines
3.6 KiB
C
Raw Normal View History

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"
#include "rtp.h"
#include "rtcp.h"
2014-11-09 11:51:52 +01:00
#include "rtsp.h"
#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:
int PidIndex(const int &pidP)
{
2014-12-01 20:50:02 +01:00
for (int i = 0; i < Size(); ++i) {
if (pidP == At(i))
2014-11-09 01:32:50 +01:00
return i;
}
return -1;
}
static int PidCompare(const void *aPidP, const void *bPidP)
{
return (*(int*)aPidP - *(int*)bPidP);
}
2014-11-09 01:32:50 +01:00
public:
void RemovePid(const int &pidP)
{
int i = PidIndex(pidP);
if (i >= 0) {
2014-12-01 20:50:02 +01:00
Remove(i);
Sort(PidCompare);
}
2014-11-09 01:32:50 +01:00
}
void AddPid(int pidP)
{
if (PidIndex(pidP) < 0) {
2014-12-01 20:50:02 +01:00
Append(pidP);
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
};
class cSatipTuner : public cThread, public cSatipTunerStatistics, public cSatipTunerIf
{
2014-03-08 12:07:47 +01:00
private:
enum {
eDummyPid = 100,
eDefaultSignalStrength = 15,
eDefaultSignalQuality = 224,
2014-12-16 21:35:49 +01:00
eSleepTimeoutMs = 1000, // in milliseconds
eStatusUpdateTimeoutMs = 1000, // in milliseconds
ePidUpdateIntervalMs = 250, // in milliseconds
eConnectTimeoutMs = 5000, // in milliseconds
2014-04-02 20:06:37 +02:00
eMinKeepAliveIntervalMs = 30000 // in milliseconds
2014-03-08 12:07:47 +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;
cSatipServer *currentServerM;
cSatipServer *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;
cTimeMs statusUpdateM;
2014-03-08 12:07:47 +01:00
cTimeMs pidUpdateCacheM;
cString sessionM;
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;
int streamIdM;
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);
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);
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); }
bool SetSource(cSatipServer *serverP, 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);
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