Loading...
Searching...
No Matches
HAP.hpp
1#pragma once
2#include <Gfx/Graph/decoders/GPUVideoDecoder.hpp>
3
4#include <hap/source/hap.h>
5
6#include <snappy.h>
7
8extern "C" {
9#include <libavformat/avformat.h>
10}
11
12namespace score::gfx
13{
18{
20 {
21 static HAPSection read(const uint8_t* bytes);
22
23 uint32_t type{};
24 uint32_t size{};
25 const uint8_t* data{};
26 };
27
28 void exec(RenderList&, QRhiResourceUpdateBatch& res, AVFrame& frame) override;
29 void setPixels_noEncoding(
30 QRhiResourceUpdateBatch& res, const uint8_t* data_start, std::size_t size);
31 void setPixels_snappy(
32 QRhiResourceUpdateBatch& res, const uint8_t* data_start, std::size_t size);
33
34 static constexpr int buffer_size = 1024 * 1024 * 16;
35 std::unique_ptr<char[]> m_buffer = std::make_unique<char[]>(1024 * 1024 * 16);
36};
37
42{
43 static inline const QString fragment = QStringLiteral(R"_(#version 450
44
45)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
46
47layout(binding=3) uniform sampler2D y_tex;
48
49layout(location = 0) in vec2 v_texcoord;
50layout(location = 0) out vec4 fragColor;
51
52vec4 processYCoCg(vec4 CoCgSY) {
53 const vec4 offsets = vec4(-0.50196078431373, -0.50196078431373, 0.0, 0.0);
54 CoCgSY += offsets;
55 float scale = ( CoCgSY.z * ( 255.0 / 8.0 ) ) + 1.0;
56
57 float Co = CoCgSY.x / scale;
58 float Cg = CoCgSY.y / scale;
59 float Y = CoCgSY.w;
60
61 vec4 rgba = vec4(Y + Co - Cg, Y + Cg, Y - Co - Cg, 1.0);
62 return rgba;
63}
64
65vec4 processTexture(vec4 tex) {
66 vec4 processed = tex;
67 { %1 }
68 return processed;
69}
70
71void main ()
72{
73 fragColor = processTexture(texture(y_tex, v_texcoord));
74})_");
75
76 static inline const QString ycocg_filter
77 = QStringLiteral("processed = processYCoCg(processed);\n");
78
79 HAPDefaultDecoder(QRhiTexture::Format fmt, Video::ImageFormat& d, QString f = "");
80 QRhiTexture::Format format;
81 Video::ImageFormat& decoder;
82 QString filter;
83
84 std::pair<QShader, QShader> init(RenderList& r) override;
85};
86
91{
92 static inline const QString fragment = QStringLiteral(R"_(#version 450
93
94)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
95
96layout(binding=3) uniform sampler2D y_tex;
97layout(binding=4) uniform sampler2D alpha_tex;
98
99layout(location = 0) in vec2 v_texcoord;
100layout(location = 0) out vec4 fragColor;
101
102// FIXME what's that???
103vec4 processYCoCg(vec4 CoCgSY, vec4 alpha) {
104 const vec4 offsets = vec4(-0.50196078431373, -0.50196078431373, 0.0, 0.0);
105 CoCgSY += offsets;
106 float scale = ( CoCgSY.z * ( 255.0 / 8.0 ) ) + 1.0;
107
108 float Co = CoCgSY.x / scale;
109 float Cg = CoCgSY.y / scale;
110 float Y = CoCgSY.w;
111
112 vec4 rgba = vec4(Y + Co - Cg, Y + Cg, Y - Co - Cg, alpha.r);
113 return rgba;
114}
115
116vec4 processTexture(vec4 tex) {
117 vec4 processed = tex;
118 { %1 }
119 return processed;
120}
121
122void main ()
123{
124 vec4 ycocg = texture(y_tex, v_texcoord);
125 vec4 alpha = texture(alpha_tex, v_texcoord);
126 fragColor = processTexture(processYCoCg(ycocg, alpha));
127})_");
128
129 HAPMDecoder(Video::ImageFormat& d, QString f = "");
130 Video::ImageFormat& decoder;
131 QString filter;
132 std::pair<QShader, QShader> init(RenderList& r) override;
133
134 void exec(RenderList&, QRhiResourceUpdateBatch& res, AVFrame& frame) override;
135
136 static void setPixels(
137 QRhiResourceUpdateBatch& res, QRhiTexture* tex, const uint8_t* ycocg_start,
138 std::size_t ycocg_size);
139
140 std::unique_ptr<char[]> m_alphaBuffer = std::make_unique<char[]>(1024 * 1024 * 16);
141};
142
143}
Processes and renders a video frame on the GPU.
Definition GPUVideoDecoder.hpp:43
List of nodes to be rendered to an output.
Definition RenderList.hpp:19
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:12
Definition VideoInterface.hpp:16
Base class for HAP ((c) Vidvox) decoding.
Definition HAP.hpp:18
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition HAP.cpp:32
Decodes HAP basic format.
Definition HAP.hpp:42
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition HAP.cpp:110
Decodes HAP-M (HAP + alpha channel)
Definition HAP.hpp:91
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition HAP.cpp:138
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition HAP.cpp:172