diff --git a/src/host.cpp b/src/host.cpp index b13b19cb5..36d94ab73 100644 --- a/src/host.cpp +++ b/src/host.cpp @@ -392,13 +392,27 @@ struct init_data *common_preinit(int argc, char *argv[]) } static void print_device(std::string_view purpose, std::string_view mod, const device_info& device){ - cout << "[capability][device] {" - "\"purpose\":" << std::quoted(purpose) << ", " - "\"module\":" << std::quoted(mod) << ", " - "\"device\":" << std::quoted(device.dev) << ", " - "\"name\":" << std::quoted(device.name) << ", " - "\"extra\": {" << device.extra << "}, " - "\"repeatable\":\"" << device.repeatable << "\"}\n"; + cout << "[capability][device] {" + "\"purpose\":" << std::quoted(purpose) << ", " + "\"module\":" << std::quoted(mod) << ", " + "\"device\":" << std::quoted(device.dev) << ", " + "\"name\":" << std::quoted(device.name) << ", " + "\"extra\": {" << device.extra << "}, " + "\"repeatable\":\"" << device.repeatable << "\", " + "\"modes\": ["; + + for(unsigned int j = 0; j < std::size(device.modes); j++) { + if (device.modes[j].id[0] == '\0') { // last item + break; + } + if (j > 0) { + printf(", "); + } + std::cout << "{\"name\":" << std::quoted(device.modes[j].name) << ", " + "\"opts\":" << device.modes[j].id << "}"; + } + + std::cout << "]}\n"; } void print_capabilities() @@ -469,7 +483,27 @@ void print_capabilities() // capturers cout << "[cap] Capturers:" << endl; - print_available_capturers(); + const auto & vidcaps = get_libraries_for_class(LIBRARY_CLASS_VIDEO_CAPTURE, VIDEO_CAPTURE_ABI_VERSION); + for (const auto& item : vidcaps) { + auto vci = static_cast(item.second); + + void (*deleter)(void *) = nullptr; + struct vidcap_type *vt = vci->probe(true, &deleter); + if (vt == nullptr) { + continue; + } + std::cout << "[cap][capture] " << item.first << "\n"; + + for (int i = 0; i < vt->card_count; ++i) { + print_device("video_cap", item.first, vt->cards[i]); + } + + if(!deleter) + deleter = free; + + deleter(vt->cards); + deleter(vt); + } // displays cout << "[cap] Displays:" << endl; diff --git a/src/video_capture.cpp b/src/video_capture.cpp index d44e7b361..010c08718 100644 --- a/src/video_capture.cpp +++ b/src/video_capture.cpp @@ -87,49 +87,6 @@ void list_video_capture_devices(bool full) list_modules(LIBRARY_CLASS_VIDEO_CAPTURE, VIDEO_CAPTURE_ABI_VERSION, full); } -void print_available_capturers() -{ - const auto & vidcaps = get_libraries_for_class(LIBRARY_CLASS_VIDEO_CAPTURE, VIDEO_CAPTURE_ABI_VERSION); - for (auto && item : vidcaps) { - auto vci = static_cast(item.second); - - void (*deleter)(void *) = nullptr; - struct vidcap_type *vt = vci->probe(true, &deleter); - if (vt == nullptr) { - continue; - } - std::cout << "[cap][capture] " << item.first << "\n"; - for (int i = 0; i < vt->card_count; ++i) { - std::cout << "[capability][device] {" - "\"purpose\":\"video_cap\", " - "\"module\":" << std::quoted(vt->name) << ", " - "\"device\":" << std::quoted(vt->cards[i].dev) << ", " - "\"name\":" << std::quoted(vt->cards[i].name) << ", " - "\"extra\": {" << vt->cards[i].extra << "}, " - "\"modes\": ["; - for (unsigned int j = 0; j < sizeof vt->cards[i].modes - / sizeof vt->cards[i].modes[0]; j++) { - if (vt->cards[i].modes[j].id[0] == '\0') { // last item - break; - } - if (j > 0) { - printf(", "); - } - std::cout << "{\"name\":" << std::quoted(vt->cards[i].modes[j].name) << ", " - "\"opts\":" << vt->cards[i].modes[j].id << "}"; - } - - std::cout << "]}\n"; - } - if(!deleter) - deleter = free; - - deleter(vt->cards); - deleter(vt); - - } -} - /** @brief Initializes video capture * @param[in] parent parent module * @param[in] param driver parameters diff --git a/src/video_capture.h b/src/video_capture.h index 7307e286d..0393b47ef 100644 --- a/src/video_capture.h +++ b/src/video_capture.h @@ -149,7 +149,6 @@ struct module; struct vidcap; void list_video_capture_devices(bool); -void print_available_capturers(void); int initialize_video_capture(struct module *parent, struct vidcap_params *params, struct vidcap **state);