VideoNodeRenderer.hpp
1 #pragma once
2 #include <Gfx/Graph/NodeRenderer.hpp>
3 #include <Gfx/Graph/VideoNode.hpp>
4 #include <Video/VideoInterface.hpp>
5 
6 namespace score::gfx
7 {
8 class GPUVideoDecoder;
9 
11 {
12 public:
13  explicit VideoNodeRenderer(
14  const VideoNodeBase& node, VideoFrameShare& frames) noexcept;
16 
17  VideoNodeRenderer() = delete;
18  VideoNodeRenderer(const VideoNodeRenderer&) = delete;
20  VideoNodeRenderer& operator=(const VideoNodeRenderer&) = delete;
21  VideoNodeRenderer& operator=(VideoNodeRenderer&&) = delete;
22 
23  TextureRenderTarget renderTargetForInput(const Port& input) override;
24 
25  void createGpuDecoder();
26  void setupGpuDecoder(RenderList& r);
27  void checkFormat(RenderList& r, AVPixelFormat fmt, int w, int h);
28 
29  void init(RenderList& renderer, QRhiResourceUpdateBatch& res) override;
30  void runRenderPass(RenderList&, QRhiCommandBuffer& commands, Edge& edge) override;
31 
32  void update(RenderList& renderer, QRhiResourceUpdateBatch& res) override;
33  void release(RenderList& r) override;
34 
35 private:
36  void createPipelines(RenderList& r);
37  void displayFrame(AVFrame& frame, RenderList& renderer, QRhiResourceUpdateBatch& res);
38  Video::VideoMetadata& decoder() const noexcept;
39 
40  const VideoNodeBase& node;
41  VideoFrameShare& reader;
42 
43  PassMap m_p;
44  QRhiBuffer* m_meshBuffer{};
45  QRhiBuffer* m_idxBuffer{};
46  QRhiBuffer* m_processUBO{};
47  QRhiBuffer* m_materialUBO{};
48 
49  struct Material
50  {
51  float scale_w{}, scale_h{};
52  float tex_w{}, tex_h{};
53  };
54 
55  std::unique_ptr<GPUVideoDecoder> m_gpu;
56 
57  Video::ImageFormat m_frameFormat{};
58  score::gfx::ScaleMode m_currentScaleMode{};
59 
60  std::shared_ptr<RefcountedFrame> m_currentFrame{};
61  int64_t m_currentFrameIdx{-1};
62  bool m_recomputeScale{};
63 };
64 
65 }
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:71
Definition: VideoNodeRenderer.hpp:11
Graphics rendering pipeline for ossia score.
Definition: Filter/PreviewWidget.hpp:12
ScaleMode
How to resize a texture to adapt it to a viewport.
Definition: Scale.hpp:10
Definition: VideoInterface.hpp:16
Definition: VideoInterface.hpp:29
Connection between two score::gfx::Port.
Definition: score-plugin-gfx/Gfx/Graph/Utils.hpp:66
Port of a score::gfx::Node.
Definition: score-plugin-gfx/Gfx/Graph/Utils.hpp:48
Useful abstraction for storing all the data related to a render target.
Definition: score-plugin-gfx/Gfx/Graph/Utils.hpp:111
Definition: VideoNode.hpp:28