📄 main.cxx
字号:
logFile.Open(logFilename, PFile::ReadWrite);
logFile.SetPosition(0, PFile::End);
}
logFile.WriteLine(msg);
logFile.Close();
logMutex.Signal();
}
//////////////////////////////////////////////////////////////////////////////////////////////
void MyConferenceManager::OnMemberJoining(Conference * conf, ConferenceMember * member)
{
if (!PIsDescendant(member, ConferenceFileMember))
conf->AddMember(new ConferenceFileMember(OpenMCU::Current().GetEnteringWAVFile(), PFile::ReadOnly));
}
void MyConferenceManager::OnMemberLeaving(Conference * conf, ConferenceMember * member)
{
if (!PIsDescendant(member, ConferenceFileMember))
conf->AddMember(new ConferenceFileMember(OpenMCU::Current().GetLeavingWAVFile(), PFile::ReadOnly));
}
//////////////////////////////////////////////////////////////////////////////////////////////
void SpliceMacro(PString & text, const PString & token, const PString & value)
{
PRegularExpression RegEx("<?!--#status[ \t\r\n]+" + token + "[ \t\r\n]*-->?",
PRegularExpression::Extended|PRegularExpression::IgnoreCase);
PINDEX pos, len;
while (text.FindRegEx(RegEx, pos, len))
text.Splice(value, pos, len);
}
PCREATE_SERVICE_MACRO_BLOCK(RoomStatus,P_EMPTY,P_EMPTY,block)
{
return OpenMCU::Current().GetEndpoint().GetRoomStatus(block);
}
MainStatusPage::MainStatusPage(OpenMCU & _app, PHTTPAuthority & auth)
: PServiceHTTPString("Status", "", "text/html; charset=UTF-8", auth),
app(_app)
{
PHTML html;
html << PHTML::Title("OpenH323 MCU Status")
<< "<meta http-equiv=\"Refresh\" content=\"30\">\n"
<< PHTML::Body()
<< app.GetPageGraphic()
<< PHTML::Paragraph() << "<center>"
//<< PHTML::Form("POST")
<< PHTML::TableStart("border=1")
<< PHTML::TableRow()
<< PHTML::TableHeader()
<< " Room Name "
<< PHTML::TableHeader()
<< " Room Members "
<< PHTML::TableHeader()
<< "<!--#macrostart RoomStatus-->"
<< PHTML::TableRow()
<< PHTML::TableData()
<< "<!--#status RoomName-->"
<< PHTML::TableData()
<< "<!--#status RoomMembers-->"
<< "<!--#macroend RoomStatus-->"
<< PHTML::TableEnd()
<< PHTML::Paragraph()
//<< PHTML::Form()
<< PHTML::HRule()
<< app.GetCopyrightText()
<< PHTML::Body();
string = html;
}
BOOL MainStatusPage::Post(PHTTPRequest & request,
const PStringToString & data,
PHTML & msg)
{
/*
PTRACE(2, "VGGK\tClear call POST received " << data);
msg << PHTML::Title() << "Accepted Control Command" << PHTML::Body()
<< PHTML::Heading(1) << "Accepted Control Command" << PHTML::Heading(1);
PWaitAndSignal m(app.endpointMutex);
std::vector<MyGatekeeperH323EndPoint *>::iterator r;
for (r = app.endpointList.begin(); r != app.endpointList.end(); ++r) {
if ((*r)->OnPostControl(data, msg))
msg << PHTML::Heading(2) << "No calls or endpoints!" << PHTML::Heading(2);
PServiceHTML::ProcessMacros(request, msg, "html/status.html",
PServiceHTML::LoadFromFile|PServiceHTML::NoSignatureForFile);
}
msg << PHTML::Paragraph()
<< PHTML::HotLink(request.url.AsString()) << "Reload page" << PHTML::HotLink()
<< " "
<< PHTML::HotLink("/") << "Home page" << PHTML::HotLink();
*/
return TRUE;
}
///////////////////////////////////////////////////////////////
MyH323EndPoint::MyH323EndPoint()
{
#if 0
terminalType = e_MCUWithAudioMP;
#ifndef NO_MCU_VIDEO
terminalType = e_MCUWithAVMP;
#endif
conferenceListener = NULL;
#endif
}
void MyH323EndPoint::Initialise(PConfig & cfg, PConfigPage * rsrc)
{
// Local alias name for H.323 endpoint
SetLocalUserName(cfg.GetString(LocalUserNameKey, "OpenH323 MCU v" + OpenMCU::Current().GetVersion()));
// Gatekeeper mode
PStringArray labels(GKMODE_LABEL_COUNT, GKModeLabels);
PINDEX idx = labels.GetStringsIndex(cfg.GetString(GatekeeperModeKey, labels[0]));
PINDEX gkMode = (idx == P_MAX_INDEX) ? 0 : idx;
rsrc->Add(new PHTTPRadioField(GatekeeperModeKey, labels, gkMode));
// Gatekeeper password
PString gkName = cfg.GetString(GatekeeperKey);
// Gatekeeper password
PString gkPassword = PHTTPPasswordField::Decrypt(cfg.GetString(GatekeeperPasswordKey));
SetGatekeeperPassword(gkPassword);
// start the H.323 listeners
PString defaultInterface = "*:1720";
H323TransportAddressArray interfaces;
PINDEX arraySize = cfg.GetInteger(PString(InterfaceKey) + " Array Size");
if (arraySize == 0)
StartListener(defaultInterface);
else {
for (int i = 0; i < arraySize; i++)
interfaces.Append(new H323TransportAddress(cfg.GetString(psprintf("%s %u", InterfaceKey, i+1), "")));
StartListeners(interfaces);
}
rsrc->Add(new PHTTPFieldArray(new PHTTPStringField(cfg.GetDefaultSection() + "\\" + InterfaceKey, InterfaceKey, 20, defaultInterface), FALSE));
if (listeners.IsEmpty()) {
PSYSTEMLOG(Fatal, "Main\tCould not open H.323 Listener");
}
/*
if (args.GetOptionString('q').IsEmpty()) {
endpoint.behind_masq = FALSE;
} else {
endpoint.masqAddressPtr = new PIPSocket::Address(args.GetOptionString('q'));
endpoint.behind_masq = TRUE;
cout << "Masquerading as address " << *(endpoint.masqAddressPtr) << endl;
}
*/
AddAllCapabilities(0, 0, "*");
// disable codecs as required
PString disableCodecs = cfg.GetString(DisableCodecsKey);
rsrc->Add(new PHTTPStringField(DisableCodecsKey, 50, disableCodecs));
if (!disableCodecs.IsEmpty()) {
PStringArray toRemove = disableCodecs.Tokenise(' ', FALSE);
capabilities.Remove(toRemove);
}
#ifndef NO_MCU_VIDEO
EnableVideoReception(args.HasOption('v'));
int videoTxQual = 10;
if (args.HasOption("videotxquality"))
videoTxQual = args.GetOptionString("videotxquality").AsInteger();
endpoint.videoTxQuality = PMAX(1, PMIN(31, videoTxQual));
int videoF = 2;
if (args.HasOption("videofill"))
videoF = args.GetOptionString("videofill").AsInteger();
endpoint.videoFill = PMAX(1, PMIN(99, videoF));
int videoFPS = 10;
if (args.HasOption("videotxfps"))
videoFPS = args.GetOptionString("videotxfps").AsInteger();
endpoint.videoFramesPS = PMAX(1,PMIN(30,videoFPS));
int videoBitRate = 0; //disable setting videoBitRate.
if (args.HasOption("videobitrate")) {
videoBitRate = args.GetOptionString("videobitrate").AsInteger();
videoBitRate = 1024 * PMAX(16, PMIN(2048, videoBitRate));
}
endpoint.videoBitRate = videoBitRate;
if (args.HasOption('v')) {
#if H323_AVCODEC
PTRACE(3, "Video bitrate for ffmpeg h263 is " << videoBitRate);
if (endpoint.videoLarge)
endpoint.SetCapability(0, 1, new H323_FFH263Capability(0, 0, 1, 0, 0, videoBitRate, videoFPS));
endpoint.SetCapability(0, 1, new H323_FFH263Capability(0, 1, 0, 0, 0, videoBitRate, videoFPS));
#endif
#if H323_VICH263
PTRACE(3, "Video bitrate for vic h263 is " << videoBitRate);
if (endpoint.videoLarge)
endpoint.SetCapability(0, 1, new H323_H263Capability(0, 0, 1, 0, 0, videoBitRate, videoFPS));
endpoint.SetCapability(0, 1, new H323_H263Capability(0, 1, 0, 0, 0, videoBitRate, videoFPS));
#endif
}
#endif /*End of test on NO_MCU_VIDEO */
AddAllUserInputCapabilities(0, 2);
switch (gkMode) {
default:
case Gatekeeper_None:
break;
case Gatekeeper_Find:
if (!DiscoverGatekeeper(new H323TransportUDP(*this)))
PSYSTEMLOG(Error, "No gatekeeper found");
break;
case Gatekeeper_Explicit:
if (!SetGatekeeper(gkName, new H323TransportUDP(*this)))
PSYSTEMLOG(Error, "Error registering with gatekeeper at \"" << gkName << '"');
}
PTRACE(2, "MCU\tCodecs (in preference order):\n" << setprecision(2) << GetCapabilities());;
}
H323Connection * MyH323EndPoint::CreateConnection(unsigned callReference)
{
return new OpenMCUH323Connection(*this, callReference);
}
void MyH323EndPoint::TranslateTCPAddress(PIPSocket::Address &localAddr, const PIPSocket::Address &remoteAddr)
{
// if (this->behind_masq &&
// (remoteAddr.Byte1() != 192)) {
// localAddr = *(this->masqAddressPtr);
// }
return;
}
PString MyH323EndPoint::GetRoomStatus(const PString & block)
{
PString substitution;
PWaitAndSignal m(conferenceManager.GetConferenceListMutex());
ConferenceList & conferenceList = conferenceManager.GetConferenceList();
ConferenceList::iterator r;
for (r = conferenceList.begin(); r != conferenceList.end(); ++r) {
// make a copy of the repeating html chunk
PString insert = block;
PStringStream members;
members << "<table border=1>"
"<tr>"
"<th>"
" Name "
"</th><th>"
" Duration "
"</th><th>"
" Codec "
"</th><th>"
" Packets/Bytes tx "
"</th><th>"
" Packets/Bytes rx "
"</th></tr>";
Conference & conference = *(r->second);
size_t memberListSize = 0;
{
PWaitAndSignal m(conference.GetMutex());
Conference::MemberList & memberList = conference.GetMemberList();
memberListSize = memberList.size();
Conference::MemberList::const_iterator s;
for (s = memberList.begin(); s != memberList.end(); ++s) {
if (PIsDescendant(s->second, H323Connection_ConferenceMember)) {
OpenMCUH323Connection & conn = *((H323Connection_ConferenceMember *)(s->second))->GetConnection();
PTime now;
PTime callStart = conn.GetConnectionStartTime();
RTP_Session * session = conn.GetSession(RTP_Session::DefaultAudioSessionID);
members << "<tr>"
"<td>"
<< conn.GetRemotePartyName()
<< "</td><td>"
<< (now -callStart) << " mins"
<< "</td><td>"
<< conn.GetAudioTransmitCodecName() << '/' << conn.GetAudioReceiveCodecName()
<< "</td><td>"
<< session->GetPacketsSent() << '/' << session->GetOctetsSent()
<< "</td><td>"
<< session->GetPacketsReceived() << '/' << session->GetOctetsReceived()
<< "</td></tr>";
}
}
}
members << "</table>";
SpliceMacro(insert, "RoomName", conference.GetNumber());
SpliceMacro(insert, "RoomMemberCount", PString(PString::Unsigned, (long)memberListSize));
SpliceMacro(insert, "RoomMembers", members);
substitution += insert;
}
return substitution;
}
Conference * MyH323EndPoint::ConferenceRequest(H323Connection & connection,
const H323SignalPDU & setupPDU,
H323Connection::AnswerCallResponse & response)
{
const H225_Setup_UUIE & setup = setupPDU.m_h323_uu_pdu.m_h323_message_body;
// get the conference ID from the incoming call
OpalGloballyUniqueID conferenceID = setup.m_conferenceID;
// we accept creates and joins. Invites come later :)
if (setup.m_conferenceGoal.GetTag() != H225_Setup_UUIE_conferenceGoal::e_create &&
setup.m_conferenceGoal.GetTag() != H225_Setup_UUIE_conferenceGoal::e_join) {
PTRACE(3, "MCU\tUnknown conference goal " << setup.m_conferenceGoal.GetTag());
response = H323Connection::AnswerCallDenied;
return NULL;
}
// see if the destination address or called party matches the name of a room
PString userSpecifiedRoom;
BOOL userSpecifiedRoomFound = FALSE;
if (setup.m_destinationAddress.GetSize() > 0) {
PINDEX i;
for (i = 0; !userSpecifiedRoomFound && (i < setup.m_destinationAddress.GetSize()); i++) {
PString roomNumber = H323GetAliasAddressString(setup.m_destinationAddress[i++]);
if (userSpecifiedRoom.IsEmpty())
userSpecifiedRoom = roomNumber;
userSpecifiedRoomFound = conferenceManager.HasConference(roomNumber);
}
PString calledPartyNumber;
if (!userSpecifiedRoomFound &&
setupPDU.GetQ931().GetCalledPartyNumber(calledPartyNumber) &&
!calledPartyNumber.IsEmpty()) {
if (userSpecifiedRoom.IsEmpty())
userSpecifiedRoom = calledPartyNumber;
userSpecifiedRoomFound = conferenceManager.HasConference(calledPartyNumber);
}
}
// join an existing conference if one matches the ID
if (conferenceManager.HasConference(conferenceID)) {
// there is a small chance that the conference has disappeared since the HasConference above
// so always use a new valid room number when creating the conference
Conference * conference = conferenceManager.MakeConference(conferenceID, OpenMCU::Current().GetNewRoomNumber(), "");
PTRACE(3, "MCU\tJoining conference by ID " << conference->GetID());
response = H323Connection::AnswerCallNow;
return conference;
}
// if we are doing a join, then we joining by ID failed
if (setup.m_conferenceGoal.GetTag() == H225_Setup_UUIE_conferenceGoal::e_join) {
PTRACE(3, "MCU\tJoin request for conference with unknown ID " << conferenceID);
response = H323Connection::AnswerCallDeniedByInvalidCID;
return NULL;
}
// if a room exists with the called party name, use that room even though the conference IDs don't match
if (userSpecifiedRoomFound) {
Conference * conference = conferenceManager.MakeConference(userSpecifiedRoom, "");
PTRACE(3, "MCU\tJoining conference " << conference->GetID() << " specified by number " << userSpecifiedRoom);
response = H323Connection::AnswerCallNow;
return conference;
}
// if no room exists with the called party name, then create a new room by that name and with the specified conference ID
if (!userSpecifiedRoom.IsEmpty()) {
Conference * conference = conferenceManager.MakeConference(conferenceID, userSpecifiedRoom, "");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -