Loading...
Searching...
No Matches
VideoNode.hpp
1#pragma once
2
3#include <Gfx/Graph/Node.hpp>
4extern "C" {
5#include <libavformat/avformat.h>
6}
7#include <ossia/detail/mutex.hpp>
8
9#include <atomic>
10
11namespace Video
12{
13struct VideoInterface;
14class ExternalInput;
15}
16namespace score::gfx
17{
18class VideoNodeRenderer;
19class VideoNode;
20
22{
23 AVFrame* frame{};
24 std::atomic_int use_count{};
25};
26
28{
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
62private:
63 QElapsedTimer m_timer;
64 AVFrame* m_nextFrame{};
65 double m_lastFrameTime{};
66 double m_lastPlaybackTime{-1.};
67 bool m_readFrame{};
68};
69
70class SCORE_PLUGIN_GFX_EXPORT VideoNodeBase : public ProcessNode
71{
72public:
73 void setScaleMode(score::gfx::ScaleMode s);
74
75 friend VideoNodeRenderer;
76
77protected:
78 QString m_filter;
79 score::gfx::ScaleMode m_scaleMode{};
80};
81
85class SCORE_PLUGIN_GFX_EXPORT VideoNode : public VideoNodeBase
86{
87public:
89 std::shared_ptr<Video::VideoInterface> dec, std::optional<double> nativeTempo);
90
91 virtual ~VideoNode();
92
93 score::gfx::NodeRenderer* createRenderer(RenderList& r) const noexcept override;
94
95 void seeked();
96
97 void process(Message&& msg) override;
98 void update() override;
99
100 VideoFrameReader reader;
101
102 void pause(bool);
103
104private:
105 friend VideoFrameReader;
106 friend VideoNodeRenderer;
107
108 std::optional<double> m_nativeTempo;
109 Timings m_lastToken{};
110 QElapsedTimer m_timer;
111 std::atomic_bool m_pause{};
112};
113}
114
115namespace score::gfx
116{
120class SCORE_PLUGIN_GFX_EXPORT CameraNode : public VideoNodeBase
121{
122public:
123 explicit CameraNode(std::shared_ptr<Video::ExternalInput> dec, QString filter = {});
124
125 virtual ~CameraNode();
126
127 score::gfx::NodeRenderer* createRenderer(RenderList& r) const noexcept override;
128
129 void process(Message&& msg) override;
130 void renderedNodesChanged() override;
131
132 VideoFrameShare reader;
133
134 std::atomic_bool must_stop{};
135
136private:
137 friend VideoNodeRenderer;
138};
139
140}
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: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