| 348 | } // namespace |
| 349 | |
| 350 | VirtualCameraCapture::VirtualCameraCapture( |
| 351 | int w, |
| 352 | int h, |
| 353 | const std::string& cameraName, |
| 354 | int captureFps, |
| 355 | bool verbose) |
| 356 | : targetWidth_(w) |
| 357 | , targetHeight_(h) |
| 358 | , selectedCameraName_(cameraName) |
| 359 | , captureFps_(captureFps) |
| 360 | , verbose_(verbose) |
| 361 | { |
| 362 | auto candidates = GetCameraCandidates(false); |
| 363 | if (candidates.empty()) |
| 364 | candidates = GetCameraCandidates(true); |
| 365 | |
| 366 | if (candidates.empty()) |
| 367 | { |
| 368 | throw std::runtime_error("[VirtualCamera] No camera devices found"); |
| 369 | } |
| 370 | |
| 371 | const std::string requestedName = selectedCameraName_; |
| 372 | if (!requestedName.empty() && OtherTools::ToLowerAscii(OtherTools::TrimAscii(requestedName)) != "none") |
| 373 | { |
| 374 | int exact = FindExactNameMatch(candidates, requestedName); |
| 375 | int partial = (exact >= 0) ? exact : FindPartialNameMatch(candidates, requestedName); |
| 376 | if (exact < 0 && partial < 0) |
| 377 | { |
| 378 | std::cerr << "[VirtualCamera] Requested camera not found: " << requestedName |
| 379 | << ". Will use fallback search." << std::endl; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | cap_ = std::make_unique<cv::VideoCapture>(); |
| 384 | bool opened = false; |
| 385 | |
| 386 | auto openByOrder = [&](const std::vector<CameraCandidate>& list) -> bool |
| 387 | { |
| 388 | const auto order = BuildOpenOrder(list, requestedName); |
| 389 | for (int idx : order) |
| 390 | { |
| 391 | if (idx < 0 || idx >= static_cast<int>(list.size())) |
| 392 | continue; |
| 393 | |
| 394 | if (TryOpenCandidate(list[idx], *cap_, verbose_)) |
| 395 | { |
| 396 | selectedCameraName_ = list[idx].displayName; |
| 397 | return true; |
| 398 | } |
| 399 | } |
| 400 | return false; |
| 401 | }; |
| 402 | |
| 403 | opened = openByOrder(candidates); |
| 404 | if (!opened) |
| 405 | { |
| 406 | candidates = GetCameraCandidates(true); |
| 407 | opened = openByOrder(candidates); |
nothing calls this directly
no test coverage detected