forked from manio/vdr-plugin-dvbapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
device-tmpl.cpp
195 lines (177 loc) · 4.68 KB
/
device-tmpl.cpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
* vdr-plugin-dvbapi - softcam dvbapi plugin for VDR
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
// -- cScDevice ----------------------------------------------------------------
#include "SCCIAdapter.h"
#include "DeCsaTSBuffer.h"
class SCDEVICE : public DVBDEVICE
{
private:
DeCsaTsBuffer *tsBuffer;
cMutex tsMutex;
cScDevicePlugin *devplugin;
cTimeMs lastDump;
SCCIAdapter *sCCIAdapter;
int fd_dvr, fd_ca, fd_ca2;
bool softcsa;
char devId[8];
bool ScActive(void);
protected:
virtual bool Ready(void);
virtual bool SetPid(cPidHandle *Handle, int Type, bool On);
virtual bool SetChannelDevice(const cChannel *Channel, bool LiveView);
virtual bool OpenDvr(void);
virtual void CloseDvr(void);
virtual bool GetTSPacket(uchar *&Data);
public:
SCDEVICE(cScDevicePlugin *DevPlugin, int Adapter, int Frontend, int cafd);
~SCDEVICE();
virtual bool HasCi(void);
void LateInit(void);
void EarlyShutdown(void);
};
SCDEVICE::SCDEVICE(cScDevicePlugin *DevPlugin, int Adapter, int Frontend, int cafd)
#ifdef OWN_DEVPARAMS
: DVBDEVICE(Adapter, Frontend, OWN_DEVPARAMS)
#else
: DVBDEVICE(Adapter, Frontend)
#endif //OWN_DEVPARAMS
{
DEBUGLOG("%s: adapter=%d frontend=%d", __FUNCTION__, Adapter, Frontend);
tsBuffer = 0;
devplugin = DevPlugin;
softcsa = false;
fd_ca = cafd;
fd_ca2 = dup(fd_ca);
fd_dvr = -1;
snprintf(devId, sizeof(devId), "%d/%d", Adapter, Frontend);
sCCIAdapter = new SCCIAdapter(this, Adapter, cafd);
DEBUGLOG("%s: done", __FUNCTION__);
}
SCDEVICE::~SCDEVICE()
{
DEBUGLOG("%s", __FUNCTION__);
DetachAllReceivers();
Cancel(3);
EarlyShutdown();
if (fd_ca >= 0)
close(fd_ca);
if (fd_ca2 >= 0)
close(fd_ca2);
}
void SCDEVICE::EarlyShutdown(void)
{
DEBUGLOG("%s", __FUNCTION__);
SetCamSlot(0);
if (sCCIAdapter)
delete sCCIAdapter;
sCCIAdapter = 0;
}
void SCDEVICE::LateInit(void)
{
DEBUGLOG("%s", __FUNCTION__);
int n = CardIndex();
if (DeviceNumber() != n)
ERRORLOG("CardIndex - DeviceNumber mismatch! Put DVBAPI plugin first on VDR commandline!");
softcsa = (fd_ca < 0);
if (softcsa)
{
if (HasDecoder())
INFOLOG("Card %s is a full-featured card but no ca device found!", devId);
}
else if (cScDevices::ForceBudget(n))
{
INFOLOG("Budget mode forced on card %s", devId);
softcsa = true;
}
if (softcsa)
{
INFOLOG("Using software decryption on card %s", devId);
}
}
bool SCDEVICE::HasCi(void)
{
DEBUGLOG("%s", __FUNCTION__);
return sCCIAdapter;
}
bool SCDEVICE::Ready(void)
{
return (sCCIAdapter ? sCCIAdapter->Ready() : true);
}
bool SCDEVICE::SetPid(cPidHandle *Handle, int Type, bool On)
{
DEBUGLOG("%s: on=%d", __FUNCTION__, On);
tsMutex.Lock();
if (tsBuffer)
tsBuffer->SetActive(ScActive());
tsMutex.Unlock();
return DVBDEVICE::SetPid(Handle, Type, On);
}
bool SCDEVICE::SetChannelDevice(const cChannel *Channel, bool LiveView)
{
DEBUGLOG("%s", __FUNCTION__);
bool ret = DVBDEVICE::SetChannelDevice(Channel, LiveView);
if (LiveView && IsPrimaryDevice() && Channel->Ca() >= CA_ENCRYPTED_MIN && !Transferring() && softcsa)
{
INFOLOG("Forcing transfermode on card %s", devId);
DVBDEVICE::SetChannelDevice(Channel, false); // force transfermode
}
return ret;
}
bool SCDEVICE::ScActive(void)
{
DEBUGLOG("%s", __FUNCTION__);
return true;
}
bool SCDEVICE::OpenDvr(void)
{
DEBUGLOG("%s", __FUNCTION__);
CloseDvr();
fd_dvr = cScDevices::DvbOpen(DEV_DVB_DVR, DVB_DEV_SPEC, O_RDONLY | O_NONBLOCK, true);
if (fd_dvr >= 0)
{
tsMutex.Lock();
tsBuffer = new DeCsaTsBuffer(fd_dvr, MEGABYTE(4), CardIndex() + 1, sCCIAdapter->GetDeCSA(), ScActive());
tsMutex.Unlock();
}
return fd_dvr >= 0;
}
void SCDEVICE::CloseDvr(void)
{
DEBUGLOG("%s", __FUNCTION__);
tsMutex.Lock();
delete tsBuffer;
tsBuffer = 0;
tsMutex.Unlock();
if (fd_dvr >= 0)
{
close(fd_dvr);
fd_dvr = -1;
}
}
bool SCDEVICE::GetTSPacket(uchar *&Data)
{
if (tsBuffer)
{
Data = tsBuffer->Get();
return true;
}
return false;
}
#undef SCDEVICE
#undef DVBDEVICE
#undef OWN_DEVPARAMS