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
7110dc75
Commit
7110dc75
authored
Apr 02, 2021
by
ziyue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
整理代码
parent
33d2e713
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
140 行增加
和
105 行删除
+140
-105
webrtc/Sdp.cpp
+7
-0
webrtc/Sdp.h
+2
-0
webrtc/WebRtcTransport.cpp
+67
-61
webrtc/WebRtcTransport.h
+64
-44
没有找到文件。
webrtc/Sdp.cpp
查看文件 @
7110dc75
...
...
@@ -1237,6 +1237,13 @@ shared_ptr<RtcSession> RtcConfigure::createAnswer(const RtcSession &offer){
if
(
ret
->
media
.
empty
())
{
throw
std
::
invalid_argument
(
"生成的answer sdp中媒体个数为0"
);
}
//设置音视频端口复用
if
(
!
offer
.
group
.
mids
.
empty
())
{
for
(
auto
&
m
:
ret
->
media
)
{
ret
->
group
.
mids
.
emplace_back
(
m
.
mid
);
}
}
return
ret
;
}
...
...
webrtc/Sdp.h
查看文件 @
7110dc75
...
...
@@ -437,6 +437,7 @@ public:
class
SdpAttrCandidate
:
public
SdpItem
{
public
:
using
Ptr
=
std
::
shared_ptr
<
SdpAttrCandidate
>
;
//https://tools.ietf.org/html/rfc5245
//15.1. "candidate" Attribute
//a=candidate:4 1 udp 2 192.168.1.7 58107 typ host
...
...
@@ -656,6 +657,7 @@ public:
class
RtcConfigure
{
public
:
using
Ptr
=
std
::
shared_ptr
<
RtcConfigure
>
;
class
RtcTrackConfigure
{
public
:
bool
enable
;
...
...
webrtc/WebRtcTransport.cpp
查看文件 @
7110dc75
差异被折叠。
点击展开。
webrtc/WebRtcTransport.h
查看文件 @
7110dc75
...
...
@@ -2,12 +2,16 @@
#include <memory>
#include <string>
#include "DtlsTransport.hpp"
#include "IceServer.hpp"
#include "SrtpSession.hpp"
#include "StunPacket.hpp"
#include "Sdp.h"
#include "Poller/EventPoller.h"
#include "Network/Socket.h"
#include "Rtsp/RtspMediaSource.h"
using
namespace
toolkit
;
using
namespace
mediakit
;
class
WebRtcTransport
:
public
RTC
::
DtlsTransport
::
Listener
,
public
RTC
::
IceServer
::
Listener
{
public
:
...
...
@@ -15,33 +19,43 @@ public:
WebRtcTransport
(
const
EventPoller
::
Ptr
&
poller
);
~
WebRtcTransport
()
override
=
default
;
/// 销毁对象
/**
* 消费对象
*/
virtual
void
onDestory
();
/**
* 创建webrtc answer sdp
* @param offer offer sdp
* @return answer sdp
*/
std
::
string
getAnswerSdp
(
const
string
&
offer
);
/// 收到udp数据
/// \param buf
/// \param len
/// \param remote_address
void
OnInputDataPacket
(
char
*
buf
,
size_t
len
,
RTC
::
TransportTuple
*
tuple
);
/// 发送rtp
/// \param buf
/// \param len
void
WritRtpPacket
(
char
*
buf
,
size_t
len
);
/**
* socket收到udp数据
* @param buf 数据指针
* @param len 数据长度
* @param tuple 数据来源
*/
void
inputSockData
(
char
*
buf
,
size_t
len
,
RTC
::
TransportTuple
*
tuple
);
/**
* 发送rtp
* @param buf rtcp内容
* @param len rtcp长度
*/
void
sendRtpPacket
(
char
*
buf
,
size_t
len
);
protected
:
//
dtls相关的回调
//
// dtls相关的回调 ////
void
OnDtlsTransportConnecting
(
const
RTC
::
DtlsTransport
*
dtlsTransport
)
override
{};
void
OnDtlsTransportConnected
(
const
RTC
::
DtlsTransport
*
dtlsTransport
,
RTC
::
SrtpSession
::
CryptoSuite
srtpCryptoSuite
,
uint8_t
*
srtpLocalKey
,
size_t
srtpLocalKeyLen
,
uint8_t
*
srtpRemoteKey
,
size_t
srtpRemoteKeyLen
,
std
::
string
&
remoteCert
)
override
;
void
OnDtlsTransportConnected
(
const
RTC
::
DtlsTransport
*
dtlsTransport
,
RTC
::
SrtpSession
::
CryptoSuite
srtpCryptoSuite
,
uint8_t
*
srtpLocalKey
,
size_t
srtpLocalKeyLen
,
uint8_t
*
srtpRemoteKey
,
size_t
srtpRemoteKeyLen
,
std
::
string
&
remoteCert
)
override
;
void
OnDtlsTransportFailed
(
const
RTC
::
DtlsTransport
*
dtlsTransport
)
override
{};
void
OnDtlsTransportClosed
(
const
RTC
::
DtlsTransport
*
dtlsTransport
)
override
{};
...
...
@@ -49,7 +63,7 @@ protected:
void
OnDtlsTransportApplicationDataReceived
(
const
RTC
::
DtlsTransport
*
dtlsTransport
,
const
uint8_t
*
data
,
size_t
len
)
override
{};
protected
:
//
ice相关的回调
//
// ice相关的回调 ///
void
OnIceServerSendStunPacket
(
const
RTC
::
IceServer
*
iceServer
,
const
RTC
::
StunPacket
*
packet
,
RTC
::
TransportTuple
*
tuple
)
override
;
void
OnIceServerSelectedTuple
(
const
RTC
::
IceServer
*
iceServer
,
RTC
::
TransportTuple
*
tuple
)
override
;
void
OnIceServerConnected
(
const
RTC
::
IceServer
*
iceServer
)
override
;
...
...
@@ -57,51 +71,57 @@ protected:
void
OnIceServerDisconnected
(
const
RTC
::
IceServer
*
iceServer
)
override
;
protected
:
/// 输出udp数据
/// \param buf
/// \param len
/// \param dst
virtual
void
onWrite
(
const
char
*
buf
,
size_t
len
,
struct
sockaddr_in
*
dst
)
=
0
;
virtual
uint32_t
getSSRC
()
const
=
0
;
virtual
uint16_t
getPort
()
const
=
0
;
virtual
std
::
string
getIP
()
const
=
0
;
virtual
int
getPayloadType
()
const
=
0
;
virtual
void
onDtlsConnected
()
=
0
;
virtual
void
onStartWebRTC
()
=
0
;
virtual
void
onRtcConfigure
(
RtcConfigure
&
configure
)
const
{}
virtual
void
onCheckSdp
(
SdpType
type
,
const
RtcSession
&
sdp
)
const
;
virtual
SdpAttrCandidate
::
Ptr
getIceCandidate
()
const
=
0
;
virtual
void
onSendSockData
(
const
char
*
buf
,
size_t
len
,
struct
sockaddr_in
*
dst
)
=
0
;
private
:
void
onWrite
(
const
char
*
buf
,
size_t
len
);
void
onSendSockData
(
const
char
*
buf
,
size_t
len
);
void
setRemoteDtlsFingerprint
(
const
RtcSession
&
remote
);
private
:
std
::
shared_ptr
<
RTC
::
IceServer
>
ice_server_
;
std
::
shared_ptr
<
RTC
::
DtlsTransport
>
dtls_transport_
;
std
::
shared_ptr
<
RTC
::
SrtpSession
>
srtp_session_
;
std
::
shared_ptr
<
RTC
::
SrtpSession
>
srtp_session_recv_
;
std
::
shared_ptr
<
RTC
::
IceServer
>
_ice_server
;
std
::
shared_ptr
<
RTC
::
DtlsTransport
>
_dtls_transport
;
std
::
shared_ptr
<
RTC
::
SrtpSession
>
_srtp_session_send
;
std
::
shared_ptr
<
RTC
::
SrtpSession
>
_srtp_session_recv
;
RtcSession
::
Ptr
_offer_sdp
;
RtcSession
::
Ptr
_answer_sdp
;
};
#include "Poller/EventPoller.h"
#include "Network/Socket.h"
#include "Rtsp/RtspMediaSource.h"
using
namespace
toolkit
;
using
namespace
mediakit
;
class
WebRtcTransportImp
:
public
WebRtcTransport
,
public
std
::
enable_shared_from_this
<
WebRtcTransportImp
>
{
public
:
using
Ptr
=
std
::
shared_ptr
<
WebRtcTransportImp
>
;
~
WebRtcTransportImp
()
override
=
default
;
/**
* 创建WebRTC对象
* @param poller 改对象需要绑定的线程
* @return 对象
*/
static
Ptr
create
(
const
EventPoller
::
Ptr
&
poller
);
~
WebRtcTransportImp
()
override
=
default
;
/**
* 绑定rtsp媒体源
* @param src 媒体源
*/
void
attach
(
const
RtspMediaSource
::
Ptr
&
src
);
protected
:
void
on
Write
(
const
char
*
buf
,
size_t
len
,
struct
sockaddr_in
*
dst
)
override
;
int
getPayloadType
()
const
override
;
void
on
StartWebRTC
(
)
override
;
void
onSendSockData
(
const
char
*
buf
,
size_t
len
,
struct
sockaddr_in
*
dst
)
override
;
uint32_t
getSSRC
()
const
override
;
uint16_t
getPort
()
const
override
;
std
::
string
getIP
()
const
override
;
void
onDtlsConnected
()
override
;
SdpAttrCandidate
::
Ptr
getIceCandidate
()
const
override
;
private
:
WebRtcTransportImp
(
const
EventPoller
::
Ptr
&
poller
);
void
onDestory
()
override
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论