Skip to content
Snippets Groups Projects
Commit 4f85c55a authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Reduce screen capture latency

parent f7e71730
No related branches found
No related tags found
No related merge requests found
...@@ -87,6 +87,9 @@ ScreenCapture::ScreenCapture(ftl::rgbd::Source *host) ...@@ -87,6 +87,9 @@ ScreenCapture::ScreenCapture(ftl::rgbd::Source *host)
return; return;
} }
// Page lock the shared memory...
cudaSafeCall(cudaHostRegister(s.shminfo.shmaddr, s.ximg->bytes_per_line * s.ximg->height, cudaHostRegisterDefault));
ready_ = true; ready_ = true;
#endif #endif
...@@ -101,6 +104,11 @@ ScreenCapture::ScreenCapture(ftl::rgbd::Source *host) ...@@ -101,6 +104,11 @@ ScreenCapture::ScreenCapture(ftl::rgbd::Source *host)
state_.getLeft() = params_; state_.getLeft() = params_;
host_->on("depth", [this](const ftl::config::Event &e) {
params_.maxDepth = host_->value("depth", 1.0f);
state_.getLeft() = params_;
});
} }
ScreenCapture::~ScreenCapture() { ScreenCapture::~ScreenCapture() {
...@@ -109,7 +117,15 @@ ScreenCapture::~ScreenCapture() { ...@@ -109,7 +117,15 @@ ScreenCapture::~ScreenCapture() {
#endif #endif
} }
void ScreenCapture::swap() {
}
bool ScreenCapture::retrieve() { bool ScreenCapture::retrieve() {
return true;
}
bool ScreenCapture::compute(int n, int b) {
if (!ready_) return false; if (!ready_) return false;
cv::Mat img; cv::Mat img;
...@@ -122,14 +138,9 @@ bool ScreenCapture::retrieve() { ...@@ -122,14 +138,9 @@ bool ScreenCapture::retrieve() {
frame_.setOrigin(&state_); frame_.setOrigin(&state_);
if (!img.empty()) { if (!img.empty()) {
frame_.create<cv::cuda::GpuMat>(Channel::Colour).upload(img); frame_.create<cv::Mat>(Channel::Colour) = img;
} }
return true;
}
bool ScreenCapture::compute(int n, int b) {
if (!ready_) return false;
host_->notify(timestamp_, frame_); host_->notify(timestamp_, frame_);
return true; return true;
} }
......
...@@ -23,12 +23,16 @@ class ScreenCapture : public ftl::rgbd::detail::Source { ...@@ -23,12 +23,16 @@ class ScreenCapture : public ftl::rgbd::detail::Source {
~ScreenCapture(); ~ScreenCapture();
bool capture(int64_t ts) { timestamp_ = ts; return true; }; bool capture(int64_t ts) { timestamp_ = ts; return true; };
void swap() override;
bool retrieve(); bool retrieve();
bool compute(int n=-1, int b=-1); bool compute(int n=-1, int b=-1);
bool isReady(); bool isReady();
private: private:
bool ready_; bool ready_;
int64_t cap_ts_;
int64_t cur_ts_;
ftl::rgbd::Frame sframe_;
ImplState *impl_state_; ImplState *impl_state_;
}; };
......
...@@ -26,7 +26,7 @@ class Sender : public ftl::Configurable { ...@@ -26,7 +26,7 @@ class Sender : public ftl::Configurable {
* Encode and transmit an entire frame set. Frames may already contain * Encode and transmit an entire frame set. Frames may already contain
* an encoded form, in which case that is used instead. * an encoded form, in which case that is used instead.
*/ */
void post(const ftl::rgbd::FrameSet &fs); void post(ftl::rgbd::FrameSet &fs);
/** /**
* Encode and transmit a set of audio channels. * Encode and transmit a set of audio channels.
...@@ -55,7 +55,7 @@ class Sender : public ftl::Configurable { ...@@ -55,7 +55,7 @@ class Sender : public ftl::Configurable {
std::unordered_map<int, EncodingState> state_; std::unordered_map<int, EncodingState> state_;
//ftl::codecs::Encoder *_getEncoder(int fsid, int fid, ftl::codecs::Channel c); //ftl::codecs::Encoder *_getEncoder(int fsid, int fid, ftl::codecs::Channel c);
void _encodeChannel(const ftl::rgbd::FrameSet &fs, ftl::codecs::Channel c, bool reset); void _encodeChannel(ftl::rgbd::FrameSet &fs, ftl::codecs::Channel c, bool reset);
int _generateTiles(const ftl::rgbd::FrameSet &fs, int offset, ftl::codecs::Channel c, cv::cuda::Stream &stream, bool); int _generateTiles(const ftl::rgbd::FrameSet &fs, int offset, ftl::codecs::Channel c, cv::cuda::Stream &stream, bool);
EncodingState &_getTile(int fsid, ftl::codecs::Channel c); EncodingState &_getTile(int fsid, ftl::codecs::Channel c);
cv::Rect _generateROI(const ftl::rgbd::FrameSet &fs, ftl::codecs::Channel c, int offset); cv::Rect _generateROI(const ftl::rgbd::FrameSet &fs, ftl::codecs::Channel c, int offset);
......
...@@ -114,7 +114,7 @@ static void mergeNALUnits(const std::list<ftl::codecs::Packet> &pkts, ftl::codec ...@@ -114,7 +114,7 @@ static void mergeNALUnits(const std::list<ftl::codecs::Packet> &pkts, ftl::codec
} }
} }
void Sender::post(const ftl::rgbd::FrameSet &fs) { void Sender::post(ftl::rgbd::FrameSet &fs) {
if (!stream_) return; if (!stream_) return;
Channels selected; Channels selected;
...@@ -222,7 +222,7 @@ void Sender::post(const ftl::rgbd::FrameSet &fs) { ...@@ -222,7 +222,7 @@ void Sender::post(const ftl::rgbd::FrameSet &fs) {
//do_inject_ = false; //do_inject_ = false;
} }
void Sender::_encodeChannel(const ftl::rgbd::FrameSet &fs, Channel c, bool reset) { void Sender::_encodeChannel(ftl::rgbd::FrameSet &fs, Channel c, bool reset) {
bool lossless = value("lossless", false); bool lossless = value("lossless", false);
int max_bitrate = std::max(0, std::min(255, value("max_bitrate", 255))); int max_bitrate = std::max(0, std::min(255, value("max_bitrate", 255)));
//int min_bitrate = std::max(0, std::min(255, value("min_bitrate", 0))); // TODO: Use this //int min_bitrate = std::max(0, std::min(255, value("min_bitrate", 0))); // TODO: Use this
...@@ -251,6 +251,13 @@ void Sender::_encodeChannel(const ftl::rgbd::FrameSet &fs, Channel c, bool reset ...@@ -251,6 +251,13 @@ void Sender::_encodeChannel(const ftl::rgbd::FrameSet &fs, Channel c, bool reset
return; return;
} }
// Upload if in host memory
for (auto &f : fs.frames) {
if (f.isCPU(c)) {
f.upload(Channels<0>(c), cv::cuda::StreamAccessor::getStream(enc->stream()));
}
}
int count = _generateTiles(fs, offset, c, enc->stream(), lossless); int count = _generateTiles(fs, offset, c, enc->stream(), lossless);
if (count <= 0) { if (count <= 0) {
LOG(ERROR) << "Could not generate tiles."; LOG(ERROR) << "Could not generate tiles.";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment