@geastack/targets 0.1.87 → 0.1.89

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/package.json +7 -7
  2. package/targets/esp32/app_project.cmake +18 -1
  3. package/targets/esp32/chip_bindings/audio/echo_cancellation.cpp +229 -0
  4. package/targets/esp32/chip_bindings/audio/echo_cancellation.h +13 -0
  5. package/targets/esp32/chip_bindings/audio/es8311.cpp +293 -45
  6. package/targets/esp32/chip_bindings/displays/rgb_panel.cpp +115 -12
  7. package/targets/esp32/chip_bindings/expanders/io_expander.h +2 -0
  8. package/targets/esp32/chip_bindings/expanders/tca9554.cpp +74 -0
  9. package/targets/esp32/chip_bindings/touch/ft3168.cpp +23 -1
  10. package/targets/esp32/chip_bindings/touch/ft3168_controller.h +1 -0
  11. package/targets/esp32/chip_bindings/touch/gt911.cpp +4 -3
  12. package/targets/esp32/components/gea_framework/CMakeLists.txt +8 -1
  13. package/targets/esp32/components/gea_juice/CMakeLists.txt +46 -0
  14. package/targets/esp32/components/gea_juice/README.md +20 -0
  15. package/targets/esp32/components/gea_juice/juice_memory.c +19 -0
  16. package/targets/esp32/components/gea_juice/juice_memory.h +16 -0
  17. package/targets/esp32/components/gea_juice/patch_threads.py +50 -0
  18. package/targets/esp32/components/gea_vp8_peer/CMakeLists.txt +16 -0
  19. package/targets/esp32/components/gea_vp8_peer/README.md +39 -0
  20. package/targets/esp32/components/gea_vp8_peer/gea_vp8_peer.h +21 -0
  21. package/targets/esp32/components/gea_vp8_peer/vp8_peer.cpp +538 -0
  22. package/targets/esp32/components/gea_vpx/CMakeLists.txt +235 -0
  23. package/targets/esp32/components/gea_vpx/README.md +133 -0
  24. package/targets/esp32/components/gea_vpx/i420_rgb565_s3.S +169 -0
  25. package/targets/esp32/components/gea_vpx/vp8_blocks_s3.c +42 -0
  26. package/targets/esp32/components/gea_vpx/vp8_copy_s3.S +39 -0
  27. package/targets/esp32/components/gea_vpx/vp8_entropy_s3.c +76 -0
  28. package/targets/esp32/components/gea_vpx/vp8_filter_s3.S +58 -0
  29. package/targets/esp32/components/gea_vpx/vp8_idct_s3.S +269 -0
  30. package/targets/esp32/components/gea_vpx/vp8_intrapred_s3.S +65 -0
  31. package/targets/esp32/components/gea_vpx/vp8_loopfilter_s3.S +333 -0
  32. package/targets/esp32/components/gea_vpx/vp8_loopfilter_s3.c +62 -0
  33. package/targets/esp32/components/gea_vpx/vp8_profile_s3.c +22 -0
  34. package/targets/esp32/components/gea_vpx/vp8_profile_s3.h +20 -0
  35. package/targets/esp32/components/gea_vpx/vp8_s3.c +120 -0
  36. package/targets/esp32/components/gea_vpx/vp8_s3.h +58 -0
  37. package/targets/esp32/components/gea_vpx/vp8_workspace_s3.c +14 -0
  38. package/targets/esp32/components/gea_vpx/vpx_memory.c +41 -0
  39. package/targets/esp32/connectivity/diagnostics_transport.cpp +18 -0
  40. package/targets/esp32/connectivity/wifi.cpp +30 -13
  41. package/targets/esp32/crypto/srtp_hmac_psa.c +118 -0
  42. package/targets/esp32/display.cpp +21 -0
  43. package/targets/esp32/gea_framework.cmake +7 -0
  44. package/targets/esp32/host_sources.cmake +2 -0
  45. package/targets/esp32/i2c_completion_order.cmake +57 -0
  46. package/targets/esp32/patch_streaming_dependencies.py +233 -0
  47. package/targets/esp32/services/device_control.cpp +209 -7
  48. package/targets/esp32/services/frame_scheduler.cpp +36 -1
  49. package/targets/esp32/services/opus_benchmark.h +82 -0
  50. package/targets/esp32/services/pcm_simd_check.h +73 -0
  51. package/targets/esp32/services/srtp_benchmark.h +106 -0
  52. package/targets/esp32/services/video_simd_benchmark.h +477 -0
  53. package/targets/esp32/services/vp8_benchmark.h +147 -0
  54. package/targets/esp32/streaming_dependency_patches.cmake +103 -0
  55. package/targets/esp32-m5stack-m5paper/main/idf_component.yml +2 -0
  56. package/targets/esp32-p4-m5stack-tab5/main/idf_component.yml +2 -0
  57. package/targets/esp32-p4-waveshare-touch-lcd-3.5/main/idf_component.yml +2 -0
  58. package/targets/esp32-p4-waveshare-touch-lcd-7/main/idf_component.yml +2 -0
  59. package/targets/esp32-s3-elecrow-rotary-2.1/main/idf_component.yml +2 -0
  60. package/targets/esp32-s3-epaper-1.54/main/idf_component.yml +2 -0
  61. package/targets/esp32-s3-lilygo-t-display-s3-long/main/idf_component.yml +2 -0
  62. package/targets/esp32-s3-m5stack-papers3/main/idf_component.yml +2 -0
  63. package/targets/esp32-s3-m5stack-sticks3/main/idf_component.yml +2 -0
  64. package/targets/esp32-s3-touch-amoled-1.75/main/idf_component.yml +2 -0
  65. package/targets/esp32-s3-touch-amoled-1.8/dependencies.lock +125 -2
  66. package/targets/esp32-s3-touch-amoled-1.8/main/CMakeLists.txt +29 -3
  67. package/targets/esp32-s3-touch-amoled-1.8/main/app_main.cpp +6 -3
  68. package/targets/esp32-s3-touch-amoled-1.8/main/idf_component.yml +15 -0
  69. package/targets/esp32-s3-touch-amoled-1.8/main/include/board.h +12 -0
  70. package/targets/esp32-s3-touch-amoled-1.8/sdkconfig.defaults +9 -1
  71. package/targets/esp32-s3-touch-amoled-2.06/CMakeLists.txt +2 -0
  72. package/targets/esp32-s3-touch-amoled-2.06/dependencies.lock +172 -8
  73. package/targets/esp32-s3-touch-amoled-2.06/main/CMakeLists.txt +9 -1
  74. package/targets/esp32-s3-touch-amoled-2.06/main/app_main.cpp +10 -3
  75. package/targets/esp32-s3-touch-amoled-2.06/main/idf_component.yml +21 -1
  76. package/targets/esp32-s3-touch-amoled-2.06/main/include/board.h +10 -0
  77. package/targets/esp32-s3-touch-amoled-2.06/main/touch.cpp +7 -0
  78. package/targets/esp32-s3-touch-amoled-2.41/dependencies.lock +57 -1
  79. package/targets/esp32-s3-touch-amoled-2.41/main/idf_component.yml +10 -0
  80. package/targets/esp32-s3-waveshare-touch-lcd-4b.json +504 -0
  81. package/targets.json +12 -1
@@ -9,6 +9,9 @@
9
9
  #include "pixel.h"
10
10
  #include "touch.h" // Touchscreen::injectEvent for GEADEV DRAG/SWIPE
11
11
  #include "wifi.h" // network::wifi() for GEADEV PING ip=/mac=
12
+ #include "host/video.h"
13
+
14
+ extern "C" uint32_t gea_display_completed_chunks() __attribute__((weak));
12
15
  #include "services/app_state.h"
13
16
  #include "services/storage_service.h"
14
17
  #include "ui/internal.h"
@@ -23,7 +26,7 @@
23
26
  #endif
24
27
 
25
28
  #include "driver/i2c_master.h"
26
- #if CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
29
+ #if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
27
30
  #include "driver/usb_serial_jtag.h"
28
31
  #include "driver/usb_serial_jtag_vfs.h"
29
32
  #endif
@@ -34,6 +37,10 @@
34
37
  #endif
35
38
  #include "platform/file_cache.h" // gea::platform::storage::ensureMounted for GEADEV PUSH
36
39
  #include "esp_log.h"
40
+ #include "esp_timer.h"
41
+ #if CONFIG_ESP_WIFI_ENABLED
42
+ #include "esp_wifi.h"
43
+ #endif
37
44
  #include "esp_err.h"
38
45
  #include "esp_mmu_map.h"
39
46
  #include "esp_partition.h"
@@ -59,6 +66,14 @@
59
66
  #include "host/notify.h" // gea::host::postNotification() for GEADEV NOTIFY
60
67
  #include "host/backends.h" // WifiBackend for GEADEV WIFI
61
68
  #include "host/storage.h" // gea::host::Storage for GEADEV STORAGE SET
69
+ #include "services/vp8_benchmark.h"
70
+ #include "services/opus_benchmark.h"
71
+ #include "services/srtp_benchmark.h"
72
+ #include "services/video_simd_benchmark.h"
73
+ #include "services/pcm_simd_check.h"
74
+ #if defined(GEA_VIDEO_SIMD_ESP32S3) && GEA_VIDEO_SIMD_ESP32S3
75
+ #include "../components/gea_vpx/vp8_profile_s3.h"
76
+ #endif
62
77
 
63
78
  // Older engines expose all four direct position fields.
64
79
  #ifndef GEA_CSS_POSITION_PX
@@ -1244,9 +1259,9 @@ void handlePush(char *args)
1244
1259
 
1245
1260
  char path[160];
1246
1261
  std::snprintf(path, sizeof(path), "%s", pathTok);
1247
- // Mount the microSD (the tile cache does this via writeCacheFile; a raw
1248
- // fopen alone won't trigger it).
1249
- if (!gea::platform::storage::ensureMounted()) {
1262
+ // Only the SD mount needs lazy initialization. SPIFFS is already mounted
1263
+ // at /storage; an absent SD card must not block writes to internal flash.
1264
+ if (std::strncmp(path, "/sdcard/", 8) == 0 && !gea::platform::storage::ensureMounted()) {
1250
1265
  std::printf("GEADEV:PUSH ERR no-storage path=%s\n", path);
1251
1266
  return;
1252
1267
  }
@@ -1327,7 +1342,7 @@ void handlePushBase64(char *args)
1327
1342
 
1328
1343
  char path[160];
1329
1344
  std::snprintf(path, sizeof(path), "%s", pathTok);
1330
- if (!gea::platform::storage::ensureMounted()) {
1345
+ if (std::strncmp(path, "/sdcard/", 8) == 0 && !gea::platform::storage::ensureMounted()) {
1331
1346
  std::printf("GEADEV:PUSH64 ERR no-storage path=%s\n", path);
1332
1347
  return;
1333
1348
  }
@@ -1499,6 +1514,77 @@ void handlePlayFile(char *args)
1499
1514
  std::printf("GEADEV:PLAYFILE %s path=%s\n", ok ? "OK" : "ERR", path);
1500
1515
  }
1501
1516
 
1517
+ void printTaskDiagnostics(bool networkOnly)
1518
+ {
1519
+ #if configUSE_TRACE_FACILITY && INCLUDE_xTaskGetHandle
1520
+ struct Sample {
1521
+ const char *name;
1522
+ UBaseType_t taskNumber = 0;
1523
+ configRUN_TIME_COUNTER_TYPE cpu = 0;
1524
+ std::int64_t at = 0;
1525
+ };
1526
+ static Sample samples[] = {{"wifi"}, {"tcpip"}, {"websocket_task"}, {"gea-ws-send"},
1527
+ {"gea_runtime"}, {"app_frame"}, {"gea_mic"}, {"gea_audio"},
1528
+ {"gea_mjpeg_dec"}, {"gea_mjpeg_rx"}, {"gea_rwrk"}, {"IDLE0"}, {"IDLE1"}};
1529
+ const char *prefix = networkOnly ? "NETDIAG" : "TASKSTATS";
1530
+ unsigned index = 0;
1531
+ for (auto &sample : samples) {
1532
+ if (networkOnly && index++ >= 4) break;
1533
+ const TaskHandle_t task = xTaskGetHandle(sample.name);
1534
+ if (!task) {
1535
+ std::printf("GEADEV:%s task=%s absent=1\n", prefix, sample.name);
1536
+ sample.at = 0;
1537
+ continue;
1538
+ }
1539
+ TaskStatus_t info{};
1540
+ // Inspect known media/runtime tasks only, without scanning their stacks.
1541
+ vTaskGetInfo(task, &info, pdFALSE, eInvalid);
1542
+ const auto now = esp_timer_get_time();
1543
+ const bool previous = sample.at && sample.taskNumber == info.xTaskNumber;
1544
+ const char *state = "invalid";
1545
+ switch (info.eCurrentState) {
1546
+ case eRunning: state = "running"; break;
1547
+ case eReady: state = "ready"; break;
1548
+ case eBlocked: state = "blocked"; break;
1549
+ case eSuspended: state = "suspended"; break;
1550
+ case eDeleted: state = "deleted"; break;
1551
+ default: break;
1552
+ }
1553
+ std::printf("GEADEV:%s task=%s id=%u state=%s priority=%u base_priority=%u core=%d cpu_ticks=%llu delta_ticks=%llu span_us=%lld\n",
1554
+ prefix, sample.name, static_cast<unsigned>(info.xTaskNumber), state,
1555
+ static_cast<unsigned>(info.uxCurrentPriority),
1556
+ static_cast<unsigned>(info.uxBasePriority),
1557
+ static_cast<int>(xTaskGetCoreID(task)),
1558
+ static_cast<unsigned long long>(info.ulRunTimeCounter),
1559
+ static_cast<unsigned long long>(previous ? info.ulRunTimeCounter - sample.cpu : 0),
1560
+ static_cast<long long>(previous ? now - sample.at : 0));
1561
+ sample.taskNumber = info.xTaskNumber;
1562
+ sample.cpu = info.ulRunTimeCounter;
1563
+ sample.at = now;
1564
+ }
1565
+ #else
1566
+ std::printf("GEADEV:NETDIAG task-stats-unavailable\n");
1567
+ #endif
1568
+ }
1569
+
1570
+ void printNetworkDiagnostics()
1571
+ {
1572
+ std::printf("GEADEV:NETDIAG BEGIN\n");
1573
+ printTaskDiagnostics(true);
1574
+ #if CONFIG_ESP_WIFI_ENABLED
1575
+ // The Wi-Fi driver owns these counters; use its public diagnostic entry.
1576
+ // Emit the marker first so USB also locates a blocked driver dump.
1577
+ std::printf("GEADEV:NETDIAG wifi-dump-begin\n");
1578
+ std::fflush(stdout);
1579
+ const auto result = esp_wifi_statis_dump(
1580
+ WIFI_STATIS_BUFFER | WIFI_STATIS_RXTX | WIFI_STATIS_HW | WIFI_STATIS_DIAG);
1581
+ std::printf("GEADEV:NETDIAG wifi-dump-result=%s\n", esp_err_to_name(result));
1582
+ #else
1583
+ std::printf("GEADEV:NETDIAG native-wifi-unavailable\n");
1584
+ #endif
1585
+ std::printf("GEADEV:NETDIAG END\n");
1586
+ }
1587
+
1502
1588
  // Optional per-target GEADEV command extension. The weak default (defined at the
1503
1589
  // end of this file, outside the namespace) returns false; a target that wants
1504
1590
  // extra commands — e.g. the ESP32-P4 camera capture (CAMSTILL / CAMCLIP) in
@@ -1527,9 +1613,85 @@ void handleCommand(char *line, CommandSource source)
1527
1613
  const std::string ip = gea::framework::network::wifi().ip();
1528
1614
  const std::string mac = gea::framework::network::wifi().mac();
1529
1615
  std::printf("GEADEV:PONG app=%s ip=%s mac=%s\n", appId ? appId : "", ip.c_str(), mac.c_str());
1616
+ } else if (tokenEquals(command, "NETDIAG")) {
1617
+ printNetworkDiagnostics();
1618
+ } else if (tokenEquals(command, "IPCSTACK")) {
1619
+ #if INCLUDE_xTaskGetHandle && CONFIG_ESP_IPC_ENABLE
1620
+ // Inspect only the two small stock IPC stacks, while the device is idle.
1621
+ // Never scan the application's large PSRAM stack or every task in a room.
1622
+ for (const char *name : {"ipc0", "ipc1"}) {
1623
+ const TaskHandle_t task = xTaskGetHandle(name);
1624
+ if (!task) std::printf("GEADEV:IPCSTACK task=%s absent=1\n", name);
1625
+ else std::printf("GEADEV:IPCSTACK task=%s capacity_bytes=%u free_bytes=%u\n", name,
1626
+ unsigned(CONFIG_ESP_IPC_TASK_STACK_SIZE), unsigned(uxTaskGetStackHighWaterMark(task)));
1627
+ }
1628
+ std::puts("GEADEV:IPCSTACK END");
1629
+ #else
1630
+ std::puts("GEADEV:IPCSTACK unavailable");
1631
+ #endif
1632
+ } else if (tokenEquals(command, "VP8PROFILE")) {
1633
+ #if defined(GEA_VIDEO_SIMD_ESP32S3) && GEA_VIDEO_SIMD_ESP32S3
1634
+ bool enabled = false;
1635
+ if (!parseOnOff(nextToken(cursor), &enabled)) {
1636
+ std::puts("GEADEV:ERR VP8PROFILE expected-on-or-off");
1637
+ } else {
1638
+ gea_vp8_profile_enable_s3(enabled);
1639
+ std::printf("GEADEV:VP8PROFILE enabled=%u\n", unsigned(enabled));
1640
+ }
1641
+ #else
1642
+ std::puts("GEADEV:ERR VP8PROFILE unavailable");
1643
+ #endif
1530
1644
  } else if (tokenEquals(command, "APP")) {
1531
1645
  const char *appId = gea::framework::apps::AppManager::currentId();
1532
1646
  std::printf("GEADEV:APP id=%s\n", appId ? appId : "");
1647
+ } else if (tokenEquals(command, "TASKSTATS")) {
1648
+ std::puts("GEADEV:TASKSTATS BEGIN");
1649
+ printTaskDiagnostics(false);
1650
+ std::puts("GEADEV:TASKSTATS END");
1651
+ } else if (tokenEquals(command, "VIDEOSTATS")) {
1652
+ gea::framework::services::AppState::lock();
1653
+ const auto stats = gea::host::HTMLVideoElement::presentationStats();
1654
+ gea::framework::services::AppState::unlock();
1655
+ std::printf("GEADEV:VIDEOSTATS decoded=%u selected=%u max_gap_ms=%u dma_chunks=%u\n",
1656
+ unsigned(stats.decoded), unsigned(stats.selected), unsigned(stats.maxGapMs),
1657
+ unsigned(gea_display_completed_chunks ? gea_display_completed_chunks() : 0));
1658
+ } else if (tokenEquals(command, "VIDEO")) {
1659
+ // Replay a local diagnostic clip through the real video/render path,
1660
+ // without creating a hosted session or opening microphone hardware.
1661
+ static gea::host::HTMLVideoElement retainedVideo;
1662
+ const char *className = nextToken(cursor);
1663
+ const char *url = nextToken(cursor);
1664
+ if (!className || !url) {
1665
+ std::puts("GEADEV:ERR VIDEO usage=GEADEV_VIDEO_class_url|STOP");
1666
+ } else {
1667
+ gea::framework::services::AppState::lock();
1668
+ auto &tree = gea::embedded::ui::Tree::instance();
1669
+ bool found = false;
1670
+ for (int id = 0; id < tree.nodeCount(); ++id) {
1671
+ if (!tree.hasClass(id, className)) continue;
1672
+ const gea::embedded::ui::NodeHandle node(id);
1673
+ gea::host::HTMLVideoElement video{node};
1674
+ const bool stopping = tokenEquals(url, "STOP");
1675
+ node.classList().toggle("ready", !stopping);
1676
+ for (int cover = 0; cover < tree.nodeCount(); ++cover) {
1677
+ if (tree.hasClass(cover, "portrait"))
1678
+ gea::embedded::ui::NodeHandle(cover).classList().toggle("hidden", !stopping);
1679
+ }
1680
+ if (stopping) {
1681
+ video.pause();
1682
+ video.setSrcObject(nullptr);
1683
+ retainedVideo = {};
1684
+ } else {
1685
+ retainedVideo = video;
1686
+ video.setSrc(url);
1687
+ video.play();
1688
+ }
1689
+ found = true;
1690
+ break;
1691
+ }
1692
+ gea::framework::services::AppState::unlock();
1693
+ std::printf("GEADEV:VIDEO %s\n", found ? "OK" : "missing-node");
1694
+ }
1533
1695
  } else if (tokenEquals(command, "MEM")) {
1534
1696
  const unsigned intFree = static_cast<unsigned>(heap_caps_get_free_size(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT));
1535
1697
  const unsigned intTotal = static_cast<unsigned>(heap_caps_get_total_size(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT));
@@ -1540,10 +1702,13 @@ void handleCommand(char *line, CommandSource source)
1540
1702
  const unsigned psramLargest = static_cast<unsigned>(heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
1541
1703
  const char *appId = gea::framework::apps::AppManager::currentId();
1542
1704
  std::printf(
1543
- "GEADEV:MEM app=%s internal_used=%u internal_free=%u internal_total=%u internal_largest=%u internal_min_free=%u psram_used=%u psram_free=%u psram_total=%u psram_largest=%u\n",
1705
+ "GEADEV:MEM app=%s internal_used=%u internal_free=%u internal_total=%u internal_largest=%u internal_min_free=%u psram_used=%u psram_free=%u psram_total=%u psram_largest=%u flush_rows=%d flush_depth=%d flush_bytes=%d\n",
1544
1706
  appId ? appId : "",
1545
1707
  intTotal - intFree, intFree, intTotal, intLargest, intMinFree,
1546
- psramTotal - psramFree, psramFree, psramTotal, psramLargest);
1708
+ psramTotal - psramFree, psramFree, psramTotal, psramLargest,
1709
+ gea::platform::display::Display::flushChunkRows(),
1710
+ gea::platform::display::Display::flushQueueDepth(),
1711
+ gea::platform::display::Display::flushBufferBytes());
1547
1712
  } else if (tokenEquals(command, "HEAPTRACE")) {
1548
1713
  #if CONFIG_HEAP_TRACING_STANDALONE
1549
1714
  // Allocate records only on demand, outside internal DMA RAM. Emit
@@ -1728,6 +1893,23 @@ void handleCommand(char *line, CommandSource source)
1728
1893
  handlePull(cursor);
1729
1894
  } else if (tokenEquals(command, "PLAYFILE")) {
1730
1895
  handlePlayFile(cursor);
1896
+ } else if (tokenEquals(command, "VP8BENCH")) {
1897
+ benchmarkVp8File(nextToken(cursor));
1898
+ } else if (tokenEquals(command, "VP8CAPTURE")) {
1899
+ const auto action = nextToken(cursor);
1900
+ if (tokenEquals(action, "START")) startVp8Capture();
1901
+ else if (tokenEquals(action, "SAVE")) saveVp8Capture();
1902
+ else if (tokenEquals(action, "CANCEL")) cancelVp8Capture();
1903
+ else std::puts("GEADEV:ERR VP8CAPTURE expected-start-save-or-cancel");
1904
+ } else if (tokenEquals(command, "OPUSBENCH")) {
1905
+ benchmarkOpus();
1906
+ } else if (tokenEquals(command, "SIMDBENCH")) {
1907
+ const auto mode = nextToken(cursor);
1908
+ benchmarkVideoSimd(tokenEquals(mode, "swap") ? 1 : tokenEquals(mode, "kernels") ? 2 : 0);
1909
+ } else if (tokenEquals(command, "PCMSIMD")) {
1910
+ checkPcmSimd();
1911
+ } else if (tokenEquals(command, "SRTPBENCH")) {
1912
+ benchmarkSrtp();
1731
1913
  } else if (tokenEquals(command, "BACK")) {
1732
1914
  const bool ok = gea::framework::apps::AppManager::returnRunningAppToLauncher("device control");
1733
1915
  std::printf("GEADEV:OK BACK returned=%d\n", ok ? 1 : 0);
@@ -1825,6 +2007,26 @@ class DeviceControlTask {
1825
2007
  public:
1826
2008
  static void run(void *)
1827
2009
  {
2010
+ #if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
2011
+ // The primary USB VFS otherwise uses a ROM/FIFO polling writer. It can
2012
+ // busy-spin for up to 50 ms while a log line drains, at the caller's
2013
+ // media priority. Use IDF's bounded driver rings and blocking waits, as
2014
+ // the secondary USB console already does. stdin blocks on RX instead
2015
+ // of polling; no extra console/network task is required.
2016
+ usb_serial_jtag_driver_config_t config = {
2017
+ .tx_buffer_size = 1024,
2018
+ .rx_buffer_size = 1024,
2019
+ };
2020
+ if (!usb_serial_jtag_is_driver_installed()) {
2021
+ const esp_err_t err = usb_serial_jtag_driver_install(&config);
2022
+ if (err != ESP_OK) {
2023
+ ESP_LOGE(kTag, "Failed to install primary USB console driver: %s", esp_err_to_name(err));
2024
+ vTaskDelete(nullptr);
2025
+ return;
2026
+ }
2027
+ }
2028
+ usb_serial_jtag_vfs_use_driver();
2029
+ #endif
1828
2030
  std::setvbuf(stdin, nullptr, _IONBF, 0);
1829
2031
  std::setvbuf(stdout, nullptr, _IONBF, 0);
1830
2032
  ESP_LOGI(kTag, "Device control ready: send 'GEADEV PING', 'GEADEV TAP x y', 'GEADEV BACK', or 'GEADEV SCREENSHOT'");
@@ -3,6 +3,7 @@
3
3
  #include "app.h"
4
4
  #include "display.h"
5
5
  #include "host/timers.h"
6
+ #include "host/worker.h"
6
7
  #include "ui/refresh_trace.h"
7
8
  #include "ui/refresh_perf.h"
8
9
  #include "ui/document.h"
@@ -20,6 +21,7 @@
20
21
  #include "freertos/FreeRTOS.h"
21
22
  #include "freertos/queue.h"
22
23
  #include "freertos/task.h"
24
+ #include "freertos/idf_additions.h"
23
25
 
24
26
  #if defined(GEA_EMBEDDED_FRAME_BENCHMARK) && GEA_EMBEDDED_FRAME_BENCHMARK
25
27
  extern "C" void gea_frame_benchmark_sample(int64_t start, int64_t done);
@@ -150,7 +152,14 @@ constexpr int kTaskStackWords = GEA_EMBEDDED_APP_FRAME_TASK_STACK_WORDS;
150
152
  #ifndef GEA_EMBEDDED_APP_FRAME_TASK_STACK_EXTERNAL
151
153
  #define GEA_EMBEDDED_APP_FRAME_TASK_STACK_EXTERNAL 0
152
154
  #endif
155
+ #if defined(GEA_EMBEDDED_APP_USES_AUDIO) && GEA_EMBEDDED_APP_USES_AUDIO && defined(GEA_EMBEDDED_RUNTIME_TASK_PRIORITY)
156
+ // The ticker takes AppState's mutex. If it outranks the media app's runtime,
157
+ // priority inheritance promotes the renderer above the JPEG/network workers
158
+ // for the entire render. Keep both sides of that lock at the app's priority.
159
+ constexpr int kTaskPriority = GEA_EMBEDDED_RUNTIME_TASK_PRIORITY;
160
+ #else
153
161
  constexpr int kTaskPriority = GEA_EMBEDDED_APP_FRAME_TASK_PRIORITY;
162
+ #endif
154
163
  #ifndef GEA_EMBEDDED_APP_FRAME_TASK_CORE
155
164
  // -1 = tskNO_AFFINITY (run on either core). Boards with BT/WiFi pinned to a
156
165
  // specific core can override this to put the frame task on the other core,
@@ -378,10 +387,17 @@ public:
378
387
  // The phase-set is kept (watchdog stall report); only the timing reads +
379
388
  // the perf accumulation around the real refresh are perf machinery.
380
389
  gea::framework::app::applicationFramePhaseSet(gea::framework::app::ApplicationFramePhase::RefreshMounted);
390
+ #if CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
391
+ const auto profileRefreshStart = esp_timer_get_time();
392
+ #endif
381
393
  #if GEA_EMBEDDED_FRAME_SCHEDULER_PERF_LOG
382
394
  const int64_t refreshStartUs = esp_timer_get_time();
383
395
  #endif
384
396
  gea::embedded::ui::Document::instance().refreshMountedIfDirty();
397
+ #if CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
398
+ const auto profileRefreshUs = esp_timer_get_time() - profileRefreshStart;
399
+ if (profileRefreshUs > 30000) ESP_LOGW("frame_phase", "render duration_ms=%lld", (long long)(profileRefreshUs / 1000));
400
+ #endif
385
401
  #if GEA_EMBEDDED_FRAME_SCHEDULER_PERF_LOG
386
402
  gea::framework::app::applicationFramePerfStatsAdd(
387
403
  gea::framework::app::ApplicationFramePhase::RefreshMounted,
@@ -1081,11 +1097,13 @@ private:
1081
1097
  const auto displayDetail = gea::platform::display::Display::flushStageDetail();
1082
1098
 
1083
1099
  ESP_LOGE(kTag,
1084
- "frame watchdog: seq=%lu stuck=%dms stage=%s app_phase=%s ui=%s/%d display=%s/%d rect=%d,%d-%d,%d rows=%d px=%d pending=%d internal_free=%u internal_largest=%u internal_min=%u psram_free=%u",
1100
+ "frame watchdog: seq=%lu stuck=%dms stage=%s app_phase=%s host_phase=%s worker_phase=%s ui=%s/%d display=%s/%d rect=%d,%d-%d,%d rows=%d px=%d pending=%d internal_free=%u internal_largest=%u internal_min=%u psram_free=%u",
1085
1101
  static_cast<unsigned long>(frameSequence_.load(std::memory_order_relaxed)),
1086
1102
  elapsedMs,
1087
1103
  stageName(frameStage()),
1088
1104
  gea::framework::app::applicationFramePhaseName(gea::framework::app::applicationFramePhaseRead()),
1105
+ gea::host::animationFrameCallbackStage(),
1106
+ gea::host::workers::Context::mainPendingStage(),
1089
1107
  gea::embedded::ui::refreshTraceStageName(),
1090
1108
  gea::embedded::ui::refreshTraceIndex(),
1091
1109
  gea::platform::display::Display::flushStageName(),
@@ -1101,6 +1119,23 @@ private:
1101
1119
  static_cast<unsigned>(heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT)),
1102
1120
  static_cast<unsigned>(heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT)),
1103
1121
  static_cast<unsigned>(heap_caps_get_free_size(MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT)));
1122
+ #if configUSE_TRACE_FACILITY && configGENERATE_RUN_TIME_STATS
1123
+ // Inspect scheduling without scanning large PSRAM task stacks. This is
1124
+ // diagnostic-only and does not alter priorities or interrupt execution.
1125
+ const char *names[] = {"main", "gea_runtime", "app_frame", "gea_mic",
1126
+ "gea_audio", "gea_rtc_loop", "gea_rtc_send", "gea_rtc_audio", "gea_rtc_video",
1127
+ "gea_rwrk", "juice", "tcpip", "wifi", "diag_srv", "gea_devctl", "gea_devctl_usb", "esp_timer", "gea_log", "IDLE0", "IDLE1"};
1128
+ for (const char *name : names) {
1129
+ if (auto task = xTaskGetHandle(name)) {
1130
+ TaskStatus_t status{};
1131
+ vTaskGetInfo(task, &status, pdFALSE, eInvalid);
1132
+ ESP_LOGW(kTag, "scheduler task=%s state=%u priority=%u base=%u cpu_us=%llu affinity=%d",
1133
+ name, unsigned(status.eCurrentState), unsigned(status.uxCurrentPriority),
1134
+ unsigned(status.uxBasePriority), (unsigned long long)status.ulRunTimeCounter,
1135
+ int(xTaskGetCoreID(task)));
1136
+ }
1137
+ }
1138
+ #endif
1104
1139
  }
1105
1140
 
1106
1141
  void queueFrameEvent()
@@ -0,0 +1,82 @@
1
+ // Offline codec measurement. No microphone, speaker, signaling or cloud session.
2
+ #pragma once
3
+ #include <cstdio>
4
+
5
+ #if GEA_EMBEDDED_APP_USES_AUDIO && __has_include("esp_opus_enc.h")
6
+ #include "host/rtc_opus.h"
7
+ #include "esp_timer.h"
8
+ #include "esp_heap_caps.h"
9
+ #include "freertos/idf_additions.h"
10
+ #include "freertos/semphr.h"
11
+
12
+ namespace gea::platform::esp32::services {
13
+ inline void benchmarkOpus() {
14
+ struct Job { SemaphoreHandle_t done; } job{xSemaphoreCreateBinary()};
15
+ if (!job.done) {
16
+ std::printf("GEADEV:ERR OPUSBENCH semaphore-allocation\n");
17
+ return;
18
+ }
19
+ const auto run = [](void* context) {
20
+ auto& job = *static_cast<Job*>(context);
21
+ try {
22
+ using Codec = gea::host::rtc::OpusAudio;
23
+ for (const auto mode : {Codec::Application::LowDelay, Codec::Application::Voice}) {
24
+ Codec codec(mode);
25
+ alignas(16) std::array<int16_t, Codec::frameSamples> pcm{};
26
+ uint64_t encodeUs = 0, decodeUs = 0, maxEncodeUs = 0;
27
+ uint32_t random = 1, totalBytes = 0;
28
+ constexpr unsigned frames = 25;
29
+ const auto started = esp_timer_get_time();
30
+ for (unsigned frame = 0; frame < frames; ++frame) {
31
+ // Periodic voiced signal plus deterministic low-level noise. Avoid
32
+ // benchmarking only silence, whose codec cost is not representative.
33
+ for (unsigned i = 0; i < pcm.size(); ++i) {
34
+ random = random * 1664525u + 1013904223u;
35
+ const int phase = (frame * pcm.size() + i) % 160;
36
+ pcm[i] = int16_t((phase < 80 ? phase - 40 : 120 - phase) * 80
37
+ + int(random >> 24) - 128);
38
+ }
39
+ auto before = esp_timer_get_time();
40
+ const auto size = codec.encode(pcm.data());
41
+ const uint64_t elapsed = esp_timer_get_time() - before;
42
+ encodeUs += elapsed;
43
+ if (elapsed > maxEncodeUs) maxEncodeUs = elapsed;
44
+ if (size <= 0) throw std::runtime_error("encode-failed");
45
+ totalBytes += size;
46
+ before = esp_timer_get_time();
47
+ if (codec.decode(codec.packet.data(), size) != Codec::frameSamples)
48
+ throw std::runtime_error("decode-failed");
49
+ decodeUs += esp_timer_get_time() - before;
50
+ vTaskDelay(1);
51
+ }
52
+ std::printf("GEADEV:OPUSBENCH mode=%s rate=%d bitrate=24000 frame_ms=%d complexity=0 frames=%u encode_avg_us=%llu encode_max_us=%llu decode_avg_us=%llu elapsed_us=%lld bytes=%u\n",
53
+ mode == Codec::Application::LowDelay ? "lowdelay" : "voice", Codec::sampleRate,
54
+ Codec::frameDurationMs, frames, (unsigned long long)(encodeUs / frames),
55
+ (unsigned long long)maxEncodeUs, (unsigned long long)(decodeUs / frames),
56
+ (long long)(esp_timer_get_time() - started), unsigned(totalBytes));
57
+ }
58
+ std::printf("GEADEV:OPUSBENCH END\n");
59
+ } catch (const std::exception& error) {
60
+ std::printf("GEADEV:ERR OPUSBENCH %s\n", error.what());
61
+ }
62
+ std::fflush(stdout);
63
+ xSemaphoreGive(job.done);
64
+ for (;;) vTaskSuspend(nullptr);
65
+ };
66
+ TaskHandle_t task = nullptr;
67
+ if (xTaskCreatePinnedToCoreWithCaps(run, "gea_opus_bench", 64 * 1024, &job, 5, &task, 1,
68
+ MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT) != pdPASS) {
69
+ std::printf("GEADEV:ERR OPUSBENCH task-allocation\n");
70
+ } else {
71
+ xSemaphoreTake(job.done, portMAX_DELAY);
72
+ while (eTaskGetState(task) != eSuspended) vTaskDelay(1);
73
+ vTaskDeleteWithCaps(task);
74
+ }
75
+ vSemaphoreDelete(job.done);
76
+ }
77
+ } // namespace gea::platform::esp32::services
78
+ #else
79
+ namespace gea::platform::esp32::services {
80
+ inline void benchmarkOpus() { std::printf("GEADEV:ERR OPUSBENCH unavailable\n"); }
81
+ }
82
+ #endif
@@ -0,0 +1,73 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+
4
+ #include "sdkconfig.h"
5
+ #include <cstddef>
6
+ #include <cstdint>
7
+ #include <cstdio>
8
+ #include <cstring>
9
+ #include "esp_timer.h"
10
+
11
+ #if defined(__XTENSA__) && defined(CONFIG_IDF_TARGET_ESP32S3) && CONFIG_IDF_TARGET_ESP32S3 && __has_include("gea_pcm.h")
12
+ #include "gea_pcm.h"
13
+
14
+ // Exercise the exact generated runtime artifact through the framework's
15
+ // normal app include directory. This performs no audio I/O or background work.
16
+ inline void checkPcmSimd() {
17
+ alignas(16) float input[40];
18
+ alignas(16) std::int16_t output[48];
19
+ constexpr std::uint32_t boundaries[] = {
20
+ 0, 0x80000000, 1, 0x80000001, 0x007fffff, 0x807fffff,
21
+ 0x377fffff, 0x37800000, 0x37800001, 0xb77fffff, 0xb7800000, 0xb7800001,
22
+ 0x3f7fffff, 0x3f800000, 0x3f800001, 0xbf7fffff, 0xbf800000, 0xbf800001,
23
+ 0x7f800000, 0xff800000, 0x7f800001, 0xff800001, 0x7fc00000, 0xffffffff,
24
+ // Half-integer PCM boundaries and adjacent Float32 encodings.
25
+ 0x3f0000ff, 0x3f000100, 0x3f000101, 0xbf00007f, 0xbf000080, 0xbf000081,
26
+ 0x3d8000ff, 0x3d800100, 0x3d800101, 0xbd8003ff, 0xbd800400, 0xbd800401};
27
+ constexpr std::size_t lengths[] = {0, 1, 7, 8, 9, 15, 16, 17, 31, 32};
28
+ std::size_t samples = 0;
29
+ std::uint32_t random = 0x713ba549;
30
+ const auto started = esp_timer_get_time();
31
+ for (unsigned dataset = 0; dataset < 2; ++dataset) {
32
+ for (std::size_t inOffset = 0; inOffset < 4; ++inOffset) {
33
+ for (std::size_t outOffset = 0; outOffset < 8; ++outOffset) {
34
+ for (auto count : lengths) {
35
+ for (std::size_t i = 0; i < 40; ++i) {
36
+ random ^= random << 13; random ^= random >> 17; random ^= random << 5;
37
+ // Mix arbitrary IEEE encodings with values in the active audio
38
+ // range so random cases do not mostly become zero/saturation.
39
+ const auto bits = dataset == 0 ? boundaries[(i + outOffset) % 36] :
40
+ (i & 1) ? random : (random & 0x807fffffU) | ((111U + ((random >> 24) & 15U)) << 23);
41
+ std::memcpy(&input[i], &bits, sizeof(bits));
42
+ }
43
+ for (auto& value : output) value = 12345;
44
+ gea::runtime::audio::float32ToPcm16(input + inOffset, output + outOffset, count);
45
+ for (std::size_t i = 0; i < count; ++i) {
46
+ const auto expected = gea::runtime::audio::detail::pcm16Sample(input[inOffset + i]);
47
+ const auto actual = output[outOffset + i];
48
+ ++samples;
49
+ if (actual != expected) {
50
+ std::uint32_t bits;
51
+ std::memcpy(&bits, &input[inOffset + i], sizeof(bits));
52
+ std::printf("GEADEV:PCMSIMD ERR bits=%08lx actual=%d expected=%d input_offset=%u output_offset=%u count=%u index=%u\n",
53
+ static_cast<unsigned long>(bits), int(actual), int(expected),
54
+ unsigned(inOffset), unsigned(outOffset), unsigned(count), unsigned(i));
55
+ return;
56
+ }
57
+ }
58
+ for (std::size_t i = 0; i < 48; ++i) {
59
+ if ((i < outOffset || i >= outOffset + count) && output[i] != 12345) {
60
+ std::printf("GEADEV:PCMSIMD ERR guard index=%u\n", unsigned(i));
61
+ return;
62
+ }
63
+ }
64
+ }
65
+ }
66
+ }
67
+ }
68
+ std::printf("GEADEV:PCMSIMD OK simd=1 samples=%u elapsed_us=%lld\n",
69
+ unsigned(samples), static_cast<long long>(esp_timer_get_time() - started));
70
+ }
71
+ #else
72
+ inline void checkPcmSimd() { std::puts("GEADEV:PCMSIMD ERR unavailable"); }
73
+ #endif
@@ -0,0 +1,106 @@
1
+ // Offline authenticated RTP measurement. No sockets or cloud session.
2
+ #pragma once
3
+ #include <cstdio>
4
+
5
+ #if GEA_EMBEDDED_APP_USES_AUDIO && __has_include("srtp.h")
6
+ #include "srtp.h"
7
+ #include "esp_timer.h"
8
+ #include "esp_heap_caps.h"
9
+ #include "freertos/idf_additions.h"
10
+ #include "freertos/semphr.h"
11
+ #include <array>
12
+ #include <cstring>
13
+ #include <stdexcept>
14
+
15
+ namespace gea::platform::esp32::services {
16
+ inline void benchmarkSrtp() {
17
+ struct Job { SemaphoreHandle_t done; } job{xSemaphoreCreateBinary()};
18
+ if (!job.done) {
19
+ std::printf("GEADEV:ERR SRTPBENCH semaphore-allocation\n");
20
+ return;
21
+ }
22
+ const auto run = [](void* context) {
23
+ auto& job = *static_cast<Job*>(context);
24
+ try {
25
+ struct Session {
26
+ srtp_t value = nullptr;
27
+ ~Session() { if (value) srtp_dealloc(value); }
28
+ };
29
+ if (srtp_init() != srtp_err_status_ok) throw std::runtime_error("init-failed");
30
+ for (const unsigned payloadSize : {120u, 1200u}) {
31
+ std::array<uint8_t, 30> key{};
32
+ for (unsigned i = 0; i < key.size(); ++i) key[i] = uint8_t(i);
33
+ srtp_policy_t policy{};
34
+ srtp_crypto_policy_set_rtp_default(&policy.rtp);
35
+ srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
36
+ policy.ssrc.type = ssrc_specific;
37
+ policy.ssrc.value = 0x12345678;
38
+ policy.key = key.data();
39
+ policy.window_size = 128;
40
+ Session sender, receiver;
41
+ if (srtp_create(&sender.value, &policy) != srtp_err_status_ok ||
42
+ srtp_create(&receiver.value, &policy) != srtp_err_status_ok)
43
+ throw std::runtime_error("session-allocation");
44
+ std::array<uint8_t, 1400> plain{}, protectedPacket{}, decoded{};
45
+ const unsigned packetSize = payloadSize + 12;
46
+ for (unsigned i = 12; i < packetSize; ++i) plain[i] = uint8_t(i * 17);
47
+ plain[0] = 0x80; plain[1] = 101;
48
+ plain[8] = 0x12; plain[9] = 0x34; plain[10] = 0x56; plain[11] = 0x78;
49
+ uint64_t protectUs = 0, unprotectUs = 0;
50
+ constexpr unsigned packets = 100;
51
+ for (unsigned i = 0; i < packets; ++i) {
52
+ plain[2] = uint8_t(i >> 8); plain[3] = uint8_t(i);
53
+ size_t protectedSize = protectedPacket.size();
54
+ auto before = esp_timer_get_time();
55
+ if (srtp_protect(sender.value, plain.data(), packetSize, protectedPacket.data(),
56
+ &protectedSize, 0) != srtp_err_status_ok)
57
+ throw std::runtime_error("protect-failed");
58
+ protectUs += esp_timer_get_time() - before;
59
+ size_t decodedSize = decoded.size();
60
+ if (!i) {
61
+ // Authentication failure must not consume the sequence number.
62
+ protectedPacket[protectedSize - 1] ^= 1;
63
+ if (srtp_unprotect(receiver.value, protectedPacket.data(), protectedSize,
64
+ decoded.data(), &decodedSize) != srtp_err_status_auth_fail)
65
+ throw std::runtime_error("tampered-packet-accepted");
66
+ protectedPacket[protectedSize - 1] ^= 1;
67
+ decodedSize = decoded.size();
68
+ }
69
+ before = esp_timer_get_time();
70
+ if (srtp_unprotect(receiver.value, protectedPacket.data(), protectedSize,
71
+ decoded.data(), &decodedSize) != srtp_err_status_ok)
72
+ throw std::runtime_error("unprotect-failed");
73
+ unprotectUs += esp_timer_get_time() - before;
74
+ if (decodedSize != packetSize || std::memcmp(plain.data(), decoded.data(), packetSize))
75
+ throw std::runtime_error("roundtrip-mismatch");
76
+ vTaskDelay(1);
77
+ }
78
+ std::printf("GEADEV:SRTPBENCH payload_bytes=%u packets=%u protect_avg_us=%llu unprotect_avg_us=%llu roundtrip=ok tamper=rejected\n",
79
+ payloadSize, packets, (unsigned long long)(protectUs / packets),
80
+ (unsigned long long)(unprotectUs / packets));
81
+ }
82
+ std::printf("GEADEV:SRTPBENCH END\n");
83
+ } catch (const std::exception& error) {
84
+ std::printf("GEADEV:ERR SRTPBENCH %s\n", error.what());
85
+ }
86
+ std::fflush(stdout);
87
+ xSemaphoreGive(job.done);
88
+ for (;;) vTaskSuspend(nullptr);
89
+ };
90
+ TaskHandle_t task = nullptr;
91
+ if (xTaskCreatePinnedToCoreWithCaps(run, "gea_srtp_bench", 24 * 1024, &job, 7, &task, 1,
92
+ MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT) != pdPASS) {
93
+ std::printf("GEADEV:ERR SRTPBENCH task-allocation\n");
94
+ } else {
95
+ xSemaphoreTake(job.done, portMAX_DELAY);
96
+ while (eTaskGetState(task) != eSuspended) vTaskDelay(1);
97
+ vTaskDeleteWithCaps(task);
98
+ }
99
+ vSemaphoreDelete(job.done);
100
+ }
101
+ } // namespace gea::platform::esp32::services
102
+ #else
103
+ namespace gea::platform::esp32::services {
104
+ inline void benchmarkSrtp() { std::printf("GEADEV:ERR SRTPBENCH unavailable\n"); }
105
+ }
106
+ #endif