MCPcopy Create free account
hub / github.com/ClassicOldSong/Apollo / captureThread

Function captureThread

src/video.cpp:1141–1405  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1139 }
1140
1141 void captureThread(
1142 std::shared_ptr<safe::queue_t<capture_ctx_t>> capture_ctx_queue,
1143 sync_util::sync_t<std::weak_ptr<platf::display_t>> &display_wp,
1144 safe::signal_t &reinit_event,
1145 const encoder_t &encoder
1146 ) {
1147 std::vector<capture_ctx_t> capture_ctxs;
1148
1149 auto fg = util::fail_guard([&]() {
1150 capture_ctx_queue->stop();
1151
1152 // Stop all sessions listening to this thread
1153 for (auto &capture_ctx : capture_ctxs) {
1154 capture_ctx.images->stop();
1155 }
1156 for (auto &capture_ctx : capture_ctx_queue->unsafe()) {
1157 capture_ctx.images->stop();
1158 }
1159 });
1160
1161 auto switch_display_event = mail::man->event<int>(mail::switch_display);
1162
1163 // Wait for the initial capture context or a request to stop the queue
1164 auto initial_capture_ctx = capture_ctx_queue->pop();
1165 if (!initial_capture_ctx) {
1166 return;
1167 }
1168 capture_ctxs.emplace_back(std::move(*initial_capture_ctx));
1169
1170 std::vector<std::string> display_names;
1171 int display_p = -1;
1172 std::shared_ptr<platf::display_t> disp;
1173 if (!proc::proc.display_name.empty()) {
1174 disp = platf::display(encoder.platform_formats->dev_type, proc::proc.display_name, capture_ctxs.front().config);
1175 }
1176 if (!disp) {
1177 // Get all the monitor names now, rather than at boot, to
1178 // get the most up-to-date list available monitors
1179 refresh_displays(encoder.platform_formats->dev_type, display_names, display_p);
1180 disp = platf::display(encoder.platform_formats->dev_type, display_names[display_p], capture_ctxs.front().config);
1181 if (disp) {
1182 proc::proc.display_name = display_names[display_p];
1183 } else {
1184 return;
1185 }
1186 }
1187
1188 display_wp = disp;
1189
1190 constexpr auto capture_buffer_size = 12;
1191 std::list<std::shared_ptr<platf::img_t>> imgs(capture_buffer_size);
1192
1193 std::vector<std::optional<std::chrono::steady_clock::time_point>> imgs_used_timestamps;
1194 const std::chrono::seconds trim_timeot = 3s;
1195 auto trim_imgs = [&]() {
1196 // count allocated and used within current pool
1197 size_t allocated_count = 0;
1198 size_t used_count = 0;

Callers

nothing calls this directly

Calls 15

fail_guardFunction · 0.85
moveFunction · 0.85
refresh_displaysFunction · 0.85
clampFunction · 0.85
reset_displayFunction · 0.85
displayFunction · 0.50
adjust_thread_priorityFunction · 0.50
stopMethod · 0.45
popMethod · 0.45
sizeMethod · 0.45
resetMethod · 0.45
runningMethod · 0.45

Tested by

no test coverage detected