AudioRtpFactory.h 5.69 KB
Newer Older
1
/*
2
 *  Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
3
 *  Author: Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com>
4
 *  Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
Julien Bonjean's avatar
Julien Bonjean committed
5
 *
6
7
8
9
10
11
12
13
 *  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.
 *  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.
Julien Bonjean's avatar
Julien Bonjean committed
14
 *
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
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19
20
21
22
23
24
25
26
27
28
 *
 *  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.
29
30
 */

31
32
#ifndef __SFL_AUDIO_RTP_FACTORY_H__
#define __SFL_AUDIO_RTP_FACTORY_H__
33

34
#include <stdexcept>
35
#include <cc++/thread.h>
36
#include "account.h" // for typedef of std::string (std::string)
37
#include <ccrtp/CryptoContext.h>
38
#include "AudioRtpSession.h"
39

40
41
42
#include "sip/SdesNegotiator.h"

class SdesNegotiator;
43
class SIPCall;
44
45
class Account;
class SIPAccount;
46

Julien Bonjean's avatar
Julien Bonjean committed
47
48
namespace sfl
{
49

Julien Bonjean's avatar
Julien Bonjean committed
50
class AudioZrtpSession;
51
class AudioCodec;
52

Julien Bonjean's avatar
Julien Bonjean committed
53
54
55
56
57
58
59
60
61
62
63
class UnsupportedRtpSessionType : public std::logic_error
{
    public:
        UnsupportedRtpSessionType (const std::string& msg = "") : std::logic_error (msg) {}
};

class AudioRtpFactoryException : public std::logic_error
{
    public:
        AudioRtpFactoryException (const std::string& msg = "") : std::logic_error (msg) {}
};
64

Julien Bonjean's avatar
Julien Bonjean committed
65
66
67
class AudioRtpFactory
{
    public:
68
        AudioRtpFactory(SIPCall *ca);
69
70
        ~AudioRtpFactory();

71
        void initAudioRtpConfig ();
Julien Bonjean's avatar
Julien Bonjean committed
72
73
74
75
76

        /**
         * 	Lazy instantiation method. Create a new RTP session of a given
         * type according to the content of the configuration file.
         * @param ca A pointer on a SIP call
77
         * @return A new AudioSymmetricRtpSession object
Julien Bonjean's avatar
Julien Bonjean committed
78
         */
79
        void initAudioSymmetricRtpSession ();
Julien Bonjean's avatar
Julien Bonjean committed
80
81
82

        /**
         * Start the audio rtp thread of the type specified in the configuration
83
         * file. initAudioSymmetricRtpSession must have been called prior to that.
Julien Bonjean's avatar
Julien Bonjean committed
84
85
86
87
88
89
         * @param None
         */
        void start (AudioCodec*);

        /**
         * Stop the audio rtp thread of the type specified in the configuration
90
         * file. initAudioSymmetricRtpSession must have been called prior to that.
Julien Bonjean's avatar
Julien Bonjean committed
91
92
93
94
         * @param None
         */
        void stop();

95
96
97
98
99
100
101
102
103
104
        /**
         * Return the RTP payload currently used for this session
         */
        int getSessionMedia();

        /**
         * Dynamically update session media
         */
        void updateSessionMedia (AudioCodec *);

Julien Bonjean's avatar
Julien Bonjean committed
105
106
107
108
109
110
        /**
         * Update current RTP destination address with one stored in call
         * @param None
         */
        void updateDestinationIpAddress (void);

111
112
        bool isSdesEnabled (void) const {
        	return _srtpEnabled && _keyExchangeProtocol == sfl::Sdes;
Julien Bonjean's avatar
Julien Bonjean committed
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
        }

        /**
         * Manually set the srtpEnable option (usefull for RTP fallback)
         */
        void setSrtpEnabled (bool enable) {
            _srtpEnabled = enable;
        }

        /**
         * Get the current AudioZrtpSession. Throws an AudioRtpFactoryException
         * if the current rtp thread is null, or if it's not of the correct type.
         * @return The current AudioZrtpSession thread.
         */
        sfl::AudioZrtpSession * getAudioZrtpSession();

129
        void initLocalCryptoInfo ();
130

Julien Bonjean's avatar
Julien Bonjean committed
131
132
133
134
135
136
        /**
         * Set remote cryptographic info. Should be called after negotiation in SDP
         * offer/answer session.
         */
        void setRemoteCryptoInfo (sfl::SdesNegotiator& nego);

137
138
        void setDtmfPayloadType(unsigned int);

Julien Bonjean's avatar
Julien Bonjean committed
139
140
141
142
143
144
145
146
147
        /**
         * Send DTMF over RTP (RFC2833). The timestamp and sequence number must be
         * incremented as if it was microphone audio. This function change the payload type of the rtp session,
         * send the appropriate DTMF digit using this payload, discard coresponding data from mainbuffer and get
         * back the codec payload for further audio processing.
         */
        void sendDtmfDigit (int digit);

    private:
148
        AudioRtpSession *_rtpSession;
Julien Bonjean's avatar
Julien Bonjean committed
149
150
151
152
153
154
155
156
        ost::Mutex _audioRtpThreadMutex;

        // Field used when initializinga udio rtp session
        // May be set manually or from config using initAudioRtpConfig
        bool _srtpEnabled;

        // Field used when initializinga udio rtp session
        // May be set manually or from config using initAudioRtpConfig
157
        RtpMethod _keyExchangeProtocol;
Julien Bonjean's avatar
Julien Bonjean committed
158
159
160
161

        // Field used when initializinga udio rtp session
        // May be set manually or from config using initAudioRtpConfig
        bool _helloHashEnabled;
162
163
164
165
166
167

        /** Remote srtp crypto context to be set into incoming data queue. */
        ost::CryptoContext *remoteContext;

        /** Local srtp crypto context to be set into outgoing data queue. */
        ost::CryptoContext *localContext;
168
169

        SIPCall *ca_;
170
};
171
172
}
#endif // __AUDIO_RTP_FACTORY_H__