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

Resolves #288 frame buffer swap bug

parent 703a51a3
No related branches found
No related tags found
No related merge requests found
......@@ -227,6 +227,10 @@ void ftl::gui::Camera::_draw(ftl::rgbd::FrameSet &fs) {
Eigen::Matrix4d t;
t.setIdentity();
renderer_->render(fs, frame_, channel_, t);
// TODO: Insert post-render pipeline.
// FXAA + Bad colour removal
_downloadFrames(&frame_);
if (record_stream_ && record_stream_->active()) {
......
......@@ -36,11 +36,16 @@ int main(int argc, char **argv) {
try {
nanogui::init();
/* scoped variables */ {
{
nanogui::ref<ftl::gui::Screen> app = new ftl::gui::Screen(root, net, controller);
app->drawAll();
app->setVisible(true);
nanogui::mainloop();
LOG(INFO) << "Stopping...";
ftl::timer::stop(false);
ftl::pool.stop(true);
LOG(INFO) << "All threads stopped.";
}
nanogui::shutdown();
......@@ -54,7 +59,8 @@ int main(int argc, char **argv) {
return -1;
}
net->shutdown();
net->shutdown();
delete controller;
delete net;
delete root;
......
......@@ -80,6 +80,13 @@ SourceWindow::SourceWindow(ftl::gui::Screen *screen)
cycle_ = 0;
receiver_->onFrameSet([this](ftl::rgbd::FrameSet &fs) {
// Enforce interpolated colour
for (int i=0; i<fs.frames.size(); ++i) {
fs.frames[i].createTexture<uchar4>(Channel::Colour, true);
}
pre_pipeline_->apply(fs, fs, 0);
fs.swapTo(frameset_);
// Request the channels required by current camera configuration
......@@ -96,13 +103,6 @@ SourceWindow::SourceWindow(ftl::gui::Screen *screen)
//LOG(INFO) << "Channels = " << (unsigned int)cstream->available(fs.id);
// Enforce interpolated colour
for (int i=0; i<frameset_.frames.size(); ++i) {
frameset_.frames[i].createTexture<uchar4>(Channel::Colour, true);
}
pre_pipeline_->apply(frameset_, frameset_, 0);
int i=0;
for (auto cam : cameras_) {
// Only update the camera periodically unless the active camera
......
......@@ -266,11 +266,11 @@ static void run(ftl::Configurable *root) {
LOG(INFO) << "Shutting down...";
ftl::timer::stop();
ftl::pool.stop(true);
ctrl.stop();
net->shutdown();
ftl::pool.stop();
cudaProfilerStop();
//cudaProfilerStop();
LOG(INFO) << "Deleting...";
......
......@@ -30,6 +30,8 @@ struct AudioData {
throw ftl::exception("Type not valid for audio channel");
}
inline void reset() {}
Audio data;
};
......
......@@ -47,13 +47,15 @@ Source::Source(nlohmann::json &config) : ftl::Configurable(config), buffer_(4800
#ifdef HAVE_PORTAUDIO
ftl::audio::pa_init();
int device = value("audio_device",-1);
if (device >= Pa_GetDeviceCount()) device = -1;
PaStreamParameters inputParameters;
//bzero( &inputParameters, sizeof( inputParameters ) );
inputParameters.channelCount = 2;
inputParameters.device = value("audio_device",-1);
//inputParameters.hostApiSpecificStreamInfo = NULL;
inputParameters.device = device;
inputParameters.sampleFormat = paInt16;
inputParameters.suggestedLatency = (inputParameters.device >= 0) ? Pa_GetDeviceInfo(inputParameters.device)->defaultLowInputLatency : 0;
inputParameters.suggestedLatency = (device >= 0) ? Pa_GetDeviceInfo(device)->defaultLowInputLatency : 0;
inputParameters.hostApiSpecificStreamInfo = NULL;
PaError err;
......
......@@ -99,7 +99,7 @@ Master::Master(Configurable *root, Universe *net)
}
Master::~Master() {
net_->unbind("log");
stop();
}
void Master::restart() {
......@@ -214,6 +214,7 @@ void Master::stop() {
net_->unbind("get_cfg");
net_->unbind("slave_details"); // TODO: Remove
net_->unbind("log_subscribe");
net_->unbind("log");
}
void Master::sendLog(const loguru::Message& message) {
......
......@@ -51,6 +51,10 @@ struct VideoData {
T &make() {
throw ftl::exception("Unsupported type for Video data channel");
};
inline void reset() {
encoded.clear();
}
};
// Specialisations for cv mat types
......
......@@ -56,9 +56,9 @@ cv::cuda::GpuMat &VideoData::make<cv::cuda::GpuMat>() {
for (size_t i=0u; i<Channels<0>::kMax; ++i) {
data_[i].encoded.clear();
}
}
}*/
void Frame::resetFull() {
/*void Frame::resetFull() {
origin_ = nullptr;
channels_.clear();
gpu_.clear();
......
......@@ -37,6 +37,7 @@ void FrameSet::swapTo(ftl::rgbd::FrameSet &fs) {
fs.count = static_cast<int>(count);
fs.stale = stale;
fs.mask = static_cast<unsigned int>(mask);
fs.id = id;
for (size_t i=0; i<frames.size(); ++i) {
frames[i].swapTo(Channels<0>::All(), fs.frames[i]);
......@@ -225,7 +226,7 @@ ftl::rgbd::FrameSet *Builder::_findFrameset(int64_t ts) {
* Note: Must occur inside a mutex lock.
*/
ftl::rgbd::FrameSet *Builder::_getFrameset() {
LOG(INFO) << "BUF SIZE = " << framesets_.size();
//LOG(INFO) << "BUF SIZE = " << framesets_.size();
for (auto i=framesets_.begin(); i!=framesets_.end(); i++) {
auto *f = *i;
//LOG(INFO) << "GET: " << f->count << " of " << size_;
......@@ -266,8 +267,11 @@ ftl::rgbd::FrameSet *Builder::_addFrameset(int64_t timestamp) {
if (framesets_.size() < kMaxFramesets) {
allocated_.push_back(new ftl::rgbd::FrameSet);
} else {
LOG(ERROR) << "Could not allocate framesetL: " << timestamp;
return nullptr;
LOG(WARNING) << "Frameset buffer full, resetting: " << timestamp;
// Do a complete reset
std::swap(framesets_, allocated_);
//return nullptr;
}
}
FrameSet *newf = allocated_.front();
......
......@@ -22,7 +22,10 @@ Receiver::Receiver(nlohmann::json &config) : ftl::Configurable(config), stream_(
}
Receiver::~Receiver() {
//if (stream_) {
// stream_->onPacket(nullptr);
//}
builder_.onFrameSet(nullptr);
}
void Receiver::onAudio(const ftl::audio::FrameSet::Callback &cb) {
......@@ -151,13 +154,15 @@ void Receiver::_processVideo(const StreamPacket &spkt, const Packet &pkt) {
//if (rchan != Channel::Colour && rchan != chan) return;
if (frame.frame.hasChannel(spkt.channel)) {
// FIXME: Is this a corruption in recording or in playback?
// Seems to occur in same place in ftl file, one channel is missing
LOG(ERROR) << "Previous frame not complete: " << frame.timestamp;
//LOG(ERROR) << " --- " << (string)spkt;
UNIQUE_LOCK(frame.mutex, lk);
frame.frame.reset();
frame.completed.clear();
//if (frame.frame.hasChannel(spkt.channel)) {
// FIXME: Is this a corruption in recording or in playback?
// Seems to occur in same place in ftl file, one channel is missing
LOG(WARNING) << "Previous frame not complete: " << frame.timestamp;
//LOG(ERROR) << " --- " << (string)spkt;
//frame.frame.reset();
//frame.completed.clear();
//}
}
frame.timestamp = spkt.timestamp;
......
......@@ -270,6 +270,9 @@ void ftl::data::Frame<BASE,N,STATE,DATA>::reset() {
origin_ = nullptr;
channels_.clear();
data_channels_.clear();
for (size_t i=0u; i<ftl::codecs::Channels<BASE>::kMax; ++i) {
data_[i].reset();
}
}
template <int BASE, int N, typename STATE, typename DATA>
......@@ -283,7 +286,7 @@ void ftl::data::Frame<BASE,N,STATE,DATA>::swapTo(ftl::codecs::Channels<BASE> cha
// Should we swap this channel?
if (channels.has(c)) {
f.channels_ += c;
f.getData(c) = std::move(getData(c));
std::swap(f.getData(c),getData(c));
}
}
......
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