aes67_sap.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * SPDX-FileCopyrightText: 2026 DatanoiseTV
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /*
  7. * SAP (Session Announcement Protocol) - RFC 2974
  8. *
  9. * Handles periodic multicast announcement and discovery of AES67
  10. * audio sessions. Each source stream is advertised with its SDP.
  11. */
  12. #pragma once
  13. #include <stdint.h>
  14. #include <stdbool.h>
  15. #include "esp_err.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /* SAP multicast address and port per RFC 2974 */
  20. #define AES67_SAP_MCAST_ADDR "239.255.255.255"
  21. #define AES67_SAP_PORT 9875
  22. #define AES67_SAP_MAX_SDP_LEN 1024
  23. /* Discovered remote source */
  24. typedef struct {
  25. uint32_t origin_ip; /* IP of announcing node */
  26. uint16_t msg_id; /* SAP message ID hash */
  27. char name[64]; /* Session name from SDP */
  28. char sdp[AES67_SAP_MAX_SDP_LEN]; /* Full SDP text */
  29. uint32_t last_seen; /* Tick count of last announcement */
  30. } aes67_sap_remote_source_t;
  31. /* Callback when a remote source is discovered or lost */
  32. typedef void (*aes67_sap_event_cb_t)(bool is_announce,
  33. const aes67_sap_remote_source_t *source,
  34. void *user_data);
  35. /* Opaque SAP context */
  36. typedef struct aes67_sap_ctx *aes67_sap_handle_t;
  37. /**
  38. * Initialize the SAP subsystem.
  39. */
  40. esp_err_t aes67_sap_init(aes67_sap_handle_t *handle);
  41. /**
  42. * Start SAP announcements and listening.
  43. */
  44. esp_err_t aes67_sap_start(aes67_sap_handle_t handle);
  45. /**
  46. * Stop SAP.
  47. */
  48. esp_err_t aes67_sap_stop(aes67_sap_handle_t handle);
  49. /**
  50. * Destroy SAP context.
  51. */
  52. esp_err_t aes67_sap_destroy(aes67_sap_handle_t handle);
  53. /**
  54. * Announce a local source. The SDP will be periodically multicast.
  55. */
  56. esp_err_t aes67_sap_announce(aes67_sap_handle_t handle,
  57. uint16_t msg_id, uint32_t origin_ip,
  58. const char *sdp);
  59. /**
  60. * Send a deletion for a previously announced source.
  61. */
  62. esp_err_t aes67_sap_delete(aes67_sap_handle_t handle,
  63. uint16_t msg_id, uint32_t origin_ip,
  64. const char *sdp);
  65. /**
  66. * Register callback for remote source discovery/loss events.
  67. */
  68. esp_err_t aes67_sap_register_cb(aes67_sap_handle_t handle,
  69. aes67_sap_event_cb_t cb, void *user_data);
  70. /**
  71. * Get the number of currently known remote sources.
  72. */
  73. int aes67_sap_get_remote_count(aes67_sap_handle_t handle);
  74. /**
  75. * Get a remote source by index (0-based). Returns ESP_ERR_NOT_FOUND if
  76. * the index is out of range.
  77. */
  78. esp_err_t aes67_sap_get_remote(aes67_sap_handle_t handle, int index,
  79. aes67_sap_remote_source_t *source);
  80. #ifdef __cplusplus
  81. }
  82. #endif