📄 h323neg.cxx
字号:
{ replyTimer.Stop(); if (channel != NULL) { channel->CleanUpOnTermination(); delete channel; channel = NULL; } state = e_Released;}H323Channel * H245NegLogicalChannel::GetChannel(){ return channel;}#if PTRACINGconst char * const H245NegLogicalChannel::StateNames[] = { "Released", "AwaitingEstablishment", "Established", "AwaitingRelease", "AwatingConfirmation", "AwaitingResponse"};#endif/////////////////////////////////////////////////////////////////////////////H245NegLogicalChannels::H245NegLogicalChannels(H323EndPoint & end, H323Connection & conn) : H245Negotiator(end, conn), lastChannelNumber(100, FALSE){}void H245NegLogicalChannels::Add(H323Channel & channel){ mutex.Wait(); channels.SetAt(channel.GetNumber(), new H245NegLogicalChannel(endpoint, connection, channel)); mutex.Signal();}BOOL H245NegLogicalChannels::Open(const H323Capability & capability, unsigned sessionID){ mutex.Wait(); lastChannelNumber++; H245NegLogicalChannel * negChan = new H245NegLogicalChannel(endpoint, connection, lastChannelNumber); channels.SetAt(lastChannelNumber, negChan); mutex.Signal(); return negChan->Open(capability, sessionID);}BOOL H245NegLogicalChannels::Close(unsigned channelNumber, BOOL fromRemote){ H245NegLogicalChannel * chan = FindNegLogicalChannel(channelNumber, fromRemote); if (chan != NULL) return chan->Close(); return connection.OnControlProtocolError(H323Connection::e_LogicalChannel, "Close unknown");}BOOL H245NegLogicalChannels::HandleOpen(const H245_OpenLogicalChannel & pdu){ H323ChannelNumber chanNum(pdu.m_forwardLogicalChannelNumber, TRUE); H245NegLogicalChannel * chan; mutex.Wait(); if (channels.Contains(chanNum)) chan = &channels[chanNum]; else { chan = new H245NegLogicalChannel(endpoint, connection, chanNum); channels.SetAt(chanNum, chan); } mutex.Signal(); return chan->HandleOpen(pdu);}BOOL H245NegLogicalChannels::HandleOpenAck(const H245_OpenLogicalChannelAck & pdu){ H245NegLogicalChannel * chan = FindNegLogicalChannel(pdu.m_forwardLogicalChannelNumber, FALSE); if (chan != NULL) return chan->HandleOpenAck(pdu); return connection.OnControlProtocolError(H323Connection::e_LogicalChannel, "Ack unknown");}BOOL H245NegLogicalChannels::HandleOpenConfirm(const H245_OpenLogicalChannelConfirm & pdu){ H245NegLogicalChannel * chan = FindNegLogicalChannel(pdu.m_forwardLogicalChannelNumber, TRUE); if (chan != NULL) return chan->HandleOpenConfirm(pdu); return connection.OnControlProtocolError(H323Connection::e_LogicalChannel, "Confirm unknown");}BOOL H245NegLogicalChannels::HandleReject(const H245_OpenLogicalChannelReject & pdu){ H245NegLogicalChannel * chan = FindNegLogicalChannel(pdu.m_forwardLogicalChannelNumber, FALSE); if (chan != NULL) return chan->HandleReject(pdu); return connection.OnControlProtocolError(H323Connection::e_LogicalChannel, "Reject unknown");}BOOL H245NegLogicalChannels::HandleClose(const H245_CloseLogicalChannel & pdu){ H245NegLogicalChannel * chan = FindNegLogicalChannel(pdu.m_forwardLogicalChannelNumber, TRUE, TRUE); if (chan != NULL) { BOOL ok = chan->HandleClose(pdu); mutex.Signal(); return ok; } return connection.OnControlProtocolError(H323Connection::e_LogicalChannel, "Close unknown");}BOOL H245NegLogicalChannels::HandleCloseAck(const H245_CloseLogicalChannelAck & pdu){ H245NegLogicalChannel * chan = FindNegLogicalChannel(pdu.m_forwardLogicalChannelNumber, FALSE); if (chan != NULL) return chan->HandleCloseAck(pdu); return connection.OnControlProtocolError(H323Connection::e_LogicalChannel, "Close Ack unknown");}BOOL H245NegLogicalChannels::HandleRequestClose(const H245_RequestChannelClose & pdu){ H245NegLogicalChannel * chan = FindNegLogicalChannel(pdu.m_forwardLogicalChannelNumber, FALSE); if (chan != NULL) return chan->HandleRequestClose(pdu); return connection.OnControlProtocolError(H323Connection::e_LogicalChannel, "Request Close unknown");}BOOL H245NegLogicalChannels::HandleRequestCloseAck(const H245_RequestChannelCloseAck & pdu){ H245NegLogicalChannel * chan = FindNegLogicalChannel(pdu.m_forwardLogicalChannelNumber, TRUE); if (chan != NULL) return chan->HandleRequestCloseAck(pdu); return connection.OnControlProtocolError(H323Connection::e_LogicalChannel, "Request Close Ack unknown");}BOOL H245NegLogicalChannels::HandleRequestCloseReject(const H245_RequestChannelCloseReject & pdu){ H245NegLogicalChannel * chan = FindNegLogicalChannel(pdu.m_forwardLogicalChannelNumber, TRUE); if (chan != NULL) return chan->HandleRequestCloseReject(pdu); return connection.OnControlProtocolError(H323Connection::e_LogicalChannel, "Request Close Reject unknown");}BOOL H245NegLogicalChannels::HandleRequestCloseRelease(const H245_RequestChannelCloseRelease & pdu){ H245NegLogicalChannel * chan = FindNegLogicalChannel(pdu.m_forwardLogicalChannelNumber, FALSE); if (chan != NULL) return chan->HandleRequestCloseRelease(pdu); return connection.OnControlProtocolError(H323Connection::e_LogicalChannel, "Request Close Release unknown");}H323ChannelNumber H245NegLogicalChannels::GetNextChannelNumber(){ PWaitAndSignal wait(mutex); lastChannelNumber++; return lastChannelNumber;}H323Channel * H245NegLogicalChannels::GetChannelAt(PINDEX i){ mutex.Wait(); H323Channel * chan = channels.GetDataAt(i).GetChannel(); mutex.Signal(); return chan;}H323Channel * H245NegLogicalChannels::FindChannel(unsigned channelNumber, BOOL fromRemote){ PWaitAndSignal wait(mutex); H323ChannelNumber chanNum(channelNumber, fromRemote); if (channels.Contains(chanNum)) return channels[chanNum].GetChannel(); return NULL;}H245NegLogicalChannel & H245NegLogicalChannels::GetNegLogicalChannelAt(PINDEX i){ PWaitAndSignal wait(mutex); return channels.GetDataAt(i);}H245NegLogicalChannel * H245NegLogicalChannels::FindNegLogicalChannel(unsigned channelNumber, BOOL fromRemote, BOOL leaveLocked){ H323ChannelNumber chanNum(channelNumber, fromRemote); H245NegLogicalChannel * channel = NULL; mutex.Wait(); if (channels.Contains(chanNum)) channel = &channels[chanNum]; if (channel != NULL && leaveLocked) return channel; mutex.Signal(); return channel;}H323Channel * H245NegLogicalChannels::FindChannelBySession(unsigned rtpSessionId, BOOL fromRemote){ PWaitAndSignal wait(mutex); PINDEX i; H323Channel::Directions desiredDirection = fromRemote ? H323Channel::IsReceiver : H323Channel::IsTransmitter; for (i = 0; i < GetSize(); i++) { H323Channel * channel = channels.GetDataAt(i).GetChannel(); if ((channel != NULL) && (channel->GetSessionID() == rtpSessionId) && (channel->GetDirection() == desiredDirection)) return channel; } return NULL;}void H245NegLogicalChannels::RemoveAll(){ PWaitAndSignal wait(mutex); channels.RemoveAll();}/////////////////////////////////////////////////////////////////////////////H245NegRequestMode::H245NegRequestMode(H323EndPoint & end, H323Connection & conn) : H245Negotiator(end, conn){ awaitingResponse = FALSE; inSequenceNumber = UINT_MAX; outSequenceNumber = 0;}BOOL H245NegRequestMode::StartRequest(){ PTRACE(3, "H245\tStarted request mode: outSeq=" << outSequenceNumber << (awaitingResponse ? " awaitingResponse" : " idle")); // Initiate a mode request outSequenceNumber = (outSequenceNumber+1)%256; replyTimer = endpoint.GetRequestModeTimeout(); awaitingResponse = TRUE; H323ControlPDU pdu; pdu.BuildRequestMode(outSequenceNumber); // more here - actually set the modes return connection.WriteControlPDU(pdu);}BOOL H245NegRequestMode::HandleRequest(const H245_RequestMode & pdu){ PTRACE(3, "H245\tReceived request mode: inSeq=" << inSequenceNumber << (awaitingResponse ? " awaitingResponse" : " idle")); H323ControlPDU reply_ack; H245_RequestModeAck & ack = reply_ack.BuildRequestModeAck(inSequenceNumber, H245_RequestModeAck_response::e_willTransmitMostPreferredMode); H323ControlPDU reply_reject; H245_RequestModeReject & reject = reply_reject.BuildRequestModeReject(inSequenceNumber, H245_RequestModeReject_cause::e_modeUnavailable); if (connection.OnRequestModeChange(pdu, ack, reject)) return connection.WriteControlPDU(reply_ack); else return connection.WriteControlPDU(reply_reject);}BOOL H245NegRequestMode::HandleAck(const H245_RequestModeAck & pdu){ PTRACE(3, "H245\tReceived ack on request mode: outSeq=" << outSequenceNumber << (awaitingResponse ? " awaitingResponse" : " idle")); if (awaitingResponse && pdu.m_sequenceNumber == outSequenceNumber) { awaitingResponse = FALSE; replyTimer.Stop(); connection.OnAcceptModeChange(pdu); } return TRUE;}BOOL H245NegRequestMode::HandleReject(const H245_RequestModeReject & pdu){ PTRACE(3, "H245\tReceived reject on request mode: outSeq=" << outSequenceNumber << (awaitingResponse ? " awaitingResponse" : " idle")); if (awaitingResponse && pdu.m_sequenceNumber == outSequenceNumber) { awaitingResponse = FALSE; replyTimer.Stop(); connection.OnRefusedModeChange(&pdu); } return TRUE;}BOOL H245NegRequestMode::HandleRelease(const H245_RequestModeRelease & /*pdu*/){ PTRACE(3, "H245\tReceived release on request mode: inSeq=" << inSequenceNumber << (awaitingResponse ? " awaitingResponse" : " idle")); return TRUE;}void H245NegRequestMode::HandleTimeout(PTimer &, INT){ PTRACE(3, "H245\tTimeout on request mode: outSeq=" << outSequenceNumber << (awaitingResponse ? " awaitingResponse" : " idle")); if (awaitingResponse) { awaitingResponse = FALSE; H323ControlPDU pdu; pdu.Build(H245_IndicationMessage::e_requestModeRelease); connection.WriteControlPDU(pdu); connection.OnRefusedModeChange(NULL); } connection.OnControlProtocolError(H323Connection::e_ModeRequest, "Timeout");}/////////////////////////////////////////////////////////////////////////////H245NegRoundTripDelay::H245NegRoundTripDelay(H323EndPoint & end, H323Connection & conn) : H245Negotiator(end, conn){ awaitingResponse = FALSE; sequenceNumber = 0; retryCount = 3;}BOOL H245NegRoundTripDelay::StartRequest(){ PTRACE(3, "H245\tStarted round trip delay: seq=" << sequenceNumber << (awaitingResponse ? " awaitingResponse" : " idle")); replyTimer = endpoint.GetRoundTripDelayTimeout(); sequenceNumber = (sequenceNumber + 1)%256; awaitingResponse = TRUE; H323ControlPDU pdu; pdu.BuildRoundTripDelayRequest(sequenceNumber); if (!connection.WriteControlPDU(pdu)) return FALSE; tripStartTime = PTimer::Tick(); return TRUE;}BOOL H245NegRoundTripDelay::HandleRequest(const H245_RoundTripDelayRequest & pdu){ PTRACE(3, "H245\tStarted round trip delay: seq=" << sequenceNumber << (awaitingResponse ? " awaitingResponse" : " idle")); H323ControlPDU reply; reply.BuildRoundTripDelayResponse(pdu.m_sequenceNumber); return connection.WriteControlPDU(reply);}BOOL H245NegRoundTripDelay::HandleResponse(const H245_RoundTripDelayResponse & pdu){ PTimeInterval tripEndTime = PTimer::Tick(); PTRACE(3, "H245\tHandling round trip delay: seq=" << sequenceNumber << (awaitingResponse ? " awaitingResponse" : " idle")); if (awaitingResponse && pdu.m_sequenceNumber == sequenceNumber) { replyTimer.Stop(); awaitingResponse = FALSE; roundTripTime = tripEndTime - tripStartTime; retryCount = 3; } return TRUE;}void H245NegRoundTripDelay::HandleTimeout(PTimer &, INT){ PTRACE(3, "H245\tTimeout on round trip delay: seq=" << sequenceNumber << (awaitingResponse ? " awaitingResponse" : " idle")); if (awaitingResponse && retryCount > 0) retryCount--; awaitingResponse = FALSE; connection.OnControlProtocolError(H323Connection::e_RoundTripDelay, "Timeout");}/////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -