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
12namespace Video
13{
14struct VideoInterface;
15class ExternalInput;
16}
17namespace score::gfx
18{
19class VideoNodeRenderer;
20class DirectVideoNodeRenderer;
21class VideoNode;
22
24{
25 AVFrame* frame{};
26 std::atomic_int use_count{};
27};
28
30{
33
34 std::shared_ptr<RefcountedFrame> currentFrame() const noexcept;
35 void updateCurrentFrame(AVFrame* frame);
36 void releaseFramesToFree();
37 void releaseAllFrames();
38
39 std::shared_ptr<Video::VideoInterface> m_decoder;
40
41 mutable std::mutex m_frameLock{};
42 std::shared_ptr<RefcountedFrame> m_currentFrame TS_GUARDED_BY(m_frameLock);
43
44 int64_t m_currentFrameIdx{};
45
46 std::vector<AVFrame*> m_framesToFree;
47 std::vector<std::shared_ptr<RefcountedFrame>> m_framesInFlight;
48};
49
51{
54
55 static AVFrame* nextFrame(
56 const VideoNode& node, Video::VideoInterface& decoder,
57 std::vector<AVFrame*>& framesToFree, AVFrame*& nextFrame);
58
59 bool mustReadVideoFrame(const VideoNode& node);
60 void readNextFrame(VideoNode& node);
61
62 void pause(bool p);
63
64private:
65 QElapsedTimer m_timer;
66 AVFrame* m_nextFrame{};
67 double m_lastFrameTime{};
68 double m_lastPlaybackTime{-1.};
69 bool m_readFrame{};
70};
71
72class SCORE_PLUGIN_GFX_EXPORT VideoNodeBase : public ProcessNode
73{
74public:
75 void setScaleMode(score::gfx::ScaleMode s);
76 void setPlaybackMode(score::gfx::PlaybackMode s);
77 void setOutputFormat(::Video::OutputFormat s);
78 void setTonemap(::Video::Tonemap s);
79
80 friend VideoNodeRenderer;
82
83protected:
84 QString m_filter;
85 score::gfx::ScaleMode m_scaleMode{};
86 score::gfx::PlaybackMode m_playbackMode{};
87 ::Video::OutputFormat m_outputFormat{};
88 ::Video::Tonemap m_tonemap{};
89};
90
94class SCORE_PLUGIN_GFX_EXPORT VideoNode : public VideoNodeBase
95{
96public:
98 std::shared_ptr<Video::VideoInterface> dec, std::optional<double> nativeTempo);
99
100 virtual ~VideoNode();
101
102 score::gfx::NodeRenderer* createRenderer(RenderList& r) const noexcept override;
103
104 void seeked();
105
106 void process(Message&& msg) override;
107 void update() override;
108
109 VideoFrameReader reader;
110
111 void pause(bool);
112
113private:
114 friend VideoFrameReader;
115 friend VideoNodeRenderer;
116
117 std::optional<double> m_nativeTempo;
118 Timings m_lastToken{};
119 QElapsedTimer m_timer;
120 std::atomic_bool m_pause{};
121};
122}
123
124namespace score::gfx
125{
129class SCORE_PLUGIN_GFX_EXPORT CameraNode : public VideoNodeBase
130{
131public:
132 explicit CameraNode(std::shared_ptr<Video::ExternalInput> dec, QString filter = {});
133
134 virtual ~CameraNode();
135
136 score::gfx::NodeRenderer* createRenderer(RenderList& r) const noexcept override;
137
138 void process(Message&& msg) override;
139 void renderedNodesChanged() override;
140
141 VideoFrameShare reader;
142
143 std::atomic_bool must_stop{};
144
145private:
146 friend VideoNodeRenderer;
147};
148
149}
Renderer for intra-only video codecs with instant seeking.
Definition DirectVideoNodeRenderer.hpp:47
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:73
Model for rendering a video.
Definition VideoNode.hpp:95
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:59
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:49
Definition VideoNode.hpp:24
Messages sent from the execution thread to the rendering thread.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:43
Definition VideoNode.hpp:51
Definition VideoNode.hpp:30