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  QString m_filter;
79  score::gfx::ScaleMode m_scaleMode{};
80 };
81 
85 class SCORE_PLUGIN_GFX_EXPORT VideoNode : public VideoNodeBase
86 {
87 public:
88  VideoNode(
89  std::shared_ptr<Video::VideoInterface> dec, std::optional<double> nativeTempo,
90  QString f = {});
91 
92  virtual ~VideoNode();
93 
94  score::gfx::NodeRenderer* createRenderer(RenderList& r) const noexcept override;
95 
96  void seeked();
97 
98  void process(Message&& msg) override;
99  void update() override;
100 
101  VideoFrameReader reader;
102 
103  void pause(bool);
104 
105 private:
106  friend VideoFrameReader;
107  friend VideoNodeRenderer;
108 
109  std::optional<double> m_nativeTempo;
110  Timings m_lastToken{};
111  QElapsedTimer m_timer;
112  std::atomic_bool m_pause{};
113 };
114 }
115 
116 namespace score::gfx
117 {
121 class SCORE_PLUGIN_GFX_EXPORT CameraNode : public VideoNodeBase
122 {
123 public:
124  CameraNode(std::shared_ptr<Video::ExternalInput> dec, QString f = {});
125 
126  virtual ~CameraNode();
127 
128  score::gfx::NodeRenderer* createRenderer(RenderList& r) const noexcept override;
129 
130  void process(Message&& msg) override;
131  void renderedNodesChanged() override;
132 
133  VideoFrameShare reader;
134 
135  std::atomic_bool must_stop{};
136 
137 private:
138  friend VideoNodeRenderer;
139 };
140 
141 }
Model for rendering a camera feed.
Definition: VideoNode.hpp:122
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:86
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:31
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