diff --git a/CHANGES.md b/CHANGES.md index 17aa236..5645803 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,6 +18,9 @@ - @torikizi - [CHANGE] CMakefile の依存から libva と libdrm を削除する - @torikizi +- [CHANGE] ForwardingFilter は非推奨であるため Obsolete を追加 + - 今後は ForwardingFilters を利用するように促すメッセージを追加 + - @torikizi - [UPDATE] Sora C++ SDK を `2024.8.0` に上げる - WEBRTC_BUILD_VERSION を `m131.6778.4.0` にアップデート - BOOST_VERSION を 1.87.0 にアップデート @@ -28,6 +31,10 @@ - @torikizi - [ADD] `Sora.Config` に `ClientCert`, `ClientKey`, `CACert` を追加 - @melpon +- [ADD] ForwardingFilter に name と priority を追加 + - @torikizi +- [ADD] ForwardingFilters 機能を使えるようにする + - @torikizi ### misc diff --git a/Sora/Sora.cs b/Sora/Sora.cs index 09fd638..dc94ce7 100644 --- a/Sora/Sora.cs +++ b/Sora/Sora.cs @@ -71,10 +71,11 @@ public class DataChannel public const string FieldKind = "kind"; public const string OperatorIsIn = "is_in"; public const string OperatorIsNotIn = "is_not_in"; - public class ForwardingFilter { public string? Action; + public string? Name; + public int? Priority; public class Rule { public string Field; @@ -85,7 +86,6 @@ public class Rule public string? Version; public string? Metadata; } - /// /// カメラの設定 /// @@ -234,8 +234,9 @@ public class Config public string ProxyPassword = ""; // Proxy サーバーに接続するときの User-Agent。未設定ならデフォルト値が使われる public string ProxyAgent = ""; - + [System.Obsolete("forwardingFilter は非推奨です。代わりに forwardingFilters を使用してください。")] public ForwardingFilter ForwardingFilter; + public List ForwardingFilters; // ハードウェアエンコーダー/デコーダーを利用するかどうか。null の場合は実装依存となる public bool? UseHardwareEncoder; @@ -461,36 +462,17 @@ public void Connect(Config config) cc.proxy_agent = config.ProxyAgent; if (config.ForwardingFilter != null) { - var ff = new SoraConf.Internal.ForwardingFilter(); - if (config.ForwardingFilter.Action != null) - { - ff.SetAction(config.ForwardingFilter.Action); - } - foreach (var rs in config.ForwardingFilter.Rules) - { - var ccrs = new SoraConf.Internal.ForwardingFilter.Rules(); - foreach (var r in rs) - { - var ccr = new SoraConf.Internal.ForwardingFilter.Rule(); - ccr.field = r.Field; - ccr.op = r.Operator; - foreach (var v in r.Values) - { - ccr.values.Add(v); - } - ccrs.rules.Add(ccr); - } - ff.rules.Add(ccrs); - } - if (config.ForwardingFilter.Version != null) - { - ff.SetVersion(config.ForwardingFilter.Version); - } - if (config.ForwardingFilter.Metadata != null) + cc.SetForwardingFilter(ConvertToInternalForwardingFilter(config.ForwardingFilter)); + } + + if (config.ForwardingFilters != null) + { + var ffs = new SoraConf.Internal.ForwardingFilters(); + foreach (var filter in config.ForwardingFilters) { - ff.SetMetadata(config.ForwardingFilter.Metadata); + ffs.filters.Add(ConvertToInternalForwardingFilter(filter)); } - cc.SetForwardingFilter(ff); + cc.SetForwardingFilters(ffs); } if (config.UseHardwareEncoder.HasValue) { @@ -522,6 +504,48 @@ public void Disconnect() sora_disconnect(p); } + static SoraConf.Internal.ForwardingFilter ConvertToInternalForwardingFilter(ForwardingFilter filter) + { + var ff = new SoraConf.Internal.ForwardingFilter(); + if (filter.Action != null) + { + ff.SetAction(filter.Action); + } + if (filter.Name != null) + { + ff.SetName(filter.Name); + } + if (filter.Priority.HasValue) + { + ff.SetPriority(filter.Priority.Value); + } + foreach (var rs in filter.Rules) + { + var ccrs = new SoraConf.Internal.ForwardingFilter.Rules(); + foreach (var r in rs) + { + var ccr = new SoraConf.Internal.ForwardingFilter.Rule(); + ccr.field = r.Field; + ccr.op = r.Operator; + foreach (var v in r.Values) + { + ccr.values.Add(v); + } + ccrs.rules.Add(ccr); + } + ff.rules.Add(ccrs); + } + if (filter.Version != null) + { + ff.SetVersion(filter.Version); + } + if (filter.Metadata != null) + { + ff.SetMetadata(filter.Metadata); + } + return ff; + } + /// /// カメラを切り替えます。 /// @@ -1248,4 +1272,4 @@ public static IAudioOutputHelper Create(Action onChangeRoute) #endif } } -} +} \ No newline at end of file diff --git a/proto/sora_conf_internal.proto b/proto/sora_conf_internal.proto index 1789086..98cf1b9 100644 --- a/proto/sora_conf_internal.proto +++ b/proto/sora_conf_internal.proto @@ -14,6 +14,8 @@ message DataChannel { message ForwardingFilter { optional string action = 2; + optional string name = 4; + optional int32 priority = 6; message Rule { string field = 1; string op = 2; @@ -27,6 +29,10 @@ message ForwardingFilter { optional string metadata = 7; } +message ForwardingFilters { + repeated ForwardingFilter filters = 1; +} + message CameraConfig { int32 capturer_type = 17; int64 unity_camera_texture = 18; @@ -80,6 +86,7 @@ message ConnectConfig { string audio_streaming_language_code = 48; string signaling_notify_metadata = 49; optional ForwardingFilter forwarding_filter = 51; + optional ForwardingFilters forwarding_filters = 52; optional bool use_hardware_encoder = 53; optional string client_cert = 54; optional string client_key = 55; diff --git a/src/sora.cpp b/src/sora.cpp index b2a3dd1..f06ab75 100644 --- a/src/sora.cpp +++ b/src/sora.cpp @@ -447,35 +447,15 @@ void Sora::DoConnect(const sora_conf::internal::ConnectConfig& cc, config.proxy_agent = cc.proxy_agent; config.audio_streaming_language_code = cc.audio_streaming_language_code; if (cc.has_forwarding_filter()) { - sora::SoraSignalingConfig::ForwardingFilter ff; - if (cc.forwarding_filter.has_action()) { - ff.action = cc.forwarding_filter.action; - } - for (const auto& rs : cc.forwarding_filter.rules) { - std::vector ffrs; - for (const auto& r : rs.rules) { - sora::SoraSignalingConfig::ForwardingFilter::Rule ffr; - ffr.field = r.field; - ffr.op = r.op; - ffr.values = r.values; - ffrs.push_back(ffr); - } - ff.rules.push_back(ffrs); - } - if (cc.forwarding_filter.has_version()) { - ff.version = cc.forwarding_filter.version; - } - if (cc.forwarding_filter.has_metadata()) { - boost::system::error_code ec; - auto ffmd = boost::json::parse(cc.forwarding_filter.metadata, ec); - if (ec) { - RTC_LOG(LS_WARNING) << "Invalid JSON: forwarding_filter metadata=" - << cc.forwarding_filter.metadata; - } else { - ff.metadata = ffmd; - } + config.forwarding_filter = + ConvertToForwardingFilter(cc.forwarding_filter); + } + if (cc.has_forwarding_filters()) { + std::vector filters; + for (const auto& filter : cc.forwarding_filters.filters) { + filters.push_back(ConvertToForwardingFilter(filter)); } - config.forwarding_filter = ff; + config.forwarding_filters = filters; } if (cc.has_client_cert()) { config.client_cert = cc.client_cert; @@ -761,6 +741,48 @@ bool Sora::InitADM(rtc::scoped_refptr adm, return true; } +sora::SoraSignalingConfig::ForwardingFilter Sora::ConvertToForwardingFilter( + const sora_conf::internal::ForwardingFilter& filter) { + sora::SoraSignalingConfig::ForwardingFilter ff; + + if (filter.has_action()) { + ff.action = filter.action; + } + if (filter.has_name()) { + ff.name = filter.name; + } + if (filter.has_priority()) { + ff.priority = filter.priority; + } + for (const auto& rs : filter.rules) { + std::vector ffrs; + for (const auto& r : rs.rules) { + sora::SoraSignalingConfig::ForwardingFilter::Rule ffr; + ffr.field = r.field; + ffr.op = r.op; + ffr.values = r.values; + ffrs.push_back(ffr); + } + ff.rules.push_back(ffrs); + } + + if (filter.has_version()) { + ff.version = filter.version; + } + if (filter.has_metadata()) { + boost::system::error_code ec; + auto ffmd = boost::json::parse(filter.metadata, ec); + if (ec) { + RTC_LOG(LS_WARNING) << "Invalid JSON: forwarding_filter metadata=" + << filter.metadata; + } else { + ff.metadata = ffmd; + } + } + + return ff; +} + rtc::scoped_refptr Sora::CreateVideoCapturer( int capturer_type, void* unity_camera_texture, diff --git a/src/sora.h b/src/sora.h index ebbbd33..1345eb2 100644 --- a/src/sora.h +++ b/src/sora.h @@ -80,6 +80,9 @@ class Sora : public std::enable_shared_from_this, void* GetAndroidApplicationContext(void* env); static sora_conf::ErrorCode ToErrorCode(sora::SoraSignalingErrorCode ec); + static sora::SoraSignalingConfig::ForwardingFilter ConvertToForwardingFilter( + const sora_conf::internal::ForwardingFilter& filter); + // SoraSignalingObserver の実装 void OnSetOffer(std::string offer) override; void OnDisconnect(sora::SoraSignalingErrorCode ec,