上一篇暫時驗證了RV1126交叉編譯live555的正確編譯,因爲本人想用RV1126做個一端推流另一端拉流的東西,但是尷尬的是手上只有一個RV1126開發板,想驗證成功了再向company申請買,因此出了這麼個想法,發送端暫時用ubuntu系統跑live555推流,這樣我可以在板子上驗證自己改寫的接受端DEMO.
那麼開始
新建個UbuntuTest文件夾把live555-latest.tar.gz和openssl-1.1.1v.tar.gz扔進去,隨後還是先搞openssl,解壓,進入openssl-1.1.1v,命令行,
./Configure linux-x86_64 --prefix=/home/alientek/UbuntuTest/openssl-build
看了一眼我用的是Ubuntu 20.04.5 LTS,64位,那沒錯了,--prefix後接自己想安裝庫的文件位置,隨後成功生產個Makefile,接着
make
make test
make install
openssl-build文件夾裏安裝好了,將他拷貝進live555解壓後的文件夾live裏,把文件夾名改了openssl,然後處理live
修改config.linux文件
COMPILE_OPTS = $(INCLUDES) -I/home/alientek/UbuntuTest/live/openssl/include/openssl -I. -O2 -DSOCKLEN_T=socklen_t -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DNO_STD_LIB
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 = -L/home/alientek/UbuntuTest/live/openssl/lib -lssl -lcrypto
LIBS_FOR_GUI_APPLICATION =
EXE =
COMPILE_OPTS和LIBS_FOR_CONSOLE_APPLICATION選項裏改寫自己的頭文件和lib的位置,COMPILE_OPTS最後加個-DNO_STD_LIB,然後命令行
./genMakefiles linux
會生成個Makefile,繼續命令行
make
編譯成功,找個測試程序測一下,testProgs裏有個testH264VideoStreamer
#include <liveMedia.hh>
#include <BasicUsageEnvironment.hh>
#include "announceURL.hh"
#include <GroupsockHelper.hh>
UsageEnvironment* env;
char const* inputFileName = "test.264";
H264VideoStreamFramer* videoSource;
RTPSink* videoSink;
void play(); // forward
int main(int argc, char** argv) {
// Begin by setting up our usage environment:
TaskScheduler* scheduler = BasicTaskScheduler::createNew();
env = BasicUsageEnvironment::createNew(*scheduler);
// Create 'groupsocks' for RTP and RTCP:
struct sockaddr_storage destinationAddress;
destinationAddress.ss_family = AF_INET;
((struct sockaddr_in&)destinationAddress).sin_addr.s_addr = chooseRandomIPv4SSMAddress(*env);
// Note: This is a multicast address. If you wish instead to stream
// using unicast, then you should use the "testOnDemandRTSPServer"
// test program - not this test program - as a model.
const unsigned short rtpPortNum = 18888;
const unsigned short rtcpPortNum = rtpPortNum+1;
const unsigned char ttl = 255;
const Port rtpPort(rtpPortNum);
const Port rtcpPort(rtcpPortNum);
Groupsock rtpGroupsock(*env, destinationAddress, rtpPort, ttl);
rtpGroupsock.multicastSendOnly(); // we're a SSM source
Groupsock rtcpGroupsock(*env, destinationAddress, rtcpPort, ttl);
rtcpGroupsock.multicastSendOnly(); // we're a SSM source
// Create a 'H264 Video RTP' sink from the RTP 'groupsock':
OutPacketBuffer::maxSize = 100000;
videoSink = H264VideoRTPSink::createNew(*env, &rtpGroupsock, 96);
// Create (and start) a 'RTCP instance' for this RTP sink:
const unsigned estimatedSessionBandwidth = 500; // in kbps; for RTCP b/w share
const unsigned maxCNAMElen = 100;
unsigned char CNAME[maxCNAMElen+1];
gethostname((char*)CNAME, maxCNAMElen);
CNAME[maxCNAMElen] = '\0'; // just in case
RTCPInstance* rtcp
= RTCPInstance::createNew(*env, &rtcpGroupsock,
estimatedSessionBandwidth, CNAME,
videoSink, NULL /* we're a server */,
True /* we're a SSM source */);
// Note: This starts RTCP running automatically
RTSPServer* rtspServer = RTSPServer::createNew(*env, 8554);
if (rtspServer == NULL) {
*env << "Failed to create RTSP server: " << env->getResultMsg() << "\n";
exit(1);
}
ServerMediaSession* sms
= ServerMediaSession::createNew(*env, "testStream", inputFileName,
"Session streamed by \"testH264VideoStreamer\"",
True /*SSM*/);
sms->addSubsession(PassiveServerMediaSubsession::createNew(*videoSink, rtcp));
rtspServer->addServerMediaSession(sms);
announceURL(rtspServer, sms);
// Start the streaming:
*env << "Beginning streaming...\n";
play();
env->taskScheduler().doEventLoop(); // does not return
return 0; // only to prevent compiler warning
}
void afterPlaying(void* /*clientData*/) {
*env << "...done reading from file\n";
videoSink->stopPlaying();
Medium::close(videoSource);
// Note that this also closes the input file that this source read from.
// Start playing once again:
play();
}
void play() {
// Open the input file as a 'byte-stream file source':
ByteStreamFileSource* fileSource
= ByteStreamFileSource::createNew(*env, inputFileName);
if (fileSource == NULL) {
*env << "Unable to open file \"" << inputFileName
<< "\" as a byte-stream file source\n";
exit(1);
}
FramedSource* videoES = fileSource;
// Create a framer for the Video Elementary Stream:
videoSource = H264VideoStreamFramer::createNew(*env, videoES);
// Finally, start playing:
*env << "Beginning to read from file...\n";
videoSink->startPlaying(*videoSource, afterPlaying, videoSink);
}
就他了,如果沒有test.264文件,去live555下載區下載,把testH264VideoStreamer執行程序和test.264放在一起,
./testH264VideoStreamer
跑起來,本人非要再開個電腦搭個局域網,vlc播放器打開網絡串流
接收到了.
還有個testH265VideoStreamer.cpp,有空再試試.