dacp_client.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. /**
  5. * DACP (Digital Audio Control Protocol) client.
  6. *
  7. * Sends commands back to the AirPlay source device (iPhone/Mac) so its
  8. * UI reflects changes made via hardware buttons on the receiver.
  9. *
  10. * Only works with AirPlay 1 connections — modern iOS AirPlay 2 does not
  11. * send DACP-ID/Active-Remote headers and uses the Media Remote Protocol
  12. * (MRP) instead, which we do not implement. When DACP headers are
  13. * present we discover the client's DACP port via mDNS (_dacp._tcp) and
  14. * authenticate our HTTP requests with the Active-Remote token.
  15. *
  16. * Commands are HTTP GET requests to the client:
  17. * GET /ctrl-int/1/playpause
  18. * GET /ctrl-int/1/nextitem
  19. * GET /ctrl-int/1/previtem
  20. * GET /ctrl-int/1/volumeup
  21. * GET /ctrl-int/1/volumedown
  22. * GET /ctrl-int/1/setproperty?dmcp.volume=<0-100>
  23. */
  24. /**
  25. * Initialize the DACP client. Must be called once at startup.
  26. */
  27. void dacp_init(void);
  28. /**
  29. * Store the DACP session identifiers from the RTSP handshake.
  30. * Called when DACP-ID and Active-Remote headers are parsed.
  31. *
  32. * @param dacp_id Client's DACP-ID (hex string, e.g. "A1B2C3D4E5F6")
  33. * @param active_remote Client's Active-Remote token
  34. * @param client_ip Client's IPv4 address (network byte order)
  35. */
  36. void dacp_set_session(const char *dacp_id, const char *active_remote,
  37. uint32_t client_ip);
  38. /**
  39. * Clear the DACP session (on client disconnect).
  40. */
  41. void dacp_clear_session(void);
  42. /**
  43. * Send play/pause toggle command to the AirPlay client.
  44. */
  45. void dacp_send_playpause(void);
  46. /**
  47. * Send next track command to the AirPlay client.
  48. */
  49. void dacp_send_next(void);
  50. /**
  51. * Send previous track command to the AirPlay client.
  52. */
  53. void dacp_send_prev(void);
  54. /**
  55. * Send volume up step command to the AirPlay client.
  56. */
  57. void dacp_send_volume_up(void);
  58. /**
  59. * Send volume down step command to the AirPlay client.
  60. */
  61. void dacp_send_volume_down(void);
  62. /**
  63. * Send absolute volume change to the AirPlay client.
  64. * @param volume_percent Volume 0-100 (DACP linear scale)
  65. */
  66. void dacp_send_volume(float volume_percent);
  67. /**
  68. * Check whether a DACP session is currently active.
  69. * @return true if DACP-ID and Active-Remote are set
  70. */
  71. bool dacp_is_active(void);
  72. /**
  73. * Probe mDNS to check if the client's DACP service is still advertised.
  74. * Used in AirPlay v1 mode to differentiate pause from genuine disconnect.
  75. * @return true if the _dacp._tcp service matching the current session is found
  76. */
  77. bool dacp_probe_service(void);