Skip to content

Commit

Permalink
ストリーム転送を配列からBase64に変更
Browse files Browse the repository at this point in the history
このほうが有意に軽い
(環境が良くて計測困難なら再生オフして4倍速ぐらいで再生してみる)
単純に転送量が減るのと、JavaScriptの型なし配列を経由せずに済むからと予想
  • Loading branch information
xtne6f committed Jun 4, 2022
1 parent ba8e9e6 commit 0e819fe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 32 deletions.
46 changes: 14 additions & 32 deletions TVTDataBroadcastingWV2/TVTDataBroadcastingWV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,11 @@ LRESULT CALLBACK CDataBroadcastingWV2::MessageWndProc(HWND hWnd, UINT uMsg, WPAR
{
continue;
}
WCHAR head[] = LR"({"type":"stream","data":[)";
WCHAR tail[] = LR"(]})";
WCHAR head[] = LR"({"type":"streamBase64","data":")";
WCHAR tail[] = LR"("})";
auto packetBlockSize = packets.value().size();
auto packetSize = pThis->packetQueue.packetSize;
size_t size = _countof(head) - 1 + packetBlockSize * 4 /* '255,' */ + _countof(tail) + 1;
size_t size = _countof(head) - 1 + (packetBlockSize + 2) / 3 * 4 /* Base64 */ + _countof(tail) + 1;
if (pThis->packetsToJsonBuf.size() < size)
{
pThis->packetsToJsonBuf.resize(size);
Expand All @@ -620,37 +620,19 @@ LRESULT CALLBACK CDataBroadcastingWV2::MessageWndProc(HWND hWnd, UINT uMsg, WPAR
size_t pos = 0;
pos += wcslen(head);
auto buffer = packets.value().data();
for (size_t p = 0; p < packetBlockSize; p += packetSize)
static const WCHAR base64[66] = L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
for (size_t i = 0; i < packetBlockSize; i += 3)
{
for (size_t i = p; i < p + packetSize; i++)
{
// デバッグビルドだからかitowとか遅すぎて間に合わないので自前でやる
if (buffer[i] < 10)
{
buf[pos] = L'0' + buffer[i];
pos += 1;
}
else if (buffer[i] < 100)
{
buf[pos] = L'0' + (buffer[i] / 10);
pos += 1;
buf[pos] = L'0' + (buffer[i] % 10);
pos += 1;
}
else
{
buf[pos] = L'0' + (buffer[i] / 100);
pos += 1;
buf[pos] = L'0' + ((buffer[i] / 10) % 10);
pos += 1;
buf[pos] = L'0' + (buffer[i] % 10);
pos += 1;
}
buf[pos] = L',';
pos += 1;
}
buf[pos] = base64[buffer[i] >> 2];
pos += 1;
buf[pos] = base64[((buffer[i] & 3) << 4) | (i + 1 < packetBlockSize ? buffer[i + 1] >> 4 : 0)];
pos += 1;
buf[pos] = base64[i + 1 < packetBlockSize ? ((buffer[i + 1] & 15) << 2) |
(i + 2 < packetBlockSize ? buffer[i + 2] >> 6 : 0) : 64];
pos += 1;
buf[pos] = base64[i + 2 < packetBlockSize ? buffer[i + 2] & 63 : 64];
pos += 1;
}
pos--;
wcscpy_s(buf + pos, size - pos, tail);
auto hr = pThis->webView->PostWebMessageAsJson(buf);
}
Expand Down
12 changes: 12 additions & 0 deletions browser/src/TVTDataBroadcastingWV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ type ToWebViewMessage = {
type: "stream",
data: number[],
time?: number,
} | {
type: "streamBase64",
data: string,
time?: number,
} | {
type: "key",
keyCode: number,
Expand Down Expand Up @@ -408,6 +412,14 @@ function onWebViewMessage(data: ToWebViewMessage, reply: (data: FromWebViewMessa
if (prevPCR !== curPCR && curPCR != null) {
player.updateTime(curPCR - 450);
}
} else if (data.type === "streamBase64") {
const ts = data.data;
const prevPCR = pcr;
tsStream.parse(Buffer.from(ts, "base64"));
const curPCR = pcr;
if (prevPCR !== curPCR && curPCR != null) {
player.updateTime(curPCR - 450);
}
} else if (data.type === "key") {
bmlBrowser.content.processKeyDown(data.keyCode);
bmlBrowser.content.processKeyUp(data.keyCode);
Expand Down

0 comments on commit 0e819fe

Please sign in to comment.