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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
/*
* osd.c: Xinelib On Screen Display control
*
* See the main source file 'xineliboutput.c' for copyright information and
* how to reach the author.
*
* $Id: osd.c,v 1.1 2006-06-03 10:01:17 phintuka Exp $
*
*/
#include <vdr/config.h>
#include "logdefs.h"
#include "device.h"
#include "osd.h"
#include "config.h"
#define LIMIT_OSD_REFRESH_RATE
#include "xine_osd_command.h"
//extern "C" {
//#include "xine_frontend.h"
//} // extern "C"
static inline void CmdSize(cXinelibDevice *Device, int wnd, int w=0, int h=0)
{
TRACEF("xinelib_osd.c:CmdSize");
if(Device) {
osd_command_t osdcmd;
memset(&osdcmd,0,sizeof(osdcmd));
osdcmd.cmd = OSD_Size;
osdcmd.wnd = wnd;
osdcmd.w = w;
osdcmd.h = h;
Device->OsdCmd((void*)&osdcmd);
}
}
static inline void CmdClose(cXinelibDevice *Device, int wnd)
{
TRACEF("xinelib_osd.c:CmdClose");
if(Device) {
osd_command_t osdcmd;
memset(&osdcmd,0,sizeof(osdcmd));
osdcmd.cmd = OSD_Close;
osdcmd.wnd = wnd;
Device->OsdCmd((void*)&osdcmd);
}
}
static inline void RleCmd(cXinelibDevice *Device, int wnd,
int x0, int y0, int w, int h, unsigned char *data,
int colors, unsigned int *palette)
{
TRACEF("xinelib_osd.c:RleCmd");
if(Device) {
xine_rle_elem_t rle, *rle_p=0;
osd_command_t osdcmd;
int x, y, num_rle=0, rle_size=0;
uint8_t *c;
xine_clut_t clut[256];
memset(&osdcmd, 0, sizeof(osdcmd));
osdcmd.cmd = OSD_Set_RLE;
osdcmd.wnd = wnd;
osdcmd.x = x0;
osdcmd.y = y0;
osdcmd.w = w;
osdcmd.h = h;
/* apply alpha layer correction and convert ARGB -> AYCrCb */
if (colors) {
for(int c=0; c<colors; c++) {
int alpha = (palette[c] & 0xff000000)>>24;
alpha = alpha + xc.alpha_correction*alpha/100 + xc.alpha_correction_abs;
float R = (float)((palette[c] & 0x00ff0000)>>16);
float G = (float)((palette[c] & 0x0000ff00)>>8);
float B = (float)((palette[c] & 0x000000ff));
float Y = + (0.2578125 * R) + (0.50390625 * G) + (0.09765625 * B) + 16.0;
float CR = + (0.4375000 * R) - (0.36718750 * G) - (0.07031250 * B) + 128.0;
float CB = - (0.1484375 * R) - (0.28906250 * G) + (0.43750000 * B) + 128.0;
int y = (int)Y;
int cr = (int)CR;
int cb = (int)CB;
clut[c].y = y<0?0 : y>0xff?0xff : y;
clut[c].cb = cb<0?0 : cb>0xff?0xff : cb;
clut[c].cr = cr<0?0 : cr>0xff?0xff : cr;
clut[c].alpha = alpha<0?0 : alpha>0xff?0xff : alpha;
}
}
osdcmd.colors = colors;
osdcmd.palette = clut;
/* RLE compression */
rle_size = 8128;
rle_p = (xine_rle_elem_t*)malloc(4*rle_size);
osdcmd.data = rle_p;
for( y = 0; y < h; y++ ) {
rle.len = 0;
rle.color = 0;
c = data + y * w;
for( x = 0; x < w; x++, c++ ) {
if( rle.color != *c ) {
if( rle.len ) {
if( (num_rle + h-y+1) > rle_size ) {
rle_size *= 2;
rle_p = (xine_rle_elem_t*)realloc( osdcmd.data, 4*rle_size);
osdcmd.data = rle_p;
rle_p += num_rle;
}
*rle_p++ = rle;
num_rle++;
}
rle.color = *c;
rle.len = 1;
} else {
rle.len++;
}
}
*rle_p++ = rle;
num_rle++;
}
osdcmd.datalen = 4 * num_rle;
TRACE("xinelib_osd.c:RleCmd uncompressed="<< (w*h) <<", compressed=" << (4*num_rle));
Device->OsdCmd((void*)&osdcmd);
if(osdcmd.data)
free(osdcmd.data);
}
}
cXinelibOsd::cXinelibOsd(cXinelibDevice *Device, int x, int y)
: cOsd(x, y), m_IsVisible(true)
{
TRACEF("cXinelibOsd::cXinelibOsd");
m_Device = Device;
m_Shown = false;
CmdSize(m_Device, 0, 720, 576);
}
cXinelibOsd::~cXinelibOsd()
{
TRACEF("cXinelibOsd::~cXinelibOsd");
cXinelibOsdProvider::OsdClosing(this);
m_Lock.Lock();
if(m_IsVisible)
Hide();
m_Lock.Unlock();
cXinelibOsdProvider::OsdClosed(this);
}
eOsdError cXinelibOsd::SetAreas(const tArea *Areas, int NumAreas)
{
TRACEF("cXinelibOsd::SetAreas");
cMutexLock ml(&m_Lock);
eOsdError Result = cOsd::SetAreas(Areas, NumAreas);
if(Result == oeOk)
m_Shown = false;
return Result;
}
eOsdError cXinelibOsd::CanHandleAreas(const tArea *Areas, int NumAreas)
{
TRACEF("cXinelibOsd::CanHandleAreas");
m_Shown = false;
eOsdError Result = cOsd::CanHandleAreas(Areas, NumAreas);
if (Result == oeOk) {
if (NumAreas > MAX_OSD_OBJECT)
return oeTooManyAreas;
for (int i = 0; i < NumAreas; i++) {
if (Areas[i].bpp != 1 && Areas[i].bpp != 2 &&
Areas[i].bpp != 4 && Areas[i].bpp != 8)
return oeBppNotSupported;
}
}
return Result;
}
void cXinelibOsd::Flush(void)
{
TRACEF("cXinelibOsd::Flush");
cMutexLock ml(&m_Lock);
cBitmap *Bitmap;
if(!m_IsVisible)
return;
int SendDone = 0;
for (int i = 0; (Bitmap = GetBitmap(i)) != NULL; i++) {
int x1 = 0, y1 = 0, x2 = Bitmap->Width()-1, y2 = Bitmap->Height()-1;
if (!m_Shown || Bitmap->Dirty(x1, y1, x2, y2)) {
/* XXX what if only palette has been changed ? */
int NumColors;
const tColor *Colors = Bitmap->Colors(NumColors);
RleCmd(m_Device, i,
Left() + Bitmap->X0(), Top() + Bitmap->Y0(),
Bitmap->Width(), Bitmap->Height(),
(unsigned char *)Bitmap->Data(0,0),
NumColors, (unsigned int *)Colors);
SendDone++;
}
Bitmap->Clean();
}
#ifdef LIMIT_OSD_REFRESH_RATE
if(SendDone) {
static int64_t last_refresh = 0LL;
int64_t now = cTimeMs::Now();
if(now - last_refresh < 100LL) {
/* too fast refresh rate, delay ... */
cCondWait::SleepMs(100);
#if 0
LOGDBG("cXinelibOsd::Flush: OSD refreshing too fast ! (>10Hz) -> Sleeping 100ms");
#endif
}
last_refresh = cTimeMs::Now();
}
#endif
#ifdef YAEPG_PATCH
// yaepg
if(!m_Shown && vidWin.bpp != 0) {
LOGDBG("yaepg vidWin %d %d %d %d\n",
vidWin.x1, vidWin.y1, vidWin.x2, vidWin.y2);
fflush(stdout);
}
#endif
m_Shown = true;
}
void cXinelibOsd::Refresh(void)
{
TRACEF("cXinelibOsd::Refresh");
cMutexLock ml(&m_Lock);
m_Shown = false;
Flush();
}
void cXinelibOsd::Show(void)
{
TRACEF("cXinelibOsd::Show");
cMutexLock ml(&m_Lock);
m_IsVisible = true;
Refresh();
}
void cXinelibOsd::Hide(void)
{
TRACEF("cXinelibOsd::Hide");
cMutexLock ml(&m_Lock);
if(m_IsVisible) {
cBitmap *Bitmap;
m_IsVisible = false;
for (int i = 0; (Bitmap = GetBitmap(i)) != NULL; i++)
CmdClose(m_Device, i);
}
}
cList<cXinelibOsd> cXinelibOsdProvider::m_OsdStack;
cMutex cXinelibOsdProvider::m_Lock;
cXinelibOsdProvider::cXinelibOsdProvider(cXinelibDevice *Device)
: m_Device(Device)
{
}
cXinelibOsdProvider::~cXinelibOsdProvider()
{
if(m_OsdStack.First())
LOGMSG("cXinelibOsdProvider: OSD open while OSD provider shutting down !");
}
cOsd *cXinelibOsdProvider::CreateOsd(int Left, int Top)
{
TRACEF("cXinelibOsdProvider::CreateOsd");
cMutexLock ml(&m_Lock);
if(m_OsdStack.First())
LOGDBG("cXinelibOsdProvider::CreateOsd - OSD already open !");
cXinelibOsd *m_OsdInstance = new cXinelibOsd(m_Device, Left, Top);
if(m_OsdStack.First())
m_OsdStack.First()->Hide();
m_OsdStack.Ins(m_OsdInstance);
return m_OsdInstance;
}
void cXinelibOsdProvider::OsdClosed(cXinelibOsd *Osd)
{
TRACEF("cXinelibOsdProvider::OsdClosed");
// m_Lock.Lock(); Atomic with OsdClosing
if(m_OsdStack.First())
m_OsdStack.First()->Show();
m_Lock.Unlock();
}
void cXinelibOsdProvider::OsdClosing(cXinelibOsd *Osd)
{
TRACEF("cXinelibOsdProvider::OsdClosing");
m_Lock.Lock();
m_OsdStack.Del(Osd,false);
// m_Lock.Unlock(); Atomic with OsdClosed
}
void cXinelibOsdProvider::RefreshOsd(void)
{
TRACEF("cXinelibOsdProvider::RefreshOsd");
cMutexLock ml(&m_Lock);
if(m_OsdStack.First())
m_OsdStack.First()->Refresh();
}
|