修复webrtc srtp相关功能在大端64位系统崩溃的问题

This commit is contained in:
ziyue 2021-08-13 16:07:27 +08:00
parent 8fd9853bc9
commit 1d161bcdc2
4 changed files with 19 additions and 19 deletions

View File

@ -231,7 +231,7 @@ namespace RTC
} }
} }
bool SrtpSession::EncryptRtp(uint8_t* data, size_t* len) bool SrtpSession::EncryptRtp(uint8_t* data, int* len)
{ {
MS_TRACE(); MS_TRACE();
srtp_err_status_t err = srtp_err_status_t err =
@ -246,7 +246,7 @@ namespace RTC
return true; return true;
} }
bool SrtpSession::DecryptSrtp(uint8_t* data, size_t* len) bool SrtpSession::DecryptSrtp(uint8_t* data, int* len)
{ {
MS_TRACE(); MS_TRACE();
@ -262,7 +262,7 @@ namespace RTC
return true; return true;
} }
bool SrtpSession::EncryptRtcp(uint8_t* data, size_t* len) bool SrtpSession::EncryptRtcp(uint8_t* data, int* len)
{ {
MS_TRACE(); MS_TRACE();
srtp_err_status_t err = srtp_protect_rtcp( srtp_err_status_t err = srtp_protect_rtcp(
@ -277,7 +277,7 @@ namespace RTC
return true; return true;
} }
bool SrtpSession::DecryptSrtcp(uint8_t* data, size_t* len) bool SrtpSession::DecryptSrtcp(uint8_t* data, int* len)
{ {
MS_TRACE(); MS_TRACE();

View File

@ -64,10 +64,10 @@ namespace RTC
~SrtpSession(); ~SrtpSession();
public: public:
bool EncryptRtp(uint8_t* data, size_t* len); bool EncryptRtp(uint8_t* data, int* len);
bool DecryptSrtp(uint8_t* data, size_t* len); bool DecryptSrtp(uint8_t* data, int* len);
bool EncryptRtcp(uint8_t* data, size_t* len); bool EncryptRtcp(uint8_t* data, int* len);
bool DecryptSrtcp(uint8_t* data, size_t* len); bool DecryptSrtcp(uint8_t* data, int* len);
void RemoveStream(uint32_t ssrc) void RemoveStream(uint32_t ssrc)
{ {
srtp_remove_stream(this->session, uint32_t{ htonl(ssrc) }); srtp_remove_stream(this->session, uint32_t{ htonl(ssrc) });

View File

@ -236,7 +236,7 @@ bool is_rtcp(char *buf) {
return ((header->pt >= 64) && (header->pt < 96)); return ((header->pt >= 64) && (header->pt < 96));
} }
void WebRtcTransport::inputSockData(char *buf, size_t len, RTC::TransportTuple *tuple) { void WebRtcTransport::inputSockData(char *buf, int len, RTC::TransportTuple *tuple) {
if (RTC::StunPacket::IsStun((const uint8_t *) buf, len)) { if (RTC::StunPacket::IsStun((const uint8_t *) buf, len)) {
RTC::StunPacket *packet = RTC::StunPacket::Parse((const uint8_t *) buf, len); RTC::StunPacket *packet = RTC::StunPacket::Parse((const uint8_t *) buf, len);
if (packet == nullptr) { if (packet == nullptr) {
@ -264,7 +264,7 @@ void WebRtcTransport::inputSockData(char *buf, size_t len, RTC::TransportTuple *
} }
} }
void WebRtcTransport::sendRtpPacket(const char *buf, size_t len, bool flush, void *ctx) { void WebRtcTransport::sendRtpPacket(const char *buf, int len, bool flush, void *ctx) {
if (_srtp_session_send) { if (_srtp_session_send) {
//预留rtx加入的两个字节 //预留rtx加入的两个字节
CHECK(len + SRTP_MAX_TRAILER_LEN + 2 <= sizeof(_srtp_buf)); CHECK(len + SRTP_MAX_TRAILER_LEN + 2 <= sizeof(_srtp_buf));
@ -276,7 +276,7 @@ void WebRtcTransport::sendRtpPacket(const char *buf, size_t len, bool flush, voi
} }
} }
void WebRtcTransport::sendRtcpPacket(const char *buf, size_t len, bool flush, void *ctx){ void WebRtcTransport::sendRtcpPacket(const char *buf, int len, bool flush, void *ctx){
if (_srtp_session_send) { if (_srtp_session_send) {
CHECK(len + SRTP_MAX_TRAILER_LEN <= sizeof(_srtp_buf)); CHECK(len + SRTP_MAX_TRAILER_LEN <= sizeof(_srtp_buf));
memcpy(_srtp_buf, buf, len); memcpy(_srtp_buf, buf, len);
@ -901,7 +901,7 @@ void WebRtcTransportImp::onSendRtp(const RtpPacket::Ptr &rtp, bool flush, bool r
_bytes_usage += rtp->size() - RtpPacket::kRtpTcpHeaderSize; _bytes_usage += rtp->size() - RtpPacket::kRtpTcpHeaderSize;
} }
void WebRtcTransportImp::onBeforeEncryptRtp(const char *buf, size_t &len, void *ctx) { void WebRtcTransportImp::onBeforeEncryptRtp(const char *buf, int &len, void *ctx) {
auto pr = (pair<bool/*rtx*/, MediaTrack *> *) ctx; auto pr = (pair<bool/*rtx*/, MediaTrack *> *) ctx;
auto header = (RtpHeader *) buf; auto header = (RtpHeader *) buf;

View File

@ -56,7 +56,7 @@ public:
* @param len * @param len
* @param tuple * @param tuple
*/ */
void inputSockData(char *buf, size_t len, RTC::TransportTuple *tuple); void inputSockData(char *buf, int len, RTC::TransportTuple *tuple);
/** /**
* rtp * rtp
@ -65,8 +65,8 @@ public:
* @param flush flush socket * @param flush flush socket
* @param ctx * @param ctx
*/ */
void sendRtpPacket(const char *buf, size_t len, bool flush, void *ctx = nullptr); void sendRtpPacket(const char *buf, int len, bool flush, void *ctx = nullptr);
void sendRtcpPacket(const char *buf, size_t len, bool flush, void *ctx = nullptr); void sendRtcpPacket(const char *buf, int len, bool flush, void *ctx = nullptr);
const EventPoller::Ptr& getPoller() const; const EventPoller::Ptr& getPoller() const;
@ -103,8 +103,8 @@ protected:
virtual void onRtp(const char *buf, size_t len) = 0; virtual void onRtp(const char *buf, size_t len) = 0;
virtual void onRtcp(const char *buf, size_t len) = 0; virtual void onRtcp(const char *buf, size_t len) = 0;
virtual void onShutdown(const SockException &ex) = 0; virtual void onShutdown(const SockException &ex) = 0;
virtual void onBeforeEncryptRtp(const char *buf, size_t &len, void *ctx) = 0; virtual void onBeforeEncryptRtp(const char *buf, int &len, void *ctx) = 0;
virtual void onBeforeEncryptRtcp(const char *buf, size_t &len, void *ctx) = 0; virtual void onBeforeEncryptRtcp(const char *buf, int &len, void *ctx) = 0;
protected: protected:
const RtcSession& getSdp(SdpType type) const; const RtcSession& getSdp(SdpType type) const;
@ -176,8 +176,8 @@ protected:
void onRtp(const char *buf, size_t len) override; void onRtp(const char *buf, size_t len) override;
void onRtcp(const char *buf, size_t len) override; void onRtcp(const char *buf, size_t len) override;
void onBeforeEncryptRtp(const char *buf, size_t &len, void *ctx) override; void onBeforeEncryptRtp(const char *buf, int &len, void *ctx) override;
void onBeforeEncryptRtcp(const char *buf, size_t &len, void *ctx) override {}; void onBeforeEncryptRtcp(const char *buf, int &len, void *ctx) override {};
void onShutdown(const SockException &ex) override; void onShutdown(const SockException &ex) override;