QTSS_Error EasyHLSClose(Easy_HLSClose_Params* inParams) { OSRefTable* sHLSSessionMap = QTSServerInterface::GetServer()->GetHLSSessionMap(); OSMutexLocker locker (sHLSSessionMap->GetMutex()); //首先查找Map里面是否已经有了对应的流 StrPtrLen streamName(inParams->inStreamName); OSRef* clientSesRef = sHLSSessionMap->Resolve(&streamName); if(NULL == clientSesRef) return QTSS_RequestFailed; EasyHLSSession* session = (EasyHLSSession*)clientSesRef->GetObject(); session->HLSSessionRelease(); sHLSSessionMap->Release(session->GetRef()); if (session->GetRef()->GetRefCount() == 0) { qtss_printf("EasyHLSModule.cpp:EasyHLSClose UnRegister and delete session =%p refcount=%"_U32BITARG_"\n", session->GetRef(), session->GetRef()->GetRefCount() ) ; sHLSSessionMap->UnRegister(session->GetRef()); delete session; } return QTSS_NoErr; }
QTSS_Error EasyHLSOpen(Easy_HLSOpen_Params* inParams) { OSRefTable* sHLSSessionMap = QTSServerInterface::GetServer()->GetHLSSessionMap(); OSMutexLocker locker (sHLSSessionMap->GetMutex()); EasyHLSSession* session = NULL; //首先查找MAP里面是否已经有了对应的流 StrPtrLen streamName(inParams->inStreamName); OSRef* clientSesRef = sHLSSessionMap->Resolve(&streamName); if(clientSesRef != NULL) { session = (EasyHLSSession*)clientSesRef->GetObject(); } else { session = NEW EasyHLSSession(&streamName); OS_Error theErr = sHLSSessionMap->Register(session->GetRef()); Assert(theErr == QTSS_NoErr); //增加一次对RelaySession的无效引用,后面会统一释放 OSRef* debug = sHLSSessionMap->Resolve(&streamName); Assert(debug == session->GetRef()); } //到这里,肯定是有一个EasyHLSSession可用的 session->HLSSessionStart(inParams->inRTSPUrl, inParams->inTimeout); if(inParams->outHLSUrl) qtss_sprintf(inParams->outHLSUrl,"%s",session->GetHLSURL()); sHLSSessionMap->Release(session->GetRef()); return QTSS_NoErr; }
char* GetHLSUrl(char* inSessionName) { OSRefTable* sHLSSessionMap = QTSServerInterface::GetServer()->GetHLSSessionMap(); OSMutexLocker locker (sHLSSessionMap->GetMutex()); char* hlsURL = NULL; //首先查找Map里面是否已经有了对应的流 StrPtrLen streamName(inSessionName); OSRef* clientSesRef = sHLSSessionMap->Resolve(&streamName); if(NULL == clientSesRef) return NULL; EasyHLSSession* session = (EasyHLSSession*)clientSesRef->GetObject(); hlsURL = session->GetHLSURL(); sHLSSessionMap->Release(session->GetRef()); return hlsURL; }