jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.3KB

  1. /*
  2. Copyright (C) 2009 Grame
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  13. */
  14. #include <string.h>
  15. #include <unistd.h>
  16. #include <errno.h>
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19. #include <assert.h>
  20. #include "reserve.h"
  21. #include "audio_reserve.h"
  22. #include "JackError.h"
  23. static DBusConnection* connection = NULL;
  24. SERVER_EXPORT int audio_reservation_init()
  25. {
  26. DBusError error;
  27. dbus_error_init(&error);
  28. if (!(connection = dbus_bus_get(DBUS_BUS_SESSION, &error))) {
  29. jack_error("Failed to connect to session bus for device reservation %s\n", error.message);
  30. return -1;
  31. }
  32. return 0;
  33. }
  34. SERVER_EXPORT int audio_reservation_finish()
  35. {
  36. if (connection)
  37. dbus_connection_unref(connection);
  38. return 0;
  39. }
  40. SERVER_EXPORT void* audio_acquire(int num)
  41. {
  42. DBusError error;
  43. rd_device* device;
  44. char audio_name[32];
  45. int e;
  46. snprintf(audio_name, sizeof(audio_name) - 1, "Audio%d", num);
  47. if ((e = rd_acquire(
  48. &device,
  49. connection,
  50. audio_name,
  51. "Jack audio server",
  52. INT32_MAX,
  53. NULL,
  54. &error)) < 0) {
  55. jack_error ("Failed to acquire device: %s\n", error.message ? error.message : strerror(-e));
  56. return NULL;
  57. }
  58. jack_info("Acquire audio card %s", audio_name);
  59. return (void*)device;
  60. }
  61. SERVER_EXPORT void audio_reserve_loop()
  62. {
  63. if (connection) {
  64. while (dbus_connection_read_write_dispatch (connection, -1))
  65. ; // empty loop body
  66. }
  67. }
  68. SERVER_EXPORT void audio_release(void* dev)
  69. {
  70. rd_device* device = (rd_device*)dev;
  71. if (device) {
  72. jack_info("Release audio card");
  73. rd_release(device);
  74. }
  75. }