-
Notifications
You must be signed in to change notification settings - Fork 4
/
femon.c
329 lines (305 loc) · 10.9 KB
/
femon.c
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/*
* femon.c: Frontend Status Monitor plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
*/
#include <getopt.h>
#include <vdr/menu.h>
#include <vdr/remote.h>
#include <vdr/player.h>
#include "config.h"
#include "femonservice.h"
#include "log.h"
#include "osd.h"
#include "tools.h"
#include "setup.h"
#if defined(APIVERSNUM) && APIVERSNUM < 20400
#error "VDR-2.4.0 API version or greater is required!"
#endif
#ifndef GITVERSION
#define GITVERSION ""
#endif
static const char VERSION[] = "2.4.1" GITVERSION;
static const char DESCRIPTION[] = trNOOP("DVB Signal Information Monitor (OSD)");
static const char MAINMENUENTRY[] = trNOOP("Signal Information");
class cPluginFemon : public cPlugin {
public:
cPluginFemon(void);
virtual ~cPluginFemon();
virtual const char *Version(void) { return VERSION; }
virtual const char *Description(void) { return tr(DESCRIPTION); }
virtual const char *CommandLineHelp(void);
virtual bool ProcessArgs(int argc, char *argv[]);
virtual bool Initialize(void);
virtual bool Start(void);
virtual void Stop(void);
virtual void Housekeeping(void);
virtual void MainThreadHook(void) {}
virtual cString Active(void) { return NULL; }
virtual const char *MainMenuEntry(void) { return (FemonConfig.GetHideMenu() ? NULL : tr(MAINMENUENTRY)); }
virtual cOsdObject *MainMenuAction(void);
virtual cMenuSetupPage *SetupMenu(void);
virtual bool SetupParse(const char *nameP, const char *valueP);
virtual bool Service(const char *idP, void *dataP);
virtual const char **SVDRPHelpPages(void);
virtual cString SVDRPCommand(const char *commandP, const char *optionP, int &replyCodeP);
};
cPluginFemon::cPluginFemon()
{
// Initialize any member variables here.
// DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
// VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
debug1("%s", __PRETTY_FUNCTION__);
}
cPluginFemon::~cPluginFemon()
{
// Clean up after yourself!
debug1("%s", __PRETTY_FUNCTION__);
}
const char *cPluginFemon::CommandLineHelp(void)
{
// Return a string that describes all known command line options.
return " -t <mode>, --trace=<mode> set the tracing mode\n";
}
bool cPluginFemon::ProcessArgs(int argc, char *argv[])
{
// Implement command line argument processing here if applicable.
static const struct option long_options[] = {
{ "trace", required_argument, NULL, 't' },
{ NULL, no_argument, NULL, 0 }
};
cString server;
int c;
while ((c = getopt_long(argc, argv, "t:", long_options, NULL)) != -1) {
switch (c) {
case 't':
FemonConfig.SetTraceMode(strtol(optarg, NULL, 0));
break;
default:
return false;
}
}
return true;
}
bool cPluginFemon::Initialize(void)
{
// Initialize any background activities the plugin shall perform.
return true;
}
bool cPluginFemon::Start(void)
{
// Start any background activities the plugin shall perform.
return true;
}
void cPluginFemon::Stop(void)
{
// Stop the background activities.
}
void cPluginFemon::Housekeeping(void)
{
// Perform any cleanup or other regular tasks.
}
cOsdObject *cPluginFemon::MainMenuAction(void)
{
// Perform the action when selected from the main VDR menu.
debug1("%s", __PRETTY_FUNCTION__);
LOCK_CHANNELS_READ;
if (cControl::Control() || (Channels->Count() <= 0))
Skins.Message(mtInfo, tr("Femon not available"));
else
return cFemonOsd::Instance(true);
return NULL;
}
cMenuSetupPage *cPluginFemon::SetupMenu(void)
{
// Return a setup menu in case the plugin supports one.
return new cMenuFemonSetup;
}
bool cPluginFemon::SetupParse(const char *nameP, const char *valueP)
{
// Parse your own setup parameters and store their values.
if (!strcasecmp(nameP, "HideMenu"))
FemonConfig.SetHideMenu(atoi(valueP));
else if (!strcasecmp(nameP, "DisplayMode"))
FemonConfig.SetDisplayMode(atoi(valueP));
else if (!strcasecmp(nameP, "Position"))
FemonConfig.SetPosition(atoi(valueP));
else if (!strcasecmp(nameP, "Skin"))
FemonConfig.SetSkin(atoi(valueP));
else if (!strcasecmp(nameP, "Theme"))
FemonConfig.SetTheme(atoi(valueP));
else if (!strcasecmp(nameP, "Downscale"))
FemonConfig.SetDownscale(atoi(valueP));
else if (!strcasecmp(nameP, "RedLimit"))
FemonConfig.SetRedLimit(atoi(valueP));
else if (!strcasecmp(nameP, "GreenLimit"))
FemonConfig.SetGreenLimit(atoi(valueP));
else if (!strcasecmp(nameP, "UpdateInterval"))
FemonConfig.SetUpdateInterval(atoi(valueP));
else if (!strcasecmp(nameP, "AnalStream"))
FemonConfig.SetAnalyzeStream(atoi(valueP));
else if (!strcasecmp(nameP, "CalcInterval"))
FemonConfig.SetCalcInterval(atoi(valueP));
else if (!strcasecmp(nameP, "UseSvdrp"))
FemonConfig.SetUseSvdrp(atoi(valueP));
else if (!strcasecmp(nameP, "ServerPort"))
FemonConfig.SetSvdrpPort(atoi(valueP));
else if (!strcasecmp(nameP, "ServerIp"))
FemonConfig.SetSvdrpIp(valueP);
else if (!strcasecmp(nameP, "SignalUnit"))
FemonConfig.SetSignalUnit(atoi(valueP));
else
return false;
return true;
}
bool cPluginFemon::Service(const char *idP, void *dataP)
{
if (strcmp(idP, "FemonService-v1.1") == 0) {
if (dataP) {
FemonService_v1_1 *data = reinterpret_cast<FemonService_v1_1*>(dataP);
cDevice *dev = cDevice::ActualDevice();
if (!dev)
return false;
data->fe_name = getFrontendName(dev);
data->fe_status = getFrontendStatus(dev);
data->fe_cnr = getCNR(dev);
data->fe_signal = getSignal(dev);
data->fe_ber = getBER(dev);
data->fe_per = getPER(dev);
data->video_bitrate = cFemonOsd::Instance() ? cFemonOsd::Instance()->GetVideoBitrate() : 0.0;
data->audio_bitrate = cFemonOsd::Instance() ? cFemonOsd::Instance()->GetAudioBitrate() : 0.0;
data->dolby_bitrate = cFemonOsd::Instance() ? cFemonOsd::Instance()->GetDolbyBitrate() : 0.0;
}
return true;
}
return false;
}
const char **cPluginFemon::SVDRPHelpPages(void)
{
static const char *HelpPages[] = {
"OPEN\n"
" Open femon plugin.",
"QUIT\n"
" Close femon plugin.",
"NEXT\n"
" Switch to next possible device.",
"PREV\n"
" Switch to previous possible device.",
"INFO <card index>\n"
" Print the frontend information.",
"NAME <card index>\n"
" Print the frontend name.",
"STAT <card index>\n"
" Print the frontend status.",
"STRG <card index>\n"
" Print the signal strength.",
"QUAL <card index>\n"
" Print the signal quality.",
"SGNL <card index>\n"
" Print the signal strength from driver.",
"CNRA <card index>\n"
" Print the carrier-to-noise ratio from driver.",
"BERA <card index>\n"
" Print the bit error rate from driver.",
"PERA <card index>\n"
" Print the packet error rate from driver.",
"VIBR\n"
" Print the current video bitrate [Mbit/s].",
"AUBR\n"
" Print the current audio bitrate [kbit/s].",
"DDBR\n"
" Print the current dolby bitrate [kbit/s].",
"TRAC [ <mode> ]\n"
" Gets and/or sets used tracing mode.\n",
NULL
};
return HelpPages;
}
cString cPluginFemon::SVDRPCommand(const char *commandP, const char *optionP, int &replyCodeP)
{
cDevice *dev = cDevice::ActualDevice();
if (strcasecmp(commandP, "TRAC") == 0) {
if (optionP && *optionP)
FemonConfig.SetTraceMode(strtol(optionP, NULL, 0));
return cString::sprintf("Tracing mode: 0x%04X\n", FemonConfig.GetTraceMode());
}
if (*optionP && isnumber(optionP)) {
cDevice *dev2 = cDevice::GetDevice(int(strtol(optionP, NULL, 10)));
if (dev2)
dev = dev2;
}
if (cReplayControl::NowReplaying() || !dev) {
replyCodeP = 550; // Requested action not taken
return cString("Cannot open femon plugin while replaying");
}
if (strcasecmp(commandP, "OPEN") == 0) {
if (!cFemonOsd::Instance())
cRemote::CallPlugin(Name());
return cString("Opening femon plugin");
}
else if (strcasecmp(commandP, "QUIT") == 0) {
if (cFemonOsd::Instance())
cRemote::Put(kBack);
return cString("Closing femon plugin");
}
else if (strcasecmp(commandP, "NEXT") == 0) {
if (cFemonOsd::Instance())
return cString::sprintf("Switching to next device: %s", cFemonOsd::Instance()->DeviceSwitch(1) ? "ok" : "failed");
else
return cString("Cannot switch device");
}
else if (strcasecmp(commandP, "PREV") == 0) {
if (cFemonOsd::Instance())
return cString::sprintf("Switching to previous device: %s", cFemonOsd::Instance()->DeviceSwitch(-1) ? "ok" : "failed");
else
return cString("Cannot switch device");
}
else if (strcasecmp(commandP, "INFO") == 0) {
return getFrontendInfo(dev);
}
else if (strcasecmp(commandP, "NAME") == 0) {
return getFrontendName(dev);
}
else if (strcasecmp(commandP, "STAT") == 0) {
return getFrontendStatus(dev);
}
else if (strcasecmp(commandP, "STRG") == 0) {
return cString::sprintf("%d on device #%d", dev->SignalStrength(), dev->CardIndex());
}
else if (strcasecmp(commandP, "QUAL") == 0) {
return cString::sprintf("%d on device #%d", dev->SignalQuality(), dev->CardIndex());
}
else if (strcasecmp(commandP, "SGNL") == 0) {
return cString::sprintf("%s on device #%d", *getSignalStrength(getSignal(dev)), dev->CardIndex());
}
else if (strcasecmp(commandP, "CNRA") == 0) {
return cString::sprintf("%.2f dB on device #%d", getCNR(dev), dev->CardIndex());
}
else if (strcasecmp(commandP, "BERA") == 0) {
return cString::sprintf("%.0f on device #%d", getBER(dev), dev->CardIndex());
}
else if (strcasecmp(commandP, "PERA") == 0) {
return cString::sprintf("%.0f on device #%d", getPER(dev), dev->CardIndex());
}
else if (strcasecmp(commandP, "VIBR") == 0) {
if (cFemonOsd::Instance())
return cString::sprintf("%s on device #%d", *getBitrateMbits(cFemonOsd::Instance()->GetVideoBitrate()), cDevice::ActualDevice()->CardIndex());
else
return cString::sprintf("--- Mbit/s on device #%d", cDevice::ActualDevice()->CardIndex());
}
else if (strcasecmp(commandP, "AUBR") == 0) {
if (cFemonOsd::Instance())
return cString::sprintf("%s on device #%d", *getBitrateKbits(cFemonOsd::Instance()->GetAudioBitrate()), cDevice::ActualDevice()->CardIndex());
else
return cString::sprintf("--- kbit/s on device #%d", cDevice::ActualDevice()->CardIndex());
}
else if (strcasecmp(commandP, "DDBR") == 0) {
if (cFemonOsd::Instance())
return cString::sprintf("%s on device #%d", *getBitrateKbits(cFemonOsd::Instance()->GetDolbyBitrate()), cDevice::ActualDevice()->CardIndex());
else
return cString::sprintf("--- kbit/s on device #%d", cDevice::ActualDevice()->CardIndex());
}
return NULL;
}
VDRPLUGINCREATOR(cPluginFemon); // Don't touch this!