Skip to content

Commit

Permalink
proto の OptionalBool を optional bool にする
Browse files Browse the repository at this point in the history
  • Loading branch information
melpon committed Apr 10, 2024
1 parent fc89057 commit 9bd6288
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 40 deletions.
26 changes: 10 additions & 16 deletions examples/sumomo/sumomo.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,22 +229,16 @@ int main(int argc, char* argv[]) {
soracp_SoraConnectConfig_set_audio(&sora_config,
opt.audio != SUMOMO_OPTIONAL_BOOL_FALSE);

soracp_SoraConnectConfig_set_multistream(&sora_config,
soracp_OPTIONAL_BOOL_TRUE);
soracp_SoraConnectConfig_set_data_channel_signaling(
&sora_config, soracp_OPTIONAL_BOOL_TRUE);
soracp_SoraConnectConfig_set_simulcast(
&sora_config, opt.simulcast == SUMOMO_OPTIONAL_BOOL_NONE
? soracp_OPTIONAL_BOOL_NONE
: opt.simulcast == SUMOMO_OPTIONAL_BOOL_FALSE
? soracp_OPTIONAL_BOOL_FALSE
: soracp_OPTIONAL_BOOL_TRUE);
soracp_SoraConnectConfig_set_simulcast_multicodec(
&sora_config, opt.simulcast_multicodec == SUMOMO_OPTIONAL_BOOL_NONE
? soracp_OPTIONAL_BOOL_NONE
: opt.simulcast_multicodec == SUMOMO_OPTIONAL_BOOL_FALSE
? soracp_OPTIONAL_BOOL_FALSE
: soracp_OPTIONAL_BOOL_TRUE);
soracp_SoraConnectConfig_set_multistream(&sora_config, true);
soracp_SoraConnectConfig_set_data_channel_signaling(&sora_config, true);
if (opt.simulcast != SUMOMO_OPTIONAL_BOOL_NONE) {
soracp_SoraConnectConfig_set_simulcast(
&sora_config, opt.simulcast == SUMOMO_OPTIONAL_BOOL_TRUE);
}
if (opt.simulcast_multicodec != SUMOMO_OPTIONAL_BOOL_NONE) {
soracp_SoraConnectConfig_set_simulcast_multicodec(
&sora_config, opt.simulcast_multicodec == SUMOMO_OPTIONAL_BOOL_TRUE);
}

soracp_SoraConnectConfig_alloc_data_channels(&sora_config, 1);
soracp_DataChannel_set_label(&dc, "#test");
Expand Down
23 changes: 8 additions & 15 deletions proto/soracp.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ syntax = "proto3";

package soracp;

enum OptionalBool {
OPTIONAL_BOOL_NONE = 0;
OPTIONAL_BOOL_TRUE = 1;
OPTIONAL_BOOL_FALSE = 2;
}

enum H264EncoderType {
H264_ENCODER_TYPE_OPEN_H264 = 0;
H264_ENCODER_TYPE_VIDEO_TOOLBOX = 1;
Expand All @@ -28,12 +22,11 @@ message DataChannel {
string direction = 2;

// optional
OptionalBool ordered = 4;

optional bool ordered = 4;
optional int32 max_packet_life_time = 6;
optional int32 max_retransmits = 8;
optional string protocol = 10;
OptionalBool compress = 12;
optional bool compress = 12;
}

message ForwardingFilter {
Expand Down Expand Up @@ -69,13 +62,13 @@ message SoraConnectConfig {
string client_id = 4;
string metadata = 5;
string role = 6;
OptionalBool multistream = 8;
OptionalBool spotlight = 10;
optional bool multistream = 8;
optional bool spotlight = 10;
int32 spotlight_number = 11;
string spotlight_focus_rid = 12;
string spotlight_unfocus_rid = 13;
OptionalBool simulcast = 15;
OptionalBool simulcast_multicodec = 150;
optional bool simulcast = 15;
optional bool simulcast_multicodec = 150;
string simulcast_rid = 16;
bool video = 20;
bool audio = 21;
Expand All @@ -86,8 +79,8 @@ message SoraConnectConfig {
int32 video_bit_rate = 26;
string audio_codec_type = 31;
int32 audio_bit_rate = 34;
OptionalBool data_channel_signaling = 36;
OptionalBool ignore_disconnect_websocket = 39;
optional bool data_channel_signaling = 36;
optional bool ignore_disconnect_websocket = 39;
repeated DataChannel data_channels = 41;
string bundle_id = 43;
string audio_streaming_language_code = 48;
Expand Down
22 changes: 13 additions & 9 deletions src/signaling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,9 +832,9 @@ class SignalingImpl : public Signaling {
}
};
auto set_optional_bool = [](nlohmann::json& js, const std::string& key,
soracp::OptionalBool value) {
if (value != soracp::OPTIONAL_BOOL_NONE) {
js[key] = value == soracp::OPTIONAL_BOOL_TRUE ? true : false;
bool has_value, bool value) {
if (has_value) {
js[key] = value;
}
};
auto set_json = [](nlohmann::json& js, const std::string& key,
Expand All @@ -847,11 +847,12 @@ class SignalingImpl : public Signaling {
set_if(js, "redirect", true, redirect);
set_string(js, "client_id", sc.client_id);
set_string(js, "bundle_id", sc.bundle_id);
set_optional_bool(js, "multistream", sc.multistream);
set_optional_bool(js, "simulcast", sc.simulcast);
set_optional_bool(js, "simulcast_multicodec", sc.simulcast_multicodec);
set_optional_bool(js, "multistream", sc.has_multistream(), sc.multistream);
set_optional_bool(js, "simulcast", sc.has_simulcast(), sc.simulcast);
set_optional_bool(js, "simulcast_multicodec", sc.has_simulcast_multicodec(),
sc.simulcast_multicodec);
set_string(js, "simulcast_rid", sc.simulcast_rid);
set_optional_bool(js, "spotlight", sc.spotlight);
set_optional_bool(js, "spotlight", sc.has_spotlight(), sc.spotlight);
set_if(js, "spotlight_number", sc.spotlight_number,
sc.spotlight_number > 0);
set_string(js, "spotlight_focus_rid", sc.spotlight_focus_rid);
Expand Down Expand Up @@ -892,8 +893,11 @@ class SignalingImpl : public Signaling {

set_string(js, "audio_streaming_language_code",
sc.audio_streaming_language_code);
set_optional_bool(js, "data_channel_signaling", sc.data_channel_signaling);
set_optional_bool(js, "data_channel_signaling",
sc.has_data_channel_signaling(),
sc.data_channel_signaling);
set_optional_bool(js, "ignore_disconnect_websocket",
sc.has_ignore_disconnect_websocket(),
sc.ignore_disconnect_websocket);

for (const auto& d : sc.data_channels) {
Expand All @@ -904,7 +908,7 @@ class SignalingImpl : public Signaling {
d.has_max_packet_life_time());
set_if(dc, "max_retransmits", d.max_retransmits, d.has_max_retransmits());
set_if(dc, "protocol", d.protocol, d.has_protocol());
set_optional_bool(dc, "compress", d.compress);
set_optional_bool(dc, "compress", d.has_compress(), d.compress);
js["data_channels"].push_back(dc);
}

Expand Down

0 comments on commit 9bd6288

Please sign in to comment.