SInt64 ReflectorSessionCheckTask::Run() { OSRefTable* reflectorSessionMap = QTSServerInterface::GetServer()->GetReflectorSessionMap(); OSMutexLocker locker(reflectorSessionMap->GetMutex()); SInt64 sNowTime = OS::Milliseconds(); for (OSRefHashTableIter theIter(reflectorSessionMap->GetHashTable()); !theIter.IsDone(); theIter.Next()) { OSRef* theRef = theIter.GetCurrent(); ReflectorSession* theSession = (ReflectorSession*)theRef->GetObject(); SInt64 sCreateTime = theSession->GetInitTimeMS(); if( (theSession->GetNumOutputs() == 0) && (sNowTime-sCreateTime >= 20*1000) ) { QTSS_RoleParams theParams; theParams.easyFreeStreamParams.inStreamName = theSession->GetStreamName(); UInt32 numModules = QTSServerInterface::GetNumModulesInRole(QTSSModule::kEasyCMSFreeStreamRole); for ( UInt32 currentModule=0;currentModule < numModules; currentModule++) { qtss_printf("没有客户端观看当前转发媒体\n"); QTSSModule* theModule = QTSServerInterface::GetModule(QTSSModule::kEasyCMSFreeStreamRole, currentModule); (void)theModule->CallDispatch(Easy_CMSFreeStream_Role, &theParams); } } } return 30*1000;//30s }
void* QTSSCallbacks::Easy_GetRTSPPushSessions() { OSRefTable* reflectorSessionMap = QTSServerInterface::GetServer()->GetReflectorSessionMap(); EasyMsgSCRTSPPushSessionListACK ack; ack.SetHeaderValue(EASY_TAG_VERSION, "1.0"); ack.SetHeaderValue(EASY_TAG_CSEQ, "1"); UInt32 uIndex= 0; OSMutexLocker locker(reflectorSessionMap->GetMutex()); for (OSRefHashTableIter theIter(reflectorSessionMap->GetHashTable()); !theIter.IsDone(); theIter.Next()) { OSRef* theRef = theIter.GetCurrent(); ReflectorSession* theSession = (ReflectorSession*)theRef->GetObject(); EasyDarwinRTSPSession session; session.index = uIndex; char* fullRequestURL = NULL; RTPSession* clientSession = (RTPSession*) theSession->GetBroadcasterSession(); if(clientSession == NULL) continue; clientSession->GetValueAsString(qtssCliSesFullURL,0,&fullRequestURL); session.Url = fullRequestURL; session.Name = theSession->GetSessionName(); session.numOutputs = theSession->GetNumOutputs(); ack.AddSession(session); uIndex++; } char count[16] = { 0 }; sprintf(count,"%d", uIndex); ack.SetBodyValue(EASY_TAG_SESSION_COUNT, count); string msg = ack.GetMsg(); UInt32 theMsgLen = strlen(msg.c_str()); char* retMsg = new char[theMsgLen+1]; retMsg[theMsgLen] = '\0'; strncpy(retMsg, msg.c_str(), strlen(msg.c_str())); return (void*)retMsg; }