2#include <Gfx/Graph/decoders/ColorSpace.hpp>
3#include <Gfx/Graph/decoders/GPUVideoDecoder.hpp>
6#include <libavformat/avformat.h>
31 static const constexpr auto frag = R
"_(#version 450
33)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
35layout(binding=3) uniform sampler2D y_tex;
36layout(binding=4) uniform sampler2D uv_tex;
38layout(location = 0) in vec2 v_texcoord;
39layout(location = 0) out vec4 fragColor;
43vec4 processTexture(vec4 tex) {
44 vec4 processed = convert_to_rgb(tex);
52 float y = s * texture(y_tex, score_tc(v_texcoord)).r;
53 float u = s * texture(uv_tex, score_tc(v_texcoord)).r;
54 float v = s * texture(uv_tex, score_tc(v_texcoord)).g;
56 fragColor = processTexture(vec4(y, u, v, 1.));
62 const char*
scale{SCORE_GFX_MSB_ALIGNED_SCALE};
73 auto& rhi = *r.
state.rhi;
74 const auto w = decoder.width, h = decoder.height;
78 auto tex = rhi.newTexture(QRhiTexture::R16, {w, h}, 1, QRhiTexture::Flag{});
81 auto sampler = rhi.newSampler(
82 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
83 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
85 samplers.push_back({sampler, tex});
91 = rhi.newTexture(QRhiTexture::RG16, {w / 2, h}, 1, QRhiTexture::Flag{});
94 auto sampler = rhi.newSampler(
95 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
96 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
98 samplers.push_back({sampler, tex});
102 r.
state, vertexShader(),
103 QString(frag).arg(
"").arg(colorMatrix(decoder)).arg(
scale));
110 const auto w = decoder.width;
111 const auto [rows, offset] = planeRows(decoder, frame, decoder.height);
113 sub.setSourceSize({w, rows});
114 sub.setDestinationTopLeft({0, offset});
115 res.uploadTexture(samplers[0].texture, {QRhiTextureUploadEntry{0, 0, sub}});
118 const auto w = decoder.width / 2;
119 const auto [rows, offset] = planeRows(decoder, frame, decoder.height);
121 sub.setSourceSize({w, rows});
122 sub.setDestinationTopLeft({0, offset});
123 res.uploadTexture(samplers[1].texture, {QRhiTextureUploadEntry{0, 0, sub}});
Processes and renders a video frame on the GPU.
Definition GPUVideoDecoder.hpp:161
static QRhiTextureSubresourceUploadDescription createTextureUpload(uint8_t *pixels, int w, int h, int bytesPerPixel, int stride)
Utility method to create a QRhiTextureSubresourceUploadDescription.
Definition GPUVideoDecoder.cpp:22
List of nodes to be rendered to an output.
Definition RenderList.hpp:36
RenderState & state
RenderState corresponding to this RenderList.
Definition RenderList.hpp:299
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:11
std::pair< QShader, QShader > makeShaders(const RenderState &v, QString vert, QString frag, int multiViewCount)
Get a pair of compiled vertex / fragment shaders from GLSL 4.5 sources.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:1707
Decodes P210 and P216 semi-planar 4:2:2 videos.
Definition P210.hpp:30
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition P210.hpp:71
const char * scale
The MSB-aligned renormalization, which P210 and P216 share.
Definition P210.hpp:62
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition P210.hpp:106