mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-29 22:55:52 +08:00
优化性能
This commit is contained in:
parent
492d083f5b
commit
1dc5eed748
@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2016 xiongziliang <771730766@qq.com>
|
|
||||||
*
|
|
||||||
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef SRC_MEDIASENDER_H_
|
|
||||||
#define SRC_MEDIASENDER_H_
|
|
||||||
|
|
||||||
#include "Thread/ThreadPool.h"
|
|
||||||
using namespace ZL::Thread;
|
|
||||||
|
|
||||||
class MediaSender {
|
|
||||||
public:
|
|
||||||
static ThreadPool & sendThread() {
|
|
||||||
static ThreadPool pool(1,ThreadPool::PRIORITY_HIGHEST);
|
|
||||||
return pool;
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
MediaSender();
|
|
||||||
virtual ~MediaSender();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* SRC_MEDIASENDER_H_ */
|
|
@ -36,7 +36,6 @@
|
|||||||
#include "Rtmp.h"
|
#include "Rtmp.h"
|
||||||
#include "RtmpParser.h"
|
#include "RtmpParser.h"
|
||||||
#include "Common/config.h"
|
#include "Common/config.h"
|
||||||
#include "Common/MediaSender.h"
|
|
||||||
#include "Common/MediaSource.h"
|
#include "Common/MediaSource.h"
|
||||||
#include "Util/util.h"
|
#include "Util/util.h"
|
||||||
#include "Util/logger.h"
|
#include "Util/logger.h"
|
||||||
@ -61,8 +60,7 @@ public:
|
|||||||
|
|
||||||
RtmpMediaSource(const string &vhost,const string &strApp, const string &strId) :
|
RtmpMediaSource(const string &vhost,const string &strApp, const string &strId) :
|
||||||
MediaSource(RTMP_SCHEMA,vhost,strApp,strId),
|
MediaSource(RTMP_SCHEMA,vhost,strApp,strId),
|
||||||
m_pRing(new RingBuffer<RtmpPacket::Ptr>()),
|
m_pRing(new RingBuffer<RtmpPacket::Ptr>()) {
|
||||||
m_thPool( MediaSender::sendThread()) {
|
|
||||||
}
|
}
|
||||||
virtual ~RtmpMediaSource() {}
|
virtual ~RtmpMediaSource() {}
|
||||||
|
|
||||||
@ -109,10 +107,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto _ring = m_pRing;
|
m_pRing->write(pkt,pkt->isVideoKeyFrame());
|
||||||
m_thPool.async([_ring,pkt]() {
|
|
||||||
_ring->write(pkt,pkt->isVideoKeyFrame());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
bool ready(){
|
bool ready(){
|
||||||
@ -124,7 +119,6 @@ protected:
|
|||||||
unordered_map<int, RtmpPacket::Ptr> m_mapCfgFrame;
|
unordered_map<int, RtmpPacket::Ptr> m_mapCfgFrame;
|
||||||
mutable recursive_mutex m_mtxMap;
|
mutable recursive_mutex m_mtxMap;
|
||||||
RingBuffer<RtmpPacket::Ptr>::Ptr m_pRing; //rtp环形缓冲
|
RingBuffer<RtmpPacket::Ptr>::Ptr m_pRing; //rtp环形缓冲
|
||||||
ThreadPool &m_thPool;
|
|
||||||
int m_iCfgFrameSize = -1;
|
int m_iCfgFrameSize = -1;
|
||||||
bool m_bAsyncRegist = false;
|
bool m_bAsyncRegist = false;
|
||||||
bool m_bRegisted = false;
|
bool m_bRegisted = false;
|
||||||
|
@ -34,7 +34,6 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include "Rtsp.h"
|
#include "Rtsp.h"
|
||||||
#include "Common/config.h"
|
#include "Common/config.h"
|
||||||
#include "Common/MediaSender.h"
|
|
||||||
#include "Common/MediaSource.h"
|
#include "Common/MediaSource.h"
|
||||||
|
|
||||||
#include "Util/logger.h"
|
#include "Util/logger.h"
|
||||||
@ -60,8 +59,7 @@ public:
|
|||||||
|
|
||||||
RtspMediaSource(const string &strVhost,const string &strApp, const string &strId) :
|
RtspMediaSource(const string &strVhost,const string &strApp, const string &strId) :
|
||||||
MediaSource(RTSP_SCHEMA,strVhost,strApp,strId),
|
MediaSource(RTSP_SCHEMA,strVhost,strApp,strId),
|
||||||
m_pRing(new RingBuffer<RtpPacket::Ptr>()),
|
m_pRing(new RingBuffer<RtpPacket::Ptr>()) {
|
||||||
m_thPool(MediaSender::sendThread()) {
|
|
||||||
}
|
}
|
||||||
virtual ~RtspMediaSource() {}
|
virtual ~RtspMediaSource() {}
|
||||||
|
|
||||||
@ -95,16 +93,12 @@ public:
|
|||||||
trackRef.timeStamp = rtppt->timeStamp;
|
trackRef.timeStamp = rtppt->timeStamp;
|
||||||
trackRef.ssrc = rtppt->ssrc;
|
trackRef.ssrc = rtppt->ssrc;
|
||||||
trackRef.type = rtppt->type;
|
trackRef.type = rtppt->type;
|
||||||
auto _outRing = m_pRing;
|
m_pRing->write(rtppt,keyPos);
|
||||||
m_thPool.async([_outRing,rtppt,keyPos]() {
|
|
||||||
_outRing->write(rtppt,keyPos);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
unordered_map<int, RtspTrack> m_mapTracks;
|
unordered_map<int, RtspTrack> m_mapTracks;
|
||||||
string m_strSdp; //媒体描述信息
|
string m_strSdp; //媒体描述信息
|
||||||
RingType::Ptr m_pRing; //rtp环形缓冲
|
RingType::Ptr m_pRing; //rtp环形缓冲
|
||||||
ThreadPool &m_thPool;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace Rtsp */
|
} /* namespace Rtsp */
|
||||||
|
Loading…
Reference in New Issue
Block a user