Persist rover observation configuration and calibrate Insta360 panorama
This commit is contained in:
@@ -24,8 +24,8 @@ constexpr size_t MAX_PACKET = 4 * 1024 * 1024;
|
||||
constexpr size_t MAX_QUEUE = 8 * 1024 * 1024;
|
||||
constexpr size_t MAX_RESULT = 60 * 1024;
|
||||
|
||||
std::string quote(const std::string& value) {
|
||||
if (value.size() > 1024) throw std::runtime_error("oversized SDK string");
|
||||
std::string quote(const std::string& value, size_t limit = 1024) {
|
||||
if (value.size() > limit) throw std::runtime_error("oversized SDK string");
|
||||
std::ostringstream out;
|
||||
out << '"';
|
||||
for (unsigned char c : value) {
|
||||
@@ -111,7 +111,7 @@ struct mc_x4 {
|
||||
std::shared_ptr<Camera> camera;
|
||||
std::shared_ptr<Frames> frames = std::make_shared<Frames>();
|
||||
std::shared_ptr<Notifications> notifications = std::make_shared<Notifications>();
|
||||
std::string firmware, result;
|
||||
std::string firmware, serial, calibration = "null", result;
|
||||
bool opened = false;
|
||||
int preview = 0;
|
||||
// Only the isolated worker calls control methods; callbacks use separate
|
||||
@@ -145,6 +145,8 @@ struct mc_x4 {
|
||||
}
|
||||
}
|
||||
std::string result = "{\"firmware\":" + quote(firmware) +
|
||||
",\"serial\":" + quote(serial) +
|
||||
",\"preview_calibration\":" + calibration +
|
||||
",\"connected\":" + (connected ? "true" : "false") +
|
||||
",\"preview\":" + std::to_string(preview) +
|
||||
",\"recording\":" + std::to_string(notifications->recording) +
|
||||
@@ -165,6 +167,30 @@ struct mc_x4 {
|
||||
return complete(result);
|
||||
}
|
||||
|
||||
void read_preview_calibration() {
|
||||
// Read-only metadata from this session's camera. A missing/unknown
|
||||
// calibration must not take down camera control or the raw lens feed.
|
||||
calibration = "null";
|
||||
try {
|
||||
auto param = camera->GetPreviewParam();
|
||||
const auto count = param.GetCalibrationCount();
|
||||
if (!count || count > 4) return;
|
||||
std::ostringstream out;
|
||||
out << "{\"offsets\":[";
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
if (i) out << ',';
|
||||
out << quote(param.GetCalibration(i), 8192);
|
||||
}
|
||||
out << "],\"crop\":{\"source_width\":" << param.GetCropSrcWidth()
|
||||
<< ",\"source_height\":" << param.GetCropSrcHeight()
|
||||
<< ",\"width\":" << param.GetCropDstWidth()
|
||||
<< ",\"height\":" << param.GetCropDstHeight()
|
||||
<< ",\"x\":" << param.GetCropOffsetX()
|
||||
<< ",\"y\":" << param.GetCropOffsetY() << "}}";
|
||||
calibration = out.str();
|
||||
} catch (...) { calibration = "null"; }
|
||||
}
|
||||
|
||||
std::string settings(CameraFunctionMode mode) {
|
||||
if (!mode_supported(mode)) return INVALID;
|
||||
if (!camera->SyncPhotographyOptions(mode)) return UNKNOWN;
|
||||
@@ -380,11 +406,13 @@ mc_x4* mc_x4_open(const char* serial, const char* log_directory) {
|
||||
const auto& device = handle->descriptors.front();
|
||||
if (device.camera_type != CameraType::Insta360X4 || device.info.connection_type != ConnectionType::USB || device.serial_number != serial) return nullptr;
|
||||
handle->firmware = device.fw_version;
|
||||
handle->serial = device.serial_number;
|
||||
handle->camera = std::make_shared<Camera>(device.info);
|
||||
handle->camera->SetServicePort(9099); // private network namespace per instance
|
||||
handle->camera->SetTimeout(10000);
|
||||
handle->opened = handle->camera->Open();
|
||||
if (!handle->opened) return nullptr;
|
||||
handle->read_preview_calibration();
|
||||
auto n = handle->notifications;
|
||||
handle->camera->SetCaptureStateNotification([n](bool active) {
|
||||
std::lock_guard<std::mutex> lock(n->mutex);
|
||||
|
||||
Reference in New Issue
Block a user