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
b714dfdd
Commit
b714dfdd
authored
Mar 29, 2021
by
ziyue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加辅助方法
parent
26432695
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
148 行增加
和
40 行删除
+148
-40
webrtc/Sdp.cpp
+93
-29
webrtc/Sdp.h
+55
-11
没有找到文件。
webrtc/Sdp.cpp
查看文件 @
b714dfdd
...
...
@@ -161,9 +161,99 @@ const char* getRtpDirectionString(RtpDirection val){
//////////////////////////////////////////////////////////////////////////////////////////
string
RtcSdpBase
::
toString
()
const
{
_StrPrinter
printer
;
for
(
auto
&
item
:
items
)
{
printer
<<
item
->
getKey
()
<<
"="
<<
item
->
toString
()
<<
"
\r\n
"
;
}
return
std
::
move
(
printer
);
}
RtpDirection
RtcSdpBase
::
getDirection
()
const
{
for
(
auto
&
item
:
items
)
{
auto
attr
=
dynamic_pointer_cast
<
SdpAttr
>
(
item
);
if
(
attr
)
{
auto
dir
=
dynamic_pointer_cast
<
DirectionInterface
>
(
attr
->
detail
);
if
(
dir
)
{
return
dir
->
getDirection
();
}
}
}
return
RtpDirection
::
invalid
;
}
SdpItem
::
Ptr
RtcSdpBase
::
getItem
(
char
key
,
const
char
*
attr_key
)
const
{
for
(
auto
item
:
items
)
{
if
(
item
->
getKey
()[
0
]
==
key
)
{
if
(
!
attr_key
)
{
return
item
;
}
auto
attr
=
dynamic_pointer_cast
<
SdpAttr
>
(
item
);
if
(
attr
&&
attr
->
detail
->
getKey
()
==
attr_key
)
{
return
item
;
}
}
}
return
SdpItem
::
Ptr
();
}
int
RtcSdpBase
::
getVersion
()
const
{
return
atoi
(
getStringItem
(
'v'
).
data
());
}
SdpOrigin
RtcSdpBase
::
getOrigin
()
const
{
return
getItemClass
<
SdpOrigin
>
(
'o'
);
}
string
RtcSdpBase
::
getSessionName
()
const
{
return
getStringItem
(
's'
);
}
string
RtcSdpBase
::
getSessionInfo
()
const
{
return
getStringItem
(
'i'
);
}
SdpTime
RtcSdpBase
::
getSessionTime
()
const
{
return
getItemClass
<
SdpTime
>
(
't'
);
}
SdpConnection
RtcSdpBase
::
getConnection
()
const
{
return
getItemClass
<
SdpConnection
>
(
'c'
);
}
SdpBandwidth
RtcSdpBase
::
getBandwidth
()
const
{
return
getItemClass
<
SdpBandwidth
>
(
'b'
);
}
string
RtcSdpBase
::
getUri
()
const
{
return
getStringItem
(
'u'
);
}
string
RtcSdpBase
::
getEmail
()
const
{
return
getStringItem
(
'e'
);
}
string
RtcSdpBase
::
getPhone
()
const
{
return
getStringItem
(
'p'
);
}
string
RtcSdpBase
::
getTimeZone
()
const
{
return
getStringItem
(
'z'
);
}
string
RtcSdpBase
::
getEncryptKey
()
const
{
return
getStringItem
(
'k'
);
}
string
RtcSdpBase
::
getRepeatTimes
()
const
{
return
getStringItem
(
'r'
);
}
//////////////////////////////////////////////////////////////////////
void
RtcSessionSdp
::
parse
(
const
string
&
str
)
{
static
auto
flag
=
registerAllItem
();
Rtc
MediaSdp
*
media
=
nullptr
;
Rtc
SdpBase
*
media
=
nullptr
;
auto
lines
=
split
(
str
,
"
\n
"
);
for
(
auto
&
line
:
lines
){
trim
(
line
);
...
...
@@ -173,7 +263,7 @@ void RtcSessionSdp::parse(const string &str) {
auto
key
=
line
.
substr
(
0
,
1
);
auto
value
=
line
.
substr
(
2
);
if
(
key
==
"m"
)
{
medias
.
emplace_back
(
Rtc
MediaSdp
());
medias
.
emplace_back
(
Rtc
SdpBase
());
media
=
&
medias
.
back
();
}
...
...
@@ -195,9 +285,7 @@ void RtcSessionSdp::parse(const string &str) {
string
RtcSessionSdp
::
toString
()
const
{
_StrPrinter
printer
;
for
(
auto
&
item
:
items
)
{
printer
<<
item
->
getKey
()
<<
"="
<<
item
->
toString
()
<<
"
\r\n
"
;
}
printer
<<
RtcSdpBase
::
toString
();
for
(
auto
&
media
:
medias
)
{
printer
<<
media
.
toString
();
}
...
...
@@ -205,30 +293,6 @@ string RtcSessionSdp::toString() const {
return
std
::
move
(
printer
);
}
//////////////////////////////////////////////////////////////////////
string
RtcMediaSdp
::
toString
()
const
{
_StrPrinter
printer
;
for
(
auto
&
item
:
items
)
{
printer
<<
item
->
getKey
()
<<
"="
<<
item
->
toString
()
<<
"
\r\n
"
;
}
return
std
::
move
(
printer
);
}
RtpDirection
RtcMediaSdp
::
getDirection
()
const
{
for
(
auto
&
item
:
items
)
{
auto
attr
=
dynamic_pointer_cast
<
SdpAttr
>
(
item
);
if
(
attr
)
{
auto
dir
=
dynamic_pointer_cast
<
DirectionInterface
>
(
attr
->
detail
);
if
(
dir
)
{
return
dir
->
getDirection
();
}
}
}
return
RtpDirection
::
invalid
;
}
//////////////////////////////////////////////////////////////////////////////////////////
#define SDP_THROW() throw std::invalid_argument(StrPrinter << "解析sdp " << getKey() << " 字段失败:" << str)
...
...
webrtc/Sdp.h
查看文件 @
b714dfdd
...
...
@@ -421,22 +421,55 @@ public:
const
char
*
getKey
()
const
override
{
return
"candidate"
;}
};
class
Rtc
MediaSdp
{
class
Rtc
SdpBase
{
public
:
vector
<
SdpItem
::
Ptr
>
items
;
string
toString
()
const
;
bool
haveAttr
(
const
char
*
attr
)
const
;
string
getAttrValue
(
const
char
*
attr
)
const
;
public
:
virtual
string
toString
()
const
;
int
getVersion
()
const
;
SdpOrigin
getOrigin
()
const
;
string
getSessionName
()
const
;
string
getSessionInfo
()
const
;
SdpTime
getSessionTime
()
const
;
SdpConnection
getConnection
()
const
;
SdpBandwidth
getBandwidth
()
const
;
string
getUri
()
const
;
string
getEmail
()
const
;
string
getPhone
()
const
;
string
getTimeZone
()
const
;
string
getEncryptKey
()
const
;
string
getRepeatTimes
()
const
;
RtpDirection
getDirection
()
const
;
private
:
SdpItem
::
Ptr
getItem
(
char
key
,
const
char
*
attr_key
=
nullptr
)
const
;
template
<
typename
cls
>
cls
getItemClass
(
char
key
,
const
char
*
attr_key
=
nullptr
)
const
{
auto
item
=
dynamic_pointer_cast
<
cls
>
(
getItem
(
key
,
attr_key
));
if
(
!
item
)
{
return
cls
();
}
return
*
item
;
}
string
getStringItem
(
char
key
,
const
char
*
attr_key
=
nullptr
)
const
{
auto
item
=
getItem
(
key
,
attr_key
);
if
(
!
item
)
{
return
""
;
}
return
item
->
toString
();
}
};
class
RtcSessionSdp
{
class
RtcSessionSdp
:
public
RtcSdpBase
{
public
:
vector
<
SdpItem
::
Ptr
>
items
;
vector
<
RtcMediaSdp
>
medias
;
vector
<
RtcSdpBase
>
medias
;
void
parse
(
const
string
&
str
);
string
toString
()
const
;
string
toString
()
const
override
;
};
//////////////////////////////////////////////////////////////////
...
...
@@ -468,12 +501,12 @@ public:
uint32_t
sample_rate
;
//音频时有效
uint32_t
channel
=
0
;
vector
<
std
::
pair
<
string
/*key*/
,
string
/*value*/
>
>
fmtp
;
vector
<
string
>
rtcp_fb
;
vector
<
std
::
pair
<
string
/*key*/
,
string
/*value*/
>
>
fmtp
;
};
//rtc 媒体描述
class
Rtc
Codec
{
class
Rtc
Media
{
public
:
TrackType
type
;
string
mid
;
...
...
@@ -508,6 +541,17 @@ public:
vector
<
SdpAttrExtmap
>
extmap
;
};
class
RtcSession
{
public
:
int
version
;
SdpOrigin
origin
;
string
session_name
;
string
session_info
;
SdpConnection
connection
;
SdpBandwidth
bandwidth
;
set
<
TrackType
>
group_bundle
;
vector
<
RtcMedia
>
media
;
};
#endif //ZLMEDIAKIT_SDP_H
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论