raop_sink.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. static const char * TAG = "platform";
  17. extern char current_namespace[];
  18. log_level raop_loglevel = lINFO;
  19. log_level util_loglevel;
  20. static log_level *loglevel = &raop_loglevel;
  21. static struct raop_ctx_s *raop;
  22. /****************************************************************************************
  23. * Airplay sink initialization
  24. */
  25. void raop_sink_init(raop_cmd_cb_t cmd_cb, raop_data_cb_t data_cb) {
  26. const char *hostname;
  27. char sink_name[64-6] = CONFIG_AIRPLAY_NAME;
  28. nvs_handle nvs;
  29. tcpip_adapter_ip_info_t ipInfo;
  30. struct in_addr host;
  31. // get various IP info
  32. tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ipInfo);
  33. tcpip_adapter_get_hostname(TCPIP_ADAPTER_IF_STA, &hostname);
  34. host.s_addr = ipInfo.ip.addr;
  35. //initialize mDNS
  36. ESP_ERROR_CHECK( mdns_init() );
  37. ESP_ERROR_CHECK( mdns_hostname_set(hostname) );
  38. if (nvs_open(current_namespace, NVS_READONLY, &nvs) == ESP_OK) {
  39. size_t len = sizeof(sink_name) - 1;
  40. nvs_get_str(nvs, "airplay_sink_name", sink_name, &len);
  41. nvs_close(nvs);
  42. }
  43. ESP_LOGI(TAG, "mdns hostname set to: [%s] with servicename %s", hostname, sink_name);
  44. //initialize service
  45. uint8_t mac[6];
  46. esp_read_mac(mac, ESP_MAC_WIFI_STA);
  47. raop = raop_create(host, sink_name, mac, 44100, cmd_cb, data_cb);
  48. }
  49. /****************************************************************************************
  50. * Airplay local command (stop, start, volume ...)
  51. */
  52. void raop_sink_cmd(raop_event_t event, void *param) {
  53. raop_cmd(raop, event, param);
  54. }