阅读量:4
一、live555源码
下载:点击跳转
二、编译
1、往文件 config.linux里的 COMPILE_OPTS 添加以下两个参数 -DNO_STD_LIB 和 -DNO_OPENSSL=1 ,修改后如下:
COMPILE_OPTS = $(INCLUDES) -I/usr/local/include -I. -O2 -DNO_STD_LIB -DNO_OPENSSL=1 -DSOCKLEN_T=socklen_t -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 C = c C_COMPILER = cc C_FLAGS = $(COMPILE_OPTS) $(CPPFLAGS) $(CFLAGS) CPP = cpp CPLUSPLUS_COMPILER = c++ CPLUSPLUS_FLAGS = $(COMPILE_OPTS) -Wall -DBSD=1 $(CPPFLAGS) $(CXXFLAGS) OBJ = o LINK = c++ -o LINK_OPTS = -L. $(LDFLAGS) CONSOLE_LINK_OPTS = $(LINK_OPTS) LIBRARY_LINK = ar cr LIBRARY_LINK_OPTS = LIB_SUFFIX = a LIBS_FOR_CONSOLE_APPLICATION = -lssl -lcrypto LIBS_FOR_GUI_APPLICATION = EXE =
2、分别执行以下命令
./genMakefiles linux make clean make -j8 mkdir build make install PREFIX=$PWD/build /*************************** 以下用于交叉编译的,若是交叉编译不用输入上面的命令 ****************************/ //创建脚本文件,并输入以下信息 #!/bin/bash LIVE555_DIR=`pwd` cd $LIVE555_DIR INSTALL_DIR=$LIVE555_DIR/build mkdir -p $INSTALL_DIR #编译成静态库 export LDFLAGS="-static" #声明交叉编译器的路径 #export PATH=/opt/arm-gcc/bin/:$PATH ./genMakefiles armlinux make -j$(nproc) CROSS_COMPILE=aarch64-linux-gnu- make install PREFIX=$INSTALL_DIR CROSS_COMPILE=aarch64-linux-gnu-
三、搭建rtsp服务器
1、利用qt creator创建工程,在 *.pro 文件添加 live555 库和头文件的路径(注意库的顺序)
INCLUDEPATH *= /home/gui/live/build/include/liveMedia/ INCLUDEPATH *= /home/gui/live/build/include/BasicUsageEnvironment/ INCLUDEPATH *= /home/gui/live/build/include/groupsock INCLUDEPATH *= /home/gui/live/build/include/UsageEnvironment/ LIBS += -L/home/gui/live/build/lib/ -lliveMedia \ -lBasicUsageEnvironment -lgroupsock -lUsageEnvironment
2、服务器代码实现如下(参考源码的testOnDemandRTSPServer.cpp文件例程):
#include <QCoreApplication> #include "liveMedia.hh" #include "BasicUsageEnvironment.hh" #include "InputFile.hh" #include "BasicHashTable.hh" #include <GroupsockHelper.hh> #include <iostream> static void announceURL(RTSPServer* rtspServer, ServerMediaSession* sms) { if (rtspServer == NULL || sms == NULL) return; // sanity check UsageEnvironment& env = rtspServer->envir(); env << "Play this stream using the URL "; if (weHaveAnIPv4Address(env)) { char* url = rtspServer->ipv4rtspURL(sms); env << "\"" << url << "\""; delete[] url; if (weHaveAnIPv6Address(env)) env << " or "; } if (weHaveAnIPv6Address(env)) { char* url = rtspServer->ipv6rtspURL(sms); env << "\"" << url << "\""; delete[] url; } env << "\n"; } static void announceStream(RTSPServer* rtspServer, ServerMediaSession* sms, char const* streamName, char const* inputFileName) { UsageEnvironment& env = rtspServer->envir(); env << "\n\"" << streamName << "\" stream, from the file \"" << inputFileName << "\"\n"; announceURL(rtspServer, sms); } int main(int argc, char *argv[]) { // Begin by setting up our usage environment: TaskScheduler* scheduler = BasicTaskScheduler::createNew(); UsageEnvironment* env = BasicUsageEnvironment::createNew(*scheduler); //设置RTP数据的最大传输大小 OutPacketBuffer::maxSize = 1000000; //创建一个rtsp的服务 RTSPServer* rtspServer = RTSPServer::createNew(*env, 8554); if (rtspServer == NULL) { *env << "Failed to create RTSP server: " << env->getResultMsg() << "\n"; exit(1); } char const* descriptionString = "Session streamed by \"LiveRTSPServer\""; Boolean reuseFirstSource = true; // A H.264 video elementary stream: { char const* streamName = "h264ESVideoTest"; char const* inputFileName = "test.264";//hevc //创建一个会话 ServerMediaSession* sms = ServerMediaSession::createNew(*env, streamName, streamName, descriptionString); //管理之前,需要先注册一个实例,实现里边所有的管理function,将来给rtsp服务调度。 sms->addSubsession(H264VideoFileServerMediaSubsession ::createNew(*env, inputFileName, reuseFirstSource)); rtspServer->addServerMediaSession(sms); //将ServerMediaSession添加到rstp服务 announceStream(rtspServer, sms, streamName, inputFileName); } // A MPEG-1 or 2 audio+video program stream: { char const* streamName = "mpeg1or2AudioVideoTest"; char const* inputFileName = "test.mpg"; // NOTE: This *must* be a Program Stream; not an Elementary Stream ServerMediaSession* sms = ServerMediaSession::createNew(*env, streamName, streamName, descriptionString); MPEG1or2FileServerDemux* demux = MPEG1or2FileServerDemux::createNew(*env, inputFileName, reuseFirstSource); sms->addSubsession(demux->newVideoServerMediaSubsession(false)); sms->addSubsession(demux->newAudioServerMediaSubsession()); rtspServer->addServerMediaSession(sms); announceStream(rtspServer, sms, streamName, inputFileName); } //开始运行服务 env->taskScheduler().doEventLoop(); // does not return return 0; }
通过ffplay播放,测试效果如下:
demo下载:点击跳转
创作不易,打赏一下呗。。