优化代码

空构造和析构函数替换为缺省
去除多余分号
This commit is contained in:
xiongziliang 2023-04-22 21:59:26 +08:00
parent e8a425945d
commit 7a95c87a29
21 changed files with 50 additions and 57 deletions

View File

@ -24,7 +24,7 @@ public:
MediaPlayerForC(){ MediaPlayerForC(){
_player = std::make_shared<MediaPlayer>(); _player = std::make_shared<MediaPlayer>();
} }
~MediaPlayerForC(){} ~MediaPlayerForC() = default;
MediaPlayer *operator->(){ MediaPlayer *operator->(){
return _player.get(); return _player.get();

View File

@ -260,16 +260,16 @@ int start_main(int argc,char *argv[]) {
auto shellSrv = std::make_shared<TcpServer>(); auto shellSrv = std::make_shared<TcpServer>();
//rtsp[s]服务器, 可用于诸如亚马逊echo show这样的设备访问 //rtsp[s]服务器, 可用于诸如亚马逊echo show这样的设备访问
auto rtspSrv = std::make_shared<TcpServer>();; auto rtspSrv = std::make_shared<TcpServer>();
auto rtspSSLSrv = std::make_shared<TcpServer>();; auto rtspSSLSrv = std::make_shared<TcpServer>();
//rtmp[s]服务器 //rtmp[s]服务器
auto rtmpSrv = std::make_shared<TcpServer>();; auto rtmpSrv = std::make_shared<TcpServer>();
auto rtmpsSrv = std::make_shared<TcpServer>();; auto rtmpsSrv = std::make_shared<TcpServer>();
//http[s]服务器 //http[s]服务器
auto httpSrv = std::make_shared<TcpServer>();; auto httpSrv = std::make_shared<TcpServer>();
auto httpsSrv = std::make_shared<TcpServer>();; auto httpsSrv = std::make_shared<TcpServer>();
#if defined(ENABLE_RTPPROXY) #if defined(ENABLE_RTPPROXY)
//GB28181 rtp推流端口支持UDP/TCP //GB28181 rtp推流端口支持UDP/TCP

View File

@ -24,9 +24,8 @@ namespace mediakit{
class Track : public FrameDispatcher , public CodecInfo{ class Track : public FrameDispatcher , public CodecInfo{
public: public:
using Ptr = std::shared_ptr<Track>; using Ptr = std::shared_ptr<Track>;
Track(){} Track() = default;
virtual ~Track() = default;
virtual ~Track(){}
/** /**
* sps pps等信息 * sps pps等信息
@ -177,8 +176,8 @@ private:
class TrackSource{ class TrackSource{
public: public:
TrackSource(){} TrackSource() = default;
virtual ~TrackSource(){} virtual ~TrackSource() = default;
/** /**
* Track * Track

View File

@ -189,7 +189,7 @@ public:
_data = map_addr.get() + offset; _data = map_addr.get() + offset;
_size = size; _size = size;
} }
~BufferMmap() override {}; ~BufferMmap() override = default;
//返回数据长度 //返回数据长度
char *data() const override { return _data; } char *data() const override { return _data; }
size_t size() const override { return _size; } size_t size() const override { return _size; }

View File

@ -30,9 +30,9 @@ namespace mediakit {
class HttpBody : public std::enable_shared_from_this<HttpBody>{ class HttpBody : public std::enable_shared_from_this<HttpBody>{
public: public:
using Ptr = std::shared_ptr<HttpBody>; using Ptr = std::shared_ptr<HttpBody>;
HttpBody(){} HttpBody() = default;
virtual ~HttpBody(){} virtual ~HttpBody() = default;
/** /**
* -1, content-length * -1, content-length
@ -151,7 +151,7 @@ public:
* @param boundary boundary字符串 * @param boundary boundary字符串
*/ */
HttpMultiFormBody(const HttpArgs &args,const std::string &filePath,const std::string &boundary = "0xKhTmLbOuNdArY"); HttpMultiFormBody(const HttpArgs &args,const std::string &filePath,const std::string &boundary = "0xKhTmLbOuNdArY");
virtual ~HttpMultiFormBody(){} virtual ~HttpMultiFormBody() = default;
int64_t remainSize() override ; int64_t remainSize() override ;
toolkit::Buffer::Ptr readData(size_t size) override; toolkit::Buffer::Ptr readData(size_t size) override;

View File

@ -27,8 +27,8 @@ class HttpCookie {
public: public:
using Ptr = std::shared_ptr<HttpCookie>; using Ptr = std::shared_ptr<HttpCookie>;
friend class HttpCookieStorage; friend class HttpCookieStorage;
HttpCookie(){} HttpCookie() = default;
~HttpCookie(){} ~HttpCookie() = default;
void setPath(const std::string &path); void setPath(const std::string &path);
void setHost(const std::string &host); void setHost(const std::string &host);
@ -52,12 +52,14 @@ private:
*/ */
class HttpCookieStorage{ class HttpCookieStorage{
public: public:
~HttpCookieStorage(){} ~HttpCookieStorage() = default;
static HttpCookieStorage &Instance(); static HttpCookieStorage &Instance();
void set(const HttpCookie::Ptr &cookie); void set(const HttpCookie::Ptr &cookie);
std::vector<HttpCookie::Ptr> get(const std::string &host,const std::string &path); std::vector<HttpCookie::Ptr> get(const std::string &host,const std::string &path);
private: private:
HttpCookieStorage(){}; HttpCookieStorage() = default;
private: private:
std::unordered_map<std::string/*host*/, std::map<std::string/*cookie path*/,std::map<std::string/*cookie_key*/, HttpCookie::Ptr> > > _all_cookie; std::unordered_map<std::string/*host*/, std::map<std::string/*cookie path*/,std::map<std::string/*cookie_key*/, HttpCookie::Ptr> > > _all_cookie;
std::mutex _mtx_cookie; std::mutex _mtx_cookie;

View File

@ -24,8 +24,8 @@ public:
typedef std::function<void(int code, const StrCaseMap &headerOut, const HttpBody::Ptr &body)> HttpResponseInvokerLambda0; typedef std::function<void(int code, const StrCaseMap &headerOut, const HttpBody::Ptr &body)> HttpResponseInvokerLambda0;
typedef std::function<void(int code, const StrCaseMap &headerOut, const std::string &body)> HttpResponseInvokerLambda1; typedef std::function<void(int code, const StrCaseMap &headerOut, const std::string &body)> HttpResponseInvokerLambda1;
HttpResponseInvokerImp(){} HttpResponseInvokerImp() = default;
~HttpResponseInvokerImp(){} ~HttpResponseInvokerImp() = default;
template<typename C> template<typename C>
HttpResponseInvokerImp(const C &c):HttpResponseInvokerImp(typename toolkit::function_traits<C>::stl_function_type(c)) {} HttpResponseInvokerImp(const C &c):HttpResponseInvokerImp(typename toolkit::function_traits<C>::stl_function_type(c)) {}
HttpResponseInvokerImp(const HttpResponseInvokerLambda0 &lambda); HttpResponseInvokerImp(const HttpResponseInvokerLambda0 &lambda);

View File

@ -18,8 +18,8 @@ namespace mediakit {
class HttpRequestSplitter { class HttpRequestSplitter {
public: public:
HttpRequestSplitter(){}; HttpRequestSplitter() = default;
virtual ~HttpRequestSplitter(){}; virtual ~HttpRequestSplitter() = default;
/** /**
* *

View File

@ -37,7 +37,7 @@ public:
template <typename... ArgsType> template <typename... ArgsType>
ClientTypeImp(ArgsType &&...args) : ClientType(std::forward<ArgsType>(args)...) {} ClientTypeImp(ArgsType &&...args) : ClientType(std::forward<ArgsType>(args)...) {}
~ClientTypeImp() override {}; ~ClientTypeImp() override = default;
protected: protected:
/** /**

View File

@ -82,7 +82,7 @@ template<typename Creator, typename HttpSessionType = mediakit::HttpSession, med
class WebSocketSessionBase : public HttpSessionType { class WebSocketSessionBase : public HttpSessionType {
public: public:
WebSocketSessionBase(const toolkit::Socket::Ptr &pSock) : HttpSessionType(pSock){} WebSocketSessionBase(const toolkit::Socket::Ptr &pSock) : HttpSessionType(pSock){}
virtual ~WebSocketSessionBase(){} virtual ~WebSocketSessionBase() = default;
//收到eof或其他导致脱离TcpServer事件的回调 //收到eof或其他导致脱离TcpServer事件的回调
void onError(const toolkit::SockException &err) override{ void onError(const toolkit::SockException &err) override{
@ -248,7 +248,7 @@ template<typename SessionType,typename HttpSessionType = mediakit::HttpSession,
class WebSocketSession : public WebSocketSessionBase<SessionCreator<SessionType>,HttpSessionType,DataType>{ class WebSocketSession : public WebSocketSessionBase<SessionCreator<SessionType>,HttpSessionType,DataType>{
public: public:
WebSocketSession(const toolkit::Socket::Ptr &pSock) : WebSocketSessionBase<SessionCreator<SessionType>,HttpSessionType,DataType>(pSock){} WebSocketSession(const toolkit::Socket::Ptr &pSock) : WebSocketSessionBase<SessionCreator<SessionType>,HttpSessionType,DataType>(pSock){}
virtual ~WebSocketSession(){} virtual ~WebSocketSession() = default;
}; };
#endif //ZLMEDIAKIT_WEBSOCKETSESSION_H #endif //ZLMEDIAKIT_WEBSOCKETSESSION_H

View File

@ -51,7 +51,7 @@ public:
//根据内存地址设置掩码随机数 //根据内存地址设置掩码随机数
_mask.assign((uint8_t*)(&ptr), (uint8_t*)(&ptr) + 4); _mask.assign((uint8_t*)(&ptr), (uint8_t*)(&ptr) + 4);
} }
virtual ~WebSocketHeader(){} virtual ~WebSocketHeader() = default;
public: public:
bool _fin; bool _fin;
@ -71,7 +71,7 @@ public:
WebSocketBuffer(WebSocketHeader::Type headType, bool fin, ARGS &&...args) WebSocketBuffer(WebSocketHeader::Type headType, bool fin, ARGS &&...args)
: toolkit::BufferString(std::forward<ARGS>(args)...), _fin(fin), _head_type(headType){} : toolkit::BufferString(std::forward<ARGS>(args)...), _fin(fin), _head_type(headType){}
~WebSocketBuffer() override {} ~WebSocketBuffer() override = default;
WebSocketHeader::Type headType() const { return _head_type; } WebSocketHeader::Type headType() const { return _head_type; }
@ -84,8 +84,8 @@ private:
class WebSocketSplitter : public WebSocketHeader{ class WebSocketSplitter : public WebSocketHeader{
public: public:
WebSocketSplitter(){} WebSocketSplitter() = default;
virtual ~WebSocketSplitter(){} virtual ~WebSocketSplitter() = default;
/** /**
* 便webSocket数据以及处理粘包问题 * 便webSocket数据以及处理粘包问题

View File

@ -86,7 +86,7 @@ namespace mediakit {
class MpegMuxer : public MediaSinkInterface { class MpegMuxer : public MediaSinkInterface {
public: public:
MpegMuxer(bool is_ps) {}; MpegMuxer(bool is_ps) = default;
~MpegMuxer() override = default; ~MpegMuxer() override = default;
bool addTrack(const Track::Ptr &track) override { return false; } bool addTrack(const Track::Ptr &track) override { return false; }
void resetTracks() override {} void resetTracks() override {}

View File

@ -242,11 +242,9 @@ vector<RtcpHeader *> RtcpHeader::loadFromBytes(char *data, size_t len) {
class BufferRtcp : public Buffer { class BufferRtcp : public Buffer {
public: public:
BufferRtcp(std::shared_ptr<RtcpHeader> rtcp) { _rtcp = std::move(rtcp); } BufferRtcp(std::shared_ptr<RtcpHeader> rtcp) { _rtcp = std::move(rtcp); }
~BufferRtcp() override = default;
~BufferRtcp() override {}
char *data() const override { return (char *)_rtcp.get(); } char *data() const override { return (char *)_rtcp.get(); }
size_t size() const override { return _rtcp->getSize(); } size_t size() const override { return _rtcp->getSize(); }
private: private:

View File

@ -207,8 +207,8 @@ class Metadata : public CodecInfo{
public: public:
using Ptr = std::shared_ptr<Metadata>; using Ptr = std::shared_ptr<Metadata>;
Metadata():_metadata(AMF_OBJECT){} Metadata(): _metadata(AMF_OBJECT) {}
virtual ~Metadata(){} virtual ~Metadata() = default;
const AMFValue &getMetadata() const{ const AMFValue &getMetadata() const{
return _metadata; return _metadata;
} }
@ -239,7 +239,7 @@ public:
using Ptr = std::shared_ptr<VideoMeta>; using Ptr = std::shared_ptr<VideoMeta>;
VideoMeta(const VideoTrack::Ptr &video); VideoMeta(const VideoTrack::Ptr &video);
virtual ~VideoMeta(){} virtual ~VideoMeta() = default;
CodecId getCodecId() const override{ CodecId getCodecId() const override{
return _codecId; return _codecId;
@ -253,8 +253,7 @@ public:
using Ptr = std::shared_ptr<AudioMeta>; using Ptr = std::shared_ptr<AudioMeta>;
AudioMeta(const AudioTrack::Ptr &audio); AudioMeta(const AudioTrack::Ptr &audio);
virtual ~AudioMeta() = default;
virtual ~AudioMeta(){}
CodecId getCodecId() const override{ CodecId getCodecId() const override{
return _codecId; return _codecId;

View File

@ -181,13 +181,13 @@ void RtmpProtocol::sendRequest(int cmd, const string& str) {
class BufferPartial : public Buffer { class BufferPartial : public Buffer {
public: public:
BufferPartial(const Buffer::Ptr &buffer, size_t offset, size_t size){ BufferPartial(const Buffer::Ptr &buffer, size_t offset, size_t size) {
_buffer = buffer; _buffer = buffer;
_data = buffer->data() + offset; _data = buffer->data() + offset;
_size = size; _size = size;
} }
~BufferPartial() override{} ~BufferPartial() override = default;
char *data() const override { char *data() const override {
return _data; return _data;

View File

@ -13,12 +13,8 @@
#include "RtpSplitter.h" #include "RtpSplitter.h"
namespace mediakit{ namespace mediakit{
static const char kEHOME_MAGIC[] = "\x01\x00\x01\x00";
static const int kEHOME_OFFSET = 256; static const int kEHOME_OFFSET = 256;
RtpSplitter::RtpSplitter() {}
RtpSplitter::~RtpSplitter() {}
ssize_t RtpSplitter::onRecvHeader(const char *data,size_t len){ ssize_t RtpSplitter::onRecvHeader(const char *data,size_t len){
//忽略偏移量 //忽略偏移量
data += _offset; data += _offset;
@ -38,11 +34,10 @@ static bool isEhome(const char *data, size_t len){
if (len < 4) { if (len < 4) {
return false; return false;
} }
if((data[0] == 0x01) && (data[1] == 0x00) && (data[2] >=0x01)){ if ((data[0] == 0x01) && (data[1] == 0x00) && (data[2] >= 0x01)) {
return true; return true;
} }
return false; return false;
//return memcmp(data, kEHOME_MAGIC, sizeof(kEHOME_MAGIC) - 1) == 0;
} }
const char *RtpSplitter::onSearchPacketTail(const char *data, size_t len) { const char *RtpSplitter::onSearchPacketTail(const char *data, size_t len) {

View File

@ -18,8 +18,8 @@ namespace mediakit{
class RtpSplitter : public HttpRequestSplitter{ class RtpSplitter : public HttpRequestSplitter{
public: public:
RtpSplitter(); RtpSplitter() = default;
~RtpSplitter() override; ~RtpSplitter() override = default;
protected: protected:
/** /**

View File

@ -25,7 +25,7 @@ class TSSegment : public HttpRequestSplitter {
public: public:
typedef std::function<void(const char *data,size_t len)> onSegment; typedef std::function<void(const char *data,size_t len)> onSegment;
TSSegment(size_t size = TS_PACKET_SIZE) : _size(size){} TSSegment(size_t size = TS_PACKET_SIZE) : _size(size){}
~TSSegment(){} ~TSSegment() = default;
void setOnSegment(onSegment cb); void setOnSegment(onSegment cb);
static bool isTSPacket(const char *data, size_t len); static bool isTSPacket(const char *data, size_t len);

View File

@ -74,7 +74,7 @@ public:
_interleaved = interleaved; _interleaved = interleaved;
} }
virtual ~RtpInfo() {} virtual ~RtpInfo() = default;
//返回rtp负载最大长度 //返回rtp负载最大长度
size_t getMaxSize() const { size_t getMaxSize() const {

View File

@ -237,9 +237,9 @@ class SdpParser {
public: public:
using Ptr = std::shared_ptr<SdpParser>; using Ptr = std::shared_ptr<SdpParser>;
SdpParser() {} SdpParser() = default;
SdpParser(const std::string &sdp) { load(sdp); } SdpParser(const std::string &sdp) { load(sdp); }
~SdpParser() {} ~SdpParser() = default;
void load(const std::string &sdp); void load(const std::string &sdp);
bool available() const; bool available() const;
@ -268,7 +268,7 @@ public:
_payload_type = payload_type; _payload_type = payload_type;
} }
virtual ~Sdp(){} virtual ~Sdp() = default;
/** /**
* sdp字符串 * sdp字符串

View File

@ -18,8 +18,8 @@ namespace mediakit{
class RtspSplitter : public HttpRequestSplitter{ class RtspSplitter : public HttpRequestSplitter{
public: public:
RtspSplitter(){} RtspSplitter() = default;
virtual ~RtspSplitter(){} virtual ~RtspSplitter() = default;
/** /**
* rtp包 * rtp包