4#include <gst/gstpluginfeature.h>
12constexpr uint16_t kPrioritizedRank = GST_RANK_PRIMARY + 1;
14constexpr uint16_t kZeroCopyRank = GST_RANK_PRIMARY + 2;
18 return decoder.rank >= GST_RANK_MARGINAL;
24 explicit Planner(
const QList<DecoderInfo>& decoders)
26 , _ranks(decoders.size())
29 template <
typename Predicate>
30 qsizetype rank(Predicate&& matches, uint16_t rank)
33 for (qsizetype i = 0; i < _decoders.size(); ++i) {
34 if (matches(_decoders.at(i))) {
42 void rankPrefix(
const char* prefix, uint16_t rank)
44 (void) this->rank([prefix](
const DecoderInfo& decoder) {
return decoder.name.startsWith(prefix); }, rank);
49 (void) this->rank([family](
const DecoderInfo& decoder) {
return decoder.family == family; }, rank);
56 unsigned highestOtherRank = GST_RANK_NONE;
57 for (
const DecoderInfo& decoder : _decoders) {
58 if (decoder.family != family) {
59 highestOtherRank = std::max(highestOtherRank, decoder.rank);
62 const unsigned rank = std::max<unsigned>(kPrioritizedRank, std::min<unsigned>(highestOtherRank, 0xFFFD) + 1);
63 rankFamily(family,
static_cast<uint16_t
>(rank));
64 return static_cast<uint16_t
>(rank);
69 void demoteOtherClass(
bool hardware, QStringList& warnings)
71 const bool classAutoplugged = std::ranges::any_of(_decoders, [&](
const DecoderInfo& decoder) {
72 return (decoder.hardware == hardware) && autoplugged(decoder);
74 if (!_decoders.isEmpty() && !classAutoplugged) {
75 warnings.append(QStringLiteral(
"No %1 video decoder that GStreamer autoplugs is installed: "
76 "video will not decode with this option.")
77 .arg(hardware ? QStringLiteral(
"hardware") : QStringLiteral(
"software")));
79 (void) rank([&](
const DecoderInfo& decoder) {
return (decoder.hardware != hardware) && autoplugged(decoder); },
85 void prioritizeZeroCopy()
88 const bool someAutoplugged = std::ranges::any_of(
89 _decoders, [&](
const DecoderInfo& decoder) {
return va(decoder) && autoplugged(decoder); });
91 [&](
const DecoderInfo& decoder) {
return va(decoder) && (!someAutoplugged || autoplugged(decoder)); },
93 rankPrefix(
"v4l2sl", kZeroCopyRank);
97 void lowerHardware(uint16_t rank)
99 for (qsizetype i = 0; i < _decoders.size(); ++i) {
100 const DecoderInfo& decoder = _decoders.at(i);
101 const unsigned planned = _ranks.at(i) ? *_ranks.at(i) : decoder.rank;
102 if (decoder.hardware && (planned > rank)) {
108 QList<RankChange> changes()
const
110 QList<RankChange> changes;
111 for (qsizetype i = 0; i < _decoders.size(); ++i) {
113 changes.append({.feature = _decoders.at(i).name, .rank = *_ranks.at(i)});
120 const QList<DecoderInfo>& _decoders;
121 QList<std::optional<uint16_t>> _ranks;
129 Planner planner(decoders);
130 uint16_t familyRank = 0;
135 planner.rankPrefix(
"vaapi", GST_RANK_NONE);
136 planner.prioritizeZeroCopy();
140 planner.demoteOtherClass(
false, plan.
warnings);
143 planner.demoteOtherClass(
true, plan.
warnings);
147 planner.prioritizeZeroCopy();
154 QStringLiteral(
"Forcing Vulkan video decoders: they output VulkanImage memory only, which the video "
155 "sink does not take, so the streams they decode will not display."));
162 familyRank = planner.prioritizeFamily(option);
171 const char*
const preferred = sampledD3D12 ?
"d3d12" :
"d3d11";
172 const auto onRhiAdapter = [&traits](
const DecoderInfo& decoder) {
173 return (traits.
rhiAdapterLuid == 0) || (decoder.adapterLuid == 0) ||
176 const auto prefer = [&](uint16_t rank) {
178 [&](
const DecoderInfo& decoder) { return decoder.name.startsWith(preferred) && onRhiAdapter(decoder); },
183 prefer(kZeroCopyRank);
184 }
else if (forced && sampledD3D12 && sampledD3D11) {
186 prefer(
static_cast<uint16_t
>(familyRank + 1));
191 return (decoder.family == VideoDecoderOption::DirectX3D) && !onRhiAdapter(decoder);
196 planner.rankPrefix(
"d3d12", GST_RANK_NONE);
199 planner.rankPrefix(
"d3d11", GST_RANK_NONE);
205 planner.lowerHardware(GST_RANK_SECONDARY);
208 plan.
changes = planner.changes();
VideoDecoderOption
The decoders VideoSettings' forceVideoDecoder can force. The values are persisted.
RankPlan planRanks(VideoDecoderOption option, const QList< DecoderInfo > &decoders, const RankTraits &traits)
The rank changes option makes to decoders, from their original ranks, on a platform with traits.
A video decoder factory as planRanks() sees it.
QList< RankChange > changes
At most one per decoder, in the order of planRanks()'s input.
QStringList warnings
Why the option may not do what it says, for the log.
The platform rules planRanks() adds to an option.
bool preferZeroCopyDecoders
std::optional< D3DApi > rhiD3DApi