@geastack/host 0.1.14 → 0.1.16
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.
- package/README.md +6 -0
- package/audio_runtime.cpp +183 -98
- package/host/audio.cpp +47 -24
- package/host/audio_buffer_runtime.cpp +117 -0
- package/host/audio_worklet.cpp +29 -17
- package/host/camera.cpp +34 -1
- package/host/device.cpp +36 -0
- package/host/http.cpp +155 -56
- package/host/image.cpp +188 -97
- package/host/media.cpp +18 -6
- package/host/mjpeg.cpp +1 -1
- package/host/rtc.cpp +1 -1
- package/host/rtc_esp.cpp +2 -2
- package/host/timers.cpp +2 -2
- package/host/websocket.cpp +7 -5
- package/host/wifi.cpp +30 -32
- package/include/gea/audio-worklet-runtime.h +4 -3
- package/include/gea/http-native-runtime.h +127 -0
- package/include/host/audio.h +84 -13
- package/include/host/backends.h +88 -51
- package/include/host/battery.h +10 -0
- package/include/host/camera.h +1 -0
- package/include/host/camera_frame.h +69 -0
- package/include/host/clock.h +6 -0
- package/include/host/http.h +80 -20
- package/include/host/image.h +1 -0
- package/include/host/navigator.h +238 -89
- package/include/host/storage.h +9 -6
- package/include/host/timers.h +2 -5
- package/include/host/websocket.h +43 -3
- package/include/platform/internal_stack.h +89 -0
- package/input.cpp +57 -33
- package/package.json +1 -1
- package/wifi.cpp +140 -121
package/host/image.cpp
CHANGED
|
@@ -8,11 +8,13 @@
|
|
|
8
8
|
#endif
|
|
9
9
|
#include "host/image.h"
|
|
10
10
|
|
|
11
|
-
#include "image.h"
|
|
12
|
-
#include "gea/embedded-host.h"
|
|
13
11
|
#include "display.h"
|
|
14
|
-
#include "host
|
|
12
|
+
#include "gea/embedded-host.h"
|
|
13
|
+
#include "host/fetch.h" // gea::host::fetch for fetchBytes/fetchText (WiFi tile download)
|
|
14
|
+
#include "image.h"
|
|
15
|
+
#include "platform/atomic_file.h"
|
|
15
16
|
#include "platform/file_cache.h"
|
|
17
|
+
#include "platform/internal_stack.h"
|
|
16
18
|
|
|
17
19
|
#ifdef GEA_IMAGE_RESTORE_CPP_VALUE_AVAILABLE
|
|
18
20
|
#define GEA_CPP_VALUE_AVAILABLE 1
|
|
@@ -23,18 +25,24 @@
|
|
|
23
25
|
#include <cstdint>
|
|
24
26
|
#include <cstdio>
|
|
25
27
|
#include <cstring>
|
|
26
|
-
#include <dirent.h>
|
|
27
28
|
#include <sys/stat.h>
|
|
28
29
|
#include <unordered_map>
|
|
29
30
|
#include <vector>
|
|
30
31
|
|
|
32
|
+
// Bare-metal newlib (RP2350's arm-none-eabi) ships a <dirent.h> that #errors;
|
|
33
|
+
// there is no directory API to list there.
|
|
34
|
+
#if defined(ESP_PLATFORM) || defined(__unix__) || defined(__APPLE__)
|
|
35
|
+
#define GEA_HOST_HAS_DIRENT 1
|
|
36
|
+
#include <dirent.h>
|
|
37
|
+
#endif
|
|
38
|
+
|
|
31
39
|
#ifdef ESP_PLATFORM
|
|
32
|
-
#include "esp_partition.h" // readMapArchive() reads a .pmtiles flashed to ota_1
|
|
33
40
|
#include "esp_heap_caps.h"
|
|
41
|
+
#include "esp_partition.h" // readMapArchive() reads a .pmtiles flashed to ota_1
|
|
34
42
|
#include "freertos/FreeRTOS.h"
|
|
35
|
-
#include "freertos/
|
|
36
|
-
#include "freertos/idf_additions.h" // xTaskCreateWithCaps (force internal stack)
|
|
43
|
+
#include "freertos/idf_additions.h" // xTaskCreateWithCaps (force internal stack)
|
|
37
44
|
#include "freertos/semphr.h"
|
|
45
|
+
#include "freertos/task.h"
|
|
38
46
|
#endif
|
|
39
47
|
|
|
40
48
|
namespace gea::platform::storage {
|
|
@@ -43,14 +51,25 @@ namespace gea::platform::storage {
|
|
|
43
51
|
// keeps the provider's TU linked.
|
|
44
52
|
namespace {
|
|
45
53
|
bool (*g_mount_provider)() = nullptr;
|
|
46
|
-
|
|
54
|
+
bool (*g_fallback_mount_provider)() = nullptr;
|
|
55
|
+
} // namespace
|
|
47
56
|
void setMountProvider(bool (*provider)()) { g_mount_provider = provider; }
|
|
48
|
-
bool
|
|
49
|
-
|
|
57
|
+
void setFallbackMountProvider(bool (*provider)()) {
|
|
58
|
+
g_fallback_mount_provider = provider;
|
|
59
|
+
}
|
|
60
|
+
bool ensureMounted() {
|
|
61
|
+
auto provider =
|
|
62
|
+
g_mount_provider ? g_mount_provider : g_fallback_mount_provider;
|
|
63
|
+
return provider ? provider() : false;
|
|
64
|
+
}
|
|
65
|
+
} // namespace gea::platform::storage
|
|
50
66
|
|
|
51
67
|
namespace gea::host {
|
|
52
68
|
|
|
53
|
-
extern "C" bool gea_embedded_asset_lookup(const char *path,
|
|
69
|
+
extern "C" bool gea_embedded_asset_lookup(const char *path,
|
|
70
|
+
const unsigned char **data,
|
|
71
|
+
unsigned long *length)
|
|
72
|
+
__attribute__((weak));
|
|
54
73
|
|
|
55
74
|
namespace {
|
|
56
75
|
|
|
@@ -58,16 +77,17 @@ gea::framework::graphics::ImageStore &store() {
|
|
|
58
77
|
return gea::framework::graphics::ImageStore::instance();
|
|
59
78
|
}
|
|
60
79
|
|
|
61
|
-
int integer(double value) {
|
|
62
|
-
return static_cast<int>(value);
|
|
63
|
-
}
|
|
80
|
+
int integer(double value) { return static_cast<int>(value); }
|
|
64
81
|
|
|
65
|
-
// mkdir -p of the parent directories in `path` (FAT/VFS); existing dirs are
|
|
82
|
+
// mkdir -p of the parent directories in `path` (FAT/VFS); existing dirs are
|
|
83
|
+
// fine.
|
|
66
84
|
void makeParentDirs(const std::string &path) {
|
|
67
85
|
for (std::size_t i = 1; i < path.size(); i++) {
|
|
68
|
-
if (path[i] != '/')
|
|
86
|
+
if (path[i] != '/')
|
|
87
|
+
continue;
|
|
69
88
|
const std::string dir = path.substr(0, i);
|
|
70
|
-
if (!dir.empty())
|
|
89
|
+
if (!dir.empty())
|
|
90
|
+
::mkdir(dir.c_str(), 0777);
|
|
71
91
|
}
|
|
72
92
|
}
|
|
73
93
|
|
|
@@ -87,28 +107,32 @@ struct MapReadCtx {
|
|
|
87
107
|
void mapReadTask(void *arg) {
|
|
88
108
|
auto *c = static_cast<MapReadCtx *>(arg);
|
|
89
109
|
std::uint8_t hdr[127];
|
|
90
|
-
if (esp_partition_read(c->p, 0, hdr, sizeof(hdr)) == ESP_OK &&
|
|
110
|
+
if (esp_partition_read(c->p, 0, hdr, sizeof(hdr)) == ESP_OK &&
|
|
111
|
+
hdr[0] == 0x50 && hdr[1] == 0x4d) {
|
|
91
112
|
std::uint64_t off = 0;
|
|
92
113
|
std::uint64_t len = 0;
|
|
93
114
|
for (int i = 7; i >= 0; i--) {
|
|
94
|
-
off = off * 256 + hdr[56 + i];
|
|
95
|
-
len = len * 256 + hdr[64 + i];
|
|
115
|
+
off = off * 256 + hdr[56 + i]; // tile_data_offset (u64 LE @56)
|
|
116
|
+
len = len * 256 + hdr[64 + i]; // tile_data_length (u64 LE @64)
|
|
96
117
|
}
|
|
97
118
|
const std::uint64_t total = off + len;
|
|
98
119
|
if (total > 0 && total <= c->p->size) {
|
|
99
120
|
c->out->resize(static_cast<std::size_t>(total));
|
|
100
|
-
if (esp_partition_read(c->p, 0, c->out->data(),
|
|
121
|
+
if (esp_partition_read(c->p, 0, c->out->data(),
|
|
122
|
+
static_cast<std::size_t>(total)) != ESP_OK)
|
|
123
|
+
c->out->clear();
|
|
101
124
|
}
|
|
102
125
|
}
|
|
103
126
|
xSemaphoreGive(c->done);
|
|
104
|
-
vTaskDeleteWithCaps(nullptr);
|
|
127
|
+
vTaskDeleteWithCaps(nullptr); // matches xTaskCreateWithCaps allocation
|
|
105
128
|
}
|
|
106
129
|
#endif
|
|
107
130
|
|
|
108
131
|
std::vector<std::uint8_t> readWholeFile(const std::string &path) {
|
|
109
132
|
std::vector<std::uint8_t> out;
|
|
110
133
|
std::FILE *f = std::fopen(path.c_str(), "rb");
|
|
111
|
-
if (!f)
|
|
134
|
+
if (!f)
|
|
135
|
+
return out;
|
|
112
136
|
std::fseek(f, 0, SEEK_END);
|
|
113
137
|
const long size = std::ftell(f);
|
|
114
138
|
std::fseek(f, 0, SEEK_SET);
|
|
@@ -121,26 +145,31 @@ std::vector<std::uint8_t> readWholeFile(const std::string &path) {
|
|
|
121
145
|
return out;
|
|
122
146
|
}
|
|
123
147
|
|
|
124
|
-
}
|
|
148
|
+
} // namespace
|
|
125
149
|
|
|
126
150
|
double ImageService::loadBytes(std::vector<std::uint8_t> bytes) const {
|
|
127
|
-
const int id =
|
|
151
|
+
const int id =
|
|
152
|
+
store().decode(bytes.data(), static_cast<int>(bytes.size()), -1);
|
|
128
153
|
return static_cast<double>(id);
|
|
129
154
|
}
|
|
130
155
|
|
|
131
156
|
double ImageService::loadBytesOpaque(std::vector<std::uint8_t> bytes) const {
|
|
132
|
-
const int id =
|
|
157
|
+
const int id =
|
|
158
|
+
store().decodeOpaque(bytes.data(), static_cast<int>(bytes.size()), -1);
|
|
133
159
|
return static_cast<double>(id);
|
|
134
160
|
}
|
|
135
161
|
|
|
136
|
-
double ImageService::loadBytesPtr(const std::uint8_t *data,
|
|
137
|
-
|
|
162
|
+
double ImageService::loadBytesPtr(const std::uint8_t *data,
|
|
163
|
+
std::size_t length) const {
|
|
164
|
+
if (!data || length == 0)
|
|
165
|
+
return -1.0;
|
|
138
166
|
// One decode per asset; an <img> that remounts reuses the same slot instead
|
|
139
167
|
// of leaking a fresh decode each time. The embedded symbol address is stable,
|
|
140
168
|
// so it's a safe cache key.
|
|
141
169
|
static std::unordered_map<const void *, int> cache;
|
|
142
170
|
const auto cached = cache.find(data);
|
|
143
|
-
if (cached != cache.end())
|
|
171
|
+
if (cached != cache.end())
|
|
172
|
+
return static_cast<double>(cached->second);
|
|
144
173
|
// Embedded-asset bytes live in flash at a stable address: defer the
|
|
145
174
|
// decode to first draw so boot only pays for visible images.
|
|
146
175
|
const int id = store().decodeDeferred(data, static_cast<int>(length), -1);
|
|
@@ -149,50 +178,74 @@ double ImageService::loadBytesPtr(const std::uint8_t *data, std::size_t length)
|
|
|
149
178
|
}
|
|
150
179
|
|
|
151
180
|
double ImageService::loadAssetPath(const char *path) const {
|
|
152
|
-
if (!path)
|
|
181
|
+
if (!path)
|
|
182
|
+
return -1.0;
|
|
153
183
|
// First: a bundled/flash asset (the common <img src="/logo.png"> case).
|
|
154
184
|
if (gea_embedded_asset_lookup) {
|
|
155
185
|
const unsigned char *data = nullptr;
|
|
156
186
|
unsigned long length = 0;
|
|
157
|
-
if (gea_embedded_asset_lookup(path, &data, &length))
|
|
187
|
+
if (gea_embedded_asset_lookup(path, &data, &length))
|
|
188
|
+
return loadBytesPtr(data, static_cast<std::size_t>(length));
|
|
158
189
|
}
|
|
159
190
|
// Fallback: an absolute filesystem path (e.g. an EPUB cover extracted to the
|
|
160
191
|
// SD card). Lets `<img src="/sdcard/...">` show runtime images through the
|
|
161
192
|
// framework's own decode/render path instead of only bundled assets.
|
|
162
|
-
if (path[0] == '/')
|
|
193
|
+
if (path[0] == '/')
|
|
194
|
+
return loadFile(std::string(path));
|
|
163
195
|
return -1.0;
|
|
164
196
|
}
|
|
165
197
|
|
|
166
198
|
double ImageService::loadFile(const std::string &path) const {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
return static_cast<double>(
|
|
199
|
+
const std::vector<std::uint8_t> bytes = readFile(path);
|
|
200
|
+
if (bytes.empty())
|
|
201
|
+
return -1.0;
|
|
202
|
+
return static_cast<double>(
|
|
203
|
+
store().decode(bytes.data(), static_cast<int>(bytes.size()), -1));
|
|
171
204
|
}
|
|
172
205
|
|
|
173
206
|
double ImageService::loadFileOpaque(const std::string &path) const {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
return static_cast<double>(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
207
|
+
const std::vector<std::uint8_t> bytes = readFile(path);
|
|
208
|
+
if (bytes.empty())
|
|
209
|
+
return -1.0;
|
|
210
|
+
return static_cast<double>(
|
|
211
|
+
store().decodeOpaque(bytes.data(), static_cast<int>(bytes.size()), -1));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
bool ImageService::writeFile(const std::string &path,
|
|
215
|
+
const std::vector<std::uint8_t> &bytes) const {
|
|
216
|
+
bool result = false;
|
|
217
|
+
gea::platform::onInternalStack([&] {
|
|
218
|
+
if (path.empty() || bytes.empty() ||
|
|
219
|
+
!gea::platform::storage::ensureMounted())
|
|
220
|
+
return;
|
|
221
|
+
makeParentDirs(path);
|
|
222
|
+
gea::platform::storage::FileOperations files;
|
|
223
|
+
result = gea::platform::storage::writeFileAtomically(path, bytes, files);
|
|
224
|
+
});
|
|
225
|
+
return result;
|
|
188
226
|
}
|
|
189
227
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
228
|
+
bool ImageService::removeFile(const std::string &path) const {
|
|
229
|
+
bool result = false;
|
|
230
|
+
gea::platform::onInternalStack([&] {
|
|
231
|
+
if (!path.empty() && gea::platform::storage::ensureMounted())
|
|
232
|
+
result = std::remove(path.c_str()) == 0;
|
|
233
|
+
});
|
|
234
|
+
return result;
|
|
193
235
|
}
|
|
194
236
|
|
|
195
|
-
std::vector<std::uint8_t>
|
|
237
|
+
std::vector<std::uint8_t>
|
|
238
|
+
ImageService::readFile(const std::string &path) const {
|
|
239
|
+
std::vector<std::uint8_t> result;
|
|
240
|
+
gea::platform::onInternalStack([&] {
|
|
241
|
+
if (!path.empty() && gea::platform::storage::ensureMounted())
|
|
242
|
+
result = readWholeFile(path);
|
|
243
|
+
});
|
|
244
|
+
return result;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
std::vector<std::uint8_t>
|
|
248
|
+
ImageService::fetchBytes(const std::string &url) const {
|
|
196
249
|
// Synchronous HTTP GET over WiFi (blocks the calling task until the body is
|
|
197
250
|
// in), returning the raw bytes — e.g. one MVT tile. Empty when WiFi is down
|
|
198
251
|
// or the request fails.
|
|
@@ -203,42 +256,53 @@ std::string ImageService::fetchText(const std::string &url) const {
|
|
|
203
256
|
return gea::host::fetch(url).text();
|
|
204
257
|
}
|
|
205
258
|
|
|
206
|
-
std::vector<std::uint8_t> ImageService::readFileRange(const std::string &path,
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
259
|
+
std::vector<std::uint8_t> ImageService::readFileRange(const std::string &path,
|
|
260
|
+
double offset,
|
|
261
|
+
double length) const {
|
|
262
|
+
std::vector<std::uint8_t> out;
|
|
263
|
+
gea::platform::onInternalStack([&] {
|
|
264
|
+
if (path.empty() || offset < 0 || length <= 0 ||
|
|
265
|
+
!gea::platform::storage::ensureMounted())
|
|
266
|
+
return;
|
|
267
|
+
std::FILE *f = std::fopen(path.c_str(), "rb");
|
|
268
|
+
if (!f)
|
|
269
|
+
return;
|
|
270
|
+
if (std::fseek(f, static_cast<long>(offset), SEEK_SET) == 0) {
|
|
271
|
+
out.resize(static_cast<std::size_t>(length));
|
|
272
|
+
out.resize(std::fread(out.data(), 1, out.size(), f));
|
|
273
|
+
}
|
|
274
|
+
std::fclose(f);
|
|
275
|
+
});
|
|
219
276
|
return out;
|
|
220
277
|
}
|
|
221
278
|
|
|
222
279
|
std::string ImageService::listFiles(const std::string &path) const {
|
|
223
|
-
if (path.empty() || !gea::platform::storage::ensureMounted()) return {};
|
|
224
|
-
DIR *dir = opendir(path.c_str());
|
|
225
|
-
if (!dir) return {};
|
|
226
280
|
std::string out;
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
if (
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
281
|
+
gea::platform::onInternalStack([&] {
|
|
282
|
+
if (path.empty() || !gea::platform::storage::ensureMounted())
|
|
283
|
+
return;
|
|
284
|
+
#ifdef GEA_HOST_HAS_DIRENT
|
|
285
|
+
DIR *dir = opendir(path.c_str());
|
|
286
|
+
if (!dir)
|
|
287
|
+
return;
|
|
288
|
+
while (const dirent *entry = readdir(dir)) {
|
|
289
|
+
if (entry->d_name[0] == '.')
|
|
290
|
+
continue;
|
|
291
|
+
bool regular = entry->d_type == DT_REG;
|
|
292
|
+
if (entry->d_type == DT_UNKNOWN) {
|
|
293
|
+
struct stat st{};
|
|
294
|
+
const std::string full = path + "/" + entry->d_name;
|
|
295
|
+
regular = stat(full.c_str(), &st) == 0 && S_ISREG(st.st_mode);
|
|
296
|
+
}
|
|
297
|
+
if (!regular)
|
|
298
|
+
continue;
|
|
299
|
+
if (!out.empty())
|
|
300
|
+
out += '\n';
|
|
301
|
+
out += entry->d_name;
|
|
236
302
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
closedir(dir);
|
|
303
|
+
closedir(dir);
|
|
304
|
+
#endif
|
|
305
|
+
});
|
|
242
306
|
return out;
|
|
243
307
|
}
|
|
244
308
|
|
|
@@ -249,17 +313,20 @@ std::vector<std::uint8_t> ImageService::readMapArchive() const {
|
|
|
249
313
|
// from the PMTiles header: tile_data_offset + tile_data_length). Empty off
|
|
250
314
|
// esp32 or when no valid archive is present.
|
|
251
315
|
#ifdef ESP_PLATFORM
|
|
252
|
-
const esp_partition_t *p =
|
|
253
|
-
|
|
254
|
-
if (!p)
|
|
316
|
+
const esp_partition_t *p = esp_partition_find_first(
|
|
317
|
+
ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, nullptr);
|
|
318
|
+
if (!p)
|
|
319
|
+
return {};
|
|
255
320
|
std::vector<std::uint8_t> out;
|
|
256
321
|
SemaphoreHandle_t done = xSemaphoreCreateBinary();
|
|
257
|
-
if (!done)
|
|
322
|
+
if (!done)
|
|
323
|
+
return {};
|
|
258
324
|
MapReadCtx ctx{p, &out, done};
|
|
259
325
|
TaskHandle_t task = nullptr;
|
|
260
326
|
// 8 KB INTERNAL-RAM stack: a flash read disables the cache, so the reading
|
|
261
327
|
// task's stack must not be in PSRAM (the app's own task stack is).
|
|
262
|
-
if (xTaskCreateWithCaps(&mapReadTask, "map_read", 8192, &ctx, 6, &task,
|
|
328
|
+
if (xTaskCreateWithCaps(&mapReadTask, "map_read", 8192, &ctx, 6, &task,
|
|
329
|
+
MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT) == pdPASS) {
|
|
263
330
|
xSemaphoreTake(done, portMAX_DELAY);
|
|
264
331
|
}
|
|
265
332
|
vSemaphoreDelete(done);
|
|
@@ -271,13 +338,16 @@ std::vector<std::uint8_t> ImageService::readMapArchive() const {
|
|
|
271
338
|
|
|
272
339
|
void ImageService::draw(double id, double x, double y) const {
|
|
273
340
|
const int slot = integer(id);
|
|
274
|
-
const gea::framework::graphics::pixel::native_t *pixels =
|
|
275
|
-
|
|
341
|
+
const gea::framework::graphics::pixel::native_t *pixels =
|
|
342
|
+
store().currentPixels(slot);
|
|
343
|
+
if (!pixels)
|
|
344
|
+
return;
|
|
276
345
|
|
|
277
346
|
const unsigned char *alpha = store().currentAlpha(slot);
|
|
278
347
|
const int width = store().width(slot);
|
|
279
348
|
const int height = store().height(slot);
|
|
280
|
-
gea::platform::display::Display::blitImage(pixels, alpha, width, height,
|
|
349
|
+
gea::platform::display::Display::blitImage(pixels, alpha, width, height,
|
|
350
|
+
integer(x), integer(y));
|
|
281
351
|
}
|
|
282
352
|
|
|
283
353
|
double ImageService::width(double id) const {
|
|
@@ -308,9 +378,7 @@ bool ImageService::advance(double id, double deltaMs) const {
|
|
|
308
378
|
return store().advance(integer(id), integer(deltaMs));
|
|
309
379
|
}
|
|
310
380
|
|
|
311
|
-
void ImageService::dispose(double id) const {
|
|
312
|
-
store().dispose(integer(id));
|
|
313
|
-
}
|
|
381
|
+
void ImageService::dispose(double id) const { store().dispose(integer(id)); }
|
|
314
382
|
|
|
315
383
|
GeaEmbeddedImage ImageService::make(double id) const {
|
|
316
384
|
const int slot = integer(id);
|
|
@@ -323,14 +391,37 @@ GeaEmbeddedImage ImageService::make(double id) const {
|
|
|
323
391
|
return handle;
|
|
324
392
|
}
|
|
325
393
|
|
|
326
|
-
bool GeaEmbeddedImage::decode() const {
|
|
394
|
+
bool GeaEmbeddedImage::decode() const {
|
|
395
|
+
return store().currentPixels(id) != nullptr;
|
|
396
|
+
}
|
|
327
397
|
void GeaEmbeddedImage::play() const { store().setPlaying(id, true); }
|
|
328
398
|
void GeaEmbeddedImage::pause() const { store().setPlaying(id, false); }
|
|
329
399
|
void GeaEmbeddedImage::seek(int frame) const { store().seek(id, frame); }
|
|
330
400
|
void GeaEmbeddedImage::dispose() const { store().dispose(id); }
|
|
331
401
|
|
|
332
|
-
}
|
|
402
|
+
} // namespace gea::host
|
|
333
403
|
|
|
334
404
|
extern "C" double gea_host_image_load_asset_path(const char *path) {
|
|
335
405
|
return gea::host::image.loadAssetPath(path);
|
|
336
406
|
}
|
|
407
|
+
|
|
408
|
+
// The src loader owns filesystem decodes only until the node takes its pin.
|
|
409
|
+
// Bundled decodes remain in the stable flash-asset cache.
|
|
410
|
+
extern "C" double gea_host_image_acquire_asset_path(const char *path, bool *owned) {
|
|
411
|
+
*owned = false;
|
|
412
|
+
if (!path) return -1.0;
|
|
413
|
+
if (gea::host::gea_embedded_asset_lookup) {
|
|
414
|
+
const unsigned char *data = nullptr;
|
|
415
|
+
unsigned long length = 0;
|
|
416
|
+
if (gea::host::gea_embedded_asset_lookup(path, &data, &length))
|
|
417
|
+
return gea::host::image.loadBytesPtr(data, length);
|
|
418
|
+
}
|
|
419
|
+
if (path[0] != '/') return -1.0;
|
|
420
|
+
const int id = static_cast<int>(gea::host::image.loadFile(path));
|
|
421
|
+
auto &images = gea::framework::graphics::ImageStore::instance();
|
|
422
|
+
if (id >= 0 && images.retain(id)) {
|
|
423
|
+
*owned = true;
|
|
424
|
+
images.dispose(id);
|
|
425
|
+
}
|
|
426
|
+
return id;
|
|
427
|
+
}
|
package/host/media.cpp
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
#include "host/media.h"
|
|
3
|
+
#include "audio.h"
|
|
3
4
|
#include "host/pcm_stream.h"
|
|
5
|
+
#include "host/worker.h"
|
|
4
6
|
|
|
5
7
|
#include <algorithm>
|
|
6
8
|
#include <atomic>
|
|
@@ -106,7 +108,7 @@ struct RecorderState {
|
|
|
106
108
|
std::string path;
|
|
107
109
|
std::string mimeType = "audio/wav";
|
|
108
110
|
std::vector<std::int16_t> pcm;
|
|
109
|
-
double sampleRate =
|
|
111
|
+
double sampleRate = gea::platform::audio::deviceSampleRate;
|
|
110
112
|
double channels = 1.0;
|
|
111
113
|
FILE *file = nullptr;
|
|
112
114
|
std::size_t samplesWritten = 0;
|
|
@@ -156,12 +158,12 @@ std::string formatHandleId(const char *prefix, std::uint32_t handle) {
|
|
|
156
158
|
}
|
|
157
159
|
|
|
158
160
|
constexpr std::size_t kCaptureChunkSamples = 2048;
|
|
159
|
-
// Eight seconds at the capture driver's
|
|
160
|
-
// consumer falls behind
|
|
161
|
-
constexpr std::size_t kMaxRingBufferSamples = 8 *
|
|
161
|
+
// Eight seconds at the capture driver's configured device rate. Storage grows
|
|
162
|
+
// only when a consumer falls behind, using PSRAM instead of I2S DMA memory.
|
|
163
|
+
constexpr std::size_t kMaxRingBufferSamples = 8 * gea::platform::audio::deviceSampleRate;
|
|
162
164
|
constexpr std::size_t kRecorderFlushSamples = kCaptureChunkSamples;
|
|
163
165
|
constexpr unsigned kMaxDefaultRecordingNames = 1000;
|
|
164
|
-
constexpr double kDefaultRecorderSampleRate =
|
|
166
|
+
constexpr double kDefaultRecorderSampleRate = gea::platform::audio::deviceSampleRate;
|
|
165
167
|
|
|
166
168
|
#ifdef ESP_PLATFORM
|
|
167
169
|
constexpr const char *kMediaLogTag = "gea_media";
|
|
@@ -656,7 +658,17 @@ void TrackPcmReader::beginDrain() {
|
|
|
656
658
|
}
|
|
657
659
|
|
|
658
660
|
NativeMediaStreamHandle get_user_media_audio() {
|
|
659
|
-
|
|
661
|
+
const auto handle = create_stream();
|
|
662
|
+
const auto owner = workers::Context::current();
|
|
663
|
+
if (!owner->isMain()) {
|
|
664
|
+
try {
|
|
665
|
+
owner->addCleanup([handle] { destroy_stream(handle); });
|
|
666
|
+
} catch (...) {
|
|
667
|
+
destroy_stream(handle);
|
|
668
|
+
throw;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
return handle;
|
|
660
672
|
}
|
|
661
673
|
|
|
662
674
|
NativeMediaRecorderHandle create_recorder(NativeMediaStreamHandle stream, const std::string &path, const std::string &mimeType) {
|
package/host/mjpeg.cpp
CHANGED
|
@@ -17,7 +17,7 @@ extern "C" void gea_mjpeg_link_bindings() {}
|
|
|
17
17
|
#if defined(ESP_PLATFORM) && !defined(GEA_EMBEDDED_WIFI_DISABLED) && __has_include("esp_jpeg_dec.h")
|
|
18
18
|
#include "esp_http_client.h"
|
|
19
19
|
#include "esp_jpeg_dec.h"
|
|
20
|
-
#if __has_include("esp_h264_dec_sw.h")
|
|
20
|
+
#if !defined(GEA_EMBEDDED_H264_UNUSED) && __has_include("esp_h264_dec_sw.h")
|
|
21
21
|
#include "host/rtc_h264.h"
|
|
22
22
|
#define GEA_HAS_MULTIPART_H264 1
|
|
23
23
|
#endif
|
package/host/rtc.cpp
CHANGED
|
@@ -220,7 +220,7 @@ std::unordered_map<NativeRtcPeerHandle, CallbackTable> &callbackTable() {
|
|
|
220
220
|
return *table;
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
-
#if defined(ESP_PLATFORM) && !defined(GEA_EMBEDDED_WIFI_DISABLED)
|
|
223
|
+
#if defined(ESP_PLATFORM) && !defined(GEA_EMBEDDED_WIFI_DISABLED) && !defined(GEA_EMBEDDED_RTC_UNUSED)
|
|
224
224
|
void platform_request_description(NativeRtcPeerHandle, bool, std::shared_ptr<DescriptionResult>);
|
|
225
225
|
void platform_create(NativeRtcPeerHandle, const RTCConfiguration &);
|
|
226
226
|
void platform_direction(NativeRtcPeerHandle, const std::string&, const std::string&);
|
package/host/rtc_esp.cpp
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
#
|
|
2
|
+
#if defined(ESP_PLATFORM) && !defined(GEA_EMBEDDED_RTC_UNUSED)
|
|
3
3
|
|
|
4
4
|
#include "host/rtc.h"
|
|
5
5
|
#include "host/media.h"
|
|
6
6
|
#include "host/rtc_opus.h"
|
|
7
7
|
#include "host/rtc_sdp.h"
|
|
8
|
-
#if __has_include("esp_h264_dec_sw.h")
|
|
8
|
+
#if !defined(GEA_EMBEDDED_H264_UNUSED) && __has_include("esp_h264_dec_sw.h")
|
|
9
9
|
#include "host/rtc_h264.h"
|
|
10
10
|
#define GEA_RTC_HAS_H264 1
|
|
11
11
|
#else
|
package/host/timers.cpp
CHANGED
|
@@ -106,7 +106,7 @@ public:
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
void run(
|
|
109
|
+
void run(double timestampMs)
|
|
110
110
|
{
|
|
111
111
|
if (!std::isfinite(timestampMs)) timestampMs = currentTimeMs();
|
|
112
112
|
lastTimestampMs_ = timestampMs;
|
|
@@ -195,7 +195,7 @@ public:
|
|
|
195
195
|
return id;
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
void run(
|
|
198
|
+
void run(AnimationFrameTimestamp timestampMs)
|
|
199
199
|
{
|
|
200
200
|
[[maybe_unused]] const std::int64_t runStartUs = rafPerfNowUs();
|
|
201
201
|
const int count = static_cast<int>(pending_.size());
|
package/host/websocket.cpp
CHANGED
|
@@ -97,7 +97,7 @@ std::unordered_map<NativeWebSocketHandle, CallbackTable> &callbackTable() {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
#if defined(ESP_PLATFORM) && !defined(GEA_EMBEDDED_WIFI_DISABLED)
|
|
100
|
-
void platform_open(NativeWebSocketHandle, const std::string &, const std::string &);
|
|
100
|
+
void platform_open(NativeWebSocketHandle, const std::string &, const std::string &, const std::string &);
|
|
101
101
|
std::size_t platform_buffered(NativeWebSocketHandle);
|
|
102
102
|
void platform_send(NativeWebSocketHandle, const std::string &);
|
|
103
103
|
void platform_close(NativeWebSocketHandle);
|
|
@@ -105,7 +105,7 @@ void platform_destroy(NativeWebSocketHandle);
|
|
|
105
105
|
void platform_reap();
|
|
106
106
|
void platform_set_producer(NativeWebSocketHandle, TextProducer);
|
|
107
107
|
#else
|
|
108
|
-
__attribute__((weak)) void platform_open(NativeWebSocketHandle, const std::string &, const std::string &) {}
|
|
108
|
+
__attribute__((weak)) void platform_open(NativeWebSocketHandle, const std::string &, const std::string &, const std::string &) {}
|
|
109
109
|
__attribute__((weak)) std::size_t platform_buffered(NativeWebSocketHandle) { return 0; }
|
|
110
110
|
__attribute__((weak)) void platform_send(NativeWebSocketHandle, const std::string &) {}
|
|
111
111
|
__attribute__((weak)) void platform_close(NativeWebSocketHandle) {}
|
|
@@ -128,7 +128,7 @@ void setTextConsumer(NativeWebSocketHandle handle, TextConsumer consumer) {
|
|
|
128
128
|
it->second.consumer = std::move(consumer);
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
NativeWebSocketHandle create_handle(const std::string &url, const std::string &protocols) {
|
|
131
|
+
NativeWebSocketHandle create_handle(const std::string &url, const std::string &protocols, const std::string &headers) {
|
|
132
132
|
auto handle = nextHandle()++;
|
|
133
133
|
{
|
|
134
134
|
std::lock_guard<std::mutex> lock(instancesMutex());
|
|
@@ -138,7 +138,7 @@ NativeWebSocketHandle create_handle(const std::string &url, const std::string &p
|
|
|
138
138
|
(void)callbackTable();
|
|
139
139
|
{ std::lock_guard lock(ownerMutex); owners[handle] = owner; }
|
|
140
140
|
if (!owner->isMain()) owner->addCleanup([handle] { destroy_handle(handle); });
|
|
141
|
-
platform_open(handle, url, protocols);
|
|
141
|
+
platform_open(handle, url, protocols, headers);
|
|
142
142
|
return handle;
|
|
143
143
|
}
|
|
144
144
|
|
|
@@ -679,11 +679,12 @@ void sendWorker(void *arg) {
|
|
|
679
679
|
// The scope below is provided by the task trampoline in platform_open.
|
|
680
680
|
}
|
|
681
681
|
|
|
682
|
-
void platform_open(NativeWebSocketHandle handle, const std::string &url, const std::string &protocols) {
|
|
682
|
+
void platform_open(NativeWebSocketHandle handle, const std::string &url, const std::string &protocols, const std::string &headers) {
|
|
683
683
|
std::lock_guard platformLock(platformMutex);
|
|
684
684
|
esp_websocket_client_config_t config = {};
|
|
685
685
|
config.uri = url.c_str();
|
|
686
686
|
config.subprotocol = protocols.empty() ? nullptr : protocols.c_str();
|
|
687
|
+
config.headers = headers.empty() ? nullptr : headers.c_str();
|
|
687
688
|
config.task_stack = 8192;
|
|
688
689
|
config.buffer_size = 4096;
|
|
689
690
|
config.disable_auto_reconnect = true;
|
|
@@ -727,6 +728,7 @@ void platform_open(NativeWebSocketHandle handle, const std::string &url, const s
|
|
|
727
728
|
esp_transport_ws_config_t transportConfig{};
|
|
728
729
|
transportConfig.ws_path = path.c_str();
|
|
729
730
|
transportConfig.sub_protocol = config.subprotocol;
|
|
731
|
+
transportConfig.headers = config.headers;
|
|
730
732
|
transportConfig.propagate_control_frames = true;
|
|
731
733
|
if (esp_transport_ws_set_config(state->transport, &transportConfig) != ESP_OK) {
|
|
732
734
|
enqueue(PendingEvent{handle, EventKind::Error, "WebSocket transport configuration failed", 0});
|