/
videodisplayprofile.cpp
1374 lines (1188 loc) · 42.7 KB
/
videodisplayprofile.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
// MythTV
#include "videodisplayprofile.h"
#include "mythcorecontext.h"
#include "mythdb.h"
#include "mythlogging.h"
#include "mythvideoout.h"
#include "avformatdecoder.h"
// Std
#include <algorithm>
#include <utility>
void ProfileItem::Clear(void)
{
m_pref.clear();
}
void ProfileItem::SetProfileID(uint Id)
{
m_profileid = Id;
}
void ProfileItem::Set(const QString &Value, const QString &Data)
{
m_pref[Value] = Data;
}
uint ProfileItem::GetProfileID() const
{
return m_profileid;
}
QMap<QString,QString> ProfileItem::GetAll(void) const
{
return m_pref;
}
QString ProfileItem::Get(const QString &Value) const
{
QMap<QString,QString>::const_iterator it = m_pref.find(Value);
if (it != m_pref.end())
return *it;
return QString();
}
uint ProfileItem::GetPriority(void) const
{
QString tmp = Get("pref_priority");
return tmp.isEmpty() ? 0 : tmp.toUInt();
}
// options are NNN NNN-MMM 0-MMM NNN-99999 >NNN >=NNN <MMM <=MMM or blank
// If string is blank then assumes a match.
// If value is 0 or negative assume a match (i.e. value unknown assumes a match)
// float values must be no more than 3 decimals.
bool ProfileItem::CheckRange(const QString &Key, float Value, bool *Ok) const
{
return CheckRange(Key, Value, 0, true, Ok);
}
bool ProfileItem::CheckRange(const QString &Key, int Value, bool *Ok) const
{
return CheckRange(Key, 0.0, Value, false, Ok);
}
bool ProfileItem::CheckRange(const QString& Key,
float FValue, int IValue, bool IsFloat, bool *Ok) const
{
bool match = true;
bool isOK = true;
if (IsFloat)
IValue = int(FValue * 1000.0F);
QString cmp = Get(Key);
if (!cmp.isEmpty())
{
cmp.replace(QLatin1String(" "),QLatin1String(""));
QStringList expr = cmp.split("&");
for (int ix = 0; ix < expr.size(); ++ix)
{
if (expr[ix].isEmpty())
{
isOK = false;
continue;
}
if (IValue > 0)
{
QRegularExpression regex("^([0-9.]*)([^0-9.]*)([0-9.]*)$");
QRegularExpressionMatch rmatch = regex.match(expr[ix]);
int value1 = 0;
int value2 = 0;
QString oper;
QString capture1 = rmatch.captured(1);
QString capture3;
if (!capture1.isEmpty())
{
if (IsFloat)
{
int dec=capture1.indexOf('.');
if (dec > -1 && (capture1.length()-dec) > 4)
isOK = false;
if (isOK)
{
double double1 = capture1.toDouble(&isOK);
if (double1 > 2000000.0 || double1 < 0.0)
isOK = false;
value1 = int(double1 * 1000.0);
}
}
else
value1 = capture1.toInt(&isOK);
}
if (isOK)
{
oper = rmatch.captured(2);
capture3 = rmatch.captured(3);
if (!capture3.isEmpty())
{
if (IsFloat)
{
int dec=capture3.indexOf('.');
if (dec > -1 && (capture3.length()-dec) > 4)
isOK = false;
if (isOK)
{
double double1 = capture3.toDouble(&isOK);
if (double1 > 2000000.0 || double1 < 0.0)
isOK = false;
value2 = int(double1 * 1000.0);
}
}
else
value2 = capture3.toInt(&isOK);
}
}
if (isOK)
{
// Invalid string
if (value1 == 0 && value2 == 0 && oper.isEmpty())
isOK=false;
}
if (isOK)
{
// Case NNN
if (value1 != 0 && oper.isEmpty() && value2 == 0)
{
value2 = value1;
oper = "-";
}
// NNN-MMM 0-MMM NNN-99999 NNN- -MMM
else if (oper == "-")
{
// NNN- or -NNN
if (capture1.isEmpty() || capture3.isEmpty())
isOK = false;
// NNN-MMM
if (value2 < value1)
isOK = false;
}
else if (capture1.isEmpty())
{
// Other operators == > < >= <=
// Convert to a range
if (oper == "==")
value1 = value2;
else if (oper == ">")
{
value1 = value2 + 1;
value2 = 99999999;
}
else if (oper == ">=")
{
value1 = value2;
value2 = 99999999;
}
else if (oper == "<")
value2 = value2 - 1;
else if (oper == "<=")
;
else isOK = false;
oper = "-";
}
}
if (isOK)
{
if (oper == "-")
match = match && (IValue >= value1 && IValue <= value2);
else isOK = false;
}
}
}
}
if (Ok != nullptr)
*Ok = isOK;
if (!isOK)
match=false;
return match;
}
bool ProfileItem::IsMatch(const QSize &Size,
float Framerate, const QString &CodecName) const
{
bool match = true;
QString cmp;
// cond_width, cond_height, cond_codecs, cond_framerate.
// These replace old settings pref_cmp0 and pref_cmp1
match &= CheckRange("cond_width",Size.width());
match &= CheckRange("cond_height",Size.height());
match &= CheckRange("cond_framerate",Framerate);
// codec
cmp = Get(QString("cond_codecs"));
if (!cmp.isEmpty())
{
QStringList clist = cmp.split(" ", QString::SkipEmptyParts);
if (!clist.empty())
match &= clist.contains(CodecName,Qt::CaseInsensitive);
}
return match;
}
bool ProfileItem::IsValid(QString *Reason) const
{
bool isOK = true;
CheckRange("cond_width",1,&isOK);
if (!isOK)
{
if (Reason)
*Reason = QString("Invalid width condition");
return false;
}
CheckRange("cond_height",1,&isOK);
if (!isOK)
{
if (Reason)
*Reason = QString("Invalid height condition");
return false;
}
CheckRange("cond_framerate",1.0F,&isOK);
if (!isOK)
{
if (Reason)
*Reason = QString("Invalid framerate condition");
return false;
}
QString decoder = Get("pref_decoder");
QString renderer = Get("pref_videorenderer");
if (decoder.isEmpty() || renderer.isEmpty())
{
if (Reason)
*Reason = "Need a decoder and renderer";
return false;
}
QStringList decoders = VideoDisplayProfile::GetDecoders();
if (!decoders.contains(decoder))
{
if (Reason)
*Reason = QString("decoder %1 is not available").arg(decoder);
return false;
}
QStringList renderers = VideoDisplayProfile::GetVideoRenderers(decoder);
if (!renderers.contains(renderer))
{
if (Reason)
*Reason = QString("renderer %1 is not supported with decoder %2")
.arg(renderer).arg(decoder);
return false;
}
if (Reason)
*Reason = QString();
return true;
}
bool ProfileItem::operator< (const ProfileItem &Other) const
{
return GetPriority() < Other.GetPriority();
}
QString ProfileItem::toString(void) const
{
QString cmp0 = Get("pref_cmp0");
QString cmp1 = Get("pref_cmp1");
QString width = Get("cond_width");
QString height = Get("cond_height");
QString framerate = Get("cond_framerate");
QString codecs = Get("cond_codecs");
QString decoder = Get("pref_decoder");
uint max_cpus = Get("pref_max_cpus").toUInt();
bool skiploop = Get("pref_skiploop").toInt() != 0;
QString renderer = Get("pref_videorenderer");
QString deint0 = Get("pref_deint0");
QString deint1 = Get("pref_deint1");
QString cond = QString("w(%1) h(%2) framerate(%3) codecs(%4)")
.arg(width).arg(height).arg(framerate).arg(codecs);
QString str = QString("cmp(%1%2) %7 dec(%3) cpus(%4) skiploop(%5) rend(%6) ")
.arg(cmp0).arg(QString(cmp1.isEmpty() ? "" : ",") + cmp1)
.arg(decoder).arg(max_cpus).arg((skiploop) ? "enabled" : "disabled").arg(renderer)
.arg(cond);
str += QString("deint(%1,%2)").arg(deint0).arg(deint1);
return str;
}
//////////////////////////////////////////////////////////////////////////////
#define LOC QString("VDP: ")
QMutex VideoDisplayProfile::s_safe_lock(QMutex::Recursive);
bool VideoDisplayProfile::s_safe_initialized = false;
QMap<QString,QStringList> VideoDisplayProfile::s_safe_renderer;
QMap<QString,QStringList> VideoDisplayProfile::s_safe_renderer_group;
QMap<QString,QStringList> VideoDisplayProfile::s_safe_equiv_dec;
QStringList VideoDisplayProfile::s_safe_custom;
QMap<QString,uint> VideoDisplayProfile::s_safe_renderer_priority;
QMap<QString,QString> VideoDisplayProfile::s_dec_name;
QMap<QString,QString> VideoDisplayProfile::s_rend_name;
QStringList VideoDisplayProfile::s_safe_decoders;
QList<QPair<QString,QString> > VideoDisplayProfile::s_deinterlacer_options;
VideoDisplayProfile::VideoDisplayProfile()
{
QMutexLocker locker(&s_safe_lock);
InitStatics();
QString hostname = gCoreContext->GetHostName();
QString cur_profile = GetDefaultProfileName(hostname);
uint groupid = GetProfileGroupID(cur_profile, hostname);
vector<ProfileItem> items = LoadDB(groupid);
vector<ProfileItem>::const_iterator it;
for (it = items.begin(); it != items.end(); ++it)
{
QString err;
if (!(*it).IsValid(&err))
{
LOG(VB_GENERAL, LOG_ERR, LOC + "Rejecting: " + (*it).toString() + "\n\t\t\t" + err);
continue;
}
LOG(VB_PLAYBACK, LOG_INFO, LOC + "Accepting: " + (*it).toString());
m_allowedPreferences.push_back(*it);
}
}
void VideoDisplayProfile::SetInput(const QSize &Size, float Framerate, const QString &CodecName)
{
QMutexLocker locker(&m_lock);
bool change = false;
if (Size != m_lastSize)
{
m_lastSize = Size;
change = true;
}
if (Framerate > 0.0F && !qFuzzyCompare(Framerate + 1.0F, m_lastRate + 1.0F))
{
m_lastRate = Framerate;
change = true;
}
if (!CodecName.isEmpty() && CodecName != m_lastCodecName)
{
m_lastCodecName = CodecName;
change = true;
}
if (change)
LoadBestPreferences(m_lastSize, m_lastRate, m_lastCodecName);
}
void VideoDisplayProfile::SetOutput(float Framerate)
{
QMutexLocker locker(&m_lock);
if (!qFuzzyCompare(Framerate + 1.0F, m_lastRate + 1.0F))
{
m_lastRate = Framerate;
LoadBestPreferences(m_lastSize, m_lastRate, m_lastCodecName);
}
}
float VideoDisplayProfile::GetOutput(void) const
{
return m_lastRate;
}
QString VideoDisplayProfile::GetDecoder(void) const
{
return GetPreference("pref_decoder");
}
QString VideoDisplayProfile::GetSingleRatePreferences(void) const
{
return GetPreference("pref_deint0");
}
QString VideoDisplayProfile::GetDoubleRatePreferences(void) const
{
return GetPreference("pref_deint1");
}
uint VideoDisplayProfile::GetMaxCPUs(void) const
{
return GetPreference("pref_max_cpus").toUInt();
}
bool VideoDisplayProfile::IsSkipLoopEnabled(void) const
{
return GetPreference("pref_skiploop").toInt();
}
QString VideoDisplayProfile::GetVideoRenderer(void) const
{
return GetPreference("pref_videorenderer");
}
QString VideoDisplayProfile::GetActualVideoRenderer(void) const
{
return m_lastVideoRenderer;
}
void VideoDisplayProfile::SetVideoRenderer(const QString &VideoRenderer)
{
QMutexLocker locker(&m_lock);
LOG(VB_PLAYBACK, LOG_INFO, LOC +
QString("SetVideoRenderer(%1)").arg(VideoRenderer));
m_lastVideoRenderer = VideoRenderer;
if (VideoRenderer == GetVideoRenderer())
{
LOG(VB_PLAYBACK, LOG_INFO, LOC +
QString("SetVideoRender(%1) == GetVideoRenderer()").arg(VideoRenderer));
return; // already made preferences safe...
}
// Make preferences safe...
LOG(VB_PLAYBACK, LOG_INFO, LOC + "Old preferences: " + toString());
SetPreference("pref_videorenderer", VideoRenderer);
LOG(VB_PLAYBACK, LOG_INFO, LOC + "New preferences: " + toString());
}
bool VideoDisplayProfile::CheckVideoRendererGroup(const QString &Renderer)
{
if (m_lastVideoRenderer == Renderer || m_lastVideoRenderer == "null")
return true;
LOG(VB_PLAYBACK, LOG_INFO, LOC +
QString("Preferred video renderer: %1 (current: %2)")
.arg(Renderer).arg(m_lastVideoRenderer));
QMap<QString,QStringList>::const_iterator it = s_safe_renderer_group.begin();
for (; it != s_safe_renderer_group.end(); ++it)
if (it->contains(m_lastVideoRenderer) && it->contains(Renderer))
return true;
return false;
}
bool VideoDisplayProfile::IsDecoderCompatible(const QString &Decoder)
{
const QString dec = GetDecoder();
if (dec == Decoder)
return true;
QMutexLocker locker(&s_safe_lock);
return (s_safe_equiv_dec[dec].contains(Decoder));
}
QString VideoDisplayProfile::GetPreference(const QString &Key) const
{
QMutexLocker locker(&m_lock);
if (Key.isEmpty())
return QString();
QMap<QString,QString>::const_iterator it = m_currentPreferences.find(Key);
if (it == m_currentPreferences.end())
return QString();
return *it;
}
void VideoDisplayProfile::SetPreference(const QString &Key, const QString &Value)
{
QMutexLocker locker(&m_lock);
if (!Key.isEmpty())
m_currentPreferences[Key] = Value;
}
vector<ProfileItem>::const_iterator VideoDisplayProfile::FindMatch
(const QSize &Size, float Framerate, const QString &CodecName)
{
vector<ProfileItem>::const_iterator it = m_allowedPreferences.begin();
for (; it != m_allowedPreferences.end(); ++it)
if ((*it).IsMatch(Size, Framerate, CodecName))
return it;
return m_allowedPreferences.end();
}
void VideoDisplayProfile::LoadBestPreferences
(const QSize &Size, float Framerate, const QString &CodecName)
{
LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("LoadBestPreferences(%1x%2, %3, %4)")
.arg(Size.width()).arg(Size.height())
.arg(static_cast<double>(Framerate), 0, 'f', 3).arg(CodecName));
m_currentPreferences.clear();
auto it = FindMatch(Size, Framerate, CodecName);
if (it != m_allowedPreferences.end())
m_currentPreferences = (*it).GetAll();
LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("LoadBestPreferences Result "
"prio:%1, w:%2, h:%3, fps:%4,"
" codecs:%5, decoder:%6, renderer:%7, deint:%8")
.arg(GetPreference("pref_priority")).arg(GetPreference("cond_width"))
.arg(GetPreference("cond_height")).arg(GetPreference("cond_framerate"))
.arg(GetPreference("cond_codecs")).arg(GetPreference("pref_decoder"))
.arg(GetPreference("pref_videorenderer")).arg(GetPreference("pref_deint0"))
);
}
vector<ProfileItem> VideoDisplayProfile::LoadDB(uint GroupId)
{
ProfileItem tmp;
vector<ProfileItem> list;
MSqlQuery query(MSqlQuery::InitCon());
query.prepare(
"SELECT profileid, value, data "
"FROM displayprofiles "
"WHERE profilegroupid = :GROUPID "
"ORDER BY profileid");
query.bindValue(":GROUPID", GroupId);
if (!query.exec())
{
MythDB::DBError("loaddb 1", query);
return list;
}
uint profileid = 0;
while (query.next())
{
if (query.value(0).toUInt() != profileid)
{
if (profileid)
{
tmp.SetProfileID(profileid);
QString error;
bool valid = tmp.IsValid(&error);
if (valid)
list.push_back(tmp);
else
LOG(VB_PLAYBACK, LOG_NOTICE, LOC + QString("Ignoring profile %1 (%2)")
.arg(profileid).arg(error));
}
tmp.Clear();
profileid = query.value(0).toUInt();
}
tmp.Set(query.value(1).toString(), query.value(2).toString());
}
if (profileid)
{
tmp.SetProfileID(profileid);
QString error;
bool valid = tmp.IsValid(&error);
if (valid)
list.push_back(tmp);
else
LOG(VB_PLAYBACK, LOG_NOTICE, LOC + QString("Ignoring profile %1 (%2)")
.arg(profileid).arg(error));
}
sort(list.begin(), list.end());
return list;
}
bool VideoDisplayProfile::DeleteDB(uint GroupId, const vector<ProfileItem> &Items)
{
MSqlQuery query(MSqlQuery::InitCon());
query.prepare(
"DELETE FROM displayprofiles "
"WHERE profilegroupid = :GROUPID AND "
" profileid = :PROFILEID");
bool ok = true;
auto it = Items.cbegin();
for (; it != Items.cend(); ++it)
{
if (!(*it).GetProfileID())
continue;
query.bindValue(":GROUPID", GroupId);
query.bindValue(":PROFILEID", (*it).GetProfileID());
if (!query.exec())
{
MythDB::DBError("vdp::deletedb", query);
ok = false;
}
}
return ok;
}
bool VideoDisplayProfile::SaveDB(uint GroupId, vector<ProfileItem> &Items)
{
MSqlQuery query(MSqlQuery::InitCon());
MSqlQuery update(MSqlQuery::InitCon());
update.prepare(
"UPDATE displayprofiles "
"SET data = :DATA "
"WHERE profilegroupid = :GROUPID AND "
" profileid = :PROFILEID AND "
" value = :VALUE");
MSqlQuery insert(MSqlQuery::InitCon());
insert.prepare(
"INSERT INTO displayprofiles "
" ( profilegroupid, profileid, value, data) "
"VALUES "
" (:GROUPID, :PROFILEID, :VALUE, :DATA) ");
MSqlQuery sqldelete(MSqlQuery::InitCon());
sqldelete.prepare(
"DELETE FROM displayprofiles "
"WHERE profilegroupid = :GROUPID AND "
" profileid = :PROFILEID AND "
" value = :VALUE");
bool ok = true;
auto it = Items.begin();
for (; it != Items.end(); ++it)
{
QMap<QString,QString> list = (*it).GetAll();
if (list.begin() == list.end())
continue;
QMap<QString,QString>::const_iterator lit = list.begin();
if (!(*it).GetProfileID())
{
// create new profileid
if (!query.exec("SELECT MAX(profileid) FROM displayprofiles"))
{
MythDB::DBError("save_profile 1", query);
ok = false;
continue;
}
if (query.next())
{
(*it).SetProfileID(query.value(0).toUInt() + 1);
}
for (; lit != list.end(); ++lit)
{
if ((*lit).isEmpty())
continue;
insert.bindValue(":GROUPID", GroupId);
insert.bindValue(":PROFILEID", (*it).GetProfileID());
insert.bindValue(":VALUE", lit.key());
insert.bindValue(":DATA", ((*lit).isNull()) ? "" : (*lit));
if (!insert.exec())
{
MythDB::DBError("save_profile 2", insert);
ok = false;
continue;
}
}
continue;
}
for (; lit != list.end(); ++lit)
{
query.prepare(
"SELECT count(*) "
"FROM displayprofiles "
"WHERE profilegroupid = :GROUPID AND "
" profileid = :PROFILEID AND "
" value = :VALUE");
query.bindValue(":GROUPID", GroupId);
query.bindValue(":PROFILEID", (*it).GetProfileID());
query.bindValue(":VALUE", lit.key());
if (!query.exec())
{
MythDB::DBError("save_profile 3", query);
ok = false;
continue;
}
if (query.next() && (1 == query.value(0).toUInt()))
{
if (lit->isEmpty())
{
sqldelete.bindValue(":GROUPID", GroupId);
sqldelete.bindValue(":PROFILEID", (*it).GetProfileID());
sqldelete.bindValue(":VALUE", lit.key());
if (!sqldelete.exec())
{
MythDB::DBError("save_profile 5a", sqldelete);
ok = false;
continue;
}
}
else
{
update.bindValue(":GROUPID", GroupId);
update.bindValue(":PROFILEID", (*it).GetProfileID());
update.bindValue(":VALUE", lit.key());
update.bindValue(":DATA", ((*lit).isNull()) ? "" : (*lit));
if (!update.exec())
{
MythDB::DBError("save_profile 5b", update);
ok = false;
continue;
}
}
}
else
{
insert.bindValue(":GROUPID", GroupId);
insert.bindValue(":PROFILEID", (*it).GetProfileID());
insert.bindValue(":VALUE", lit.key());
insert.bindValue(":DATA", ((*lit).isNull()) ? "" : (*lit));
if (!insert.exec())
{
MythDB::DBError("save_profile 4", insert);
ok = false;
continue;
}
}
}
}
return ok;
}
QStringList VideoDisplayProfile::GetDecoders(void)
{
InitStatics();
return s_safe_decoders;
}
QStringList VideoDisplayProfile::GetDecoderNames(void)
{
InitStatics();
QStringList list;
const QStringList decs = GetDecoders();
QStringList::const_iterator it = decs.begin();
for (; it != decs.end(); ++it)
list += GetDecoderName(*it);
return list;
}
QString VideoDisplayProfile::GetDecoderName(const QString &Decoder)
{
if (Decoder.isEmpty())
return "";
QMutexLocker locker(&s_safe_lock);
if (s_dec_name.empty())
{
s_dec_name["ffmpeg"] = QObject::tr("Standard");
s_dec_name["vdpau"] = QObject::tr("NVIDIA VDPAU acceleration");
s_dec_name["vdpau-dec"] = QObject::tr("NVIDIA VDPAU acceleration (decode only)");
s_dec_name["vaapi"] = QObject::tr("VAAPI acceleration");
s_dec_name["vaapi-dec"] = QObject::tr("VAAPI acceleration (decode only)");
s_dec_name["dxva2"] = QObject::tr("Windows hardware acceleration");
s_dec_name["mediacodec"] = QObject::tr("Android MediaCodec acceleration");
s_dec_name["mediacodec-dec"] = QObject::tr("Android MediaCodec acceleration (decode only)");
s_dec_name["nvdec"] = QObject::tr("NVIDIA NVDEC acceleration");
s_dec_name["nvdec-dec"] = QObject::tr("NVIDIA NVDEC acceleration (decode only)");
s_dec_name["vtb"] = QObject::tr("VideoToolbox acceleration");
s_dec_name["vtb-dec"] = QObject::tr("VideoToolbox acceleration (decode only)");
s_dec_name["v4l2"] = QObject::tr("V4L2 acceleration");
s_dec_name["v4l2-dec"] = QObject::tr("V4L2 acceleration (decode only)");
s_dec_name["mmal"] = QObject::tr("MMAL acceleration");
s_dec_name["mmal-dec"] = QObject::tr("MMAL acceleration (decode only)");
s_dec_name["drmprime"] = QObject::tr("DRM PRIME acceleration");
}
QString ret = Decoder;
QMap<QString,QString>::const_iterator it = s_dec_name.find(Decoder);
if (it != s_dec_name.end())
ret = *it;
return ret;
}
QString VideoDisplayProfile::GetDecoderHelp(const QString& Decoder)
{
QString msg = QObject::tr("Processing method used to decode video.");
if (Decoder.isEmpty())
return msg;
msg += "\n";
if (Decoder == "ffmpeg")
msg += QObject::tr("Standard will use the FFmpeg library for software decoding.");
if (Decoder.startsWith("vdpau"))
msg += QObject::tr(
"VDPAU will attempt to use the graphics hardware to "
"accelerate video decoding.");
if (Decoder.startsWith("vaapi"))
msg += QObject::tr(
"VAAPI will attempt to use the graphics hardware to "
"accelerate video decoding and playback.");
if (Decoder.startsWith("dxva2"))
msg += QObject::tr(
"DXVA2 will use the graphics hardware to "
"accelerate video decoding and playback. ");
if (Decoder.startsWith("mediacodec"))
msg += QObject::tr(
"Mediacodec will use Android graphics hardware to "
"accelerate video decoding and playback. ");
if (Decoder.startsWith("nvdec"))
msg += QObject::tr(
"Nvdec uses the NVDEC API to "
"accelerate video decoding and playback with NVIDIA Graphics Adapters. ");
if (Decoder.startsWith("vtb"))
msg += QObject::tr(
"The VideoToolbox library is used to accelerate video decoding. ");
if (Decoder.startsWith("mmal"))
msg += QObject::tr(
"MMAL is used to accelerated video decoding (Raspberry Pi only). ");
if (Decoder == "v4l2")
msg += "Highly experimental: ";
if (Decoder.startsWith("v4l2"))
msg += QObject::tr(
"Video4Linux codecs are used to accelerate video decoding on "
"supported platforms. ");
if (Decoder == "drmprime")
msg += QObject::tr(
"DRM-PRIME decoders are used to accelerate video decoding on "
"supported platforms. ");
if (Decoder.endsWith("-dec"))
msg += QObject::tr("The decoder will transfer frames back to system memory "
"which will significantly reduce performance but may allow "
"other functionality to be used (such as automatic "
"letterbox detection). ");
return msg;
}
QString VideoDisplayProfile::GetVideoRendererName(const QString &Renderer)
{
QMutexLocker locker(&s_safe_lock);
if (s_rend_name.empty())
{
s_rend_name["opengl"] = QObject::tr("OpenGL");
s_rend_name["opengl-yv12"] = QObject::tr("OpenGL YV12");
s_rend_name["opengl-hw"] = QObject::tr("OpenGL Hardware");
}
QString ret = Renderer;
QMap<QString,QString>::const_iterator it = s_rend_name.find(Renderer);
if (it != s_rend_name.end())
ret = *it;
return ret;
}
QStringList VideoDisplayProfile::GetProfiles(const QString &HostName)
{
InitStatics();
QStringList list;
MSqlQuery query(MSqlQuery::InitCon());
query.prepare(
"SELECT name "
"FROM displayprofilegroups "
"WHERE hostname = :HOST ");
query.bindValue(":HOST", HostName);
if (!query.exec() || !query.isActive())
MythDB::DBError("get_profiles", query);
else
{
while (query.next())
list += query.value(0).toString();
}
return list;
}
QString VideoDisplayProfile::GetDefaultProfileName(const QString &HostName)
{
QString tmp =
gCoreContext->GetSettingOnHost("DefaultVideoPlaybackProfile", HostName);
QStringList profiles = GetProfiles(HostName);
tmp = (profiles.contains(tmp)) ? tmp : QString();
if (tmp.isEmpty())
{
if (!profiles.empty())
tmp = profiles[0];
tmp = (profiles.contains("Normal")) ? "Normal" : tmp;
if (!tmp.isEmpty())
{
gCoreContext->SaveSettingOnHost(
"DefaultVideoPlaybackProfile", tmp, HostName);
}
}
return tmp;
}
void VideoDisplayProfile::SetDefaultProfileName(const QString &ProfileName, const QString &HostName)
{
gCoreContext->SaveSettingOnHost("DefaultVideoPlaybackProfile", ProfileName, HostName);
}
uint VideoDisplayProfile::GetProfileGroupID(const QString &ProfileName,
const QString &HostName)
{
MSqlQuery query(MSqlQuery::InitCon());
query.prepare(
"SELECT profilegroupid "
"FROM displayprofilegroups "
"WHERE name = :NAME AND "
" hostname = :HOST ");
query.bindValue(":NAME", ProfileName);
query.bindValue(":HOST", HostName);
if (!query.exec() || !query.isActive())
MythDB::DBError("get_profile_group_id", query);
else if (query.next())
return query.value(0).toUInt();
return 0;
}
void VideoDisplayProfile::CreateProfile(uint GroupId, uint Priority,
const QString& Width, const QString& Height, const QString& Codecs,
const QString& Decoder, uint MaxCpus, bool SkipLoop, const QString& VideoRenderer,
const QString& Deint1, const QString& Deint2)
{
MSqlQuery query(MSqlQuery::InitCon());
// create new profileid
uint profileid = 1;
if (!query.exec("SELECT MAX(profileid) FROM displayprofiles"))
MythDB::DBError("create_profile 1", query);
else if (query.next())
profileid = query.value(0).toUInt() + 1;
query.prepare(
"INSERT INTO displayprofiles "
"VALUES (:GRPID, :PROFID, 'pref_priority', :PRIORITY)");
query.bindValue(":GRPID", GroupId);
query.bindValue(":PROFID", profileid);
query.bindValue(":PRIORITY", Priority);
if (!query.exec())
MythDB::DBError("create_profile 2", query);
QStringList queryValue;
QStringList queryData;
queryValue += "cond_width";
queryData += Width;
queryValue += "cond_height";
queryData += Height;
queryValue += "cond_codecs";
queryData += Codecs;
queryValue += "pref_decoder";
queryData += Decoder;
queryValue += "pref_max_cpus";
queryData += QString::number(MaxCpus);
queryValue += "pref_skiploop";
queryData += (SkipLoop) ? "1" : "0";
queryValue += "pref_videorenderer";
queryData += VideoRenderer;