conference.cpp 4.69 KB
Newer Older
1
/*
2
 *  Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
3
 *  Author : Alexandre Savard <alexandre.savard@savoirfairelinux.com>
Emmanuel Milou's avatar
Emmanuel Milou committed
4 5
 *
 *
6 7 8 9
 *  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.
Emmanuel Milou's avatar
Emmanuel Milou committed
10
 *
11 12 13 14
 *  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.
Emmanuel Milou's avatar
Emmanuel Milou committed
15
 *
16 17
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
19 20 21 22 23 24 25 26 27 28 29
 *
 *  Additional permission under GNU GPL version 3 section 7:
 *
 *  If you modify this program, or any covered work, by linking or
 *  combining it with the OpenSSL project's OpenSSL library (or a
 *  modified version of that library), containing parts covered by the
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 *  grants you additional permission to convey the resulting work.
 *  Corresponding Source for a non-source form of such a combination
 *  shall include the source code for the parts of OpenSSL used as well
 *  as that of the covered work.
30 31
 */

32 33
#include <sstream>

34 35
#include "conference.h"
#include "manager.h"
36
#include "audio/audiolayer.h"
37
#include "audio/mainbuffer.h"
38

39
#ifdef SFL_VIDEO
40 41
#include "sip/sipvoiplink.h"
#include "sip/sipcall.h"
42 43 44 45
#include "client/video_controls.h"
#include "video/video_camera.h"
#endif

46 47
#include "logger.h"

48

49
Conference::Conference()
50 51
    : id_(Manager::instance().getNewCallID())
    , confState_(ACTIVE_ATTACHED)
52
    , participants_()
53
#ifdef SFL_VIDEO
54
    , videoMixer_(new sfl_video::VideoMixer(id_))
55
#endif
Julien Bonjean's avatar
Julien Bonjean committed
56
{
57
    Recordable::initRecFilename(id_);
58 59
}

60 61
Conference::~Conference()
{
62
#ifdef SFL_VIDEO
63
    for (const auto &participant_id : participants_)
64 65
        SIPVoIPLink::instance()->getSipCall(participant_id)->getVideoRtp().exitConference();
#endif // SFL_VIDEO
66 67
}

68
Conference::ConferenceState Conference::getState() const
Julien Bonjean's avatar
Julien Bonjean committed
69
{
70
    return confState_;
71 72
}

73
void Conference::setState(ConferenceState state)
Julien Bonjean's avatar
Julien Bonjean committed
74
{
75
    confState_ = state;
76 77
}

78
void Conference::add(const std::string &participant_id)
Julien Bonjean's avatar
Julien Bonjean committed
79
{
80 81 82 83 84
    if (participants_.insert(participant_id).second) {
#ifdef SFL_VIDEO
    SIPVoIPLink::instance()->getSipCall(participant_id)->getVideoRtp().enterConference(this);
#endif // SFL_VIDEO
    }
85 86
}

87
void Conference::remove(const std::string &participant_id)
Julien Bonjean's avatar
Julien Bonjean committed
88
{
89 90 91 92 93
    if (participants_.erase(participant_id)) {
#ifdef SFL_VIDEO
        SIPVoIPLink::instance()->getSipCall(participant_id)->getVideoRtp().exitConference();
#endif // SFL_VIDEO
    }
94
}
95

96
void Conference::bindParticipant(const std::string &participant_id)
Julien Bonjean's avatar
Julien Bonjean committed
97
{
98
    auto &mainBuffer = Manager::instance().getMainBuffer();
99 100

    for (const auto &item : participants_) {
101
        if (participant_id != item)
102 103 104
            mainBuffer.bindCallID(participant_id, item);
        mainBuffer.flush(item);
    }
105

106 107
    mainBuffer.bindCallID(participant_id, MainBuffer::DEFAULT_ID);
    mainBuffer.flush(MainBuffer::DEFAULT_ID);
108
}
109

110
std::string Conference::getStateStr() const
Julien Bonjean's avatar
Julien Bonjean committed
111
{
112
    switch (confState_) {
113 114 115 116 117 118 119 120 121 122 123 124 125 126
        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 "";
127 128
    }
}
129

130
ParticipantSet Conference::getParticipantList() const
Julien Bonjean's avatar
Julien Bonjean committed
131
{
132
    return participants_;
133
}
134

135
bool Conference::toggleRecording()
Julien Bonjean's avatar
Julien Bonjean committed
136
{
137
    const bool startRecording = Recordable::recAudio_.toggleRecording();
138
    MainBuffer &mbuffer = Manager::instance().getMainBuffer();
139

140
    std::string process_id(Recordable::recorder_.getRecorderID());
141

Emmanuel Milou's avatar
Emmanuel Milou committed
142
    // start recording
143
    if (startRecording) {
144 145
        for (const auto &item : participants_)
            mbuffer.bindHalfDuplexOut(process_id, item);
146

147
        mbuffer.bindHalfDuplexOut(process_id, MainBuffer::DEFAULT_ID);
148

149
        Recordable::recorder_.start();
150
    } else {
151 152
        for (const auto &item : participants_)
            mbuffer.unBindHalfDuplexOut(process_id, item);
153

154
        mbuffer.unBindHalfDuplexOut(process_id, MainBuffer::DEFAULT_ID);
Emmanuel Milou's avatar
Emmanuel Milou committed
155
    }
156

157
    return startRecording;
158
}
159 160 161 162 163

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

164
#ifdef SFL_VIDEO
165
std::shared_ptr<sfl_video::VideoMixer> Conference::getVideoMixer()
166
{
167
    return videoMixer_;
168 169
}
#endif