-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathosd.c
261 lines (230 loc) · 7.74 KB
/
osd.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
#include "osd.h"
#include "common.h"
#include "connection.h"
#include "helper.h"
#include <sys/time.h>
#ifndef NO_PNGPP
#include <png++/image.hpp>
#include <png++/rgba_pixel.hpp>
#endif
#include <vdr/device.h>
#include <vdr/videodir.h>
#define DBUSOSDDIR "/tmp/dbus2vdr"
//#define DBUSOSDDIR VideoDirectory
int cDBusOsd::osd_number = 0;
cDBusOsd::cDBusOsd(cDBusOsdProvider& Provider, int Left, int Top, uint Level)
:cOsd(Left, Top, Level)
,provider(Provider)
,osd_index(osd_number++)
,counter(0)
{
osd_dir = cString::sprintf("%s/dbusosd-%04x", DBUSOSDDIR, osd_index);
if (!MakeDirs(*osd_dir, true))
esyslog("dbus2vdr: can't create %s", *osd_dir);
provider.SendMessage(new cDbusOsdMsg("Open", osd_dir, Left, Top, 0, 0));
}
cDBusOsd::~cDBusOsd()
{
provider.SendMessage(new cDbusOsdMsg("Close", osd_dir, 0, 0, 0, 0));
}
void cDBusOsd::Flush(void)
{
if (!cOsd::Active())
return;
#ifndef NO_PNGPP
/*
struct timeval start;
struct timeval end;
struct timezone timeZone;
gettimeofday(&start, &timeZone);
bool write = false;
*/
#if VDRVERSNUM >= 10717
if (IsTrueColor()) {
LOCK_PIXMAPS;
int left = Left();
int top = Top();
const cRect* vp;
int vx, vy, vw, vh;
int x, y;
const uint8_t *pixel;
png::image<png::rgba_pixel> *pngfile;
while (cPixmapMemory *pm = dynamic_cast<cPixmapMemory*>(RenderPixmaps())) {
/*write = true;*/
vp = &pm->ViewPort();
vx = vp->X();
vy = vp->Y();
vw = vp->Width();
vh = vp->Height();
pixel = pm->Data();
pngfile = new png::image<png::rgba_pixel>(vw, vh);
for (y = 0; y < vh ; y++) {
for (x = 0; x < vw; x++) {
(*pngfile)[y][x] = png::rgba_pixel(pixel[2], pixel[1], pixel[0], pixel[3]);
pixel += 4;
}
}
cString filename = cString::sprintf("%s/%04x-%d-%d-%d-%d.png", *osd_dir, counter, left, top, vx, vy);
pngfile->write(*filename);
provider.SendMessage(new cDbusOsdMsg("Display", filename, left, top, vx, vy));
counter++;
delete pngfile;
#if APIVERSNUM >= 20110
DestroyPixmap(pm);
#else
delete pm;
#endif
}
}
#endif
/*
if (write) {
gettimeofday(&end, &timeZone);
int timeNeeded = end.tv_usec - start.tv_usec;
timeNeeded += (end.tv_sec - start.tv_sec) * 1000000;
isyslog("dbus2vdr: flushing osd %d needed %d\n", osd_index, timeNeeded);
}
*/
#endif
}
cDBusOsdProvider *cDBusOsdProvider::_provider = NULL;
cDBusOsdProvider::cDBusOsdProvider(cDBusObject *Object)
{
_provider = this;
_object = Object;
isyslog("dbus2vdr: new DBus-OSD-provider");
SetDescription("dbus2vdr: osd-provider signal");
Start();
}
cDBusOsdProvider::~cDBusOsdProvider()
{
_provider = NULL;
isyslog("dbus2vdr: delete DBus-OSD-provider");
msgCond.Broadcast();
Cancel(10);
}
cOsd *cDBusOsdProvider::CreateOsd(int Left, int Top, uint Level)
{
return new cDBusOsd(*this, Left, Top, Level);
}
void cDBusOsdProvider::Action(void)
{
while (Running() || (msgQueue.Count() > 0)) {
cDbusOsdMsg *dbmsg = NULL;
{ // for short lock
cMutexLock MutexLock(&msgMutex);
dbmsg = msgQueue.First();
if (dbmsg != NULL)
msgQueue.Del(dbmsg, false);
}
if (dbmsg != NULL) {
GVariantBuilder *builder = NULL;
if (strcmp(dbmsg->action, "Open") == 0) {
builder = g_variant_builder_new(G_VARIANT_TYPE("(sii)"));
g_variant_builder_add(builder, "s", *dbmsg->file);
g_variant_builder_add(builder, "i", dbmsg->left);
g_variant_builder_add(builder, "i", dbmsg->top);
}
else if (strcmp(dbmsg->action, "Display") == 0) {
builder = g_variant_builder_new(G_VARIANT_TYPE("(siiii)"));
g_variant_builder_add(builder, "s", *dbmsg->file);
g_variant_builder_add(builder, "i", dbmsg->left);
g_variant_builder_add(builder, "i", dbmsg->top);
g_variant_builder_add(builder, "i", dbmsg->vx);
g_variant_builder_add(builder, "i", dbmsg->vy);
}
else if (strcmp(dbmsg->action, "Close") == 0) {
builder = g_variant_builder_new(G_VARIANT_TYPE("(s)"));
g_variant_builder_add(builder, "s", *dbmsg->file);
}
if ((builder != NULL) && (_object != NULL)) {
_object->Connection()->EmitSignal(new cDBusSignal(NULL, "/OSD", DBUS_VDR_OSD_INTERFACE, dbmsg->action, g_variant_builder_end(builder), NULL, NULL));
g_variant_builder_unref(builder);
}
delete dbmsg;
}
cMutexLock MutexLock(&msgMutex);
if (msgQueue.Count() == 0)
msgCond.TimedWait(msgMutex, 1000);
}
}
void cDBusOsdProvider::SendMessage(cDbusOsdMsg *Msg)
{
cMutexLock MutexLock(&msgMutex);
msgQueue.Add(Msg);
msgCond.Broadcast();
}
cDbusOsdMsg::~cDbusOsdMsg(void)
{
if (strcmp(action, "Close") == 0) {
isyslog("dbus2vdr: deleting osd files at %s", *file);
RemoveFileOrDir(*file, false);
}
}
class cDBusOsdObjectHelper
{
public:
static const char *_xmlNodeInfo;
static void CreateProvider(cDBusObject *Object, GVariant *Parameters, GDBusMethodInvocation *Invocation)
{
if (cDBusOsdProvider::_provider == NULL) {
new cDBusOsdProvider(Object);
cDBusHelper::SendReply(Invocation, 250, "DBus-OSD-provider created");
return;
}
cDBusHelper::SendReply(Invocation, 900, "DBus-OSD-provider already active");
};
static void DeleteProvider(cDBusObject *Object, GVariant *Parameters, GDBusMethodInvocation *Invocation)
{
if (cDBusOsdProvider::_provider != NULL) {
delete cDBusOsdProvider::_provider;
// try to re-create the OSD provider of the primary device
// I don't know if it's "good" or work with all output plugins
cDevice *pd = cDevice::PrimaryDevice();
if (pd)
cDevice::SetPrimaryDevice(pd->CardIndex() + 1);
cDBusHelper::SendReply(Invocation, 250, "DBus-OSD-provider deleted");
return;
}
cDBusHelper::SendReply(Invocation, 900, "DBus-OSD-provider not active");
};
};
const char *cDBusOsdObjectHelper::_xmlNodeInfo =
"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
" \"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
"<node>\n"
" <interface name=\""DBUS_VDR_OSD_INTERFACE"\">\n"
" <method name=\"CreateProvider\">\n"
" <arg name=\"replycode\" type=\"i\" direction=\"out\"/>\n"
" <arg name=\"replymessage\" type=\"s\" direction=\"out\"/>\n"
" </method>\n"
" <method name=\"DeleteProvider\">\n"
" <arg name=\"replycode\" type=\"i\" direction=\"out\"/>\n"
" <arg name=\"replymessage\" type=\"s\" direction=\"out\"/>\n"
" </method>\n"
" <signal name=\"Open\">\n"
" <arg name=\"osdid\" type=\"s\"/>\n"
" <arg name=\"left\" type=\"i\"/>\n"
" <arg name=\"top\" type=\"i\"/>\n"
" </signal>\n"
" <signal name=\"Display\">\n"
" <arg name=\"filename\" type=\"s\"/>\n"
" <arg name=\"left\" type=\"i\"/>\n"
" <arg name=\"top\" type=\"i\"/>\n"
" <arg name=\"vx\" type=\"i\"/>\n"
" <arg name=\"vy\" type=\"i\"/>\n"
" </signal>\n"
" <signal name=\"Close\">\n"
" <arg name=\"osdid\" type=\"s\"/>\n"
" </signal>\n"
" </interface>\n"
"</node>\n";
cDBusOsdObject::cDBusOsdObject(void)
:cDBusObject("/OSD", cDBusOsdObjectHelper::_xmlNodeInfo)
{
AddMethod("CreateProvider", cDBusOsdObjectHelper::CreateProvider);
AddMethod("DeleteProvider", cDBusOsdObjectHelper::DeleteProvider);
}
cDBusOsdObject::~cDBusOsdObject(void)
{
}