1/*
2 * Python bindings.
3 *
4 * Open Phone Abstraction Library (OPAL)
5 *
6 * Copyright (c) 2011 Demetrius Cassidy
7 *
8 * The contents of this file are subject to the Mozilla Public License
9 * Version 1.0 (the "License"); you may not use this file except in
10 * compliance with the License. You may obtain a copy of the License at
11 * http://www.mozilla.org/MPL/
12 *
13 * Software distributed under the License is distributed on an "AS IS"
14 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
15 * the License for the specific language governing rights and limitations
16 * under the License.
17 *
18 * The Original Code is Open Phone Abstraction Library (OPAL)
19 *
20 * The Initial Developer of the Original Code is Demetrius Cassidy
21 *
22 * Contributor(s): ______________________________________.
23 *
24 * $Revision: 26117 $
25 * $Author: rjongbloed $
26 * $Date: 2011-07-04 22:45:05 -0500 (Mon, 04 Jul 2011) $
27 */
28
29%ModuleHeaderCode
30#include <ptlib.h>
31#include <h323/h323con.h>
32%End
33
34///////////////////////////////////////////////////////////////////////////////
35
36/**This class represents a particular H323 connection between two endpoints.
37   There are at least two threads in use, this one to look after the
38   signalling channel, an another to look after the control channel. There
39   would then be additional threads created for each data channel created by
40   the control channel protocol thread.
41 */
42class H323Connection : OpalRTPConnection
43{
44  public:
45  /**@name Construction */
46  //@{
47    /**Create a new connection.
48     */
49    H323Connection(
50      OpalCall & call,                         ///<  Call object connection belongs to
51      H323EndPoint & endpoint,                 ///<  H323 End Point object
52      const PString & token,                   ///<  Token for new connection
53      const PString & alias,                   ///<  Alias for outgoing call
54      const H323TransportAddress & address,    ///<  Address for outgoing call
55      unsigned options = 0,                    ///<  Connection option bits
56      OpalConnection::StringOptions * stringOptions = NULL ///<  complex string options
57    );
58
59    /**Destroy the connection
60     */
61    ~H323Connection();
62  //@}
63
64  /**@name Overrides from OpalConnection */
65  //@{
66    /**Get indication of connection being to a "network".
67       This indicates the if the connection may be regarded as a "network"
68       connection. The distinction is about if there is a concept of a "remote"
69       party being connected to and is best described by example: sip, h323,
70       iax and pstn are all "network" connections as they connect to something
71       "remote". While pc, pots and ivr are not as the entity being connected
72       to is intrinsically local.
73      */
74    virtual bool IsNetworkConnection() const;
75
76    /**Get this connections protocol prefix for URLs.
77      */
78    virtual PString GetPrefixName() const;
79
80	/// Call back for connection to act on changed string options
81	virtual void OnApplyStringOptions();
82
83    /**Start an outgoing connection.
84       This function will initiate the connection to the remote entity, for
85       example in H.323 it sends a SETUP, in SIP it sends an INVITE etc.
86
87       The default behaviour is to send SETUP packet.
88      */
89    virtual PBoolean SetUpConnection();
90
91    /**Indicate to remote endpoint an alert is in progress.
92       If this is an incoming connection and it is in the Alerting phase, then
93       this function is used to indicate to that endpoint that an alert is in
94       progress. This is usually due to another connection which is in the
95       call (the B party) has received an OnAlerting() indicating that its
96       remote endpoint is "ringing".
97
98       The default behaviour sends an ALERTING pdu.
99      */
100    virtual PBoolean SetAlerting(
101      const PString & calleeName,   ///<  Name of endpoint being alerted.
102      PBoolean withMedia                ///<  Open media with alerting
103    );
104
105    /**Indicate to remote endpoint we are connected.
106
107       The default behaviour sends a CONNECT pdu.
108      */
109    virtual PBoolean SetConnected();
110
111    /**Indicate to remote endpoint we are sending a progress.
112
113      The default behaviour sends a PROGRESS pdu.
114     */
115    virtual PBoolean SetProgressed();
116
117    /** Called when a connection is established.
118        This indicates that a connection to an endpoint was established. This
119        usually occurs after OnConnected() and indicates that the connection
120        is both connected and has media flowing.
121
122        Default behaviour is to call H323EndPoint::OnConnectionEstablished
123      */
124    virtual void OnEstablished();
125
126    /**Clean up the termination of the connection.
127       This function can do any internal cleaning up and waiting on background
128       threads that may be using the connection object.
129
130       Note that there is not a one to one relationship with the
131       OnEstablishedConnection() function. This function may be called without
132       that function being called. For example if SetUpConnection() was used
133       but the call never completed.
134
135       Classes that override this function should make sure they call the
136       ancestor version for correct operation.
137
138       An application will not typically call this function as it is used by
139       the OpalManager during a release of the connection.
140
141       The default behaviour calls OnRelease() then calls the ancestor.
142      */
143    virtual void OnReleased();
144
145    /**Get the destination address of an incoming connection.
146       This will, for example, collect a phone number from a POTS line, or
147       get the fields from the H.225 SETUP pdu in a H.323 connection.
148      */
149    virtual PString GetDestinationAddress();
150
151    /**Get alerting type information of an incoming call.
152       The type of "distinctive ringing" for the call. The string is protocol
153       dependent, so the caller would need to be aware of the type of call
154       being made. Some protocols may ignore the field completely.
155
156       For SIP this corresponds to the string contained in the "Alert-Info"
157       header field of the INVITE. This is typically a URI for the ring file.
158
159       For H.323 this must be a string representation of an integer from 0 to 7
160       which will be contained in the Q.931 SIGNAL (0x34) Information Element.
161
162       Default behaviour returns an empty string.
163      */
164    virtual PString GetAlertingType() const;
165
166    /**Set alerting type information for outgoing call.
167       The type of "distinctive ringing" for the call. The string is protocol
168       dependent, so the caller would need to be aware of the type of call
169       being made. Some protocols may ignore the field completely.
170
171       For SIP this corresponds to the string contained in the "Alert-Info"
172       header field of the INVITE. This is typically a URI for the ring file.
173
174       For H.323 this must be a string representation of an integer from 0 to 7
175       which will be contained in the Q.931 SIGNAL (0x34) Information Element.
176
177       Default behaviour returns false.
178      */
179    virtual bool SetAlertingType(const PString & info);
180
181    /** Get Q.931 Progress Indicator IE description from received PROGRESS or ALERTING pdus.
182      */
183    unsigned GetProgressIndicator() const;
184
185    /** Set Q.931 Progress Indicator IE description to send in PROGRESS or ALERTING pdus.
186      */
187    void SetProgressIndicator(unsigned indicator);
188
189    /**Get the data formats this connection is capable of operating.
190       This provides a list of media data format names that an
191       OpalMediaStream may be created in within this connection.
192
193       The default behaviour returns media data format names contained in
194       the remote capability table.
195      */
196    virtual OpalMediaFormatList GetMediaFormats() const;
197
198    /**Get next available session ID for the media type.
199      */
200    virtual unsigned GetNextSessionID(
201      const OpalMediaType & mediaType,   ///< Media type of stream being opened
202      bool isSource                      ///< Stream is a source/sink
203    );
204
205    /**Switch to/from FAX mode.
206      */
207    virtual bool SwitchFaxMediaStreams(
208      bool enableFax  ///< Enable FAX or return to audio mode
209    );
210
211    /**Request close of a specific media stream.
212       Note that this is usually asymchronous, the OnClosedMediaStream() function is
213       called when the stream is really closed.
214      */
215    virtual bool CloseMediaStream(
216      OpalMediaStream & stream  ///< Stream to close
217    );
218
219    /**Get information on the media channel for the connection.
220       The default behaviour returns PTrue and fills the info structure if
221       there is a media channel active for the sessionID.
222     */
223    virtual PBoolean GetMediaInformation(
224      unsigned sessionID,     ///<  Session ID for media channel
225      MediaInformation & info ///<  Information on media channel
226    ) const;
227  //@}
228
229  /**@name Signalling Channel */
230  //@{
231    /**Attach a transport to this connection as the signalling channel.
232      */
233    void AttachSignalChannel(
234      const PString & token,    ///<  New token to use to identify connection
235      H323Transport * channel,  ///<  Transport for the PDU's
236      PBoolean answeringCall        ///<  Flag for if incoming/outgoing call.
237    );
238
239    /**Forward incoming call to specified address.
240       This would typically be called from within the OnIncomingCall()
241       function when an application wishes to redirct an unwanted incoming
242       call.
243
244       The return value is PTrue if the call is to be forwarded, PFalse
245       otherwise. Note that if the call is forwarded the current connection is
246       cleared with the ended call code of EndedByCallForwarded.
247      */
248    virtual PBoolean ForwardCall(
249      const PString & forwardParty   ///<  Party to forward call to.
250    );
251
252    /**Initiate the transfer of an existing call (connection) to a new remote
253       party.
254
255       If remoteParty is a valid call token, then the remote party is transferred
256       to that party (consultation transfer) and both calls are cleared.
257     */
258    virtual bool TransferConnection(
259      const PString & remoteParty   ///<  Remote party to transfer the existing call to
260    );
261
262
263    /**Initiate the transfer of an existing call (connection) to a new remote party
264       using H.450.2.  This sends a Call Transfer Initiate Invoke message from the
265       A-Party (transferring endpoint) to the B-Party (transferred endpoint).
266     */
267    bool TransferCall(
268      const PString & remoteParty,   ///<  Remote party to transfer the existing call to
269      const PString & callIdentity = PString::Empty()
270                                    ///<  Call Identity of secondary call if present
271    );
272
273    /**Transfer the call through consultation so the remote party in the primary call is connected to
274       the called party in the second call using H.450.2.  This sends a Call Transfer Identify Invoke
275       message from the A-Party (transferring endpoint) to the C-Party (transferred-to endpoint).
276     */
277    void ConsultationTransfer(
278      const PString & primaryCallToken  ///<  Primary call
279    );
280
281    /**Handle the reception of a callTransferSetupInvoke APDU whilst a secondary call exists.  This
282       method checks whether the secondary call is still waiting for a callTransferSetupInvoke APDU and
283       proceeds to clear the call if the call identies match.
284       This is an internal function and it is not expected the user will call
285       it directly.
286     */
287    virtual void HandleConsultationTransfer(
288      const PString & callIdentity, /**Call Identity of secondary call
289                                       received in SETUP Message. */
290      H323Connection & incoming     ///<  Connection upon which SETUP PDU was received.
291    );
292
293    /**Determine whether this connection is being transferred.
294     */
295    PBoolean IsTransferringCall() const;
296
297    /**Determine whether this connection is the result of a transferred call.
298     */
299    PBoolean IsTransferredCall() const;
300
301    /**Handle the transfer of an existing connection to a new remote.
302       This is an internal function and it is not expected the user will call
303       it directly.
304     */
305    virtual void HandleTransferCall(
306      const PString & token,
307      const PString & identity
308    );
309
310    /**Get transfer invoke ID dureing trasfer.
311       This is an internal function and it is not expected the user will call
312       it directly.
313      */
314    int GetCallTransferInvokeId();
315
316    /**Handle the failure of a call transfer operation at the Transferred Endpoint.  This method is
317       used to handle the following transfer failure cases that can occur at the Transferred Endpoint.
318       The cases are:
319       Reception of an Admission Reject
320       Reception of a callTransferSetup return error APDU.
321       Expiry of Call Transfer timer CT-T4.
322     */
323    virtual void HandleCallTransferFailure(
324      const int returnError    ///<  Failure reason code
325    );
326
327    /**Store the passed token on the current connection's H4502Handler.
328       This is an internal function and it is not expected the user will call
329       it directly.
330     */
331    void SetAssociatedCallToken(
332      const PString & token  ///<  Associated token
333    );
334
335    /**Callback to indicate a successful transfer through consultation.  The paramter passed is a
336       reference to the existing connection between the Transferring endpoint and Transferred-to
337       endpoint.
338     */
339    virtual void OnConsultationTransferSuccess(
340      H323Connection & secondaryCall  ///<  Secondary call for consultation
341    );
342
343    /**Place the call on hold, suspending all media channels (H.450.4).  Note it is the responsibility
344       of the application layer to delete the MOH Channel if music on hold is provided to the remote
345       endpoint.  So far only Local Hold has been implemented.
346     */
347    bool HoldCall(
348      PBoolean localHold   ///<  true for Local Hold, false for Remote Hold
349    );
350
351    /**Retrieve the call from hold, activating all media channels (H.450.4).
352       This method examines the call hold state and performs the necessary
353       actions required to retrieve a Near-end or Remote-end call on hold.
354       NOTE: Only Local Hold is implemented so far.
355    */
356    bool RetrieveCall();
357
358    /**Set the alternative media channel.  This channel can be used to provide
359       Media On Hold (MOH) for a near end call hold operation or to provide
360       Recorded Voice Anouncements (RVAs).  If this method is not called before
361       a call hold operation is attempted, no media on hold will be provided
362       for the held endpoint.
363      */
364    void SetHoldMedia(
365      PChannel * audioChannel
366    );
367
368    /**Determine if Meadia On Hold is enabled.
369      */
370    PBoolean IsMediaOnHold() const;
371
372    /**Determine if held.
373      */
374    PBoolean IsLocalHold() const;
375
376    /**Determine if held.
377      */
378    PBoolean IsRemoteHold() const;
379
380    /**Determine if the current call is held or in the process of being held.
381      */
382    PBoolean IsCallOnHold() const;
383
384    /**Begin a call intrusion request.
385       Calls h45011handler->IntrudeCall where SS pdu is added to Call Setup
386       message.
387      */
388    virtual void IntrudeCall(
389      unsigned capabilityLevel
390    );
391
392    /**Handle an incoming call instrusion request.
393       Calls h45011handler->AwaitSetupResponse where we set Handler state to
394       CI-Wait-Ack
395      */
396    virtual void HandleIntrudeCall(
397      const PString & token,
398      const PString & identity
399    );
400
401    /**Set flag indicating call intrusion.
402       Used to set a flag when intrusion occurs and to determine if
403       connection is created for Call Intrusion. This flag is used when we
404       should decide whether to Answer the call or to Close it.
405      */
406    void SetCallIntrusion();
407
408    PBoolean IsCallIntrusion();
409
410    /**Get Call Intrusion Protection Level of the local endpoint.
411      */
412    unsigned GetLocalCallIntrusionProtectionLevel();
413
414    /**Get Call Intrusion Protection Level of other endpoints that we are in
415       connection with.
416      */
417    virtual PBoolean GetRemoteCallIntrusionProtectionLevel(
418      const PString & callToken,
419      unsigned callIntrusionProtectionLevel
420    );
421
422    virtual void SetIntrusionImpending();
423
424    virtual void SetForcedReleaseAccepted();
425
426    virtual void SetIntrusionNotAuthorized();
427
428    /**Send a Call Waiting indication message to the remote endpoint using
429       H.450.6.  The second paramter is used to indicate to the calling user
430       how many additional users are "camped on" the called user. A value of
431       zero indicates to the calling user that he/she is the only user
432       attempting to reach the busy called user.
433     */
434    void SendCallWaitingIndication(
435      const unsigned nbOfAddWaitingCalls = 0   ///<  number of additional waiting calls at the served user
436    );
437
438    /**This function is called when insufficient digits have been entered.
439       This supports overlapped dialling so that a call can begin when it is
440       not known how many more digits are to be entered in a phone number.
441
442       It is expected that the application will override this function. It
443       should be noted that the application should not block in the function
444       but only indicate to whatever other thread is gathering digits that
445       more are required and that thread should call SendMoreDigits().
446
447       If PFalse is returned the connection is aborted and a Release Complete
448       PDU is sent.
449
450       The default behaviour simply returns PFalse.
451     */
452     virtual PBoolean OnInsufficientDigits();
453
454    /**This function is called when sufficient digits have been entered.
455       This supports overlapped dialling so that a call can begin when it is
456       not known how many more digits are to be entered in a phone number.
457
458       The digits parameter is appended to the existing remoteNumber member
459       variable and the call is retried.
460
461       If PFalse is returned the connection is aborted and a Release Complete
462       PDU is sent.
463
464       The default behaviour simply returns PTrue.
465     */
466    virtual void SendMoreDigits(
467      const PString & digits    ///<  Extra digits
468    );
469
470    /**Start control channel negotiations.
471      */
472    virtual PBoolean StartControlNegotiations();
473
474    /**Handle reading data on the control channel.
475     */
476    virtual void HandleControlChannel();
477
478
479    /**Handle a H.239 flow control request.
480       Default behaviour simply sends an acknowedge response.
481      */
482    virtual bool OnH239FlowControlRequest(
483      unsigned logicalChannel,
484      unsigned bitRate
485    );
486
487    /**Handle a H.239 flow control ack/reject response.
488       Default behaviour does nothing
489      */
490    virtual bool OnH239FlowControlResponse(
491      unsigned logicalChannel,
492      bool rejected
493    );
494
495    /**Handle a H.239 presentation token request.
496       Default behaviour simply sends an acknowedge response.
497      */
498    virtual bool OnH239PresentationRequest(
499      unsigned logicalChannel,
500      unsigned symmetryBreaking,
501      unsigned terminalLabel
502    );
503
504	/**Send a H.239 presentation token request.
505       Asks the remote for the "token" allow local system to own the
506       presentation video channel. A OnH239PresentationResponse() callback
507       should occur when the remote responds to the request.
508      */
509    virtual bool SendH239PresentationRequest(
510      unsigned logicalChannel,
511      unsigned symmetryBreaking,
512      unsigned terminalLabel
513    );
514
515    /**Handle a H.239 presentation token ack/reject response.
516       Default behaviour simply sends a release command.
517      */
518    virtual bool OnH239PresentationResponse(
519      unsigned logicalChannel,
520      unsigned terminalLabel,
521      bool rejected
522    );
523
524	/**Send a H.239 presentation token release.
525       Tell the remote we no longer require the "token" allowing the local
526       system to own the presentation video channel.
527      */
528    virtual bool SendH239PresentationRelease(
529      unsigned logicalChannel,
530      unsigned terminalLabel
531    );
532
533    /**Handle a H.239 presentation token release command.
534       Default behaviour does nothing.
535      */
536    virtual bool OnH239PresentationRelease(
537      unsigned logicalChannel,
538      unsigned terminalLabel
539    );
540
541    /**Handle a H.239 presentation token owner indication.
542       Default behaviour does nothing.
543      */
544    virtual bool OnH239PresentationIndication(
545      unsigned logicalChannel,
546      unsigned terminalLabel
547    );
548
549    /**Error discriminator for the OnControlProtocolError() function.
550      */
551    enum ControlProtocolErrors {
552      e_MasterSlaveDetermination,
553      e_CapabilityExchange,
554      e_LogicalChannel,
555      e_ModeRequest,
556      e_RoundTripDelay
557    };
558
559    /**This function is called from the HandleControlPDU() function or
560       any of its sub-functions for protocol errors, eg unhandled PDU types.
561
562       The errorData field may be a string or PDU or some other data depending
563       on the value of the errorSource parameter. These are:
564          e_UnhandledPDU                    &H323ControlPDU
565          e_MasterSlaveDetermination        const char *
566
567       If PFalse is returned the connection is aborted. The default behaviour
568       returns PTrue.
569     */
570    virtual PBoolean OnControlProtocolError(
571      ControlProtocolErrors errorSource,  ///<  Source of the proptoerror
572      const void * errorData = NULL       ///<  Data associated with error
573    );
574
575    /**Send a new capability set.
576      */
577    virtual bool SendCapabilitySet(
578      PBoolean empty  ///<  Send an empty set.
579    );
580
581    /**check if TCS procedure in progress states.
582      */
583    virtual bool IsSendingCapabilitySet();
584
585    /**Call back to set the local capabilities.
586       This is called just before the capabilties are required when a call
587       is begun. It is called when a SETUP PDU is received or when one is
588       about to be sent, so that the capabilities may be adjusted for correct
589       fast start operation.
590
591       The default behaviour adds all media formats.
592      */
593    virtual void OnSetLocalCapabilities();
594
595    /**Return if this H245 connection is a master or slave
596     */
597    PBoolean IsH245Master() const;
598
599    /**Start the round trip delay calculation over the control channel.
600     */
601    void StartRoundTripDelay();
602
603    /**Get the round trip delay over the control channel.
604     */
605    PTimeInterval GetRoundTripDelay() const;
606  //@}
607
608  /**@name Logical Channel Management */
609  //@{
610    /**Call back to select logical channels to start.
611
612       This function must be defined by the descendent class. It is used
613       to select the logical channels to be opened between the two endpoints.
614       There are three ways in which this may be called: when a "fast start"
615       has been initiated by the local endpoint (via SendSignalSetup()
616       function), when a "fast start" has been requested from the remote
617       endpoint (via the OnReceivedSignalSetup() function) or when the H245
618       capability set (and master/slave) negotiations have completed (via the
619       OnControlChannelOpen() function.
620
621       The function would typically examine several member variable to decide
622       which mode it is being called in and what to do. If fastStartState is
623       FastStartDisabled then non-fast start semantics should be used. The
624       H245 capabilities in the remoteCapabilities members should be
625       examined, and appropriate transmit channels started using
626       OpenLogicalChannel().
627
628       If fastStartState is FastStartInitiate, then the local endpoint has
629       initiated a call and is asking the application if fast start semantics
630       are to be used. If so it is expected that the function call
631       OpenLogicalChannel() for all the channels that it wishes to be able to
632       be use. A subset (possibly none!) of these would actually be started
633       when the remote endpoint replies.
634
635       If fastStartState is FastStartResponse, then this indicates the remote
636       endpoint is attempting a fast start. The fastStartChannels member
637       contains a list of possible channels from the remote that the local
638       endpoint is to select which to accept. For each accepted channel it
639       simply necessary to call the Start() function on that channel eg
640       fastStartChannels[0].Start();
641
642       The default behaviour selects the first codec of each session number
643       that is available. This is according to the order of the capabilities
644       in the remoteCapabilities, the local capability table or of the
645       fastStartChannels list respectively for each of the above scenarios.
646      */
647    virtual void OnSelectLogicalChannels();
648
649    /**Select default logical channel for normal start.
650      */
651    virtual void SelectDefaultLogicalChannel(
652      const OpalMediaType & mediaType,  ///<  media type of channel
653      unsigned sessionID                ///<  Session ID to find default logical channel.
654    );
655
656    /**Select default logical channel for fast start.
657       Internal function, not for normal use.
658      */
659    virtual void SelectFastStartChannels(
660      unsigned sessionID,   ///<  Session ID to find default logical channel.
661      PBoolean transmitter,     ///<  Whether to open transmitters
662      PBoolean receiver         ///<  Whether to open receivers
663    );
664
665  /**@name Bandwidth Management */
666  //@{
667    /**Set the available bandwidth in 100's of bits/sec.
668       Note if the force parameter is PTrue this function will close down
669       active logical channels to meet the new bandwidth requirement.
670      */
671    virtual PBoolean SetBandwidthAvailable(
672      unsigned newBandwidth,    ///<  New bandwidth limit
673      PBoolean force = PFalse        ///<  Force bandwidth limit
674    );
675
676    /**Get the bandwidth currently used.
677       This totals the open channels and returns the total bandwidth used in
678       100's of bits/sec
679      */
680    virtual unsigned GetBandwidthUsed() const;
681  //@}
682
683  /**@name Indications */
684  //@{
685    /**Get the real user input indication transmission mode.
686       This will return the user input mode that will actually be used for
687       transmissions. It will be the value of GetSendUserInputMode() provided
688       the remote endpoint is capable of that mode.
689      */
690    virtual SendUserInputModes GetRealSendUserInputMode() const;
691
692    /**Send a user input indication to the remote endpoint.
693       This is for sending arbitrary strings as user indications.
694
695       The user indication is sent according to the sendUserInputMode member
696       variable. If SendUserInputAsString then this uses an H.245 "string"
697       UserInputIndication pdu sending the entire string in one go. If
698       SendUserInputAsTone then a separate H.245 "signal" UserInputIndication
699       pdu is sent for each character. If SendUserInputAsInlineRFC2833 then
700       the indication is inserted into the outgoing audio stream as an RFC2833
701       RTP data pdu.
702
703       SendUserInputAsSeparateRFC2833 is not yet supported.
704      */
705    virtual PBoolean SendUserInputString(
706      const PString & value                   ///<  String value of indication
707    );
708
709    /**Send a user input indication to the remote endpoint.
710       This sends DTMF emulation user input. If something more sophisticated
711       than the simple tones that can be sent using the SendUserInput()
712       function.
713
714       A duration of zero indicates that no duration is to be indicated.
715       A non-zero logical channel indicates that the tone is to be syncronised
716       with the logical channel at the rtpTimestamp value specified.
717
718       The tone parameter must be one of "0123456789#*ABCD!" where '!'
719       indicates a hook flash. If tone is a ' ' character then a
720       signalUpdate PDU is sent that updates the last tone indication
721       sent. See the H.245 specifcation for more details on this.
722
723       The user indication is sent according to the sendUserInputMode member
724       variable. If SendUserInputAsString then this uses an H.245 "string"
725       UserInputIndication pdu sending the entire string in one go. If
726       SendUserInputAsTone then a separate H.245 "signal" UserInputIndication
727       pdu is sent for each character. If SendUserInputAsInlineRFC2833 then
728       the indication is inserted into the outgoing audio stream as an RFC2833
729       RTP data pdu.
730
731       SendUserInputAsSeparateRFC2833 is not yet supported.
732      */
733    virtual PBoolean SendUserInputTone(
734      char tone,             ///<  DTMF tone code
735      unsigned duration = 0  ///<  Duration of tone in milliseconds
736    );
737
738    /**Send a user input indication to the remote endpoint.
739       This is for sending arbitrary strings as user indications.
740
741       This always uses a Q.931 Keypad Information Element in a Information
742       pdu sending the entire string in one go.
743      */
744    virtual PBoolean SendUserInputIndicationQ931(
745      const PString & value                   ///<  String value of indication
746    );
747
748    /**Send a user input indication to the remote endpoint.
749       This is for sending arbitrary strings as user indications.
750
751       This always uses an H.245 "string" UserInputIndication pdu sending the
752       entire string in one go.
753      */
754    virtual PBoolean SendUserInputIndicationString(
755      const PString & value                   ///<  String value of indication
756    );
757
758    /**Send a user input indication to the remote endpoint.
759       This sends DTMF emulation user input.This uses an H.245 "signal"
760       UserInputIndication pdu.
761      */
762    virtual PBoolean SendUserInputIndicationTone(
763      char tone,                   ///<  DTMF tone code
764      unsigned duration = 0,       ///<  Duration of tone in milliseconds
765      unsigned logicalChannel = 0, ///<  Logical channel number for RTP sync.
766      unsigned rtpTimestamp = 0    ///<  RTP timestamp in logical channel sync.
767    );
768
769
770    /**Callback from the RTP session for statistics monitoring.
771       This is called every so many packets on the transmitter and receiver
772       threads of the RTP session indicating that the statistics have been
773       updated.
774
775       The default behaviour calls H323EndPoint::OnRTPStatistics().
776      */
777    virtual void OnRTPStatistics(
778      const RTP_Session & session   ///<  Session with statistics
779    ) const;
780
781    /**Get the names of the codecs in use for the RTP session.
782       If there is no session of the specified ID, an empty string is returned.
783      */
784    virtual PString GetSessionCodecNames(
785      unsigned sessionID
786    ) const;
787
788  //@}
789
790  /**@name Request Mode Changes */
791  //@{
792    /**Make a request to mode change to remote.
793       This asks the remote system to stop it transmitters and start sending
794       one of the combinations specifed.
795
796       The modes are separated in the string by \n characters, and all of the
797       channels (capabilities) are strings separated by \t characters. Thus a
798       very simple mode change would be "T.38" which requests that the remote
799       start sending T.38 data and nothing else. A more complicated example
800       would be "G.723\tH.261\nG.729\tH.261\nG.728" which indicates that the
801       remote should either start sending G.723 and H.261, G.729 and H.261 or
802       just G.728 on its own.
803
804       Returns PFalse if a mode change is currently in progress, only one mode
805       change may be done at a time.
806      */
807    virtual PBoolean RequestModeChange(
808      const PString & newModes  ///<  New modes to select
809    );
810
811  /**@name Other services */
812  //@{
813    /**Request a mode change to T.38 data.
814       Note this function is strictly H.323 and does operate correctly in the
815       OPAL media stream model. It is maintained for backward compatibility
816       with older applications only.
817      */
818    virtual PBoolean RequestModeChangeT38(
819      const char * capabilityNames = "T.38\nT38FaxUDP"
820    );
821
822  /**@name Member variable access */
823  //@{
824    /**Get the owner endpoint for this connection.
825     */
826    H323EndPoint & GetEndPoint() const;
827
828    /**Get the call direction for this connection.
829     */
830    PBoolean HadAnsweredCall() const;
831
832    /**Determined if connection is gatekeeper routed.
833     */
834    PBoolean IsGatekeeperRouted() const;
835
836    /**Get the distinctive ring code for incoming call.
837       This returns an integer from 0 to 7 that may indicate to an application
838       that different ring cadences are to be used.
839      */
840    unsigned GetDistinctiveRing() const;
841
842    /**Set the distinctive ring code for outgoing call.
843       This sets the integer from 0 to 7 that will be used in the outgoing
844       Setup PDU. Note this must be called either immediately after
845       construction or during the OnSendSignalSetup() callback function so the
846       member variable is set befor ethe PDU is sent.
847      */
848    void SetDistinctiveRing(unsigned pattern);
849
850    /**Get the internal OpenH323 call token for this connection.
851       Deprecated, only used for backward compatibility.
852     */
853    const PString & GetCallToken() const;
854
855    /**Get the call reference for this connection.
856     */
857    unsigned GetCallReference() const;
858
859     /**Get the protocol-specific unique identifier for this connection.
860     */
861    virtual PString GetIdentifier() const;
862
863    /**Get the conference identifier for this connection.
864     */
865    const PGloballyUniqueID & GetConferenceIdentifier() const;
866
867    /**Set the local name/alias from information in the PDU.
868      */
869    void SetLocalPartyName(const PString & name);
870
871    /**Get the list of all alias names this connection is using.
872      */
873    const PStringList & GetLocalAliasNames() const;
874
875    /**Get the remote party address.
876       This will return the "best guess" at an address to use in a
877       to call the user again later.
878      */
879    PString GetRemotePartyURL() const;
880
881    ///**Get the remotes capability table for this connection.
882    // */
883    const H323Capabilities & GetLocalCapabilities() const;
884
885    ///**Get the remotes capability table for this connection.
886    // */
887    const H323Capabilities & GetRemoteCapabilities() const;
888
889    /**Get the maximum audio jitter delay.
890     */
891    unsigned GetRemoteMaxAudioDelayJitter() const;
892
893    /**Get the signalling channel being used.
894      */
895    const H323Transport * GetSignallingChannel() const;
896
897    /**Get the signalling channel protocol version number.
898      */
899    unsigned GetSignallingVersion() const;
900
901    /**Get the control channel being used (may return signalling channel).
902      */
903    const H323Transport & GetControlChannel() const;
904
905    /**Get the control channel being used (may return signalling channel).
906      */
907    OpalTransport & GetTransport() const;
908
909    /**Get the control channel protocol version number.
910      */
911    unsigned GetControlVersion() const;
912
913    /**Get the UUIE PDU monitor bit mask.
914     */
915    unsigned GetUUIEsRequested() const;
916
917    /**Set the UUIE PDU monitor bit mask.
918     */
919    void SetUUIEsRequested(unsigned mask);
920
921    /**Get the iNow Gatekeeper Access Token OID.
922     */
923    const PString GetGkAccessTokenOID() const;
924
925    /**Set the iNow Gatekeeper Access Token OID.
926     */
927    void SetGkAccessTokenOID(const PString & oid);
928
929    /**Get the iNow Gatekeeper Access Token data.
930     */
931    const PBYTEArray & GetGkAccessTokenData() const;
932
933    /**Set the Destionation Extra Call Info memeber.
934     */
935    void SetDestExtraCallInfo(
936      const PString & info
937    );
938
939    /** Set the remote call waiting flag
940     */
941    void SetRemotCallWaiting(const unsigned value);
942
943    /**How many caller's are waiting on the remote endpoint?
944      -1 - None
945       0 - Just this connection
946       n - n plus this connection
947     */
948    int GetRemoteCallWaiting() const;
949
950    /**Set the enforced duration limit for the call.
951       This starts a timer that will automatically shut down the call when it
952       expires.
953      */
954    void SetEnforcedDurationLimit(
955      unsigned seconds  ///<  max duration of call in seconds
956    );
957  //@}
958
959    /**Get the local H.239 control capability.
960     */
961    bool GetLocalH239Control() const;
962
963    /**Set the local H.239 control capability.
964     */
965    void SetLocalH239Control(
966      bool on   ///< H.239 control capability is to be sent to remote
967    );
968
969    /**Get the remote H.239 control capability.
970     */
971    bool GetRemoteH239Control() const;
972
973    /**Get the remote H.239 options.
974     */
975    OpalMediaFormatList GetRemoteH239Formats() const;
976
977
978    virtual void OnMediaCommand(OpalMediaCommand & note, int extra);
979
980  protected:
981      enum ConnectionStates {
982      NoConnectionActive,
983      AwaitingGatekeeperAdmission,
984      AwaitingTransportConnect,
985      AwaitingSignalConnect,
986      AwaitingLocalAnswer,
987      HasExecutedSignalConnect,
988      EstablishedConnection,
989      ShuttingDownConnection,
990      NumConnectionStates
991    };
992
993    enum FastStartStates {
994      FastStartDisabled,
995      FastStartInitiate,
996      FastStartResponse,
997      FastStartAcknowledged,
998      NumFastStartStates
999    };
1000
1001};
1002
1003/////////////////////////////////////////////////////////////////////////////
1004