Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v1.4] Fix conflict in camera subscriptions #2133

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 3 additions & 26 deletions src/mavsdk/plugins/camera/camera_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ void CameraImpl::manual_enable()
_parent->add_call_every(
[this]() { request_camera_information(); }, 10.0, &_camera_information_call_every_cookie);

_parent->add_call_every([this]() { request_status(); }, 5.0, &_status.call_every_cookie);

// for backwards compatibility with Yuneec drones
if (_parent->has_autopilot()) {
request_flight_information();
Expand All @@ -222,6 +224,7 @@ void CameraImpl::manual_disable()
{
invalidate_params();
_parent->remove_call_every(_camera_information_call_every_cookie);
_parent->remove_call_every(_status.call_every_cookie);

if (_flight_information_call_every_cookie) {
_parent->remove_call_every(_flight_information_call_every_cookie);
Expand Down Expand Up @@ -582,21 +585,6 @@ void CameraImpl::subscribe_information(const Camera::InformationCallback& callba
{
std::lock_guard<std::mutex> lock(_information.mutex);
_information.subscription_callback = callback;

// If there was already a subscription, cancel the call
if (_status.call_every_cookie) {
_parent->remove_call_every(_status.call_every_cookie);
}

if (callback) {
if (_status.call_every_cookie == nullptr) {
_parent->add_call_every(
[this]() { request_status(); }, 5.0, &_status.call_every_cookie);
}
} else {
_parent->remove_call_every(_status.call_every_cookie);
_status.call_every_cookie = nullptr;
}
}

Camera::Result CameraImpl::start_video_streaming()
Expand Down Expand Up @@ -849,18 +837,7 @@ void CameraImpl::request_status()
void CameraImpl::subscribe_status(const Camera::StatusCallback callback)
{
std::lock_guard<std::mutex> lock(_status.mutex);

_status.subscription_callback = callback;

if (callback) {
if (_status.call_every_cookie == nullptr) {
_parent->add_call_every(
[this]() { request_status(); }, 5.0, &_status.call_every_cookie);
}
} else {
_parent->remove_call_every(_status.call_every_cookie);
_status.call_every_cookie = nullptr;
}
}

Camera::Status CameraImpl::status()
Expand Down
Loading