#include #include #include #include #include snd_config_t *conf_copy; static int snd_pcm_hook_testhook_hw_params(snd_pcm_hook_t *hook) { const char *str; snd_config_t *h = snd_pcm_hook_get_private(hook); snd_config_t *s; snd_config_search(h, "hw", &s); snd_config_get_string(s, &str); fprintf(stderr, "testhook: hw_params, %s\n", str); return 0; } static int snd_pcm_hook_testhook_hw_free(snd_pcm_hook_t *hook) { const char *str; snd_config_t *h = snd_pcm_hook_get_private(hook); snd_config_t *s; snd_config_search(h, "close", &s); snd_config_get_string(s, &str); fprintf(stderr, "testhook: hw_free, %s\n", str); return 0; } static int snd_pcm_hook_testhook_close(snd_pcm_hook_t *hook) { fprintf(stderr, "testhook: close\n"); return 0; } int _snd_pcm_hook_testhook_install(snd_pcm_t *pcm, snd_config_t *conf) { int err; snd_pcm_hook_t *h_hw_params = NULL, *h_hw_free = NULL, *h_close = NULL; snd_config_copy(&conf_copy, conf); // dlopen("testhook.so", RTLD_NOW); err = snd_pcm_hook_add(&h_hw_params, pcm, SND_PCM_HOOK_TYPE_HW_PARAMS, snd_pcm_hook_testhook_hw_params, conf_copy); if (err < 0) goto _err; err = snd_pcm_hook_add(&h_hw_free, pcm, SND_PCM_HOOK_TYPE_HW_FREE, snd_pcm_hook_testhook_hw_free, conf_copy); if (err < 0) goto _err; err = snd_pcm_hook_add(&h_close, pcm, SND_PCM_HOOK_TYPE_CLOSE, snd_pcm_hook_testhook_close, NULL); return 0; _err: if (h_hw_params) snd_pcm_hook_remove(h_hw_params); if (h_hw_free) snd_pcm_hook_remove(h_hw_free); if (h_close) snd_pcm_hook_remove(h_close); return err; } SND_DLSYM_BUILD_VERSION(_snd_pcm_hook_testhook_install, SND_PCM_DLSYM_VERSION);