Windows下编译live555

先下载live555的代码
http://www.live555.com/liveMedia/public/live555-latest.tar.gz

本文用的版本是2017-10-27的。本地安装的是Visual Studio 2015对代码进行解压缩,进入live目录,修改win32config文件。把TOOLS32改成VC的安装目录 D:\Program Files (x86)\Visual Studio 2015\VC

进入VS2015开发人员命令提示,运行live目录下的 genWindowsMakefiles 批处理,产生每个项目目录下的*.mak文件。然后依次进入各个项目的子目录进行编译

cd liveMedia
nmake /f liveMedia.mak
cd ../groupsock
nmake /f groupsock.mak
cd ../UsageEnvironment
nmake /f UsageEnvironment.mak
cd ../BasicUsageEnvironment
nmake /f BasicUsageEnvironment.mak

第一次编译过程中出现错误 liveMedia.mak(19) : fatal error U1052: 未找到文件“ntwin32.mak”。这是因为VS的高级版本中,这个文件不在VC的include目录下,而是在Windows SDK的include目录下。把 NtWin32.Mak、Win32.Mak 从
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include
拷贝到
D:\Program Files (x86)\Visual Studio 2015\VC\include
就可以正常编译了

编译完成后会在四个子目录中生成四个.lib文件

如果要编译可调试的debug版本静态库,先把win32config文件中的第二行“NODEBUG=1”注释掉。然后重新运行 genWindowsMakefiles以及之后的每一步。注意在每个目录下先运行一下
del *.obj
清除上次编译的结果

如果想将c运行库从多线程DLL(/MD)改成多线程(/MT),把win32config文件中
COMPILE_OPTS = $(INCLUDES) $(cdebug) $(cflags) $(cvarsdll) -I. -I"$(TOOLS32)\include"
一行改为
COMPILE_OPTS = $(INCLUDES) $(cdebug) $(cflags) $(cvarsmt) -I. -I"$(TOOLS32)\include"

然后可以在VC里面新建一个控制台项目,跑一下测试程序。这个测试程序是根据testOnDemandRTSPServer.cpp简化的

#include "liveMedia.hh"
#include "BasicUsageEnvironment.hh"

UsageEnvironment* env;

// To make the second and subsequent client for each stream reuse the same
// input stream as the first client (rather than playing the file from the
// start for each client), change the following "False" to "True":
Boolean reuseFirstSource = False;

static void announceStream(RTSPServer* rtspServer, ServerMediaSession* sms,
    char const* streamName, char const* inputFileName) {
    char* url = rtspServer->rtspURL(sms);
    UsageEnvironment& env = rtspServer->envir();
    env << "\n\"" << streamName << "\" stream, from the file \""
        << inputFileName << "\"\n";
    env << "Play this stream using the URL \"" << url << "\"\n";
    delete[] url;
}

int main()
{
    // Begin by setting up our usage environment:
    TaskScheduler* scheduler = BasicTaskScheduler::createNew();
    env = BasicUsageEnvironment::createNew(*scheduler);

    // Create the RTSP server:
    RTSPServer* rtspServer = RTSPServer::createNew(*env, 8554, NULL);
    if (rtspServer == NULL) {
        *env << "Failed to create RTSP server: " << env->getResultMsg() << "\n";
        exit(1);
    }

    char const* descriptionString
        = "Session streamed by \"testOnDemandRTSPServer\"";

    // A H.264 video elementary stream:
    {
        char const* streamName = "h264ESVideoTest";
        char const* inputFileName = "test.264";
        ServerMediaSession* sms
            = ServerMediaSession::createNew(*env, streamName, streamName,
                descriptionString);
        sms->addSubsession(H264VideoFileServerMediaSubsession
            ::createNew(*env, inputFileName, reuseFirstSource));
        rtspServer->addServerMediaSession(sms);

        announceStream(rtspServer, sms, streamName, inputFileName);
    }

    env->taskScheduler().doEventLoop(); // does not return

    return 0; // only to prevent compiler warning
}

要在工程中添加include目录
live\liveMedia\include
live\groupsock\include
live\UsageEnvironment\include
live\BasicUsageEnvironment\include

需要链接的库文件包括
BasicUsageEnvironment/libBasicUsageEnvironment.lib
groupsock/libgroupsock.lib
liveMedia/libliveMedia.lib
UsageEnvironment/libUsageEnvironment.lib
Ws2_32.lib

测试文件可以直接从live555官网下载,或者自己编一段264码流
http://www.live555.com/liveMedia/public/264/test.264

工程运行后会提示
"h264ESVideoTest" stream, from the file "test.264"
Play this stream using the URL "rtsp://192.168.14.20:8554/h264ESVideoTest"

用ffplay就可以播放了
ffplay rtsp://192.168.14.20:8554/h264ESVideoTest

或者测试rtsp over tcp
ffplay -rtsp_transport tcp rtsp://192.168.14.20:8554/h264ESVideoTest

你可能感兴趣的:(Windows下编译live555)