forked from jowi24/vdr-screenshot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreenshot.c
More file actions
executable file
·318 lines (277 loc) · 11.9 KB
/
screenshot.c
File metadata and controls
executable file
·318 lines (277 loc) · 11.9 KB
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
/*
* screenshot.c: A plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
*/
#include "screenshot.h"
#include <vdr/interface.h>
#include <vdr/status.h>
#include <vdr/recording.h>
#include <vdr/skins.h>
cScreenshotConfig screenshotConfig;
cScreenshotData screenshotData;
#ifdef FALSE
static const char *DESCRIPTION = trNOOP("Takes screenshots");
static const char *MAINMENUENTRY = trNOOP("Screenshot");
#endif
/*-------------------------------------------------------------------------------------------------
**************** class cThreadScreenshot **********************************************************
-------------------------------------------------------------------------------------------------*/
void cThreadScreenshot::Action(void) {
//FIX
// cCondWait::SleepMs(500);
const char *Title = screenshotData.osd_title[0] ? screenshotData.osd_title :
screenshotData.title[0] ? screenshotData.title : "screenshot";
int i = 0;
int pnr = 0;
time_t t = time(NULL);
struct tm *now = localtime(&t);
bool isOk = true;
// take pictures
while (isOk && i < screenshotConfig.iNoOfPics) {
char fileName[100];
FILE *fp;
do {
pnr++;
now = localtime(&t);
sprintf(fileName, "%s/%s-%d%02d%02d-%03d.%s", screenshotConfig.sPath, Title, \
now->tm_year + 1900, now->tm_mon + 1, now->tm_mday, \
pnr, FILEFORMATS[screenshotConfig.iFileformat]);
fp = fopen(fileName, "r");
if (fp) fclose(fp);
} while (fp != NULL);
//FIX
/*
if (screenshotConfig.iShowDate) {
Skins.Message(mtInfo, tmp);
Skins.Flush();
}
*/
int iResY = screenshotConfig.iResY;
if( iResY == 0 )
{
iResY = screenshotConfig.iResX / (1.25 * Setup.OSDAspect);
}
isOk = cDevice::PrimaryDevice()->GrabImageFile(fileName, screenshotConfig.iFileformat,
screenshotConfig.iQuality,
screenshotConfig.iResX,
iResY);
i++;
}
if (screenshotData.osd) {
delete screenshotData.osd;
screenshotData.osd = NULL;
}
// show result
if (isOk) {
isyslog("screenshot: %d image%s saved", screenshotConfig.iNoOfPics, (screenshotConfig.iNoOfPics > 1) ? "s" : "");
const char *tmp = tr(screenshotConfig.iNoOfPics > 1 ? "OK - Images saved." : "OK - Image saved.");
Skins.QueueMessage(mtInfo, tmp);
Skins.Flush();
} else {
esyslog("screenshot: error calling GrabImage(...)");
Skins.QueueMessage(mtError, tr("Error"));
Skins.Flush();
}
}
/*-------------------------------------------------------------------------------------------------
**************** class cMenuScreenshot ************************************************************
-------------------------------------------------------------------------------------------------*/
cMenuScreenshot::cMenuScreenshot(void) {
}
void cMenuScreenshot::Show(void) {
time_t t = time(NULL);
struct tm *now = localtime(&t);
strftime(tmp, sizeof(tmp), "%Y.%m.%d %H:%M", now);
if (screenshotConfig.iShowDate) {
const cFont *fn = cFont::GetFont(fontSml);
cOsd *osd = cOsdProvider::NewOsd(Setup.OSDLeft, Setup.OSDTop);
tArea Areas[] = { { 0, Setup.OSDHeight - fn->Height(tmp), Setup.OSDWidth - 1, Setup.OSDHeight - 1, 4 } };
osd->SetAreas(Areas, sizeof(Areas) / sizeof(tArea));
osd->DrawRectangle(0, Setup.OSDHeight - fn->Height(tmp), Setup.OSDWidth - 1, Setup.OSDHeight - 1, clrTransparent);
osd->DrawText(1, Setup.OSDHeight - fn->Height(tmp), tmp, (tColor)clrWhite, (tColor)clrTransparent, fn);
osd->Flush();
screenshotData.osd = osd;
}
(new cThreadScreenshot())->Start();
}
/*-------------------------------------------------------------------------------------------------
**************** struct cScreenshotConfig **********************************************************
-------------------------------------------------------------------------------------------------*/
cScreenshotConfig::cScreenshotConfig(void) {
strcpy(sPath, "/tmp");
iFileformat = 1;
iQuality = 95;
iResX = 768;
iResY = 576;
iNoOfPics = 1;
iHideMenuEntry = false;
iUserKey = 0;
iHideOsd = true;
iShowDate = false;
iDelayed = false;
}
/*-------------------------------------------------------------------------------------------------
**************** class cMenuSetupScreenshot *******************************************************
-------------------------------------------------------------------------------------------------*/
void cMenuSetupScreenshot::Store(void) {
strcpy(screenshotConfig.sPath, sNewPath);
screenshotConfig.iFileformat = iNewFileformat;
screenshotConfig.iQuality = iNewQuality;
screenshotConfig.iResX = iNewResX;
screenshotConfig.iResY = iNewResY;
screenshotConfig.iNoOfPics = iNewNoOfPics;
screenshotConfig.iHideMenuEntry = iNewHideMenuEntry;
screenshotConfig.iHideOsd = iNewHideOsd;
screenshotConfig.iShowDate = iNewShowDate;
screenshotConfig.iDelayed = iNewDelayed;
SetupStore("Path", screenshotConfig.sPath);
SetupStore("Fileformat", screenshotConfig.iFileformat);
SetupStore("Quality", screenshotConfig.iQuality);
SetupStore("ResX", screenshotConfig.iResX);
SetupStore("ResY", screenshotConfig.iResY);
SetupStore("NoOfPics", screenshotConfig.iNoOfPics);
SetupStore("HideMenuEntry", screenshotConfig.iHideMenuEntry);
SetupStore("UserKey", screenshotConfig.iUserKey);
SetupStore("HideOsd", screenshotConfig.iHideOsd);
SetupStore("ShowDate", screenshotConfig.iShowDate);
SetupStore("Delayed", screenshotConfig.iDelayed);
}
cMenuSetupScreenshot::cMenuSetupScreenshot(void) {
strcpy(sNewPath, screenshotConfig.sPath);
iNewFileformat = screenshotConfig.iFileformat;
iNewQuality = screenshotConfig.iQuality;
iNewResX = screenshotConfig.iResX;
iNewResY = screenshotConfig.iResY;
iNewNoOfPics = screenshotConfig.iNoOfPics;
iNewHideMenuEntry = screenshotConfig.iHideMenuEntry;
iNewUserKey = screenshotConfig.iUserKey;
iNewHideOsd = screenshotConfig.iHideOsd;
iNewShowDate = screenshotConfig.iShowDate;
iNewDelayed = screenshotConfig.iDelayed;
char allowedChars[100];
sprintf(allowedChars, "%s/", tr(FileNameChars));
Add(new cMenuEditStrItem (tr("Image directory"), sNewPath, sizeof(sNewPath), allowedChars));
Add(new cMenuEditStraItem (tr("Fileformat"), &iNewFileformat, 2, FILEFORMATS));
Add(new cMenuEditIntItem (tr("Image quality (1-100)"), &iNewQuality, 1, 100));
Add(new cMenuEditIntItem (tr("Image width (Pixel)"), &iNewResX, 1, 768));
Add(new cMenuEditIntItem (tr("Image height (Pixel)"), &iNewResY, 0, 576));
Add(new cMenuEditIntItem (tr("No. of pictures to take"), &iNewNoOfPics, 1, 100));
Add(new cMenuEditBoolItem (tr("Hide mainmenu entry"), &iNewHideMenuEntry));
// Add(new cMenuEditBoolItem (tr("Hide OSD"), &iNewHideOsd));
Add(new cMenuEditBoolItem (tr("Show Date"), &iNewShowDate));
Add(new cMenuEditBoolItem (tr("Enable delayed shooting"), &iNewDelayed));
}
/*-------------------------------------------------------------------------------------------------
**************** class cPluginScreenshot **********************************************************
-------------------------------------------------------------------------------------------------*/
cPluginScreenshot::cPluginScreenshot(void) {
// 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!
screenshotData.title[0] = 0;
screenshotData.osd_title[0] = 0;
screenshotData.osd = NULL;
delayActive = false;
muteCounter = 0;
currentVolume = -1;
}
cPluginScreenshot::~cPluginScreenshot() {
// Clean up after yourself!
}
const char *cPluginScreenshot::CommandLineHelp(void) {
// Return a string that describes all known command line options.
return NULL;
}
bool cPluginScreenshot::ProcessArgs(int argc, char *argv[]) {
// Implement command line argument processing here if applicable.
return true;
}
bool cPluginScreenshot::Initialize(void) {
// Initialize any background activities the plugin shall perform.
return true;
}
bool cPluginScreenshot::Start(void) {
// Start any background activities the plugin shall perform.
// Make dummy picture at startup, because the first screenshot using
// GrabImage(...) only takes a gray image.
cDevice::PrimaryDevice()->GrabImageFile("/dev/null", false);
return true;
}
void cPluginScreenshot::Housekeeping(void) {
// Perform any cleanup or other regular tasks.
}
const char *cPluginScreenshot::MainMenuEntry(void) {
return screenshotConfig.iHideMenuEntry ? NULL : tr(MAINMENUENTRY);
}
cOsdObject *cPluginScreenshot::MainMenuAction(void) {
if (screenshotConfig.iDelayed && muteCounter < 2) {
delayActive = true;
Skins.QueueMessage(mtInfo, tr("Delayed shooting active."));
Skins.Flush();
} else {
muteCounter = 0;
if (screenshotConfig.iDelayed)
(new cThreadScreenshot())->Start();
else {
return new cMenuScreenshot();
}
}
return NULL;
}
cMenuSetupPage *cPluginScreenshot::SetupMenu(void) {
// Return a setup menu in case the plugin supports one.
return new cMenuSetupScreenshot;
}
bool cPluginScreenshot::SetupParse(const char *Name, const char *Value) {
// Parse your own setup parameters and store their values.
if (!strcasecmp(Name, "Path")) strcpy(screenshotConfig.sPath, Value);
else if (!strcasecmp(Name, "Quality")) screenshotConfig.iQuality = atoi(Value);
else if (!strcasecmp(Name, "ResX")) screenshotConfig.iResX = atoi(Value);
else if (!strcasecmp(Name, "ResY")) screenshotConfig.iResY = atoi(Value);
else if (!strcasecmp(Name, "Fileformat")) screenshotConfig.iFileformat = atoi(Value);
else if (!strcasecmp(Name, "NoOfPics")) screenshotConfig.iNoOfPics = atoi(Value);
else if (!strcasecmp(Name, "HideMenuEntry")) screenshotConfig.iHideMenuEntry = atoi(Value);
else if (!strcasecmp(Name, "UserKey")) screenshotConfig.iUserKey = atoi(Value);
else if (!strcasecmp(Name, "HideOsd")) screenshotConfig.iHideOsd = atoi(Value);
else if (!strcasecmp(Name, "ShowDate")) screenshotConfig.iShowDate = atoi(Value);
else if (!strcasecmp(Name, "Delayed")) screenshotConfig.iDelayed = atoi(Value);
else return false;
return true;
}
void cPluginScreenshot::Replaying(const cControl *Control, const char *Name, const char *FileName, bool On) {
if (Name)
strncpy(screenshotData.title, Name, sizeof(screenshotData.title));
else
strcpy(screenshotData.title, "screenshot");
while (char *s= strchr(screenshotData.title, '/'))
s[0] = '-';
}
void cPluginScreenshot::OsdProgramme(time_t PresentTime, const char *PresentTitle, const char *PresentSubtitle,
time_t FollowingTime, const char *FollowingTitle, const char *FollowingSubtitle) {
if (PresentTitle)
strncpy(screenshotData.title, PresentTitle, sizeof(screenshotData.title));
else
strcpy(screenshotData.title, "screenshot");
while (char *s= strchr(screenshotData.title, '/'))
s[0] = '-';
}
void cPluginScreenshot::SetVolume(int Volume, bool Absolute) {
if (delayActive) {
if ((currentVolume == 0 && Volume > 0) || (currentVolume > 0 && Volume == 0))
muteCounter++;
if (muteCounter == 2) {
delayActive = false;
MainMenuAction();
}
}
currentVolume = Volume;
}
void cPluginScreenshot::OsdTitle(const char *title) {
strncpy(screenshotData.osd_title, title, sizeof(screenshotData.osd_title));
}
void cPluginScreenshot::OsdClear() {
screenshotData.osd_title[0] = 0;
}
VDRPLUGINCREATOR(cPluginScreenshot); // Don't touch this!