Skip to content

Commit d324e45

Browse files
committed
Add error propagation for processors
The new internal API policy: Packet processors should report internal errors by setting good() to false, and pass the last frame to the user with status set to 1. Currently CUDA, OpenCL, Tegra, and VAAPI have been added with the error propagation. CPU, OpenGL, and VT have no error checking in place so they do not report errors. TurboJPEG seems to produce non-fatal errors so it also does not propagate errors. The user should check the received frame's status for errors. If there are errors, the user should stop the device and exit. When good() is false, the processor->process() will no longer be called, and if the user continues to call waitForNewFrame(), it will hang.
1 parent 5177a1d commit d324e45

6 files changed

+45
-63
lines changed

include/internal/libfreenect2/async_packet_processor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ class AsyncPacketProcessor : public PacketProcessor<PacketT>
135135
if(current_packet_available_)
136136
{
137137
// invoke process impl
138-
processor_->process(current_packet_);
138+
if (processor_->good())
139+
processor_->process(current_packet_);
139140
/*
140141
* The stream parser passes the buffer asynchronously to processors so
141142
* it can not wait after process() finishes and free the buffer. In

src/cuda_depth_packet_processor.cu

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -937,11 +937,6 @@ void CudaDepthPacketProcessor::process(const DepthPacket &packet)
937937
if (listener_ == NULL)
938938
return;
939939

940-
if (!impl_->good) {
941-
LOG_ERROR << "CUDA in error state";
942-
return;
943-
}
944-
945940
impl_->startTiming();
946941

947942
impl_->ir_frame->timestamp = packet.timestamp;
@@ -953,12 +948,15 @@ void CudaDepthPacketProcessor::process(const DepthPacket &packet)
953948

954949
impl_->stopTiming(LOG_INFO);
955950

956-
if (impl_->good) {
957-
if (listener_->onNewFrame(Frame::Ir, impl_->ir_frame))
958-
impl_->newIrFrame();
959-
if (listener_->onNewFrame(Frame::Depth, impl_->depth_frame))
960-
impl_->newDepthFrame();
951+
if (!impl_->good) {
952+
impl_->ir_frame->status = 1;
953+
impl_->depth_frame->status = 1;
961954
}
955+
956+
if (listener_->onNewFrame(Frame::Ir, impl_->ir_frame))
957+
impl_->newIrFrame();
958+
if (listener_->onNewFrame(Frame::Depth, impl_->depth_frame))
959+
impl_->newDepthFrame();
962960
}
963961

964962
Allocator *CudaDepthPacketProcessor::getAllocator()

src/opencl_depth_packet_processor.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ class OpenCLDepthPacketProcessorImpl: public WithPerfLogging
223223
bool deviceInitialized;
224224
bool programBuilt;
225225
bool programInitialized;
226+
bool runtimeOk;
226227
std::string sourceCode;
227228

228229
#ifdef LIBFREENECT2_WITH_PROFILING_CL
@@ -234,6 +235,7 @@ class OpenCLDepthPacketProcessorImpl: public WithPerfLogging
234235
: deviceInitialized(false)
235236
, programBuilt(false)
236237
, programInitialized(false)
238+
, runtimeOk(true)
237239
{
238240
#if _BSD_SOURCE || _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600
239241
setenv("OCL_IGNORE_SELF_TEST", "1", 0);
@@ -773,15 +775,17 @@ void OpenCLDepthPacketProcessor::loadLookupTable(const short *lut)
773775

774776
bool OpenCLDepthPacketProcessor::good()
775777
{
776-
return impl_->deviceInitialized;
778+
return impl_->deviceInitialized && impl_->runtimeOk;
777779
}
778780

779781
void OpenCLDepthPacketProcessor::process(const DepthPacket &packet)
780782
{
781-
bool has_listener = this->listener_ != 0;
783+
if (!listener_)
784+
return;
782785

783786
if(!impl_->programInitialized && !impl_->initProgram())
784787
{
788+
impl_->runtimeOk = false;
785789
LOG_ERROR << "could not initialize OpenCLDepthPacketProcessor";
786790
return;
787791
}
@@ -793,22 +797,20 @@ void OpenCLDepthPacketProcessor::process(const DepthPacket &packet)
793797
impl_->ir_frame->sequence = packet.sequence;
794798
impl_->depth_frame->sequence = packet.sequence;
795799

796-
bool r = impl_->run(packet);
800+
impl_->runtimeOk = impl_->run(packet);
797801

798802
impl_->stopTiming(LOG_INFO);
799803

800-
if(has_listener && r)
804+
if (!impl_->runtimeOk)
801805
{
802-
if(this->listener_->onNewFrame(Frame::Ir, impl_->ir_frame))
803-
{
804-
impl_->newIrFrame();
805-
}
806-
807-
if(this->listener_->onNewFrame(Frame::Depth, impl_->depth_frame))
808-
{
809-
impl_->newDepthFrame();
810-
}
806+
impl_->ir_frame->status = 1;
807+
impl_->depth_frame->status = 1;
811808
}
809+
810+
if(listener_->onNewFrame(Frame::Ir, impl_->ir_frame))
811+
impl_->newIrFrame();
812+
if(listener_->onNewFrame(Frame::Depth, impl_->depth_frame))
813+
impl_->newDepthFrame();
812814
}
813815

814816
Allocator *OpenCLDepthPacketProcessor::getAllocator()

src/opengl_depth_packet_processor.cpp

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,8 @@ void OpenGLDepthPacketProcessor::loadLookupTable(const short *lut)
955955

956956
void OpenGLDepthPacketProcessor::process(const DepthPacket &packet)
957957
{
958-
bool has_listener = this->listener_ != 0;
958+
if (!listener_)
959+
return;
959960
Frame *ir = 0, *depth = 0;
960961

961962
impl_->startTiming();
@@ -964,34 +965,22 @@ void OpenGLDepthPacketProcessor::process(const DepthPacket &packet)
964965

965966
std::copy(packet.buffer, packet.buffer + packet.buffer_length/10*9, impl_->input_data.data);
966967
impl_->input_data.upload();
967-
impl_->run(has_listener ? &ir : 0, has_listener ? &depth : 0);
968+
impl_->run(&ir, &depth);
968969

969970
if(impl_->do_debug) glfwSwapBuffers(impl_->opengl_context_ptr);
970971

971972
impl_->stopTiming(LOG_INFO);
972973

973-
if(has_listener)
974-
{
975-
ir->timestamp = packet.timestamp;
976-
depth->timestamp = packet.timestamp;
977-
ir->sequence = packet.sequence;
978-
depth->sequence = packet.sequence;
979-
980-
if(!this->listener_->onNewFrame(Frame::Ir, ir))
981-
{
982-
delete ir;
983-
}
974+
ir->timestamp = packet.timestamp;
975+
depth->timestamp = packet.timestamp;
976+
ir->sequence = packet.sequence;
977+
depth->sequence = packet.sequence;
984978

985-
if(!this->listener_->onNewFrame(Frame::Depth, depth))
986-
{
987-
delete depth;
988-
}
989-
}
990-
else
991-
{
979+
if(!listener_->onNewFrame(Frame::Ir, ir))
992980
delete ir;
981+
982+
if(!listener_->onNewFrame(Frame::Depth, depth))
993983
delete depth;
994-
}
995984
}
996985

997986
} /* namespace libfreenect2 */

src/tegra_jpeg_rgb_packet_processor.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,6 @@ void TegraJpegRgbPacketProcessor::process(const RgbPacket &packet)
283283
if (listener_ == NULL)
284284
return;
285285

286-
if (!impl_->good) {
287-
LOG_ERROR << "Tegra jpeg is in error state";
288-
return;
289-
}
290-
291286
impl_->startTiming();
292287

293288
impl_->frame->timestamp = packet.timestamp;
@@ -300,9 +295,10 @@ void TegraJpegRgbPacketProcessor::process(const RgbPacket &packet)
300295

301296
impl_->stopTiming(LOG_INFO);
302297

303-
if (impl_->good) {
304-
if (listener_->onNewFrame(Frame::Color, impl_->frame))
305-
impl_->newFrame();
306-
}
298+
if (!impl_->good)
299+
impl_->frame->status = 1;
300+
301+
if (listener_->onNewFrame(Frame::Color, impl_->frame))
302+
impl_->newFrame();
307303
}
308304
} /* namespace libfreenect2 */

src/vaapi_rgb_packet_processor.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -464,11 +464,6 @@ void VaapiRgbPacketProcessor::process(const RgbPacket &packet)
464464
if (listener_ == 0)
465465
return;
466466

467-
if (!impl_->good) {
468-
LOG_ERROR << "libva in error state";
469-
return;
470-
}
471-
472467
impl_->startTiming();
473468

474469
impl_->frame->timestamp = packet.timestamp;
@@ -484,10 +479,11 @@ void VaapiRgbPacketProcessor::process(const RgbPacket &packet)
484479

485480
impl_->stopTiming(LOG_INFO);
486481

487-
if (impl_->good) {
488-
if (listener_->onNewFrame(Frame::Color, impl_->frame))
489-
impl_->newFrame();
490-
}
482+
if (!impl_->good)
483+
impl_->frame->status = 1;
484+
485+
if (listener_->onNewFrame(Frame::Color, impl_->frame))
486+
impl_->newFrame();
491487
}
492488

493489
Allocator *VaapiRgbPacketProcessor::getAllocator()

0 commit comments

Comments
 (0)