aes67_session.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * SPDX-FileCopyrightText: 2026 DatanoiseTV
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /*
  7. * Session manager for AES67 source and sink streams.
  8. *
  9. * Orchestrates stream lifecycle: creating/removing sources and sinks,
  10. * generating SDP, managing SAP announcements, and mapping between
  11. * RTP streams and the local audio I/O.
  12. */
  13. #pragma once
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include "esp_err.h"
  17. #include "aes67_config.h"
  18. #include "aes67_rtp.h"
  19. #include "aes67_sdp.h"
  20. #include "aes67_ptp.h"
  21. #include "aes67_sap.h"
  22. #include "aes67_audio.h"
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /* Source stream descriptor */
  27. typedef struct {
  28. uint8_t id;
  29. char name[64];
  30. aes67_rtp_stream_config_t rtp_config;
  31. aes67_sdp_t sdp;
  32. aes67_rtp_stream_handle_t rtp_stream;
  33. uint16_t sap_msg_id; /* CRC16 hash used for SAP announce/delete matching */
  34. bool enabled;
  35. } aes67_source_t;
  36. /* Sink stream descriptor */
  37. typedef struct {
  38. uint8_t id;
  39. char name[64];
  40. aes67_rtp_stream_config_t rtp_config;
  41. aes67_sdp_t sdp;
  42. aes67_rtp_stream_handle_t rtp_stream;
  43. bool enabled;
  44. char remote_sdp[AES67_SDP_MAX_LEN];
  45. } aes67_sink_t;
  46. /* Session manager context (opaque) */
  47. typedef struct aes67_session_mgr *aes67_session_handle_t;
  48. /**
  49. * Initialize the session manager with references to all subsystems.
  50. */
  51. esp_err_t aes67_session_init(aes67_rtp_engine_handle_t rtp,
  52. aes67_ptp_handle_t ptp,
  53. aes67_sap_handle_t sap,
  54. aes67_audio_handle_t audio,
  55. const aes67_config_t *config,
  56. aes67_session_handle_t *handle);
  57. /**
  58. * Create a source stream. Generates SDP, adds RTP stream, and optionally
  59. * starts SAP announcements.
  60. *
  61. * @param handle Session manager
  62. * @param name Stream name (used in SDP s= line)
  63. * @param channels Number of channels (0 = use default)
  64. * @param codec Audio codec (or -1 for default)
  65. * @param id Output: assigned stream ID
  66. * @return ESP_OK on success
  67. */
  68. esp_err_t aes67_session_add_source(aes67_session_handle_t handle,
  69. const char *name,
  70. uint8_t channels,
  71. aes67_codec_t codec,
  72. uint8_t *id);
  73. /**
  74. * Remove a source stream by ID.
  75. */
  76. esp_err_t aes67_session_remove_source(aes67_session_handle_t handle, uint8_t id);
  77. /**
  78. * Create a sink stream from an SDP description (e.g. from SAP discovery).
  79. *
  80. * @param handle Session manager
  81. * @param name Local name for this sink
  82. * @param sdp_text SDP of the remote source to subscribe to
  83. * @param id Output: assigned stream ID
  84. * @return ESP_OK on success
  85. */
  86. esp_err_t aes67_session_add_sink(aes67_session_handle_t handle,
  87. const char *name,
  88. const char *sdp_text,
  89. uint8_t *id);
  90. /**
  91. * Remove a sink stream by ID.
  92. */
  93. esp_err_t aes67_session_remove_sink(aes67_session_handle_t handle, uint8_t id);
  94. /**
  95. * Get a source descriptor by ID. Returns ESP_ERR_NOT_FOUND if not active.
  96. */
  97. esp_err_t aes67_session_get_source(aes67_session_handle_t handle, uint8_t id,
  98. aes67_source_t *source);
  99. /**
  100. * Get a sink descriptor by ID.
  101. */
  102. esp_err_t aes67_session_get_sink(aes67_session_handle_t handle, uint8_t id,
  103. aes67_sink_t *sink);
  104. /**
  105. * Get the number of active sources.
  106. */
  107. int aes67_session_get_source_count(aes67_session_handle_t handle);
  108. /**
  109. * Get the number of active sinks.
  110. */
  111. int aes67_session_get_sink_count(aes67_session_handle_t handle);
  112. /**
  113. * Set the packet time for new source streams (does not affect existing).
  114. */
  115. void aes67_session_set_packet_time(aes67_session_handle_t handle, uint16_t ptime_us);
  116. /**
  117. * Destroy session manager and all streams.
  118. */
  119. esp_err_t aes67_session_destroy(aes67_session_handle_t handle);
  120. #ifdef __cplusplus
  121. }
  122. #endif