@geastack/host 0.1.13 → 0.1.15

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/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/fetch.h" // gea::host::fetch for fetchBytes/fetchText (WiFi tile download)
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/task.h"
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 ensureMounted() { return g_mount_provider ? g_mount_provider() : false; }
49
- } // namespace gea::platform::storage
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, const unsigned char **data, unsigned long *length) __attribute__((weak));
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 fine.
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] != '/') continue;
86
+ if (path[i] != '/')
87
+ continue;
69
88
  const std::string dir = path.substr(0, i);
70
- if (!dir.empty()) ::mkdir(dir.c_str(), 0777);
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 && hdr[0] == 0x50 && hdr[1] == 0x4d) {
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]; // tile_data_offset (u64 LE @56)
95
- len = len * 256 + hdr[64 + i]; // tile_data_length (u64 LE @64)
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(), static_cast<std::size_t>(total)) != ESP_OK) c->out->clear();
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); // matches xTaskCreateWithCaps allocation
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) return out;
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
- } // namespace
148
+ } // namespace
125
149
 
126
150
  double ImageService::loadBytes(std::vector<std::uint8_t> bytes) const {
127
- const int id = store().decode(bytes.data(), static_cast<int>(bytes.size()), -1);
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 = store().decodeOpaque(bytes.data(), static_cast<int>(bytes.size()), -1);
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, std::size_t length) const {
137
- if (!data || length == 0) return -1.0;
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()) return static_cast<double>(cached->second);
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) return -1.0;
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)) return loadBytesPtr(data, static_cast<std::size_t>(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] == '/') return loadFile(std::string(path));
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
- if (path.empty() || !gea::platform::storage::ensureMounted()) return -1.0;
168
- const std::vector<std::uint8_t> bytes = readWholeFile(path);
169
- if (bytes.empty()) return -1.0;
170
- return static_cast<double>(store().decode(bytes.data(), static_cast<int>(bytes.size()), -1));
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
- if (path.empty() || !gea::platform::storage::ensureMounted()) return -1.0;
175
- const std::vector<std::uint8_t> bytes = readWholeFile(path);
176
- if (bytes.empty()) return -1.0;
177
- return static_cast<double>(store().decodeOpaque(bytes.data(), static_cast<int>(bytes.size()), -1));
178
- }
179
-
180
- bool ImageService::writeFile(const std::string &path, const std::vector<std::uint8_t> &bytes) const {
181
- if (path.empty() || bytes.empty() || !gea::platform::storage::ensureMounted()) return false;
182
- makeParentDirs(path);
183
- std::FILE *f = std::fopen(path.c_str(), "wb");
184
- if (!f) return false;
185
- const std::size_t wrote = std::fwrite(bytes.data(), 1, bytes.size(), f);
186
- std::fclose(f);
187
- return wrote == bytes.size();
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
- std::vector<std::uint8_t> ImageService::readFile(const std::string &path) const {
191
- if (path.empty() || !gea::platform::storage::ensureMounted()) return {};
192
- return readWholeFile(path);
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> ImageService::fetchBytes(const std::string &url) const {
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, double offset, double length) const {
207
- // Read just [offset, offset+length) — PMTiles' random-access pattern: the
208
- // directory + each tile are small ranges, so the whole archive never loads
209
- // into RAM. SD reads (fopen/fread) don't disable the flash cache, so this is
210
- // safe straight from the app task.
211
- if (path.empty() || length <= 0 || !gea::platform::storage::ensureMounted()) return {};
212
- std::FILE *f = std::fopen(path.c_str(), "rb");
213
- if (!f) return {};
214
- std::vector<std::uint8_t> out(static_cast<std::size_t>(length));
215
- std::fseek(f, static_cast<long>(offset), SEEK_SET);
216
- const std::size_t got = std::fread(out.data(), 1, out.size(), f);
217
- std::fclose(f);
218
- out.resize(got);
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
- while (const dirent *entry = readdir(dir)) {
228
- // Some VFS drivers (e.g. FATFS on ESP-IDF) don't fill d_type; stat the
229
- // entry when the type is unknown so directories stay excluded either way.
230
- if (entry->d_name[0] == '.') continue;
231
- bool regular = entry->d_type == DT_REG;
232
- if (entry->d_type == DT_UNKNOWN) {
233
- struct stat st {};
234
- const std::string full = path + "/" + entry->d_name;
235
- regular = stat(full.c_str(), &st) == 0 && S_ISREG(st.st_mode);
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
- if (!regular) continue;
238
- if (!out.empty()) out += '\n';
239
- out += entry->d_name;
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
- esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, nullptr);
254
- if (!p) return {};
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) return {};
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, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT) == pdPASS) {
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 = store().currentPixels(slot);
275
- if (!pixels) return;
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, integer(x), integer(y));
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 { return store().currentPixels(id) != nullptr; }
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
- } // namespace gea::host
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 = 16000.0;
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 16 kHz. Storage grows only when a
160
- // consumer falls behind and uses PSRAM rather than starving I2S DMA memory.
161
- constexpr std::size_t kMaxRingBufferSamples = 8 * 16000;
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 = 16000.0;
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
- return create_stream();
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
- #ifdef ESP_PLATFORM
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(AnimationFrameTimestamp timestampMs)
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(double timestampMs)
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/wifi.cpp CHANGED
@@ -24,61 +24,59 @@ void sleepForMs(int ms) {
24
24
  #endif
25
25
  }
26
26
 
27
- } // namespace
27
+ } // namespace
28
28
 
29
- bool WifiBackend::enabled() {
30
- return wifi().enabled();
31
- }
29
+ bool WifiBackend::enabled() { return wifi().enabled(); }
32
30
 
33
- void WifiBackend::setEnabled(bool enabled) {
34
- wifi().setEnabled(enabled);
35
- }
31
+ void WifiBackend::setEnabled(bool enabled) { wifi().setEnabled(enabled); }
36
32
 
37
- bool WifiBackend::connected() {
38
- return wifi().connected();
39
- }
33
+ bool WifiBackend::connected() { return wifi().connected(); }
40
34
 
41
- double WifiBackend::rssi() {
42
- return static_cast<double>(wifi().rssi());
43
- }
35
+ double WifiBackend::rssi() { return static_cast<double>(wifi().rssi()); }
44
36
 
45
- std::string WifiBackend::ssid() {
46
- return wifi().ssid();
47
- }
37
+ std::string WifiBackend::ssid() { return wifi().ssid(); }
48
38
 
49
- std::string WifiBackend::ip() {
50
- return wifi().ip();
51
- }
39
+ std::string WifiBackend::ip() { return wifi().ip(); }
52
40
 
53
- std::string WifiBackend::mac() {
54
- return wifi().mac();
55
- }
41
+ std::string WifiBackend::mac() { return wifi().mac(); }
56
42
 
57
- void WifiBackend::configure(const std::string &ssid, const std::string &password) {
43
+ void WifiBackend::configure(const std::string &ssid,
44
+ const std::string &password) {
58
45
  wifi().configure(ssid, password);
59
46
  }
60
47
 
48
+ bool WifiBackend::startAccessPoint(const std::string &ssid,
49
+ const std::string &password) {
50
+ return wifi().startAccessPoint(ssid, password);
51
+ }
52
+
53
+ void WifiBackend::stopAccessPoint() { wifi().stopAccessPoint(); }
54
+
55
+ std::string WifiBackend::accessPointMac() { return wifi().accessPointMac(); }
56
+
57
+ bool WifiBackend::startCaptivePortal() { return wifi().startCaptivePortal(); }
58
+
59
+ void WifiBackend::stopCaptivePortal() { wifi().stopCaptivePortal(); }
60
+
61
61
  bool WifiBackend::waitForConnection(double timeoutMs) {
62
- if (wifi().connected()) return true;
62
+ if (wifi().connected())
63
+ return true;
63
64
  wifi().setEnabled(true);
64
65
 
65
66
  const int timeout = timeoutMs > 0 ? static_cast<int>(timeoutMs) : 0;
66
67
  int elapsed = 0;
67
68
  while (elapsed < timeout) {
68
- if (wifi().connected()) return true;
69
+ if (wifi().connected())
70
+ return true;
69
71
  sleepForMs(100);
70
72
  elapsed += 100;
71
73
  }
72
74
  return wifi().connected();
73
75
  }
74
76
 
75
- void WifiBackend::startScan() {
76
- wifi().scan();
77
- }
77
+ void WifiBackend::startScan() { wifi().scan(); }
78
78
 
79
- bool WifiBackend::scanning() {
80
- return wifi().scanning();
81
- }
79
+ bool WifiBackend::scanning() { return wifi().scanning(); }
82
80
 
83
81
  double WifiBackend::scanCount() {
84
82
  return static_cast<double>(wifi().scanCount());
@@ -96,4 +94,4 @@ bool WifiBackend::scanSecuredAt(double index) {
96
94
  return wifi().networkAt(static_cast<int>(index)).secured;
97
95
  }
98
96
 
99
- } // namespace gea::framework::network
97
+ } // namespace gea::framework::network