Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
a0736b4e
提交
a0736b4e
authored
10月 05, 2017
作者:
José Luis Millán
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
EncodingContext: set codec layer preferences
上级
8d4b7e9c
隐藏空白字符变更
内嵌
并排
正在显示
14 个修改的文件
包含
158 行增加
和
13 行删除
+158
-13
Consumer.js
lib/Consumer.js
+28
-0
Request.hpp
worker/include/Channel/Request.hpp
+1
-0
PayloadDescriptorHandler.hpp
worker/include/RTC/Codecs/PayloadDescriptorHandler.hpp
+21
-1
VP8.hpp
worker/include/RTC/Codecs/VP8.hpp
+1
-1
Consumer.hpp
worker/include/RTC/Consumer.hpp
+1
-0
RtpPacket.hpp
worker/include/RTC/RtpPacket.hpp
+1
-1
SeqManager.hpp
worker/include/RTC/SeqManager.hpp
+2
-0
Request.cpp
worker/src/Channel/Request.cpp
+1
-0
VP8.cpp
worker/src/RTC/Codecs/VP8.cpp
+24
-3
Consumer.cpp
worker/src/RTC/Consumer.cpp
+27
-4
Router.cpp
worker/src/RTC/Router.cpp
+35
-0
RtpPacket.cpp
worker/src/RTC/RtpPacket.cpp
+3
-3
SeqManager.cpp
worker/src/RTC/SeqManager.cpp
+12
-0
Worker.cpp
worker/src/Worker.cpp
+1
-0
没有找到文件。
lib/Consumer.js
浏览文件 @
a0736b4e
...
@@ -596,6 +596,34 @@ class Consumer extends EnhancedEventEmitter
...
@@ -596,6 +596,34 @@ class Consumer extends EnhancedEventEmitter
});
});
}
}
/**
* Sets the encoding preferences.
*
* @param {String} profile
*/
setEncodingPreferences
(
preferences
)
{
logger
.
debug
(
'setEncodingPreferences() [preferences:%o]'
,
preferences
);
if
(
this
.
_closed
)
{
logger
.
error
(
'setEncodingPreferences() | Consumer closed'
);
return
;
}
this
.
_channel
.
request
(
'consumer.setEncodingPreferences'
,
this
.
_internal
,
preferences
)
.
then
(()
=>
{
logger
.
debug
(
'"consumer.setEncodingPreferences" request succeeded'
);
})
.
catch
((
error
)
=>
{
logger
.
error
(
'"consumer.setEncodingPreferences" request failed: %s'
,
String
(
error
));
});
}
/**
/**
* Preferred receiving profile was set on my remote Consumer.
* Preferred receiving profile was set on my remote Consumer.
*
*
...
...
worker/include/Channel/Request.hpp
浏览文件 @
a0736b4e
...
@@ -49,6 +49,7 @@ namespace Channel
...
@@ -49,6 +49,7 @@ namespace Channel
CONSUMER_PAUSE
,
CONSUMER_PAUSE
,
CONSUMER_RESUME
,
CONSUMER_RESUME
,
CONSUMER_SET_PREFERRED_PROFILE
,
CONSUMER_SET_PREFERRED_PROFILE
,
CONSUMER_SET_ENCODING_PREFERENCES
,
CONSUMER_REQUEST_KEY_FRAME
CONSUMER_REQUEST_KEY_FRAME
};
};
...
...
worker/include/RTC/Codecs/PayloadDescriptorHandler.hpp
浏览文件 @
a0736b4e
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
#define MS_RTC_PAYLOAD_DESCRIPTOR_HANDLER_HPP
#define MS_RTC_PAYLOAD_DESCRIPTOR_HANDLER_HPP
#include "common.hpp"
#include "common.hpp"
#include <limits> // std::numeric_limits
namespace
RTC
namespace
RTC
{
{
...
@@ -17,21 +18,40 @@ namespace RTC
...
@@ -17,21 +18,40 @@ namespace RTC
// Encoding context used by PayloadDescriptionHandler to properly rewrite the PayloadDescriptor.
// Encoding context used by PayloadDescriptionHandler to properly rewrite the PayloadDescriptor.
class
EncodingContext
class
EncodingContext
{
{
public
:
struct
Preferences
{
Preferences
()
=
default
;
uint8_t
qualityLayer
{
std
::
numeric_limits
<
uint8_t
>::
max
()
};
uint8_t
spatialLayer
{
std
::
numeric_limits
<
uint8_t
>::
max
()
};
uint8_t
temporalLayer
{
std
::
numeric_limits
<
uint8_t
>::
max
()
};
};
public
:
public
:
virtual
void
SyncRequired
()
=
0
;
virtual
void
SyncRequired
()
=
0
;
virtual
void
SetPreferences
(
Preferences
preferences
);
public
:
Preferences
preferences
;
};
};
class
PayloadDescriptorHandler
class
PayloadDescriptorHandler
{
{
public
:
public
:
virtual
void
Dump
()
const
=
0
;
virtual
void
Dump
()
const
=
0
;
virtual
void
Encode
(
RTC
::
Codecs
::
EncodingContext
*
context
,
uint8_t
*
data
)
=
0
;
virtual
bool
Encode
(
RTC
::
Codecs
::
EncodingContext
*
context
,
uint8_t
*
data
)
=
0
;
virtual
void
Restore
(
uint8_t
*
data
)
=
0
;
virtual
void
Restore
(
uint8_t
*
data
)
=
0
;
virtual
bool
IsKeyFrame
()
const
=
0
;
virtual
bool
IsKeyFrame
()
const
=
0
;
public
:
public
:
virtual
~
PayloadDescriptorHandler
()
=
default
;
virtual
~
PayloadDescriptorHandler
()
=
default
;
};
};
inline
void
EncodingContext
::
SetPreferences
(
Preferences
preferences
)
{
this
->
preferences
=
preferences
;
}
}
// namespace Codecs
}
// namespace Codecs
}
// namespace RTC
}
// namespace RTC
...
...
worker/include/RTC/Codecs/VP8.hpp
浏览文件 @
a0736b4e
...
@@ -93,7 +93,7 @@ namespace RTC
...
@@ -93,7 +93,7 @@ namespace RTC
public
:
public
:
void
Dump
()
const
;
void
Dump
()
const
;
void
Encode
(
RTC
::
Codecs
::
EncodingContext
*
context
,
uint8_t
*
data
);
bool
Encode
(
RTC
::
Codecs
::
EncodingContext
*
context
,
uint8_t
*
data
);
void
Restore
(
uint8_t
*
data
);
void
Restore
(
uint8_t
*
data
);
bool
IsKeyFrame
()
const
;
bool
IsKeyFrame
()
const
;
...
...
worker/include/RTC/Consumer.hpp
浏览文件 @
a0736b4e
...
@@ -49,6 +49,7 @@ namespace RTC
...
@@ -49,6 +49,7 @@ namespace RTC
void
SourceRtpParametersUpdated
();
void
SourceRtpParametersUpdated
();
void
SetPreferredProfile
(
const
RTC
::
RtpEncodingParameters
::
Profile
profile
);
void
SetPreferredProfile
(
const
RTC
::
RtpEncodingParameters
::
Profile
profile
);
void
SetSourcePreferredProfile
(
const
RTC
::
RtpEncodingParameters
::
Profile
profile
);
void
SetSourcePreferredProfile
(
const
RTC
::
RtpEncodingParameters
::
Profile
profile
);
void
SetEncodingPreferences
(
const
RTC
::
Codecs
::
EncodingContext
::
Preferences
preferences
);
void
Disable
();
void
Disable
();
bool
IsEnabled
()
const
;
bool
IsEnabled
()
const
;
const
RTC
::
RtpParameters
&
GetParameters
()
const
;
const
RTC
::
RtpParameters
&
GetParameters
()
const
;
...
...
worker/include/RTC/RtpPacket.hpp
浏览文件 @
a0736b4e
...
@@ -127,7 +127,7 @@ namespace RTC
...
@@ -127,7 +127,7 @@ namespace RTC
void
RtxEncode
(
uint8_t
payloadType
,
uint32_t
ssrc
,
uint16_t
seq
);
void
RtxEncode
(
uint8_t
payloadType
,
uint32_t
ssrc
,
uint16_t
seq
);
bool
RtxDecode
(
uint8_t
payloadType
,
uint32_t
ssrc
);
bool
RtxDecode
(
uint8_t
payloadType
,
uint32_t
ssrc
);
void
SetPayloadDescriptorHandler
(
RTC
::
Codecs
::
PayloadDescriptorHandler
*
payloadDescriptorHandler
);
void
SetPayloadDescriptorHandler
(
RTC
::
Codecs
::
PayloadDescriptorHandler
*
payloadDescriptorHandler
);
void
EncodePayload
(
RTC
::
Codecs
::
EncodingContext
*
context
);
bool
EncodePayload
(
RTC
::
Codecs
::
EncodingContext
*
context
);
void
RestorePayload
();
void
RestorePayload
();
void
ShiftPayload
(
size_t
payloadOffset
,
size_t
shift
,
bool
expand
=
true
);
void
ShiftPayload
(
size_t
payloadOffset
,
size_t
shift
,
bool
expand
=
true
);
...
...
worker/include/RTC/SeqManager.hpp
浏览文件 @
a0736b4e
...
@@ -39,6 +39,8 @@ namespace RTC
...
@@ -39,6 +39,8 @@ namespace RTC
void
Sync
(
T
input
);
void
Sync
(
T
input
);
void
Drop
(
T
input
);
void
Drop
(
T
input
);
bool
Input
(
const
T
input
,
T
&
output
);
bool
Input
(
const
T
input
,
T
&
output
);
T
GetMaxInput
()
const
;
T
GetMaxOutput
()
const
;
private
:
private
:
T
base
{
0
};
T
base
{
0
};
...
...
worker/src/Channel/Request.cpp
浏览文件 @
a0736b4e
...
@@ -44,6 +44,7 @@ namespace Channel
...
@@ -44,6 +44,7 @@ namespace Channel
{
"consumer.pause"
,
Request
::
MethodId
::
CONSUMER_PAUSE
},
{
"consumer.pause"
,
Request
::
MethodId
::
CONSUMER_PAUSE
},
{
"consumer.resume"
,
Request
::
MethodId
::
CONSUMER_RESUME
},
{
"consumer.resume"
,
Request
::
MethodId
::
CONSUMER_RESUME
},
{
"consumer.setPreferredProfile"
,
Request
::
MethodId
::
CONSUMER_SET_PREFERRED_PROFILE
},
{
"consumer.setPreferredProfile"
,
Request
::
MethodId
::
CONSUMER_SET_PREFERRED_PROFILE
},
{
"consumer.setEncodingPreferences"
,
Request
::
MethodId
::
CONSUMER_SET_ENCODING_PREFERENCES
},
{
"consumer.requestKeyFrame"
,
Request
::
MethodId
::
CONSUMER_REQUEST_KEY_FRAME
}
{
"consumer.requestKeyFrame"
,
Request
::
MethodId
::
CONSUMER_REQUEST_KEY_FRAME
}
};
};
// clang-format on
// clang-format on
...
...
worker/src/RTC/Codecs/VP8.cpp
浏览文件 @
a0736b4e
...
@@ -158,7 +158,7 @@ namespace RTC
...
@@ -158,7 +158,7 @@ namespace RTC
this
->
payloadDescriptor
.
reset
(
payloadDescriptor
);
this
->
payloadDescriptor
.
reset
(
payloadDescriptor
);
}
}
void
VP8
::
PayloadDescriptorHandler
::
Encode
(
bool
VP8
::
PayloadDescriptorHandler
::
Encode
(
RTC
::
Codecs
::
EncodingContext
*
encodingContext
,
uint8_t
*
data
)
RTC
::
Codecs
::
EncodingContext
*
encodingContext
,
uint8_t
*
data
)
{
{
EncodingContext
*
context
=
dynamic_cast
<
EncodingContext
*>
(
encodingContext
);
EncodingContext
*
context
=
dynamic_cast
<
EncodingContext
*>
(
encodingContext
);
...
@@ -172,14 +172,35 @@ namespace RTC
...
@@ -172,14 +172,35 @@ namespace RTC
context
->
syncRequired
=
false
;
context
->
syncRequired
=
false
;
}
}
// Incremental pictureId. Check the temporal layer.
if
(
RTC
::
SeqManager
<
uint16_t
>::
IsSeqHigherThan
(
this
->
payloadDescriptor
->
pictureId
,
context
->
pictureIdManager
.
GetMaxInput
()))
{
if
(
this
->
payloadDescriptor
->
t
&&
this
->
payloadDescriptor
->
tlIndex
>
context
->
preferences
.
temporalLayer
)
{
context
->
pictureIdManager
.
Drop
(
this
->
payloadDescriptor
->
pictureId
);
context
->
tl0PictureIndexManager
.
Drop
(
this
->
payloadDescriptor
->
tl0PictureIndex
);
return
false
;
}
}
// Update pictureId and tl0PictureIndex values.
// Update pictureId and tl0PictureIndex values.
uint16_t
pictureId
;
uint16_t
pictureId
;
uint8_t
tl0PictureIndex
;
uint8_t
tl0PictureIndex
;
context
->
pictureIdManager
.
Input
(
this
->
payloadDescriptor
->
pictureId
,
pictureId
);
// Do not send a dropped pictureId.
context
->
tl0PictureIndexManager
.
Input
(
this
->
payloadDescriptor
->
tl0PictureIndex
,
tl0PictureIndex
);
if
(
!
context
->
pictureIdManager
.
Input
(
this
->
payloadDescriptor
->
pictureId
,
pictureId
))
return
false
;
// Do not send a dropped tl0PicutreIndex.
if
(
!
context
->
tl0PictureIndexManager
.
Input
(
this
->
payloadDescriptor
->
tl0PictureIndex
,
tl0PictureIndex
))
return
false
;
this
->
payloadDescriptor
->
Encode
(
data
,
pictureId
,
tl0PictureIndex
);
this
->
payloadDescriptor
->
Encode
(
data
,
pictureId
,
tl0PictureIndex
);
return
true
;
};
};
void
VP8
::
PayloadDescriptorHandler
::
Restore
(
uint8_t
*
data
)
void
VP8
::
PayloadDescriptorHandler
::
Restore
(
uint8_t
*
data
)
...
...
worker/src/RTC/Consumer.cpp
浏览文件 @
a0736b4e
...
@@ -372,6 +372,24 @@ namespace RTC
...
@@ -372,6 +372,24 @@ namespace RTC
RecalculateTargetProfile
(
true
/*forcePreferred*/
);
RecalculateTargetProfile
(
true
/*forcePreferred*/
);
}
}
void
Consumer
::
SetEncodingPreferences
(
const
RTC
::
Codecs
::
EncodingContext
::
Preferences
preferences
)
{
MS_TRACE
();
if
(
!
this
->
encodingContext
)
return
;
MS_DEBUG_TAG
(
rtp
,
"setting encoding preferences [qualityLayer:%"
PRIu8
", spatialLayer:%"
PRIu8
", temporalLayer:%"
PRIu8
"]"
,
preferences
.
qualityLayer
,
preferences
.
spatialLayer
,
preferences
.
temporalLayer
);
this
->
encodingContext
->
SetPreferences
(
preferences
);
}
/**
/**
* Called when the Transport assigned to this Consumer has been closed, so this
* Called when the Transport assigned to this Consumer has been closed, so this
* Consumer becomes unhandled.
* Consumer becomes unhandled.
...
@@ -477,6 +495,15 @@ namespace RTC
...
@@ -477,6 +495,15 @@ namespace RTC
this
->
encodingContext
->
SyncRequired
();
this
->
encodingContext
->
SyncRequired
();
}
}
// Rewrite payload if needed. Drop packet if necessary.
if
(
this
->
encodingContext
&&
!
packet
->
EncodePayload
(
this
->
encodingContext
.
get
()))
{
this
->
rtpSeqManager
.
Drop
(
packet
->
GetSequenceNumber
());
this
->
rtpTimestampManager
.
Drop
(
packet
->
GetTimestamp
());
return
;
}
// Update RTP seq number and timestamp.
// Update RTP seq number and timestamp.
uint16_t
rtpSeq
;
uint16_t
rtpSeq
;
uint32_t
rtpTimestamp
;
uint32_t
rtpTimestamp
;
...
@@ -502,10 +529,6 @@ namespace RTC
...
@@ -502,10 +529,6 @@ namespace RTC
// Rewrite packet timestamp.
// Rewrite packet timestamp.
packet
->
SetTimestamp
(
rtpTimestamp
);
packet
->
SetTimestamp
(
rtpTimestamp
);
// Rewrite payload if needed.
if
(
this
->
encodingContext
)
packet
->
EncodePayload
(
this
->
encodingContext
.
get
());
if
(
isSyncPacket
)
if
(
isSyncPacket
)
{
{
MS_DEBUG_TAG
(
MS_DEBUG_TAG
(
...
...
worker/src/RTC/Router.cpp
浏览文件 @
a0736b4e
...
@@ -1343,6 +1343,41 @@ namespace RTC
...
@@ -1343,6 +1343,41 @@ namespace RTC
break
;
break
;
}
}
case
Channel
:
:
Request
::
MethodId
::
CONSUMER_SET_ENCODING_PREFERENCES
:
{
static
const
Json
::
StaticString
JsonStringQualityLayer
{
"qualityLayer"
};
static
const
Json
::
StaticString
JsonStringSpatialLayer
{
"spatialLayer"
};
static
const
Json
::
StaticString
JsonStringTemporalLayer
{
"temporalLayer"
};
RTC
::
Consumer
*
consumer
;
try
{
consumer
=
GetConsumerFromRequest
(
request
);
}
catch
(
const
MediaSoupError
&
error
)
{
request
->
Reject
(
error
.
what
());
return
;
}
RTC
::
Codecs
::
EncodingContext
::
Preferences
preferences
;
if
(
request
->
data
[
JsonStringQualityLayer
].
isUInt
())
preferences
.
qualityLayer
=
request
->
data
[
JsonStringQualityLayer
].
asUInt
();
if
(
request
->
data
[
JsonStringSpatialLayer
].
isUInt
())
preferences
.
spatialLayer
=
request
->
data
[
JsonStringSpatialLayer
].
asUInt
();
if
(
request
->
data
[
JsonStringTemporalLayer
].
isUInt
())
preferences
.
temporalLayer
=
request
->
data
[
JsonStringTemporalLayer
].
asUInt
();
consumer
->
SetEncodingPreferences
(
preferences
);
request
->
Accept
();
break
;
}
case
Channel
:
:
Request
::
MethodId
::
CONSUMER_REQUEST_KEY_FRAME
:
case
Channel
:
:
Request
::
MethodId
::
CONSUMER_REQUEST_KEY_FRAME
:
{
{
RTC
::
Consumer
*
consumer
;
RTC
::
Consumer
*
consumer
;
...
...
worker/src/RTC/RtpPacket.cpp
浏览文件 @
a0736b4e
...
@@ -456,14 +456,14 @@ namespace RTC
...
@@ -456,14 +456,14 @@ namespace RTC
return
true
;
return
true
;
}
}
void
RtpPacket
::
EncodePayload
(
RTC
::
Codecs
::
EncodingContext
*
context
)
bool
RtpPacket
::
EncodePayload
(
RTC
::
Codecs
::
EncodingContext
*
context
)
{
{
MS_TRACE
();
MS_TRACE
();
if
(
!
this
->
payloadDescriptorHandler
)
if
(
!
this
->
payloadDescriptorHandler
)
return
;
return
true
;
this
->
payloadDescriptorHandler
->
Encode
(
context
,
this
->
payload
);
return
this
->
payloadDescriptorHandler
->
Encode
(
context
,
this
->
payload
);
}
}
void
RtpPacket
::
RestorePayload
()
void
RtpPacket
::
RestorePayload
()
...
...
worker/src/RTC/SeqManager.cpp
浏览文件 @
a0736b4e
...
@@ -111,6 +111,18 @@ namespace RTC
...
@@ -111,6 +111,18 @@ namespace RTC
return
true
;
return
true
;
}
}
template
<
typename
T
>
T
SeqManager
<
T
>::
GetMaxInput
()
const
{
return
this
->
maxInput
;
}
template
<
typename
T
>
T
SeqManager
<
T
>::
GetMaxOutput
()
const
{
return
this
->
maxOutput
;
}
// Explicit instantiation to have all SeqManager definitions in this file.
// Explicit instantiation to have all SeqManager definitions in this file.
template
class
SeqManager
<
uint8_t
>
;
template
class
SeqManager
<
uint8_t
>
;
template
class
SeqManager
<
uint16_t
>
;
template
class
SeqManager
<
uint16_t
>
;
...
...
worker/src/Worker.cpp
浏览文件 @
a0736b4e
...
@@ -265,6 +265,7 @@ void Worker::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::R
...
@@ -265,6 +265,7 @@ void Worker::OnChannelRequest(Channel::UnixStreamSocket* /*channel*/, Channel::R
case
Channel
:
:
Request
::
MethodId
::
CONSUMER_PAUSE
:
case
Channel
:
:
Request
::
MethodId
::
CONSUMER_PAUSE
:
case
Channel
:
:
Request
::
MethodId
::
CONSUMER_RESUME
:
case
Channel
:
:
Request
::
MethodId
::
CONSUMER_RESUME
:
case
Channel
:
:
Request
::
MethodId
::
CONSUMER_SET_PREFERRED_PROFILE
:
case
Channel
:
:
Request
::
MethodId
::
CONSUMER_SET_PREFERRED_PROFILE
:
case
Channel
:
:
Request
::
MethodId
::
CONSUMER_SET_ENCODING_PREFERENCES
:
case
Channel
:
:
Request
::
MethodId
::
CONSUMER_REQUEST_KEY_FRAME
:
case
Channel
:
:
Request
::
MethodId
::
CONSUMER_REQUEST_KEY_FRAME
:
{
{
RTC
::
Router
*
router
;
RTC
::
Router
*
router
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论