Advertisement
Guest User

jr

a guest
Sep 17th, 2009
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. /**
  2. * \file pcm/ACIhookexec.c
  3. * \ingroup PCM_Hook
  4. * \brief PCM Hook function lib to execute cmdline
  5. * \author Pavel Fertser
  6. * \author Joerg Reisenweber <joerg@openmoko.org>
  7. * \date 2009
  8. */
  9. /*
  10. * PCM - Hook functions
  11. * Copyright (c) 2009 by J.Reisenweber, P.Fertser
  12. *
  13. * This library is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU Lesser General Public License as
  15. * published by the Free Software Foundation; either version 2.1 of
  16. * the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Lesser General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Lesser General Public
  24. * License along with this library; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. *
  27. */
  28.  
  29. #define debug true
  30. #define dlclose_alsa_botch true
  31.  
  32. #include <alsa/asoundlib.h>
  33. #include <alsa/conf.h>
  34. #include <alsa/pcm.h>
  35. #include <dlfcn.h>
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38.  
  39. snd_config_t *conf_copy;
  40.  
  41. static int snd_pcm_hook_testhook_hw_params(snd_pcm_hook_t *hook)
  42. {
  43. const char *str;
  44. snd_config_t *h = snd_pcm_hook_get_private(hook);
  45. snd_config_t *s;
  46. int ret;
  47.  
  48. if ( ! snd_config_search(h, "open", &s) ) {
  49.  
  50. if ( ret = snd_config_get_string(s, &str) ) {
  51. fprintf(stderr, "testhook open: no string: ret:%i\n", ret);
  52. return -2;
  53. };
  54. //#ifdef debug
  55. fprintf(stderr, "testhook: hw_params ret:%i str:%s\n", ret, str);
  56. //#endif
  57. ret = system(str);
  58. if (ret != 0) {
  59. fprintf(stderr, "testhook: system ret:%i\n", ret);
  60. return -1;
  61. }
  62. }
  63. return 0;
  64. }
  65.  
  66. static int snd_pcm_hook_testhook_hw_free(snd_pcm_hook_t *hook)
  67. {
  68. const char *str;
  69. snd_config_t *h = snd_pcm_hook_get_private(hook);
  70. snd_config_t *s;
  71. snd_config_search(h, "close", &s);
  72. snd_config_get_string(s, &str);
  73. #ifdef debug
  74. fprintf(stderr, "testhook: hw_free, %s\n", str);
  75. #endif
  76. int ret = system(str);
  77. return ret;
  78. }
  79.  
  80. static int snd_pcm_hook_testhook_close(snd_pcm_hook_t *hook)
  81. {
  82. fprintf(stderr, "testhook: close\n");
  83. return 0;
  84. }
  85.  
  86. int _snd_pcm_hook_testhook_install(snd_pcm_t *pcm, snd_config_t *conf)
  87. {
  88. int err;
  89. snd_pcm_hook_t *h_hw_params = NULL, *h_hw_free = NULL, *h_close = NULL;
  90.  
  91. snd_config_copy(&conf_copy, conf);
  92.  
  93. #ifdef dlclose_alsa_botch
  94. dlopen("testhook.so", RTLD_NOW);
  95. fprintf(stderr, "testhook: install + dlopen\n");
  96. #endif
  97.  
  98. err = snd_pcm_hook_add(&h_hw_params, pcm, SND_PCM_HOOK_TYPE_HW_PARAMS,
  99. snd_pcm_hook_testhook_hw_params, conf_copy);
  100. if (err < 0)
  101. goto _err;
  102. err = snd_pcm_hook_add(&h_hw_free, pcm, SND_PCM_HOOK_TYPE_HW_FREE,
  103. snd_pcm_hook_testhook_hw_free, conf_copy);
  104. if (err < 0)
  105. goto _err;
  106. err = snd_pcm_hook_add(&h_close, pcm, SND_PCM_HOOK_TYPE_CLOSE,
  107. snd_pcm_hook_testhook_close, NULL);
  108. return 0;
  109. _err:
  110. if (h_hw_params)
  111. snd_pcm_hook_remove(h_hw_params);
  112. if (h_hw_free)
  113. snd_pcm_hook_remove(h_hw_free);
  114. if (h_close)
  115. snd_pcm_hook_remove(h_close);
  116. return err;
  117. }
  118.  
  119. SND_DLSYM_BUILD_VERSION(_snd_pcm_hook_testhook_install, SND_PCM_DLSYM_VERSION);
  120.  
  121.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement