MCPcopy Create free account
hub / github.com/brainflow-dev/brainflow / start_stream

Method start_stream

src/board_controller/dyn_lib_board.cpp:61–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59}
60
61int DynLibBoard::start_stream (int buffer_size, const char *streamer_params)
62{
63 if (is_streaming)
64 {
65 safe_logger (spdlog::level::err, "Streaming thread already running");
66 return (int)BrainFlowExitCodes::STREAM_ALREADY_RUN_ERROR;
67 }
68 if (buffer_size <= 0 || buffer_size > MAX_CAPTURE_SAMPLES)
69 {
70 safe_logger (spdlog::level::err, "invalid array size");
71 return (int)BrainFlowExitCodes::INVALID_BUFFER_SIZE_ERROR;
72 }
73
74 int res = prepare_for_acquisition (buffer_size, streamer_params);
75 if (res != (int)BrainFlowExitCodes::STATUS_OK)
76 {
77 return res;
78 }
79
80 res = call_start ();
81 if (res != (int)BrainFlowExitCodes::STATUS_OK)
82 {
83 return res;
84 }
85
86 keep_alive = true;
87 streaming_thread = std::thread ([this] { read_thread (); });
88
89 // wait for data to ensure that everything is okay
90 std::unique_lock<std::mutex> lk (m);
91 auto sec = std::chrono::seconds (1);
92 if (cv.wait_for (lk, params.timeout * sec,
93 [this] { return state != (int)BrainFlowExitCodes::SYNC_TIMEOUT_ERROR; }))
94 {
95 is_streaming = true;
96 return state;
97 }
98 else
99 {
100 safe_logger (
101 spdlog::level::err, "no data received in {} sec, stopping thread", params.timeout);
102 is_streaming = true;
103 stop_stream ();
104 return (int)BrainFlowExitCodes::SYNC_TIMEOUT_ERROR;
105 }
106}
107
108int DynLibBoard::stop_stream ()
109{

Callers

nothing calls this directly

Calls 1

stop_streamFunction · 0.70

Tested by

no test coverage detected