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
|
//////////////////////////////////////////////////////////////////////////////
/// ///
/// This file is part of the VDR mpv plugin and licensed under AGPLv3 ///
/// ///
/// See the README file for copyright information ///
/// ///
//////////////////////////////////////////////////////////////////////////////
#include <sys/mman.h>
#include "osd.h"
cMpvOsdProvider::cMpvOsdProvider(cMpvPlayer *player)
{
Player = player;
}
cOsd *cMpvOsdProvider::CreateOsd(int Left, int Top, uint Level)
{
return new cMpvOsd(Left, Top, Level, Player);
}
bool cMpvOsdProvider::ProvidesTrueColor()
{
return true;
}
cMpvOsd::cMpvOsd(int Left, int Top, uint Level, cMpvPlayer *player)
:cOsd(Left, Top, Level)
{
Player = player;
int OsdAreaWidth = OsdWidth() + cOsd::Left();
int OsdAreaHeight = OsdHeight() + cOsd::Top();
fdOsd = open ("/tmp/vdr_mpv_osd", O_CREAT | O_RDWR, S_IWUSR | S_IRUSR);
lseek(fdOsd, OsdAreaWidth*OsdAreaHeight*4, SEEK_SET);
write(fdOsd, "", 1);
pOsd = (char*) mmap (NULL, OsdAreaWidth*OsdAreaHeight*4, PROT_WRITE, MAP_SHARED, fdOsd, 0);
SetActive(true);
}
cMpvOsd::~cMpvOsd()
{
dsyslog("[mpv] %s\n", __FUNCTION__);
SetActive(false);
if (cMpvPlayer::PlayerIsRunning())
Player->OsdClose();
munmap(pOsd, sizeof(pOsd));
close(fdOsd);
remove("/tmp/vdr_mpv_osd");
}
void cMpvOsd::SetActive(bool On)
{
if (On == Active())
{
return;
}
cOsd::SetActive(On);
if (!On)
{
if (cMpvPlayer::PlayerIsRunning())
Player->OsdClose();
cOsd::SetActive(false);
}
}
void cMpvOsd::WriteToMpv(int sw, int sh, int x, int y, int w, int h, const uint8_t * argb)
{
if (!cMpvPlayer::PlayerIsRunning())
return;
int sx;
int sy;
int pos;
char cmd[64];
for (sy = 0; sy < h; ++sy) {
for (sx = 0; sx < w; ++sx) {
pos=0;
pos = pos + ((sy+y)*sw*4);
pos = pos + ((sx+x)*4);
pOsd[pos + 0] = argb[(w * sy + sx) * 4 + 0];
pOsd[pos + 1] = argb[(w * sy + sx) * 4 + 1];
pOsd[pos + 2] = argb[(w * sy + sx) * 4 + 2];
pOsd[pos + 3] = argb[(w * sy + sx) * 4 + 3];
}
}
snprintf (cmd, sizeof(cmd), "overlay_add 1 0 0 @%d 0 \"bgra\" %d %d %d\n", fdOsd, sw, sh, sw*4);
Player->SendCommand (cmd);
}
void cMpvOsd::Flush()
{
cPixmapMemory *pm;
if (!cMpvPlayer::PlayerIsRunning())
cOsd::SetActive(false);
if (!Active())
return;
int OsdAreaWidth = Width() + Left();
int OsdAreaHeight = Height()+ Top();
if (IsTrueColor())
{
LOCK_PIXMAPS;
while ((pm = dynamic_cast<cPixmapMemory *>(RenderPixmaps())))
{
int x;
int y;
int w;
int h;
x = Left() + pm->ViewPort().X();
y = Top() + pm->ViewPort().Y();
w = pm->ViewPort().Width();
h = pm->ViewPort().Height();
WriteToMpv(OsdAreaWidth, OsdAreaHeight, x, y, w, h, pm->Data());
DestroyPixmap(pm);
}
}
else
{
cBitmap *bitmap;
int i;
// draw all bitmaps
for (i = 0; (bitmap = GetBitmap(i)); ++i)
{
uint8_t *argb;
int x;
int y;
int w;
int h;
int x1;
int y1;
int x2;
int y2;
if (!bitmap->Dirty(x1, y1, x2, y2))
{
continue; // nothing dirty continue
}
// convert and upload only dirty areas
w = x2 - x1 + 1;
h = y2 - y1 + 1;
if (1) // just for the case it makes trouble
{
if (w > OsdAreaWidth)
{
w = OsdAreaWidth;
x2 = x1 + OsdAreaWidth - 1;
}
if (h > OsdAreaHeight)
{
h = OsdAreaHeight;
y2 = y1 + OsdAreaHeight - 1;
}
}
argb = (uint8_t *) malloc(w * h * sizeof(uint32_t));
for (y = y1; y <= y2; ++y)
{
for (x = x1; x <= x2; ++x)
{
((uint32_t *) argb)[x - x1 + (y - y1) * w] =
bitmap->GetColor(x, y);
}
}
WriteToMpv(OsdAreaWidth, OsdAreaHeight, Left() + bitmap->X0() + x1, Top() + bitmap->Y0() + y1, w, h, argb);
bitmap->Clean();
// FIXME: reuse argb
free(argb);
}
}
}
|