Update Active Speaker API (fix synchronizations)

This commit is contained in:
Julien Wadel 2022-11-02 10:38:43 +01:00
parent 29122171cf
commit 04f3997fd9
13 changed files with 66 additions and 66 deletions

View file

@ -41,6 +41,11 @@ ConferenceListener::~ConferenceListener(){
//-----------------------------------------------------------------------------------------------------------------------
// LINPHONE LISTENERS
//-----------------------------------------------------------------------------------------------------------------------
void ConferenceListener::onActiveSpeakerParticipantDevice(const std::shared_ptr<linphone::Conference> & conference, const std::shared_ptr<const linphone::ParticipantDevice> & participantDevice) {
qDebug() << "onActiveSpeakerParticipantDevice: " << participantDevice->getAddress()->asString().c_str();
emit activeSpeakerParticipantDevice(participantDevice);
}
void ConferenceListener::onParticipantAdded(const std::shared_ptr<linphone::Conference> & conference, const std::shared_ptr<const linphone::Participant> & participant){
qDebug() << "onParticipantAdded: " << participant->getAddress()->asString().c_str();
emit participantAdded(participant);

View file

@ -35,6 +35,7 @@ public:
virtual ~ConferenceListener();
// LINPHONE LISTENERS
virtual void onActiveSpeakerParticipantDevice(const std::shared_ptr<linphone::Conference> & conference, const std::shared_ptr<const linphone::ParticipantDevice> & participantDevice) override;
virtual void onParticipantAdded(const std::shared_ptr<linphone::Conference> & conference, const std::shared_ptr<const linphone::Participant> & participant) override;
virtual void onParticipantRemoved(const std::shared_ptr<linphone::Conference> & conference, const std::shared_ptr<const linphone::Participant> & participant) override;
virtual void onParticipantAdminStatusChanged(const std::shared_ptr<linphone::Conference> & conference, const std::shared_ptr<const linphone::Participant> & participant) override;
@ -50,6 +51,7 @@ public:
//---------------------------------------------------------------------------
signals:
void activeSpeakerParticipantDevice(const std::shared_ptr<const linphone::ParticipantDevice> & participantDevice);
void participantAdded(const std::shared_ptr<const linphone::Participant> & participant);
void participantRemoved(const std::shared_ptr<const linphone::Participant> & participant);
void participantAdminStatusChanged(const std::shared_ptr<const linphone::Participant> & participant);
@ -61,6 +63,7 @@ signals:
void participantDeviceIsSpeakingChanged(const std::shared_ptr<const linphone::ParticipantDevice> & participantDevice, bool isSpeaking);
void conferenceStateChanged(linphone::Conference::State newState);
void subjectChanged(const std::string & subject);
};

View file

@ -37,6 +37,7 @@
#include "components/Components.hpp"
void ConferenceModel::connectTo(ConferenceListener * listener){
connect(listener, &ConferenceListener::activeSpeakerParticipantDevice, this, &ConferenceModel::onActiveSpeakerParticipantDevice);
connect(listener, &ConferenceListener::participantAdded, this, &ConferenceModel::onParticipantAdded);
connect(listener, &ConferenceListener::participantRemoved, this, &ConferenceModel::onParticipantRemoved);
connect(listener, &ConferenceListener::participantAdminStatusChanged, this, &ConferenceModel::onParticipantAdminStatusChanged);
@ -140,6 +141,9 @@ void ConferenceModel::setIsReady(bool state){
//-----------------------------------------------------------------------------------------------------------------------
// LINPHONE LISTENERS
//-----------------------------------------------------------------------------------------------------------------------
void ConferenceModel::onActiveSpeakerParticipantDevice(const std::shared_ptr<const linphone::ParticipantDevice> & participantDevice){
emit activeSpeakerParticipantDevice(participantDevice);
}
void ConferenceModel::onParticipantAdded(const std::shared_ptr<const linphone::Participant> & participant){
qDebug() << "Added call, participant count: " << getParticipantList().size() << ". Me devices : " << mConference->getMe()->getDevices().size();
updateLocalParticipant();

View file

@ -62,7 +62,7 @@ public:
void setIsReady(bool state);
virtual void onActiveSpeakerParticipantDevice(const std::shared_ptr<const linphone::ParticipantDevice> & participantDevice);
virtual void onParticipantAdded(const std::shared_ptr<const linphone::Participant> & participant);
virtual void onParticipantRemoved(const std::shared_ptr<const linphone::Participant> & participant);
virtual void onParticipantAdminStatusChanged(const std::shared_ptr<const linphone::Participant> & participant);
@ -77,6 +77,7 @@ public:
//---------------------------------------------------------------------------
signals:
void activeSpeakerParticipantDevice(const std::shared_ptr<const linphone::ParticipantDevice> & participantDevice);
void localParticipantChanged();
void participantAdded(const std::shared_ptr<const linphone::Participant> & participant);
void participantRemoved(const std::shared_ptr<const linphone::Participant> & participant);

View file

@ -100,7 +100,6 @@ public:
virtual void onStateChanged(linphone::ConferenceScheduler::State state);
virtual void onInvitationsSent(const std::list<std::shared_ptr<linphone::Address>> & failedInvitations);
signals:
void timeZoneModelChanged();
void dateTimeChanged();

View file

@ -58,6 +58,7 @@ void ParticipantDeviceListModel::initConferenceModel(){
updateDevices(conferenceModel->getConference()->getParticipantDeviceList(), false);
qDebug() << "Conference have " << mList.size() << " devices";
connect(conferenceModel.get(), &ConferenceModel::activeSpeakerParticipantDevice, this, &ParticipantDeviceListModel::onActiveSpeakerParticipantDevice);
connect(conferenceModel.get(), &ConferenceModel::participantAdded, this, &ParticipantDeviceListModel::onParticipantAdded);
connect(conferenceModel.get(), &ConferenceModel::participantRemoved, this, &ParticipantDeviceListModel::onParticipantRemoved);
connect(conferenceModel.get(), &ConferenceModel::participantDeviceAdded, this, &ParticipantDeviceListModel::onParticipantDeviceAdded);
@ -116,6 +117,9 @@ bool ParticipantDeviceListModel::add(std::shared_ptr<linphone::ParticipantDevice
if( addMe){
qDebug() << "Added a me device";
emit meChanged();
}else if(mList.size() == 1 || (mList.size() == 2 && isMe(mList.front().objectCast<ParticipantDeviceModel>()->getDevice()))){
mActiveSpeaker = mList.back().objectCast<ParticipantDeviceModel>();
emit activeSpeakerChanged();
}
return true;
}
@ -126,7 +130,6 @@ bool ParticipantDeviceListModel::remove(std::shared_ptr<const linphone::Particip
auto device = item.objectCast<ParticipantDeviceModel>();
if( device->getDevice() == deviceToRemove){
device->updateVideoEnabled();
mActiveSpeakers.removeAll(device.get());
removeRow(row);
return true;
}else
@ -163,14 +166,8 @@ QSharedPointer<ParticipantDeviceModel> ParticipantDeviceListModel::getMe(int * i
return nullptr;
}
ParticipantDeviceModel* ParticipantDeviceListModel::getLastActiveSpeaking() const{
if( mActiveSpeakers.size() == 0){
if( mList.size() == 0)
return getMe().get();
else
return mList.back().objectCast<ParticipantDeviceModel>().get();
}else
return mActiveSpeakers.first();
ParticipantDeviceModel* ParticipantDeviceListModel::getActiveSpeakerModel() const{
return mActiveSpeaker.get();
}
bool ParticipantDeviceListModel::isMe(std::shared_ptr<linphone::ParticipantDevice> deviceToCheck)const{
@ -280,6 +277,13 @@ void ParticipantDeviceListModel::onParticipantDeviceMediaAvailabilityChanged(con
else
onParticipantDeviceAdded(participantDevice);
}
void ParticipantDeviceListModel::onActiveSpeakerParticipantDevice(const std::shared_ptr<const linphone::ParticipantDevice>& participantDevice){
auto device = get(participantDevice);
if( device){
mActiveSpeaker = device;
emit activeSpeakerChanged();
}
}
void ParticipantDeviceListModel::onParticipantDeviceIsSpeakingChanged(const std::shared_ptr<const linphone::ParticipantDevice> & participantDevice, bool isSpeaking){
auto device = get(participantDevice);
@ -288,14 +292,5 @@ void ParticipantDeviceListModel::onParticipantDeviceIsSpeakingChanged(const std:
}
void ParticipantDeviceListModel::onParticipantDeviceSpeaking(){
auto deviceModel = qobject_cast<ParticipantDeviceModel*>(sender());
bool changed = false;
// Me should not be in the list.
if( !deviceModel->isMe() && (mActiveSpeakers.size() == 0 || deviceModel->getIsSpeaking())) {// Ensure to have at least one last active speaker
changed = mActiveSpeakers.removeAll(deviceModel) > 0;
mActiveSpeakers.push_front(deviceModel);
changed = true;
}
if(changed)
emit participantSpeaking(deviceModel);
}

View file

@ -47,12 +47,13 @@ public:
bool remove(std::shared_ptr<const linphone::ParticipantDevice> deviceToAdd);
QSharedPointer<ParticipantDeviceModel> get(std::shared_ptr<const linphone::ParticipantDevice> deviceToGet, int * index = nullptr);
QSharedPointer<ParticipantDeviceModel> getMe(int * index = nullptr)const;
ParticipantDeviceModel* getLastActiveSpeaking() const;
ParticipantDeviceModel* getActiveSpeakerModel() const;
bool isMe(std::shared_ptr<linphone::ParticipantDevice> device)const;
bool isMeAlone() const;
public slots:
void onActiveSpeakerParticipantDevice(const std::shared_ptr<const linphone::ParticipantDevice>& participantDevice);
void onConferenceModelChanged ();
void onSecurityLevelChanged(std::shared_ptr<const linphone::Address> device);
void onParticipantAdded(const std::shared_ptr<const linphone::Participant> & participant);
@ -66,6 +67,7 @@ public slots:
void onParticipantDeviceSpeaking();
signals:
void activeSpeakerChanged();
void securityLevelChanged(std::shared_ptr<const linphone::Address> device);
void participantSpeaking(ParticipantDeviceModel *speakingDevice);
void conferenceCreated();
@ -73,7 +75,8 @@ signals:
private:
CallModel * mCallModel = nullptr;
QList<ParticipantDeviceModel*> mActiveSpeakers;// First item is last speaker
QSharedPointer<ParticipantDeviceModel> mActiveSpeaker;
//QList<ParticipantDeviceModel*> mActiveSpeakers;// First item is last speaker
bool mInitialized = false;
};

View file

@ -57,9 +57,9 @@ ParticipantDeviceModel *ParticipantDeviceProxyModel::getAt(int row){
return sourceModel()->data(sourceIndex).value<ParticipantDeviceModel *>();
}
ParticipantDeviceModel* ParticipantDeviceProxyModel::getLastActiveSpeaking(){
ParticipantDeviceModel* ParticipantDeviceProxyModel::getActiveSpeakerModel(){
auto listModel = qobject_cast<ParticipantDeviceListModel*>(sourceModel());
return listModel ? listModel->getLastActiveSpeaking() : nullptr;
return listModel ? listModel->getActiveSpeakerModel() : nullptr;
}
CallModel * ParticipantDeviceProxyModel::getCallModel() const{
@ -74,15 +74,19 @@ ParticipantDeviceModel * ParticipantDeviceProxyModel::getMe() const{
bool ParticipantDeviceProxyModel::isShowMe() const{
return mShowMe;
}
void ParticipantDeviceProxyModel::connectTo(ParticipantDeviceListModel* model){
connect(model, &ParticipantDeviceListModel::countChanged, this, &ParticipantDeviceProxyModel::onCountChanged);
connect(model, &ParticipantDeviceListModel::participantSpeaking, this, &ParticipantDeviceProxyModel::onParticipantSpeaking);
connect(model, &ParticipantDeviceListModel::conferenceCreated, this, &ParticipantDeviceProxyModel::conferenceCreated);
connect(model, &ParticipantDeviceListModel::meChanged, this, &ParticipantDeviceProxyModel::meChanged);
connect(model, &ParticipantDeviceListModel::activeSpeakerChanged, this, &ParticipantDeviceProxyModel::activeSpeakerChanged);
}
void ParticipantDeviceProxyModel::setCallModel(CallModel * callModel){
setFilterType(1);
mCallModel = callModel;
auto sourceModel = new ParticipantDeviceListModel(mCallModel);
connect(sourceModel, &ParticipantDeviceListModel::countChanged, this, &ParticipantDeviceProxyModel::onCountChanged);
connect(sourceModel, &ParticipantDeviceListModel::participantSpeaking, this, &ParticipantDeviceProxyModel::onParticipantSpeaking);
connect(sourceModel, &ParticipantDeviceListModel::conferenceCreated, this, &ParticipantDeviceProxyModel::conferenceCreated);
connect(sourceModel, &ParticipantDeviceListModel::meChanged, this, &ParticipantDeviceProxyModel::meChanged);
connectTo(sourceModel);
setSourceModel(sourceModel);
emit countChanged();
emit meChanged();
@ -91,10 +95,7 @@ void ParticipantDeviceProxyModel::setCallModel(CallModel * callModel){
void ParticipantDeviceProxyModel::setParticipant(ParticipantModel * participant){
setFilterType(0);
auto sourceModel = participant->getParticipantDevices().get();
connect(sourceModel, &ParticipantDeviceListModel::countChanged, this, &ParticipantDeviceProxyModel::countChanged);
connect(sourceModel, &ParticipantDeviceListModel::participantSpeaking, this, &ParticipantDeviceProxyModel::onParticipantSpeaking);
connect(sourceModel, &ParticipantDeviceListModel::conferenceCreated, this, &ParticipantDeviceProxyModel::conferenceCreated);
connect(sourceModel, &ParticipantDeviceListModel::meChanged, this, &ParticipantDeviceProxyModel::meChanged);
connectTo(sourceModel);
setSourceModel(sourceModel);
emit countChanged();
emit meChanged();

View file

@ -42,12 +42,14 @@ public:
Q_PROPERTY(CallModel * callModel READ getCallModel WRITE setCallModel NOTIFY callModelChanged)
Q_PROPERTY(bool showMe READ isShowMe WRITE setShowMe NOTIFY showMeChanged)
Q_PROPERTY(ParticipantDeviceModel * me READ getMe NOTIFY meChanged)
Q_PROPERTY(ParticipantDeviceModel* activeSpeaker READ getActiveSpeakerModel NOTIFY activeSpeakerChanged)
ParticipantDeviceProxyModel (QObject *parent = nullptr);
Q_INVOKABLE ParticipantDeviceModel* getAt(int row);
Q_INVOKABLE ParticipantDeviceModel* getLastActiveSpeaking();
ParticipantDeviceModel * getMe() const;
ParticipantDeviceModel* getActiveSpeakerModel();
ParticipantDeviceModel* getMe() const;
CallModel * getCallModel() const;
bool isShowMe() const;
@ -56,11 +58,14 @@ public:
void setParticipant(ParticipantModel * participant);
void setShowMe(const bool& show);
void connectTo(ParticipantDeviceListModel* model);
public slots:
void onCountChanged();
void onParticipantSpeaking(ParticipantDeviceModel * speakingDevice);
signals:
void activeSpeakerChanged();
void callModelChanged();
void showMeChanged();
void meChanged();

View file

@ -189,6 +189,7 @@ void fromString(const QString& transportType, LinphoneEnums::TransportType *tran
Q_DECLARE_METATYPE(LinphoneEnums::CallStatus)
Q_DECLARE_METATYPE(LinphoneEnums::ChatMessageState)
Q_DECLARE_METATYPE(LinphoneEnums::ConferenceLayout)
Q_DECLARE_METATYPE(LinphoneEnums::ConferenceInfoState)
@ -198,6 +199,6 @@ Q_DECLARE_METATYPE(LinphoneEnums::MediaEncryption)
Q_DECLARE_METATYPE(LinphoneEnums::ParticipantDeviceState)
Q_DECLARE_METATYPE(LinphoneEnums::RecorderState)
Q_DECLARE_METATYPE(LinphoneEnums::TunnelMode)
Q_DECLARE_METATYPE(LinphoneEnums::TransportType)
#endif

View file

@ -107,7 +107,9 @@ Rectangle {
? item.organizer
? item.organizer
: entry.sipAddress || entry.fullPeerAddress || entry.peerAddress || ''
: entry.participants.addressesToString
: entry.participants
? entry.participants.addressesToString
: ''
: ''
}

View file

@ -29,30 +29,12 @@ Item {
property int participantCount: callModel.isConference ? allDevices.count + 1 : 2 // +me. allDevices==0 if !conference
onParticipantCountChanged: {Qt.callLater(allDevices.updateCurrentDevice)}
property ParticipantDeviceProxyModel participantDevices : ParticipantDeviceProxyModel {
id: allDevices
callModel: mainItem.callModel
showMe: false
onParticipantSpeaking: updateCurrentDevice()
showMe: false
onConferenceCreated: cameraView.resetCamera()
function updateCurrentDevice(){
if( callModel ){
if( callModel.isConference) {
var device = getLastActiveSpeaking()
if(device) // Get
cameraView.currentDevice = device
}
}
}
onMeChanged: if(cameraView.isPreview) {
cameraView.currentDevice = me
cameraView.resetCamera()
}
}
function clearAll(layoutMode){
@ -67,6 +49,11 @@ Item {
anchors.leftMargin: isRightReducedLayout || isLeftReducedLayout? 30 : 140
anchors.rightMargin: isRightReducedLayout ? 10 : 140
callModel: mainItem.callModel
currentDevice: isPreview
? allDevices.me
: callModel.isConference
? allDevices.activeSpeaker
: null
deactivateCamera: isPreview && callModel.pausedByUser
? true
: callModel.isConference
@ -79,14 +66,7 @@ Item {
isVideoEnabled: !deactivateCamera
isPreview: !preview.visible && mainItem.participantCount == 1
onIsPreviewChanged: {
if( isPreview){
currentDevice = allDevices.me
cameraView.resetCamera()
}else
allDevices.updateCurrentDevice()
cameraView.resetCamera()
}
onIsPreviewChanged: {cameraView.resetCamera() }
isCameraFromDevice: isPreview
isPaused: isPreview && callModel.pausedByUser
? false
@ -193,3 +173,4 @@ Item {
}
}

@ -1 +1 @@
Subproject commit b5cc94b43b9ad5644f5d7ec8bd8f9f7a81127a54
Subproject commit 11f72d4e254a2a8305a9400e38cb44f125c18873