std::shared_ptr<UsbCamera> UsbHandler::open_camera (std::string serial_number) { auto list = get_device_list(); device_info d; for (auto& dev : list) { // std::cout << "Comparing |" << dev.serial << "|" << (unsigned char*)serial_number.c_str() << "|" << std::endl; if (serial_number.compare(dev.serial) == 0) { // std::cout << "dev.serial " << dev.serial << ";serial " << serial_number << std::endl; d = dev; break; } } camera_type t = find_camera_type(d.idVendor, d.idProduct); switch(t.camera_type) { case USB3: return std::make_shared<Usb3Camera>(this->session, d); case USB2: return std::make_shared<Usb2Camera>(this->session, d); default: return nullptr; } }
void WINAPI GetPluginInfoW(PluginInfo* info) { info->StructSize = sizeof(PluginInfo); ObjectArray<DeviceInfo> dev_list; try { init_if_needed(); get_device_list(dev_list); } catch (...) { dev_list.clear(); } if (dev_list.size() == 0) { if (g_plugin_options.last_dev_type == dtPDA) disk_menu[0] = far_msg_ptr(MSG_DISK_MENU_PDA); else if (g_plugin_options.last_dev_type == dtSmartPhone) disk_menu[0] = far_msg_ptr(MSG_DISK_MENU_SMARTPHONE); else disk_menu[0] = far_msg_ptr(MSG_DISK_MENU_PDA); } else { if (dev_list[0].platform == L"PocketPC") { disk_menu[0] = far_msg_ptr(MSG_DISK_MENU_PDA); g_plugin_options.last_dev_type = dtPDA; } else if (dev_list[0].platform == L"SmartPhone") { disk_menu[0] = far_msg_ptr(MSG_DISK_MENU_SMARTPHONE); g_plugin_options.last_dev_type = dtSmartPhone; } else { disk_menu[0] = far_msg_ptr(MSG_DISK_MENU_PDA); g_plugin_options.last_dev_type = dtPDA; } save_plugin_options(g_plugin_options); } if (g_plugin_options.add_to_disk_menu) { info->DiskMenu.Strings = disk_menu; info->DiskMenu.Guids = &c_disk_menu_guid; info->DiskMenu.Count = ARRAYSIZE(disk_menu); } if (g_plugin_options.add_to_plugin_menu) { plugin_menu[0] = far_msg_ptr(MSG_PLUGIN_NAME); info->PluginMenu.Strings = plugin_menu; info->PluginMenu.Guids = &c_plugin_menu_guid; info->PluginMenu.Count = ARRAYSIZE(plugin_menu); } config_menu[0] = far_msg_ptr(MSG_PLUGIN_NAME); info->PluginConfig.Strings = config_menu; info->PluginConfig.Guids = &c_config_menu_guid; info->PluginConfig.Count = ARRAYSIZE(config_menu); info->CommandPrefix = g_plugin_format.data(); }
cl_int compile_program(cl_uint *num_devices_out, const char *src, size_t src_size, cl_platform_id platform, cl_uint platform_idx) { cl_int err = CL_SUCCESS; // Get the device list cl_device_id* devices = NULL; cl_uint num_devices = 0; get_device_list(&devices, &num_devices, platform); *num_devices_out = num_devices; // Create context cl_context_properties ctx_properties[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)platform, 0 }; cl_context ctx = clCreateContext(ctx_properties, num_devices, devices, NULL, NULL, &err); if (err != CL_SUCCESS) { goto cleanup; } // Create program cl_program program = clCreateProgramWithSource(ctx, 1, &src, &src_size, &err); if (err != CL_SUCCESS) { goto cleanup; } // Compile program err = clBuildProgram(program, num_devices, devices, NULL, NULL, NULL); if (err != CL_SUCCESS) { goto cleanup_program; } // Write the binaries write_binaries(program, num_devices, platform_idx); cleanup_program: // Free the built program clReleaseProgram(program); cleanup: // Free the device list free_device_list(devices, num_devices); return err; }
static void get_default_adapter_cb (DBusPendingCall *pending, void *user_data) { DBusMessage *reply = NULL; gchar *result = NULL; OHM_DEBUG(DBG_BT, "> get_default_adapter_cb\n"); (void) user_data; if (pending == NULL) goto error; reply = dbus_pending_call_steal_reply(pending); dbus_pending_call_unref(pending); pending = NULL; if (reply == NULL) { goto error; } if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { goto error; } if (!dbus_message_get_args (reply, NULL, DBUS_TYPE_OBJECT_PATH, &result, DBUS_TYPE_INVALID)) { goto error; } /* ok, then ask the adapter (whose object path we now know) about * the listed devices */ if (!get_device_list(result)) { goto error; } return; error: if (reply) dbus_message_unref (reply); return; }
int get_current_network_device() { char *dev_list[30]; int i = 0, state, type, num_of_dev = 0; /* Get the list of available interfaces for the given system. * This function would give the object path of the devices */ num_of_dev = get_device_list(conn, dev_list); /* For each given object path get the current state */ for (i = 0; i < num_of_dev; i++) { state = get_device_state(conn, dev_list[i]); if (state == ACTIVE) { /* If the state is connected then get the type of the device * corresponding to the object path */ get_device_properties(conn, dev_list[i], &type); return type; } } }
static device_list list( void ) { return get_device_list(2151); }
Error AudioDriverALSA::init_device() { mix_rate = GLOBAL_DEF("audio/mix_rate", DEFAULT_MIX_RATE); speaker_mode = SPEAKER_MODE_STEREO; channels = 2; // If there is a specified device check that it is really present if (device_name != "Default") { Array list = get_device_list(); if (list.find(device_name) == -1) { device_name = "Default"; new_device = "Default"; } } int status; snd_pcm_hw_params_t *hwparams; snd_pcm_sw_params_t *swparams; #define CHECK_FAIL(m_cond) \ if (m_cond) { \ fprintf(stderr, "ALSA ERR: %s\n", snd_strerror(status)); \ if (pcm_handle) { \ snd_pcm_close(pcm_handle); \ pcm_handle = NULL; \ } \ ERR_FAIL_COND_V(m_cond, ERR_CANT_OPEN); \ } //todo, add //6 chans - "plug:surround51" //4 chans - "plug:surround40"; if (device_name == "Default") { status = snd_pcm_open(&pcm_handle, "default", SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK); } else { String device = device_name; int pos = device.find(";"); if (pos != -1) { device = device.substr(0, pos); } status = snd_pcm_open(&pcm_handle, device.utf8().get_data(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK); } ERR_FAIL_COND_V(status < 0, ERR_CANT_OPEN); snd_pcm_hw_params_alloca(&hwparams); status = snd_pcm_hw_params_any(pcm_handle, hwparams); CHECK_FAIL(status < 0); status = snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED); CHECK_FAIL(status < 0); //not interested in anything else status = snd_pcm_hw_params_set_format(pcm_handle, hwparams, SND_PCM_FORMAT_S16_LE); CHECK_FAIL(status < 0); //todo: support 4 and 6 status = snd_pcm_hw_params_set_channels(pcm_handle, hwparams, 2); CHECK_FAIL(status < 0); status = snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &mix_rate, NULL); CHECK_FAIL(status < 0); // In ALSA the period size seems to be the one that will determine the actual latency // Ref: https://www.alsa-project.org/main/index.php/FramesPeriods unsigned int periods = 2; int latency = GLOBAL_DEF("audio/output_latency", DEFAULT_OUTPUT_LATENCY); buffer_frames = closest_power_of_2(latency * mix_rate / 1000); buffer_size = buffer_frames * periods; period_size = buffer_frames; // set buffer size from project settings status = snd_pcm_hw_params_set_buffer_size_near(pcm_handle, hwparams, &buffer_size); CHECK_FAIL(status < 0); status = snd_pcm_hw_params_set_period_size_near(pcm_handle, hwparams, &period_size, NULL); CHECK_FAIL(status < 0); if (OS::get_singleton()->is_stdout_verbose()) { print_line("audio buffer frames: " + itos(period_size) + " calculated latency: " + itos(period_size * 1000 / mix_rate) + "ms"); } status = snd_pcm_hw_params_set_periods_near(pcm_handle, hwparams, &periods, NULL); CHECK_FAIL(status < 0); status = snd_pcm_hw_params(pcm_handle, hwparams); CHECK_FAIL(status < 0); //snd_pcm_hw_params_free(&hwparams); snd_pcm_sw_params_alloca(&swparams); status = snd_pcm_sw_params_current(pcm_handle, swparams); CHECK_FAIL(status < 0); status = snd_pcm_sw_params_set_avail_min(pcm_handle, swparams, period_size); CHECK_FAIL(status < 0); status = snd_pcm_sw_params_set_start_threshold(pcm_handle, swparams, 1); CHECK_FAIL(status < 0); status = snd_pcm_sw_params(pcm_handle, swparams); CHECK_FAIL(status < 0); samples_in.resize(period_size * channels); samples_out.resize(period_size * channels); return OK; }
static int devices_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data) { int len = get_device_list(page); return proc_calc_metrics(page, start, off, count, eof, len); }
static int get_root_array(char * page, int type, char **start, off_t offset, int length) { switch (type) { case PROC_LOADAVG: return get_loadavg(page); case PROC_UPTIME: return get_uptime(page); case PROC_MEMINFO: return get_meminfo(page); #ifdef CONFIG_PCI case PROC_PCI: return get_pci_list(page); #endif case PROC_CPUINFO: return get_cpuinfo(page); case PROC_VERSION: return get_version(page); #ifdef CONFIG_DEBUG_MALLOC case PROC_MALLOC: return get_malloc(page); #endif #ifdef CONFIG_MODULES case PROC_MODULES: return get_module_list(page); case PROC_KSYMS: return get_ksyms_list(page, start, offset, length); #endif case PROC_STAT: return get_kstat(page); case PROC_DEVICES: return get_device_list(page); case PROC_INTERRUPTS: return get_irq_list(page); case PROC_FILESYSTEMS: return get_filesystem_list(page); case PROC_DMA: return get_dma_list(page); case PROC_IOPORTS: return get_ioport_list(page); #ifdef CONFIG_BLK_DEV_MD case PROC_MD: return get_md_status(page); #endif #ifdef __SMP_PROF__ case PROC_SMP_PROF: return get_smp_prof_list(page); #endif case PROC_CMDLINE: return get_cmdline(page); case PROC_MTAB: return get_filesystem_info( page ); #ifdef CONFIG_RTC case PROC_RTC: return get_rtc_status(page); #endif case PROC_LOCKS: return get_locks_status(page); } return -EBADF; }
static device_list list( void ) { return get_device_list(2820); }
HANDLE WINAPI OpenW(const OpenInfo* info) { try { if (info->OpenFrom == OPEN_COMMANDLINE) { // test if plugin is already open on active panel for (unsigned i = 0; i < g_plugin_objects.size(); i++) { PanelInfo pi; if (far_control_ptr(g_plugin_objects[i], FCTL_GETPANELINFO, &pi)) { if (pi.Flags & PFLAGS_FOCUS) { // change current directory of active plugin set_dir(g_plugin_objects[i], reinterpret_cast<OpenCommandLineInfo*>(info->Data)->CommandLine, true); far_control_int(INVALID_HANDLE_VALUE, FCTL_UPDATEPANEL, 0); PanelRedrawInfo pri = { sizeof(PanelRedrawInfo) }; pri.CurrentItem = 0; pri.TopPanelItem = 0; far_control_ptr(INVALID_HANDLE_VALUE, FCTL_REDRAWPANEL, &pri); // do not create new plugin instance return nullptr; } } } } init_if_needed(); ObjectArray<DeviceInfo> dev_list; get_device_list(dev_list); if (dev_list.size() == 0) FAIL(MsgError(far_get_msg(MSG_ERR_NO_DEVICE))); intptr_t mi = 0; if (dev_list.size() > 1) { ObjectArray<UnicodeString> menu_str; for (unsigned i = 0; i < dev_list.size(); i++) { menu_str += UnicodeString::format(L"%S %S (%S)", &dev_list[i].name, &dev_list[i].platform, &dev_list[i].con_type); } mi = far_menu(c_device_list_menu_guid, far_get_msg(MSG_DEVICE_LIST_TITLE), menu_str); if (mi == -1) BREAK; } PluginInstance* plugin = new PluginInstance(); try { plugin->device_info = dev_list[mi]; create_session(plugin->device_info.id, plugin); if (info->OpenFrom == OPEN_COMMANDLINE) { // directory is specified on command line plugin->current_dir = reinterpret_cast<OpenCommandLineInfo*>(info->Data)->CommandLine; if (!dir_exists(plugin->current_dir, plugin->session)) plugin->current_dir = L"\\"; } else if (g_plugin_options.save_last_dir) { // restore last directory plugin->current_dir = load_last_dir(plugin->device_info.strid()); if (!dir_exists(plugin->current_dir, plugin->session)) plugin->current_dir = L"\\"; } else { plugin->current_dir = L"\\"; } NOFAIL(refresh_system_info(plugin)); g_plugin_objects += plugin; } catch (...) { delete plugin; throw; } return plugin; } catch (Break&) { } catch (MsgError& e) { msg_dlg(e.message()); } catch (Error& e) { LOG_ERR(e); error_dlg(e, far_get_msg(MSG_ERR_PLUGIN_INIT)); } catch (...) { far_message(c_error_dialog_guid, L"\nFailure!", 0, FMSG_WARNING | FMSG_MB_OK); } return nullptr; }
Error AudioDriverPulseAudio::init_device() { // If there is a specified device check that it is really present if (device_name != "Default") { Array list = get_device_list(); if (list.find(device_name) == -1) { device_name = "Default"; new_device = "Default"; } } // Detect the amount of channels PulseAudio is using // Note: If using an even amount of channels (2, 4, etc) channels and pa_map.channels will be equal, // if not then pa_map.channels will have the real amount of channels PulseAudio is using and channels // will have the amount of channels Godot is using (in this case it's pa_map.channels + 1) detect_channels(); switch (pa_map.channels) { case 1: // Mono case 3: // Surround 2.1 case 5: // Surround 5.0 case 7: // Surround 7.0 channels = pa_map.channels + 1; break; case 2: // Stereo case 4: // Surround 4.0 case 6: // Surround 5.1 case 8: // Surround 7.1 channels = pa_map.channels; break; default: WARN_PRINTS("PulseAudio: Unsupported number of channels: " + itos(pa_map.channels)); pa_channel_map_init_stereo(&pa_map); channels = 2; break; } int latency = GLOBAL_DEF_RST("audio/output_latency", DEFAULT_OUTPUT_LATENCY); buffer_frames = closest_power_of_2(latency * mix_rate / 1000); pa_buffer_size = buffer_frames * pa_map.channels; print_verbose("PulseAudio: detected " + itos(pa_map.channels) + " channels"); print_verbose("PulseAudio: audio buffer frames: " + itos(buffer_frames) + " calculated latency: " + itos(buffer_frames * 1000 / mix_rate) + "ms"); pa_sample_spec spec; spec.format = PA_SAMPLE_S16LE; spec.channels = pa_map.channels; spec.rate = mix_rate; pa_str = pa_stream_new(pa_ctx, "Sound", &spec, &pa_map); if (pa_str == NULL) { ERR_PRINTS("PulseAudio: pa_stream_new error: " + String(pa_strerror(pa_context_errno(pa_ctx)))); ERR_FAIL_V(ERR_CANT_OPEN); } pa_buffer_attr attr; // set to appropriate buffer length (in bytes) from global settings // Note: PulseAudio defaults to 4 fragments, which means that the actual // latency is tlength / fragments. It seems that the PulseAudio has no way // to get the fragments number so we're hardcoding this to the default of 4 const int fragments = 4; attr.tlength = pa_buffer_size * sizeof(int16_t) * fragments; // set them to be automatically chosen attr.prebuf = (uint32_t)-1; attr.maxlength = (uint32_t)-1; attr.minreq = (uint32_t)-1; const char *dev = device_name == "Default" ? NULL : device_name.utf8().get_data(); pa_stream_flags flags = pa_stream_flags(PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_ADJUST_LATENCY | PA_STREAM_AUTO_TIMING_UPDATE); int error_code = pa_stream_connect_playback(pa_str, dev, &attr, flags, NULL, NULL); ERR_FAIL_COND_V(error_code < 0, ERR_CANT_OPEN); samples_in.resize(buffer_frames * channels); samples_out.resize(pa_buffer_size); // Reset audio input to keep synchronisation. input_position = 0; input_size = 0; return OK; }