blob: 960af2f1d3864d902b5b9f6db72264c2ac64c587 [file] [log] [blame]
Emeric Vigier2f625822012-08-06 11:09:52 -04001// 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
26namespace 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 */
36class KeyRTP : public Keydata
37{
38public:
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 */
76class KeyAudio : public Keydata
77{
78public:
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 */
92class KeyThreads : public Keydata
93{
94public:
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 */
148class RTPEvent
149{
150private:
151 friend class RTPAudio;
152
153 static RTPEvent *first;
154 RTPEvent *next;
155
156protected:
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 */
174class RTPAudio : public RTPSocket
175{
176private:
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
184public:
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 */
196class DevAudio
197{
198protected:
199 DevAudio();
200
201public:
202 virtual void open(void) = 0; // open device channel
203 virtual void close(void) = 0; // close device channel
204};
205
206extern bool multicast;
207extern bool daemon;
208extern KeyThreads keythreads;
209extern KeyRTP keyrtp;
210extern KeyAudio keyaudio;
211extern RTPAudio *rtp;
212extern DevAudio *audio;
213
214#ifdef CCXX_NAMESPACES
215}
216#endif
217
218#endif