Skip to content

Commit

Permalink
Merge branch 'release/2021.13'
Browse files Browse the repository at this point in the history
  • Loading branch information
voluntas committed Oct 19, 2021
2 parents dbaec51 + d31e8bf commit 1a54a74
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 49 deletions.
11 changes: 9 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@

## develop

## 2021.13

- [CHANGE] data_channel_messaging を data_channles へ変更する
- @torikizi

## 2021.12

- [UPDATE] `CLI11``2.1.1` に上げる
- @voluntas
- [UPDATE] `CLI11``2.1.2` に上げる
- @voluntas @melpon
- [UPDATE] libwebrtc のバージョンを `m94.4606.3.4` に上げる
- @voluntas
- [FIX] Let's Encrypt な証明書の SSL 接続が失敗する問題を修正する
- @melpon
- [ADD] DataChannel メッセージングのデータに時刻とカウンターを追加
- @melpon

## 2021.11

Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ Options:
Signaling metadata used in connect message
--sora-signaling-notify-metadata TEXT:JSON Value
Signaling metadata
--sora-data-channel-messaging TEXT:JSON Value
DataChannel messaging
--sora-data-channels TEXT:JSON Value
DataChannels
--fake-network-send-queue-length-packets UINT
Queue length in number of packets for sending
--fake-network-send-queue-delay-ms INT
Expand Down Expand Up @@ -186,3 +186,15 @@ limitations under the License.

[ゲーム等に使えるフリー声素材配布ページ \- あみたろの声素材工房](https://www14.big.or.jp/~amiami/happy/voice.html)

## 優先実装

優先実装とは Sora のライセンスを契約頂いているお客様限定で Momo の実装予定機能を有償にて前倒しで実装することです。

### 優先実装が可能な機能一覧

**詳細は Discord やメールなどでお気軽にお問い合わせください**

- Content Hint への対応
- --fake-video-capture で mjpeg も指定可能にする
- --audio-device 追加

4 changes: 2 additions & 2 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ZAKURO_VERSION=2021.12
ZAKURO_VERSION=2021.13
WEBRTC_BUILD_VERSION=94.4606.3.4
BOOST_VERSION=1.77.0
CLI11_VERSION=2.1.1
CLI11_VERSION=2.1.2
CMAKE_VERSION=3.21.3
BLEND2D_VERSION=3a0299c9126d19759a483ac3267a52b50ec77141
ASMJIT_VERSION=d0d14ac774977d0060a351f66e35cb57ba0bf59c
Expand Down
2 changes: 1 addition & 1 deletion doc/SUPPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

最新の状況などは Discord で共有しています。

https://discord.gg/eEUZf6j
https://discord.gg/shiguredo

## バグ報告

Expand Down
27 changes: 22 additions & 5 deletions doc/USE.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,30 @@ zakuro:
role: sendrecv
multistream: true
data-channel-signaling: true
data-channel-messaging:
data-channels:
- label: "#test"
direction: "sendrecv"
# 省略時は 500 (ms)
interval: 1000
# 省略時は 10 (bytes)
size_min: 10
# 省略時は 10 (bytes)
# 省略時は 16 (bytes)
size_min: 16
# 省略時は 16 (bytes)
size_max: 100
```
```
### 複数シグナリング URL
```yaml
zakuro:
instances:
- name: zakuro
vcs: 2
sora:
signaling-url:
- "wss://sora1.example.com/signaling"
- "wss://sora2.example.com/signaling"
- "wss://sora3.example.com/signaling"
channel-id: sora
role: sendrecv
multistream: true
```
24 changes: 23 additions & 1 deletion src/scenario_player.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef SCENARIO_PLAYER_H_
#define SCENARIO_PLAYER_H_

#include <chrono>
#include <map>
#include <memory>
#include <random>
Expand Down Expand Up @@ -166,8 +167,28 @@ class ScenarioPlayer {
}
case ScenarioData::OP_SEND_DATA_CHANNEL_MESSAGE: {
auto& op = boost::get<ScenarioData::OpSendDataChannelMessage>(opv);
std::string data = config_.binary_pool->Get(op.min_size, op.max_size);
std::string data =
config_.binary_pool->Get(op.min_size - 16, op.max_size - 16);

// 先頭に8バイトに現在時刻(マイクロ秒単位の UNIX Time)、次の8バイトにカウンターを入れる
char buf[16];
uint64_t time = std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
for (int i = 0; i < 8; i++) {
buf[i] = (char)((time >> ((7 - i) * 8)) & 0xff);
}
auto& counter = dc_counter_[op.label];
for (int i = 0; i < 8; i++) {
buf[i + 8] = (char)((counter >> ((7 - i) * 8)) & 0xff);
}
data.insert(data.begin(), buf, buf + sizeof(data));

RTC_LOG(LS_INFO) << "Send DataChannel unixtime(us)=" << time
<< " counter=" << counter;

(*config_.vcs)[client_id]->SendMessage(op.label, data);
counter += 1;
break;
}
case ScenarioData::OP_DISCONNECT: {
Expand Down Expand Up @@ -199,6 +220,7 @@ class ScenarioPlayer {
std::vector<ClientInfo> client_infos_;
VoiceNumberReader voice_reader_;
std::map<std::string, std::shared_ptr<ScenarioPlayer>> sub_scenario_;
std::map<std::string, uint64_t> dc_counter_;
};

#endif
25 changes: 22 additions & 3 deletions src/sora/sora_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ void SoraClient::DoSendConnect(bool redirect) {
*config_.ignore_disconnect_websocket;
}

if (!config_.data_channel_messaging.is_null()) {
json_message["data_channel_messaging"] = config_.data_channel_messaging;
if (!config_.data_channels.is_null()) {
json_message["data_channels"] = config_.data_channels;
}

ws_->WriteText(boost::json::serialize(json_message),
Expand Down Expand Up @@ -681,7 +681,26 @@ void SoraClient::OnMessage(
<< " datasize=" << data.size();

// ハンドリングする必要のあるラベル以外は何もしない
if (label != "signaling" && label != "stats") {
if (label != "signaling" && label != "stats" && label[0] != '#') {
return;
}

// zakuro の場合、DataChannel メッセージは Fake データだけのはずで、
// その場合は先頭 16 バイトに特定のデータが入っている。
if (label[0] == '#') {
if (data.size() < 16) {
return;
}
uint64_t time = 0;
for (int i = 0; i < 8; i++) {
time |= ((uint64_t)data[i] & 0xff) << ((7 - i) * 8);
}
uint64_t counter = 0;
for (int i = 0; i < 8; i++) {
counter |= ((uint64_t)data[i + 8] & 0xff) << ((7 - i) * 8);
}
RTC_LOG(LS_INFO) << "Recv DataChannel unixtime(us)=" << time
<< " counter=" << counter;
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/sora/sora_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct SoraClientConfig {
int data_channel_signaling_timeout = 180;
boost::optional<bool> ignore_disconnect_websocket;
int disconnect_wait_timeout = 5;
boost::json::value data_channel_messaging;
boost::json::value data_channels;
};

class SoraClient : public std::enable_shared_from_this<SoraClient>,
Expand Down
18 changes: 9 additions & 9 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ void Util::ParseArgs(const std::vector<std::string>& cargs,
app.add_option("--sora-signaling-notify-metadata",
sora_signaling_notify_metadata, "Signaling metadata")
->check(is_json);
std::string sora_data_channel_messaging;
app.add_option("--sora-data-channel-messaging", sora_data_channel_messaging,
"DataChannel messaging")
std::string sora_data_channels;
app.add_option("--sora-data-channels", sora_data_channels,
"DataChannels")
->check(is_json);

// Fake network 系
Expand Down Expand Up @@ -344,9 +344,9 @@ void Util::ParseArgs(const std::vector<std::string>& cargs,
config.sora_signaling_notify_metadata =
boost::json::parse(sora_signaling_notify_metadata);
}
if (!sora_data_channel_messaging.empty()) {
config.sora_data_channel_messaging =
boost::json::parse(sora_data_channel_messaging);
if (!sora_data_channels.empty()) {
config.sora_data_channels =
boost::json::parse(sora_data_channels);
}
}

Expand Down Expand Up @@ -518,9 +518,9 @@ std::vector<std::vector<std::string>> Util::NodeToArgs(const YAML::Node& inst) {
args.push_back("--sora-signaling-notify-metadata");
args.push_back(boost::json::serialize(value));
}
if (sora["data-channel-messaging"]) {
boost::json::value value = NodeToJson(sora["data-channel-messaging"]);
args.push_back("--sora-data-channel-messaging");
if (sora["data-channels"]) {
boost::json::value value = NodeToJson(sora["data-channels"]);
args.push_back("--sora-data-channels");
args.push_back(boost::json::serialize(value));
}
}
Expand Down
44 changes: 22 additions & 22 deletions src/zakuro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,31 @@

Zakuro::Zakuro(ZakuroConfig config) : config_(std::move(config)) {}

const int MESSAGE_SIZE_MIN = 1;
const int MESSAGE_SIZE_MIN = 16;
const int MESSAGE_SIZE_MAX = 256 * 1000;
const int BINARY_POOL_SIZE = 1 * 1024 * 1024;

struct DataChannelMessaging {
struct DataChannels {
struct Channel {
std::string label;
int interval = 500;
int size_min = 10;
int size_max = 10;
int size_min = 16;
int size_max = 16;
};
std::vector<Channel> channels;
boost::json::value remain;
};

static bool ParseDataChannelMessaging(boost::json::value data_channel_messaging,
DataChannelMessaging& m) {
m = DataChannelMessaging();
boost::json::value& dcm = data_channel_messaging;
if (!dcm.is_array()) {
static bool ParseDataChannels(boost::json::value data_channels,
DataChannels& m) {
m = DataChannels();
boost::json::value& dcs = data_channels;
if (!dcs.is_array()) {
std::cout << __LINE__ << std::endl;
return false;
}
for (auto& j : dcm.as_array()) {
DataChannelMessaging::Channel ch;
for (auto& j : dcs.as_array()) {
DataChannels::Channel ch;

if (!j.is_object()) {
std::cout << __LINE__ << std::endl;
Expand Down Expand Up @@ -152,7 +152,7 @@ static bool ParseDataChannelMessaging(boost::json::value data_channel_messaging,
m.channels.push_back(ch);
}
}
m.remain = dcm;
m.remain = dcs;
return true;
}

Expand Down Expand Up @@ -265,11 +265,11 @@ int Zakuro::Run() {
}

// DataChannel メッセージング
DataChannelMessaging dcm;
if (!config_.sora_data_channel_messaging.is_null()) {
if (!ParseDataChannelMessaging(config_.sora_data_channel_messaging, dcm)) {
DataChannels dcs;
if (!config_.sora_data_channels.is_null()) {
if (!ParseDataChannels(config_.sora_data_channels, dcs)) {
std::cerr << "[" << config_.name
<< "] failed to parse DataChannel messaging" << std::endl;
<< "] failed to parse DataChannels" << std::endl;
return 2;
}
}
Expand Down Expand Up @@ -311,7 +311,7 @@ int Zakuro::Run() {
sorac_config.ignore_disconnect_websocket =
config_.sora_ignore_disconnect_websocket;
sorac_config.disconnect_wait_timeout = config_.sora_disconnect_wait_timeout;
sorac_config.data_channel_messaging = dcm.remain;
sorac_config.data_channels = dcs.remain;

for (int i = 0; i < config_.vcs; i++) {
auto vc = std::unique_ptr<VirtualClient>(
Expand All @@ -326,12 +326,12 @@ int Zakuro::Run() {
spc.binary_pool.reset(new BinaryPool(BINARY_POOL_SIZE));

// メインのシナリオとは別に、ラベル毎に裏で DataChannel を送信し続けるシナリオを作る
std::vector<std::tuple<std::string, ScenarioData>> dcm_data;
for (const auto& ch : dcm.channels) {
std::vector<std::tuple<std::string, ScenarioData>> dcs_data;
for (const auto& ch : dcs.channels) {
ScenarioData sd;
sd.Sleep(ch.interval, ch.interval);
sd.SendDataChannelMessage(ch.label, ch.size_min, ch.size_max);
dcm_data.push_back(std::make_tuple("scenario-dcm-" + ch.label, sd));
dcs_data.push_back(std::make_tuple("scenario-dcs-" + ch.label, sd));
}

ScenarioPlayer scenario_player(spc);
Expand All @@ -343,12 +343,12 @@ int Zakuro::Run() {
loop_index = 1;
} else if (config_.scenario == "") {
data.Reconnect();
for (const auto& d : dcm_data) {
for (const auto& d : dcs_data) {
data.PlaySubScenario(std::get<0>(d), std::get<1>(d), 0);
}
data.Sleep(1000, 5000);
data.PlayVoiceNumberClient();
loop_index = 1 + dcm_data.size();
loop_index = 1 + dcs_data.size();
} else if (config_.scenario == "reconnect") {
data.Reconnect();
data.Sleep(1000, 5000);
Expand Down
2 changes: 1 addition & 1 deletion src/zakuro.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct ZakuroConfig {
int sora_disconnect_wait_timeout = 5;
boost::json::value sora_metadata;
boost::json::value sora_signaling_notify_metadata;
boost::json::value sora_data_channel_messaging;
boost::json::value sora_data_channels;

webrtc::BuiltInNetworkBehaviorConfig fake_network_send;
webrtc::BuiltInNetworkBehaviorConfig fake_network_receive;
Expand Down

0 comments on commit 1a54a74

Please sign in to comment.