raop_sink.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <stdlib.h>
  5. #include "mdns.h"
  6. #include "nvs.h"
  7. #include "tcpip_adapter.h"
  8. #include "esp_log.h"
  9. #include "esp_console.h"
  10. #include "esp_pthread.h"
  11. #include "esp_system.h"
  12. #include "freertos/timers.h"
  13. #include "raop.h"
  14. #include "log_util.h"
  15. #include "trace.h"
  16. #ifndef CONFIG_AIRPLAY_NAME
  17. #define CONFIG_AIRPLAY_NAME "disabled"
  18. #endif
  19. static const char * TAG = "platform";
  20. extern char current_namespace[];
  21. log_level raop_loglevel = lINFO;
  22. log_level util_loglevel;
  23. static log_level *loglevel = &raop_loglevel;
  24. static struct raop_ctx_s *raop;
  25. /****************************************************************************************
  26. * Airplay sink initialization
  27. */
  28. void raop_sink_init(raop_cmd_cb_t cmd_cb, raop_data_cb_t data_cb) {
  29. const char *hostname;
  30. char sink_name[64-6] = CONFIG_AIRPLAY_NAME;
  31. nvs_handle nvs;
  32. tcpip_adapter_ip_info_t ipInfo;
  33. struct in_addr host;
  34. // get various IP info
  35. tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ipInfo);
  36. tcpip_adapter_get_hostname(TCPIP_ADAPTER_IF_STA, &hostname);
  37. host.s_addr = ipInfo.ip.addr;
  38. // initialize mDNS
  39. ESP_ERROR_CHECK( mdns_init() );
  40. ESP_ERROR_CHECK( mdns_hostname_set(hostname) );
  41. if (nvs_open(current_namespace, NVS_READONLY, &nvs) == ESP_OK) {
  42. size_t len = sizeof(sink_name) - 1;
  43. nvs_get_str(nvs, "airplay_sink_name", sink_name, &len);
  44. nvs_close(nvs);
  45. }
  46. ESP_LOGI(TAG, "mdns hostname set to: [%s] with servicename %s", hostname, sink_name);
  47. // create RAOP instance, latency is set by controller
  48. uint8_t mac[6];
  49. esp_read_mac(mac, ESP_MAC_WIFI_STA);
  50. raop = raop_create(host, sink_name, mac, 0, cmd_cb, data_cb);
  51. }
  52. /****************************************************************************************
  53. * Airplay local command (stop, start, volume ...)
  54. */
  55. void raop_sink_cmd(raop_event_t event, void *param) {
  56. raop_cmd(raop, event, param);
  57. }