iaxcall.h 4.99 KB
Newer Older
1
/*
Adrien Béraud's avatar
Adrien Béraud committed
2
 *  Copyright (C) 2004-2015 Savoir-Faire Linux Inc.
3
 *  Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com>
4
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
Guillaume Roguez's avatar
Guillaume Roguez committed
5
 *  Author : Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
6 7 8
 *
 *  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
9
 *  the Free Software Foundation; either version 3 of the License, or
10 11 12 13 14 15 16 17 18
 *  (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.
 *
 *  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 24 25 26 27 28 29 30
 *
 *  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.
31 32 33 34
 */
#ifndef IAXCALL_H
#define IAXCALL_H

35 36 37 38
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

39
#include "call.h"
40
#include "noncopyable.h"
Emmanuel Milou's avatar
Emmanuel Milou committed
41

Guillaume Roguez's avatar
Guillaume Roguez committed
42
class iax_session;
43

Adrien Béraud's avatar
Adrien Béraud committed
44
namespace ring {
Guillaume Roguez's avatar
Guillaume Roguez committed
45 46 47 48

class IAXAccount;
class RingBuffer;
class AudioBuffer;
49

Éloi Bail's avatar
Éloi Bail committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
/** Enumeration that contains known audio payloads */
enum {
    // http://www.iana.org/assignments/rtp-parameters
    // http://www.gnu.org/software/ccrtp/doc/refman/html/formats_8h.html#a0
    // 0 PCMU A 8000 1 [RFC3551]
    PAYLOAD_CODEC_ULAW = 0,
    // 3 GSM  A 8000 1 [RFC3551]
    PAYLOAD_CODEC_GSM = 3,
    // 8 PCMA A 8000 1 [RFC3551]
    PAYLOAD_CODEC_ALAW = 8,
    // 9 G722 A 8000 1 [RFC3551]
    PAYLOAD_CODEC_G722 = 9,
    // http://www.ietf.org/rfc/rfc3952.txt
    // 97 iLBC/8000
    PAYLOAD_CODEC_ILBC_20 = 97,
    PAYLOAD_CODEC_ILBC_30 = 98,
    // http://www.speex.org/drafts/draft-herlein-speex-rtp-profile-00.txt
    //  97 speex/8000
    // http://support.xten.com/viewtopic.php?p=8684&sid=3367a83d01fdcad16c7459a79859b08e
    // 100 speex/16000
    PAYLOAD_CODEC_SPEEX_8000 = 110,
    PAYLOAD_CODEC_SPEEX_16000 = 111,
    PAYLOAD_CODEC_SPEEX_32000 = 112
};


76
/**
77
 * @file: iaxcall.h
Julien Bonjean's avatar
Julien Bonjean committed
78
 * @brief IAXCall are IAX implementation of a normal Call
79
 */
80

Guillaume Roguez's avatar
Guillaume Roguez committed
81 82
class IAXCall : public Call
{
Julien Bonjean's avatar
Julien Bonjean committed
83
    public:
Guillaume Roguez's avatar
Guillaume Roguez committed
84 85 86
        static const char* const LINK_TYPE;

    protected:
Julien Bonjean's avatar
Julien Bonjean committed
87 88 89 90 91
        /**
         * Constructor
         * @param id  The unique ID of the call
         * @param type  The type of the call
         */
Guillaume Roguez's avatar
Guillaume Roguez committed
92
        IAXCall(IAXAccount& account, const std::string& id, Call::CallType type);
Julien Bonjean's avatar
Julien Bonjean committed
93

Guillaume Roguez's avatar
Guillaume Roguez committed
94
    public:
95 96 97 98
        const char* getLinkType() const override {
            return LINK_TYPE;
        }

Julien Bonjean's avatar
Julien Bonjean committed
99 100 101
        /**
         * @return int  The bitwise list of supported formats
         */
102
        int getSupportedFormat(const std::string &accountID) const;
Julien Bonjean's avatar
Julien Bonjean committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116

        /**
         * Return a format (int) with the first matching codec selected.
         *
         * This considers the order of the appearance in the CodecMap,
         * thus, the order of preference.
         *
         * NOTE: Everything returned is bound to the content of the local
         *       CodecMap, so it won't return format values that aren't valid
         *       in this call context.
         *
         * @param needles  The format(s) (bitwise) you are looking for to match
         * @return int  The matching format, thus 0 if none matches
         */
117
        int getFirstMatchingFormat(int needles, const std::string &accountID) const;
Julien Bonjean's avatar
Julien Bonjean committed
118

Éloi Bail's avatar
Éloi Bail committed
119
        int getAudioCodecPayload() const;
Julien Bonjean's avatar
Julien Bonjean committed
120

Rafaël Carré's avatar
Rafaël Carré committed
121 122
        int format;
        iax_session* session;
123

124
        void answer() override;
125

126
        void hangup(int reason) override;
127

128
        void refuse() override;
129

130
        void transfer(const std::string& to) override;
131

132
        bool attendedTransfer(const std::string& to) override;
133

134
        bool onhold() override;
135

136
        bool offhold() override;
137

Éloi Bail's avatar
Éloi Bail committed
138
        //TODO: implement mute for IAX
Alexandre Lision's avatar
Alexandre Lision committed
139
        void muteMedia(const std::string& /*mediaType*/, bool /*isMuted*/) override {}
Éloi Bail's avatar
Éloi Bail committed
140

Éloi Bail's avatar
Éloi Bail committed
141
        //TODO: implement restartMedia for IAX
142
        void restartMediaSender() override {}
Éloi Bail's avatar
Éloi Bail committed
143

144
        void peerHungup() override;
145

146
        void carryingDTMFdigits(char code) override;
147

148
#if HAVE_INSTANT_MESSAGING
149 150
        void sendTextMessage(const std::map<std::string, std::string>& messages,
                             const std::string &from) override;
151 152
#endif

Guillaume Roguez's avatar
Guillaume Roguez committed
153
        void putAudioData(AudioBuffer& buf);
154

155 156
    private:
        NON_COPYABLE(IAXCall);
157 158

        // Incoming audio ring buffer
Guillaume Roguez's avatar
Guillaume Roguez committed
159
        std::shared_ptr<RingBuffer> ringbuffer_{};
160 161
};

Guillaume Roguez's avatar
Guillaume Roguez committed
162 163
} // namespace ring

164
#endif