live555 基本套路

3,367次阅读
没有评论

点播模式

TaskScheduler* scheduler = BasicTaskScheduler::createNew();
BasicUsageEnvironment* env = BasicUsageEnvironment::createNew(*scheduler);
RTSPServer* rtspServer = RTSPServer::createNew(*env);
ServerMediaSession* sms = ServerMediaSession::createNew(*env);
sms->addSubsession(H264VideoFileServerMediaSubsession::createNew(*env, "test.264",false));
sms->addSubsession(ADTSAudioFileServerMediaSubsession::createNew(*env, "test.aac",false));
rtspServer->addServerMediaSession(sms);

组播模式

OutPacketBuffer::maxSize = xxx;
TaskScheduler* scheduler = BasicTaskScheduler::createNew();
BasicUsageEnvironment* env = BasicUsageEnvironment::createNew(*scheduler);

Groupsock *rtpGroupsock = new Groupsock(*env, destinationAddress, rtpPort, ttl);
Groupsock *rtcpGroupsock = new Groupsock(*env, destinationAddress, rtcpPort, ttl);
rtpGroupsock->multicastSendOnly();
rtcpGroupsock->multicastSendOnly();

RTPSink* rtpSink = H264VideoRTPSink::createNew(*env, rtpGroupsock, 96);   // 针对H264
RTCPInstance* rtcp = RTCPInstance::createNew(*env, &rtcpGroupsock,500/*码率 Kbps*/, CNAME/*HOST NAME*/,rtpSink, NULL /* we're a server */,True /* we're a SSM source */);
RTSPServer* rtspServer = RTSPServer::createNew(*env, 端口号,authDB(没有则NULL));
        if (rtspServer == NULL) {
            *env << "Failed to create RTSP server: " << env->getResultMsg() << "\n";
            exit(1);
        }
sms = ServerMediaSession::createNew(*env,"流名称", NULL, "流描述", True /*SSM*/);
sms->addSubsession(PassiveServerMediaSubsession::createNew(rtpSink, rtcp));
rtspServer->addServerMediaSession(sms);

// === 最主要的一步,数据源获取
FramedSource* liveSource = JappByteStreamLiveSource::createNew(*env, NULL, 0,this);
H264VideoStreamDiscreteFramer* source = H264VideoStreamDiscreteFramer::createNew(*env, liveSource);

rtpSink->startPlaying(*source, NULL, rtpSink);

env->taskScheduler().doEventLoop(); // does not return
正文完
 0
评论(没有评论)