VideoNode.hpp
1 #pragma once
2 
3 #include <Gfx/Graph/Node.hpp>
4 extern "C" {
5 #include <libavformat/avformat.h>
6 }
7 #include <ossia/detail/mutex.hpp>
8 
9 #include <atomic>
10 
11 namespace Video
12 {
13 struct VideoInterface;
14 class ExternalInput;
15 }
16 namespace score::gfx
17 {
18 class VideoNodeRenderer;
19 class VideoNode;
20 
22 {
23  AVFrame* frame{};
24  std::atomic_int use_count{};
25 };
26 
28 {
30  ~VideoFrameShare();
31 
32  std::shared_ptr<RefcountedFrame> currentFrame() const noexcept;
33  void updateCurrentFrame(AVFrame* frame);
34  void releaseFramesToFree();
35  void releaseAllFrames();
36 
37  std::shared_ptr<Video::VideoInterface> m_decoder;
38 
39  mutable std::mutex m_frameLock{};
40  std::shared_ptr<RefcountedFrame> m_currentFrame TS_GUARDED_BY(m_frameLock);
41 
42  int64_t m_currentFrameIdx{};
43 
44  std::vector<AVFrame*> m_framesToFree;
45  std::vector<std::shared_ptr<RefcountedFrame>> m_framesInFlight;
46 };
47 
49 {
52 
53  static AVFrame* nextFrame(
54  const VideoNode& node, Video::VideoInterface& decoder,
55  std::vector<AVFrame*>& framesToFree, AVFrame*& nextFrame);
56 
57  bool mustReadVideoFrame(const VideoNode& node);
58  void readNextFrame(VideoNode& node);
59 
60  void pause(bool p);
61 
62 private:
63  QElapsedTimer m_timer;
64  AVFrame* m_nextFrame{};
65  double m_lastFrameTime{};
66  double m_lastPlaybackTime{-1.};
67  bool m_readFrame{};
68 };
69 
70 class SCORE_PLUGIN_GFX_EXPORT VideoNodeBase : public ProcessNode
71 {
72 public:
73  void setScaleMode(score::gfx::ScaleMode s);
74 
75  friend VideoNodeRenderer;
76 
77 protected:
78  score::gfx::ScaleMode m_scaleMode{};
79 };
80 
84 class SCORE_PLUGIN_GFX_EXPORT VideoNode : public VideoNodeBase
85 {
86 public:
87  VideoNode(
88  std::shared_ptr<Video::VideoInterface> dec, std::optional<double> nativeTempo);
89 
90  virtual ~VideoNode();
91 
92  score::gfx::NodeRenderer* createRenderer(RenderList& r) const noexcept override;
93 
94  void seeked();
95 
96  void process(Message&& msg) override;
97  void update() override;
98 
99  VideoFrameReader reader;
100 
101  void pause(bool);
102 
103 private:
104  friend VideoFrameReader;
105  friend VideoNodeRenderer;
106 
107  std::optional<double> m_nativeTempo;
108  Timings m_lastToken{};
109  QElapsedTimer m_timer;
110  std::atomic_bool m_pause{};
111 };
112 }
113 
114 namespace score::gfx
115 {
119 class SCORE_PLUGIN_GFX_EXPORT CameraNode : public VideoNodeBase
120 {
121 public:
122  explicit CameraNode(std::shared_ptr<Video::ExternalInput> dec);
123 
124  virtual ~CameraNode();
125 
126  score::gfx::NodeRenderer* createRenderer(RenderList& r) const noexcept override;
127 
128  void process(Message&& msg) override;
129  void renderedNodesChanged() override;
130 
131  VideoFrameShare reader;
132 
133  std::atomic_bool must_stop{};
134 
135 private:
136  friend VideoNodeRenderer;
137 };
138 
139 }
Model for rendering a camera feed.
Definition: VideoNode.hpp:120
Renderer for a given node.
Definition: NodeRenderer.hpp:11
Common base class for nodes that map to score processes.
Definition: score-plugin-gfx/Gfx/Graph/Node.hpp:110
List of nodes to be rendered to an output.
Definition: RenderList.hpp:19
Definition: VideoNode.hpp:71
Model for rendering a video.
Definition: VideoNode.hpp:85
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:37
Definition: score-plugin-gfx/Gfx/Graph/Node.hpp:51
Definition: VideoNode.hpp:22
Messages sent from the execution thread to the rendering thread.
Definition: score-plugin-gfx/Gfx/Graph/Node.hpp:45
Definition: VideoNode.hpp:49
Definition: VideoNode.hpp:28