int MultiConf::SendFPU(int partId) { int ret = 0; Log("-SendFPU [id:%d]\n",partId); //Lock participantsLock.IncUse(); //Get participant Participant *part = GetParticipant(partId); //Check participant if (part) //Send FPU ret = part->SendVideoFPU(); if(m_CurrentBroadCaster != 0) { Log("-RequestFPU [id:%d]\n",m_CurrentBroadCaster); listener->onParticipantRequestFPU(this,m_CurrentBroadCaster,this->param); listener->onParticipantRequestFPU(this,partId,this->param); } //Unlock participantsLock.DecUse(); //Exit return ret; }
MultiConf::ParticipantStatistics* MultiConf::GetParticipantStatistic(int partId) { //Create statistics map ParticipantStatistics *stats = new ParticipantStatistics(); //Lock participantsLock.IncUse(); //Find participant Participant* part = GetParticipant(partId); //Check participant if (part) { //Append (*stats)["audio"] = part->GetStatistics(MediaFrame::Audio); (*stats)["video"] = part->GetStatistics(MediaFrame::Video); (*stats)["text"] = part->GetStatistics(MediaFrame::Text); } //Unlock participantsLock.DecUse(); //Return stats return stats; }
/************************ * SetAudioCodec * SetAudioCodec *************************/ int MultiConf::SetAudioCodec(int id,int codec) { int ret = 0; Log("-SetAudioCodec [%d]\n",id); //Use list participantsLock.IncUse(); //Get the participant Participant *part = GetParticipant(id); //Check particpant if (part) //Set video codec ret = part->SetAudioCodec((AudioCodec::Type)codec); if (!m_GroupAudio.IsInited()) { m_GroupAudio.SetAudioCodec((AudioCodec::Type)codec); } //Unlock participantsLock.DecUse(); //Exit return ret; }
/************************ * SetVideoCodec * SetVideoCodec *************************/ int MultiConf::SetVideoCodec(int id,int codec,int mode,int fps,int bitrate,int quality, int fillLevel,int intraPeriod) { int ret = 0; Log("-SetVideoCodec [%d]\n",id); //Use list participantsLock.IncUse(); //Get the participant Participant *part = GetParticipant(id); if (!m_GroupVideo.IsInited()) { m_GroupVideo.SetVideoCodec((VideoCodec::Type)codec,mode,fps,bitrate,quality,fillLevel,intraPeriod); } //Check particpant if (part) //Set video codec ret = part->SetVideoCodec((VideoCodec::Type)codec,mode,fps,bitrate,quality,fillLevel,intraPeriod); //Unlock participantsLock.DecUse(); //Exit return ret; }
int MultiConf::DeleteSpy(int spyId) { int ret = 0; Spys::iterator it = spys.find(spyId); if(it == spys.end()) return 0; spysLock.WaitUnusedAndLock(); int spyeeId = spys[spyId]; spys.erase(it); spysLock.Unlock(); Log(">DeleteSpy [%d]\n",spyId); //Use list participantsLock.IncUse(); RTPParticipant *part = (RTPParticipant*)GetParticipant(spyeeId,Participant::RTP); //Check particpant if (part) //Set video codec ret = part->DeleteVideoSpy(spyId); //Unlock participantsLock.DecUse(); Log("<DeleteSpy [%d]\n",spyId); return 1; }
int MultiConf::StartReceivingVideoSpy(int spyId, VideoCodec::RTPMap& rtpMap) { int ret = 0; Log("-StartReceivingVideoSpy [%d]\n",spyId); if(spys.find(spyId) == spys.end()) return 0; int spyeeId = spys[spyId]; //Use list participantsLock.IncUse(); //Get the participant RTPParticipant *part = (RTPParticipant*)GetParticipant(spyeeId,Participant::RTP); //Check particpant if (part) //Set video codec ret = part->StartReceivingVideoSpy(spyId, rtpMap); //Unlock participantsLock.DecUse(); //Exit return ret; }
int MultiConf::StartSendingVideoSpy(int spyId,char *sendVideoIp,int sendVideoPort,VideoCodec::RTPMap& rtpMap) { int ret = 0; RTPSession *rtp = NULL; if(spys.find(spyId) == spys.end()) return 0; int spyeeId = spys[spyId]; Log("-StartSendingVideoSpy [%d]\n",spyeeId); //Use list participantsLock.IncUse(); RTPParticipant *part = (RTPParticipant*)GetParticipant(spyeeId,Participant::RTP); //Check particpant if (part) //Set video codec ret = part->StartSendingVideoSpy(spyId, sendVideoIp, sendVideoPort, rtpMap); //Unlock participantsLock.DecUse(); //Start sending the video //return ((RTPParticipant*)part)->StartSendingVideo(sendVideoIp,sendVideoPort,rtpMap); return ret; }
/************************ * SetParticipantMosaic * Change participant mosaic *************************/ int MultiConf::SetParticipantMosaic(int partId,int mosaicId) { int ret = 0; Log("-SetParticipantMosaic [partId:%d,mosaic:%d]\n",partId,mosaicId); //Use list participantsLock.IncUse(); //Get the participant Participant *part = GetParticipant(partId); //If it is the app mixer mosaic if (mosaicId==-1) //Get it mosaicId = appMixerEncoderPrivateMosaicId; //Check particpant if (part) //Set it in the video mixer ret = videoMixer.SetMixerMosaic(partId,mosaicId); //Unlock participantsLock.DecUse(); //Exit return ret; }
//--------------------------------------------------------------------------- const std::string ribi::gtst::ParticipantStateFinished::ToAdminStr() const { assert(GetParticipant()); const Participant * const participant = GetParticipant(); std::string s = std::to_string(participant->GetId()) + std::string(": ") + this->ToStr() + std::string(": earnings: ") + std::to_string( m_server->GetParameters()->GetFinished()->CalculateEarnings( participant->GetPayoffs()->GetTotal())) + std::string(" euros"); return s; }
int MultiConf::StopRecordingParticipant(int partId) { int ret = 0; Log("-StopRecordingParticipant [id:%d]\n",partId); //Lock participantsLock.IncUse(); //Get rtp participant RTPParticipant* rtp = (RTPParticipant*)GetParticipant(partId,Participant::RTP); //Check participant if (rtp) { //Set the listener for the rtp video packets rtp->SetMediaListener(NULL); //Add the listener for audio and text frames of the watcher audioEncoder.RemoveListener(&rtp->recorder); textEncoder.RemoveListener(&rtp->recorder); //Stop recording rtp->recorder.Stop(); //End recording ret = rtp->recorder.End(); } //Unlock participantsLock.DecUse(); //Exit return ret; }
const std::string ribi::gtst::ParticipantStateQuiz::ToAdminStr() const { const Participant * const participant = GetParticipant(); std::string s = std::to_string(participant->GetId()) + std::string(": ") + this->ToStr() + std::string(": "); if (!participant->GetVotes().empty()) { for(const boost::shared_ptr<VotingOption>& i: participant->GetVotes()) { s+=i->GetDescription()+","; } s.resize(s.size() - 1); s += std::string("(") + std::to_string(participant->GetVotes().size()) + std::string(")"); } else { s+="no votes"; } return s; }
//--------------------------------------------------------------------------- const std::string ParticipantStateViewResultsGroup::ToAdminStr() const { const Participant * const participant = GetParticipant(); std::string s = std::to_string(participant->GetId()) + std::string(": ") + this->ToStr(); return s; }
//-------------------------------------------------------------------------------------- // Processes an inbox message that the manoeuvre received. // Param1: A pointer to the message to process. //-------------------------------------------------------------------------------------- void ActiveBaseDefence::ProcessMessage(Message* pMessage) { switch(pMessage->GetType()) { case FlagPickedUpMessageType: { FlagPickedUpMessage* pMsg = reinterpret_cast<FlagPickedUpMessage*>(pMessage); if(pMsg->GetData().m_flagOwner == GetTeamAI()->GetTeam()) { // The team's flag was picked up, the manoeuvre failed SetFailed(true); } break; } case EntityKilledMessageType: { EntityKilledMessage* pMsg = reinterpret_cast<EntityKilledMessage*>(pMessage); if(IsParticipant(pMsg->GetData().m_id) && pMsg->GetData().m_team == GetTeamAI()->GetTeam()) { XMFLOAT2 deathPosition = GetParticipant(pMsg->GetData().m_id)->GetPosition(); // Participants that get killed, drop out of the manoeuvre m_pTeamAI->ReleaseEntityFromManoeuvre(pMsg->GetData().m_id); // Send other participants to investigate the position, where the entity died InvestigatePosition(deathPosition); } break; } case UpdateOrderStateMessageType: { // Cancel old order, Send Follow-Up Orders, finish manoeuvre etc UpdateOrderStateMessage* pMsg = reinterpret_cast<UpdateOrderStateMessage*>(pMessage); if(IsParticipant(pMsg->GetData().m_entityId)) { if(pMsg->GetData().m_orderState == SucceededOrderState) { XMFLOAT2 movePosition(0.0f, 0.0f); if(!m_pTeamAI->GetTestEnvironment()->GetRandomUnblockedTargetInArea(GetTeamAI()->GetFlagData(GetTeamAI()->GetTeam()).m_basePosition, m_patrolRadius, movePosition)) { m_pTeamAI->ReleaseEntityFromManoeuvre(pMsg->GetData().m_entityId); }else { // Set the next patrol target reinterpret_cast<MoveOrder*>(m_activeOrders[pMsg->GetData().m_entityId])->SetTargetPosition(movePosition); } }else if(pMsg->GetData().m_orderState == FailedOrderState) { m_pTeamAI->ReleaseEntityFromManoeuvre(pMsg->GetData().m_entityId); } } break; } default: TeamManoeuvre::ProcessMessage(pMessage); } }
void ChatSession::OnMessageReceived(const Tp::ReceivedMessage &message) { QList<Tp::ReceivedMessage> messages; messages.append(message); tp_text_channel_->acknowledge(messages); ChatSessionParticipant* from = GetParticipant(message.sender()); ChatMessage* m = new ChatMessage(from, message.received(), message.text()); message_history_.push_back(m); emit( MessageReceived(*m) ); }
const std::string ribi::gtst::ParticipantStateLoggedIn::ToAdminStr() const { const Participant * const participant = GetParticipant(); const std::string s = ToStr() + std::string(", ID: ") + (participant->CanGetId() ? std::to_string(participant->GetId()) : std::string("?NONE?")) + std::string(", IP address: ") + (participant->CanGetIpAddress() ? participant->GetIpAddress()->Get() : std::string("?NONE?")); return s; }
//-------------------------------------------------------------------------------------- // Initiates the manoeuvre. This mostly consists of sending initial orders to all // participating entities and everything that is involved in that process, such as // determining targets etc. // Returns a behaviour status code representing the current state of the initiation of the manoeuvre. //-------------------------------------------------------------------------------------- BehaviourStatus GuardedFlagCapture::Initiate(void) { EntityTeam enemyTeam = (GetTeamAI()->GetTeam() == TeamRed) ? (TeamBlue) : (TeamRed); m_flagCarrierId = GetTeamAI()->GetFlagData(enemyTeam).m_carrierId; XMFLOAT2 flagCarrierPosition = GetParticipant(m_flagCarrierId)->GetPosition(); for(std::vector<Entity*>::iterator it = m_participants.begin(); it != m_participants.end(); ++it) { Order* pNewOrder = nullptr; if((*it)->GetId() != m_flagCarrierId) { // Orders for the protectors XMFLOAT2 movementTarget(0.0f, 0.0f); if(!m_pTeamAI->GetTestEnvironment()->GetRandomUnblockedTargetInArea(flagCarrierPosition, m_guardRadius, movementTarget)) { return StatusFailure; } pNewOrder = new MoveOrder((*it)->GetId(), MoveToPositionOrder, MediumPriority, movementTarget); }else { // Orders for the flag carrier // Move to the home base but attack enemies if they get in the way // Note: In future versions the manoeuvre should send the carrier on a path, where he is less likely to // encounter enemies. pNewOrder = new MoveOrder((*it)->GetId(), MoveToPositionOrder, MediumPriority, GetTeamAI()->GetFlagData(GetTeamAI()->GetTeam()).m_basePosition); } if(!pNewOrder) { return StatusFailure; } FollowOrderMessageData data(pNewOrder); SendMessage(*it, FollowOrderMessageType, &data); m_activeOrders.insert(std::pair<unsigned long, Order*>((*it)->GetId(), pNewOrder)); } return StatusSuccess; }
Participant *MultiConf::GetParticipant(int partId,Participant::Type type) { //Find participant Participant *part = GetParticipant(partId); //If no participant if (!part) //Exit return NULL; //Ensure it is from the correct type if (part->GetType()!=type) //Error return (Participant *)Error("Participant is not of desired type"); //Return it return part; }
void ChatSession::HandlePendingMessage() { QDBusPendingReply<Tp::PendingTextMessageList> pending_messages = tp_text_channel_->textInterface()->ListPendingMessages(true); if( !pending_messages.isFinished() ) pending_messages.waitForFinished(); if ( pending_messages.isValid() ) { LogDebug("Received pending messages:"); QDBusMessage m = pending_messages.reply(); Tp::PendingTextMessageList list = pending_messages.value(); if (list.size() == 0) { LogDebug("There is no pending messages."); } else { LogDebug(QString("There is ").append(QString::number(list.size())).append(" pending messages.").toStdString()); for (Tp::PendingTextMessageList::iterator i = list.begin(); i != list.end(); ++i) { QString note = QString("* Pending message received: ").append(i->text); LogDebug(note.toStdString()); uint type = i->messageType; //! @todo Check if we need value of this parameter if (type != Tp::ChannelTextMessageTypeNormal) continue; ChatSessionParticipant* originator = GetParticipant(i->sender); if (originator == 0) { //! @HACK and memory leak here. We should have a contact object from Connection object! //! @HACK We should search contact object with given i->sender id value originator = new ChatSessionParticipant(new Contact(tp_text_channel_->initiatorContact())); participants_.push_back(originator); } ChatMessage* message = new ChatMessage( originator, QDateTime::fromTime_t(i->unixTimestamp), i->text); message_history_.push_back(message); emit( MessageReceived(*message) ); } } } else LogError("Received invalid pending messages"); }
int MultiConf::StartRecordingParticipant(int partId,const char* filename) { int ret = 0; Log("-StartRecordingParticipant [id:%d,name:\"%s\"]\n",partId,filename); //Lock participantsLock.IncUse(); //Get participant RTPParticipant *rtp = (RTPParticipant*)GetParticipant(partId,Participant::RTP); //Check if if (!rtp) //End goto end; //Create recording if (!rtp->recorder.Create(filename)) //End goto end; //Start recording if (!rtp->recorder.Record()) //End goto end; //Set the listener for the rtp video packets rtp->SetMediaListener(&rtp->recorder); //Add the listener for audio and text frames of the watcher audioEncoder.AddListener(&rtp->recorder); textEncoder.AddListener(&rtp->recorder); //OK ret = 1; end: //Unlock participantsLock.DecUse(); //Exit return ret; }
//-------------------------------------------------------------------------------------- // Updates the movement targets for the protectors to move to new guard positions closer // to the current position of the flag carrier. //-------------------------------------------------------------------------------------- void GuardedFlagCapture::UpdateMovementTargets(void) { XMFLOAT2 flagCarrierPosition = GetParticipant(m_flagCarrierId)->GetPosition(); for(std::vector<Entity*>::iterator it = m_participants.begin(); it != m_participants.end(); ++it) { if((*it)->GetId() != m_flagCarrierId) { XMFLOAT2 newMovementTarget(0.0f, 0.0f); if(!m_pTeamAI->GetTestEnvironment()->GetRandomUnblockedTargetInArea(flagCarrierPosition, m_guardRadius, newMovementTarget)) { m_pTeamAI->ReleaseEntityFromManoeuvre((*it)->GetId()); } // Change the movement target in the orders for the entities reinterpret_cast<MoveOrder*>(m_activeOrders[(*it)->GetId()])->SetTargetPosition(newMovementTarget); } } }
//--------------------------------------------------------------------------- const std::string ribi::gtst::ParticipantStateVoting::ToAdminStr() const { const Participant * const participant = GetParticipant(); std::string s = std::to_string(participant->GetId()) + std::string(": ") + this->ToStr() + std::string(": "); if (!participant->GetVotes().empty()) { BOOST_FOREACH(const boost::shared_ptr<VotingOption>& i,participant->GetVotes()) { s+=i->GetDescription()+","; } s.resize(s.size() - 1); s += std::string("(") + std::to_string(participant->GetVotes().size()) + std::string(")"); }
//--------------------------------------------------------------------------- const std::string ribi::gtst::ParticipantStateChat::ToAdminStr() const { const Participant * const participant = GetParticipant(); std::string s = std::to_string(participant->GetId()) + std::string(": "); const std::vector<std::vector<boost::shared_ptr<ChatMessage> > >& chat = participant->GetChatLog(); if (chat.back().empty()) { s+="[no chat this round]"; } else { std::for_each(chat.back().begin(), chat.back().end(), [&s](const boost::shared_ptr<ChatMessage>& t) { s+=t->GetText() +" | "; } ); } return s; }
int MultiConf::SetRTPProperties(int id,MediaFrame::Type media,const Properties& properties) { int ret = 0; //Use list participantsLock.IncUse(); //Get the participant RTPParticipant *part = (RTPParticipant*)GetParticipant(id,Participant::RTP); //Check particpant if (part) //Set codec ret = part->SetRTPProperties(media,properties); //Unlock participantsLock.DecUse(); //Exit return ret; }
/************************ * End * Termina una multiconferencia *************************/ int MultiConf::StopReceivingText(int id) { int ret = 0; Log("-StopReceivingText [%d]\n",id); //Use list participantsLock.IncUse(); //Get the participant RTPParticipant *part = (RTPParticipant*)GetParticipant(id,Participant::RTP); //Check particpant if (part) //Set video codec ret = part->StopReceivingText(); //Unlock participantsLock.DecUse(); //Exit return ret; }
/************************ * StartReceivingVideo * StartReceivingVideo *************************/ int MultiConf::StartReceivingVideo(int id,VideoCodec::RTPMap& rtpMap) { int ret = 0; Log("-StartReceivingVideo [%d]\n",id); //Use list participantsLock.IncUse(); //Get the participant RTPParticipant *part = (RTPParticipant*)GetParticipant(id,Participant::RTP); //Check particpant if (part) //Set video codec ret = part->StartReceivingVideo(rtpMap); //Unlock participantsLock.DecUse(); //Exit return ret; }
int MultiConf::SetRemoteCryptoDTLS(int id,MediaFrame::Type media,const char *setup,const char *hash,const char *fingerprint) { int ret = 0; Log("-SetRemoteCryptoDTLS %s [partId:%d]\n",MediaFrame::TypeToString(media),id); //Use list participantsLock.IncUse(); //Get the participant RTPParticipant *part = (RTPParticipant*)GetParticipant(id,Participant::RTP); //Check particpant if (part) //Set codec ret = part->SetRemoteCryptoDTLS(media,setup,hash,fingerprint); //Unlock participantsLock.DecUse(); //Exit return ret; }
int MultiConf::SetLocalSTUNCredentials(int id,MediaFrame::Type media,const char *username,const char* pwd) { int ret = 0; Log("-SetLocalSTUNCredentials %s [partId:%d,username:%s,pwd:%s]\n",MediaFrame::TypeToString(media),id,username,pwd); //Use list participantsLock.IncUse(); //Get the participant RTPParticipant *part = (RTPParticipant*)GetParticipant(id,Participant::RTP); //Check particpant if (part) //Set codec ret = part->SetLocalSTUNCredentials(media,username,pwd); //Unlock participantsLock.DecUse(); //Exit return ret; }
/******************************************************** * SetMute * Set participant mute ********************************************************/ int MultiConf::SetMute(int partId,MediaFrame::Type media,bool isMuted) { int ret = 0; Log("-SetMute [id:%d,media:%d,muted:%d]\n",partId,media,isMuted); //Lock participantsLock.IncUse(); //Get participant Participant *part = GetParticipant(partId); //Check participant if (part) //Send FPU ret = part->SetMute(media,isMuted); //Unlock participantsLock.DecUse(); //Exit return ret; }
/************************ * SetTextCodec * SetTextCodec *************************/ int MultiConf::SetTextCodec(int id,int codec) { int ret = 0; Log("-SetTextCodec [%d]\n",id); //Use list participantsLock.IncUse(); //Get the participant Participant *part = GetParticipant(id); //Check particpant if (part) //Set video codec ret = part->SetTextCodec((TextCodec::Type)codec); //Unlock participantsLock.DecUse(); //Exit return ret; }
/************************ * StartSendingText * StartSendingText *************************/ int MultiConf::StartSendingText(int id,char *sendTextIp,int sendTextPort,TextCodec::RTPMap& rtpMap) { int ret = 0; Log("-StartSendingText [%d]\n",id); //Use list participantsLock.IncUse(); //Get the participant RTPParticipant *part = (RTPParticipant*)GetParticipant(id,Participant::RTP); //Check particpant if (part) //Set video codec ret = part->StartSendingText(sendTextIp,sendTextPort,rtpMap); //Unlock participantsLock.DecUse(); //Exit return ret; }