-
Notifications
You must be signed in to change notification settings - Fork 11
/
vaapidevice.cpp
2782 lines (2498 loc) · 75.5 KB
/
vaapidevice.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
/// Copyright (C) 2011 - 2015 by Johns. All Rights Reserved.
/// Copyright (C) 2018 by pesintta, rofafor.
///
/// SPDX-License-Identifier: AGPL-3.0-only
#define __STDC_CONSTANT_MACROS ///< needed for ffmpeg UINT64_C
#include <vdr/interface.h>
#include <vdr/plugin.h>
#include <vdr/player.h>
#include <vdr/osd.h>
#include <vdr/dvbspu.h>
#include <vdr/shutdown.h>
#include <vdr/tools.h>
#include "vaapidevice.h"
extern "C"
{
#include <stdint.h>
#include <libavcodec/avcodec.h>
#include "audio.h"
#include "video.h"
#include "codec.h"
#include "misc.h"
}
#if defined(APIVERSNUM) && APIVERSNUM < 20200
#error "VDR-2.2.0 API version or greater is required!"
#endif
//////////////////////////////////////////////////////////////////////////////
/// vdr-plugin version number.
/// Makefile extracts the version number for generating the file name
/// for the distribution archive.
static const char *const VERSION = "1.0.0"
#ifdef GIT_REV
"-GIT" GIT_REV
#endif
;
/// vdr-plugin description.
static const char *const DESCRIPTION = trNOOP("VA-API Output Device");
/// vdr-plugin text of main menu entry
static const char *MAINMENUENTRY = trNOOP("VA-API Device");
/// single instance of vaapidevice plugin device.
static class cVaapiDevice *MyDevice;
//////////////////////////////////////////////////////////////////////////////
#define RESOLUTIONS 5 ///< number of resolutions
/// resolutions names
static const char *const Resolution[RESOLUTIONS] = {
"576i", "720p", "1080i", "1080p", "2160p"
};
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 char ConfigVideo60HzMode; ///< config use 60Hz display mode
static char ConfigVideoSoftStartSync; ///< config use softstart sync
static int ConfigVideoColorBalance = 1; ///< config video color balance
static int ConfigVideoBrightness; ///< config video brightness
static int ConfigVideoContrast = 1; ///< config video contrast
static int ConfigVideoSaturation = 1; ///< config video saturation
static int ConfigVideoHue; ///< config video hue
static int ConfigVideoStde = 0; ///< config video skin tone enhancement
/// config deinterlace
static int ConfigVideoDeinterlace[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 ConfigAutoCropEnabled; ///< auto crop detection enabled
static int ConfigAutoCropInterval; ///< auto crop detection interval
static int ConfigAutoCropDelay; ///< auto crop detection delay
static int ConfigAutoCropTolerance; ///< auto crop detection tolerance
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 char *ConfigX11Display; ///< config x11 display
static char *ConfigAudioDevice; ///< config audio stereo device
static char *ConfigPassthroughDevice; ///< config audio pass-through device
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
volatile char SoftIsPlayingVideo; ///< stream contains video data
static cString CommandLineParameters = ""; ///< plugin's command-line parameters
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// C Callbacks
//////////////////////////////////////////////////////////////////////////////
/**
** Logging function with thread information
*/
extern "C" void LogMessage(int trace, int level, const char *format, ...)
{
if (SysLogLevel > level) {
va_list ap;
char fmt[256];
int priority, mask;
const char *prefix = "VAAPI: ";
switch (level) {
case 0: // ERROR
prefix = "VAAPI-ERROR: ";
priority = LOG_ERR;
break;
case 1: // INFO
priority = LOG_INFO;
break;
case 2: // DEBUG
mask = (1 << (trace - 1)) & 0xFFFF;
if (!(mask & TraceMode))
return;
priority = LOG_DEBUG;
break;
default:
priority = LOG_DEBUG;
break;
}
snprintf(fmt, sizeof(fmt), "[%d] %s%s", cThread::ThreadId(), prefix, format);
va_start(ap, format);
vsyslog(priority, fmt, ap);
va_end(ap);
}
}
/**
** Debug statistics on OSD class.
*/
class cDebugStatistics:public cThread
{
private:
cOsd * osd;
int area_w;
int area_h;
int area_bpp;
cString VideoStats(void)
{
cString stats = "";
char *info = GetVideoStats();
if (info)
{
stats = info;
free(info);
}
return stats;
}
cString VideoInfo(void)
{
cString stats = "";
char *info = GetVideoInfo();
if (info) {
stats = info;
free(info);
}
return stats;
}
cString AudioInfo(void)
{
cString stats = "";
char *info = GetAudioInfo();
if (info) {
stats = info;
free(info);
}
return stats;
}
void Draw(void)
{
LOCK_THREAD;
if (osd) {
const cFont *font = cFont::GetFont(fontSml);
int y = 0, h = font->Height();
osd->DrawText(0, y, *VideoStats(), clrWhite, clrGray50, font, area_w, h);
y += h;
osd->DrawText(0, y, *VideoInfo(), clrWhite, clrGray50, font, area_w, h);
y += h;
osd->DrawText(0, y, *AudioInfo(), clrWhite, clrGray50, font, area_w, h);
y += h;
osd->Flush();
}
}
bool Delete(void)
{
LOCK_THREAD;
if (Running()) {
Cancel(3);
DELETENULL(osd);
return true;
}
return false;
}
bool Create(void)
{
LOCK_THREAD;
if (!osd) {
osd = cOsdProvider::NewOsd(0, 0, 1);
tArea Area = { 0, 0, area_w, area_h, area_bpp };
osd->SetAreas(&Area, 1);
}
return osd != NULL;
}
protected:
virtual void Action(void)
{
Create();
while (Running()) {
Draw();
cCondWait::SleepMs(500);
}
}
public:
cDebugStatistics():cThread("VAAPI Stats"), osd(NULL), area_w(4096), area_h(2160), area_bpp(32) {
}
virtual ~ cDebugStatistics() {
Delete();
}
bool Toggle(void)
{
if (Delete()) {
return false;
}
Start();
return true;
}
cString Dump(void)
{
return cString::sprintf("%s\n%s\n%s\nCommand:%s\n", *VideoStats(), *VideoInfo(), *AudioInfo(),
*CommandLineParameters);
}
};
static class cDebugStatistics *MyDebug;
/**
** 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)
{
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)
{
OsdLevel = level;
}
/**
** OSD Destructor.
**
** Shuts down the OSD.
*/
cSoftOsd::~cSoftOsd(void)
{
SetActive(false);
// done by SetActive: OsdClose();
}
/**
+* Set the sub-areas to the given areas
*/
eOsdError cSoftOsd::SetAreas(const tArea * areas, int n)
{
// 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;
if (!Active()) { // this osd is not active
return;
}
if (!IsTrueColor()) {
cBitmap *bitmap;
int i;
// 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;
int width;
int height;
double video_aspect;
// 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 (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()) {
Error("Dirty area too big");
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);
}
}
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;
int width;
int height;
double video_aspect;
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 (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;
}
OsdDrawARGB(xp, yp, w, h, stride, pm->Data(), x, y);
DestroyPixmap(pm);
}
Dirty = 0;
}
//////////////////////////////////////////////////////////////////////////////
// OSD provider
//////////////////////////////////////////////////////////////////////////////
/**
** Soft device plugin OSD provider class.
*/
class cSoftOsdProvider:public cOsdProvider
{
private:
static cOsd *Osd; ///< single OSD
public:
virtual cOsd * CreateOsd(int, int, uint);
virtual bool ProvidesTrueColor(void);
cSoftOsdProvider(void); ///< OSD provider constructor
//virtual ~cSoftOsdProvider(); ///< OSD provider destructor
};
cOsd *cSoftOsdProvider::Osd; ///< single osd
/**
** 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)
{
return Osd = new cSoftOsd(left, top, level);
}
/**
** 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;
}
/**
** Create cOsdProvider class.
*/
cSoftOsdProvider::cSoftOsdProvider(void)
: cOsdProvider()
{
}
/**
** Destroy cOsdProvider class.
cSoftOsdProvider::~cSoftOsdProvider()
{
Debug1("%s", __FUNCTION__);
}
*/
//////////////////////////////////////////////////////////////////////////////
// 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 SuspendClose;
int SuspendX11;
int Video;
int Video4to3DisplayFormat;
int VideoOtherDisplayFormat;
uint32_t Background;
uint32_t BackgroundAlpha;
int _60HzMode;
int SoftStartSync;
int ColorBalance;
int Brightness;
int Contrast;
int Saturation;
int Hue;
int Stde;
int ResolutionShown[RESOLUTIONS];
int Scaling[RESOLUTIONS];
int Deinterlace[RESOLUTIONS];
int Denoise[RESOLUTIONS];
int Sharpen[RESOLUTIONS];
int CutTopBottom[RESOLUTIONS];
int CutLeftRight[RESOLUTIONS];
int AutoCropInterval;
int AutoCropDelay;
int AutoCropTolerance;
int Audio;
int AudioDelay;
int AudioDrift;
int AudioPassthroughDefault;
int AudioPassthroughPCM;
int AudioPassthroughAC3;
int AudioPassthroughEAC3;
int AudioDownmix;
int AudioSoftvol;
int AudioNormalize;
int AudioMaxNormalize;
int AudioCompression;
int AudioMaxCompression;
int AudioStereoDescent;
int AudioBufferTime;
/// @}
private:
inline cOsdItem * CollapsedItem(const char *, int &, const char * = NULL);
inline bool IsResolutionProgressive(int mode);
void Create(void); // create sub-menu
protected:
virtual void Store(void);
public:
cMenuSetupSoft(void);
~cMenuSetupSoft();
virtual eOSState ProcessKey(eKeys); // handle input
};
/**
** Create a seperator item.
**
** @param label text inside separator
*/
static inline cOsdItem *SeparatorItem(const char *label)
{
cOsdItem *item;
item = new cOsdItem(cString::sprintf("* %s: ", label));
item->SetSelectable(false);
return item;
}
/**
** Create a collapsed item.
**
** @param label text inside collapsed
** @param flag flag handling collapsed or opened
** @param msg open message
*/
inline cOsdItem *cMenuSetupSoft::CollapsedItem(const char *label, int &flag, const char *msg)
{
cOsdItem *item;
item = new cMenuEditBoolItem(cString::sprintf("* %s", label), &flag, msg ? msg : tr("show"), tr("hide"));
return item;
}
bool cMenuSetupSoft::IsResolutionProgressive(int mode)
{
return ! !strstr(Resolution[mode], "p");
}
/**
** Create setup menu.
*/
void cMenuSetupSoft::Create(void)
{
static const char *const video_display_formats_4_3[] = {
"pan&scan", "letterbox", "center cut-out",
};
static const char *const video_display_formats_16_9[] = {
"pan&scan", "pillarbox", "center cut-out",
};
static const char *const audiodrift[] = {
"None", "PCM", "AC-3", "PCM + AC-3"
};
int current;
const char **scaling;
const char **scaling_short;
const char **deinterlace;
const char **deinterlace_short;
int scaling_modes = VideoGetScalingModes(&scaling, &scaling_short);
int deinterlace_modes = VideoGetDeinterlaceModes(&deinterlace, &deinterlace_short);
int brightness_min, brightness_def, brightness_max;
int brightness_active = VideoGetBrightnessConfig(&brightness_min, &brightness_def, &brightness_max);
int contrast_min, contrast_def, contrast_max;
int contrast_active = VideoGetContrastConfig(&contrast_min, &contrast_def, &contrast_max);
int saturation_min, saturation_def, saturation_max;
int saturation_active = VideoGetSaturationConfig(&saturation_min, &saturation_def, &saturation_max);
int hue_min, hue_def, hue_max;
int hue_active = VideoGetHueConfig(&hue_min, &hue_def, &hue_max);
int stde_min, stde_def, stde_max;
int stde_active = VideoGetSkinToneEnhancementConfig(&stde_min, &stde_def, &stde_max);
int denoise_min, denoise_def, denoise_max;
int denoise_active = VideoGetDenoiseConfig(&denoise_min, &denoise_def, &denoise_max);
int sharpen_min, sharpen_def, sharpen_max;
int sharpen_active = VideoGetSharpenConfig(&sharpen_min, &sharpen_def, &sharpen_max);
current = Current(); // get current menu item index
Clear(); // clear the menu
SetHelp(NULL, NULL, NULL, MyDebug->Active()? tr("Debug/OFF") : tr("Debug/ON"));
//
// general
//
Add(CollapsedItem(tr("General"), General));
if (General) {
Add(new cMenuEditBoolItem(tr("Make primary device"), &MakePrimary, trVDR("no"), trVDR("yes")));
Add(new cMenuEditBoolItem(tr("Hide main menu entry"), &HideMainMenuEntry, trVDR("no"), trVDR("yes")));
//
// suspend
//
Add(SeparatorItem(tr("Suspend")));
Add(new cMenuEditBoolItem(tr("Detach from main menu entry"), &DetachFromMainMenu, trVDR("no"), trVDR("yes")));
Add(new cMenuEditBoolItem(tr("Suspend closes video+audio"), &SuspendClose, trVDR("no"), trVDR("yes")));
Add(new cMenuEditBoolItem(tr("Suspend stops x11"), &SuspendX11, trVDR("no"), trVDR("yes")));
}
//
// video
//
Add(CollapsedItem(tr("Video"), Video));
if (Video) {
Add(new cMenuEditStraItem(trVDR("4:3 video display format"), &Video4to3DisplayFormat, 3,
video_display_formats_4_3));
Add(new cMenuEditStraItem(trVDR("16:9+other video display format"), &VideoOtherDisplayFormat, 3,
video_display_formats_16_9));
// FIXME: switch config gray/color configuration
Add(new cMenuEditIntItem(tr("Video background color (RGB)"), (int *)&Background, 0, 0x00FFFFFF));
Add(new cMenuEditIntItem(tr("Video background color (Alpha)"), (int *)&BackgroundAlpha, 0, 0xFF));
Add(new cMenuEditBoolItem(tr("60hz display mode"), &_60HzMode, trVDR("no"), trVDR("yes")));
Add(new cMenuEditBoolItem(tr("Soft start a/v sync"), &SoftStartSync, trVDR("no"), trVDR("yes")));
Add(new cMenuEditBoolItem(tr("Color balance"), &ColorBalance, trVDR("off"), trVDR("on")));
if (ColorBalance) {
if (brightness_active)
Add(new cMenuEditIntItem(*cString::sprintf(tr("\040\040Brightness (%d..[%d]..%d)"), brightness_min,
brightness_def, brightness_max), &Brightness, brightness_min, brightness_max));
if (contrast_active)
Add(new cMenuEditIntItem(*cString::sprintf(tr("\040\040Contrast (%d..[%d]..%d)"), contrast_min,
contrast_def, contrast_max), &Contrast, contrast_min, contrast_max));
if (saturation_active)
Add(new cMenuEditIntItem(*cString::sprintf(tr("\040\040Saturation (%d..[%d]..%d)"), saturation_min,
saturation_def, saturation_max), &Saturation, saturation_min, saturation_max));
if (hue_active)
Add(new cMenuEditIntItem(*cString::sprintf(tr("\040\040Hue (%d..[%d]..%d)"), hue_min, hue_def,
hue_max), &Hue, hue_min, hue_max));
}
if (stde_active)
Add(new cMenuEditIntItem(*cString::sprintf(tr("Skin Tone Enhancement (%d..[%d]..%d)"), stde_min, stde_def,
stde_max), &Stde, stde_min, stde_max));
for (int i = 0; i < RESOLUTIONS; ++i) {
cString msg;
// short hidden informations
msg =
cString::sprintf("%s,%s,%s", scaling_short[Scaling[i]], deinterlace_short[Deinterlace[i]],
Denoise[i] ? "D" : "N");
Add(CollapsedItem(Resolution[i], ResolutionShown[i], msg));
if (ResolutionShown[i]) {
Add(new cMenuEditStraItem(tr("Scaling"), &Scaling[i], scaling_modes, scaling));
if (!IsResolutionProgressive(i))
Add(new cMenuEditStraItem(tr("Deinterlace"), &Deinterlace[i], deinterlace_modes, deinterlace));
if (denoise_active)
Add(new cMenuEditIntItem(*cString::sprintf(tr("Denoise (%d..[%d]..%d)"), denoise_min, denoise_def,
denoise_max), &Denoise[i], denoise_min, denoise_max));
if (sharpen_active)
Add(new cMenuEditIntItem(*cString::sprintf(tr("Sharpen (%d..[%d]..%d)"), sharpen_min, sharpen_def,
sharpen_max), &Sharpen[i], sharpen_min, sharpen_max));
Add(new cMenuEditIntItem(tr("Cut top and bottom (pixel)"), &CutTopBottom[i], 0, 250));
Add(new cMenuEditIntItem(tr("Cut left and right (pixel)"), &CutLeftRight[i], 0, 250));
}
}
//
// auto-crop
//
Add(SeparatorItem(tr("Auto-crop")));
Add(new cMenuEditIntItem(tr("Autocrop interval (frames)"), &AutoCropInterval, 0, 200, tr("off")));
Add(new cMenuEditIntItem(tr("Autocrop delay (n * interval)"), &AutoCropDelay, 0, 200));
Add(new cMenuEditIntItem(tr("Autocrop tolerance (pixel)"), &AutoCropTolerance, 0, 32));
}
//
// audio
//
Add(CollapsedItem(tr("Audio"), Audio));
if (Audio) {
Add(new cMenuEditIntItem(tr("Audio/Video delay (ms)"), &AudioDelay, -1000, 1000));
Add(new cMenuEditStraItem(tr("Audio drift correction"), &AudioDrift, 4, audiodrift));
Add(new cMenuEditBoolItem(tr("Pass-through default"), &AudioPassthroughDefault, trVDR("off"), trVDR("on")));
Add(new cMenuEditBoolItem(tr("\040\040PCM pass-through"), &AudioPassthroughPCM, trVDR("no"), trVDR("yes")));
Add(new cMenuEditBoolItem(tr("\040\040AC-3 pass-through"), &AudioPassthroughAC3, trVDR("no"), trVDR("yes")));
Add(new cMenuEditBoolItem(tr("\040\040E-AC-3 pass-through"), &AudioPassthroughEAC3, trVDR("no"),
trVDR("yes")));
Add(new cMenuEditBoolItem(tr("Enable (E-)AC-3 (decoder) downmix"), &AudioDownmix, trVDR("no"), trVDR("yes")));
Add(new cMenuEditBoolItem(tr("Volume control"), &AudioSoftvol, tr("Hardware"), tr("Software")));
Add(new cMenuEditBoolItem(tr("Enable normalize volume"), &AudioNormalize, trVDR("no"), trVDR("yes")));
if (AudioNormalize)
Add(new cMenuEditIntItem(tr("\040\040Max normalize factor (/1000)"), &AudioMaxNormalize, 0, 10000));
Add(new cMenuEditBoolItem(tr("Enable volume compression"), &AudioCompression, trVDR("no"), trVDR("yes")));