Skip to content

Commit 76d8fc8

Browse files
uknunknownFlole998
authored andcommitted
update vaapi - vainfo
- add enable vainfo detection checkbox in config - defined PT_DYN_INT to load integer field from function - PT_DYN_INT must be paired with dyn_i - show only VAAPI codecs advertised by vainfo - defined two invisible fields: ui and uilp used for UI enable/disable features - check if bitrate is greater than max_bitrate (fix to avoid tvh crash) - vp8, vp9 separate Global Quality from Quality - load quality and max B frames filters from vainfo - UI has several constrains or warnings implemented using vainfo - separated 'b_depth' from 'bf'
1 parent 49ac938 commit 76d8fc8

17 files changed

Lines changed: 1678 additions & 182 deletions

File tree

src/config.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ struct config config;
5656
static char config_lock[PATH_MAX];
5757
static int config_lock_fd;
5858
static int config_scanfile_ok;
59+
#if ENABLE_VAAPI
60+
int vainfo_probe_enabled;
61+
#endif
5962

6063
/* *************************************************************************
6164
* Config migration
@@ -1896,6 +1899,9 @@ config_init ( int backup )
18961899
if (config_migrate(backup))
18971900
config_check();
18981901
}
1902+
#if ENABLE_VAAPI
1903+
vainfo_probe_enabled = config.enable_vainfo;
1904+
#endif
18991905
tvhinfo(LS_CONFIG, "loaded");
19001906
}
19011907

@@ -2754,6 +2760,19 @@ const idclass_t config_class = {
27542760
.opts = PO_EXPERT,
27552761
.group = 7,
27562762
},
2763+
#if ENABLE_VAAPI
2764+
{
2765+
.type = PT_BOOL,
2766+
.id = "enable_vainfo",
2767+
.name = N_("Enable vainfo detection"),
2768+
.desc = N_("Enable vainfo detection in order to show only "
2769+
"encoders that are advertised by VAAPI driver.\n"
2770+
"NOTE: After save, Tvheadend restart is required!"),
2771+
.off = offsetof(config_t, enable_vainfo),
2772+
.opts = PO_EXPERT,
2773+
.group = 7,
2774+
},
2775+
#endif
27572776
{
27582777
.type = PT_STR,
27592778
.id = "wizard",

src/config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ typedef struct config {
7878
uint32_t hdhomerun_server_tuner_count;
7979
char *hdhomerun_server_model_name;
8080
int hdhomerun_server_enable;
81+
#if ENABLE_VAAPI
82+
int enable_vainfo;
83+
#endif
8184
} config_t;
8285

8386
extern const idclass_t config_class;

src/idnode.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ idnode_get_u32
391391
ptr = ((void*)self) + p->off;
392392
switch (p->type) {
393393
case PT_INT:
394+
case PT_DYN_INT:
394395
case PT_BOOL:
395396
*u32 = *(int*)ptr;
396397
return 0;
@@ -425,6 +426,7 @@ idnode_get_s64
425426
ptr = ((void*)self) + p->off;
426427
switch (p->type) {
427428
case PT_INT:
429+
case PT_DYN_INT:
428430
case PT_BOOL:
429431
*s64 = *(int*)ptr;
430432
return 0;
@@ -495,6 +497,7 @@ idnode_get_dbl
495497
ptr = ((void*)self) + p->off;
496498
switch (p->type) {
497499
case PT_INT:
500+
case PT_DYN_INT:
498501
case PT_BOOL:
499502
*dbl = *(int*)ptr;
500503
return 0;
@@ -761,6 +764,7 @@ idnode_cmp_sort
761764
}
762765
break;
763766
case PT_INT:
767+
case PT_DYN_INT:
764768
case PT_U16:
765769
case PT_BOOL:
766770
case PT_PERM:

src/main.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,9 @@ main(int argc, char **argv)
804804
} randseed;
805805
struct rlimit rl;
806806
extern int dvb_bouquets_parse;
807-
807+
#if ENABLE_VAAPI
808+
extern int vainfo_probe_enabled;
809+
#endif
808810
main_tid = pthread_self();
809811

810812
/* Setup global mutexes */
@@ -1293,7 +1295,11 @@ main(int argc, char **argv)
12931295
tvhftrace(LS_MAIN, fsmonitor_init);
12941296
tvhftrace(LS_MAIN, libav_init);
12951297
tvhftrace(LS_MAIN, tvhtime_init);
1298+
#if ENABLE_VAAPI
1299+
tvhftrace(LS_MAIN, codec_init, vainfo_probe_enabled);
1300+
#else
12961301
tvhftrace(LS_MAIN, codec_init);
1302+
#endif
12971303
tvhftrace(LS_MAIN, profile_init);
12981304
tvhftrace(LS_MAIN, imagecache_init);
12991305
tvhftrace(LS_MAIN, http_client_init);

src/prop.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ static const struct strtab typetab[] = {
4646
{ "s64", PT_S64_ATOMIC },
4747
{ "dbl", PT_DBL },
4848
{ "time", PT_TIME },
49+
{ "int", PT_DYN_INT },
4950
{ "langstr", PT_LANGSTR },
5051
{ "perm", PT_PERM },
5152
};
@@ -84,6 +85,7 @@ prop_write_values
8485
uint32_t u32, opts;
8586
uint16_t u16;
8687
time_t tm;
88+
int dyn_i;
8789
#define PROP_UPDATE(v, t)\
8890
snew = &v;\
8991
if (!p->set && (*((t*)cur) != *((t*)snew))) {\
@@ -212,6 +214,13 @@ prop_write_values
212214
PROP_UPDATE(tm, time_t);
213215
break;
214216
}
217+
case PT_DYN_INT: {
218+
if (htsmsg_field_get_s64(f, &s64))
219+
continue;
220+
dyn_i = s64;
221+
PROP_UPDATE(dyn_i, int);
222+
break;
223+
}
215224
case PT_LANGSTR: {
216225
lang_str_t **lstr1 = cur;
217226
lang_str_t *lstr2;
@@ -349,6 +358,9 @@ prop_read_value
349358
case PT_TIME:
350359
htsmsg_add_s64(m, name, *(time_t *)val);
351360
break;
361+
case PT_DYN_INT:
362+
htsmsg_add_s64(m, name, *(int *)val);
363+
break;
352364
case PT_LANGSTR:
353365
lang_str_serialize(*(lang_str_t **)val, m, name);
354366
break;
@@ -481,6 +493,9 @@ prop_serialize_value
481493
case PT_TIME:
482494
htsmsg_add_s64(m, "default", pl->def.tm);
483495
break;
496+
case PT_DYN_INT:
497+
htsmsg_add_s32(m, "default", pl->def.dyn_i());
498+
break;
484499
case PT_LANGSTR:
485500
/* TODO? */
486501
break;

src/prop.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ typedef enum {
3838
PT_S64_ATOMIC,
3939
PT_DBL,
4040
PT_TIME,
41+
PT_DYN_INT,
4142
PT_LANGSTR,
4243
PT_PERM, // like PT_U32 but with the special save
4344
} prop_type_t;
@@ -115,6 +116,7 @@ typedef struct property {
115116
double d; // PT_DBL
116117
time_t tm; // PT_TIME
117118
htsmsg_t *(*list)(void); // islist != 0
119+
int (*dyn_i)(void); // dynamically load a PT_DYN_INT
118120
} def;
119121

120122
/* Extended options */

src/transcoding/codec.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ htsmsg_t *
171171
codec_get_profiles_list(enum AVMediaType media_type);
172172

173173
void
174+
#if ENABLE_VAAPI
175+
codec_init(int vainfo_probe_enabled);
176+
#else
174177
codec_init(void);
178+
#endif
175179

176180
void
177181
codec_done(void);

src/transcoding/codec/codec.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
#include "internals.h"
2222

23+
#if ENABLE_VAAPI
24+
#include "vainfo.h"
25+
#endif
2326

2427
struct TVHCodecs tvh_codecs;
2528

@@ -254,7 +257,11 @@ tvh_codec_find(const char *name)
254257

255258

256259
void
260+
#if ENABLE_VAAPI
261+
tvh_codecs_register(int vainfo_probe_enabled)
262+
#else
257263
tvh_codecs_register()
264+
#endif
258265
{
259266
SLIST_INIT(&tvh_codecs);
260267
tvh_codec_register(&tvh_codec_mpeg2video);
@@ -291,10 +298,26 @@ tvh_codecs_register()
291298
#endif
292299

293300
#if ENABLE_VAAPI
294-
tvh_codec_register(&tvh_codec_vaapi_h264);
295-
tvh_codec_register(&tvh_codec_vaapi_hevc);
296-
tvh_codec_register(&tvh_codec_vaapi_vp8);
297-
tvh_codec_register(&tvh_codec_vaapi_vp9);
301+
if (vainfo_probe_enabled && !vainfo_init(VAINFO_SHOW_LOGS)) {
302+
if (vainfo_encoder_isavailable(VAINFO_H264) ||
303+
vainfo_encoder_isavailable(VAINFO_H264_LOW_POWER))
304+
tvh_codec_register(&tvh_codec_vaapi_h264);
305+
if (vainfo_encoder_isavailable(VAINFO_HEVC) ||
306+
vainfo_encoder_isavailable(VAINFO_HEVC_LOW_POWER))
307+
tvh_codec_register(&tvh_codec_vaapi_hevc);
308+
if (vainfo_encoder_isavailable(VAINFO_VP8) ||
309+
vainfo_encoder_isavailable(VAINFO_VP8_LOW_POWER))
310+
tvh_codec_register(&tvh_codec_vaapi_vp8);
311+
if (vainfo_encoder_isavailable(VAINFO_VP9) ||
312+
vainfo_encoder_isavailable(VAINFO_VP9_LOW_POWER))
313+
tvh_codec_register(&tvh_codec_vaapi_vp9);
314+
}
315+
else {
316+
tvh_codec_register(&tvh_codec_vaapi_h264);
317+
tvh_codec_register(&tvh_codec_vaapi_hevc);
318+
tvh_codec_register(&tvh_codec_vaapi_vp8);
319+
tvh_codec_register(&tvh_codec_vaapi_vp9);
320+
}
298321
#endif
299322

300323
#if ENABLE_NVENC

0 commit comments

Comments
 (0)