Moved function that reads User Input into a destination address to
[opal.git] / include / opal / manager.h
blob4933f268de408759094009dc7bd80234a57a69a6
1 /*
2 * manager.h
4 * OPAL system manager.
6 * Open Phone Abstraction Library (OPAL)
7 * Formally known as the Open H323 project.
9 * Copyright (c) 2001 Equivalence Pty. Ltd.
11 * The contents of this file are subject to the Mozilla Public License
12 * Version 1.0 (the "License"); you may not use this file except in
13 * compliance with the License. You may obtain a copy of the License at
14 * http://www.mozilla.org/MPL/
16 * Software distributed under the License is distributed on an "AS IS"
17 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
18 * the License for the specific language governing rights and limitations
19 * under the License.
21 * The Original Code is Open Phone Abstraction Library.
23 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
25 * Contributor(s): ______________________________________.
27 * $Log$
28 * Revision 2.51 2006/11/19 06:02:58 rjongbloed
29 * Moved function that reads User Input into a destination address to
30 * OpalManager so can be easily overidden in applications.
32 * Revision 2.50 2006/10/10 07:18:18 csoutheren
33 * Allow compilation with and without various options
35 * Revision 2.49 2006/09/28 07:42:17 csoutheren
36 * Merge of useful SRTP implementation
38 * Revision 2.48 2006/06/21 23:43:27 csoutheren
39 * Fixed comment on OpalManager::SetTranslationAddress
41 * Revision 2.47 2006/06/21 04:54:15 csoutheren
42 * Fixed build with latest PWLib
44 * Revision 2.46 2006/04/20 16:52:22 hfriederich
45 * Adding support for H.224/H.281
47 * Revision 2.45 2005/11/30 13:35:26 csoutheren
48 * Changed tags for Doxygen
50 * Revision 2.44 2005/11/24 20:31:54 dsandras
51 * Added support for echo cancelation using Speex.
52 * Added possibility to add a filter to an OpalMediaPatch for all patches of a connection.
54 * Revision 2.43 2005/10/08 19:26:38 dsandras
55 * Added OnForwarded callback in case of call forwarding.
57 * Revision 2.42 2005/09/20 07:25:43 csoutheren
58 * Allow userdata to be passed from SetupCall through to Call and Connection constructors
60 * Revision 2.41 2005/08/24 10:43:51 rjongbloed
61 * Changed create video functions yet again so can return pointers that are not to be deleted.
63 * Revision 2.40 2005/08/23 12:45:09 rjongbloed
64 * Fixed creation of video preview window and setting video grab/display initial frame size.
66 * Revision 2.39 2005/07/14 08:51:18 csoutheren
67 * Removed CreateExternalRTPAddress - it's not needed because you can override GetMediaAddress
68 * to do the same thing
69 * Fixed problems with logic associated with media bypass
71 * Revision 2.38 2005/07/11 06:52:16 csoutheren
72 * Added support for outgoing calls using external RTP
74 * Revision 2.37 2005/07/11 01:52:24 csoutheren
75 * Extended AnsweringCall to work for SIP as well as H.323
76 * Fixed problems with external RTP connection in H.323
77 * Added call to OnClosedMediaStream
79 * Revision 2.36 2005/07/09 06:57:20 rjongbloed
80 * Changed SetSTUNServer so returns the determined NAT type.
82 * Revision 2.35 2005/06/13 23:13:53 csoutheren
83 * Fixed various typos thanks to Julien PUYDT
85 * Revision 2.34 2005/05/25 17:04:08 dsandras
86 * Fixed ClearAllCalls when being executed synchronously. Fixes a crash on exit when a call is in progress. Thanks Robert!
88 * Revision 2.33 2005/04/10 20:46:56 dsandras
89 * Added callback that is called when a connection is put on hold (locally or remotely).
91 * Revision 2.32 2005/01/31 07:37:09 csoutheren
92 * Fixed problem with compiling under gcc 3.4
93 * Thanks to Peter Robinson
95 * Revision 2.31 2004/12/21 08:24:31 dsandras
96 * The dictionnary key is a PString, not an OpalGloballyUniqueID. Fixes problem when doing several calls at the same time.
98 * Revision 2.30 2004/08/18 13:02:48 rjongbloed
99 * Changed to make calling OPalManager::OnClearedCall() in override optional.
101 * Revision 2.29 2004/08/14 07:56:29 rjongbloed
102 * Major revision to utilise the PSafeCollection classes for the connections and calls.
104 * Revision 2.28 2004/07/14 13:26:14 rjongbloed
105 * Fixed issues with the propagation of the "established" phase of a call. Now
106 * calling an OnEstablished() chain like OnAlerting() and OnConnected() to
107 * finally arrive at OnEstablishedCall() on OpalManager
109 * Revision 2.27 2004/07/11 12:42:10 rjongbloed
110 * Added function on endpoints to get the list of all media formats any
111 * connection the endpoint may create can support.
113 * Revision 2.26 2004/07/04 12:50:50 rjongbloed
114 * Added some access functions to manager lists
116 * Revision 2.25 2004/06/05 14:34:44 rjongbloed
117 * Added functions to set the auto start video tx/rx flags.
119 * Revision 2.24 2004/05/24 13:40:12 rjongbloed
120 * Added default values for silence suppression parameters.
122 * Revision 2.23 2004/05/15 12:53:03 rjongbloed
123 * Added default username and display name to manager, for all endpoints.
125 * Revision 2.22 2004/04/18 07:09:12 rjongbloed
126 * Added a couple more API functions to bring OPAL into line with similar functions in OpenH323.
128 * Revision 2.21 2004/03/11 06:54:27 csoutheren
129 * Added ability to disable SIP or H.323 stacks
131 * Revision 2.20 2004/02/24 11:37:01 rjongbloed
132 * More work on NAT support, manual external address translation and STUN
134 * Revision 2.19 2004/02/19 10:47:01 rjongbloed
135 * Merged OpenH323 version 1.13.1 changes.
137 * Revision 2.18 2004/01/18 15:36:07 rjongbloed
138 * Added stun support
140 * Revision 2.17 2003/03/17 10:26:59 robertj
141 * Added video support.
143 * Revision 2.16 2003/03/06 03:57:47 robertj
144 * IVR support (work in progress) requiring large changes everywhere.
146 * Revision 2.15 2002/11/10 11:33:17 robertj
147 * Updated to OpenH323 v1.10.3
149 * Revision 2.14 2002/09/16 02:52:35 robertj
150 * Added #define so can select if #pragma interface/implementation is used on
151 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
153 * Revision 2.13 2002/09/06 02:44:09 robertj
154 * Added routing table system to route calls by regular expressions.
156 * Revision 2.12 2002/09/04 06:01:47 robertj
157 * Updated to OpenH323 v1.9.6
159 * Revision 2.11 2002/07/01 04:56:31 robertj
160 * Updated to OpenH323 v1.9.1
162 * Revision 2.10 2002/04/10 08:15:31 robertj
163 * Added functions to set ports.
165 * Revision 2.9 2002/02/19 07:42:50 robertj
166 * Restructured media bypass functions to fix problems with RFC2833.
168 * Revision 2.8 2002/02/11 07:38:55 robertj
169 * Added media bypass for streams between compatible protocols.
171 * Revision 2.7 2002/01/22 05:04:58 robertj
172 * Revamp of user input API triggered by RFC2833 support
174 * Revision 2.6 2001/12/07 08:56:19 robertj
175 * Renamed RTP to be more general UDP port base, and TCP to be IP.
177 * Revision 2.5 2001/11/14 01:31:55 robertj
178 * Corrected placement of adjusting media format list.
180 * Revision 2.4 2001/11/13 06:25:56 robertj
181 * Changed SetUpConnection() so returns BOOL as returning
182 * pointer to connection is not useful.
184 * Revision 2.3 2001/08/23 05:51:17 robertj
185 * Completed implementation of codec reordering.
187 * Revision 2.2 2001/08/17 08:23:59 robertj
188 * Changed OnEstablished() to OnEstablishedCall() to be consistent.
189 * Moved call end reasons enum from OpalConnection to global.
191 * Revision 2.1 2001/08/01 05:52:55 robertj
192 * Moved media formats list from endpoint to connection.
193 * Added function to adjust calls media formats list.
195 * Revision 2.0 2001/07/27 15:48:24 robertj
196 * Conversion of OpenH323 to Open Phone Abstraction Library (OPAL)
200 #ifndef __OPAL_MANAGER_H
201 #define __OPAL_MANAGER_H
203 #ifdef P_USE_PRAGMA
204 #pragma interface
205 #endif
207 #include <opal/buildopts.h>
209 #include <opal/call.h>
210 #include <opal/guid.h>
211 #include <codec/silencedetect.h>
212 #include <codec/echocancel.h>
213 #include <ptclib/pstun.h>
215 #if OPAL_VIDEO
216 #include <ptlib/videoio.h>
217 #endif
219 class OpalEndPoint;
220 class OpalMediaPatch;
221 class OpalH224Handler;
222 class OpalH281Handler;
224 /**This class is the central manager for OPAL.
225 The OpalManager embodies the root of the tree of objects that constitute an
226 OPAL system. It contains all of the endpoints that make up the system. Other
227 entities such as media streams etc are in turn contained in these objects.
228 It is expected that an application would only ever have one instance of
229 this class, and also descend from it to override call back functions.
231 The manager is the eventual destination for call back indications from
232 various other objects. It is possible, for instance, to get an indication
233 of a completed call by creating a descendant of the OpalCall and overriding
234 the OnClearedCall() virtual. However, this could quite unwieldy for all of
235 the possible classes, so the default behaviour is to call the equivalent
236 function on the OpalManager. This allows most applications to only have to
237 create a descendant of the OpalManager and override virtual functions there
238 to get all the indications it needs.
240 class OpalManager : public PObject
242 PCLASSINFO(OpalManager, PObject);
243 public:
244 /**@name Construction */
245 //@{
246 /**Create a new manager.
248 OpalManager();
250 /**Destroy the manager.
251 This will clear all calls, then delete all endpoints still attached to
252 the manager.
254 ~OpalManager();
255 //@}
257 /**@name Endpoint management */
258 //@{
259 /**Attach a new endpoint to the manager.
260 This is an internal function called by the OpalEndPoint constructor.
262 Note that any endpoint is automatically "owned" by the manager. They
263 should not be deleted directly. The RemoveEndPoint() command should be
264 used to do this.
266 void AttachEndPoint(
267 OpalEndPoint * endpoint
270 /**Remove an endpoint from the manager.
271 This will delete the endpoint object.
273 void DetachEndPoint(
274 OpalEndPoint * endpoint
277 /**Find an endpoint instance that is using the specified prefix.
279 OpalEndPoint * FindEndPoint(
280 const PString & prefix
283 /**Get the endpoints attached to this manager.
285 const PList<OpalEndPoint> & GetEndPoints() const { return endpoints; }
286 //@}
288 /**@name Call management */
289 //@{
290 /**Set up a call between two parties.
291 This is used to initiate a call. Incoming calls are "answered" using a
292 different mechanism.
294 The A party and B party strings indicate the protocol and address of
295 the party to call in the style of a URL. The A party is the initiator
296 of the call and the B party is the remote system being called. See the
297 MakeConnection() function for more details on the format of these
298 strings.
300 The token returned is a unique identifier for the call that allows an
301 application to gain access to the call at later time. This is necesary
302 as any pointer being returned could become invalid (due to being
303 deleted) at any time due to the multithreaded nature of the OPAL
304 system. While this function does return a pointer it is only safe to
305 use immediately after the function returns. At any other time the
306 FindCallWithLock() function should be used to gain a locked pointer
307 to the call.
309 virtual BOOL SetUpCall(
310 const PString & partyA, ///< The A party of call
311 const PString & partyB, ///< The B party of call
312 PString & token, ///< Token for call
313 void * userData = NULL ///< user data passed to Call and Connection
316 /**A call back function whenever a call is completed.
317 In telephony terminology a completed call is one where there is an
318 established link between two parties.
320 This called from the OpalCall::OnEstablished() function.
322 The default behaviour does nothing.
324 virtual void OnEstablishedCall(
325 OpalCall & call ///< Call that was completed
328 /**Determine if a call is active.
329 Return TRUE if there is an active call with the specified token. Note
330 that the call could clear any time (even milliseconds) after this
331 function returns TRUE.
333 virtual BOOL HasCall(
334 const PString & token ///< Token for identifying call
335 ) { return activeCalls.FindWithLock(token, PSafeReference) != NULL; }
337 /**Determine if a call is established.
338 Return TRUE if there is an active call with the specified token and
339 that call has at least two parties with media flowing between them.
340 Note that the call could clear any time (even milliseconds) after this
341 function returns TRUE.
343 virtual BOOL IsCallEstablished(
344 const PString & token ///< Token for identifying call
347 /**Find a call with the specified token.
348 This searches the manager database for the call that contains the token
349 as provided by functions such as SetUpCall().
351 Note the caller of this function MUST call the OpalCall::Unlock()
352 function if this function returns a non-NULL pointer. If it does not
353 then a deadlock can occur.
355 PSafePtr<OpalCall> FindCallWithLock(
356 const PString & token, ///< Token to identify connection
357 PSafetyMode mode = PSafeReadWrite
358 ) { return activeCalls.FindWithLock(token, mode); }
360 /**Clear a call.
361 This finds the call by using the token then calls the OpalCall::Clear()
362 function on it. All connections are released, and the connections and
363 call are disposed of. Note that this function returns quickly and the
364 disposal happens at some later time in a background thread. It is safe
365 to call this function from anywhere.
367 virtual BOOL ClearCall(
368 const PString & token, ///< Token for identifying connection
369 OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser, ///< Reason for call clearing
370 PSyncPoint * sync = NULL ///< Sync point to wait on.
373 /**Clear a call.
374 This finds the call by using the token then calls the OpalCall::Clear()
375 function on it. All connections are released, and the connections and
376 call er disposed of. Note that this function waits until the call has
377 been cleared and all responses timeouts etc completed. Care must be
378 used as to when it is called as deadlocks may result.
380 virtual BOOL ClearCallSynchronous(
381 const PString & token, ///< Token for identifying connection
382 OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser ///< Reason for call clearing
385 /**Clear all current calls.
386 This effectively executes OpalCall::Clear() on every call that the
387 manager has active.
388 This function can not be called from several threads at the same time.
390 virtual void ClearAllCalls(
391 OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser, ///< Reason for call clearing
392 BOOL wait = TRUE ///< Flag to wait for calls to e cleared.
395 /**A call back function whenever a call is cleared.
396 A call is cleared whenever there is no longer any connections attached
397 to it. This function is called just before the call is deleted.
398 However, it may be used to display information on the call after
399 completion, eg the call parties and duration.
401 Note that there is not a one to one relationship with the
402 OnEstablishedCall() function. This function may be called without that
403 function being called. For example if MakeConnection() was used but
404 the call never completed.
406 The default behaviour removes the call from the activeCalls dictionary.
408 virtual void OnClearedCall(
409 OpalCall & call ///< Connection that was established
412 /**Create a call object.
413 This function allows an application to have the system create
414 desccendants of the OpalCall class instead of instances of that class
415 directly. The application can thus override call backs or add extra
416 information that it wishes to maintain on a call by call basis.
418 The default behavious returns an instance of OpalCall.
420 virtual OpalCall * CreateCall();
421 virtual OpalCall * CreateCall(
422 void * userData ///< user data passed to SetUpCall
425 /**Destroy a call object.
426 This gets called from background thread that garbage collects all calls
427 and connections. If an application has object lifetime issues with the
428 threading, it can override this function and take responsibility for
429 deleting the object at some later time.
431 The default behaviour simply calls "delete call".
433 virtual void DestroyCall(
434 OpalCall * call
437 /**Get next unique token ID for calls.
438 This is an internal function called by the OpalCall constructor.
440 PString GetNextCallToken();
441 //@}
443 /**@name Connection management */
444 //@{
445 /**Set up a connection to a remote party.
446 An appropriate protocol (endpoint) is determined from the party
447 parameter. That endpoint is then called to create a connection and that
448 connection is attached to the call provided.
450 If the endpoint is already occupied in a call then the endpoints list
451 is further searched for additional endpoints that support the protocol.
452 For example multiple pstn endpoints may be present for multiple LID's.
454 The general form for this party parameter is:
456 [proto:][alias@][transport$]address[:port]
458 where the various fields will have meanings specific to the endpoint
459 type. For example, with H.323 it could be "h323:Fred@site.com" which
460 indicates a user Fred at gatekeeper size.com. Whereas for the PSTN
461 endpoint it could be "pstn:5551234" which is to call 5551234 on the
462 first available PSTN line.
464 The default for the proto is the name of the protocol for the first
465 endpoint attached to the manager. Other fields default to values on an
466 endpoint basis.
468 This function usually returns almost immediately with the connection
469 continuing to occur in a new background thread.
471 If FALSE is returned then the connection could not be established. For
472 example if a PSTN endpoint is used and the associated line is engaged
473 then it may return immediately. Returning a non-NULL value does not
474 mean that the connection will succeed, only that an attempt is being
475 made.
477 The default behaviour is pure.
479 virtual BOOL MakeConnection(
480 OpalCall & call, ///< Owner of connection
481 const PString & party ///< Party to call
483 virtual BOOL MakeConnection(
484 OpalCall & call, ///< Owner of connection
485 const PString & party, ///< Party to call
486 void * userData ///< user data to pass to connections
489 /**Call back for answering an incoming call.
490 This function is used for an application to control the answering of
491 incoming calls.
493 If TRUE is returned then the connection continues. If FALSE then the
494 connection is aborted.
496 Note this function should not block for any length of time. If the
497 decision to answer the call may take some time eg waiting for a user to
498 pick up the phone, then AnswerCallPending or AnswerCallDeferred should
499 be returned.
501 If an application overrides this function, it should generally call the
502 ancestor version to complete calls. Unless the application completely
503 takes over that responsibility. Generally, an application would only
504 intercept this function if it wishes to do some form of logging. For
505 this you can obtain the name of the caller by using the function
506 OpalConnection::GetRemotePartyName().
508 The default behaviour is to call OnRouteConnection to determine a
509 B party for the connection.
511 If the call associated with the incoming call already had two parties
512 and this connection is a third party for a conference call then
513 AnswerCallNow is returned as a B party is not required.
515 virtual BOOL OnIncomingConnection(
516 OpalConnection & connection ///< Connection that is calling
519 /**Route a connection to another connection from an endpoint.
521 The default behaviour gets the destination address from the connection
522 and translates it into an address by using the routeTable member
523 variable.
525 virtual PString OnRouteConnection(
526 OpalConnection & connection ///< Connection being routed
529 /**Call back for remote party being alerted on outgoing call.
530 This function is called after the connection is informed that the
531 remote endpoint is "ringing". This function is generally called
532 some time after the MakeConnection() function was called.
534 If FALSE is returned the connection is aborted.
536 If an application overrides this function, it should generally call the
537 ancestor version for correct operation. An application would typically
538 only intercept this function if it wishes to do some form of logging.
539 For this you can obtain the name of the caller by using the function
540 OpalConnection::GetRemotePartyName().
542 The default behaviour calls the OnAlerting() on the connection's
543 associated OpalCall object.
545 virtual void OnAlerting(
546 OpalConnection & connection ///< Connection that was established
549 virtual OpalConnection::AnswerCallResponse
550 OnAnswerCall(OpalConnection & connection,
551 const PString & caller
554 /**A call back function whenever a connection is "connected".
555 This indicates that a connection to an endpoint was connected. That
556 is the endpoint received acknowledgement via whatever protocol it uses
557 that the connection may now start media streams.
559 In the context of H.323 this means that the CONNECT pdu has been
560 received.
562 The default behaviour calls the OnConnected() on the connections
563 associated OpalCall object.
565 virtual void OnConnected(
566 OpalConnection & connection ///< Connection that was established
569 /**A call back function whenever a connection is "established".
570 This indicates that a connection to an endpoint was connected and that
571 media streams are opened.
573 In the context of H.323 this means that the CONNECT pdu has been
574 received and either fast start was in operation or the subsequent Open
575 Logical Channels have occurred. For SIP it indicates the INVITE/OK/ACK
576 sequence is complete.
578 The default behaviour calls the OnEstablished() on the connection's
579 associated OpalCall object.
581 virtual void OnEstablished(
582 OpalConnection & connection ///< Connection that was established
585 /**A call back function whenever a connection is released.
586 This function can do any internal cleaning up and waiting on background
587 threads that may be using the connection object.
589 Classes that override this function should make sure they call the
590 ancestor version for correct operation.
592 An application will not typically call this function as it is used by
593 the OpalManager during a release of the connection.
595 The default behaviour calls OnReleased() on the connection's
596 associated OpalCall object. This indicates to the call that the
597 connection has been released so it can release the last remaining
598 connection and then returns TRUE.
600 virtual void OnReleased(
601 OpalConnection & connection ///< Connection that was established
604 /**A call back function whenever a connection is "held" or "retrieved".
605 This indicates that a connection to an endpoint was held, or
606 retrieved, either locally or by the remote endpoint.
608 The default behaviour does nothing.
610 virtual void OnHold(
611 OpalConnection & connection ///< Connection that was held
614 /**A call back function whenever a connection is forwarded.
616 The default behaviour does nothing.
618 virtual BOOL OnForwarded(
619 OpalConnection & connection, ///< Connection that was held
620 const PString & remoteParty ///< The new remote party
622 //@}
624 /**@name Media Streams management */
625 //@{
626 /**Adjust media formats available on a connection.
627 This is called by a connection after it has called
628 OpalCall::GetMediaFormats() to get all media formats that it can use so
629 that an application may remove or reorder the media formats before they
630 are used to open media streams.
632 The default behaviour uses the mediaFormatOrder and mediaFormatMask
633 member variables to adjust the mediaFormats list.
635 virtual void AdjustMediaFormats(
636 const OpalConnection & connection, ///< Connection that is about to use formats
637 OpalMediaFormatList & mediaFormats ///< Media formats to use
638 ) const;
640 /**See if the media can bypass the local host.
642 virtual BOOL IsMediaBypassPossible(
643 const OpalConnection & source, ///< Source connection
644 const OpalConnection & destination, ///< Destination connection
645 unsigned sessionID ///< Session ID for media channel
646 ) const;
648 /**Call back when opening a media stream.
649 This function is called when a connection has created a new media
650 stream according to the logic of its underlying protocol.
652 The usual requirement is that media streams are created on all other
653 connections participating in the call and all of the media streams are
654 attached to an instance of an OpalMediaPatch object that will read from
655 one of the media streams passing data to the other media streams.
657 The default behaviour achieves the above using the FindMatchingCodecs()
658 to determine what (if any) software codecs are required, the
659 OpalConnection::CreateMediaStream() function to open streams and the
660 CreateMediaPatch() function to create a patch for all of the streams
661 and codecs just produced.
663 virtual BOOL OnOpenMediaStream(
664 OpalConnection & connection, ///< Connection that owns the media stream
665 OpalMediaStream & stream ///< New media stream being opened
668 /**Call back for closed a media stream.
670 The default behaviour does nothing.
672 virtual void OnClosedMediaStream(
673 const OpalMediaStream & stream ///< Stream being closed
676 #if OPAL_VIDEO
678 /**Add video media formats available on a connection.
680 The default behaviour calls the OpalEndPoint function of the same name.
682 virtual void AddVideoMediaFormats(
683 OpalMediaFormatList & mediaFormats, ///< Media formats to use
684 const OpalConnection * connection = NULL ///< Optional connection that is using formats
685 ) const;
687 /**Create a PVideoInputDevice for a source media stream.
689 virtual BOOL CreateVideoInputDevice(
690 const OpalConnection & connection, ///< Connection needing created video device
691 const OpalMediaFormat & mediaFormat, ///< Media format for stream
692 PVideoInputDevice * & device, ///< Created device
693 BOOL & autoDelete ///< Flag for auto delete device
696 /**Create an PVideoOutputDevice for a sink media stream or the preview
697 display for a source media stream.
699 virtual BOOL CreateVideoOutputDevice(
700 const OpalConnection & connection, ///< Connection needing created video device
701 const OpalMediaFormat & mediaFormat, ///< Media format for stream
702 BOOL preview, ///< Flag indicating is a preview output
703 PVideoOutputDevice * & device, ///< Created device
704 BOOL & autoDelete ///< Flag for auto delete device
706 #endif
708 /**Create a OpalMediaPatch instance.
709 This function allows an application to have the system create descendant
710 class versions of the OpalMediPatch class. The application could use
711 this to modify the default behaviour of a patch.
713 The default behaviour returns an instance of OpalMediaPatch.
715 virtual OpalMediaPatch * CreateMediaPatch(
716 OpalMediaStream & source ///< Source media stream
719 /**Destroy a OpalMediaPatch instance.
721 The default behaviour simply calls delete patch.
723 virtual void DestroyMediaPatch(
724 OpalMediaPatch * patch
727 /**Call back for a media patch thread starting.
728 This function is called within the context of the thread associated
729 with the media patch. It may be used to do any last checks on if the
730 patch should proceed.
732 The default behaviour simply returns TRUE.
734 virtual BOOL OnStartMediaPatch(
735 const OpalMediaPatch & patch ///< Media patch being started
737 //@}
739 /**@name User indications */
740 //@{
741 /**Call back for remote endpoint has sent user input as a string.
743 The default behaviour call OpalConnection::SetUserInput() which
744 saves the value so the GetUserInput() function can return it.
746 virtual void OnUserInputString(
747 OpalConnection & connection, ///< Connection input has come from
748 const PString & value ///< String value of indication
751 /**Call back for remote enpoint has sent user input as tones.
752 If duration is zero then this indicates the beginning of the tone. If
753 duration is non-zero then it indicates the end of the tone output.
755 The default behaviour calls the OpalCall function of the same name.
757 virtual void OnUserInputTone(
758 OpalConnection & connection, ///< Connection input has come from
759 char tone, ///< Tone received
760 int duration ///< Duration of tone
763 /**Read a sequence of user indications from connection with timeouts.
765 virtual PString ReadUserInput(
766 OpalConnection & connection, ///< Connection to read input from
767 const char * terminators = "#\r\n", ///< Characters that can terminte input
768 unsigned lastDigitTimeout = 4, ///< Timeout on last digit in string
769 unsigned firstDigitTimeout = 30 ///< Timeout on receiving any digits
771 //@}
773 /**@name Other services */
774 //@{
775 /**Create an instance of the T.120 protocol handler.
776 This is called when the OpenLogicalChannel subsystem requires that
777 a T.120 channel be established.
779 Note that if the application overrides this it should return a pointer
780 to a heap variable (using new) as it will be automatically deleted when
781 the H323Connection is deleted.
783 The default behavour returns NULL.
785 virtual OpalT120Protocol * CreateT120ProtocolHandler(
786 const OpalConnection & connection ///< Connection for which T.120 handler created
787 ) const;
789 /**Create an instance of the T.38 protocol handler.
790 This is called when the OpenLogicalChannel subsystem requires that
791 a T.38 fax channel be established.
793 Note that if the application overrides this it should return a pointer
794 to a heap variable (using new) as it will be automatically deleted when
795 the H323Connection is deleted.
797 The default behavour returns NULL.
799 virtual OpalT38Protocol * CreateT38ProtocolHandler(
800 const OpalConnection & connection ///< Connection for which T.38 handler created
801 ) const;
803 /** Create an instance of the H.224 protocol handler.
804 This is called when the call subsystem requires that a H.224 channel be established.
806 Note that if the application overrides this it should return a pointer
807 to a heap variable (using new) as it will be automatically deleted when
808 the OpalConnection is deleted.
810 The default behaviour creates a standard OpalH224Handler instance
812 virtual OpalH224Handler * CreateH224ProtocolHandler(
813 OpalConnection & connection, unsigned sessionID
814 ) const;
816 /** Create an instance of the H.281 protocol handler.
817 This is called when a H.224 channel is established.
819 Note that if the application overrides this it should return a pointer
820 to a heap variable (using new) as it will be automatically deleted when
821 the OpalConnection is deleted.
823 The default behaviour creates a standard OpalH281Handler instance
825 virtual OpalH281Handler * CreateH281ProtocolHandler(
826 OpalH224Handler & h224Handler
827 ) const;
829 class RouteEntry : public PObject
831 PCLASSINFO(RouteEntry, PObject);
832 public:
833 RouteEntry(const PString & pat, const PString & dest);
834 void PrintOn(ostream & strm) const;
835 PString pattern;
836 PString destination;
837 PRegularExpression regex;
839 PLIST(RouteTable, RouteEntry);
841 /**Parse a route table specification list for the manager.
842 Add a route entry to the route table.
844 The specification string is of the form pattern=destination where
845 pattern is a regular expression matching the incoming calls
846 destination address and will translate it to the outgoing destination
847 address for making an outgoing call. For example, picking up a PhoneJACK
848 handset and dialing 2, 6 would result in an address of "pots:26"
849 which would then be matched against, say, a specification of
850 pots:26=h323:10.0.1.1, resulting in a call from the pots handset to
851 10.0.1.1 using H.323.
853 As the pattern field is a regular expression, you could have used in
854 the above .*:26=h323:10.0.1.1 to achieve the same result with the
855 addition that an incoming call from a SIP client would also be routed
856 to the H.323 client.
858 Note that the pattern has an implicit ^ and $ at the beginning and end
859 of the regular expression. So it must match the entire address.
861 If the specification is of the form @filename, then the file is read
862 with each line consisting of a pattern=destination route specification.
863 Lines without an equal sign or beginning with '#' are ignored.
865 Returns TRUE if an entry was added.
867 virtual BOOL AddRouteEntry(
868 const PString & spec ///< Specification string to add
871 /**Parse a route table specification list for the manager.
872 This removes the current routeTable and calls AddRouteEntry for every
873 string in the array.
875 Returns TRUE if at least one entry was added.
877 BOOL SetRouteTable(
878 const PStringArray & specs ///< Array of specification strings.
881 /**Set a route table for the manager.
882 Note that this will make a copy of the table and not maintain a
883 reference.
885 void SetRouteTable(
886 const RouteTable & table ///< New table to set for routing
889 /**Get the active route table for the manager.
891 const RouteTable & GetRouteTable() const { return routeTable; }
893 /**Route the source address to a destination using the route table.
895 virtual PString ApplyRouteTable(
896 const PString & proto,
897 const PString & addr
899 //@}
901 /**@name Member variable access */
902 //@{
903 /**Get the default username for all endpoints.
905 const PString & GetDefaultUserName() const { return defaultUserName; }
907 /**Set the default username for all endpoints.
909 void SetDefaultUserName(
910 const PString & name
911 ) { defaultUserName = name; }
913 /**Get the default display name for all endpoints.
915 const PString & GetDefaultDisplayName() const { return defaultDisplayName; }
917 /**Set the default display name for all endpoints.
919 void SetDefaultDisplayName(
920 const PString & name
921 ) { defaultDisplayName = name; }
923 #if OPAL_VIDEO
925 /**See if should auto-start receive video channels on connection.
927 BOOL CanAutoStartReceiveVideo() const { return autoStartReceiveVideo; }
929 /**Set if should auto-start receive video channels on connection.
931 void SetAutoStartReceiveVideo(BOOL can) { autoStartReceiveVideo = can; }
933 /**See if should auto-start transmit video channels on connection.
935 BOOL CanAutoStartTransmitVideo() const { return autoStartTransmitVideo; }
937 /**Set if should auto-start transmit video channels on connection.
939 void SetAutoStartTransmitVideo(BOOL can) { autoStartTransmitVideo = can; }
941 #endif
943 /**Determine if the address is "local", ie does not need any address
944 translation (fixed or via STUN) to access.
946 The default behaviour checks if remoteAddress is a RFC1918 private
947 IP address: 10.x.x.x, 172.16.x.x or 192.168.x.x.
949 virtual BOOL IsLocalAddress(
950 const PIPSocket::Address & remoteAddress
951 ) const;
953 /**Provide address translation hook.
954 This will check to see that remoteAddress is NOT a local address by
955 using IsLocalAddress() and if not, set localAddress to the
956 translationAddress (if valid) which would normally be the router
957 address of a NAT system.
959 virtual BOOL TranslateIPAddress(
960 PIPSocket::Address & localAddress,
961 const PIPSocket::Address & remoteAddress
964 /**Get the translation address to use for TranslateIPAddress().
966 const PIPSocket::Address & GetTranslationAddress() const { return translationAddress; }
968 /**Set the translation address to use for TranslateIPAddress().
970 void SetTranslationAddress(
971 const PIPSocket::Address & address
972 ) { translationAddress = address; }
974 /**Return the STUN server to use.
975 Returns NULL if address is a local address as per IsLocalAddress().
976 Always returns the STUN server if address is zero.
977 Note, the pointer is NOT to be deleted by the user.
979 PSTUNClient * GetSTUN(
980 const PIPSocket::Address & address = 0
981 ) const;
983 /**Set the STUN server address, is of the form host[:port]
984 Note that if the STUN server is found then the translationAddress
985 is automatically set to the router address as determined by STUN.
987 PSTUNClient::NatTypes SetSTUNServer(
988 const PString & server
991 /**Get the TCP port number base for H.245 channels
993 WORD GetTCPPortBase() const { return tcpPorts.base; }
995 /**Get the TCP port number base for H.245 channels.
997 WORD GetTCPPortMax() const { return tcpPorts.max; }
999 /**Set the TCP port number base and max for H.245 channels.
1001 void SetTCPPorts(unsigned tcpBase, unsigned tcpMax);
1003 /**Get the next TCP port number for H.245 channels
1005 WORD GetNextTCPPort();
1007 /**Get the UDP port number base for RAS channels
1009 WORD GetUDPPortBase() const { return udpPorts.base; }
1011 /**Get the UDP port number base for RAS channels.
1013 WORD GetUDPPortMax() const { return udpPorts.max; }
1015 /**Set the TCP port number base and max for H.245 channels.
1017 void SetUDPPorts(unsigned udpBase, unsigned udpMax);
1019 /**Get the next UDP port number for RAS channels
1021 WORD GetNextUDPPort();
1023 /**Get the UDP port number base for RTP channels.
1025 WORD GetRtpIpPortBase() const { return rtpIpPorts.base; }
1027 /**Get the max UDP port number for RTP channels.
1029 WORD GetRtpIpPortMax() const { return rtpIpPorts.max; }
1031 /**Set the UDP port number base and max for RTP channels.
1033 void SetRtpIpPorts(unsigned udpBase, unsigned udpMax);
1035 /**Get the UDP port number pair for RTP channels.
1037 WORD GetRtpIpPortPair();
1039 /**Get the IP Type Of Service byte for media (eg RTP) channels.
1041 BYTE GetRtpIpTypeofService() const { return rtpIpTypeofService; }
1043 /**Set the IP Type Of Service byte for media (eg RTP) channels.
1045 void SetRtpIpTypeofService(unsigned tos) { rtpIpTypeofService = (BYTE)tos; }
1047 /**Get the default maximum audio jitter delay parameter.
1048 Defaults to 50ms
1050 unsigned GetMinAudioJitterDelay() const { return minAudioJitterDelay; }
1052 /**Get the default maximum audio jitter delay parameter.
1053 Defaults to 250ms.
1055 unsigned GetMaxAudioJitterDelay() const { return maxAudioJitterDelay; }
1057 /**Set the maximum audio jitter delay parameter.
1059 void SetAudioJitterDelay(
1060 unsigned minDelay, ///< New minimum jitter buffer delay in milliseconds
1061 unsigned maxDelay ///< New maximum jitter buffer delay in milliseconds
1064 /**Get the default media format order.
1066 const PStringArray & GetMediaFormatOrder() const { return mediaFormatOrder; }
1068 /**Set the default media format order.
1070 void SetMediaFormatOrder(const PStringArray & order) { mediaFormatOrder = order; }
1072 /**Get the default media format mask.
1074 const PStringArray & GetMediaFormatMask() const { return mediaFormatMask; }
1076 /**Set the default media format mask.
1078 void SetMediaFormatMask(const PStringArray & mask) { mediaFormatMask = mask; }
1080 /**Set the default parameters for the silence detector.
1082 virtual void SetSilenceDetectParams(
1083 const OpalSilenceDetector::Params & params
1084 ) { silenceDetectParams = params; }
1086 /**Get the default parameters for the silence detector.
1088 const OpalSilenceDetector::Params & GetSilenceDetectParams() const { return silenceDetectParams; }
1090 /**Set the default parameters for the echo cancelation.
1092 virtual void SetEchoCancelParams(
1093 const OpalEchoCanceler::Params & params
1094 ) { echoCancelParams = params; }
1096 /**Get the default parameters for the silence detector.
1098 const OpalEchoCanceler::Params & GetEchoCancelParams() const { return echoCancelParams; }
1100 #if OPAL_VIDEO
1102 /**Set the parameters for the video device to be used for input.
1103 If the name is not suitable for use with the PVideoInputDevice class
1104 then the function will return FALSE and not change the device.
1106 This defaults to the value of the PVideoInputDevice::GetInputDeviceNames()
1107 function.
1109 virtual BOOL SetVideoInputDevice(
1110 const PVideoDevice::OpenArgs & deviceArgs ///< Full description of device
1113 /**Get the parameters for the video device to be used for input.
1114 This defaults to the value of the PSoundChannel::GetInputDeviceNames()[0].
1116 const PVideoDevice::OpenArgs & GetVideoInputDevice() const { return videoInputDevice; }
1118 /**Set the parameters for the video device to be used to preview input.
1119 If the name is not suitable for use with the PVideoOutputDevice class
1120 then the function will return FALSE and not change the device.
1122 This defaults to the value of the PVideoInputDevice::GetOutputDeviceNames()
1123 function.
1125 virtual BOOL SetVideoPreviewDevice(
1126 const PVideoDevice::OpenArgs & deviceArgs ///< Full description of device
1129 /**Get the parameters for the video device to be used for input.
1130 This defaults to the value of the PSoundChannel::GetInputDeviceNames()[0].
1132 const PVideoDevice::OpenArgs & GetVideoPreviewDevice() const { return videoPreviewDevice; }
1134 /**Set the parameters for the video device to be used for output.
1135 If the name is not suitable for use with the PVideoOutputDevice class
1136 then the function will return FALSE and not change the device.
1138 This defaults to the value of the PVideoInputDevice::GetOutputDeviceNames()
1139 function.
1141 virtual BOOL SetVideoOutputDevice(
1142 const PVideoDevice::OpenArgs & deviceArgs ///< Full description of device
1145 /**Get the parameters for the video device to be used for input.
1146 This defaults to the value of the PSoundChannel::GetOutputDeviceNames()[0].
1148 const PVideoDevice::OpenArgs & GetVideoOutputDevice() const { return videoOutputDevice; }
1150 #endif
1152 BOOL DetectInBandDTMFDisabled() const
1153 { return disableDetectInBandDTMF; }
1155 /**Set the default H.245 tunneling mode.
1157 void DisableDetectInBandDTMF(
1158 BOOL mode ///< New default mode
1159 ) { disableDetectInBandDTMF = mode; }
1161 /**Get the amount of time with no media that should cause a call to clear
1163 const PTimeInterval & GetNoMediaTimeout() const { return noMediaTimeout; }
1165 /**Set the amount of time with no media that should cause a call to clear
1167 BOOL SetNoMediaTimeout(
1168 const PTimeInterval & newInterval ///< New timeout for media
1171 /**Get the default ILS server to use for user lookup.
1173 const PString & GetDefaultILSServer() const { return ilsServer; }
1175 /**Set the default ILS server to use for user lookup.
1177 void SetDefaultILSServer(
1178 const PString & server
1179 ) { ilsServer = server; }
1180 //@}
1182 // needs to be public for gcc 3.4
1183 void GarbageCollection();
1185 virtual void OnNewConnection(OpalConnection & conn);
1187 virtual void SetDefaultSecurityMode(const PString & v)
1188 { defaultSecurityMode = v; }
1190 virtual PString GetDefaultSecurityMode() const
1191 { return defaultSecurityMode; }
1193 protected:
1194 // Configuration variables
1195 PString defaultUserName;
1196 PString defaultDisplayName;
1198 #if OPAL_VIDEO
1199 BOOL autoStartReceiveVideo;
1200 BOOL autoStartTransmitVideo;
1201 #endif
1203 BYTE rtpIpTypeofService;
1204 unsigned minAudioJitterDelay;
1205 unsigned maxAudioJitterDelay;
1206 PStringArray mediaFormatOrder;
1207 PStringArray mediaFormatMask;
1208 BOOL disableDetectInBandDTMF;
1209 PTimeInterval noMediaTimeout;
1210 PString ilsServer;
1212 OpalSilenceDetector::Params silenceDetectParams;
1213 OpalEchoCanceler::Params echoCancelParams;
1215 #if OPAL_VIDEO
1216 PVideoDevice::OpenArgs videoInputDevice;
1217 PVideoDevice::OpenArgs videoPreviewDevice;
1218 PVideoDevice::OpenArgs videoOutputDevice;
1219 #endif
1221 struct PortInfo {
1222 void Set(
1223 unsigned base,
1224 unsigned max,
1225 unsigned range,
1226 unsigned dflt
1228 WORD GetNext(
1229 unsigned increment
1232 PMutex mutex;
1233 WORD base;
1234 WORD max;
1235 WORD current;
1236 } tcpPorts, udpPorts, rtpIpPorts;
1238 PIPSocket::Address translationAddress;
1239 PSTUNClient * stun;
1241 RouteTable routeTable;
1242 PMutex routeTableMutex;
1244 // Dynamic variables
1245 PMutex inUseFlag;
1247 PList<OpalEndPoint> endpoints;
1249 unsigned lastCallTokenID;
1251 class CallDict : public PSafeDictionary<PString, OpalCall>
1253 public:
1254 CallDict(OpalManager & mgr) : manager(mgr) { }
1255 virtual void DeleteObject(PObject * object) const;
1256 OpalManager & manager;
1257 } activeCalls;
1259 BOOL clearingAllCalls;
1260 PSyncPoint allCallsCleared;
1261 PThread * garbageCollector;
1262 PSyncPoint garbageCollectExit;
1263 PDECLARE_NOTIFIER(PThread, OpalManager, GarbageMain);
1265 PString defaultSecurityMode;
1267 friend OpalCall::OpalCall(OpalManager & mgr);
1268 friend void OpalCall::OnReleased(OpalConnection & connection);
1272 PString OpalGetVersion();
1273 unsigned OpalGetMajorVersion();
1274 unsigned OpalGetMinorVersion();
1275 unsigned OpalGetBuildNumber();
1278 #endif // __OPAL_MANAGER_H
1281 // End of File ///////////////////////////////////////////////////////////////