api: get_streams (#886)

## Link to GitHub Issue or related Pull Request, if one exists
#0

## Description of change
MSE method of streaming video needs the dimensions up front. This new
api delivers that. Also provides an easier way to determine which
screens are available and a way to discover port number.

## Testing
See pending changes in substream project
This commit is contained in:
bicarus
2026-08-22 19:38:48 -07:00
committed by GitHub
parent d51de976b1
commit 95f10ed733
15 changed files with 280 additions and 6 deletions
@@ -11,6 +11,7 @@ part "src/exceptions.dart";
part "src/rc4.dart";
part "src/wrappers/analogs.dart";
part "src/wrappers/buttons.dart";
part "src/wrappers/capture.dart";
part "src/wrappers/card.dart";
part "src/wrappers/coin.dart";
part "src/wrappers/control.dart";
@@ -4,8 +4,8 @@ part of spiceapi;
class Connection {
// settings
static const _TIMEOUT = Duration(seconds: 2);
static const _BUFFER_SIZE = 1024 * 8;
static const _TIMEOUT = Duration(seconds: 3);
static const _BUFFER_SIZE = 1024 * 1024 * 8;
// state
final String host, pass;
@@ -0,0 +1,47 @@
part of spiceapi;
class CaptureData {
int timestamp;
int width, height;
Uint8List data;
}
var _base64DecoderInstance = Base64Decoder();
Future<List> captureGetScreens(Connection con) {
var req = Request("capture", "get_screens");
return con.request(req).then((res) {
return res.getData();
});
}
Future<CaptureData> captureGetJPG(Connection con, {
int screen = 0,
int quality = 70,
int divide = 1,
}) {
var req = Request("capture", "get_jpg");
req.addParam(screen);
req.addParam(quality);
req.addParam(divide);
return con.request(req).then((res) {
var captureData = CaptureData();
var data = res.getData();
if (data.length > 0) captureData.timestamp = data[0];
if (data.length > 1) captureData.width = data[1];
if (data.length > 2) captureData.height = data[2];
if (data.length > 3) {
captureData.data = _base64DecoderInstance.convert(data[3]);
}
return captureData;
});
}
/// Describes the HTTP video stream, or null when this spice2x serves none.
Future<Map> captureGetStreams(Connection con) {
var req = Request("capture", "get_streams");
return con.request(req).then((res) {
var data = res.getData();
return data.length > 0 ? data[0] : null;
});
}
@@ -17,7 +17,7 @@ Future<List> captureGetScreens(Connection con) {
Future<CaptureData> captureGetJPG(Connection con, {
int screen = 0,
int quality = 60,
int quality = 70,
int divide = 1,
}) {
var req = Request("capture", "get_jpg");
@@ -36,3 +36,12 @@ Future<CaptureData> captureGetJPG(Connection con, {
return captureData;
});
}
/// Describes the HTTP video stream, or null when this spice2x serves none.
Future<Map> captureGetStreams(Connection con) {
var req = Request("capture", "get_streams");
return con.request(req).then((res) {
var data = res.getData();
return data.length > 0 ? data[0] : null;
});
}
@@ -2,6 +2,7 @@ from .connection import Connection
from .request import Request
from .analogs import *
from .buttons import *
from .capture import *
from .card import *
from .coin import *
from .control import *
@@ -0,0 +1,33 @@
import base64
from .connection import Connection
from .request import Request
def capture_get_screens(con: Connection):
res = con.request(Request("capture", "get_screens"))
return res.get_data()
def capture_get_jpg(con: Connection, screen: int = 0, quality: int = 70, divide: int = 1):
req = Request("capture", "get_jpg")
req.add_param(screen)
req.add_param(quality)
req.add_param(divide)
data = con.request(req).get_data()
if len(data) < 4:
return None
return {
"timestamp": data[0],
"width": data[1],
"height": data[2],
"data": base64.b64decode(data[3]),
}
def capture_get_streams(con: Connection):
"""Describes the HTTP video stream, or None when this spice2x serves none."""
data = con.request(Request("capture", "get_streams")).get_data()
return data[0] if data else None