forked from jojo61/vdr-plugin-softhdcuvid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsofthdcuvid.cpp
3819 lines (3423 loc) · 120 KB
/
softhdcuvid.cpp
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
///
/// @file softhddevice.cpp @brief A software HD device plugin for VDR.
///
/// Copyright (c) 2011 - 2015 by Johns. All Rights Reserved.
///
/// Contributor(s):
///
/// License: AGPLv3
///
/// This program is free software: you can redistribute it and/or modify
/// it under the terms of the GNU Affero General Public License as
/// published by the Free Software Foundation, either version 3 of the
/// License.
///
/// This program is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/// GNU Affero General Public License for more details.
///
/// $Id: fa6a877682f47297580ff5f502425fc7948cb2fa $
//////////////////////////////////////////////////////////////////////////////
#define __STDC_CONSTANT_MACROS ///< needed for ffmpeg UINT64_C
#include <vdr/dvbspu.h>
#include <vdr/interface.h>
#include <vdr/osd.h>
#include <vdr/player.h>
#include <vdr/plugin.h>
#include <vdr/shutdown.h>
#include <vdr/tools.h>
#ifdef HAVE_CONFIG
#include "config.h"
#endif
#include "softhddev.h"
#include "softhddevice.h"
#include "softhddevice_service.h"
#ifdef USE_OPENGLOSD
#include "openglosd.h"
#endif
extern "C" {
#include <libavcodec/avcodec.h>
#include <stdint.h>
#ifndef USE_OPENGLOSD
#include "audio.h"
#include "codec.h"
#include "video.h"
#endif
#ifdef PLACEBO
#include <libplacebo/filters.h>
extern void ToggleLUT();
#endif
}
//////////////////////////////////////////////////////////////////////////////
/// vdr-plugin version number.
/// Makefile extracts the version number for generating the file name
/// for the distribution archive.
static const char *const VERSION = "3.15"
#ifdef GIT_REV
"-GIT" GIT_REV
#endif
;
/// vdr-plugin description.
static const char *const DESCRIPTION = trNOOP("A software and GPU emulated UHD device");
/// vdr-plugin text of main menu entry
static const char *MAINMENUENTRY = trNOOP("SoftUHD");
/// single instance of softhddevice plugin device.
static class cSoftHdDevice *MyDevice;
//////////////////////////////////////////////////////////////////////////////
#define RESOLUTIONS 5 ///< number of resolutions
/// resolutions names
static const char *const Resolution[RESOLUTIONS] = {"576i", "720p", "1080i_fake", "1080i", "UHD"};
static char ConfigMakePrimary; ///< config primary wanted
static char ConfigHideMainMenuEntry; ///< config hide main menu entry
static char ConfigDetachFromMainMenu; ///< detach from main menu entry instead
///< of suspend
static char ConfigSuspendClose; ///< suspend should close devices
static char ConfigSuspendX11; ///< suspend should stop x11
static char Config4to3DisplayFormat = 1; ///< config 4:3 display format
static char ConfigOtherDisplayFormat = 1; ///< config other display format
static uint32_t ConfigVideoBackground; ///< config video background color
static int ConfigOsdWidth; ///< config OSD width
static int ConfigOsdHeight; ///< config OSD height
static char ConfigVideoStudioLevels; ///< config use studio levels
static char ConfigVideo60HzMode; ///< config use 60Hz display mode
static char ConfigVideoSoftStartSync; ///< config use softstart sync
static char ConfigVideoBlackPicture; ///< config enable black picture mode
char ConfigVideoClearOnSwitch; ///< config enable Clear on channel switch
static int ConfigVideoBrightness; ///< config video brightness
static int ConfigVideoContrast = 100; ///< config video contrast
static int ConfigVideoSaturation = 100; ///< config video saturation
static int ConfigVideoHue; ///< config video hue
static int ConfigGamma = 100; ///< config Gamma
static int ConfigTemperature = 0; ///< config Temperature
static int ConfigTargetColorSpace; ///< config Target Colrospace
static int ConfigScalerTest; /// Test for Scalers
static int ConfigColorBlindness;
static int ConfigColorBlindnessFaktor;
/// config deinterlace
static int ConfigVideoDeinterlace[RESOLUTIONS];
/// config skip chroma
static int ConfigVideoSkipChromaDeinterlace[RESOLUTIONS];
/// config inverse telecine
static int ConfigVideoInverseTelecine[RESOLUTIONS];
/// config denoise
static int ConfigVideoDenoise[RESOLUTIONS];
/// config sharpen
static int ConfigVideoSharpen[RESOLUTIONS];
/// config scaling
static int ConfigVideoScaling[RESOLUTIONS];
/// config cut top and bottom pixels
static int ConfigVideoCutTopBottom[RESOLUTIONS];
/// config cut left and right pixels
static int ConfigVideoCutLeftRight[RESOLUTIONS];
static int ConfigVideoAudioDelay; ///< config audio delay
static char ConfigAudioDrift; ///< config audio drift
static char ConfigAudioPassthrough; ///< config audio pass-through mask
static char AudioPassthroughState; ///< flag audio pass-through on/off
static char ConfigAudioDownmix; ///< config ffmpeg audio downmix
static char ConfigAudioSoftvol; ///< config use software volume
static char ConfigAudioNormalize; ///< config use normalize volume
static int ConfigAudioMaxNormalize; ///< config max normalize factor
static char ConfigAudioCompression; ///< config use volume compression
static int ConfigAudioMaxCompression; ///< config max volume compression
static int ConfigAudioStereoDescent; ///< config reduce stereo loudness
int ConfigAudioBufferTime; ///< config size ms of audio buffer
static int ConfigAudioAutoAES; ///< config automatic AES handling
static char *ConfigX11Display; ///< config x11 display
static char *ConfigAudioDevice; ///< config audio stereo device
static char *ConfigPassthroughDevice; ///< config audio pass-through device
#ifdef USE_PIP
static int ConfigPipX = 100 - 3 - 18; ///< config pip pip x in %
static int ConfigPipY = 100 - 4 - 18; ///< config pip pip y in %
static int ConfigPipWidth = 18; ///< config pip pip width in %
static int ConfigPipHeight = 18; ///< config pip pip height in %
static int ConfigPipVideoX; ///< config pip video x in %
static int ConfigPipVideoY; ///< config pip video y in %
static int ConfigPipVideoWidth; ///< config pip video width in %
static int ConfigPipVideoHeight; ///< config pip video height in %
static int ConfigPipAltX; ///< config pip alt. pip x in %
static int ConfigPipAltY = 50; ///< config pip alt. pip y in %
static int ConfigPipAltWidth; ///< config pip alt. pip width in %
static int ConfigPipAltHeight = 50; ///< config pip alt. pip height in %
static int ConfigPipAltVideoX; ///< config pip alt. video x in %
static int ConfigPipAltVideoY; ///< config pip alt. video y in %
static int ConfigPipAltVideoWidth; ///< config pip alt. video width in %
static int ConfigPipAltVideoHeight = 50; ///< config pip alt. video height in %
#endif
#ifdef USE_SCREENSAVER
static char ConfigEnableDPMSatBlackScreen; ///< Enable DPMS(Screensaver) while
///< displaying black screen(radio)
#endif
#ifdef USE_OPENGLOSD
static int ConfigMaxSizeGPUImageCache = 128; ///< maximum size of GPU mem to be used for image caching
#endif
static volatile int DoMakePrimary; ///< switch primary device to this
#define SUSPEND_EXTERNAL -1 ///< play external suspend mode
#define NOT_SUSPENDED 0 ///< not suspend mode
#define SUSPEND_NORMAL 1 ///< normal suspend mode
#define SUSPEND_DETACHED 2 ///< detached suspend mode
static signed char SuspendMode; ///< suspend mode
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// C Callbacks
//////////////////////////////////////////////////////////////////////////////
/**
** Soft device plugin remote class.
*/
class cSoftRemote : public cRemote, private cThread {
private:
cMutex mutex;
cCondVar keyReceived;
cString Command;
virtual void Action(void);
public:
/**
** Soft device remote class constructor.
**
** @param name remote name
*/
cSoftRemote(void) : cRemote("XKeySym") { Start(); }
virtual ~cSoftRemote() { Cancel(3); }
/**
** Receive keycode.
**
** @param code key code
*/
void Receive(const char *code) {
cMutexLock MutexLock(&mutex);
Command = code;
keyReceived.Broadcast();
}
};
void cSoftRemote::Action(void) {
// see also VDR's cKbdRemote::Action()
cTimeMs FirstTime;
cTimeMs LastTime;
cString FirstCommand = "";
cString LastCommand = "";
bool Delayed = false;
bool Repeat = false;
while (Running()) {
cMutexLock MutexLock(&mutex);
if (keyReceived.TimedWait(mutex, Setup.RcRepeatDelta * 3 / 2) && **Command) {
if (strcmp(Command, LastCommand) == 0) {
// If two keyboard events with the same command come in without an
// intermediate timeout, this is a long key press that caused the repeat
// function to kick in:
Delayed = false;
FirstCommand = "";
if (FirstTime.Elapsed() < (uint)Setup.RcRepeatDelay)
continue; // repeat function kicks in after a short delay
if (LastTime.Elapsed() < (uint)Setup.RcRepeatDelta)
continue; // skip same keys coming in too fast
cRemote::Put(Command, true);
Repeat = true;
LastTime.Set();
} else if (strcmp(Command, FirstCommand) == 0) {
// If the same command comes in twice with an intermediate timeout, we
// need to delay the second command to see whether it is going to be
// a repeat function or a separate key press:
Delayed = true;
} else {
// This is a totally new key press, so we accept it immediately:
cRemote::Put(Command);
Delayed = false;
FirstCommand = Command;
FirstTime.Set();
}
} else if (Repeat) {
// Timeout after a repeat function, so we generate a 'release':
cRemote::Put(LastCommand, false, true);
Repeat = false;
} else if (Delayed && *FirstCommand) {
// Timeout after two normal key presses of the same key, so accept the
// delayed key:
cRemote::Put(FirstCommand);
Delayed = false;
FirstCommand = "";
FirstTime.Set();
} else if (**FirstCommand && FirstTime.Elapsed() > (uint)Setup.RcRepeatDelay) {
Delayed = false;
FirstCommand = "";
FirstTime.Set();
}
LastCommand = Command;
Command = "";
}
}
static cSoftRemote *csoft = NULL;
/**
** Feed key press as remote input (called from C part).
**
** @param keymap target keymap "XKeymap" name (obsolete, ignored)
** @param key pressed/released key name
** @param repeat repeated key flag (obsolete, ignored)
** @param release released key flag (obsolete, ignored)
** @param letter x11 character string (system setting locale)
*/
extern "C" void FeedKeyPress(const char *keymap, const char *key, int repeat, int release, const char *letter) {
if (!csoft || !keymap || !key) {
return;
}
csoft->Receive(key);
}
//////////////////////////////////////////////////////////////////////////////
// OSD
//////////////////////////////////////////////////////////////////////////////
/**
** Soft device plugin OSD class.
*/
class cSoftOsd : public cOsd {
public:
static volatile char Dirty; ///< flag force redraw everything
int OsdLevel; ///< current osd level FIXME: remove
cSoftOsd(int, int, uint); ///< osd constructor
virtual ~cSoftOsd(void); ///< osd destructor
/// set the sub-areas to the given areas
virtual eOsdError SetAreas(const tArea *, int);
virtual void Flush(void); ///< commits all data to the hardware
virtual void SetActive(bool); ///< sets OSD to be the active one
};
volatile char cSoftOsd::Dirty; ///< flag force redraw everything
/**
** Sets this OSD to be the active one.
**
** @param on true on, false off
**
** @note only needed as workaround for text2skin plugin with
** undrawn areas.
*/
void cSoftOsd::SetActive(bool on) {
#ifdef OSD_DEBUG
dsyslog("[softhddev]%s: %d level %d\n", __FUNCTION__, on, OsdLevel);
#endif
if (Active() == on) {
return; // already active, no action
}
cOsd::SetActive(on);
if (on) {
Dirty = 1;
// only flush here if there are already bitmaps
if (GetBitmap(0)) {
Flush();
}
} else {
OsdClose();
}
}
/**
** Constructor OSD.
**
** Initializes the OSD with the given coordinates.
**
** @param left x-coordinate of osd on display
** @param top y-coordinate of osd on display
** @param level level of the osd (smallest is shown)
*/
cSoftOsd::cSoftOsd(int left, int top, uint level) : cOsd(left, top, level) {
#ifdef OSD_DEBUG
/* FIXME: OsdWidth/OsdHeight not correct!
*/
dsyslog("[softhddev]%s: %dx%d%+d%+d, %d\n", __FUNCTION__, OsdWidth(), OsdHeight(), left, top, level);
#endif
OsdLevel = level;
}
/**
** OSD Destructor.
**
** Shuts down the OSD.
*/
cSoftOsd::~cSoftOsd(void) {
#ifdef OSD_DEBUG
dsyslog("[softhddev]%s: level %d\n", __FUNCTION__, OsdLevel);
#endif
SetActive(false);
// done by SetActive: OsdClose();
#ifdef USE_YAEPG
// support yaepghd, video window
if (vidWin.bpp) { // restore fullsized video
int width;
int height;
double video_aspect;
::GetOsdSize(&width, &height, &video_aspect);
// works osd relative
::ScaleVideo(0, 0, width, height);
}
#endif
}
/**
** Set the sub-areas to the given areas
*/
eOsdError cSoftOsd::SetAreas(const tArea *areas, int n) {
#ifdef OSD_DEBUG
dsyslog("[softhddev]%s: %d areas \n", __FUNCTION__, n);
#endif
// clear old OSD, when new areas are set
if (!IsTrueColor()) {
cBitmap *bitmap;
int i;
for (i = 0; (bitmap = GetBitmap(i)); i++) {
bitmap->Clean();
}
}
if (Active()) {
VideoOsdClear();
Dirty = 1;
}
return cOsd::SetAreas(areas, n);
}
/**
** Actually commits all data to the OSD hardware.
*/
void cSoftOsd::Flush(void) {
cPixmapMemory *pm;
#ifdef OSD_DEBUG
dsyslog("[softhddev]%s: level %d active %d\n", __FUNCTION__, OsdLevel, Active());
#endif
if (!Active()) { // this osd is not active
return;
}
#ifdef USE_YAEPG
// support yaepghd, video window
if (vidWin.bpp) {
#ifdef OSD_DEBUG
dsyslog("[softhddev]%s: %dx%d%+d%+d\n", __FUNCTION__, vidWin.Width(), vidWin.Height(), vidWin.x1, vidWin.y2);
#endif
// FIXME: vidWin is OSD relative not video window.
// FIXME: doesn't work if fixed OSD width != real window width
// FIXME: solved in VideoSetOutputPosition
::ScaleVideo(Left() + vidWin.x1, Top() + vidWin.y1, vidWin.Width(), vidWin.Height());
}
#endif
if (!IsTrueColor()) {
cBitmap *bitmap;
int i;
#ifdef OSD_DEBUG
static char warned;
if (!warned) {
dsyslog("[softhddev]%s: FIXME: should be truecolor\n", __FUNCTION__);
warned = 1;
}
#endif
// draw all bitmaps
for (i = 0; (bitmap = GetBitmap(i)); ++i) {
uint8_t *argb;
int xs;
int ys;
int x;
int y;
int w;
int h;
int x1;
int y1;
int x2;
int y2;
// get dirty bounding box
if (Dirty) { // forced complete update
x1 = 0;
y1 = 0;
x2 = bitmap->Width() - 1;
y2 = bitmap->Height() - 1;
} else if (!bitmap->Dirty(x1, y1, x2, y2)) {
continue; // nothing dirty continue
}
// convert and upload only visible dirty areas
xs = bitmap->X0() + Left();
ys = bitmap->Y0() + Top();
// FIXME: negtative position bitmaps
w = x2 - x1 + 1;
h = y2 - y1 + 1;
// clip to screen
if (1) { // just for the case it makes trouble
int width;
int height;
double video_aspect;
if (xs < 0) {
if (xs + x1 < 0) {
x1 -= xs + x1;
w += xs + x1;
if (w <= 0) {
continue;
}
}
xs = 0;
}
if (ys < 0) {
if (ys + y1 < 0) {
y1 -= ys + y1;
h += ys + y1;
if (h <= 0) {
continue;
}
}
ys = 0;
}
::GetOsdSize(&width, &height, &video_aspect);
if (w > width - xs - x1) {
w = width - xs - x1;
if (w <= 0) {
continue;
}
x2 = x1 + w - 1;
}
if (h > height - ys - y1) {
h = height - ys - y1;
if (h <= 0) {
continue;
}
y2 = y1 + h - 1;
}
}
#ifdef DEBUG
if (w > bitmap->Width() || h > bitmap->Height()) {
esyslog(tr("[softhddev]: dirty area too big\n"));
abort();
}
#endif
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);
}
}
#ifdef OSD_DEBUG
dsyslog("[softhddev]%s: draw %dx%d%+d%+d bm\n", __FUNCTION__, w, h, xs + x1, ys + y1);
#endif
OsdDrawARGB(0, 0, w, h, w * sizeof(uint32_t), argb, xs + x1, ys + y1);
bitmap->Clean();
// FIXME: reuse argb
free(argb);
}
Dirty = 0;
return;
}
LOCK_PIXMAPS;
while ((pm = (dynamic_cast<cPixmapMemory *>(RenderPixmaps())))) {
int xp;
int yp;
int stride;
int x;
int y;
int w;
int h;
x = pm->ViewPort().X();
y = pm->ViewPort().Y();
w = pm->ViewPort().Width();
h = pm->ViewPort().Height();
stride = w * sizeof(tColor);
// clip to osd
xp = 0;
if (x < 0) {
xp = -x;
w -= xp;
x = 0;
}
yp = 0;
if (y < 0) {
yp = -y;
h -= yp;
y = 0;
}
if (w > Width() - x) {
w = Width() - x;
}
if (h > Height() - y) {
h = Height() - y;
}
x += Left();
y += Top();
// clip to screen
if (1) { // just for the case it makes trouble
// and it can happen!
int width;
int height;
double video_aspect;
if (x < 0) {
w += x;
xp += -x;
x = 0;
}
if (y < 0) {
h += y;
yp += -y;
y = 0;
}
::GetOsdSize(&width, &height, &video_aspect);
if (w > width - x) {
w = width - x;
}
if (h > height - y) {
h = height - y;
}
}
#ifdef OSD_DEBUG
dsyslog("[softhddev]%s: draw %dx%d%+d%+d*%d -> %+d%+d %p\n", __FUNCTION__, w, h, xp, yp, stride, x, y,
pm->Data());
#endif
OsdDrawARGB(xp, yp, w, h, stride, pm->Data(), x, y);
DestroyPixmap(pm);
}
Dirty = 0;
}
#ifdef USE_OPENGLOSD
// Dummy Pixmap for skins
class cDummyPixmap : public cPixmap {
public:
cDummyPixmap(int Layer, const cRect &ViewPort, const cRect &DrawPort = cRect::Null)
: cPixmap(Layer, ViewPort, DrawPort) {}
virtual ~cDummyPixmap(void) {}
virtual void Clear(void) {}
virtual void Fill(tColor Color) { (void)Color; }
virtual void DrawImage(const cPoint &Point, const cImage &Image) {
(void)Point;
(void)Image;
}
virtual void DrawImage(const cPoint &Point, int ImageHandle) {
(void)Point;
(void)ImageHandle;
}
virtual void DrawPixel(const cPoint &Point, tColor Color) {
(void)Point;
(void)Color;
}
virtual void DrawBitmap(const cPoint &Point, const cBitmap &Bitmap, tColor ColorFg = 0, tColor ColorBg = 0,
bool Overlay = false) {
(void)Point;
(void)Bitmap;
(void)ColorFg;
(void)ColorBg;
(void)Overlay;
}
virtual void DrawText(const cPoint &Point, const char *s, tColor ColorFg, tColor ColorBg, const cFont *Font,
int Width = 0, int Height = 0, int Alignment = taDefault) {
(void)Point;
(void)s;
(void)ColorFg;
(void)ColorBg;
(void)Font;
(void)Width;
(void)Height;
(void)Alignment;
}
virtual void DrawRectangle(const cRect &Rect, tColor Color) {
(void)Rect;
(void)Color;
}
virtual void DrawEllipse(const cRect &Rect, tColor Color, int Quadrants = 0) {
(void)Rect;
(void)Color;
(void)Quadrants;
}
virtual void DrawSlope(const cRect &Rect, tColor Color, int Type) {
(void)Rect;
(void)Color;
(void)Type;
}
virtual void Render(const cPixmap *Pixmap, const cRect &Source, const cPoint &Dest) {
(void)Pixmap;
(void)Source;
(void)Dest;
}
virtual void Copy(const cPixmap *Pixmap, const cRect &Source, const cPoint &Dest) {
(void)Pixmap;
(void)Source;
(void)Dest;
}
virtual void Scroll(const cPoint &Dest, const cRect &Source = cRect::Null) {
(void)Dest;
(void)Source;
}
virtual void Pan(const cPoint &Dest, const cRect &Source = cRect::Null) {
(void)Dest;
(void)Source;
}
};
// Dummy OSD for OpenGL OSD if no X Server is available
class cDummyOsd : public cOsd {
private:
cDummyPixmap *p;
public:
cDummyOsd(int Left, int Top, uint Level) : cOsd(Left, Top, Level) {}
virtual ~cDummyOsd() {}
static void SetOsdPosition(int Left, int Top, int Width, int Height) {
(void) Left;
(void) Top;
(void) Width;
(void) Height;
}
virtual cPixmap *CreatePixmap(int Layer, const cRect &ViewPort, const cRect &DrawPort = cRect::Null) {
p = new cDummyPixmap(Layer, ViewPort, DrawPort);
return p;
}
virtual void DestroyPixmap(cPixmap *Pixmap) { (void)Pixmap; }
virtual void DrawImage(const cPoint &Point, const cImage &Image) {
(void)Point;
(void)Image;
}
virtual void DrawImage(const cPoint &Point, int ImageHandle) {
(void)Point;
(void)ImageHandle;
}
virtual eOsdError CanHandleAreas(const tArea *Areas, int NumAreas) {
(void)Areas;
(void)NumAreas;
return oeOk;
}
virtual eOsdError SetAreas(const tArea *Areas, int NumAreas) {
(void)Areas;
(void)NumAreas;
return oeOk;
}
virtual void SaveRegion(int x1, int y1, int x2, int y2) {
(void)x1;
(void)y1;
(void)x2;
(void)y2;
}
virtual void RestoreRegion(void) {}
virtual eOsdError SetPalette(const cPalette &Palette, int Area) {
(void)Palette;
(void)Area;
return oeOk;
}
virtual void DrawPixel(int x, int y, tColor Color) {
(void)x;
(void)y;
(void)Color;
}
virtual void DrawBitmap(int x, int y, const cBitmap &Bitmap, tColor ColorFg = 0, tColor ColorBg = 0,
bool ReplacePalette = false, bool Overlay = false) {
(void)x;
(void)y;
(void)Bitmap;
(void)ColorFg;
(void)ColorBg;
(void)ReplacePalette;
(void)Overlay;
}
virtual void DrawText(int x, int y, const char *s, tColor ColorFg, tColor ColorBg, const cFont *Font,
int Width = 0, int Height = 0, int Alignment = taDefault) {
(void)x;
(void)y;
(void)s;
(void)ColorFg;
(void)ColorBg;
(void)Font;
(void)Width;
(void)Height;
(void)Alignment;
}
virtual void DrawRectangle(int x1, int y1, int x2, int y2, tColor Color) {
(void)x1;
(void)y1;
(void)x2;
(void)y2;
(void)Color;
}
virtual void DrawEllipse(int x1, int y1, int x2, int y2, tColor Color, int Quadrants = 0) {
(void)x1;
(void)y1;
(void)x2;
(void)y2;
(void)Color;
(void)Quadrants;
}
virtual void DrawSlope(int x1, int y1, int x2, int y2, tColor Color, int Type) {
(void)x1;
(void)y1;
(void)x2;
(void)y2;
(void)Color;
(void)Type;
}
virtual void Flush(void) {}
};
#endif
//////////////////////////////////////////////////////////////////////////////
// OSD provider
//////////////////////////////////////////////////////////////////////////////
/**
** Soft device plugin OSD provider class.
*/
class cSoftOsdProvider : public cOsdProvider {
private:
static cOsd *Osd; ///< single OSD
#ifdef USE_OPENGLOSD
static std::shared_ptr<cOglThread> oglThread;
static bool StartOpenGlThread(void);
protected:
virtual int StoreImageData(const cImage &Image);
virtual void DropImageData(int ImageHandle);
#endif
public:
virtual cOsd *CreateOsd(int, int, uint);
virtual bool ProvidesTrueColor(void);
#ifdef USE_OPENGLOSD
static void StopOpenGlThread(void);
static const cImage *GetImageData(int ImageHandle);
static void OsdSizeChanged(void);
#endif
cSoftOsdProvider(void); ///< OSD provider constructor
virtual ~cSoftOsdProvider(); ///< OSD provider destructor
};
cOsd *cSoftOsdProvider::Osd; ///< single osd
#ifdef USE_OPENGLOSD
std::shared_ptr<cOglThread> cSoftOsdProvider::oglThread; ///< openGL worker Thread
int cSoftOsdProvider::StoreImageData(const cImage &Image) {
if (StartOpenGlThread()) {
int imgHandle = oglThread->StoreImage(Image);
return imgHandle;
}
return 0;
}
void cSoftOsdProvider::DropImageData(int ImageHandle) {
if (StartOpenGlThread())
oglThread->DropImageData(ImageHandle);
}
#endif
/**
** Create a new OSD.
**
** @param left x-coordinate of OSD
** @param top y-coordinate of OSD
** @param level layer level of OSD
*/
cOsd *cSoftOsdProvider::CreateOsd(int left, int top, uint level) {
#ifdef USE_OPENGLOSD
dsyslog("[softhddev]%s: left %d, top %d, level %d, using OpenGL OSD support\n", __FUNCTION__, left, top, level);
if (StartOpenGlThread())
return Osd = new cOglOsd(left, top, level, oglThread);
// return dummy osd if shd is detached
dsyslog("[softhddev]OpenGl Thread not started successfully, using Dummy OSD");
return Osd = new cDummyOsd(left, top, 999);
#else
dsyslog("[softhddev]%s: %d, %d, %d\n", __FUNCTION__, left, top, level);
return Osd = new cSoftOsd(left, top, level);
#endif
}
/**
** Check if this OSD provider is able to handle a true color OSD.
**
** @returns true we are able to handle a true color OSD.
*/
bool cSoftOsdProvider::ProvidesTrueColor(void) { return true; }
#ifdef USE_OPENGLOSD
const cImage *cSoftOsdProvider::GetImageData(int ImageHandle) { return cOsdProvider::GetImageData(ImageHandle); }
void cSoftOsdProvider::OsdSizeChanged(void) {
// cleanup OpenGl Context
cSoftOsdProvider::StopOpenGlThread();
cOsdProvider::UpdateOsdSize();
}
bool cSoftOsdProvider::StartOpenGlThread(void) {
// only try to start worker thread if shd is attached
// otherwise glutInit() crashes
if (SuspendMode != NOT_SUSPENDED) {
dsyslog("[softhddev]detached - OpenGl Worker Thread not tried to start");
return false;
}
if (oglThread.get()) {
if (oglThread->Active()) {
return true;
}
oglThread.reset();
}
cCondWait wait;
dsyslog("[softhddev]Trying to start OpenGL Worker Thread");
oglThread.reset(new cOglThread(&wait, ConfigMaxSizeGPUImageCache));
wait.Wait();
if (oglThread->Active()) {
dsyslog("[softhddev]OpenGL Worker Thread successfully started");
return true;
}
dsyslog("[softhddev]openGL Thread NOT successfully started");
return false;
}
void cSoftOsdProvider::StopOpenGlThread(void) {
dsyslog("[softhddev]stopping OpenGL Worker Thread ");
if (oglThread) {
// OsdClose();
oglThread->Stop();
}
oglThread.reset();
dsyslog("[softhddev]OpenGL Worker Thread stopped");
}
#endif
/**
** Create cOsdProvider class.
*/
cSoftOsdProvider::cSoftOsdProvider(void) : cOsdProvider() {
#ifdef OSD_DEBUG
dsyslog("[softhddev]%s:\n", __FUNCTION__);
#endif
#ifdef USE_OPENGLOSD
StopOpenGlThread();
VideoSetVideoEventCallback(&OsdSizeChanged);
#endif
}
/**
** Destroy cOsdProvider class.
*/
cSoftOsdProvider::~cSoftOsdProvider() {
#ifdef OSD_DEBUG
dsyslog("[softhddev]%s:\n", __FUNCTION__);
#endif
#ifdef USE_OPENGLOSD
StopOpenGlThread();
#endif
}
//////////////////////////////////////////////////////////////////////////////
// cMenuSetupPage
//////////////////////////////////////////////////////////////////////////////
/**
** Soft device plugin menu setup page class.
*/
class cMenuSetupSoft : public cMenuSetupPage {
protected:
///
/// local copies of global setup variables:
/// @{
int General;
int MakePrimary;
int HideMainMenuEntry;
int DetachFromMainMenu;
int OsdSize;
int OsdWidth;
int OsdHeight;
int SuspendClose;
int SuspendX11;
int Video;
int Video4to3DisplayFormat;
int VideoOtherDisplayFormat;
uint32_t Background;
uint32_t BackgroundAlpha;
int StudioLevels;
int _60HzMode;
int SoftStartSync;
int BlackPicture;