File: renderbackend.h

package info (click to toggle)
olive-editor 20200620-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 40,228 kB
  • sloc: cpp: 51,932; sh: 56; makefile: 7; xml: 7
file content (155 lines) | stat: -rw-r--r-- 3,334 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/***

  Olive - Non-Linear Video Editor
  Copyright (C) 2019 Olive Team

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

***/

#ifndef RENDERBACKEND_H
#define RENDERBACKEND_H

#include <QtConcurrent/QtConcurrent>

#include "dialog/rendercancel/rendercancel.h"
#include "decodercache.h"
#include "node/graph.h"
#include "node/output/viewer/viewer.h"
#include "render/backend/colorprocessorcache.h"
#include "renderticket.h"
#include "renderworker.h"

OLIVE_NAMESPACE_ENTER

class RenderBackend : public QObject
{
  Q_OBJECT
public:
  RenderBackend(QObject* parent = nullptr);

  virtual ~RenderBackend() override;

  void Close();

  ViewerOutput* GetViewerNode() const
  {
    return viewer_node_;
  }

  void SetViewerNode(ViewerOutput* viewer_node);

  void SetUpdateWithGraph(bool e)
  {
    update_with_graph_ = e;
  }

  void SetRenderMode(RenderMode::Mode e)
  {
    render_mode_ = e;
  }

  void EnablePreviewGeneration(qint64 job_time)
  {
    preview_job_time_ = job_time;
  }

  void ClearVideoQueue();

  void ProcessUpdateQueue();

  /**
   * @brief Asynchronously generate a hash at a given time
   */
  RenderTicketPtr Hash(const QVector<rational> &times);

  /**
   * @brief Asynchronously generate a frame at a given time
   */
  RenderTicketPtr RenderFrame(const rational& time);

  /**
   * @brief Asynchronously generate a chunk of audio
   */
  RenderTicketPtr RenderAudio(const TimeRange& r);

  const VideoParams& GetVideoParams() const
  {
    return video_params_;
  }

  const AudioParams& GetAudioParams() const
  {
    return audio_params_;
  }

  void SetVideoParams(const VideoParams& params);

  void SetAudioParams(const AudioParams& params);

  void SetVideoDownloadMatrix(const QMatrix4x4& mat);

  static std::list<TimeRange> SplitRangeIntoChunks(const TimeRange& r);

public slots:
  void NodeGraphChanged(NodeInput *source);

protected:
  virtual RenderWorker* CreateNewWorker() = 0;

private:
  void CopyNodeInputValue(NodeInput* input);
  Node *CopyNodeConnections(Node *src_node);
  void CopyNodeMakeConnection(NodeInput *src_input, NodeInput *dst_input);

  ViewerOutput* viewer_node_;

  // VIDEO MEMBERS
  VideoParams video_params_;
  QMatrix4x4 video_download_matrix_;

  // AUDIO MEMBERS
  AudioParams audio_params_;

  QList<NodeInput*> graph_update_queue_;
  QHash<Node*, Node*> copy_map_;
  ViewerOutput* copied_viewer_node_;

  QThreadPool pool_;

  std::list<RenderTicketPtr> render_queue_;

  struct WorkerData {
    RenderWorker* worker;
    bool busy;
  };

  QVector<WorkerData> workers_;

  bool update_with_graph_;

  qint64 preview_job_time_;

  RenderMode::Mode render_mode_;

private slots:
  void WorkerFinished();

  void RunNextJob();

};

OLIVE_NAMESPACE_EXIT

#endif // RENDERBACKEND_H