@geastack/host 0.1.8
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/LICENSE +202 -0
- package/README.md +25 -0
- package/audio_runtime.cpp +807 -0
- package/bluetooth.cpp +125 -0
- package/geolocation.cpp +43 -0
- package/host/apps.cpp +20 -0
- package/host/audio.cpp +240 -0
- package/host/ble.cpp +239 -0
- package/host/camera.cpp +193 -0
- package/host/display.cpp +230 -0
- package/host/fetch.cpp +1060 -0
- package/host/geolocation.cpp +31 -0
- package/host/gpio.cpp +55 -0
- package/host/http.cpp +349 -0
- package/host/image.cpp +335 -0
- package/host/imu.cpp +51 -0
- package/host/input.cpp +12 -0
- package/host/media.cpp +579 -0
- package/host/memory.cpp +91 -0
- package/host/rtc.cpp +212 -0
- package/host/rtc_esp.cpp +291 -0
- package/host/tile_loader.cpp +478 -0
- package/host/timers.cpp +327 -0
- package/host/touch.cpp +25 -0
- package/host/websocket.cpp +279 -0
- package/host/wifi.cpp +99 -0
- package/include/gea/embedded-host.h +38 -0
- package/include/host/apps.h +15 -0
- package/include/host/audio.h +158 -0
- package/include/host/backends.h +455 -0
- package/include/host/battery.h +25 -0
- package/include/host/camera.h +236 -0
- package/include/host/clock.h +45 -0
- package/include/host/device_control.h +23 -0
- package/include/host/display.h +266 -0
- package/include/host/display_orientation.h +291 -0
- package/include/host/fetch.h +310 -0
- package/include/host/gpio.h +36 -0
- package/include/host/http.h +161 -0
- package/include/host/image.h +144 -0
- package/include/host/input.h +14 -0
- package/include/host/media.h +165 -0
- package/include/host/memory.h +44 -0
- package/include/host/navigator.h +283 -0
- package/include/host/notify.h +41 -0
- package/include/host/profiler.h +49 -0
- package/include/host/rtc.h +174 -0
- package/include/host/storage.h +141 -0
- package/include/host/tile_loader.h +59 -0
- package/include/host/timers.h +41 -0
- package/include/host/touch.h +20 -0
- package/include/host/websocket.h +179 -0
- package/include/host/window.h +31 -0
- package/input.cpp +68 -0
- package/package.json +27 -0
- package/services/app_state.cpp +19 -0
- package/services/battery_service.cpp +19 -0
- package/services/bluetooth_service.cpp +37 -0
- package/services/diagnostics.cpp +233 -0
- package/services/diagnostics_connection.cpp +231 -0
- package/services/diagnostics_internal.h +15 -0
- package/services/diagnostics_server.cpp +135 -0
- package/services/mirror.cpp +364 -0
- package/services/network_services.cpp +62 -0
- package/services/runtime_log.cpp +23 -0
- package/services/settings_surface.h +221 -0
- package/wifi.cpp +185 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#include <cstdint>
|
|
5
|
+
#include <functional>
|
|
6
|
+
#include <string>
|
|
7
|
+
#include <unordered_map>
|
|
8
|
+
#include <vector>
|
|
9
|
+
|
|
10
|
+
// A lightweight device-hosted HTTP server, modeled after Node's `http` package:
|
|
11
|
+
// `http.createServer(handler)` returns a server; the handler is called once per
|
|
12
|
+
// request and RETURNS a plain reply record `{ status, contentType, body, file,
|
|
13
|
+
// download }`. Like the WebSocket facade, the handler crosses the JS<->native
|
|
14
|
+
// boundary as a boxed callable and is invoked on the FRAME task (drained by
|
|
15
|
+
// `runRequests()` from the app frame loop), so app logic stays in TypeScript.
|
|
16
|
+
//
|
|
17
|
+
// The reply is data, never a live object: there is no `res` with mutating
|
|
18
|
+
// methods. A reply that sets `file` streams that path straight off disk on the
|
|
19
|
+
// server worker task, so large recordings (tens of MB of WAV) are sent without
|
|
20
|
+
// ever materializing in JS or the frame task.
|
|
21
|
+
|
|
22
|
+
namespace gea::host {
|
|
23
|
+
|
|
24
|
+
using NativeHttpServerHandle = std::uint32_t;
|
|
25
|
+
|
|
26
|
+
// The request a handler sees (built natively from the incoming HTTP request).
|
|
27
|
+
struct HttpRequest {
|
|
28
|
+
std::string method; // "GET", "POST", ...
|
|
29
|
+
std::string path; // request path, query stripped (e.g. "/note_003.wav")
|
|
30
|
+
std::string query; // raw query string after '?' (e.g. "tag=Idea"), or ""
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// What a handler returns. Either an inline `body`, or a `file` path to stream
|
|
34
|
+
// from disk. `download` (when set) turns the response into an attachment.
|
|
35
|
+
struct HttpReply {
|
|
36
|
+
int status = 200;
|
|
37
|
+
std::string contentType = "text/plain";
|
|
38
|
+
std::string body;
|
|
39
|
+
std::string file;
|
|
40
|
+
std::string download;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
namespace http {
|
|
44
|
+
|
|
45
|
+
// Handler signature on the native side. Runs on the frame task. Pure value
|
|
46
|
+
// types in the signature (no gea_cpp_value), so this file's non-generated TUs
|
|
47
|
+
// can store and call it without the dynamic-value runtime.
|
|
48
|
+
using RequestHandler = std::function<HttpReply(const HttpRequest &)>;
|
|
49
|
+
|
|
50
|
+
// Registers a handler, allocates a server handle, returns it. Defined in
|
|
51
|
+
// http.cpp; called by create_server() below.
|
|
52
|
+
NativeHttpServerHandle register_handler(RequestHandler handler);
|
|
53
|
+
void unregister_handler(NativeHttpServerHandle handle);
|
|
54
|
+
|
|
55
|
+
std::unordered_map<NativeHttpServerHandle, RequestHandler> &handlerTable();
|
|
56
|
+
|
|
57
|
+
// Frame-loop pump: drains requests posted by the server worker, runs each
|
|
58
|
+
// handler on the frame task, fills the reply, and releases the waiting worker.
|
|
59
|
+
void runRequests();
|
|
60
|
+
|
|
61
|
+
// Platform transport (esp_http_server on device; weak no-ops elsewhere).
|
|
62
|
+
bool platform_listen(NativeHttpServerHandle handle, int port);
|
|
63
|
+
void platform_close(NativeHttpServerHandle handle);
|
|
64
|
+
|
|
65
|
+
// Stop + unregister a server by its handle. Lets an app persist just the
|
|
66
|
+
// numeric handle (a plain double cell — no boxing) instead of the HttpServer
|
|
67
|
+
// object across module scope. Handle 0 is a no-op.
|
|
68
|
+
inline void close_server(double handle) {
|
|
69
|
+
const NativeHttpServerHandle h = static_cast<NativeHttpServerHandle>(handle);
|
|
70
|
+
if (h == 0) return;
|
|
71
|
+
platform_close(h);
|
|
72
|
+
unregister_handler(h);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Test seam (non-ESP): dispatch a request synchronously through the registered
|
|
76
|
+
// handler and return its reply, without any sockets.
|
|
77
|
+
HttpReply test_dispatch(NativeHttpServerHandle handle, const std::string &method,
|
|
78
|
+
const std::string &path, const std::string &query);
|
|
79
|
+
|
|
80
|
+
#ifdef GEA_CPP_VALUE_AVAILABLE
|
|
81
|
+
// Builds a native RequestHandler that marshals the request into a JS record,
|
|
82
|
+
// invokes the boxed JS callable, and reads back the reply record. Instantiated
|
|
83
|
+
// only in generated TUs (where gea_cpp_value exists), matching the WebSocket
|
|
84
|
+
// callback lowering.
|
|
85
|
+
inline NativeHttpServerHandle create_server(gea_cpp_value handler) {
|
|
86
|
+
if (handler.kind != gea_cpp_value::kind_t::callable || !handler.callable) {
|
|
87
|
+
return register_handler(nullptr);
|
|
88
|
+
}
|
|
89
|
+
auto callable = handler.callable;
|
|
90
|
+
RequestHandler native = [callable](const HttpRequest &req) -> HttpReply {
|
|
91
|
+
gea_cpp_value request;
|
|
92
|
+
request.kind = gea_cpp_value::kind_t::record;
|
|
93
|
+
request.entries = std::make_shared<std::vector<std::pair<std::string, gea_cpp_value>>>();
|
|
94
|
+
request.record_set_literal("method", gea_cpp_value(req.method));
|
|
95
|
+
request.record_set_literal("path", gea_cpp_value(req.path));
|
|
96
|
+
request.record_set_literal("url", gea_cpp_value(req.query.empty() ? req.path : req.path + "?" + req.query));
|
|
97
|
+
request.record_set_literal("query", gea_cpp_value(req.query));
|
|
98
|
+
|
|
99
|
+
const gea_cpp_value result = (*callable)(std::vector<gea_cpp_value>{request});
|
|
100
|
+
|
|
101
|
+
HttpReply reply;
|
|
102
|
+
if (result.kind != gea_cpp_value::kind_t::record) {
|
|
103
|
+
// A handler that returns nothing useful => 404.
|
|
104
|
+
reply.status = 404;
|
|
105
|
+
reply.contentType = "text/plain";
|
|
106
|
+
reply.body = "Not found";
|
|
107
|
+
return reply;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const gea_cpp_value status = result.record_get_literal("status");
|
|
111
|
+
if (status.kind == gea_cpp_value::kind_t::number && status.number > 0) {
|
|
112
|
+
reply.status = static_cast<int>(status.number);
|
|
113
|
+
}
|
|
114
|
+
const gea_cpp_value contentType = result.record_get_literal("contentType");
|
|
115
|
+
if (contentType.kind == gea_cpp_value::kind_t::string && !contentType.text.empty()) {
|
|
116
|
+
reply.contentType = contentType.text;
|
|
117
|
+
}
|
|
118
|
+
const gea_cpp_value file = result.record_get_literal("file");
|
|
119
|
+
if (file.kind == gea_cpp_value::kind_t::string && !file.text.empty()) {
|
|
120
|
+
reply.file = file.text;
|
|
121
|
+
}
|
|
122
|
+
const gea_cpp_value download = result.record_get_literal("download");
|
|
123
|
+
if (download.kind == gea_cpp_value::kind_t::string && !download.text.empty()) {
|
|
124
|
+
reply.download = download.text;
|
|
125
|
+
}
|
|
126
|
+
const gea_cpp_value body = result.record_get_literal("body");
|
|
127
|
+
if (body.kind == gea_cpp_value::kind_t::string) {
|
|
128
|
+
reply.body = body.text;
|
|
129
|
+
}
|
|
130
|
+
return reply;
|
|
131
|
+
};
|
|
132
|
+
return register_handler(std::move(native));
|
|
133
|
+
}
|
|
134
|
+
#endif // GEA_CPP_VALUE_AVAILABLE
|
|
135
|
+
|
|
136
|
+
} // namespace http
|
|
137
|
+
|
|
138
|
+
// A server handle. `createServer()` lowers to `http::create_server(...)`, whose
|
|
139
|
+
// double return is wrapped back into this by the plugin's nativeTypes mapping,
|
|
140
|
+
// so `server.listen(...)` / `server.close()` lower to direct native calls.
|
|
141
|
+
class HttpServer {
|
|
142
|
+
public:
|
|
143
|
+
NativeHttpServerHandle nativeHandle = 0;
|
|
144
|
+
|
|
145
|
+
constexpr HttpServer() = default;
|
|
146
|
+
explicit HttpServer(NativeHttpServerHandle h) : nativeHandle(h) {}
|
|
147
|
+
explicit HttpServer(double h) : nativeHandle(static_cast<NativeHttpServerHandle>(h)) {}
|
|
148
|
+
|
|
149
|
+
constexpr operator double() const { return static_cast<double>(nativeHandle); }
|
|
150
|
+
|
|
151
|
+
// Numeric handle, so apps can persist it as a plain number and close later
|
|
152
|
+
// via `http.close(handle)` without storing (and boxing) the object.
|
|
153
|
+
double id() const { return static_cast<double>(nativeHandle); }
|
|
154
|
+
bool listen(double port) const { return http::platform_listen(nativeHandle, static_cast<int>(port)); }
|
|
155
|
+
void close() const {
|
|
156
|
+
http::platform_close(nativeHandle);
|
|
157
|
+
http::unregister_handler(nativeHandle);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
} // namespace gea::host
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#include <cstddef>
|
|
5
|
+
#include <cstdint>
|
|
6
|
+
#include <string>
|
|
7
|
+
#include <vector>
|
|
8
|
+
|
|
9
|
+
namespace gea::host {
|
|
10
|
+
|
|
11
|
+
// Typed handle for a decoded image slot. This is the native lowering of the TS
|
|
12
|
+
// `GeaEmbeddedImage` (see runtime/images.ts + index.d.ts) — `loadImage()` returns
|
|
13
|
+
// one of these by value, so cached images flow as a concrete struct (id + the
|
|
14
|
+
// immutable post-decode dimensions) instead of a boxed `gea_cpp_value` record.
|
|
15
|
+
// `img.width`/`img.height`/… are plain field reads; `img.play()`/`dispose()`/…
|
|
16
|
+
// delegate to the image store. `canvasImageId` reads the `id` member, so
|
|
17
|
+
// `ctx.drawImage(img, …)` consumes it directly.
|
|
18
|
+
struct GeaEmbeddedImage {
|
|
19
|
+
int id = -1;
|
|
20
|
+
int width = 0;
|
|
21
|
+
int height = 0;
|
|
22
|
+
int frameCount = 0;
|
|
23
|
+
bool isAnimated = false;
|
|
24
|
+
|
|
25
|
+
void play() const;
|
|
26
|
+
void pause() const;
|
|
27
|
+
void seek(int frame) const;
|
|
28
|
+
void dispose() const;
|
|
29
|
+
|
|
30
|
+
// The absence state this handle already documents, made readable. `id = -1`
|
|
31
|
+
// is what every failing producer returns -- `loadBytes`/`loadFile`/
|
|
32
|
+
// `loadAssetPath` all answer -1, and `image.make(-1)` is what the TS runtime
|
|
33
|
+
// hands back -- so the struct has always had a "refers to nothing" state; it
|
|
34
|
+
// simply had no way to be asked. Every other gea handle answers this the same
|
|
35
|
+
// way (`gea::NativeHandle` over its `valid()`, the Apple bridge's wrappers
|
|
36
|
+
// over `handle != 0`), which is what lets a compiler carry `GeaEmbeddedImage |
|
|
37
|
+
// null` as the handle itself instead of wrapping a second absence flag around
|
|
38
|
+
// one that is already there. Explicit, so it never participates in arithmetic
|
|
39
|
+
// or overload resolution -- only in a test that asks the question directly.
|
|
40
|
+
explicit operator bool() const { return id >= 0; }
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
class ImageService {
|
|
44
|
+
public:
|
|
45
|
+
double loadBytes(std::vector<std::uint8_t> bytes) const;
|
|
46
|
+
double loadBytesOpaque(std::vector<std::uint8_t> bytes) const;
|
|
47
|
+
|
|
48
|
+
// Decode a build-embedded asset from a pointer/length into its `.rodata`
|
|
49
|
+
// bytes. `<img src="face.png">` lowers to a direct reference to the generated
|
|
50
|
+
// `gea_asset_<path>` symbol (see generate-gea-embedded-assets.mjs) passed
|
|
51
|
+
// here — that reference is what keeps the asset object in the link. Returns
|
|
52
|
+
// the image id, or -1 on decode failure. Decoded once per pointer and cached,
|
|
53
|
+
// so a remounting <img> reuses the same slot instead of re-decoding.
|
|
54
|
+
double loadBytesPtr(const std::uint8_t *data, std::size_t length) const;
|
|
55
|
+
double loadAssetPath(const char *path) const;
|
|
56
|
+
// Same bundled-asset lookup for a path a canvas app computes at runtime --
|
|
57
|
+
// `<img src="...">` lowers a string LITERAL to a direct gea_asset_ symbol,
|
|
58
|
+
// which a ctx.drawImage() app selecting among N bundled icons cannot use.
|
|
59
|
+
// Inline and delegating, so the device host and the native test host each
|
|
60
|
+
// pick it up from their own loadAssetPath(const char *) definition.
|
|
61
|
+
double loadAssetPath(const std::string &path) const { return loadAssetPath(path.c_str()); }
|
|
62
|
+
|
|
63
|
+
// Persistent file cache (e.g. microSD at /sdcard). loadFile/loadFileOpaque read
|
|
64
|
+
// + decode an image straight from a file, returning the slot id or -1 if the
|
|
65
|
+
// file is missing / undecodable (callers treat -1 as a cache miss and fetch
|
|
66
|
+
// over the network). writeFile saves raw bytes (creating parent dirs).
|
|
67
|
+
// All no-op when no persistent storage is mounted.
|
|
68
|
+
double loadFile(const std::string &path) const;
|
|
69
|
+
double loadFileOpaque(const std::string &path) const;
|
|
70
|
+
bool writeFile(const std::string &path, const std::vector<std::uint8_t> &bytes) const;
|
|
71
|
+
// Read a whole file's raw bytes (e.g. a .pmtiles on microSD) into memory.
|
|
72
|
+
// Empty vector when the file is missing or no storage is mounted.
|
|
73
|
+
std::vector<std::uint8_t> readFile(const std::string &path) const;
|
|
74
|
+
// Read a .pmtiles archive flashed into the spare ota_1 partition (esptool),
|
|
75
|
+
// sized from its header. Empty off-esp32 or when absent/invalid.
|
|
76
|
+
std::vector<std::uint8_t> readMapArchive() const;
|
|
77
|
+
// Read a byte range [offset, offset+length) from a file (e.g. one tile out of
|
|
78
|
+
// a .pmtiles on microSD), without loading the whole file.
|
|
79
|
+
std::vector<std::uint8_t> readFileRange(const std::string &path, double offset, double length) const;
|
|
80
|
+
// List a directory's regular-file names (non-recursive), newline-joined —
|
|
81
|
+
// e.g. the EPUBs on a microSD. Empty string when the directory is missing or
|
|
82
|
+
// no storage is mounted.
|
|
83
|
+
std::string listFiles(const std::string &path) const;
|
|
84
|
+
// Synchronous HTTP GET over WiFi: fetch a URL's body as bytes (e.g. an MVT
|
|
85
|
+
// tile) or text (e.g. a TileJSON). Empty when WiFi is down / request fails.
|
|
86
|
+
std::vector<std::uint8_t> fetchBytes(const std::string &url) const;
|
|
87
|
+
std::string fetchText(const std::string &url) const;
|
|
88
|
+
|
|
89
|
+
#if defined(GEA_CPP_VALUE_AVAILABLE) && defined(GEA_HOST_IMAGE_BOXED_BYTE_OVERLOADS) && GEA_HOST_IMAGE_BOXED_BYTE_OVERLOADS
|
|
90
|
+
double loadBytes(const gea_cpp_value &bytes) const;
|
|
91
|
+
double loadBytesOpaque(const gea_cpp_value &bytes) const;
|
|
92
|
+
bool writeFile(const std::string &path, const gea_cpp_value &bytes) const;
|
|
93
|
+
#endif
|
|
94
|
+
|
|
95
|
+
void draw(double id, double x, double y) const;
|
|
96
|
+
double width(double id) const;
|
|
97
|
+
double height(double id) const;
|
|
98
|
+
double frameCount(double id) const;
|
|
99
|
+
bool isAnimated(double id) const;
|
|
100
|
+
void setPlaying(double id, double playing) const;
|
|
101
|
+
void seek(double id, double frame) const;
|
|
102
|
+
bool advance(double id, double deltaMs) const;
|
|
103
|
+
void dispose(double id) const;
|
|
104
|
+
|
|
105
|
+
// Wrap an already-decoded slot id in a typed handle, snapshotting the
|
|
106
|
+
// immutable dimensions. `loadImage()` (runtime/images.ts) calls this so its
|
|
107
|
+
// result is a native `GeaEmbeddedImage` value rather than a boxed record.
|
|
108
|
+
GeaEmbeddedImage make(double id) const;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
inline constexpr ImageService image{};
|
|
112
|
+
|
|
113
|
+
#if defined(GEA_CPP_VALUE_AVAILABLE) && defined(GEA_HOST_IMAGE_BOXED_BYTE_OVERLOADS) && GEA_HOST_IMAGE_BOXED_BYTE_OVERLOADS
|
|
114
|
+
inline std::vector<std::uint8_t> image_byte_vector_from_value(const gea_cpp_value &bytes) {
|
|
115
|
+
std::vector<std::uint8_t> out;
|
|
116
|
+
// Typed-array values keep their backing vector inside the boxed value. Read it
|
|
117
|
+
// by reference so a tile body does not become a huge temporary vector of
|
|
118
|
+
// gea_cpp_value boxes before being packed back to bytes.
|
|
119
|
+
if (bytes.kind == gea_cpp_value::kind_t::array_value) {
|
|
120
|
+
const std::vector<gea_cpp_value> &items = bytes.array_ref();
|
|
121
|
+
out.reserve(items.size());
|
|
122
|
+
for (const auto &item : items) out.push_back(static_cast<std::uint8_t>(static_cast<double>(item)));
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
125
|
+
auto items = static_cast<std::vector<gea_cpp_value>>(bytes);
|
|
126
|
+
out.reserve(items.size());
|
|
127
|
+
for (const auto &item : items) out.push_back(static_cast<std::uint8_t>(static_cast<double>(item)));
|
|
128
|
+
return out;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
inline double ImageService::loadBytes(const gea_cpp_value &bytes) const {
|
|
132
|
+
return loadBytes(image_byte_vector_from_value(bytes));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
inline double ImageService::loadBytesOpaque(const gea_cpp_value &bytes) const {
|
|
136
|
+
return loadBytesOpaque(image_byte_vector_from_value(bytes));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
inline bool ImageService::writeFile(const std::string &path, const gea_cpp_value &bytes) const {
|
|
140
|
+
return writeFile(path, image_byte_vector_from_value(bytes));
|
|
141
|
+
}
|
|
142
|
+
#endif
|
|
143
|
+
|
|
144
|
+
} // namespace gea::host
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#include "backends.h"
|
|
5
|
+
|
|
6
|
+
namespace gea::host {
|
|
7
|
+
|
|
8
|
+
struct InputFacade {
|
|
9
|
+
bool consumeBackButton() const { return gea::framework::input::InputBackend::consumeBackButton(); }
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
inline constexpr InputFacade Input{};
|
|
13
|
+
|
|
14
|
+
} // namespace gea::host
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#include <cstddef>
|
|
5
|
+
#include <cstdint>
|
|
6
|
+
#include <functional>
|
|
7
|
+
#include <string>
|
|
8
|
+
#include <vector>
|
|
9
|
+
|
|
10
|
+
namespace gea::host {
|
|
11
|
+
|
|
12
|
+
using NativeMediaStreamHandle = std::uint32_t;
|
|
13
|
+
using NativeMediaTrackHandle = std::uint32_t;
|
|
14
|
+
using NativeMediaRecorderHandle = std::uint32_t;
|
|
15
|
+
|
|
16
|
+
class MediaStreamTrack {
|
|
17
|
+
public:
|
|
18
|
+
NativeMediaTrackHandle nativeHandle = 0;
|
|
19
|
+
|
|
20
|
+
constexpr MediaStreamTrack() = default;
|
|
21
|
+
explicit MediaStreamTrack(NativeMediaTrackHandle h) : nativeHandle(h) {}
|
|
22
|
+
explicit MediaStreamTrack(double h) : nativeHandle(static_cast<NativeMediaTrackHandle>(h)) {}
|
|
23
|
+
constexpr operator double() const { return static_cast<double>(nativeHandle); }
|
|
24
|
+
|
|
25
|
+
template <typename Value>
|
|
26
|
+
static MediaStreamTrack __gea_native_from_value(const Value &value) {
|
|
27
|
+
if constexpr (requires { static_cast<double>(value); }) return MediaStreamTrack(static_cast<double>(value));
|
|
28
|
+
else return MediaStreamTrack{};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
std::string id() const;
|
|
32
|
+
std::string kind() const;
|
|
33
|
+
std::string readyState() const;
|
|
34
|
+
bool enabled() const;
|
|
35
|
+
void setEnabled(bool value) const;
|
|
36
|
+
void stop() const;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
class MediaStream {
|
|
40
|
+
public:
|
|
41
|
+
NativeMediaStreamHandle nativeHandle = 0;
|
|
42
|
+
|
|
43
|
+
constexpr MediaStream() = default;
|
|
44
|
+
explicit MediaStream(NativeMediaStreamHandle h) : nativeHandle(h) {}
|
|
45
|
+
explicit MediaStream(double h) : nativeHandle(static_cast<NativeMediaStreamHandle>(h)) {}
|
|
46
|
+
constexpr operator double() const { return static_cast<double>(nativeHandle); }
|
|
47
|
+
|
|
48
|
+
template <typename Value>
|
|
49
|
+
static MediaStream __gea_native_from_value(const Value &value) {
|
|
50
|
+
if constexpr (requires { static_cast<double>(value); }) return MediaStream(static_cast<double>(value));
|
|
51
|
+
else return MediaStream{};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
std::string id() const;
|
|
55
|
+
std::vector<MediaStreamTrack> getAudioTracks() const;
|
|
56
|
+
std::vector<MediaStreamTrack> getTracks() const;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
struct GeaAudioBlob {
|
|
60
|
+
std::string path;
|
|
61
|
+
std::string type = "audio/wav";
|
|
62
|
+
double size = 0.0;
|
|
63
|
+
|
|
64
|
+
template <typename Value>
|
|
65
|
+
static GeaAudioBlob __gea_native_from_value(const Value &) { return {}; }
|
|
66
|
+
|
|
67
|
+
std::vector<std::uint8_t> arrayBuffer() const;
|
|
68
|
+
std::string text() const;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
struct MediaRecorderDataEvent {
|
|
72
|
+
GeaAudioBlob data;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
namespace media {
|
|
76
|
+
template <typename Options>
|
|
77
|
+
std::string recorder_path_from_options(const Options &options);
|
|
78
|
+
|
|
79
|
+
template <typename Options>
|
|
80
|
+
std::string recorder_mime_from_options(const Options &options);
|
|
81
|
+
} // namespace media
|
|
82
|
+
|
|
83
|
+
struct MediaRecorderStateProperty {
|
|
84
|
+
NativeMediaRecorderHandle nativeHandle = 0;
|
|
85
|
+
|
|
86
|
+
constexpr MediaRecorderStateProperty() = default;
|
|
87
|
+
explicit constexpr MediaRecorderStateProperty(NativeMediaRecorderHandle handle) : nativeHandle(handle) {}
|
|
88
|
+
|
|
89
|
+
operator std::string() const;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
class MediaRecorder {
|
|
93
|
+
public:
|
|
94
|
+
NativeMediaRecorderHandle nativeHandle = 0;
|
|
95
|
+
MediaStream stream;
|
|
96
|
+
mutable MediaRecorderStateProperty state;
|
|
97
|
+
std::function<void(MediaRecorderDataEvent)> ondataavailable = nullptr;
|
|
98
|
+
std::function<void()> onstop = nullptr;
|
|
99
|
+
|
|
100
|
+
MediaRecorder() = default;
|
|
101
|
+
explicit MediaRecorder(double handle) : nativeHandle(static_cast<NativeMediaRecorderHandle>(handle)), state(nativeHandle) {}
|
|
102
|
+
explicit MediaRecorder(MediaStream mediaStream);
|
|
103
|
+
|
|
104
|
+
template <typename Options>
|
|
105
|
+
MediaRecorder(MediaStream mediaStream, const Options &options)
|
|
106
|
+
: MediaRecorder(mediaStream, media::recorder_path_from_options(options), media::recorder_mime_from_options(options)) {}
|
|
107
|
+
|
|
108
|
+
MediaRecorder(MediaStream mediaStream, const std::string &path, const std::string &mimeType = "audio/wav");
|
|
109
|
+
|
|
110
|
+
std::string mimeType() const;
|
|
111
|
+
void start(double timesliceMs = 0.0) const;
|
|
112
|
+
void stop() const;
|
|
113
|
+
|
|
114
|
+
template <typename Value>
|
|
115
|
+
static MediaRecorder __gea_native_from_value(const Value &value) {
|
|
116
|
+
if constexpr (requires { static_cast<double>(value); }) return MediaRecorder(static_cast<double>(value));
|
|
117
|
+
else return MediaRecorder{};
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
namespace media {
|
|
122
|
+
|
|
123
|
+
NativeMediaStreamHandle create_stream();
|
|
124
|
+
void destroy_stream(NativeMediaStreamHandle handle);
|
|
125
|
+
NativeMediaTrackHandle stream_audio_track(NativeMediaStreamHandle handle);
|
|
126
|
+
|
|
127
|
+
void track_inject_pcm(NativeMediaTrackHandle handle, const std::int16_t *samples, std::size_t count);
|
|
128
|
+
std::size_t track_read_pcm(NativeMediaTrackHandle handle, std::int16_t *samples, std::size_t max_samples);
|
|
129
|
+
|
|
130
|
+
NativeMediaStreamHandle get_user_media_audio();
|
|
131
|
+
NativeMediaRecorderHandle create_recorder(NativeMediaStreamHandle stream, const std::string &path, const std::string &mimeType);
|
|
132
|
+
std::string recorder_state(NativeMediaRecorderHandle handle);
|
|
133
|
+
std::string recorder_mime_type(NativeMediaRecorderHandle handle);
|
|
134
|
+
void recorder_start(NativeMediaRecorderHandle handle);
|
|
135
|
+
GeaAudioBlob recorder_stop(NativeMediaRecorderHandle handle);
|
|
136
|
+
|
|
137
|
+
template <typename Options>
|
|
138
|
+
std::string recorder_path_from_options(const Options &options) {
|
|
139
|
+
if constexpr (requires { options.path; }) {
|
|
140
|
+
return std::string(options.path);
|
|
141
|
+
} else {
|
|
142
|
+
return {};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
template <typename Options>
|
|
147
|
+
std::string recorder_mime_from_options(const Options &options) {
|
|
148
|
+
if constexpr (requires { options.mimeType; }) {
|
|
149
|
+
return std::string(options.mimeType);
|
|
150
|
+
} else {
|
|
151
|
+
return "audio/wav";
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Overload accepting a MediaStreamConstraints-shaped record (from
|
|
156
|
+
// `navigator.mediaDevices.getUserMedia({...})`). The fields aren't acted on
|
|
157
|
+
// yet — there's no per-device picker on the embedded target — but accepting
|
|
158
|
+
// the arg lets the geatsc-emitted call site link. The single-arg form
|
|
159
|
+
// dispatches to the no-arg implementation.
|
|
160
|
+
template <typename Constraints>
|
|
161
|
+
NativeMediaStreamHandle get_user_media_audio(const Constraints &) { return get_user_media_audio(); }
|
|
162
|
+
|
|
163
|
+
} // namespace media
|
|
164
|
+
|
|
165
|
+
} // namespace gea::host
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#include "backends.h"
|
|
5
|
+
|
|
6
|
+
namespace gea::host {
|
|
7
|
+
|
|
8
|
+
struct MemoryFacade {
|
|
9
|
+
double internalFree() const { return gea::framework::memory::MemoryBackend::internalFree(); }
|
|
10
|
+
double internalLargestFreeBlock() const { return gea::framework::memory::MemoryBackend::internalLargestFreeBlock(); }
|
|
11
|
+
double internalMinimumFree() const { return gea::framework::memory::MemoryBackend::internalMinimumFree(); }
|
|
12
|
+
double psramFree() const { return gea::framework::memory::MemoryBackend::psramFree(); }
|
|
13
|
+
double currentTaskStackHighWaterMark() const {
|
|
14
|
+
return gea::framework::memory::MemoryBackend::currentTaskStackHighWaterMark();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
double geaMainStackBytes() const { return gea::framework::memory::MemoryBackend::geaMainStackBytes(); }
|
|
18
|
+
double geaInitStackBytes() const { return gea::framework::memory::MemoryBackend::geaInitStackBytes(); }
|
|
19
|
+
double appFrameStackWords() const { return gea::framework::memory::MemoryBackend::appFrameStackWords(); }
|
|
20
|
+
double appFrameStackBytes() const { return gea::framework::memory::MemoryBackend::appFrameStackBytes(); }
|
|
21
|
+
|
|
22
|
+
double displayFlushConfiguredRows() const {
|
|
23
|
+
return gea::framework::memory::MemoryBackend::displayFlushConfiguredRows();
|
|
24
|
+
}
|
|
25
|
+
double displayFlushConfiguredDepth() const {
|
|
26
|
+
return gea::framework::memory::MemoryBackend::displayFlushConfiguredDepth();
|
|
27
|
+
}
|
|
28
|
+
double displayFlushBufferMaxBytes() const {
|
|
29
|
+
return gea::framework::memory::MemoryBackend::displayFlushBufferMaxBytes();
|
|
30
|
+
}
|
|
31
|
+
double displayFlushRows() const { return gea::framework::memory::MemoryBackend::displayFlushRows(); }
|
|
32
|
+
double displayFlushDepth() const { return gea::framework::memory::MemoryBackend::displayFlushDepth(); }
|
|
33
|
+
double displayFlushBufferBytes() const { return gea::framework::memory::MemoryBackend::displayFlushBufferBytes(); }
|
|
34
|
+
double allocationSramCount() const { return gea::framework::memory::MemoryBackend::allocationSramCount(); }
|
|
35
|
+
double allocationPsramCount() const { return gea::framework::memory::MemoryBackend::allocationPsramCount(); }
|
|
36
|
+
double allocationSramBytes() const { return gea::framework::memory::MemoryBackend::allocationSramBytes(); }
|
|
37
|
+
double allocationPsramBytes() const { return gea::framework::memory::MemoryBackend::allocationPsramBytes(); }
|
|
38
|
+
double allocationSramPeakBytes() const { return gea::framework::memory::MemoryBackend::allocationSramPeakBytes(); }
|
|
39
|
+
double allocationPsramPeakBytes() const { return gea::framework::memory::MemoryBackend::allocationPsramPeakBytes(); }
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
inline constexpr MemoryFacade Memory{};
|
|
43
|
+
|
|
44
|
+
} // namespace gea::host
|