conference.cpp 4.29 KB
Newer Older
1
/*
2
 *  Copyright (C) 2004-2019 Savoir-faire Linux Inc.
3 4 5
 *
 *  Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
 *  Author: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
6
 *
7 8 9 10
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
11
 *
12 13 14 15
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
16
 *
17 18
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
19
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
20 21
 */

22 23
#include <sstream>

24 25
#include "conference.h"
#include "manager.h"
26
#include "audio/audiolayer.h"
27
#include "audio/ringbufferpool.h"
28

Adrien Béraud's avatar
Adrien Béraud committed
29
#ifdef ENABLE_VIDEO
30
#include "sip/sipcall.h"
31
#include "client/videomanager.h"
32
#include "video/video_input.h"
33
#include "video/video_mixer.h"
34 35
#endif

36 37
#include "call_factory.h"

38 39
#include "logger.h"

Adrien Béraud's avatar
Adrien Béraud committed
40
namespace jami {
41

42
Conference::Conference()
43 44
    : id_(Manager::instance().getNewCallID())
    , confState_(ACTIVE_ATTACHED)
45
    , participants_()
Adrien Béraud's avatar
Adrien Béraud committed
46
#ifdef ENABLE_VIDEO
47
    , videoMixer_(nullptr)
48
#endif
Julien Bonjean's avatar
Julien Bonjean committed
49
{
50 51
}

52 53
Conference::~Conference()
{
Adrien Béraud's avatar
Adrien Béraud committed
54
#ifdef ENABLE_VIDEO
55
    for (const auto &participant_id : participants_) {
56
        if (auto call = Manager::instance().callFactory.getCall<SIPCall>(participant_id))
57 58
            call->getVideoRtp().exitConference();
    }
Adrien Béraud's avatar
Adrien Béraud committed
59
#endif // ENABLE_VIDEO
60 61
}

62
Conference::ConferenceState Conference::getState() const
Julien Bonjean's avatar
Julien Bonjean committed
63
{
64
    return confState_;
65 66
}

67
void Conference::setState(ConferenceState state)
Julien Bonjean's avatar
Julien Bonjean committed
68
{
69
    confState_ = state;
70 71
}

72
void Conference::add(const std::string &participant_id)
Julien Bonjean's avatar
Julien Bonjean committed
73
{
74
    if (participants_.insert(participant_id).second) {
Adrien Béraud's avatar
Adrien Béraud committed
75
#ifdef ENABLE_VIDEO
76
        if (auto call = Manager::instance().callFactory.getCall<SIPCall>(participant_id))
77
            call->getVideoRtp().enterConference(this);
78
        else
Adrien Béraud's avatar
Adrien Béraud committed
79 80
            JAMI_ERR("no call associate to participant %s", participant_id.c_str());
#endif // ENABLE_VIDEO
81
    }
82 83
}

84
void Conference::remove(const std::string &participant_id)
Julien Bonjean's avatar
Julien Bonjean committed
85
{
86
    if (participants_.erase(participant_id)) {
Adrien Béraud's avatar
Adrien Béraud committed
87
#ifdef ENABLE_VIDEO
88
        if (auto call = Manager::instance().callFactory.getCall<SIPCall>(participant_id))
89
            call->getVideoRtp().exitConference();
Adrien Béraud's avatar
Adrien Béraud committed
90
#endif // ENABLE_VIDEO
91
    }
92
}
93

94
void Conference::bindParticipant(const std::string &participant_id)
Julien Bonjean's avatar
Julien Bonjean committed
95
{
96
    auto &rbPool = Manager::instance().getRingBufferPool();
97 98

    for (const auto &item : participants_) {
99
        if (participant_id != item)
100 101
            rbPool.bindCallID(participant_id, item);
        rbPool.flush(item);
102
    }
103

104 105
    rbPool.bindCallID(participant_id, RingBufferPool::DEFAULT_ID);
    rbPool.flush(RingBufferPool::DEFAULT_ID);
106
}
107

108
std::string Conference::getStateStr() const
Julien Bonjean's avatar
Julien Bonjean committed
109
{
110
    switch (confState_) {
111 112 113 114 115 116 117 118 119 120 121 122 123 124
        case ACTIVE_ATTACHED:
            return "ACTIVE_ATTACHED";
        case ACTIVE_DETACHED:
            return "ACTIVE_DETACHED";
        case ACTIVE_ATTACHED_REC:
            return "ACTIVE_ATTACHED_REC";
        case ACTIVE_DETACHED_REC:
            return "ACTIVE_DETACHED_REC";
        case HOLD:
            return "HOLD";
        case HOLD_REC:
            return "HOLD_REC";
        default:
            return "";
125 126
    }
}
127

Adrien Béraud's avatar
Adrien Béraud committed
128 129
const ParticipantSet&
Conference::getParticipantList() const
Julien Bonjean's avatar
Julien Bonjean committed
130
{
131
    return participants_;
132
}
133

134 135 136 137 138 139 140 141 142 143 144 145 146
std::vector<std::string>
Conference::getDisplayNames() const
{
    std::vector<std::string> result;

    for (const auto &p : participants_) {
        auto details = Manager::instance().getCallDetails(p);
        const auto tmp = details["DISPLAY_NAME"];
        result.push_back(tmp.empty() ? details["PEER_NUMBER"] : tmp);
    }
    return result;
}

147
bool Conference::toggleRecording()
Julien Bonjean's avatar
Julien Bonjean committed
148
{
149
    const bool startRecording = Recordable::toggleRecording();
150
    return startRecording;
151
}
152 153 154 155 156

std::string Conference::getConfID() const {
    return id_;
}

Adrien Béraud's avatar
Adrien Béraud committed
157
#ifdef ENABLE_VIDEO
158
std::shared_ptr<video::VideoMixer> Conference::getVideoMixer()
159
{
160
    if (!videoMixer_)
161
        videoMixer_.reset(new video::VideoMixer(id_));
162
    return videoMixer_;
163 164
}
#endif
165

Adrien Béraud's avatar
Adrien Béraud committed
166
} // namespace jami