Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
f263dd5d
Commit
f263dd5d
authored
May 07, 2021
by
xia-chu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化rtp ext相关代码
parent
c5fff230
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
67 行增加
和
51 行删除
+67
-51
webrtc/RtpExt.cpp
+61
-48
webrtc/RtpExt.h
+6
-3
没有找到文件。
webrtc/RtpExt.cpp
查看文件 @
f263dd5d
...
...
@@ -9,6 +9,7 @@
*/
#include "RtpExt.h"
#include "Sdp.h"
#if defined(_WIN32)
#pragma pack(push, 1)
...
...
@@ -108,8 +109,35 @@ uint8_t *RtpExtTwoByte::getData() {
static
constexpr
uint16_t
kOneByteHeader
=
0xBEDE
;
static
constexpr
uint16_t
kTwoByteHeader
=
0x1000
;
map
<
uint8_t
/*id*/
,
RtpExt
/*data*/
>
RtpExt
::
getExtValue
(
const
RtpHeader
*
header
,
const
RtcMedia
&
media
)
{
map
<
uint8_t
,
RtpExt
>
ret
;
static
RtpExtType
getExtTypeById
(
uint8_t
id
,
const
RtcMedia
&
media
){
auto
it
=
media
.
extmap
.
find
(
id
);
if
(
it
==
media
.
extmap
.
end
())
{
return
RtpExtType
::
padding
;
}
return
RtpExt
::
getExtType
(
it
->
second
.
ext
);
}
template
<
typename
Type
>
static
void
appendExt
(
map
<
RtpExtType
,
RtpExt
>
&
ret
,
const
RtcMedia
&
media
,
uint8_t
*
ptr
,
const
uint8_t
*
end
){
while
(
ptr
<
end
)
{
auto
ext
=
reinterpret_cast
<
Type
*>
(
ptr
);
if
(
ext
->
getId
()
==
(
uint8_t
)
RtpExtType
::
padding
)
{
//padding,忽略
++
ptr
;
continue
;
}
//15类型的rtp ext为保留
CHECK
(
ext
->
getId
()
<
(
uint8_t
)
RtpExtType
::
reserved
);
CHECK
(
reinterpret_cast
<
uint8_t
*>
(
ext
)
+
Type
::
kMinSize
<=
end
);
CHECK
(
ext
->
getData
()
+
ext
->
getSize
()
<=
end
);
auto
type
=
getExtTypeById
(
ext
->
getId
(),
media
);
ret
.
emplace
(
type
,
RtpExt
(
type
,
ext
->
getId
(),
reinterpret_cast
<
char
*>
(
ext
->
getData
()),
ext
->
getSize
()));
ptr
+=
Type
::
kMinSize
+
ext
->
getSize
();
}
}
map
<
RtpExtType
/*type*/
,
RtpExt
/*data*/
>
RtpExt
::
getExtValue
(
const
RtpHeader
*
header
,
const
RtcMedia
&
media
)
{
map
<
RtpExtType
,
RtpExt
>
ret
;
assert
(
header
);
auto
ext_size
=
header
->
getExtSize
();
if
(
!
ext_size
)
{
...
...
@@ -118,66 +146,37 @@ map<uint8_t/*id*/, RtpExt/*data*/> RtpExt::getExtValue(const RtpHeader *header,
auto
reserved
=
header
->
getExtReserved
();
auto
ptr
=
const_cast
<
RtpHeader
*>
(
header
)
->
getExtData
();
auto
end
=
ptr
+
ext_size
;
RtpExtType
type
;
if
(
reserved
==
kOneByteHeader
)
{
while
(
ptr
<
end
)
{
RtpExtOneByte
*
ext
=
reinterpret_cast
<
RtpExtOneByte
*>
(
ptr
);
if
(
ext
->
getId
()
==
(
uint8_t
)
RtpExtType
::
padding
)
{
//padding,忽略
++
ptr
;
continue
;
}
//15类型的rtp ext为保留
CHECK
(
ext
->
getId
()
<
(
uint8_t
)
RtpExtType
::
reserved
);
CHECK
(
reinterpret_cast
<
uint8_t
*>
(
ext
)
+
RtpExtOneByte
::
kMinSize
<=
end
);
CHECK
(
ext
->
getData
()
+
ext
->
getSize
()
<=
end
);
ret
.
emplace
(
ext
->
getId
(),
RtpExt
(
type
,
reinterpret_cast
<
char
*>
(
ext
->
getData
()),
ext
->
getSize
()));
ptr
+=
RtpExtOneByte
::
kMinSize
+
ext
->
getSize
();
}
appendExt
<
RtpExtOneByte
>
(
ret
,
media
,
ptr
,
end
);
return
ret
;
}
if
((
reserved
&
0xFFF0
)
>>
4
==
kTwoByteHeader
)
{
while
(
ptr
<
end
)
{
RtpExtTwoByte
*
ext
=
reinterpret_cast
<
RtpExtTwoByte
*>
(
ptr
);
if
(
ext
->
getId
()
==
(
uint8_t
)
RtpExtType
::
padding
)
{
//padding,忽略
++
ptr
;
continue
;
}
//15类型的rtp ext为保留
CHECK
(
ext
->
getId
()
<
(
uint8_t
)
RtpExtType
::
reserved
);
CHECK
(
reinterpret_cast
<
uint8_t
*>
(
ext
)
+
RtpExtTwoByte
::
kMinSize
<=
end
);
CHECK
(
ext
->
getData
()
+
ext
->
getSize
()
<=
end
);
ret
.
emplace
(
ext
->
getId
(),
RtpExt
(
type
,
reinterpret_cast
<
char
*>
(
ext
->
getData
()),
ext
->
getSize
()));
ptr
+=
RtpExtTwoByte
::
kMinSize
+
ext
->
getSize
();
}
appendExt
<
RtpExtTwoByte
>
(
ret
,
media
,
ptr
,
end
);
return
ret
;
}
return
ret
;
}
#define RTP_EXT_MAP(XX) \
XX(
RtpExtType::
ssrc_audio_level, "urn:ietf:params:rtp-hdrext:ssrc-audio-level") \
XX(
RtpExtType::
abs_send_time, "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time") \
XX(
RtpExtType::
transport_cc, "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01") \
XX(
RtpExtType::
sdes_mid, "urn:ietf:params:rtp-hdrext:sdes:mid") \
XX(
RtpExtType::
sdes_rtp_stream_id, "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id") \
XX(
RtpExtType::
sdes_repaired_rtp_stream_id, "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id") \
XX(
RtpExtType::
video_timing, "http://www.webrtc.org/experiments/rtp-hdrext/video-timing") \
XX(
RtpExtType::
color_space, "http://www.webrtc.org/experiments/rtp-hdrext/color-space") \
XX(
RtpExtType::
video_content_type, "http://www.webrtc.org/experiments/rtp-hdrext/video-content-type") \
XX(
RtpExtType::
playout_delay, "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay") \
XX(
RtpExtType::
video_orientation, "urn:3gpp:video-orientation") \
XX(
RtpExtType::
toffset, "urn:ietf:params:rtp-hdrext:toffset")
#define XX(type, url) {type , url},
XX(ssrc_audio_level, "urn:ietf:params:rtp-hdrext:ssrc-audio-level") \
XX(abs_send_time, "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time") \
XX(transport_cc, "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01") \
XX(sdes_mid, "urn:ietf:params:rtp-hdrext:sdes:mid") \
XX(sdes_rtp_stream_id, "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id") \
XX(sdes_repaired_rtp_stream_id, "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id") \
XX(video_timing, "http://www.webrtc.org/experiments/rtp-hdrext/video-timing") \
XX(color_space, "http://www.webrtc.org/experiments/rtp-hdrext/color-space") \
XX(video_content_type, "http://www.webrtc.org/experiments/rtp-hdrext/video-content-type") \
XX(playout_delay, "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay") \
XX(video_orientation, "urn:3gpp:video-orientation") \
XX(toffset, "urn:ietf:params:rtp-hdrext:toffset")
#define XX(type, url) {
RtpExtType::
type , url},
static
unordered_map
<
RtpExtType
/*id*/
,
string
/*ext*/
>
s_type_to_url
=
{
RTP_EXT_MAP
(
XX
)};
#undef XX
#define XX(type, url) {url, type},
#define XX(type, url) {url,
RtpExtType::
type},
static
unordered_map
<
string
/*ext*/
,
RtpExtType
/*id*/
>
s_url_to_type
=
{
RTP_EXT_MAP
(
XX
)};
#undef XX
...
...
@@ -197,3 +196,17 @@ const string &RtpExt::getExtUrl(RtpExtType type) {
return
it
->
second
;
}
const
char
*
RtpExt
::
getExtName
(
RtpExtType
type
)
{
#define XX(type, url) case RtpExtType::type: return #type;
switch
(
type
)
{
RTP_EXT_MAP
(
XX
)
default
:
return
"unknown ext type"
;
}
#undef XX
}
string
RtpExt
::
dumpString
()
const
{
_StrPrinter
printer
;
printer
<<
getExtName
(
_type
)
<<
", id:"
<<
(
int
)
_id
<<
" "
<<
hexdump
(
data
(),
size
());
return
std
::
move
(
printer
);
}
webrtc/RtpExt.h
查看文件 @
f263dd5d
...
...
@@ -41,16 +41,19 @@ class RtcMedia;
class
RtpExt
:
public
std
::
string
{
public
:
RtpExt
(
RtpExtType
type
,
uint8_t
id
,
const
char
*
str
,
size_t
size
)
:
std
::
string
(
str
,
size
),
_type
(
type
),
_id
(
id
)
{}
~
RtpExt
()
=
default
;
static
map
<
uint8_t
/*id*/
,
RtpExt
/*data*/
>
getExtValue
(
const
RtpHeader
*
header
,
const
RtcMedia
&
media
);
static
map
<
RtpExtType
/*type*/
,
RtpExt
/*data*/
>
getExtValue
(
const
RtpHeader
*
header
,
const
RtcMedia
&
media
);
static
RtpExtType
getExtType
(
const
string
&
url
);
static
const
string
&
getExtUrl
(
RtpExtType
type
);
static
const
char
*
getExtName
(
RtpExtType
type
);
private
:
RtpExt
(
RtpExtType
type
,
const
char
*
str
,
size_t
size
)
:
std
::
string
(
str
,
size
),
_type
(
type
)
{}
string
dumpString
()
const
;
private
:
RtpExtType
_type
;
uint8_t
_id
;
};
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论