Commit 0fc38bba by Xiaofeng Wang

避免对外传递 srtp 依赖

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