Loading...
Searching...
No Matches
VideoNode.hpp
1#pragma once
2
3#include <Gfx/Graph/Node.hpp>
4#include <Video/VideoEnums.hpp>
5extern "C" {
6#include <libavformat/avformat.h>
7}
8#include <ossia/detail/mutex.hpp>
9
10#include <atomic>
11#include <limits>
12
13namespace Video
14{
15struct VideoInterface;
16class ExternalInput;
17}
18namespace score::gfx
19{
20class VideoNodeRenderer;
21class DirectVideoNodeRenderer;
22class VideoNode;
23
25{
26 AVFrame* frame{};
27 std::atomic_int use_count{};
28};
29
30struct SCORE_PLUGIN_GFX_EXPORT VideoFrameShare
31{
34
35 std::shared_ptr<RefcountedFrame> currentFrame() const noexcept;
36 void updateCurrentFrame(AVFrame* frame);
37 void releaseFramesToFree();
38 void releaseAllFrames();
39
40 std::shared_ptr<Video::VideoInterface> m_decoder;
41
42 mutable std::mutex m_frameLock{};
43 std::shared_ptr<RefcountedFrame> m_currentFrame TS_GUARDED_BY(m_frameLock);
44
45 int64_t m_currentFrameIdx{};
46
47 std::vector<AVFrame*> m_framesToFree;
48 std::vector<std::shared_ptr<RefcountedFrame>> m_framesInFlight;
49};
50
51struct SCORE_PLUGIN_GFX_EXPORT VideoFrameReader : VideoFrameShare
52{
55
59 static AVFrame* nextFrame(
60 const VideoNode& node, Video::VideoInterface& decoder,
61 std::vector<AVFrame*>& framesToFree, AVFrame*& nextFrame, bool showing);
62
63 bool mustReadVideoFrame(const VideoNode& node);
64 void readNextFrame(VideoNode& node);
65
66 void pause(bool p);
67
68private:
69 QElapsedTimer m_timer;
70 AVFrame* m_nextFrame{};
71 double m_lastFrameTime{};
72 double m_lastPlaybackTime{-1.};
73 bool m_readFrame{};
74 bool m_showing{};
77 int m_backwardSeekGeneration{-1};
78 double m_earliestFrameTime{std::numeric_limits<double>::infinity()};
79};
80
81class SCORE_PLUGIN_GFX_EXPORT VideoNodeBase : public ProcessNode
82{
83public:
84 void setScaleMode(score::gfx::ScaleMode s);
85 void setPlaybackMode(score::gfx::PlaybackMode s);
86 void setOutputFormat(::Video::OutputFormat s);
87 void setTonemap(::Video::Tonemap s);
88 void setDecodingSettings(QString hardwareDecode, int threads);
89
90 friend VideoNodeRenderer;
92
93protected:
94 QString m_filter;
95 score::gfx::ScaleMode m_scaleMode{};
96 score::gfx::PlaybackMode m_playbackMode{};
97 ::Video::OutputFormat m_outputFormat{};
98 ::Video::Tonemap m_tonemap{};
102 int m_decodingThreads{};
103};
104
108class SCORE_PLUGIN_GFX_EXPORT VideoNode : public VideoNodeBase
109{
110public:
111 VideoNode(
112 std::shared_ptr<Video::VideoInterface> dec, std::optional<double> nativeTempo);
113
114 virtual ~VideoNode();
115
116 score::gfx::NodeRenderer* createRenderer(RenderList& r) const noexcept override;
117
118 void seeked();
119
120 void process(Message&& msg) override;
121 void update() override;
122
123 VideoFrameReader reader;
124
125 void pause(bool);
126
127private:
128 friend VideoFrameReader;
129 friend VideoNodeRenderer;
130
131 std::optional<double> m_nativeTempo;
132 Timings m_lastToken{};
133 QElapsedTimer m_timer;
135 double m_rate{1.};
136 std::atomic_bool m_pause{};
137};
138}
139
140namespace score::gfx
141{
145class SCORE_PLUGIN_GFX_EXPORT CameraNode : public VideoNodeBase
146{
147public:
148 explicit CameraNode(std::shared_ptr<Video::ExternalInput> dec, QString filter = {});
149
150 virtual ~CameraNode();
151
152 score::gfx::NodeRenderer* createRenderer(RenderList& r) const noexcept override;
153
154 void process(Message&& msg) override;
155 void renderedNodesChanged() override;
156
157 VideoFrameShare reader;
158
159 std::atomic_bool must_stop{};
160
161private:
162 friend VideoNodeRenderer;
163};
164
165}
Renderer for intra-only video codecs with instant seeking.
Definition DirectVideoNodeRenderer.hpp:50
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:216
List of nodes to be rendered to an output.
Definition RenderList.hpp:33
Definition VideoNode.hpp:82
QString m_hardwareDecode
Definition VideoNode.hpp:101
Model for rendering a video.
Definition VideoNode.hpp:109
Definition VideoNodeRenderer.hpp:88
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:11
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:91
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:51
Definition VideoNode.hpp:25
Messages sent from the execution thread to the rendering thread.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:45
Definition VideoNode.hpp:52
Definition VideoNode.hpp:31