raop_sink.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 de-initialization
  27. */
  28. void raop_sink_deinit(void) {
  29. raop_delete(raop);
  30. mdns_free();
  31. }
  32. /****************************************************************************************
  33. * Airplay sink initialization
  34. */
  35. void raop_sink_init(raop_cmd_cb_t cmd_cb, raop_data_cb_t data_cb) {
  36. const char *hostname;
  37. char sink_name[64-6] = CONFIG_AIRPLAY_NAME;
  38. nvs_handle nvs;
  39. tcpip_adapter_ip_info_t ipInfo;
  40. struct in_addr host;
  41. // get various IP info
  42. tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ipInfo);
  43. tcpip_adapter_get_hostname(TCPIP_ADAPTER_IF_STA, &hostname);
  44. host.s_addr = ipInfo.ip.addr;
  45. // initialize mDNS
  46. ESP_ERROR_CHECK( mdns_init() );
  47. ESP_ERROR_CHECK( mdns_hostname_set(hostname) );
  48. if (nvs_open(current_namespace, NVS_READONLY, &nvs) == ESP_OK) {
  49. size_t len = sizeof(sink_name) - 1;
  50. nvs_get_str(nvs, "airplay_sink_name", sink_name, &len);
  51. nvs_close(nvs);
  52. }
  53. ESP_LOGI(TAG, "mdns hostname set to: [%s] with servicename %s", hostname, sink_name);
  54. // create RAOP instance, latency is set by controller
  55. uint8_t mac[6];
  56. esp_read_mac(mac, ESP_MAC_WIFI_STA);
  57. raop = raop_create(host, sink_name, mac, 0, cmd_cb, data_cb);
  58. }
  59. /****************************************************************************************
  60. * Airplay local command (stop, start, volume ...)
  61. */
  62. void raop_sink_cmd(raop_event_t event, void *param) {
  63. raop_cmd(raop, event, param);
  64. }