📄 connection.cxx
字号:
OpalMediaStream * OpalConnection::GetMediaStream(unsigned sessionId, BOOL source) const
{
PWaitAndSignal mutex(mediaStreamMutex);
for (PINDEX i = 0; i < mediaStreams.GetSize(); i++) {
if (mediaStreams[i].GetSessionID() == sessionId &&
mediaStreams[i].IsSource() == source)
return &mediaStreams[i];
}
return NULL;
}
BOOL OpalConnection::IsMediaBypassPossible(unsigned /*sessionID*/) const
{
PTRACE(3, "OpalCon\tIsMediaBypassPossible: default returns FALSE");
return FALSE;
}
BOOL OpalConnection::GetMediaInformation(unsigned sessionID,
MediaInformation & info) const
{
if (!mediaTransportAddresses.Contains(sessionID)) {
PTRACE(3, "OpalCon\tGetMediaInformation for session " << sessionID << " - no channel.");
return FALSE;
}
OpalTransportAddress & address = mediaTransportAddresses[sessionID];
PIPSocket::Address ip;
WORD port;
if (address.GetIpAndPort(ip, port)) {
info.data = OpalTransportAddress(ip, (WORD)(port&0xfffe));
info.control = OpalTransportAddress(ip, (WORD)(port|0x0001));
}
else
info.data = info.control = address;
info.rfc2833 = rfc2833Handler->GetPayloadType();
PTRACE(3, "OpalCon\tGetMediaInformation for session " << sessionID
<< " data=" << info.data << " rfc2833=" << info.rfc2833);
return TRUE;
}
void OpalConnection::AddVideoMediaFormats(OpalMediaFormatList & mediaFormats) const
{
endpoint.AddVideoMediaFormats(mediaFormats, this);
}
BOOL OpalConnection::CreateVideoInputDevice(const OpalMediaFormat & mediaFormat,
PVideoInputDevice * & device,
BOOL & autoDelete)
{
return endpoint.CreateVideoInputDevice(*this, mediaFormat, device, autoDelete);
}
BOOL OpalConnection::CreateVideoOutputDevice(const OpalMediaFormat & mediaFormat,
BOOL preview,
PVideoOutputDevice * & device,
BOOL & autoDelete)
{
return endpoint.CreateVideoOutputDevice(*this, mediaFormat, preview, device, autoDelete);
}
RTP_Session * OpalConnection::GetSession(unsigned sessionID) const
{
return rtpSessions.GetSession(sessionID);
}
RTP_Session * OpalConnection::UseSession(const OpalTransport & transport,
unsigned sessionID,
RTP_QOS * rtpqos)
{
RTP_Session * rtpSession = rtpSessions.UseSession(sessionID);
if (rtpSession == NULL) {
rtpSession = CreateSession(transport, sessionID, rtpqos);
rtpSessions.AddSession(rtpSession);
}
return rtpSession;
}
void OpalConnection::ReleaseSession(unsigned sessionID)
{
rtpSessions.ReleaseSession(sessionID);
}
RTP_Session * OpalConnection::CreateSession(const OpalTransport & transport,
unsigned sessionID,
RTP_QOS * rtpqos)
{
// We only support RTP over UDP at this point in time ...
if (!transport.IsCompatibleTransport("ip$127.0.0.1"))
return NULL;
PIPSocket::Address localAddress;
transport.GetLocalAddress().GetIpAddress(localAddress);
OpalManager & manager = GetEndPoint().GetManager();
PIPSocket::Address remoteAddress;
transport.GetRemoteAddress().GetIpAddress(remoteAddress);
PSTUNClient * stun = manager.GetSTUN(remoteAddress);
// create an RTP session
RTP_UDP * rtpSession = new RTP_UDP(sessionID);
WORD firstPort = manager.GetRtpIpPortPair();
WORD nextPort = firstPort;
while (!rtpSession->Open(localAddress,
nextPort, nextPort,
manager.GetRtpIpTypeofService(),
stun,
rtpqos)) {
nextPort = manager.GetRtpIpPortPair();
if (nextPort == firstPort) {
delete rtpSession;
return NULL;
}
}
localAddress = rtpSession->GetLocalAddress();
if (manager.TranslateIPAddress(localAddress, remoteAddress))
rtpSession->SetLocalAddress(localAddress);
return rtpSession;
}
BOOL OpalConnection::SetBandwidthAvailable(unsigned newBandwidth, BOOL force)
{
PTRACE(3, "OpalCon\tSetting bandwidth to "
<< newBandwidth << "00b/s on connection " << *this);
unsigned used = GetBandwidthUsed();
if (used > newBandwidth) {
if (!force)
return FALSE;
#if 0
// Go through media channels and close down some.
PINDEX chanIdx = GetmediaStreams->GetSize();
while (used > newBandwidth && chanIdx-- > 0) {
OpalChannel * channel = logicalChannels->GetChannelAt(chanIdx);
if (channel != NULL) {
used -= channel->GetBandwidthUsed();
const H323ChannelNumber & number = channel->GetNumber();
CloseLogicalChannel(number, number.IsFromRemote());
}
}
#endif
}
bandwidthAvailable = newBandwidth - used;
return TRUE;
}
unsigned OpalConnection::GetBandwidthUsed() const
{
unsigned used = 0;
#if 0
for (PINDEX i = 0; i < logicalChannels->GetSize(); i++) {
OpalChannel * channel = logicalChannels->GetChannelAt(i);
if (channel != NULL)
used += channel->GetBandwidthUsed();
}
#endif
PTRACE(3, "OpalCon\tBandwidth used is "
<< used << "00b/s for " << *this);
return used;
}
BOOL OpalConnection::SetBandwidthUsed(unsigned releasedBandwidth,
unsigned requiredBandwidth)
{
PTRACE_IF(3, releasedBandwidth > 0, "OpalCon\tBandwidth release of "
<< releasedBandwidth/10 << '.' << releasedBandwidth%10 << "kb/s");
bandwidthAvailable += releasedBandwidth;
PTRACE_IF(3, requiredBandwidth > 0, "OpalCon\tBandwidth request of "
<< requiredBandwidth/10 << '.' << requiredBandwidth%10
<< "kb/s, available: "
<< bandwidthAvailable/10 << '.' << bandwidthAvailable%10
<< "kb/s");
if (requiredBandwidth > bandwidthAvailable) {
PTRACE(2, "OpalCon\tAvailable bandwidth exceeded on " << *this);
return FALSE;
}
bandwidthAvailable -= requiredBandwidth;
return TRUE;
}
void OpalConnection::SetSendUserInputMode(SendUserInputModes mode)
{
PTRACE(2, "OPAL\tSetting default User Input send mode to " << mode);
sendUserInputMode = mode;
}
BOOL OpalConnection::SendUserInputString(const PString & value)
{
for (const char * c = value; *c != '\0'; c++) {
if (!SendUserInputTone(*c, 0))
return FALSE;
}
return TRUE;
}
BOOL OpalConnection::SendUserInputTone(char tone, unsigned duration)
{
if (duration == 0)
duration = 180;
return rfc2833Handler->SendTone(tone, duration);
}
void OpalConnection::OnUserInputString(const PString & value)
{
endpoint.OnUserInputString(*this, value);
}
void OpalConnection::OnUserInputTone(char tone, unsigned duration)
{
endpoint.OnUserInputTone(*this, tone, duration);
}
PString OpalConnection::GetUserInput(unsigned timeout)
{
PString reply;
if (userInputAvailable.Wait(PTimeInterval(0, timeout))) {
userInputMutex.Wait();
reply = userInputString;
userInputString = PString();
userInputMutex.Signal();
}
return reply;
}
void OpalConnection::SetUserInput(const PString & input)
{
userInputMutex.Wait();
userInputString += input;
userInputMutex.Signal();
userInputAvailable.Signal();
}
PString OpalConnection::ReadUserInput(const char * terminators,
unsigned lastDigitTimeout,
unsigned firstDigitTimeout)
{
PTRACE(3, "OpalCon\tReadUserInput from " << *this);
PromptUserInput(TRUE);
PString input = GetUserInput(firstDigitTimeout);
PromptUserInput(FALSE);
if (!input) {
for (;;) {
PString next = GetUserInput(lastDigitTimeout);
if (next.IsEmpty()) {
PTRACE(3, "OpalCon\tReadUserInput last character timeout on " << *this);
break;
}
if (next.FindOneOf(terminators) != P_MAX_INDEX) {
if (input.IsEmpty())
input = next;
break;
}
input += next;
}
}
else {
PTRACE(3, "OpalCon\tReadUserInput first character timeout on " << *this);
}
return input;
}
BOOL OpalConnection::PromptUserInput(BOOL /*play*/)
{
return TRUE;
}
void OpalConnection::OnUserInputInlineRFC2833(OpalRFC2833Info & info, INT)
{
if (!info.IsToneStart())
OnUserInputTone(info.GetTone(), info.GetDuration()/8);
}
void OpalConnection::OnUserInputInBandDTMF(RTP_DataFrame & frame, INT)
{
// This function is set up as an 'audio filter'.
// This allows us to access the 16 bit PCM audio (at 8Khz sample rate)
// before the audio is passed on to the sound card (or other output device)
// Pass the 16 bit PCM audio through the DTMF decoder
PString tones = dtmfDecoder.Decode(frame.GetPayloadPtr(), frame.GetPayloadSize());
if (!tones.IsEmpty()) {
PTRACE(1, "DTMF detected. " << tones);
PINDEX i;
for (i = 0; i < tones.GetLength(); i++) {
OnUserInputTone(tones[i], 0);
}
}
}
OpalT120Protocol * OpalConnection::CreateT120ProtocolHandler()
{
if (t120handler == NULL)
t120handler = endpoint.CreateT120ProtocolHandler(*this);
return t120handler;
}
OpalT38Protocol * OpalConnection::CreateT38ProtocolHandler()
{
if (t38handler == NULL)
t38handler = endpoint.CreateT38ProtocolHandler(*this);
return t38handler;
}
OpalH224Handler * OpalConnection::CreateH224ProtocolHandler(unsigned sessionID)
{
if(h224Handler == NULL)
h224Handler = endpoint.CreateH224ProtocolHandler(*this, sessionID);
return h224Handler;
}
OpalH281Handler * OpalConnection::CreateH281ProtocolHandler(OpalH224Handler & h224Handler)
{
return endpoint.CreateH281ProtocolHandler(h224Handler);
}
void OpalConnection::SetLocalPartyName(const PString & name)
{
localPartyName = name;
}
void OpalConnection::SetAudioJitterDelay(unsigned minDelay, unsigned maxDelay)
{
PAssert(minDelay <= 1000 && maxDelay <= 1000, PInvalidParameter);
if (minDelay < 10)
minDelay = 10;
minAudioJitterDelay = minDelay;
if (maxDelay < minDelay)
maxDelay = minDelay;
maxAudioJitterDelay = maxDelay;
}
void OpalConnection::SetPhase(Phases phaseToSet)
{
PTRACE(3, "OpalCon\tSetPhase from " << phase << " to " << phaseToSet);
phase = phaseToSet;
}
/////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -