Skip to content

Commit

Permalink
gst: Fix device lost notification handling for closed devices
Browse files Browse the repository at this point in the history
  • Loading branch information
TIS-Edgar committed Apr 26, 2023
1 parent 41f36af commit 0c84ea6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/CaptureDeviceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ CaptureDeviceImpl::~CaptureDeviceImpl()

available_output_formats_.clear();

index_.remove_device_lost(deviceindex_lost_cb);

device_.reset();
}

Expand Down
15 changes: 15 additions & 0 deletions src/gstreamer-1.0/tcamsrc/gsttcammainsrc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,19 @@ static void gst_tcam_mainsrc_device_lost_callback(const tcam::tcam_device_info*
{
GstTcamMainSrc* self = (GstTcamMainSrc*)user_data;

GstState state;

// wait for 1 seconds max
gst_element_get_state(GST_ELEMENT(self), &state, nullptr, 1000000000);

if (!self->device || state == GST_STATE_NULL)
{
// device does not exist
// or source is null (aka no device exists)
// do nothing
return;
}

if (!self->device->is_streaming_)
{
return;
Expand Down Expand Up @@ -386,6 +399,8 @@ static bool gst_tcam_mainsrc_init_camera(GstTcamMainSrc* self)
return false;
}

// this cb will automatically be deleted once the device is closed
// no need for explicit cleanup
self->device->device_->register_device_lost_callback(gst_tcam_mainsrc_device_lost_callback,
self);

Expand Down

0 comments on commit 0c84ea6

Please sign in to comment.