miccontrol.c 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * miccontrol.c
  3. * Copyright (C) 2018 jshaver <jshaver@je-laptop>
  4. *
  5. * Distributed under terms of the MIT license.
  6. */
  7. #include "stdio.h"
  8. #include "pulse/pulseaudio.h"
  9. const char *NAME = "miccontrol";
  10. static pa_context *context = NULL;
  11. static pa_mainloop_api *mainloop_api = NULL;
  12. static pa_mainloop *mainloop = NULL;
  13. void querySources(pa_context *c, void *userdata);
  14. void handleSourceList(struct pa_context *c, const pa_source_info *i, int eol, void *userdata);
  15. int main() {
  16. int ret = 1;
  17. mainloop = pa_mainloop_new();
  18. mainloop_api = pa_mainloop_get_api(mainloop);
  19. context = pa_context_new(mainloop_api, NULL);
  20. pa_context_set_state_callback(context, querySources, NULL);
  21. pa_context_connect(context, NULL, 0, NULL);
  22. //pa_operation_unref(getSourceOp);
  23. pa_mainloop_run(mainloop, &ret);
  24. pa_context_unref(context);
  25. pa_mainloop_free(mainloop);
  26. return ret;
  27. }
  28. void querySources(pa_context *c, void *userdata) {
  29. if(pa_context_get_state(context) != PA_CONTEXT_READY) {
  30. return;
  31. }
  32. pa_operation *getSourceOp = NULL;
  33. getSourceOp = pa_context_get_source_info_list(context, handleSourceList, NULL);
  34. if(!getSourceOp) {
  35. } else {
  36. pa_operation_state_t state = pa_operation_get_state(getSourceOp);
  37. switch(state) {
  38. case PA_OPERATION_RUNNING:
  39. break;
  40. case PA_OPERATION_DONE:
  41. break;
  42. case PA_OPERATION_CANCELLED:
  43. }
  44. }
  45. }
  46. void handleSourceList(pa_context *c, const pa_source_info *i, int eol, void *userdata) {
  47. printf("Callback called...\n");
  48. printf("eol is %d\n", eol);
  49. printf(i->description);
  50. printf("\n");
  51. return;
  52. }