aes67_sdp.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * SPDX-FileCopyrightText: 2026 DatanoiseTV
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /*
  7. * SDP (Session Description Protocol) parser and generator for AES67.
  8. *
  9. * Generates and parses SDP documents conforming to AES67 / RAVENNA
  10. * requirements, including PTP reference clock attributes.
  11. */
  12. #pragma once
  13. #include <stdint.h>
  14. #include <stdbool.h>
  15. #include "esp_err.h"
  16. #include "aes67_config.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #define AES67_SDP_MAX_LEN 1024
  21. /* Parsed SDP session description */
  22. typedef struct {
  23. /* Origin (o= line) */
  24. char origin_username[32];
  25. uint32_t session_id;
  26. uint32_t session_version;
  27. uint32_t origin_ip;
  28. /* Session name (s= line) */
  29. char session_name[64];
  30. /* Connection (c= line) */
  31. uint32_t connection_ip; /* Multicast group address */
  32. uint8_t ttl;
  33. /* Media (m= line) */
  34. uint16_t port;
  35. uint8_t payload_type;
  36. /* Audio parameters (from a=rtpmap) */
  37. aes67_codec_t codec;
  38. uint32_t sample_rate;
  39. uint8_t channels;
  40. uint8_t word_length;
  41. /* Packet time (a=ptime) */
  42. uint16_t ptime_us; /* Packet time in microseconds */
  43. /* PTP reference clock (a=ts-refclk) */
  44. bool has_ptp_refclk;
  45. uint8_t ptp_grandmaster_id[8];
  46. uint8_t ptp_domain;
  47. bool ptp_traceable;
  48. /* Media clock offset (a=mediaclk) */
  49. bool has_mediaclk;
  50. uint32_t mediaclk_offset;
  51. /* Stream direction for SDP attribute (a=sendonly / a=recvonly) */
  52. bool is_source; /* true = sendonly, false = recvonly */
  53. } aes67_sdp_t;
  54. /**
  55. * Generate an AES67-compliant SDP string.
  56. *
  57. * @param sdp Populated SDP structure
  58. * @param buf Output buffer for SDP text
  59. * @param buf_len Size of output buffer
  60. * @return Number of bytes written, or -1 on error
  61. */
  62. int aes67_sdp_generate(const aes67_sdp_t *sdp, char *buf, size_t buf_len);
  63. /**
  64. * Parse an SDP string into an aes67_sdp_t structure.
  65. *
  66. * @param sdp_text Null-terminated SDP text
  67. * @param sdp Output structure
  68. * @return ESP_OK on success, ESP_ERR_INVALID_ARG on parse failure
  69. */
  70. esp_err_t aes67_sdp_parse(const char *sdp_text, aes67_sdp_t *sdp);
  71. /**
  72. * Get the codec name string for a given codec enum.
  73. */
  74. const char *aes67_codec_to_str(aes67_codec_t codec);
  75. /**
  76. * Parse a codec name string to enum. Returns -1 on unknown codec.
  77. */
  78. int aes67_codec_from_str(const char *name);
  79. /**
  80. * Get word length (bytes per sample) for a codec.
  81. */
  82. uint8_t aes67_codec_word_length(aes67_codec_t codec);
  83. #ifdef __cplusplus
  84. }
  85. #endif