raop_sink.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 "nvs_utilities.h"
  14. #include "raop.h"
  15. #include "log_util.h"
  16. #include "trace.h"
  17. #ifndef CONFIG_AIRPLAY_NAME
  18. #define CONFIG_AIRPLAY_NAME "ESP32-AirPlay"
  19. #endif
  20. static const char * TAG = "platform";
  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. tcpip_adapter_ip_info_t ipInfo;
  39. struct in_addr host;
  40. // get various IP info
  41. tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ipInfo);
  42. tcpip_adapter_get_hostname(TCPIP_ADAPTER_IF_STA, &hostname);
  43. host.s_addr = ipInfo.ip.addr;
  44. // initialize mDNS
  45. ESP_ERROR_CHECK( mdns_init() );
  46. ESP_ERROR_CHECK( mdns_hostname_set(hostname) );
  47. char * sink_name_buffer= (char *)get_nvs_value_alloc(NVS_TYPE_STR, "airplay_name");
  48. if(sink_name_buffer != NULL){
  49. memset(sink_name, 0x00, sizeof(sink_name));
  50. strncpy(sink_name,sink_name_buffer,sizeof(sink_name)-1 );
  51. free(sink_name_buffer);
  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. }