格式化代码

This commit is contained in:
ziyue 2022-06-07 10:01:42 +08:00
commit e5ca3aa0fb
10 changed files with 44 additions and 53 deletions

View File

@ -1,9 +1,19 @@
#ifndef ZLMEDIAKIT_SRT_COMMON_H
#define ZLMEDIAKIT_SRT_COMMON_H
#if defined(_WIN32)
#include <winsock2.h>
#include <ws2tcpip.h>
#include <Iphlpapi.h>
#pragma comment (lib, "Ws2_32.lib")
#pragma comment(lib,"Iphlpapi.lib")
#else
#include <netdb.h>
#include <sys/socket.h>
#endif // defined(_WIN32)
#include <chrono>
namespace SRT {
using SteadyClock = std::chrono::steady_clock;
using TimePoint = std::chrono::time_point<SteadyClock>;

View File

@ -1,18 +1,7 @@

#if defined(_WIN32)
#include <winsock2.h>
#include <ws2tcpip.h>
#include <Iphlpapi.h>
#pragma comment (lib, "Ws2_32.lib")
#pragma comment(lib,"Iphlpapi.lib")
#else
#include <sys/socket.h>
#include <netdb.h>
#endif // defined(_WIN32)
#include <atomic>
#include "Util/logger.h"
#include "Util/MD5.h"
#include "Util/logger.h"
#include <atomic>
#include "Packet.hpp"
namespace SRT {
@ -342,7 +331,6 @@ size_t HandshakePacket::getExtSize() {
}
return size;
}
bool HandshakePacket::storeToData() {
_data = BufferRaw::create();
for (auto ex : ext_list) {
@ -445,15 +433,11 @@ uint32_t HandshakePacket::generateSynCookie(
// SYN cookie
char clienthost[NI_MAXHOST];
char clientport[NI_MAXSERV];
getnameinfo((struct sockaddr*)addr,
sizeof(struct sockaddr_storage),
clienthost,
sizeof(clienthost),
clientport,
sizeof(clientport),
NI_NUMERICHOST | NI_NUMERICSERV);
int64_t timestamp = (DurationCountMicroseconds(SteadyClock::now() - ts) / 60000000) + distractor.load() +
correction; // secret changes every one minute
getnameinfo(
(struct sockaddr *)addr, sizeof(struct sockaddr_storage), clienthost, sizeof(clienthost), clientport,
sizeof(clientport), NI_NUMERICHOST | NI_NUMERICSERV);
int64_t timestamp = (DurationCountMicroseconds(SteadyClock::now() - ts) / 60000000) + distractor.load()
+ correction; // secret changes every one minute
std::stringstream cookiestr;
cookiestr << clienthost << ":" << clientport << ":" << timestamp;
union {

View File

@ -63,8 +63,6 @@ public:
uint32_t timestamp;
uint32_t dst_socket_id;
TimePoint get_ts; // recv or send time
private:
BufferRaw::Ptr _data;
};
@ -189,7 +187,8 @@ public:
static bool isHandshakePacket(uint8_t *buf, size_t len);
static uint32_t getHandshakeType(uint8_t *buf, size_t len);
static uint32_t getSynCookie(uint8_t *buf, size_t len);
static uint32_t generateSynCookie(struct sockaddr_storage *addr, TimePoint ts, uint32_t current_cookie = 0, int correction = 0);
static uint32_t
generateSynCookie(struct sockaddr_storage *addr, TimePoint ts, uint32_t current_cookie = 0, int correction = 0);
void assignPeerIP(struct sockaddr_storage *addr);
///////ControlPacket override///////

View File

@ -68,7 +68,7 @@ uint32_t PacketSendQueue::timeLatency() {
} else {
dur = first - last;
}
if (dur > (0x01 << 31)) {
if (dur > ((uint32_t)0x01 << 31)) {
TraceL << "cycle timeLatency " << dur;
dur = 0xffffffff - dur;
}

View File

@ -25,7 +25,6 @@ public:
private:
uint32_t timeLatency();
private:
uint32_t _pkt_cap;
uint32_t _pkt_latency;

View File

@ -1,8 +1,9 @@
#include <stdlib.h>
#include "Util/onceToken.h"
#include "Ack.hpp"
#include "Packet.hpp"
#include "SrtTransport.hpp"
#include "Util/onceToken.h"
namespace SRT {
#define SRT_FIELD "srt."
@ -13,7 +14,6 @@ const std::string kPort = SRT_FIELD "port";
const std::string kLatencyMul = SRT_FIELD "latencyMul";
static std::atomic<uint32_t> s_srt_socket_id_generate { 125 };
//////////// SrtTransport //////////////////////////
SrtTransport::SrtTransport(const EventPoller::Ptr &poller)
: _poller(poller) {
@ -432,7 +432,6 @@ void SrtTransport::handleDataPacket(uint8_t *buf, int len, struct sockaddr_stora
DataPacket::Ptr pkt = std::make_shared<DataPacket>();
pkt->loadFromData(buf, len);
pkt->get_ts = _now;
std::list<DataPacket::Ptr> list;
//TraceL<<" seq="<< pkt->packet_seq_number<<" ts="<<pkt->timestamp<<" size="<<pkt->payloadSize()<<\
//" PP="<<(int)pkt->PP<<" O="<<(int)pkt->O<<" kK="<<(int)pkt->KK<<" R="<<(int)pkt->R;

View File

@ -9,16 +9,15 @@ SrtTransportImp::SrtTransportImp(const EventPoller::Ptr &poller) : SrtTransport(
SrtTransportImp::~SrtTransportImp() {
InfoP(this);
uint64_t duration = _alive_ticker.createdTime() / 1000;
WarnP(this) << (_is_pusher ? "srt 推流器(" : "srt 播放器(")
<< _media_info._vhost << "/"
<< _media_info._app << "/"
<< _media_info._streamid
<< ")断开,耗时(s):" << duration;
WarnP(this) << (_is_pusher ? "srt 推流器(" : "srt 播放器(") << _media_info._vhost << "/" << _media_info._app << "/"
<< _media_info._streamid << ")断开,耗时(s):" << duration;
//流量统计事件广播
GET_CONFIG(uint32_t, iFlowThreshold, General::kFlowThreshold);
if (_total_bytes >= iFlowThreshold * 1024) {
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _media_info, _total_bytes, duration, false, static_cast<SockInfo &>(*this));
NoticeCenter::Instance().emitEvent(
Broadcast::kBroadcastFlowReport, _media_info, _total_bytes, duration, false,
static_cast<SockInfo &>(*this));
}
}
@ -71,7 +70,6 @@ bool SrtTransportImp::close(mediakit::MediaSource &sender, bool force) {
<< sender.getVhost() << "/"
<< sender.getApp() << "/"
<< sender.getId() << " " << force;
weak_ptr<SrtTransportImp> weak_self = static_pointer_cast<SrtTransportImp>(shared_from_this());
getPoller()->async([weak_self, err]() {
auto strong_self = weak_self.lock();
@ -112,10 +110,9 @@ void SrtTransportImp::emitOnPublish() {
return;
}
if (err.empty()) {
strong_self->_muxer = std::make_shared<MultiMediaSourceMuxer>(strong_self->_media_info._vhost,
strong_self->_media_info._app,
strong_self->_media_info._streamid, 0.0f,
option);
strong_self->_muxer = std::make_shared<MultiMediaSourceMuxer>(
strong_self->_media_info._vhost, strong_self->_media_info._app, strong_self->_media_info._streamid,
0.0f, option);
strong_self->_muxer->setMediaListener(strong_self);
strong_self->doCachedFunc();
InfoP(strong_self) << "允许 srt 推流";
@ -126,7 +123,9 @@ void SrtTransportImp::emitOnPublish() {
};
//触发推流鉴权事件
auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPublish, MediaOriginType::srt_push, _media_info, invoker, static_cast<SockInfo &>(*this));
auto flag = NoticeCenter::Instance().emitEvent(
Broadcast::kBroadcastMediaPublish, MediaOriginType::srt_push, _media_info, invoker,
static_cast<SockInfo &>(*this));
if (!flag) {
//该事件无人监听,默认不鉴权
invoker("", ProtocolOption());
@ -149,7 +148,8 @@ void SrtTransportImp::emitOnPlay() {
});
};
auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed, _media_info, invoker, static_cast<SockInfo &>(*this));
auto flag = NoticeCenter::Instance().emitEvent(
Broadcast::kBroadcastMediaPlayed, _media_info, invoker, static_cast<SockInfo &>(*this));
if (!flag) {
doPlay();
}

View File

@ -12,7 +12,6 @@ namespace SRT {
using namespace std;
using namespace toolkit;
using namespace mediakit;
class SrtTransportImp
: public SrtTransport
, public toolkit::SockInfo
@ -27,7 +26,6 @@ public:
_total_bytes += len;
}
void onSendTSData(const Buffer::Ptr &buffer, bool flush) override { SrtTransport::onSendTSData(buffer, flush); }
/// SockInfo override
std::string get_local_ip() override;
uint16_t get_local_port() override;

View File

@ -9,7 +9,8 @@ namespace SRT {
class PacketRecvRateContext {
public:
PacketRecvRateContext(TimePoint start): _start(start) {};
PacketRecvRateContext(TimePoint start)
: _start(start) {};
~PacketRecvRateContext() = default;
void inputPacket(TimePoint &ts);
uint32_t getPacketRecvRate();
@ -33,7 +34,8 @@ private:
class RecvRateContext {
public:
RecvRateContext(TimePoint start): _start(start) {};
RecvRateContext(TimePoint start)
: _start(start) {};
~RecvRateContext() = default;
void inputPacket(TimePoint &ts, size_t size);
uint32_t getRecvRate();