2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2019-05-30 19:12:05 -07:00
|
|
|
|
2025-11-11 22:00:42 -08:00
|
|
|
#pragma once
|
2019-05-30 19:12:05 -07:00
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
|
#include <functional>
|
2021-06-06 16:13:58 -07:00
|
|
|
#include <string_view>
|
2019-05-30 19:12:05 -07:00
|
|
|
#include <thread>
|
|
|
|
|
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "Frame.hpp"
|
|
|
|
|
#include "SinkImpl.hpp"
|
|
|
|
|
#include "wpi/cs/cscore_raw.h"
|
2025-11-07 19:57:55 -05:00
|
|
|
#include "wpi/util/condition_variable.hpp"
|
2019-05-30 19:12:05 -07:00
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
namespace wpi::cs {
|
2025-11-11 22:00:42 -08:00
|
|
|
|
2019-05-30 19:12:05 -07:00
|
|
|
class SourceImpl;
|
|
|
|
|
|
|
|
|
|
class RawSinkImpl : public SinkImpl {
|
|
|
|
|
public:
|
2025-11-07 20:01:58 -05:00
|
|
|
RawSinkImpl(std::string_view name, wpi::util::Logger& logger,
|
|
|
|
|
Notifier& notifier, Telemetry& telemetry);
|
|
|
|
|
RawSinkImpl(std::string_view name, wpi::util::Logger& logger,
|
|
|
|
|
Notifier& notifier, Telemetry& telemetry,
|
2019-05-30 19:12:05 -07:00
|
|
|
std::function<void(uint64_t time)> processFrame);
|
|
|
|
|
~RawSinkImpl() override;
|
|
|
|
|
|
|
|
|
|
void Stop();
|
|
|
|
|
|
2023-11-23 13:55:10 -05:00
|
|
|
uint64_t GrabFrame(WPI_RawFrame& frame);
|
|
|
|
|
uint64_t GrabFrame(WPI_RawFrame& frame, double timeout);
|
2024-12-28 23:44:48 -05:00
|
|
|
// Wait for a frame with a time other than lastFrameTime
|
|
|
|
|
uint64_t GrabFrame(WPI_RawFrame& frame, double timeout,
|
|
|
|
|
uint64_t lastFrameTime);
|
2019-05-30 19:12:05 -07:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void ThreadMain();
|
|
|
|
|
|
2024-12-28 23:44:48 -05:00
|
|
|
// Copies the image from incomingFrame into rawFrame, converting where
|
|
|
|
|
// necessary to the resolution of rawFrame
|
2023-11-23 13:55:10 -05:00
|
|
|
uint64_t GrabFrameImpl(WPI_RawFrame& rawFrame, Frame& incomingFrame);
|
2019-05-30 19:12:05 -07:00
|
|
|
|
|
|
|
|
std::atomic_bool m_active; // set to false to terminate threads
|
|
|
|
|
std::thread m_thread;
|
|
|
|
|
std::function<void(uint64_t time)> m_processFrame;
|
|
|
|
|
};
|
|
|
|
|
|
2025-11-11 22:00:42 -08:00
|
|
|
} // namespace wpi::cs
|