aes67.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * SPDX-FileCopyrightText: 2026 DatanoiseTV
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /*
  7. * AES67/RAVENNA audio-over-IP component for ESP-IDF
  8. *
  9. * Top-level API for initialization, configuration and lifecycle management.
  10. */
  11. #pragma once
  12. #include <stdint.h>
  13. #include <stdbool.h>
  14. #include "esp_err.h"
  15. #include "freertos/FreeRTOS.h"
  16. #include "freertos/stream_buffer.h"
  17. #include "aes67_config.h"
  18. #include "aes67_session.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /* Opaque handle for an AES67 node instance */
  23. typedef struct aes67_node *aes67_node_handle_t;
  24. /* Event types posted to the application event loop */
  25. typedef enum {
  26. AES67_EVENT_PTP_LOCKED, /* PTP clock achieved lock */
  27. AES67_EVENT_PTP_UNLOCKED, /* PTP clock lost lock */
  28. AES67_EVENT_SOURCE_ADDED, /* Local source stream created */
  29. AES67_EVENT_SOURCE_REMOVED, /* Local source stream removed */
  30. AES67_EVENT_SINK_ADDED, /* Local sink stream created */
  31. AES67_EVENT_SINK_REMOVED, /* Local sink stream removed */
  32. AES67_EVENT_REMOTE_FOUND, /* Remote source discovered via SAP/mDNS */
  33. AES67_EVENT_REMOTE_LOST, /* Remote source timed out */
  34. AES67_EVENT_SINK_RX_ACTIVE, /* Sink is receiving audio data */
  35. AES67_EVENT_SINK_RX_TIMEOUT, /* Sink stopped receiving audio data */
  36. } aes67_event_t;
  37. /* Event base declaration for ESP event loop */
  38. ESP_EVENT_DECLARE_BASE(AES67_EVENT);
  39. /**
  40. * Initialize the AES67 node with the given configuration.
  41. *
  42. * Brings up PTP, RTP engine, SAP, mDNS and audio subsystems.
  43. * The Ethernet interface must already be initialized and connected.
  44. *
  45. * @param config Node configuration. NULL uses defaults from Kconfig.
  46. * @param handle Output handle for the created node instance.
  47. * @return ESP_OK on success
  48. */
  49. esp_err_t aes67_node_init(const aes67_config_t *config, aes67_node_handle_t *handle);
  50. /**
  51. * Start the AES67 node. Begins PTP sync, SAP announcements and enables
  52. * stream processing.
  53. */
  54. esp_err_t aes67_node_start(aes67_node_handle_t handle);
  55. /**
  56. * Stop the AES67 node. Tears down all active streams and halts PTP.
  57. */
  58. esp_err_t aes67_node_stop(aes67_node_handle_t handle);
  59. /**
  60. * Destroy the AES67 node and free all resources.
  61. */
  62. esp_err_t aes67_node_destroy(aes67_node_handle_t handle);
  63. /**
  64. * Get the node's current configuration (read-only snapshot).
  65. */
  66. esp_err_t aes67_node_get_config(aes67_node_handle_t handle, aes67_config_t *config);
  67. /**
  68. * Get the session manager handle from a running node.
  69. * Useful for adding/removing sources and sinks at the application level.
  70. */
  71. esp_err_t aes67_node_get_session(aes67_node_handle_t handle,
  72. aes67_session_handle_t *session);
  73. /**
  74. * Get the audio driver handle from a running node.
  75. */
  76. #include "aes67_audio.h"
  77. esp_err_t aes67_node_get_audio(aes67_node_handle_t handle,
  78. aes67_audio_handle_t *audio);
  79. /**
  80. * Get the SAP handle from a running node.
  81. */
  82. #include "aes67_sap.h"
  83. esp_err_t aes67_node_get_sap(aes67_node_handle_t handle,
  84. aes67_sap_handle_t *sap);
  85. /**
  86. * Get the PTP handle from a running node.
  87. */
  88. #include "aes67_ptp.h"
  89. esp_err_t aes67_node_get_ptp(aes67_node_handle_t handle,
  90. aes67_ptp_handle_t *ptp);
  91. /**
  92. * Get the RTP engine handle from a running node.
  93. */
  94. #include "aes67_rtp.h"
  95. esp_err_t aes67_node_get_rtp(aes67_node_handle_t handle,
  96. aes67_rtp_engine_handle_t *rtp);
  97. /**
  98. * Provide an external playout stream buffer for the node's playback task.
  99. *
  100. * By default the playback task consumes audio from the RTP engine's own
  101. * stream buffer. An integration that intercepts RTP frames earlier (for
  102. * example, an esp_eth Rx hook that parses audio in the driver callback and
  103. * feeds it in directly) can register its own buffer here; when set and
  104. * non-NULL, the playback task reads from it instead. Pass NULL to clear.
  105. *
  106. * Optional. Call before aes67_node_start(); has no effect on the ISR-driven
  107. * I2S path, which is fed via aes67_audio_slot_write().
  108. */
  109. esp_err_t aes67_node_set_playout_buf(aes67_node_handle_t handle,
  110. StreamBufferHandle_t sbuf);
  111. #ifdef __cplusplus
  112. }
  113. #endif