~noskcaj/ubuntu/saucy/sflphone/merge-1.2.3-2

« back to all changes in this revision

Viewing changes to daemon/src/audio/audiortp/audio_zrtp_session.cpp

  • Committer: Jackson Doak
  • Date: 2013-07-10 21:04:46 UTC
  • mfrom: (20.1.3 sid)
  • Revision ID: noskcaj@ubuntu.com-20130710210446-y8f587vza807icr9
Properly merged from upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
 
2
 *  Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
3
3
 *  Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
4
4
 *  Author: Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com>
5
5
 *
14
14
 *
15
15
 *  You should have received a copy of the GNU General Public License
16
16
 *  along with this program; if not, write to the Free Software
17
 
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
18
18
 *
19
19
 *  Additional permission under GNU GPL version 3 section 7:
20
20
 *
47
47
namespace sfl {
48
48
 
49
49
AudioZrtpSession::AudioZrtpSession(SIPCall &call, const std::string &zidFilename) :
50
 
    ost::TimerPort()
51
 
    , ost::SymmetricZRTPSession(ost::InetHostAddress(call.getLocalIp().c_str()), call.getLocalAudioPort())
52
 
    , AudioRtpSession(call, *this, *this)
 
50
    ost::SymmetricZRTPSession(ost::InetHostAddress(call.getLocalIp().c_str()), call.getLocalAudioPort())
 
51
    , AudioRtpSession(call, *this)
53
52
    , zidFilename_(zidFilename)
54
 
    , rtpThread_(*this)
55
53
{
56
54
    initializeZid();
57
55
    DEBUG("Setting new RTP session with destination %s:%d",
59
57
    audioRtpRecord_.callId_ = call_.getCallId();
60
58
}
61
59
 
62
 
AudioZrtpSession::~AudioZrtpSession()
 
60
std::vector<long>
 
61
AudioZrtpSession::getSocketDescriptors() const
63
62
{
64
 
    if (rtpThread_.running_) {
65
 
        rtpThread_.running_ = false;
66
 
        rtpThread_.join();
67
 
    }
 
63
    std::vector<long> result;
 
64
    result.push_back(dso->getRecvSocket());
 
65
    result.push_back(cso->getRecvSocket());
 
66
    return result;
68
67
}
69
68
 
70
 
 
71
69
void AudioZrtpSession::initializeZid()
72
70
{
73
71
    if (zidFilename_.empty())
74
72
        throw ZrtpZidException("zid filename empty");
75
73
 
 
74
    const std::string cache_home(XDG_CACHE_HOME);
76
75
    std::string zidCompleteFilename;
77
76
 
78
 
    std::string xdg_config = std::string(HOMEDIR) + DIR_SEPARATOR_STR + ".cache" + DIR_SEPARATOR_STR + PACKAGE + "/" + zidFilename_;
79
 
 
80
 
    DEBUG("xdg_config %s", xdg_config.c_str());
81
 
 
82
 
    if (XDG_CACHE_HOME != NULL) {
83
 
        std::string xdg_env = std::string(XDG_CACHE_HOME) + zidFilename_;
84
 
        DEBUG("xdg_env %s", xdg_env.c_str());
85
 
        (xdg_env.length() > 0) ? zidCompleteFilename = xdg_env : zidCompleteFilename = xdg_config;
86
 
    } else
87
 
        zidCompleteFilename = xdg_config;
88
 
 
 
77
    if (not cache_home.empty()) {
 
78
        zidCompleteFilename = cache_home + DIR_SEPARATOR_STR + zidFilename_;
 
79
    } else {
 
80
        zidCompleteFilename = fileutils::get_home_dir() + DIR_SEPARATOR_STR +
 
81
                              ".cache" + DIR_SEPARATOR_STR + PACKAGE +
 
82
                              DIR_SEPARATOR_STR + zidFilename_;
 
83
    }
89
84
 
90
85
    if (initialize(zidCompleteFilename.c_str()) >= 0) {
91
86
        setEnableZrtp(true);
122
117
    queue_.sendImmediate(timestamp_, getMicDataEncoded(), compSize);
123
118
}
124
119
 
125
 
AudioZrtpSession::AudioZrtpThread::AudioZrtpThread(AudioZrtpSession &session) : running_(true), zrtpSession_(session)
126
 
{}
127
 
 
128
 
void AudioZrtpSession::AudioZrtpThread::run()
129
 
{
130
 
    // Set recording sampling rate
131
 
    int threadSleep = 20;
132
 
 
133
 
    DEBUG("Entering Audio zrtp thread main loop %s", running_ ? "running" : "not running");
134
 
 
135
 
    TimerPort::setTimer(threadSleep);
136
 
 
137
 
    while (running_) {
138
 
        // Send session
139
 
        if (zrtpSession_.hasDTMFPending())
140
 
            zrtpSession_.sendDtmfEvent();
141
 
        else
142
 
            zrtpSession_.sendMicData();
143
 
 
144
 
        Thread::sleep(TimerPort::getTimer());
145
 
 
146
 
        TimerPort::incTimer(threadSleep);
147
 
    }
148
 
 
149
 
    DEBUG("Leaving audio rtp thread loop");
150
 
}
151
 
 
152
120
int AudioZrtpSession::getIncrementForDTMF() const
153
121
{
154
122
    return 160;
155
123
}
156
124
 
157
 
void AudioZrtpSession::setSessionMedia(AudioCodec &audioCodec)
158
 
{
159
 
    AudioRtpSession::setSessionMedia(audioCodec);
160
 
}
161
 
 
162
 
int AudioZrtpSession::startRtpThread(AudioCodec &audiocodec)
163
 
{
164
 
    if(isStarted_)
165
 
        return 0;
166
 
 
167
 
    AudioRtpSession::startRtpThread(audiocodec);
168
 
    return startZrtpThread();
 
125
void AudioZrtpSession::startReceiveThread()
 
126
{
 
127
    ost::SymmetricZRTPSession::start();
169
128
}
170
129
 
171
130
}