Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add CMakeLists.txt #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
cmake_minimum_required(VERSION 2.6)
project(RtspServer LANGUAGES CXX)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()

# 不需要RTSP摘要认证就删除-DAUTH_CONFIG
set(CMAKE_CXX_FLAGS "-g -Wall -std=c++11 -DAUTH_CONFIG")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -DXOP_DEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR})

string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE)
message(STATUS "CXX_FLAGS = " ${CMAKE_CXX_FLAGS} " " ${CMAKE_CXX_FLAGS_${BUILD_TYPE}})

include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${PROJECT_SOURCE_DIR}/src/3rdpart)

set(NET_SOURCES
${PROJECT_SOURCE_DIR}/src/net/Acceptor.cpp
${PROJECT_SOURCE_DIR}/src/net/BufferReader.cpp
${PROJECT_SOURCE_DIR}/src/net/BufferWriter.cpp
${PROJECT_SOURCE_DIR}/src/net/EpollTaskScheduler.cpp
${PROJECT_SOURCE_DIR}/src/net/EventLoop.cpp
${PROJECT_SOURCE_DIR}/src/net/Logger.cpp
${PROJECT_SOURCE_DIR}/src/net/MemoryManager.cpp
${PROJECT_SOURCE_DIR}/src/net/NetInterface.cpp
${PROJECT_SOURCE_DIR}/src/net/Pipe.cpp
${PROJECT_SOURCE_DIR}/src/net/SelectTaskScheduler.cpp
${PROJECT_SOURCE_DIR}/src/net/SocketUtil.cpp
${PROJECT_SOURCE_DIR}/src/net/TaskScheduler.cpp
${PROJECT_SOURCE_DIR}/src/net/TcpSocket.cpp
${PROJECT_SOURCE_DIR}/src/net/TcpServer.cpp
${PROJECT_SOURCE_DIR}/src/net/Timestamp.cpp
${PROJECT_SOURCE_DIR}/src/net/Timer.cpp
${PROJECT_SOURCE_DIR}/src/net/TcpConnection.cpp
)
add_library(net ${NET_SOURCES})

set(XOP_SOURCES
${PROJECT_SOURCE_DIR}/src/xop/AACSource.cpp
${PROJECT_SOURCE_DIR}/src/xop/DigestAuthentication.cpp
${PROJECT_SOURCE_DIR}/src/xop/G711ASource.cpp
${PROJECT_SOURCE_DIR}/src/xop/H264Parser.cpp
${PROJECT_SOURCE_DIR}/src/xop/H264Source.cpp
${PROJECT_SOURCE_DIR}/src/xop/H265Source.cpp
${PROJECT_SOURCE_DIR}/src/xop/MediaSession.cpp
${PROJECT_SOURCE_DIR}/src/xop/RtpConnection.cpp
${PROJECT_SOURCE_DIR}/src/xop/RtspConnection.cpp
${PROJECT_SOURCE_DIR}/src/xop/RtspMessage.cpp
${PROJECT_SOURCE_DIR}/src/xop/RtspPusher.cpp
${PROJECT_SOURCE_DIR}/src/xop/RtspServer.cpp
)
add_library(xop ${XOP_SOURCES})

add_executable(rtsp_server ${PROJECT_SOURCE_DIR}/example/rtsp_server.cpp)
target_link_libraries(rtsp_server xop net pthread)

add_executable(rtsp_pusher ${PROJECT_SOURCE_DIR}/example/rtsp_pusher.cpp)
target_link_libraries(rtsp_pusher xop net pthread)

add_executable(rtsp_h264_file ${PROJECT_SOURCE_DIR}/example/rtsp_h264_file.cpp)
target_link_libraries(rtsp_h264_file xop net pthread)

2 changes: 1 addition & 1 deletion example/rtsp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void snedFrameThread(xop::RtspServer* rtspServer, xop::MediaSessionId sessionId,
//获取一帧 AAC, 打包
xop::AVFrame audioFrame = {0};
audioFrame.type = xop::AUDIO_FRAME;
audioFrame.size = audio frame size; /* 音频帧大小
audioFrame.size = audio frame size; // 音频帧大小
audioFrame.timestamp = xop::AACSource::getTimeStamp(44100); // 时间戳
audioFrame.buffer.reset(new uint8_t[audioFrame.size]);
memcpy(audioFrame.buffer.get(), audio frame data, audioFrame.size);
Expand Down
2 changes: 1 addition & 1 deletion src/net/BufferWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class BufferWriter
uint32_t writeIndex;
} Packet;

std::shared_ptr<std::queue<Packet>> _buffer;
int _maxQueueLength = 0;
std::shared_ptr<std::queue<Packet>> _buffer;

static const int kMaxQueueLength = 10000;
};
Expand Down
5 changes: 2 additions & 3 deletions src/net/EventLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,13 @@ void EventLoop::loop()
_threads.push_back(t);
}

int priority = TASK_SCHEDULER_PRIORITY_REALTIME;

for (auto iter : _threads)
{
#if defined(__linux) || defined(__linux__)

#elif defined(WIN32) || defined(_WIN32)
switch (priority)
int priority = TASK_SCHEDULER_PRIORITY_REALTIME;
switch (priority)
{
case TASK_SCHEDULER_PRIORITY_LOW:
SetThreadPriority(iter->native_handle(), THREAD_PRIORITY_BELOW_NORMAL);
Expand Down
2 changes: 1 addition & 1 deletion src/net/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Logger
};

}
#ifdef _DEBUG
#ifdef XOP_DEBUG
#define LOG_DEBUG(fmt, ...) xop::Logger::instance().log(xop::LOG_DEBUG, __FILE__, __FUNCTION__,__LINE__, fmt, ##__VA_ARGS__)
#else
#define LOG_DEBUG(fmt, ...)
Expand Down
4 changes: 2 additions & 2 deletions src/net/MemoryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void* MemoryPool::Alloc(uint32_t size)
std::lock_guard<std::mutex> locker(_mutex);
if (_head != nullptr)
{
MemoryBlock* block = _head;
block = _head;
_head = _head->_next;
return ((char*)block + sizeof(MemoryBlock));
}
Expand Down Expand Up @@ -128,4 +128,4 @@ void MemoryManager::Free(void* ptr)
{
::free(block);
}
}
}
4 changes: 2 additions & 2 deletions src/net/RingBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class RingBuffer
{
public:
RingBuffer(unsigned capacity=60)
: _buffer(capacity)
, _capacity(capacity)
: _capacity(capacity)
, _numDatas(0)
, _buffer(capacity)
{ }

~RingBuffer() { }
Expand Down
2 changes: 1 addition & 1 deletion src/xop/RtspConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ using namespace std;

RtspConnection::RtspConnection(Rtsp *rtsp, TaskScheduler *taskScheduler, SOCKET sockfd)
: TcpConnection(taskScheduler, sockfd)
, _pTaskScheduler(taskScheduler)
, _pRtsp(rtsp)
, _pTaskScheduler(taskScheduler)
, _rtpChannelPtr(new Channel(sockfd))
, _rtspRequestPtr(new RtspRequest)
, _rtspResponsePtr(new RtspResponse)
Expand Down