rtsp_handlers.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #pragma once
  2. #include <stddef.h>
  3. #include <stdint.h>
  4. #include "esp_err.h"
  5. #include "rtsp_conn.h"
  6. #include "rtsp_message.h"
  7. /**
  8. * RTSP Method Handler Dispatch Table
  9. * Inspired by shairport-sync's method_handlers pattern
  10. */
  11. // Key bits:
  12. // Bit 38: SupportsCoreUtilsPairingAndEncryption
  13. // Bit 46: SupportsHKPairingAndAccessControl
  14. // Bit 48: SupportsTransientPairing
  15. #ifdef CONFIG_AIRPLAY_FORCE_V1
  16. // AirPlay v1: strip pairing/encryption bits so iOS uses classic RAOP
  17. #define AIRPLAY_FEATURES_HI 0x0
  18. #define AIRPLAY_FEATURES_LO 0x5C4A00
  19. #else
  20. #define AIRPLAY_FEATURES_HI 0x1C340
  21. #define AIRPLAY_FEATURES_LO 0x405C4A00
  22. #endif
  23. // Audio buffer size for buffered streams (type 103)
  24. #define AP2_AUDIO_BUFFER_SIZE (1 * 1024 * 1024)
  25. // Include for audio_format_t
  26. #include "audio_receiver.h"
  27. /**
  28. * Codec registry entry
  29. */
  30. typedef struct {
  31. const char *name; // Codec name: "ALAC", "AAC", "OPUS"
  32. int64_t type_id; // bplist "ct" value (2=ALAC, 4=AAC, 8=AAC-ELD)
  33. } rtsp_codec_t;
  34. /**
  35. * Configure audio format from codec type ID
  36. * Looks up codec in registry and calls its configure function.
  37. * @param type_id Codec type from bplist "ct" field
  38. * @param fmt Audio format struct to configure
  39. * @param sample_rate Sample rate from bplist
  40. * @param samples_per_frame Samples per frame from bplist
  41. * @return true if codec found and configured, false otherwise
  42. */
  43. bool rtsp_codec_configure(int64_t type_id, audio_format_t *fmt,
  44. int64_t sample_rate, int64_t samples_per_frame);
  45. /**
  46. * Handler function type
  47. */
  48. typedef void (*rtsp_handler_fn)(int socket, rtsp_conn_t *conn,
  49. const rtsp_request_t *req,
  50. const uint8_t *raw_request, size_t raw_len);
  51. /**
  52. * Method handler entry
  53. */
  54. typedef struct {
  55. const char *method;
  56. rtsp_handler_fn handler;
  57. } rtsp_method_handler_t;
  58. /**
  59. * Dispatch RTSP request to appropriate handler
  60. * @param socket Client socket
  61. * @param conn Connection state
  62. * @param raw_request Raw request data
  63. * @param raw_len Length of raw request
  64. * @return 0 on success, -1 on error
  65. */
  66. int rtsp_dispatch(int socket, rtsp_conn_t *conn, const uint8_t *raw_request,
  67. size_t raw_len);
  68. /**
  69. * Get device ID string (MAC address format)
  70. * @param device_id Output buffer (at least 18 bytes)
  71. * @param len Buffer size
  72. */
  73. void rtsp_get_device_id(char *device_id, size_t len);
  74. // Event port task management
  75. esp_err_t rtsp_start_event_port_task(int listen_socket);
  76. void rtsp_stop_event_port_task(void);
  77. int rtsp_event_port_listen_socket(void);