snd_hctl_t* CALSAHControlMonitor::GetHandle(const std::string& ctlHandleName) { if (!m_ctlHandles.count(ctlHandleName)) { snd_hctl_t *hctl; if (snd_hctl_open(&hctl, ctlHandleName.c_str(), 0) != 0) { CLog::Log(LOGWARNING, "CALSAHControlMonitor::GetHandle - snd_hctl_open() failed for \"%s\"", ctlHandleName.c_str()); return NULL; } if (snd_hctl_load(hctl) != 0) { CLog::Log(LOGERROR, "CALSAHControlMonitor::GetHandle - snd_hctl_load() failed for \"%s\"", ctlHandleName.c_str()); snd_hctl_close(hctl); return NULL; } snd_hctl_nonblock(hctl, 1); m_ctlHandles[ctlHandleName] = CTLHandle(hctl); } m_ctlHandles[ctlHandleName].useCount++; return m_ctlHandles[ctlHandleName].handle; }
int phoneui_utils_sound_init_finish(GKeyFile *keyfile,char* suffix) { int err, f; char *device_name; char *alsa; static GSourceFuncs funcs = { _sourcefunc_prepare, _sourcefunc_check, _sourcefunc_dispatch, 0, 0, 0 }; alsa = malloc(strlen(suffix) + strlen("alsa") + 1); if (alsa) { strcpy(alsa, "alsa"); strcat(alsa, suffix); }else{ alsa = strdup("alsa"); g_warning("Malloc failure in %s at line %d",__func__,__LINE__); } sound_state = SOUND_STATE_IDLE; sound_state_type = SOUND_STATE_TYPE_DEFAULT; device_name = g_key_file_get_string(keyfile, alsa, "hardware_control_name", NULL); if (!device_name) { g_message("No hw control found, using default"); device_name = strdup("hw:0"); } if (hctl) { snd_hctl_close(hctl); } err = snd_hctl_open(&hctl, device_name, 0); if (err) { g_warning("Cannot open alsa:hardware_control_name '%s': %s", device_name, snd_strerror(err)); g_key_file_free(keyfile); return err; } err = snd_hctl_load(hctl); if (err) { g_warning("Cannot load alsa:hardware_control_name '%s': %s", device_name, snd_strerror(err)); } free(device_name); /*FIXME: add idle bt */ _phoneui_utils_sound_init_set_control(keyfile, "idle", suffix, SOUND_STATE_IDLE, SOUND_STATE_TYPE_HANDSET); _phoneui_utils_sound_init_set_control(keyfile, "bluetooth", suffix, SOUND_STATE_CALL, SOUND_STATE_TYPE_BLUETOOTH); _phoneui_utils_sound_init_set_control(keyfile, "handset", suffix, SOUND_STATE_CALL, SOUND_STATE_TYPE_HANDSET); _phoneui_utils_sound_init_set_control(keyfile, "headset", suffix, SOUND_STATE_CALL, SOUND_STATE_TYPE_HEADSET); _phoneui_utils_sound_init_set_control(keyfile, "speaker", suffix, SOUND_STATE_SPEAKER, SOUND_STATE_TYPE_HANDSET); snd_hctl_nonblock(hctl, 1); poll_fd_count = snd_hctl_poll_descriptors_count(hctl); poll_fds = malloc(sizeof(struct pollfd) * poll_fd_count); snd_hctl_poll_descriptors(hctl, poll_fds, poll_fd_count); source_alsa_poll = g_source_new(&funcs, sizeof(GSource)); for (f = 0; f < poll_fd_count; f++) { g_source_add_poll(source_alsa_poll, (GPollFD *)&poll_fds[f]); } g_source_attach(source_alsa_poll, NULL); /*Register for HEADPHONE insertion */ phoneui_info_register_input_events(_input_events_cb, NULL); fso_audio = (FreeSmartphoneDeviceAudio *)_fso (FREE_SMARTPHONE_DEVICE_TYPE_AUDIO_PROXY, FSO_FRAMEWORK_DEVICE_ServiceDBusName, FSO_FRAMEWORK_DEVICE_AudioServicePath, FSO_FRAMEWORK_DEVICE_AudioServiceFace); g_key_file_free(keyfile); return err; }