适配ZLToolKit develop分支

This commit is contained in:
xiongziliang
2018-02-23 15:36:51 +08:00
parent b0a64d1e6f
commit f1b4a196c6
30 changed files with 137 additions and 125 deletions

View File

@@ -126,7 +126,7 @@ void RtmpPlayer::onConnect(const SockException &err){
strongSelf->send_connect();
});
}
void RtmpPlayer::onRecv(const Socket::Buffer::Ptr &pBuf){
void RtmpPlayer::onRecv(const Buffer::Ptr &pBuf){
try {
onParseRtmp(pBuf->data(), pBuf->size());
} catch (exception &e) {

View File

@@ -99,7 +99,7 @@ private:
}
//for Tcpclient
void onRecv(const Socket::Buffer::Ptr &pBuf) override;
void onRecv(const Buffer::Ptr &pBuf) override;
void onConnect(const SockException &err) override;
void onErr(const SockException &ex) override;
//fro RtmpProtocol
@@ -108,8 +108,8 @@ private:
void onSendRawData(const char *pcRawData, int iSize) override {
send(pcRawData, iSize);
}
void onSendRawData(const Socket::Buffer::Ptr &buffer,int flags) override{
m_pSock->send(buffer,flags);
void onSendRawData(const Buffer::Ptr &buffer,int flags) override{
_sock->send(buffer,flags);
}
template<typename FUN>

View File

@@ -204,7 +204,7 @@ void RtmpProtocol::sendRtmp(uint8_t ui8Type, uint32_t ui32StreamId,
//估算rtmp包数据大小
uint32_t capacity = ((bExtStamp ? 5 : 1) * (1 + (strBuf.size() / m_iChunkLenOut))) + strBuf.size() + sizeof(header);
uint32_t totalSize = 0;
Socket::BufferRaw::Ptr buffer = m_bufferPool.obtain();
BufferRaw::Ptr buffer = m_bufferPool.obtain();
buffer->setCapacity(capacity);
memcpy(buffer->data() + totalSize,(char *) &header, sizeof(header));
totalSize += sizeof(header);

View File

@@ -55,7 +55,7 @@ public:
void reset();
protected:
virtual void onSendRawData(const char *pcRawData,int iSize) = 0;
virtual void onSendRawData(const Socket::Buffer::Ptr &buffer,int flags) = 0;
virtual void onSendRawData(const Buffer::Ptr &buffer,int flags) = 0;
virtual void onRtmpChunk(RtmpPacket &chunkData) = 0;
@@ -85,7 +85,7 @@ protected:
int m_iNowStreamID = 0;
int m_iNowChunkID = 0;
bool m_bDataStarted = false;
ResourcePool<Socket::BufferRaw,MAX_SEND_PKT> m_bufferPool;
ResourcePool<BufferRaw,MAX_SEND_PKT> m_bufferPool;
private:
void handle_S0S1S2(const function<void()> &cb);
void handle_C0C1();

View File

@@ -131,7 +131,7 @@ void RtmpPusher::onConnect(const SockException &err){
strongSelf->send_connect();
});
}
void RtmpPusher::onRecv(const Socket::Buffer::Ptr &pBuf){
void RtmpPusher::onRecv(const Buffer::Ptr &pBuf){
try {
onParseRtmp(pBuf->data(), pBuf->size());
} catch (exception &e) {

View File

@@ -56,7 +56,7 @@ public:
protected:
//for Tcpclient
void onRecv(const Socket::Buffer::Ptr &pBuf) override;
void onRecv(const Buffer::Ptr &pBuf) override;
void onConnect(const SockException &err) override;
void onErr(const SockException &ex) override;
@@ -65,8 +65,8 @@ protected:
void onSendRawData(const char *pcRawData, int iSize) override {
send(pcRawData, iSize);
}
void onSendRawData(const Socket::Buffer::Ptr &buffer,int flags) override{
m_pSock->send(buffer,flags);
void onSendRawData(const Buffer::Ptr &buffer,int flags) override{
_sock->send(buffer,flags);
}
private:
void init(const RtmpMediaSource::Ptr &src);

View File

@@ -33,7 +33,7 @@ namespace Rtmp {
unordered_map<string, RtmpSession::rtmpCMDHandle> RtmpSession::g_mapCmd;
RtmpSession::RtmpSession(const std::shared_ptr<ThreadPool> &pTh, const Socket::Ptr &pSock) :
TcpLimitedSession(pTh, pSock) {
TcpSession(pTh, pSock) {
static onceToken token([]() {
g_mapCmd.emplace("connect",&RtmpSession::onCmd_connect);
g_mapCmd.emplace("createStream",&RtmpSession::onCmd_createStream);
@@ -43,11 +43,11 @@ RtmpSession::RtmpSession(const std::shared_ptr<ThreadPool> &pTh, const Socket::P
g_mapCmd.emplace("play2",&RtmpSession::onCmd_play2);
g_mapCmd.emplace("seek",&RtmpSession::onCmd_seek);
g_mapCmd.emplace("pause",&RtmpSession::onCmd_pause);}, []() {});
DebugL << getPeerIp();
DebugL << get_peer_ip();
}
RtmpSession::~RtmpSession() {
DebugL << getPeerIp();
DebugL << get_peer_ip();
}
void RtmpSession::onError(const SockException& err) {
@@ -64,20 +64,20 @@ void RtmpSession::onError(const SockException& err) {
void RtmpSession::onManager() {
if (m_ticker.createdTime() > 10 * 1000) {
if (!m_pRingReader && !m_pPublisherSrc) {
WarnL << "非法链接:" << getPeerIp();
WarnL << "非法链接:" << get_peer_ip();
shutdown();
}
}
if (m_pPublisherSrc) {
//publisher
if (m_ticker.elapsedTime() > 10 * 1000) {
WarnL << "数据接收超时:" << getPeerIp();
WarnL << "数据接收超时:" << get_peer_ip();
shutdown();
}
}
}
void RtmpSession::onRecv(const Socket::Buffer::Ptr &pBuf) {
void RtmpSession::onRecv(const Buffer::Ptr &pBuf) {
m_ticker.resetTime();
try {
m_ui64TotalBytes += pBuf->size();
@@ -273,7 +273,7 @@ void RtmpSession::doPlay(AMFDecoder &dec){
m_pRingReader = src->getRing()->attach();
weak_ptr<RtmpSession> weakSelf = dynamic_pointer_cast<RtmpSession>(shared_from_this());
SockUtil::setNoDelay(sock->rawFD(), false);
SockUtil::setNoDelay(_sock->rawFD(), false);
m_pRingReader->setReadCB([weakSelf](const RtmpPacket::Ptr &pkt) {
auto strongSelf = weakSelf.lock();
if (!strongSelf) {

View File

@@ -36,7 +36,7 @@
#include "RtmpToRtspMediaSource.h"
#include "Util/util.h"
#include "Util/TimeTicker.h"
#include "Network/TcpLimitedSession.h"
#include "Network/TcpSession.h"
using namespace ZL::Util;
using namespace ZL::Network;
@@ -44,12 +44,12 @@ using namespace ZL::Network;
namespace ZL {
namespace Rtmp {
class RtmpSession: public TcpLimitedSession<MAX_TCP_SESSION> ,public RtmpProtocol , public MediaSourceEvent{
class RtmpSession: public TcpSession ,public RtmpProtocol , public MediaSourceEvent{
public:
typedef std::shared_ptr<RtmpSession> Ptr;
RtmpSession(const std::shared_ptr<ThreadPool> &_th, const Socket::Ptr &_sock);
virtual ~RtmpSession();
void onRecv(const Socket::Buffer::Ptr &pBuf) override;
void onRecv(const Buffer::Ptr &pBuf) override;
void onError(const SockException &err) override;
void onManager() override;
private:
@@ -86,9 +86,9 @@ private:
m_ui64TotalBytes += iSize;
send(pcRawData, iSize);
}
void onSendRawData(const Socket::Buffer::Ptr &buffer,int flags) override{
void onSendRawData(const Buffer::Ptr &buffer,int flags) override{
m_ui64TotalBytes += buffer->size();
sock->send(buffer,flags);
_sock->send(buffer,flags);
}
void onRtmpChunk(RtmpPacket &chunkData) override;