Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
“penghaoze committed Dec 24, 2019
1 parent c5aff50 commit 60d0245
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 92 deletions.
2 changes: 1 addition & 1 deletion Makefile
@@ -1,4 +1,4 @@
DEUBG = -DXOP_DEBUG
DEUBG = -D_DEBUG

TARGET1 = rtsp_server
TARGET2 = rtsp_pusher
Expand Down
6 changes: 3 additions & 3 deletions src/net/TcpSocket.cpp
Expand Up @@ -34,7 +34,7 @@ bool TcpSocket::bind(std::string ip, uint16_t port)

if(::bind(_sockfd, (struct sockaddr*)&addr, sizeof(addr)) == SOCKET_ERROR)
{
LOG_DEBUG(" <socket=%d> bind <%s:%u> failed.\n", _sockfd, ip.c_str(), port);
LOG_ERROR(" <socket=%d> bind <%s:%u> failed.\n", _sockfd, ip.c_str(), port);
return false;
}

Expand All @@ -45,7 +45,7 @@ bool TcpSocket::listen(int backlog)
{
if(::listen(_sockfd, backlog) == SOCKET_ERROR)
{
LOG_DEBUG("<socket=%d> listen failed.\n", _sockfd);
LOG_ERROR("<socket=%d> listen failed.\n", _sockfd);
return false;
}

Expand All @@ -66,7 +66,7 @@ bool TcpSocket::connect(std::string ip, uint16_t port, int timeout)
{
if(!SocketUtil::connect(_sockfd, ip, port, timeout))
{
LOG_DEBUG("<socket=%d> connect failed.\n", _sockfd);
LOG_ERROR("<socket=%d> connect failed.\n", _sockfd);
return false;
}

Expand Down
176 changes: 88 additions & 88 deletions src/xop/RtspPusher.cpp
@@ -1,58 +1,58 @@
#include "RtspPusher.h"
#include "RtspConnection.h"
#include "net/Logger.h"
#include "net/TcpSocket.h"
#include "net/Timestamp.h"

using namespace xop;

RtspPusher::RtspPusher(xop::EventLoop *eventLoop)
: _eventLoop(eventLoop)
{

}

RtspPusher::~RtspPusher()
{

}

void RtspPusher::addMeidaSession(MediaSession* session)
{
std::lock_guard<std::mutex> locker(_mutex);
_mediaSessionPtr.reset(session);
}

void RtspPusher::removeMeidaSession(MediaSessionId sessionId)
{
std::lock_guard<std::mutex> locker(_mutex);
_mediaSessionPtr = nullptr;
}

MediaSessionPtr RtspPusher::lookMediaSession(MediaSessionId sessionId)
{
return _mediaSessionPtr;
}

int RtspPusher::openUrl(std::string url, int msec)
{
std::lock_guard<std::mutex> lock(_mutex);

#include "RtspPusher.h"
#include "RtspConnection.h"
#include "net/Logger.h"
#include "net/TcpSocket.h"
#include "net/Timestamp.h"

using namespace xop;

RtspPusher::RtspPusher(xop::EventLoop *eventLoop)
: _eventLoop(eventLoop)
{

}

RtspPusher::~RtspPusher()
{

}

void RtspPusher::addMeidaSession(MediaSession* session)
{
std::lock_guard<std::mutex> locker(_mutex);
_mediaSessionPtr.reset(session);
}

void RtspPusher::removeMeidaSession(MediaSessionId sessionId)
{
std::lock_guard<std::mutex> locker(_mutex);
_mediaSessionPtr = nullptr;
}

MediaSessionPtr RtspPusher::lookMediaSession(MediaSessionId sessionId)
{
return _mediaSessionPtr;
}

int RtspPusher::openUrl(std::string url, int msec)
{
std::lock_guard<std::mutex> lock(_mutex);

static xop::Timestamp tp;
int timeout = msec;
if (timeout <= 0)
{
timeout = 10000;
}

tp.reset();

if (!this->parseRtspUrl(url))
{
LOG_ERROR("rtsp url(%s) was illegal.\n", url.c_str());
return -1;
}

tp.reset();

if (!this->parseRtspUrl(url))
{
LOG_ERROR("rtsp url(%s) was illegal.\n", url.c_str());
return -1;
}

if (_rtspConn != nullptr)
{
std::shared_ptr<RtspConnection> rtspConn = _rtspConn;
Expand All @@ -61,22 +61,22 @@ int RtspPusher::openUrl(std::string url, int msec)
rtspConn->disconnect();
});
_rtspConn = nullptr;
}

TcpSocket tcpSocket;
tcpSocket.create();
if (!tcpSocket.connect(_rtspUrlInfo.ip, _rtspUrlInfo.port, timeout))
{
tcpSocket.close();
return -1;
}

_taskScheduler = _eventLoop->getTaskScheduler().get();
_rtspConn.reset(new RtspConnection((RtspPusher*)this, _taskScheduler, tcpSocket.fd()));
_eventLoop->addTriggerEvent([this]() {
_rtspConn->sendOptions(RtspConnection::RTSP_PUSHER);
});

}

TcpSocket tcpSocket;
tcpSocket.create();
if (!tcpSocket.connect(_rtspUrlInfo.ip, _rtspUrlInfo.port, timeout))
{
tcpSocket.close();
return -1;
}

_taskScheduler = _eventLoop->getTaskScheduler().get();
_rtspConn.reset(new RtspConnection((RtspPusher*)this, _taskScheduler, tcpSocket.fd()));
_eventLoop->addTriggerEvent([this]() {
_rtspConn->sendOptions(RtspConnection::RTSP_PUSHER);
});

timeout -= (int)tp.elapsed();
if (timeout < 0)
{
Expand All @@ -98,13 +98,13 @@ int RtspPusher::openUrl(std::string url, int msec)
});
_rtspConn = nullptr;
return -1;
}

return 0;
}

void RtspPusher::close()
{
}

return 0;
}

void RtspPusher::close()
{
std::lock_guard<std::mutex> lock(_mutex);

if (_rtspConn != nullptr)
Expand All @@ -115,26 +115,26 @@ void RtspPusher::close()
rtspConn->disconnect();
});
_rtspConn = nullptr;
}
}

bool RtspPusher::isConnected()
{
}
}

bool RtspPusher::isConnected()
{
std::lock_guard<std::mutex> lock(_mutex);
if (_rtspConn != nullptr)
{
return (!_rtspConn->isClosed());
}
return false;
}

bool RtspPusher::pushFrame(MediaChannelId channelId, AVFrame frame)
{
std::lock_guard<std::mutex> locker(_mutex);
if (_mediaSessionPtr==nullptr || _rtspConn==nullptr)
{
return false;
}

return _mediaSessionPtr->handleFrame(channelId, frame);
return false;
}

bool RtspPusher::pushFrame(MediaChannelId channelId, AVFrame frame)
{
std::lock_guard<std::mutex> locker(_mutex);
if (_mediaSessionPtr==nullptr || _rtspConn==nullptr)
{
return false;
}

return _mediaSessionPtr->handleFrame(channelId, frame);
}

0 comments on commit 60d0245

Please sign in to comment.