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
// Copyright (c) 2012-2017 VideoStitch SAS
// Copyright (c) 2018 stitchEm
#pragma once
#include "frameBuffer.hpp"
#include "libvideostitch/output.hpp"
#include "libvideostitch/frame.hpp"
#include "libvideostitch/stitchOutput.hpp"
#include "libvideostitch/utils/semaphore.hpp"
#include <map>
#include <mutex>
#include <thread>
#include <vector>
namespace VideoStitch {
namespace Core {
/**
* The internal interface of the source loopback:
* an object holding buffers on the host and device side
* for a video frame.
*/
class ExtractOutput::Pimpl {
public:
typedef Output::VideoWriter Writer;
virtual ~Pimpl() {}
virtual bool setRenderers(const std::vector<std::shared_ptr<SourceRenderer>>&) = 0;
virtual bool addRenderer(std::shared_ptr<SourceRenderer>) = 0;
virtual bool removeRenderer(const std::string&) = 0;
virtual bool setWriters(const std::vector<std::shared_ptr<Output::VideoWriter>>&) = 0;
virtual bool addWriter(std::shared_ptr<Output::VideoWriter>) = 0;
virtual bool removeWriter(const std::string&) = 0;
virtual bool updateWriter(const std::string&, const Ptv::Value&) = 0;
videoreaderid_t getSource() const { return sourceIdx; }
/**
* Returns a device buffer to extract a source to, and an optional stream
* for asynchronous implementations.
*/
virtual GPU::Surface& acquireFrame(mtime_t date, GPU::Stream& stream) = 0;
/**
* Called by the stitcher when stitching is done.
*/
virtual Status pushVideo(mtime_t date) = 0;
protected:
explicit Pimpl(int64_t width, int64_t height, videoreaderid_t source = -1)
: width(width), height(height), sourceIdx(source) {}
int64_t width, height;
videoreaderid_t sourceIdx;
private:
Pimpl(const Pimpl&);
const Pimpl& operator=(const Pimpl&);
};
/**
* The internal interface of the pano stitcher's output:
* an object holding buffers on the host and device side
* for a panoramic frame.
*/
template <>
class StitchOutput::Pimpl {
public:
typedef Output::VideoWriter Writer;
virtual ~Pimpl() {}
virtual bool setRenderers(const std::vector<std::shared_ptr<PanoRenderer>>&) = 0;
virtual bool addRenderer(std::shared_ptr<PanoRenderer>) = 0;
virtual bool removeRenderer(const std::string&) = 0;
virtual void setCompositor(const std::shared_ptr<GPU::Overlayer>&) = 0;
virtual bool setWriters(const std::vector<std::shared_ptr<Output::VideoWriter>>&) = 0;
virtual bool addWriter(std::shared_ptr<Output::VideoWriter>) = 0;
virtual bool removeWriter(const std::string&) = 0;
virtual bool updateWriter(const std::string&, const Ptv::Value&) = 0;
/**
* Returns a device buffer to stitch a panorama to, and an optional stream
* for asynchronous implementations.
*/
virtual PanoSurface& acquireFrame(mtime_t) = 0;
/**
* Called by the stitcher when stitching is done.
*/
virtual Status pushVideo(mtime_t) = 0;
protected:
explicit Pimpl(int64_t width, int64_t height) : width(width), height(height) {}
int64_t width, height;
private:
Pimpl(const Pimpl&);
const Pimpl& operator=(const Pimpl&);
};
/**
* A function that pushes video frames to a bunch of user callbacks.
*/
template <typename FrameBuffer>
class WriterPusher {
public:
WriterPusher(size_t w, size_t h, const std::vector<std::shared_ptr<Output::VideoWriter>>& writers);
virtual ~WriterPusher();
bool setRenderers(const std::vector<std::shared_ptr<typename FrameBuffer::Renderer>>&);
bool addRenderer(std::shared_ptr<typename FrameBuffer::Renderer>);
bool removeRenderer(const std::string&);
void setCompositor(const std::shared_ptr<GPU::Overlayer>&);
bool setWriters(const std::vector<std::shared_ptr<Output::VideoWriter>>&);
bool addWriter(std::shared_ptr<Output::VideoWriter>);
bool removeWriter(const std::string&);
bool updateWriter(const std::string&, const Ptv::Value&);
protected:
void pushVideoToWriters(mtime_t date, FrameBuffer* delegate) const;
private:
size_t width;
std::map<std::string, std::shared_ptr<typename FrameBuffer::Renderer>> renderers;
mutable std::mutex renderersLock;
std::map<std::string, std::shared_ptr<Output::VideoWriter>> writers;
mutable std::mutex writersLock;
std::map<std::string, int> downsamplingFactors;
std::shared_ptr<GPU::Overlayer> compositor;
mutable std::mutex compositorLock;
};
typedef WriterPusher<PanoFrameBuffer> PanoWriterPusher;
typedef WriterPusher<SourceFrameBuffer> SourceWriterPusher;
} // namespace Core
} // namespace VideoStitch