~ubuntu-branches/ubuntu/saucy/sflphone/saucy

« back to all changes in this revision

Viewing changes to sflphone-common/src/audio/audiortp/AudioRtpFactory.h

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2010-12-24 16:33:55 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20101224163355-tkvvikqxbrbav6up
Tags: 0.9.11-1
* New upstream release
* Add new build dependencies on libwebkit-dev and libyaml-dev

* Bump Standards-Version up to 3.9.1
* Bump debhelper compatibility to 8
* Patch another typo in the upstream code (lintian notice)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *  Copyright (C) 2004, 2005, 2006, 2009, 2008, 2009, 2010 Savoir-Faire Linux Inc.
3
3
 *  Author: Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com>
4
 
 * 
 
4
 *  Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
 
5
 *
5
6
 *  This program is free software; you can redistribute it and/or modify
6
7
 *  it under the terms of the GNU General Public License as published by
7
8
 *  the Free Software Foundation; either version 3 of the License, or
10
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
13
 *  GNU General Public License for more details.
13
 
 * 
 
14
 *
14
15
 *  You should have received a copy of the GNU General Public License
15
16
 *  along with this program; if not, write to the Free Software
16
17
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
39
40
class SdesNegotiator;
40
41
class SIPCall;
41
42
 
42
 
namespace sfl {
43
 
    class AudioZrtpSession;
44
 
    class AudioSrtpSession;
45
 
    class AudioSymmetricRtpSession;
 
43
/*
 
44
namespace sfl
 
45
{
 
46
class AudioZrtpSession;
 
47
class AudioSrtpSession;
 
48
class AudioSymmetricRtpSession;
46
49
}
47
 
 
48
 
namespace sfl {
49
 
 
50
 
    class AudioZrtpSession;
51
 
    class AudioSrtpSession;
52
 
 
53
 
    // Possible kind of rtp session
54
 
    typedef enum RtpMethod {
55
 
        Symmetric,
56
 
        Zrtp,
57
 
        Sdes
58
 
    } RtpMethod;
59
 
 
60
 
 
61
 
    class UnsupportedRtpSessionType : public std::logic_error {
62
 
        public:
63
 
        UnsupportedRtpSessionType(const std::string& msg = "") : std::logic_error(msg) {}
64
 
    };
65
 
    
66
 
    class AudioRtpFactoryException : public std::logic_error {
67
 
        public:
68
 
        AudioRtpFactoryException(const std::string& msg = "") : std::logic_error(msg) {}
69
 
    };
70
 
 
71
 
    class AudioRtpFactory {
72
 
        public:
 
50
*/
 
51
 
 
52
namespace sfl
 
53
{
 
54
 
 
55
class AudioZrtpSession;
 
56
class AudioSrtpSession;
 
57
class AudioSymmetricRtpSession;
 
58
 
 
59
// Possible kind of rtp session
 
60
typedef enum RtpMethod {
 
61
    Symmetric,
 
62
    Zrtp,
 
63
    Sdes
 
64
} RtpMethod;
 
65
 
 
66
 
 
67
class UnsupportedRtpSessionType : public std::logic_error
 
68
{
 
69
    public:
 
70
        UnsupportedRtpSessionType (const std::string& msg = "") : std::logic_error (msg) {}
 
71
};
 
72
 
 
73
class AudioRtpFactoryException : public std::logic_error
 
74
{
 
75
    public:
 
76
        AudioRtpFactoryException (const std::string& msg = "") : std::logic_error (msg) {}
 
77
};
 
78
 
 
79
class AudioRtpFactory
 
80
{
 
81
    public:
73
82
        AudioRtpFactory();
74
 
        AudioRtpFactory(SIPCall * ca);
 
83
        AudioRtpFactory (SIPCall * ca);
75
84
        ~AudioRtpFactory();
76
85
 
77
 
        void initAudioRtpConfig(SIPCall *ca);
78
 
 
79
 
        /**
80
 
         *      Lazy instantiation method. Create a new RTP session of a given
81
 
         * type according to the content of the configuration file.
82
 
         * @param ca A pointer on a SIP call
83
 
         * @return A new AudioRtpSession object
84
 
         */
85
 
        void initAudioRtpSession(SIPCall *ca);
86
 
 
87
 
        /**
88
 
         * Start the audio rtp thread of the type specified in the configuration
89
 
         * file. initAudioRtpSession must have been called prior to that.
90
 
         * @param None
91
 
         */
92
 
        void start(AudioCodec*);
93
 
 
94
 
        /**
95
 
         * Stop the audio rtp thread of the type specified in the configuration
96
 
         * file. initAudioRtpSession must have been called prior to that.
97
 
         * @param None
98
 
         */
99
 
        void stop();
100
 
 
101
 
        /**
102
 
         * Update current RTP destination address with one stored in call
103
 
         * @param None
104
 
         */
105
 
        void updateDestinationIpAddress (void);
106
 
          
107
 
        /**
108
 
         * @param None
109
 
         * @return The internal audio rtp thread of the type specified in the configuration
110
 
         * file. initAudioRtpSession must have been called prior to that.
111
 
         */
112
 
        inline void * getAudioRtpSession(void) { return _rtpSession; }
113
 
 
114
 
        AudioSymmetricRtpSession * getAudioSymetricRtpSession();
115
 
 
116
 
        /** 
117
 
         * @param None
118
 
         * @return The internal audio rtp session type
119
 
         *         Symmetric = 0
120
 
         *         Zrtp = 1
121
 
         *         Sdes = 2
122
 
         */
123
 
        inline RtpMethod getAudioRtpType(void) { return _rtpSessionType; }
124
 
        
125
 
        /**
126
 
         * @param Set internal audio rtp session type (Symmetric, Zrtp, Sdes)
127
 
         */
128
 
        inline void setAudioRtpType(RtpMethod type) { _rtpSessionType = type; }
129
 
 
130
 
        /**
131
 
         * Manually set the srtpEnable option (usefull for RTP fallback)
132
 
         */
133
 
        void setSrtpEnabled(bool enable){ _srtpEnabled = enable; }
134
 
 
135
 
        /**
136
 
         * Manually set the keyExchangeProtocol parameter (usefull for RTP fallback)
137
 
         */
138
 
        void setKeyExchangeProtocol(int proto){ _keyExchangeProtocol = proto; }
139
 
 
140
 
        /**
141
 
         * Manually set the setHelloHashEnabled parameter (usefull for RTP fallback)
142
 
         */
143
 
        void setHelloHashEnabled(bool enable){ _helloHashEnabled = enable; }
144
 
 
145
 
        /**
146
 
         * Get the current AudioZrtpSession. Throws an AudioRtpFactoryException
147
 
         * if the current rtp thread is null, or if it's not of the correct type.
148
 
         * @return The current AudioZrtpSession thread.
149
 
         */
150
 
        sfl::AudioZrtpSession * getAudioZrtpSession();
151
 
 
152
 
        /**
153
 
         * Set remote cryptographic info. Should be called after negotiation in SDP
154
 
         * offer/answer session.
155
 
         */
156
 
        void setRemoteCryptoInfo(sfl::SdesNegotiator& nego);
157
 
 
158
 
        /**
159
 
         * Send DTMF over RTP (RFC2833). The timestamp and sequence number must be
160
 
         * incremented as if it was microphone audio. This function change the payload type of the rtp session,
161
 
         * send the appropriate DTMF digit using this payload, discard coresponding data from mainbuffer and get
162
 
         * back the codec payload for further audio processing.
163
 
         */
164
 
        void sendDtmfDigit(int digit);
165
 
        
166
 
private:
167
 
        void * _rtpSession;
168
 
        RtpMethod _rtpSessionType;
169
 
        ost::Mutex _audioRtpThreadMutex;
170
 
 
171
 
        // Field used when initializinga udio rtp session
172
 
        // May be set manually or from config using initAudioRtpConfig
173
 
        bool _srtpEnabled;
174
 
 
175
 
        // Field used when initializinga udio rtp session
176
 
        // May be set manually or from config using initAudioRtpConfig
177
 
        int _keyExchangeProtocol;
178
 
 
179
 
        // Field used when initializinga udio rtp session
180
 
        // May be set manually or from config using initAudioRtpConfig
181
 
        bool _helloHashEnabled;
 
86
        void initAudioRtpConfig (SIPCall *ca);
 
87
 
 
88
        /**
 
89
         *      Lazy instantiation method. Create a new RTP session of a given
 
90
         * type according to the content of the configuration file.
 
91
         * @param ca A pointer on a SIP call
 
92
         * @return A new AudioRtpSession object
 
93
         */
 
94
        void initAudioRtpSession (SIPCall *ca);
 
95
 
 
96
        /**
 
97
         * Start the audio rtp thread of the type specified in the configuration
 
98
         * file. initAudioRtpSession must have been called prior to that.
 
99
         * @param None
 
100
         */
 
101
        void start (AudioCodec*);
 
102
 
 
103
        /**
 
104
         * Stop the audio rtp thread of the type specified in the configuration
 
105
         * file. initAudioRtpSession must have been called prior to that.
 
106
         * @param None
 
107
         */
 
108
        void stop();
 
109
 
 
110
        /**
 
111
         * Update current RTP destination address with one stored in call
 
112
         * @param None
 
113
         */
 
114
        void updateDestinationIpAddress (void);
 
115
 
 
116
        /**
 
117
         * @param None
 
118
         * @return The internal audio rtp thread of the type specified in the configuration
 
119
         * file. initAudioRtpSession must have been called prior to that.
 
120
         */
 
121
        inline void * getAudioRtpSession (void) {
 
122
            return _rtpSession;
 
123
        }
 
124
 
 
125
        AudioSymmetricRtpSession * getAudioSymetricRtpSession();
 
126
 
 
127
        /**
 
128
         * @param None
 
129
         * @return The internal audio rtp session type
 
130
         *         Symmetric = 0
 
131
         *         Zrtp = 1
 
132
         *         Sdes = 2
 
133
         */
 
134
        inline RtpMethod getAudioRtpType (void) {
 
135
            return _rtpSessionType;
 
136
        }
 
137
 
 
138
        /**
 
139
         * @param Set internal audio rtp session type (Symmetric, Zrtp, Sdes)
 
140
         */
 
141
        inline void setAudioRtpType (RtpMethod type) {
 
142
            _rtpSessionType = type;
 
143
        }
 
144
 
 
145
        /**
 
146
         * Manually set the srtpEnable option (usefull for RTP fallback)
 
147
         */
 
148
        void setSrtpEnabled (bool enable) {
 
149
            _srtpEnabled = enable;
 
150
        }
 
151
 
 
152
        /**
 
153
         * Manually set the keyExchangeProtocol parameter (usefull for RTP fallback)
 
154
         */
 
155
        void setKeyExchangeProtocol (int proto) {
 
156
            _keyExchangeProtocol = proto;
 
157
        }
 
158
 
 
159
        /**
 
160
         * Manually set the setHelloHashEnabled parameter (usefull for RTP fallback)
 
161
         */
 
162
        void setHelloHashEnabled (bool enable) {
 
163
            _helloHashEnabled = enable;
 
164
        }
 
165
 
 
166
        /**
 
167
         * Get the current AudioZrtpSession. Throws an AudioRtpFactoryException
 
168
         * if the current rtp thread is null, or if it's not of the correct type.
 
169
         * @return The current AudioZrtpSession thread.
 
170
         */
 
171
        sfl::AudioZrtpSession * getAudioZrtpSession();
 
172
 
 
173
        void initLocalCryptoInfo (SIPCall *ca);
 
174
 
 
175
        /**
 
176
         * Set remote cryptographic info. Should be called after negotiation in SDP
 
177
         * offer/answer session.
 
178
         */
 
179
        void setRemoteCryptoInfo (sfl::SdesNegotiator& nego);
 
180
 
 
181
        /**
 
182
         * Send DTMF over RTP (RFC2833). The timestamp and sequence number must be
 
183
         * incremented as if it was microphone audio. This function change the payload type of the rtp session,
 
184
         * send the appropriate DTMF digit using this payload, discard coresponding data from mainbuffer and get
 
185
         * back the codec payload for further audio processing.
 
186
         */
 
187
        void sendDtmfDigit (int digit);
 
188
 
 
189
    private:
 
190
        void * _rtpSession;
 
191
        RtpMethod _rtpSessionType;
 
192
        ost::Mutex _audioRtpThreadMutex;
 
193
 
 
194
        // Field used when initializinga udio rtp session
 
195
        // May be set manually or from config using initAudioRtpConfig
 
196
        bool _srtpEnabled;
 
197
 
 
198
        // Field used when initializinga udio rtp session
 
199
        // May be set manually or from config using initAudioRtpConfig
 
200
        int _keyExchangeProtocol;
 
201
 
 
202
        // Field used when initializinga udio rtp session
 
203
        // May be set manually or from config using initAudioRtpConfig
 
204
        bool _helloHashEnabled;
182
205
};
183
206
}
184
207
#endif // __AUDIO_RTP_FACTORY_H__