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 DirectVideoNodeRenderer;
20class VideoNode;
21
23{
24 AVFrame* frame{};
25 std::atomic_int use_count{};
26};
27
29{
32
33 std::shared_ptr<RefcountedFrame> currentFrame() const noexcept;
34 void updateCurrentFrame(AVFrame* frame);
35 void releaseFramesToFree();
36 void releaseAllFrames();
37
38 std::shared_ptr<Video::VideoInterface> m_decoder;
39
40 mutable std::mutex m_frameLock{};
41 std::shared_ptr<RefcountedFrame> m_currentFrame TS_GUARDED_BY(m_frameLock);
42
43 int64_t m_currentFrameIdx{};
44
45 std::vector<AVFrame*> m_framesToFree;
46 std::vector<std::shared_ptr<RefcountedFrame>> m_framesInFlight;
47};
48
50{
53
54 static AVFrame* nextFrame(
55 const VideoNode& node, Video::VideoInterface& decoder,
56 std::vector<AVFrame*>& framesToFree, AVFrame*& nextFrame);
57
58 bool mustReadVideoFrame(const VideoNode& node);
59 void readNextFrame(VideoNode& node);
60
61 void pause(bool p);
62
63private:
64 QElapsedTimer m_timer;
65 AVFrame* m_nextFrame{};
66 double m_lastFrameTime{};
67 double m_lastPlaybackTime{-1.};
68 bool m_readFrame{};
69};
70
71class SCORE_PLUGIN_GFX_EXPORT VideoNodeBase : public ProcessNode
72{
73public:
74 void setScaleMode(score::gfx::ScaleMode s);
75 void setPlaybackMode(score::gfx::PlaybackMode s);
76
77 friend VideoNodeRenderer;
79
80protected:
81 QString m_filter;
82 score::gfx::ScaleMode m_scaleMode{};
83 score::gfx::PlaybackMode m_playbackMode{};
84};
85
89class SCORE_PLUGIN_GFX_EXPORT VideoNode : public VideoNodeBase
90{
91public:
93 std::shared_ptr<Video::VideoInterface> dec, std::optional<double> nativeTempo);
94
95 virtual ~VideoNode();
96
97 score::gfx::NodeRenderer* createRenderer(RenderList& r) const noexcept override;
98
99 void seeked();
100
101 void process(Message&& msg) override;
102 void update() override;
103
104 VideoFrameReader reader;
105
106 void pause(bool);
107
108private:
109 friend VideoFrameReader;
110 friend VideoNodeRenderer;
111
112 std::optional<double> m_nativeTempo;
113 Timings m_lastToken{};
114 QElapsedTimer m_timer;
115 std::atomic_bool m_pause{};
116};
117}
118
119namespace score::gfx
120{
124class SCORE_PLUGIN_GFX_EXPORT CameraNode : public VideoNodeBase
125{
126public:
127 explicit CameraNode(std::shared_ptr<Video::ExternalInput> dec, QString filter = {});
128
129 virtual ~CameraNode();
130
131 score::gfx::NodeRenderer* createRenderer(RenderList& r) const noexcept override;
132
133 void process(Message&& msg) override;
134 void renderedNodesChanged() override;
135
136 VideoFrameShare reader;
137
138 std::atomic_bool must_stop{};
139
140private:
141 friend VideoNodeRenderer;
142};
143
144}
Renderer for intra-only video codecs with instant seeking.
Definition DirectVideoNodeRenderer.hpp:35
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:176
List of nodes to be rendered to an output.
Definition RenderList.hpp:19
Definition VideoNode.hpp:72
Model for rendering a video.
Definition VideoNode.hpp:90
Definition VideoNodeRenderer.hpp:11
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:12
PlaybackMode
How to choose the video renderer.
Definition Scale.hpp:21
ScaleMode
How to resize a texture to adapt it to a viewport.
Definition Scale.hpp:10
Definition VideoInterface.hpp:41
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:49
Definition VideoNode.hpp:23
Messages sent from the execution thread to the rendering thread.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:43
Definition VideoNode.hpp:50
Definition VideoNode.hpp:29