Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

マルチ転送フィルターの追加 #108

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
- @torikizi
- [ADD] `Sora.Config` に `ClientCert`, `ClientKey`, `CACert` を追加
- @melpon
- [ADD] ForwardingFilter に name と priority を追加
- @torikizi
- [ADD] ForwardingFilters 機能を使えるようにする
- @torikizi

### misc

Expand Down
91 changes: 59 additions & 32 deletions Sora/Sora.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -85,7 +86,10 @@ public class Rule
public string? Version;
public string? Metadata;
}

public class ForwardingFilters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これはもう不要なはず

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正しました。

{
public List<ForwardingFilter> Filters = new List<ForwardingFilter>();
}
/// <summary>
/// カメラの設定
/// </summary>
Expand Down Expand Up @@ -234,8 +238,8 @@ public class Config
public string ProxyPassword = "";
// Proxy サーバーに接続するときの User-Agent。未設定ならデフォルト値が使われる
public string ProxyAgent = "";

public ForwardingFilter ForwardingFilter;
public List<ForwardingFilter> ForwardingFilters;

// ハードウェアエンコーダー/デコーダーを利用するかどうか。null の場合は実装依存となる
public bool? UseHardwareEncoder;
Expand Down Expand Up @@ -461,36 +465,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(ConvertToInternalFilter(config.ForwardingFilter));
}

if (config.ForwardingFilters != null && config.ForwardingFilters.Count > 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config.ForwardingFilters.Count == 0 の時に空の SoraConf.Internal.ForwardingFilters を設定しないといけないので、config.ForwardingFilters.Count > 0 の条件は外した方が良いです。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ご指摘の通りに修正しました。

{
var ffs = new SoraConf.Internal.ForwardingFilters();
foreach (var filter in config.ForwardingFilters)
{
ff.SetMetadata(config.ForwardingFilter.Metadata);
ffs.filters.Add(ConvertToInternalFilter(filter));
}
cc.SetForwardingFilter(ff);
cc.SetForwardingFilters(ffs);
}
if (config.UseHardwareEncoder.HasValue)
{
Expand Down Expand Up @@ -522,6 +507,48 @@ public void Disconnect()
sora_disconnect(p);
}

private SoraConf.Internal.ForwardingFilter ConvertToInternalFilter(ForwardingFilter filter)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forwarding filter で1個の機能なので、ConvertToInternalForwardingFilter の方が良さそう

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

あとこの関数は static で良いはず

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

名前の変更と static へ変更しました

{
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;
}

/// <summary>
/// カメラを切り替えます。
/// </summary>
Expand Down Expand Up @@ -1248,4 +1275,4 @@ public static IAudioOutputHelper Create(Action onChangeRoute)
#endif
}
}
}
}
7 changes: 7 additions & 0 deletions proto/sora_conf_internal.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional repeated ForwardingFilter forwarding_filters とは書けないんでしたっけ。できないならそのままで良いです。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

書けないようです。ビルドエラーとなりました。

optional bool use_hardware_encoder = 53;
optional string client_cert = 54;
optional string client_key = 55;
Expand Down
77 changes: 49 additions & 28 deletions src/sora.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,35 +447,14 @@ 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<sora::SoraSignalingConfig::ForwardingFilter::Rule> 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 = convertForwardingFilter(cc.forwarding_filter);
}
if (cc.has_forwarding_filters()) {
std::vector<sora::SoraSignalingConfig::ForwardingFilter> filters;
for (const auto& filter : cc.forwarding_filters.filters) {
filters.push_back(convertForwardingFilter(filter));
}
config.forwarding_filter = ff;
config.forwarding_filters = filters;
}
if (cc.has_client_cert()) {
config.client_cert = cc.client_cert;
Expand Down Expand Up @@ -761,6 +740,48 @@ bool Sora::InitADM(rtc::scoped_refptr<webrtc::AudioDeviceModule> adm,
return true;
}

sora::SoraSignalingConfig::ForwardingFilter Sora::convertForwardingFilter(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • convertForwardingFilter だと、sora::SoraSignalingConfig::ForwardingFiltersora_conf::internal::ForwardingFilter に変換する関数に読めるので、convertToForwardingFilter の方が良さそう
  • 全体的に関数名は UpperCamelCase で書いてるので ConvertToForwardingFilter にした方が良さそう

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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<sora::SoraSignalingConfig::ForwardingFilter::Rule> 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<webrtc::VideoTrackSourceInterface> Sora::CreateVideoCapturer(
int capturer_type,
void* unity_camera_texture,
Expand Down
4 changes: 4 additions & 0 deletions src/sora.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ class Sora : public std::enable_shared_from_this<Sora>,
void* GetAndroidApplicationContext(void* env);
static sora_conf::ErrorCode ToErrorCode(sora::SoraSignalingErrorCode ec);

private:
sora::SoraSignalingConfig::ForwardingFilter convertForwardingFilter(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この関数は static にできるはず

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cpp の修正と合わせて static に変更しました。

const sora_conf::internal::ForwardingFilter& filter);

// SoraSignalingObserver の実装
void OnSetOffer(std::string offer) override;
void OnDisconnect(sora::SoraSignalingErrorCode ec,
Expand Down