Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
9fa46f3e
提交
9fa46f3e
authored
9月 25, 2017
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ActiveSpeakerDetector: improve logic
上级
d25bd20d
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
70 行增加
和
38 行删除
+70
-38
ActiveSpeakerDetector.js
lib/plugins/ActiveSpeakerDetector.js
+70
-38
没有找到文件。
lib/plugins/ActiveSpeakerDetector.js
浏览文件 @
9fa46f3e
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
const
Logger
=
require
(
'../Logger'
);
const
Logger
=
require
(
'../Logger'
);
const
EnhancedEventEmitter
=
require
(
'../EnhancedEventEmitter'
);
const
EnhancedEventEmitter
=
require
(
'../EnhancedEventEmitter'
);
const
MIN_AUDIO_LEVEL
=
-
70
;
// dB.
const
REQUIRED_MIN_AUDIO_LEVEL
=
-
70
;
// dB.
const
REQUIRED_MAX_NUM_REPORTS
=
4
;
const
logger
=
new
Logger
(
'ActiveSpeakerDetector'
);
const
logger
=
new
Logger
(
'ActiveSpeakerDetector'
);
...
@@ -23,9 +24,9 @@ class ActiveSpeakerDetector extends EnhancedEventEmitter
...
@@ -23,9 +24,9 @@ class ActiveSpeakerDetector extends EnhancedEventEmitter
// @type {Room}
// @type {Room}
this
.
_room
=
room
;
this
.
_room
=
room
;
// Latest max audio levels.
// Latest max audio level
report
s.
// @type {Array}
// @type {Array}
this
.
_
latestMaxAudioLevel
s
=
[];
this
.
_
report
s
=
[];
// Current active Producer.
// Current active Producer.
// @type {Producer}
// @type {Producer}
...
@@ -74,83 +75,114 @@ class ActiveSpeakerDetector extends EnhancedEventEmitter
...
@@ -74,83 +75,114 @@ class ActiveSpeakerDetector extends EnhancedEventEmitter
if
(
this
.
_closed
)
if
(
this
.
_closed
)
return
;
return
;
const
times
=
2
;
let
previousActiveProducer
=
this
.
_activeProducer
;
const
latest
=
this
.
_latestMaxAudioLevel
s
;
let
requiredNumReport
s
;
// Insert the loudest audio level entry into the latest array.
if
(
previousActiveProducer
&&
!
previousActiveProducer
.
closed
&&
!
previousActiveProducer
.
paused
)
{
requiredNumReports
=
REQUIRED_MAX_NUM_REPORTS
;
}
else
{
previousActiveProducer
=
null
;
requiredNumReports
=
1
;
this
.
_reports
=
[];
}
const
reports
=
this
.
_reports
;
// Insert the loudest audio level report into the reports array.
// NOTE: This may be undefined, meaning that nobody is producing audio.
// NOTE: This may be undefined, meaning that nobody is producing audio.
latest
.
push
(
levels
[
0
]);
reports
.
push
(
levels
[
0
]);
// No more than REQUIRED_MAX_NUM_REPORTS.
if
(
reports
.
length
>
REQUIRED_MAX_NUM_REPORTS
)
{
reports
.
shift
();
}
// No less than requiredNumReports.
else
if
(
reports
.
length
<
requiredNumReports
)
{
this
.
_mayUpdateActiveSpeaker
(
previousActiveProducer
);
// No more than times.
if
(
latest
.
length
>
times
)
latest
.
shift
();
// No less than times.
else
if
(
latest
.
length
<
times
)
return
;
return
;
}
// If the same Producer was the loudest speaker in the last
4
reports, make
// If the same Producer was the loudest speaker in the last
N
reports, make
// it the active speaker.
// it the active speaker.
let
newActiveProducer
;
let
currentActiveProducer
;
let
newAudioLevel
;
const
numReports
=
reports
.
length
;
const
latestLen
=
latest
.
length
;
for
(
let
i
=
latestLen
-
1
;
i
>=
latestLen
-
time
s
;
--
i
)
for
(
let
i
=
numReports
-
1
;
i
>=
numReports
-
requiredNumReport
s
;
--
i
)
{
{
const
entry
=
latest
[
i
];
const
report
=
reports
[
i
];
if
(
!
entry
||
entry
.
audioLevel
<
MIN_AUDIO_LEVEL
)
if
(
!
report
)
{
{
newActiveProducer
=
undefined
;
currentActiveProducer
=
null
;
break
;
break
;
}
}
const
{
producer
,
audioLevel
}
=
entry
;
const
{
producer
,
audioLevel
}
=
report
;
if
(
producer
.
closed
||
producer
.
paused
)
if
(
producer
.
closed
||
producer
.
paused
||
audioLevel
<
REQUIRED_MIN_AUDIO_LEVEL
)
{
{
newActiveProducer
=
undefined
;
currentActiveProducer
=
null
;
break
;
break
;
}
}
if
(
newActiveProducer
&&
producer
!==
new
ActiveProducer
)
if
(
currentActiveProducer
&&
producer
!==
current
ActiveProducer
)
{
{
newActiveProducer
=
undefined
;
currentActiveProducer
=
null
;
break
;
break
;
}
}
newActiveProducer
=
producer
;
currentActiveProducer
=
producer
;
newAudioLevel
=
audioLevel
;
}
}
// If there is an effective new audio Producer, make it the active one.
// If there is an effective new audio Producer, make it the active one.
if
(
newActiveProducer
&&
newActiveProducer
!==
this
.
_a
ctiveProducer
)
if
(
currentA
ctiveProducer
)
{
{
this
.
_activeProducer
=
newActiveProducer
;
this
.
_mayUpdateActiveSpeaker
(
currentActiveProducer
);
}
// Otherwise check the previous active speaker.
else
{
this
.
_mayUpdateActiveSpeaker
(
previousActiveProducer
);
}
}
_mayUpdateActiveSpeaker
(
activeProducer
)
{
if
(
this
.
_activeProducer
===
activeProducer
)
return
;
this
.
_activeProducer
=
activeProducer
;
if
(
this
.
_activeProducer
)
{
const
peer
=
this
.
_activeProducer
.
peer
;
const
peer
=
this
.
_activeProducer
.
peer
;
logger
.
debug
(
logger
.
debug
(
'emitting "activespeakerchange" [peerName:"%s"]'
,
peer
.
name
);
'emitting "activespeakerchange" [peerName:"%s"]'
,
peer
.
name
);
this
.
safeEmit
(
this
.
safeEmit
(
'activespeakerchange'
,
peer
,
this
.
_activeProducer
,
newAudioLevel
);
'activespeakerchange'
,
peer
,
this
.
_activeProducer
);
}
}
// Otherwise, if the previous active speaker (if any) is closed or paused,
else
// unset it.
else
if
(
this
.
_activeProducer
&&
(
this
.
_activeProducer
.
closed
||
this
.
_activeProducer
.
paused
))
{
{
this
.
_activeProducer
=
undefined
;
logger
.
debug
(
logger
.
debug
(
'emitting "activespeakerchange" [peerName:null]'
);
'emitting "activespeakerchange" [peerName:null]'
);
this
.
safeEmit
(
'activespeakerchange'
,
null
,
null
);
this
.
safeEmit
(
'activespeakerchange'
,
undefined
,
undefined
);
}
}
}
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论