Commit 0fc38bba by Xiaofeng Wang

避免对外传递 srtp 依赖

parent 388bf718
...@@ -20,64 +20,45 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -20,64 +20,45 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define MS_RTC_SRTP_SESSION_HPP #define MS_RTC_SRTP_SESSION_HPP
#include "Utils.hpp" #include "Utils.hpp"
#include <srtp2/srtp.h>
#include <vector>
#include <memory> #include <memory>
namespace RTC typedef struct srtp_ctx_t_ *srtp_t;
{
class DepLibSRTP : public std::enable_shared_from_this<DepLibSRTP> namespace RTC {
{
public:
using Ptr = std::shared_ptr<DepLibSRTP>;
~DepLibSRTP();
static bool IsError(srtp_err_status_t code); class DepLibSRTP;
static const char *GetErrorString(srtp_err_status_t code);
static DepLibSRTP &Instance();
private: class SrtpSession {
DepLibSRTP(); public:
enum class CryptoSuite {
NONE = 0,
AES_CM_128_HMAC_SHA1_80 = 1,
AES_CM_128_HMAC_SHA1_32,
AEAD_AES_256_GCM,
AEAD_AES_128_GCM
}; };
class SrtpSession public:
{ enum class Type { INBOUND = 1, OUTBOUND };
public:
enum class CryptoSuite public:
{ SrtpSession(Type type, CryptoSuite cryptoSuite, uint8_t *key, size_t keyLen);
NONE = 0, ~SrtpSession();
AES_CM_128_HMAC_SHA1_80 = 1,
AES_CM_128_HMAC_SHA1_32, public:
AEAD_AES_256_GCM, bool EncryptRtp(uint8_t *data, int *len);
AEAD_AES_128_GCM bool DecryptSrtp(uint8_t *data, int *len);
}; bool EncryptRtcp(uint8_t *data, int *len);
bool DecryptSrtcp(uint8_t *data, int *len);
public: void RemoveStream(uint32_t ssrc);
enum class Type
{ private:
INBOUND = 1, // Allocated by this.
OUTBOUND srtp_t session { nullptr };
}; std::shared_ptr<DepLibSRTP> _env;
};
public:
SrtpSession(Type type, CryptoSuite cryptoSuite, uint8_t* key, size_t keyLen);
~SrtpSession();
public:
bool EncryptRtp(uint8_t* data, int* len);
bool DecryptSrtp(uint8_t* data, int* len);
bool EncryptRtcp(uint8_t* data, int* len);
bool DecryptSrtcp(uint8_t* data, int* len);
void RemoveStream(uint32_t ssrc)
{
srtp_remove_stream(this->session, uint32_t{ htonl(ssrc) });
}
private:
// Allocated by this.
srtp_t session{ nullptr };
DepLibSRTP::Ptr _env;
};
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
#include "Rtcp/RtcpFCI.h" #include "Rtcp/RtcpFCI.h"
#include "RtpExt.h" #include "RtpExt.h"
#include "Rtsp/RtpReceiver.h" #include "Rtsp/RtpReceiver.h"
#include <srtp2/srtp.h>
#include <iostream> #include <iostream>
#define RTP_SSRC_OFFSET 1 #define RTP_SSRC_OFFSET 1
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论