fix rare race condition in debug vid src
Some checks are pending
ContinuousDelivery / linux-ubuntu (push) Waiting to run
ContinuousDelivery / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Waiting to run
ContinuousDelivery / android (map[ndk_abi:armeabi-v7a vcpkg_toolkit:arm-neon-android]) (push) Waiting to run
ContinuousDelivery / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Waiting to run
ContinuousDelivery / windows (push) Waiting to run
ContinuousDelivery / windows-asan (push) Waiting to run
ContinuousDelivery / release (push) Blocked by required conditions
ContinuousIntegration / linux (push) Waiting to run
ContinuousIntegration / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Waiting to run
ContinuousIntegration / android (map[ndk_abi:armeabi-v7a vcpkg_toolkit:arm-neon-android]) (push) Waiting to run
ContinuousIntegration / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Waiting to run
ContinuousIntegration / macos (push) Waiting to run
ContinuousIntegration / windows (push) Waiting to run

This commit is contained in:
Green Sky 2024-12-22 15:31:54 +01:00
parent ac951b2afa
commit 586b49f4a8
No known key found for this signature in database

View File

@ -85,6 +85,7 @@ struct DebugVideoTapSink : public FrameStream2SinkI<SDLVideoFrame> {
}; };
struct DebugVideoTestSource : public FrameStream2SourceI<SDLVideoFrame> { struct DebugVideoTestSource : public FrameStream2SourceI<SDLVideoFrame> {
std::mutex _readers_mutex;
std::vector<std::shared_ptr<LockedFrameStream2<SDLVideoFrame>>> _readers; std::vector<std::shared_ptr<LockedFrameStream2<SDLVideoFrame>>> _readers;
std::atomic_bool _stop {false}; std::atomic_bool _stop {false};
@ -94,6 +95,9 @@ struct DebugVideoTestSource : public FrameStream2SourceI<SDLVideoFrame> {
std::cout << "DVTS: starting new test video source\n"; std::cout << "DVTS: starting new test video source\n";
_thread = std::thread([this](void) { _thread = std::thread([this](void) {
while (!_stop) { while (!_stop) {
std::this_thread::sleep_for(std::chrono::milliseconds(50));
std::lock_guard lg{_readers_mutex};
if (!_readers.empty()) { if (!_readers.empty()) {
auto* surf = SDL_CreateSurface(960, 720, SDL_PIXELFORMAT_RGBA32); auto* surf = SDL_CreateSurface(960, 720, SDL_PIXELFORMAT_RGBA32);
@ -113,8 +117,6 @@ struct DebugVideoTestSource : public FrameStream2SourceI<SDLVideoFrame> {
SDL_DestroySurface(surf); SDL_DestroySurface(surf);
} }
std::this_thread::sleep_for(std::chrono::milliseconds(50));
} }
}); });
} }
@ -124,10 +126,12 @@ struct DebugVideoTestSource : public FrameStream2SourceI<SDLVideoFrame> {
} }
std::shared_ptr<FrameStream2I<SDLVideoFrame>> subscribe(void) override { std::shared_ptr<FrameStream2I<SDLVideoFrame>> subscribe(void) override {
std::lock_guard lg{_readers_mutex};
return _readers.emplace_back(std::make_shared<LockedFrameStream2<SDLVideoFrame>>()); return _readers.emplace_back(std::make_shared<LockedFrameStream2<SDLVideoFrame>>());
} }
bool unsubscribe(const std::shared_ptr<FrameStream2I<SDLVideoFrame>>& sub) override { bool unsubscribe(const std::shared_ptr<FrameStream2I<SDLVideoFrame>>& sub) override {
std::lock_guard lg{_readers_mutex};
for (auto it = _readers.cbegin(); it != _readers.cend(); it++) { for (auto it = _readers.cbegin(); it != _readers.cend(); it++) {
if (it->get() == sub.get()) { if (it->get() == sub.get()) {
_readers.erase(it); _readers.erase(it);