Skip to content

Commit

Permalink
Implemented basic prototype of record functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
asahtik committed Jan 10, 2024
1 parent 6e6a094 commit beaee9e
Show file tree
Hide file tree
Showing 19 changed files with 409 additions and 3 deletions.
59 changes: 59 additions & 0 deletions include/depthai/common/CameraBoardSocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,62 @@ inline std::ostream& operator<<(std::ostream& out, const dai::CameraBoardSocket&
}
return out;
}

namespace dai {

inline std::string toString(CameraBoardSocket socket) {
switch(socket) {
case CameraBoardSocket::AUTO:
return "AUTO";
case CameraBoardSocket::CAM_A:
return "CAM_A";
case CameraBoardSocket::CAM_B:
return "CAM_B";
case CameraBoardSocket::CAM_C:
return "CAM_C";
case CameraBoardSocket::CAM_D:
return "CAM_D";
case CameraBoardSocket::CAM_E:
return "CAM_E";
case CameraBoardSocket::CAM_F:
return "CAM_F";
case CameraBoardSocket::CAM_G:
return "CAM_G";
case CameraBoardSocket::CAM_H:
return "CAM_H";
case CameraBoardSocket::CAM_I:
return "CAM_I";
case CameraBoardSocket::CAM_J:
return "CAM_J";
default:
return "UNKNOWN";
}
}

inline CameraBoardSocket fromString(const std::string& socket) {
if(socket == "CAM_A") {
return CameraBoardSocket::CAM_A;
} else if(socket == "CAM_B") {
return CameraBoardSocket::CAM_B;
} else if(socket == "CAM_C") {
return CameraBoardSocket::CAM_C;
} else if(socket == "CAM_D") {
return CameraBoardSocket::CAM_D;
} else if(socket == "CAM_E") {
return CameraBoardSocket::CAM_E;
} else if(socket == "CAM_F") {
return CameraBoardSocket::CAM_F;
} else if(socket == "CAM_G") {
return CameraBoardSocket::CAM_G;
} else if(socket == "CAM_H") {
return CameraBoardSocket::CAM_H;
} else if(socket == "CAM_I") {
return CameraBoardSocket::CAM_I;
} else if(socket == "CAM_J") {
return CameraBoardSocket::CAM_J;
} else {
return CameraBoardSocket::AUTO;
}
}

} // namespace dai
21 changes: 21 additions & 0 deletions include/depthai/device/Device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,27 @@
#include <mutex>
#include <string>
#include <unordered_map>
#include <utility>
#include <fstream>

// project
#include "DataQueue.hpp"
#include "depthai/device/DeviceBase.hpp"

namespace dai {


namespace rr {
struct RecordStream {
dai::Path path;
std::shared_ptr<DataOutputQueue> queue;
std::ofstream file;
std::unique_ptr<std::thread> thread;
std::atomic<bool> running {false};
};
}


/**
* Represents the DepthAI device with the methods to interact with it.
* Implements the host-side queues to connect with XLinkIn and XLinkOut nodes
Expand Down Expand Up @@ -222,6 +237,12 @@ class Device : public DeviceBase {
std::condition_variable eventCv;
std::deque<std::string> eventQueue;

// Record & Replay
enum class RecordReplayState { NONE, RECORD, REPLAY };

RecordReplayState recordReplayState = RecordReplayState::NONE;
std::unordered_map<std::string, rr::RecordStream> recordStreams;

bool startPipelineImpl(const Pipeline& pipeline) override;
void closeImpl() override;
};
Expand Down
4 changes: 4 additions & 0 deletions include/depthai/device/DeviceBase.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

// std
#include <spdlog/logger.h>
#include <atomic>
#include <chrono>
#include <condition_variable>
Expand Down Expand Up @@ -921,6 +922,8 @@ class DeviceBase {
void init(Config config, const DeviceInfo& devInfo, UsbSpeed maxUsbSpeed);
void init(Config config, const DeviceInfo& devInfo, const dai::Path& pathToCmd);

spdlog::logger& getLogger();

private:
// private functions
void init2(Config cfg, const dai::Path& pathToMvcmd, tl::optional<const Pipeline&> pipeline);
Expand Down Expand Up @@ -968,5 +971,6 @@ class DeviceBase {

dai::Path firmwarePath;
bool dumpOnly = false;

};
} // namespace dai
6 changes: 6 additions & 0 deletions include/depthai/pipeline/Node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class PipelineImpl;
class Node {
friend class Pipeline;
friend class PipelineImpl;
friend class Device;

public:
/// Node identificator. Unique for every node on a single Pipeline
Expand Down Expand Up @@ -57,6 +58,11 @@ class Node {
void setInputMapRefs(std::initializer_list<InputMap*> l);
void setInputMapRefs(InputMap* inMapRef);

virtual bool isSourceNode() const;
virtual std::string getNodeRecordName() const;
virtual Output& getRecordOutput();
virtual Input& getReplayInput();

public:
struct DatatypeHierarchy {
DatatypeHierarchy(DatatypeEnum d, bool c) : datatype(d), descendants(c) {}
Expand Down
14 changes: 14 additions & 0 deletions include/depthai/pipeline/Pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Node.hpp"
#include "depthai/device/CalibrationHandler.hpp"
#include "depthai/device/Device.hpp"
#include "depthai/device/DeviceBase.hpp"
#include "depthai/openvino/OpenVINO.hpp"

// shared
Expand All @@ -24,6 +25,11 @@ class PipelineImpl {
friend class Pipeline;
friend class Node;

protected:
enum class RecordAndReplay {NONE, RECORD, REPLAY};
RecordAndReplay recordAndReplay = RecordAndReplay::NONE;
std::string recordAndReplayPath;

public:
PipelineImpl() = default;
PipelineImpl(const PipelineImpl&) = default;
Expand Down Expand Up @@ -51,6 +57,7 @@ class PipelineImpl {
std::vector<std::shared_ptr<Node>> getAllNodes();
std::shared_ptr<const Node> getNode(Node::Id id) const;
std::shared_ptr<Node> getNode(Node::Id id);
std::vector<std::shared_ptr<Node>> getSourceNodes();

void serialize(PipelineSchema& schema, Assets& assets, std::vector<std::uint8_t>& assetStorage, SerializationType type = DEFAULT_SERIALIZATION_TYPE) const;
nlohmann::json serializeToJson() const;
Expand Down Expand Up @@ -98,6 +105,8 @@ class PipelineImpl {
* @brief Represents the pipeline, set of nodes and connections between them
*/
class Pipeline {
friend class Device;

std::shared_ptr<PipelineImpl> pimpl;
PipelineImpl* impl() {
return pimpl.get();
Expand All @@ -106,6 +115,11 @@ class Pipeline {
return pimpl.get();
}

protected:
std::vector<std::shared_ptr<Node>> getSourceNodes() {
return impl()->getSourceNodes();
}

public:
/**
* Constructs a new pipeline
Expand Down
4 changes: 4 additions & 0 deletions include/depthai/pipeline/node/Camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class Camera : public NodeCRTP<Node, Camera, CameraProperties> {

protected:
Properties& getProperties();
bool isSourceNode() const override;
std::string getNodeRecordName() const override;
Output& getRecordOutput() override;
Input& getReplayInput() override;

private:
std::shared_ptr<RawCameraControl> rawControl;
Expand Down
4 changes: 4 additions & 0 deletions include/depthai/pipeline/node/ColorCamera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class ColorCamera : public NodeCRTP<Node, ColorCamera, ColorCameraProperties> {

protected:
Properties& getProperties();
bool isSourceNode() const override;
std::string getNodeRecordName() const override;
Output& getRecordOutput() override;
Input& getReplayInput() override;

private:
std::shared_ptr<RawCameraControl> rawControl;
Expand Down
6 changes: 6 additions & 0 deletions include/depthai/pipeline/node/IMU.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ namespace node {
* @brief IMU node for BNO08X.
*/
class IMU : public NodeCRTP<Node, IMU, IMUProperties> {
protected:
bool isSourceNode() const override;
std::string getNodeRecordName() const override;
Output& getRecordOutput() override;
Input& getReplayInput() override;

public:
constexpr static const char* NAME = "IMU";

Expand Down
4 changes: 4 additions & 0 deletions include/depthai/pipeline/node/MonoCamera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class MonoCamera : public NodeCRTP<Node, MonoCamera, MonoCameraProperties> {

protected:
Properties& getProperties();
bool isSourceNode() const override;
std::string getNodeRecordName() const override;
Output& getRecordOutput() override;
Input& getReplayInput() override;

public:
MonoCamera(const std::shared_ptr<PipelineImpl>& par, int64_t nodeId);
Expand Down
Loading

0 comments on commit beaee9e

Please sign in to comment.