void BGM_PlugIn::Deactivate() { CAMutex::Locker theLocker(mMutex); BGM_Object::Deactivate(); // TODO: //_RemoveAllDevices(); }
/* 删去并返回当前队列中锚点元素的前一个队列元素 */ OSQueueElem* OSQueue_Blocking::DeQueue() { OSMutexLocker theLocker(&fMutex); /* 用到OSQueue::DeQueue() */ OSQueueElem* retval = fQueue.DeQueue(); return retval; }
bool WatcherMgr::RegWatcher(SharedPtr<WatcherBase> pWatcher) { if (pWatcher.isNull()){ LOG_ERROR("WatcherMgr Register Handler But The Arg Handler Is NULL!"); return false; } UInt32 connID = WatcherMgr::GetNextConnId(); pWatcher->SetConnID(connID); if(pWatcher->Open() != 0){ LOG_ERROR("WatcherMgr Register Handler Error When Open It!"); return false; } if(pWatcher->GetServerID() == 0) { OSMutexLocker theLocker(&m_connIDMutex); if (m_ConnID2WatcherMap.find(connID) != m_ConnID2WatcherMap.end()) { LOG_DEBUG("The connection:%d,already exist!",connID); return false; } m_ConnID2WatcherMap[connID] = pWatcher; LOG_DEBUG("WatcherMgr::RegWatcher connID:%u fd:%d", connID, pWatcher->GetHandle()); }else{ return gCliConnMgr::instance()->AddCliConn(pWatcher.cast<WatcherCliConn>()); } return true; }
WatcherMgr::~WatcherMgr() { OSMutexLocker theLocker(&m_connIDMutex); if(m_FdToConnID != NULL) delete []m_FdToConnID;//no use m_ConnID2WatcherMap.clear(); }
void OSQueue_Blocking::EnQueue(OSQueueElem* obj) { { OSMutexLocker theLocker(&fMutex); fQueue.EnQueue(obj); } fCond.Signal(); }
/* 将入参加入当前队列,并传信 */ void OSQueue_Blocking::EnQueue(OSQueueElem* obj) { { /* 获取互斥锁 */ OSMutexLocker theLocker(&fMutex); /* 将当前入参加入描点队列元素后 */ fQueue.EnQueue(obj); } /* 参见OSCond.h,等同于::SetEvent(fCondition) */ /* 发信号通知外部条件已改变 */ fCond.Signal(); }
void WatcherNoticePipe::ProcessNotices() { OSMutexLocker theLocker(&m_Mutex); while(m_noticeHead != NULL) { if( m_noticeCB[m_noticeHead->type] != NULL) m_noticeCB[m_noticeHead->type](m_noticeHead); Notice* next = m_noticeHead->next; delete m_noticeHead; m_noticeHead = next; } }
WatcherNoticePipe::~WatcherNoticePipe() { Socket::Close(m_readFD); Socket::Close(m_writeFD); OSMutexLocker theLocker(&m_Mutex); while(m_noticeHead != NULL) { Notice* next = m_noticeHead->next; delete m_noticeHead; m_noticeHead = next; } }
bool WatcherMgr::RemoveWatcher(UInt32 connID) { OSMutexLocker theLocker(&m_connIDMutex); std::map<UInt32, SharedPtr<WatcherBase> >::iterator it = m_ConnID2WatcherMap.find(connID); if (it == m_ConnID2WatcherMap.end()) { LOG_DEBUG("Can't Find Watcher By connID:%u,when Remove Watcher!", connID); return false; } m_ConnID2WatcherMap.erase(it); LOG_DEBUG("WatcherMgr::RemoveWatcher connID:%u", connID); return true; }
void OSQueue::EnQueue(OSQueueElem* elem) { OSMutexLocker theLocker(&fMutex); Assert(elem != NULL); if (elem->fQueue == this) return; Assert(elem->fQueue == NULL); elem->fNext = fSentinel.fNext; elem->fPrev = &fSentinel; elem->fQueue = this; fSentinel.fNext->fPrev = elem; fSentinel.fNext = elem; fLength++; }
SharedPtr<WatcherBase> WatcherMgr::GetWatcher(UInt32 connID) { OSMutexLocker theLocker(&m_connIDMutex); SharedPtr<WatcherBase> watcher; std::map<UInt32, SharedPtr<WatcherBase> >::iterator it = m_ConnID2WatcherMap.find(connID); if (it == m_ConnID2WatcherMap.end()) { LOG_TRACE("Can't Find watcher In WatcherMgr By ConnID:%d",connID); return watcher; } watcher = it->second; LOG_DEBUG("Find watcher In WatcherMgr By ConnID:%d",connID); return watcher; }
void OSQueue::Remove(OSQueueElem* elem) { OSMutexLocker theLocker(&fMutex); Assert(elem != NULL); Assert(elem != &fSentinel); if (elem->fQueue == this) { elem->fNext->fPrev = elem->fPrev; elem->fPrev->fNext = elem->fNext; elem->fQueue = NULL; fLength--; } }
OSQueueElem* OSQueue_Blocking::DeQueueBlocking(OSThread* inCurThread, SInt32 inTimeoutInMilSecs) { OSMutexLocker theLocker(&fMutex); #ifdef __Win32_ if (fQueue.GetLength() == 0) { fCond.Wait(&fMutex, inTimeoutInMilSecs); return NULL; } #else if (fQueue.GetLength() == 0) fCond.Wait(&fMutex, inTimeoutInMilSecs); #endif OSQueueElem* retval = fQueue.DeQueue(); return retval; }
OSQueueElem* OSQueue::DeQueue() { OSMutexLocker theLocker(&fMutex); if (fLength > 0) { OSQueueElem* elem = fSentinel.fPrev; Assert(fSentinel.fPrev != &fSentinel); elem->fPrev->fNext = &fSentinel; fSentinel.fPrev = elem->fPrev; elem->fQueue = NULL; fLength--; return elem; } return NULL; }
/* 当队列长度为0时,仅让当前线程阻塞,超时等待指定时间后,返回NULL;否则,否则删去并返回当前队列中锚点元素的前一个队列元素 */ OSQueueElem* OSQueue_Blocking::DeQueueBlocking(OSThread* inCurThread, SInt32 inTimeoutInMilSecs) { OSMutexLocker theLocker(&fMutex); #ifdef __Win32_ /* 当当前队列长度为0,则仅让当前线程阻塞,超时等待,并返回空值 */ if (fQueue.GetLength() == 0) { fCond.Wait(&fMutex, inTimeoutInMilSecs); return NULL; } #else if (fQueue.GetLength() == 0) fCond.Wait(&fMutex, inTimeoutInMilSecs); #endif /* 否则删去并返回当前队列中锚点元素的前一个队列元素 */ OSQueueElem* retval = fQueue.DeQueue(); return retval; }
bool WatcherNoticePipe::AddNotice(Notice* pNotice) { OSMutexLocker theLocker(&m_Mutex); if(!pNotice){ LOG_ERROR("The Notice Is NULL!"); return false; } if (1 != ::write(m_writeFD, "n", 1)){ LOG_ERROR("Failure to write msg to notice pipe, errno=%d", errno); delete pNotice ; return false; } else { pNotice->next = m_noticeHead; m_noticeHead = pNotice; } return true; }
RTPSession::~RTPSession() { // Delete all the streams RTPStream** theStream = NULL; UInt32 theLen = 0; /* 假如预设值能打印RUDP信息 */ if (QTSServerInterface::GetServer()->GetPrefs()->GetReliableUDPPrintfsEnabled()) { SInt32 theNumLatePacketsDropped = 0;/* 丢弃延迟包个数 */ SInt32 theNumResends = 0; /* 重传包个数 */ /* 遍历该RTPSession的每个RTPStream,计算丢弃的过时包总数和重传包总数 */ for (int x = 0; this->GetValuePtr(qtssCliSesStreamObjects, x, (void**)&theStream, &theLen) == QTSS_NoErr; x++) { Assert(theStream != NULL); Assert(theLen == sizeof(RTPStream*)); if (*theStream != NULL) { /* 计算丢弃的过时包总数 */ theNumLatePacketsDropped += (*theStream)->GetStalePacketsDropped(); /* 得到重传包总数 */ theNumResends += (*theStream)->GetResender()->GetNumResends(); } } /* 得到客户端请求播放文件的Full URL */ char* theURL = NULL; (void)this->GetValueAsString(qtssCliSesFullURL, 0, &theURL); Assert(theURL != NULL); /* 获得RTPBandwidthTracker类 */ RTPBandwidthTracker* tracker = this->GetBandwidthTracker(); qtss_printf("Client complete. URL: %s.\n",theURL); qtss_printf("Max congestion window: %ld. Min congestion window: %ld. Avg congestion window: %ld\n", tracker->GetMaxCongestionWindowSize(), tracker->GetMinCongestionWindowSize(), tracker->GetAvgCongestionWindowSize()); qtss_printf("Max RTT: %ld. Min RTT: %ld. Avg RTT: %ld\n", tracker->GetMaxRTO(), tracker->GetMinRTO(), tracker->GetAvgRTO()); qtss_printf("Num resends: %ld. Num skipped frames: %ld. Num late packets dropped: %ld\n", theNumResends, this->GetFramesSkipped(), theNumLatePacketsDropped); delete [] theURL; } /* 遍历该RTPSession的每个RTPStream,逐一删除它们 */ for (int x = 0; this->GetValuePtr(qtssCliSesStreamObjects, x, (void**)&theStream, &theLen) == QTSS_NoErr; x++) { Assert(theStream != NULL); Assert(theLen == sizeof(RTPStream*)); if (*theStream != NULL) delete *theStream; } /* 获取服务器接口类,逐一将该RTPSession从qtssSvrClientSessions属性中删去 */ QTSServerInterface* theServer = QTSServerInterface::GetServer(); { OSMutexLocker theLocker(theServer->GetMutex()); RTPSession** theSession = NULL; // Remove this session from the qtssSvrClientSessions attribute UInt32 y = 0; for ( ; y < theServer->GetNumRTPSessions(); y++) { QTSS_Error theErr = theServer->GetValuePtr(qtssSvrClientSessions, y, (void**)&theSession, &theLen, true); Assert(theErr == QTSS_NoErr); if (*theSession == this) { theErr = theServer->RemoveValue(qtssSvrClientSessions, y, QTSSDictionary::kDontObeyReadOnly); break; } } Assert(y < theServer->GetNumRTPSessions()); theServer->AlterCurrentRTPSessionCount(-1); if (!fIsFirstPlay) // The session was started playing (the counter ignores additional pause-play changes while session is active) theServer->AlterRTPPlayingSessions(-1); } //we better not be in the RTPSessionMap anymore! #if DEBUG Assert(!fRTPMapElem.IsInTable()); StrPtrLen theRTSPSessionID(fRTSPSessionIDBuf,sizeof(fRTSPSessionIDBuf)); /* 从RTPSession Map中删去它们 */ OSRef* theRef = QTSServerInterface::GetServer()->GetRTPSessionMap()->Resolve(&theRTSPSessionID); Assert(theRef == NULL); #endif }