精通
英语
和
开源
,
擅长
开发
与
培训
,
胸怀四海
第一信赖
主要类关系如下
-------- DynamicRTSPServer----------------RTSPServerSupportingHTTPStreaming----------------RTSPServer提供虚函数接口--------------------------------------Medium
-------- RTSPServer主要功能总结
testH264VideoStreamer.例子中创建了 RTSPServer* rtspServer,直接引用创建,说明其是全局变量,一个服务端对应一个
rtspServer->addServerMediaSession(sms);
play();开始播放
//void addServerMediaSession(ServerMediaSession* serverMediaSession) {--fServerMediaSessions是对应ServerMediaSession has表、全局只有一个,对应RTSPServer
// fServerMediaSessions->Add(sessionName, (void*)serverMediaSession); 这样我们了解到RTSPServer还提供了hash表等控制全局的数据结构
//}
RTSP 首先需建立 TCP 侦听 socket。可见于此函数:
[cpp]view plaincopyprint?
初始化流程大体如下
1、 RTSPServer::createNew(UsageEnvironment& env, Port ourPort,
int ourSocket = setUpOurSocket(env, ourPort); //----根据port 建立 TCP socket,设置缓冲区
}
{
env.taskScheduler().turnOnBackgroundReadHandling(fRTSPServerSocket,
(TaskScheduler::BackgroundHandlerProc*)&incomingConnectionHandlerRTSP, this);
}
void turnOnBackgroundReadHandling(int socketNum, BackgroundHandlerProc* handlerProc, void* clientData) {
setBackgroundHandling(socketNum, SOCKET_READABLE, handlerProc, clientData);-------------此函数是不是很熟悉!!!!,创立对应本地套接字处理函数incomingConnectionHandlerRTSP
}
{---------
(void)createNewClientConnection(clientSocket, clientAddr);//Create a new object for handling this RTSP connection:可以理解为
}
RTSPServer::RTSPClientConnection::RTSPClientConnection(RTSPServer& ourServer, int clientSocket, struct sockaddr_in clientAddr)
{
envir().taskScheduler().setBackgroundHandling(fClientInputSocket, SOCKET_READABLE|SOCKET_EXCEPTION,----与上面类似,此处设置incomingRequestHandler,接下来如果有数据就调用handleRequestBytes (TaskScheduler::BackgroundHandlerProc*)&incomingRequestHandler, this);
}
4、RTSPServer::RTSPClientConnection::handleRequestBytes(int newBytesRead) {---------------接下来正真处理客户端发来的数据,尼玛的这个路好漫长!!!!
{
parseRTSPRequestString(------) -------------------------------------------------------------------------解析rtsp的数据
handleCmd_DESCRIBE(------) -------------------------------------------------------------------------创立了ServerMediaSession,一
ServerMediaSession------------------------------------------------------------------------------------------------Medium
class ServerMediaSession: public Medium {
ServerMediaSubsession* fSubsessionsHead; -----------看到没,双链表,由此看出一个ServerMediaSession包含了多个ServerMediaSubsession
ServerMediaSubsession* fSubsessionsTail; ServerMediaSubsession是纯虚,抽象类
virtual void startStream(unsigned clientSessionId, void* streamToken, virtual void startStream(unsigned clientSessionId, void* streamToken,---)---------------是不是还没看懂,不要紧,接着看下面的主题
A 'ServerMediaSubsession' object that represents an existing
// 'RTPSink', rather than one that creates new 'RTPSink's on demand
class ServerMediaSubsession:
{
virtual void getStreamParameters(unsigned clientSessionId, // in
.................
...................
) = 0;
virtual void startStream(unsigned clientSessionId, void* streamToken,
..................
..................
void* serverRequestAlternativeByteHandlerClientData) = 0;
}
private:
friend class ServerMediaSession;
friend class ServerMediaSubsessionIterator;
ServerMediaSubsession* fNext;
unsigned fTrackNumber; // within an enclosing ServerMediaSession
char const* fTrackId;
}
class PassiveServerMediaSubsession: public ServerMediaSubsession
{
virtual char const* sdpLines();
virtual void getStreamParameters(unsigned clientSessionId,
.....................
.....................
void*& streamToken);
virtual void startStream(unsigned clientSessionId, void* streamToken,
....................
....................
void* serverRequestAlternativeByteHandlerClientData);
private:
RTPSink& fRTPSink;
RTCPInstance* fRTCPInstance;
HashTable* fClientRTCPSourceRecords; // indexed by client session id; used to implement RTCP "RR" handling
ServerMediaSession类功能总结:ServerMediaSession 代表的是一个静态的流, 也就是可以从它里面获取一个流的各种信息
ServerMediaSubsession类功能总结: