Loading...
Searching...
No Matches
P210.hpp
1#pragma once
2#include <Gfx/Graph/decoders/ColorSpace.hpp>
3#include <Gfx/Graph/decoders/GPUVideoDecoder.hpp>
4
5extern "C" {
6#include <libavformat/avformat.h>
7}
8
9namespace score::gfx
10{
11
23{
24 static const constexpr auto frag = R"_(#version 450
25
26)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
27
28layout(binding=3) uniform sampler2D y_tex;
29layout(binding=4) uniform sampler2D uv_tex;
30
31layout(location = 0) in vec2 v_texcoord;
32layout(location = 0) out vec4 fragColor;
33
34%2
35
36vec4 processTexture(vec4 tex) {
37 vec4 processed = convert_to_rgb(tex);
38 { %1 }
39 return processed;
40}
41
42void main()
43{
44 float y = texture(y_tex, v_texcoord).r;
45 float u = texture(uv_tex, v_texcoord).r;
46 float v = texture(uv_tex, v_texcoord).g;
47
48 fragColor = processTexture(vec4(y, u, v, 1.));
49})_";
50
51 Video::ImageFormat& decoder;
52
54 : decoder{d}
55 {
56 }
57
58 std::pair<QShader, QShader> init(RenderList& r) override
59 {
60 auto& rhi = *r.state.rhi;
61 const auto w = decoder.width, h = decoder.height;
62
63 // Y plane: R16 at full resolution
64 {
65 auto tex = rhi.newTexture(QRhiTexture::R16, {w, h}, 1, QRhiTexture::Flag{});
66 tex->create();
67
68 auto sampler = rhi.newSampler(
69 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
70 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
71 sampler->create();
72 samplers.push_back({sampler, tex});
73 }
74
75 // UV plane: RG16 at half width, full height
76 {
77 auto tex
78 = rhi.newTexture(QRhiTexture::RG16, {w / 2, h}, 1, QRhiTexture::Flag{});
79 tex->create();
80
81 auto sampler = rhi.newSampler(
82 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
83 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
84 sampler->create();
85 samplers.push_back({sampler, tex});
86 }
87
89 r.state, vertexShader(), QString(frag).arg("").arg(colorMatrix(decoder)));
90 }
91
92 void exec(RenderList&, QRhiResourceUpdateBatch& res, AVFrame& frame) override
93 {
94 {
95 const auto w = decoder.width, h = decoder.height;
96 QRhiTextureUploadEntry entry{
97 0, 0, createTextureUpload(frame.data[0], w, h, 2, frame.linesize[0])};
98 res.uploadTexture(samplers[0].texture, {entry});
99 }
100 {
101 const auto w = decoder.width / 2, h = decoder.height;
102 QRhiTextureUploadEntry entry{
103 0, 0, createTextureUpload(frame.data[1], w, h, 4, frame.linesize[1])};
104 res.uploadTexture(samplers[1].texture, {entry});
105 }
106 }
107};
108
109}
Processes and renders a video frame on the GPU.
Definition GPUVideoDecoder.hpp:43
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:19
RenderState & state
RenderState corresponding to this RenderList.
Definition RenderList.hpp:94
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:12
std::pair< QShader, QShader > makeShaders(const RenderState &v, QString vert, QString frag)
Get a pair of compiled vertex / fragment shaders from GLSL 4.5 sources.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:394
Definition VideoInterface.hpp:18
Decodes P210 semi-planar 4:2:2 10-bit videos.
Definition P210.hpp:23
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition P210.hpp:58
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition P210.hpp:92