Loading...
Searching...
No Matches
DirectVideoNodeRenderer.hpp
1#pragma once
2#include <Gfx/Graph/NodeRenderer.hpp>
3#include <Gfx/Graph/VideoNode.hpp>
4#include <Video/VideoInterface.hpp>
5
6#include <vector>
7
8class QRhi;
9
10extern "C" {
11struct AVFormatContext;
12struct AVCodecContext;
13struct AVStream;
14struct AVFrame;
15struct AVPacket;
16struct AVBufferRef;
17struct SwsContext;
18#include <libavutil/pixfmt.h>
19}
20
21namespace Video
22{
23class Rescale;
24}
25
26namespace score::gfx
27{
28class GPUVideoDecoder;
29struct PixelFormatInfo;
30
47{
48public:
50 const VideoNodeBase& node, const Video::VideoMetadata& metadata) noexcept;
52
53 DirectVideoNodeRenderer() = delete;
56 DirectVideoNodeRenderer& operator=(const DirectVideoNodeRenderer&) = delete;
58
59 TextureRenderTarget renderTargetForInput(const Port& input) override;
60
61 void init(RenderList& renderer, QRhiResourceUpdateBatch& res) override;
62 void runRenderPass(RenderList&, QRhiCommandBuffer& commands, Edge& edge) override;
63 void update(RenderList& renderer, QRhiResourceUpdateBatch& res, Edge* edge) override;
64 void release(RenderList& r) override;
65
66private:
67 const VideoNodeBase& node() const noexcept
68 {
69 return static_cast<const VideoNodeBase&>(NodeRenderer::node);
70 }
71
72 bool openFile(score::gfx::GraphicsApi api, QRhi* rhi = nullptr);
73 void closeFile();
74 bool seekAndDecode(int64_t flicks);
75 bool isSequentialRead(int64_t flicks) const;
76 bool readNextPacketRaw();
77 bool readNextPacketAVCodec();
78
79 void createGpuDecoder(QRhi& rhi);
80 score::gfx::PixelFormatInfo hwPixelFormatInfo() const;
81 std::unique_ptr<GPUVideoDecoder> tryCreateZeroCopyDecoder(QRhi& rhi);
82 void setupGpuDecoder(RenderList& r);
83 void createPipelines(RenderList& r);
84
85 // Hardware decoding
86 AVPixelFormat selectHardwareAcceleration(
87 score::gfx::GraphicsApi api, int codec_id) const;
88 bool setupHardwareDecoder(
89 const void* codec, AVPixelFormat hwPixFmt);
90 static enum AVPixelFormat negotiateHWFormat(
91 AVCodecContext* ctx, const enum AVPixelFormat* pix_fmts);
92 void transferHWFrame();
93
94 // Video file info
95 std::string m_filePath;
96 Video::ImageFormat m_frameFormat{};
97 double m_fps{};
98 double m_flicks_per_dts{};
99 double m_dts_per_flicks{};
100 bool m_useAVCodec{true};
101
102 // Own LibAV context
103 AVFormatContext* m_formatContext{};
104 AVCodecContext* m_codecContext{};
105 const void* m_codec{}; // AVCodec*
106 AVStream* m_avstream{};
107 AVFrame* m_decodedFrame{};
108
109 // Hardware decode state
110 AVBufferRef* m_hwDeviceCtx{};
111 AVPixelFormat m_hwPixelFormat{AV_PIX_FMT_NONE};
112 AVPixelFormat m_hwSwFormat{AV_PIX_FMT_NONE};
113 std::vector<const char*> m_vkEnabledExtensions; // kept alive for FFmpeg
114 AVFrame* m_swTransferFrame{};
115 score::gfx::GraphicsApi m_rhiApi{};
116 QRhi* m_rhi{};
117 bool m_hwSwFormatChecked{false};
118 bool m_zeroCopyFailed{false};
119 bool m_sharedVulkanDevice{false}; // true if FFmpeg uses QRhi's VkDevice
120
121 // Render state
122 PassMap m_p;
123 MeshBuffers m_meshBuffer{};
124 QRhiBuffer* m_processUBO{};
125 QRhiBuffer* m_materialUBO{};
126
127 struct Material
128 {
129 float scale_w{}, scale_h{};
130 float tex_w{}, tex_h{};
131 };
132
133 std::unique_ptr<GPUVideoDecoder> m_gpu;
134 score::gfx::ScaleMode m_currentScaleMode{};
135
136 int64_t m_lastRequestedFlicks{-1};
137 int64_t m_lastDecodedDts{INT64_MIN};
138 bool m_recomputeScale{true};
139};
140
141}
Renderer for intra-only video codecs with instant seeking.
Definition DirectVideoNodeRenderer.hpp:47
Renderer for a given node.
Definition NodeRenderer.hpp:11
List of nodes to be rendered to an output.
Definition RenderList.hpp:19
Definition VideoNode.hpp:73
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:12
GraphicsApi
Available graphics APIs to use.
Definition RenderState.hpp:22
ScaleMode
How to resize a texture to adapt it to a viewport.
Definition Scale.hpp:10
Definition VideoInterface.hpp:26
Definition VideoInterface.hpp:49
Connection between two score::gfx::Port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:74
Definition Mesh.hpp:23
Definition GPUVideoDecoder.hpp:29
Port of a score::gfx::Node.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:53
Useful abstraction for storing all the data related to a render target.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:119