Live555源码分析@njzhujinhua[3]:ServerMediaSubsession与ServerMediaSession

[1]ServerMediaSubsession与ServerMediaSession
两者均继承自Medium,但他们的作用却不是像其名字般看上去是继承关系。
两者均可预先建立,也可在收到describe命令时根据请求而去查找文件并建立。在目前分析的testOnDemandRTSPServer.cpp中是启动时即预先建立的,如下
    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);

而在live555MediaServer.exe的程序实现则是通过DynamicRTSPServer::lookupServerMediaSession时若文件存在且SMS尚不存在时进行新建。本质大同小异。


看一下两个类的类图:
 

注意箭头所示。


另外看一下ServerMediaSession的主要成员:
class ServerMediaSession: public Medium {
//精简版
public:
  char* generateSDPDescription(); // based on the entire session
      // Note: The caller is responsible for freeing the returned string


  Boolean addSubsession(ServerMediaSubsession* subsession);
  unsigned numSubsessions() const { return fSubsessionCounter; }
  void deleteAllSubsessions();
    // Removes and deletes all subsessions added by "addSubsession()", returning us to an 'empty' state
    // Note: If you have already added this "ServerMediaSession" to a "RTSPServer" then, before calling this function,
    //   you must first close any client connections that use it,
    //   by calling "RTSPServer::closeAllClientSessionsForServerMediaSession()".


private:


  // Linkage fields:
  friend class ServerMediaSubsessionIterator;
  ServerMediaSubsession* fSubsessionsHead;
  ServerMediaSubsession* fSubsessionsTail;
  unsigned fSubsessionCounter;


  char* fStreamName;
  char* fInfoSDPString;
  char* fDescriptionSDPString;
  char* fMiscSDPLines;
  struct timeval fCreationTime;
  unsigned fReferenceCount;
  Boolean fDeleteWhenUnreferenced;
};
即可明白其主要维护的是一个流的描述信息, 及管理多个ServerMediaSubsession.

对于文件存储来说, 其对应于该文件信息, 而ServerMediaSubsession则对应于该媒体文件的多个track, 且由ServerMediaSession管理. 

代码中另一个看上去与Session有关的类RTSPClientSession则是与每个客户的rtsp连接相关联的。



[2]ServerMediaSubsession的实现
该类定义为抽象类. 在 Live555源码分析[1]:RTSPServer中有一副图提到过其具体子类的派生关系。如下是H264VideoFileServerMediaSubsession的一种

Live555源码分析@njzhujinhua[3]:ServerMediaSubsession与ServerMediaSession_第1张图片

先休息,后面继续针对OnDemandServerMediaSubsession等展开讨论下sdp的生成等细节

你可能感兴趣的:(Live555源码分析@njzhujinhua[3]:ServerMediaSubsession与ServerMediaSession)