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 个修改的文件
包含
65 行增加
和
49 行删除
+65
-49
webrtc/RtpExt.cpp
+59
-46
webrtc/RtpExt.h
+6
-3
没有找到文件。
webrtc/RtpExt.cpp
查看文件 @
f263dd5d
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
*/
*/
#include "RtpExt.h"
#include "RtpExt.h"
#include "Sdp.h"
#if defined(_WIN32)
#if defined(_WIN32)
#pragma pack(push, 1)
#pragma pack(push, 1)
...
@@ -108,20 +109,18 @@ uint8_t *RtpExtTwoByte::getData() {
...
@@ -108,20 +109,18 @@ uint8_t *RtpExtTwoByte::getData() {
static
constexpr
uint16_t
kOneByteHeader
=
0xBEDE
;
static
constexpr
uint16_t
kOneByteHeader
=
0xBEDE
;
static
constexpr
uint16_t
kTwoByteHeader
=
0x1000
;
static
constexpr
uint16_t
kTwoByteHeader
=
0x1000
;
map
<
uint8_t
/*id*/
,
RtpExt
/*data*/
>
RtpExt
::
getExtValue
(
const
RtpHeader
*
header
,
const
RtcMedia
&
media
)
{
static
RtpExtType
getExtTypeById
(
uint8_t
id
,
const
RtcMedia
&
media
){
map
<
uint8_t
,
RtpExt
>
ret
;
auto
it
=
media
.
extmap
.
find
(
id
);
assert
(
header
);
if
(
it
==
media
.
extmap
.
end
())
{
auto
ext_size
=
header
->
getExtSize
();
return
RtpExtType
::
padding
;
if
(
!
ext_size
)
{
return
ret
;
}
}
auto
reserved
=
header
->
getExtReserved
(
);
return
RtpExt
::
getExtType
(
it
->
second
.
ext
);
auto
ptr
=
const_cast
<
RtpHeader
*>
(
header
)
->
getExtData
();
}
auto
end
=
ptr
+
ext_size
;
RtpExtType
type
;
template
<
typename
Type
>
if
(
reserved
==
kOneByteHeader
)
{
static
void
appendExt
(
map
<
RtpExtType
,
RtpExt
>
&
ret
,
const
RtcMedia
&
media
,
uint8_t
*
ptr
,
const
uint8_t
*
end
)
{
while
(
ptr
<
end
)
{
while
(
ptr
<
end
)
{
RtpExtOneByte
*
ext
=
reinterpret_cast
<
RtpExtOneByt
e
*>
(
ptr
);
auto
ext
=
reinterpret_cast
<
Typ
e
*>
(
ptr
);
if
(
ext
->
getId
()
==
(
uint8_t
)
RtpExtType
::
padding
)
{
if
(
ext
->
getId
()
==
(
uint8_t
)
RtpExtType
::
padding
)
{
//padding,忽略
//padding,忽略
++
ptr
;
++
ptr
;
...
@@ -129,55 +128,55 @@ map<uint8_t/*id*/, RtpExt/*data*/> RtpExt::getExtValue(const RtpHeader *header,
...
@@ -129,55 +128,55 @@ map<uint8_t/*id*/, RtpExt/*data*/> RtpExt::getExtValue(const RtpHeader *header,
}
}
//15类型的rtp ext为保留
//15类型的rtp ext为保留
CHECK
(
ext
->
getId
()
<
(
uint8_t
)
RtpExtType
::
reserved
);
CHECK
(
ext
->
getId
()
<
(
uint8_t
)
RtpExtType
::
reserved
);
CHECK
(
reinterpret_cast
<
uint8_t
*>
(
ext
)
+
RtpExtOneByt
e
::
kMinSize
<=
end
);
CHECK
(
reinterpret_cast
<
uint8_t
*>
(
ext
)
+
Typ
e
::
kMinSize
<=
end
);
CHECK
(
ext
->
getData
()
+
ext
->
getSize
()
<=
end
);
CHECK
(
ext
->
getData
()
+
ext
->
getSize
()
<=
end
);
ret
.
emplace
(
ext
->
getId
(),
RtpExt
(
type
,
reinterpret_cast
<
char
*>
(
ext
->
getData
()),
ext
->
getSize
()));
auto
type
=
getExtTypeById
(
ext
->
getId
(),
media
);
ptr
+=
RtpExtOneByte
::
kMinSize
+
ext
->
getSize
();
ret
.
emplace
(
type
,
RtpExt
(
type
,
ext
->
getId
(),
reinterpret_cast
<
char
*>
(
ext
->
getData
()),
ext
->
getSize
()));
}
ptr
+=
Type
::
kMinSize
+
ext
->
getSize
();
return
ret
;
}
}
}
if
((
reserved
&
0xFFF0
)
>>
4
==
kTwoByteHeader
)
{
map
<
RtpExtType
/*type*/
,
RtpExt
/*data*/
>
RtpExt
::
getExtValue
(
const
RtpHeader
*
header
,
const
RtcMedia
&
media
)
{
while
(
ptr
<
end
)
{
map
<
RtpExtType
,
RtpExt
>
ret
;
RtpExtTwoByte
*
ext
=
reinterpret_cast
<
RtpExtTwoByte
*>
(
ptr
);
assert
(
header
);
if
(
ext
->
getId
()
==
(
uint8_t
)
RtpExtType
::
padding
)
{
auto
ext_size
=
header
->
getExtSize
();
//padding,忽略
if
(
!
ext_size
)
{
++
ptr
;
return
ret
;
continue
;
}
}
//15类型的rtp ext为保留
auto
reserved
=
header
->
getExtReserved
();
CHECK
(
ext
->
getId
()
<
(
uint8_t
)
RtpExtType
::
reserved
);
auto
ptr
=
const_cast
<
RtpHeader
*>
(
header
)
->
getExtData
(
);
CHECK
(
reinterpret_cast
<
uint8_t
*>
(
ext
)
+
RtpExtTwoByte
::
kMinSize
<=
end
)
;
auto
end
=
ptr
+
ext_size
;
CHECK
(
ext
->
getData
()
+
ext
->
getSize
()
<=
end
);
if
(
reserved
==
kOneByteHeader
)
{
ret
.
emplace
(
ext
->
getId
(),
RtpExt
(
type
,
reinterpret_cast
<
char
*>
(
ext
->
getData
()),
ext
->
getSize
())
);
appendExt
<
RtpExtOneByte
>
(
ret
,
media
,
ptr
,
end
);
ptr
+=
RtpExtTwoByte
::
kMinSize
+
ext
->
getSize
()
;
return
ret
;
}
}
if
((
reserved
&
0xFFF0
)
>>
4
==
kTwoByteHeader
)
{
appendExt
<
RtpExtTwoByte
>
(
ret
,
media
,
ptr
,
end
);
return
ret
;
return
ret
;
}
}
return
ret
;
return
ret
;
}
}
#define RTP_EXT_MAP(XX) \
#define RTP_EXT_MAP(XX) \
XX(
RtpExtType::
ssrc_audio_level, "urn:ietf:params:rtp-hdrext:ssrc-audio-level") \
XX(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(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(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(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(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(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(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(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(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(playout_delay, "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay") \
XX(
RtpExtType::
video_orientation, "urn:3gpp:video-orientation") \
XX(video_orientation, "urn:3gpp:video-orientation") \
XX(
RtpExtType::
toffset, "urn:ietf:params:rtp-hdrext:toffset")
XX(toffset, "urn:ietf:params:rtp-hdrext:toffset")
#define XX(type, url) {type , url},
#define XX(type, url) {
RtpExtType::
type , url},
static
unordered_map
<
RtpExtType
/*id*/
,
string
/*ext*/
>
s_type_to_url
=
{
RTP_EXT_MAP
(
XX
)};
static
unordered_map
<
RtpExtType
/*id*/
,
string
/*ext*/
>
s_type_to_url
=
{
RTP_EXT_MAP
(
XX
)};
#undef 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
)};
static
unordered_map
<
string
/*ext*/
,
RtpExtType
/*id*/
>
s_url_to_type
=
{
RTP_EXT_MAP
(
XX
)};
#undef XX
#undef XX
...
@@ -197,3 +196,17 @@ const string &RtpExt::getExtUrl(RtpExtType type) {
...
@@ -197,3 +196,17 @@ const string &RtpExt::getExtUrl(RtpExtType type) {
return
it
->
second
;
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;
...
@@ -41,16 +41,19 @@ class RtcMedia;
class
RtpExt
:
public
std
::
string
{
class
RtpExt
:
public
std
::
string
{
public
:
public
:
RtpExt
(
RtpExtType
type
,
uint8_t
id
,
const
char
*
str
,
size_t
size
)
:
std
::
string
(
str
,
size
),
_type
(
type
),
_id
(
id
)
{}
~
RtpExt
()
=
default
;
~
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
RtpExtType
getExtType
(
const
string
&
url
);
static
const
string
&
getExtUrl
(
RtpExtType
type
);
static
const
string
&
getExtUrl
(
RtpExtType
type
);
static
const
char
*
getExtName
(
RtpExtType
type
);
private
:
string
dumpString
()
const
;
RtpExt
(
RtpExtType
type
,
const
char
*
str
,
size_t
size
)
:
std
::
string
(
str
,
size
),
_type
(
type
)
{}
private
:
private
:
RtpExtType
_type
;
RtpExtType
_type
;
uint8_t
_id
;
};
};
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论