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 13 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
88 changes: 56 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,7 @@ public class Rule
public string? Version;
public string? Metadata;
}

public List<ForwardingFilter> Filters = new List<ForwardingFilter>();
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.

失礼しました。ご指摘の通り不要でした。

/// <summary>
/// カメラの設定
/// </summary>
Expand Down Expand Up @@ -234,8 +235,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 +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)
{
Expand Down Expand Up @@ -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;
}

/// <summary>
/// カメラを切り替えます。
/// </summary>
Expand Down Expand Up @@ -1248,4 +1272,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
78 changes: 50 additions & 28 deletions src/sora.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<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 =
ConvertToForwardingFilter(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(ConvertToForwardingFilter(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 +741,48 @@ bool Sora::InitADM(rtc::scoped_refptr<webrtc::AudioDeviceModule> 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<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
3 changes: 3 additions & 0 deletions src/sora.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class Sora : public std::enable_shared_from_this<Sora>,
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,
Expand Down