Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 1 | // Copyright (C) 2000-2005 Open Source Telecom Corporation. |
| 2 | // Copyright (C) 2006-2008 David Sugar, Tycho Softworks. |
| 3 | // |
| 4 | // This program is free software; you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation; either version 2 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program; if not, write to the Free Software |
| 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | |
| 18 | #ifndef CCXX_PHONE_H_ |
| 19 | #define CCXX_PHONE_H_ |
| 20 | |
| 21 | #ifndef CCXX_RTP_H_ |
| 22 | #include <ccrtp/rtp.h> |
| 23 | #endif |
| 24 | |
| 25 | #ifdef CCXX_NAMESPACES |
| 26 | namespace ost { |
| 27 | #endif |
| 28 | |
| 29 | /** |
| 30 | * Load /etc/phone.conf [thread] key value pairs. Has internal defaults |
| 31 | * if section or file is missing. |
| 32 | * |
| 33 | * @author David Sugar <dyfet@ostel.com> |
| 34 | * @short Load keythreads priority and session count configuration. |
| 35 | */ |
| 36 | class KeyRTP : public Keydata |
| 37 | { |
| 38 | public: |
| 39 | /** |
| 40 | * Initialize keythread data. |
| 41 | */ |
| 42 | KeyRTP(); |
| 43 | |
| 44 | /** |
| 45 | * Get unicast address. |
| 46 | */ |
| 47 | inline InetHostAddress getInterface(void) |
| 48 | {return InetHostAddress(getLast("interface"));}; |
| 49 | |
| 50 | /** |
| 51 | * Get binding port number. |
| 52 | */ |
| 53 | inline tpport_t getPort(void) |
| 54 | {return (tpport_t) atoi(getLast("port"));}; |
| 55 | |
| 56 | /** |
| 57 | * Get stack timer. |
| 58 | */ |
| 59 | inline microtimeout_t getTimer(void) |
| 60 | {return (microtimeout_t)atol(getLast("timer")) * 1000l;}; |
| 61 | |
| 62 | /** |
| 63 | * Get packet expiration timer. |
| 64 | */ |
| 65 | inline microtimeout_t getExpire(void) |
| 66 | {return (microtimeout_t)atol(getLast("expire")) * 1000l;}; |
| 67 | }; |
| 68 | |
| 69 | /** |
| 70 | * Load /etc/phone.conf [audio] key value pairs. Has internal defaults |
| 71 | * if section or file is missing. |
| 72 | * |
| 73 | * @author David Sugar <dyfet@ostel.com> |
| 74 | * @short Load keythreads priority and session count configuration. |
| 75 | */ |
| 76 | class KeyAudio : public Keydata |
| 77 | { |
| 78 | public: |
| 79 | /** |
| 80 | * Initialize keythread data. |
| 81 | */ |
| 82 | KeyAudio(); |
| 83 | }; |
| 84 | |
| 85 | /** |
| 86 | * Load /etc/phone.conf [thread] key value pairs. Has internal defaults |
| 87 | * if section or file is missing. |
| 88 | * |
| 89 | * @author David Sugar <dyfet@ostel.com> |
| 90 | * @short Load keythreads priority and session count configuration. |
| 91 | */ |
| 92 | class KeyThreads : public Keydata |
| 93 | { |
| 94 | public: |
| 95 | /** |
| 96 | * Initialize keythread data. |
| 97 | */ |
| 98 | KeyThreads(); |
| 99 | |
| 100 | /** |
| 101 | * Get relative priority to run service threads at. |
| 102 | * |
| 103 | * @return audio thread priority (relative). |
| 104 | */ |
| 105 | inline int priAudio(void) |
| 106 | {return atoi(getLast("audio"));}; |
| 107 | |
| 108 | /** |
| 109 | * Get relative priority for the rtp stack. |
| 110 | * |
| 111 | * @return audio thread priority (relative). |
| 112 | */ |
| 113 | inline int priRTP(void) |
| 114 | {return atoi(getLast("rtp"));}; |
| 115 | |
| 116 | /** |
| 117 | * Get relative process priority. |
| 118 | * |
| 119 | * @return rtp stack thread priority (relative). |
| 120 | */ |
| 121 | inline int getPriority(void) |
| 122 | {return atoi(getLast("priority"));}; |
| 123 | |
| 124 | /** |
| 125 | * Get thread stack frame size. |
| 126 | * |
| 127 | * @return thread stack frame in k. |
| 128 | */ |
| 129 | inline unsigned getStack(void) |
| 130 | {return atoi(getLast("stack"));}; |
| 131 | |
| 132 | |
| 133 | /** |
| 134 | * Get scheduler policy to use. |
| 135 | * |
| 136 | * @return scheduler policy. |
| 137 | */ |
| 138 | inline const char *getPolicy(void) |
| 139 | {return getLast("priority");}; |
| 140 | }; |
| 141 | |
| 142 | /** |
| 143 | * Process RTP Events for plugins and special purpose classes. |
| 144 | * |
| 145 | * @author David Sugar <dyfet@ostel.com> |
| 146 | * @short RTP event processing. |
| 147 | */ |
| 148 | class RTPEvent |
| 149 | { |
| 150 | private: |
| 151 | friend class RTPAudio; |
| 152 | |
| 153 | static RTPEvent *first; |
| 154 | RTPEvent *next; |
| 155 | |
| 156 | protected: |
| 157 | RTPEvent(); |
| 158 | |
| 159 | virtual void gotHello(const SyncSource &src) |
| 160 | {return;}; |
| 161 | |
| 162 | virtual void gotGoodbye(const SyncSource &src, |
| 163 | const std::string& reason) |
| 164 | {return;}; |
| 165 | }; |
| 166 | |
| 167 | /** |
| 168 | * This is the base session stack that will maintain all network audio |
| 169 | * activity. |
| 170 | * |
| 171 | * @author David Sugar <dyfet@ostel.com> |
| 172 | * @short RTP stack for network audio. |
| 173 | */ |
| 174 | class RTPAudio : public RTPSocket |
| 175 | { |
| 176 | private: |
| 177 | unsigned groups; // multicast groups joined |
| 178 | bool unicast; // indicate if in unicast call |
| 179 | bool shutdown; // tracks shutdown state |
| 180 | |
| 181 | void onGotHello(const SyncSource &src); |
| 182 | void onGotGoodbye(const SyncSource &src, const std::string& reason); |
| 183 | |
| 184 | public: |
| 185 | RTPAudio(); |
| 186 | |
| 187 | void exit(const char *reason); |
| 188 | }; |
| 189 | |
| 190 | /** |
| 191 | * This is the base interface for DSO loadable audio devices. |
| 192 | * |
| 193 | * @author David Sugar <dyfet@ostel.com> |
| 194 | * @short base class for Audio devices. |
| 195 | */ |
| 196 | class DevAudio |
| 197 | { |
| 198 | protected: |
| 199 | DevAudio(); |
| 200 | |
| 201 | public: |
| 202 | virtual void open(void) = 0; // open device channel |
| 203 | virtual void close(void) = 0; // close device channel |
| 204 | }; |
| 205 | |
| 206 | extern bool multicast; |
| 207 | extern bool daemon; |
| 208 | extern KeyThreads keythreads; |
| 209 | extern KeyRTP keyrtp; |
| 210 | extern KeyAudio keyaudio; |
| 211 | extern RTPAudio *rtp; |
| 212 | extern DevAudio *audio; |
| 213 | |
| 214 | #ifdef CCXX_NAMESPACES |
| 215 | } |
| 216 | #endif |
| 217 | |
| 218 | #endif |