OPAL  Version 3.14.3
call.h
Go to the documentation of this file.
1 /*
2  * call.h
3  *
4  * Telephone call management
5  *
6  * Open Phone Abstraction Library (OPAL)
7  * Formally known as the Open H323 project.
8  *
9  * Copyright (c) 2001 Equivalence Pty. Ltd.
10  *
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/
15  *
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.
20  *
21  * The Original Code is Open Phone Abstraction Library.
22  *
23  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24  *
25  * Contributor(s): ______________________________________.
26  *
27  * $Revision: 32046 $
28  * $Author: rjongbloed $
29  * $Date: 2014-06-03 16:41:33 +1000 (Tue, 03 Jun 2014) $
30  */
31 
32 #ifndef OPAL_OPAL_CALL_H
33 #define OPAL_OPAL_CALL_H
34 
35 #ifdef P_USE_PRAGMA
36 #pragma interface
37 #endif
38 
39 #include <opal_config.h>
40 
41 #include <opal/connection.h>
42 #include <opal/recording.h>
43 #include <opal/guid.h>
44 
45 #include <ptlib/safecoll.h>
46 
47 
48 class OpalManager;
49 
50 
65 class OpalCall : public PSafeObject
66 {
67  PCLASSINFO(OpalCall, PSafeObject);
68  public:
73  OpalCall(
75  );
76 
79  ~OpalCall();
81 
88  void PrintOn(
89  ostream & strm
90  ) const;
92 
97  PBoolean IsEstablished() const { return m_isEstablished; }
98 
107  virtual void OnEstablishedCall();
108 
118 
122 
127  void SetCallEndReason(
129  );
130 
139  void Clear(
140  OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser,
141  PSyncPoint * sync = NULL
142  );
143 
149  virtual void OnCleared();
151 
159  virtual void OnNewConnection(
160  OpalConnection & connection
161  );
162 
168  virtual PBoolean OnSetUp(
169  OpalConnection & connection
170  );
171 
186  virtual void OnProceeding(
187  OpalConnection & connection
188  );
189 
206  virtual PBoolean OnAlerting(
207  OpalConnection & connection
208  );
209 
226  virtual OpalConnection::AnswerCallResponse OnAnswerCall(
227  OpalConnection & connection,
228  const PString & caller
229  );
230 
242  virtual PBoolean OnConnected(
243  OpalConnection & connection
244  );
245 
260  virtual PBoolean OnEstablished(
261  OpalConnection & connection
262  );
263 
269  virtual void OnReleased(
270  OpalConnection & connection
271  );
272 
279  virtual void OnHold(
280  OpalConnection & connection,
281  bool fromRemote,
282  bool onHold
283  );
284 
290  PSafePtr<OpalConnection> GetOtherPartyConnection(
291  const OpalConnection & connection
292  ) const;
293 
296  PINDEX GetConnectionCount() const { return connectionsActive.GetSize(); }
297 
300  PSafePtr<OpalConnection> GetConnection(
301  PINDEX idx,
302  PSafetyMode mode = PSafeReference
303  ) { return connectionsActive.GetAt(idx, mode); }
304 
308  template <class ConnClass>
309  PSafePtr<ConnClass> GetConnectionAs(
310  PINDEX count = 0,
311  PSafetyMode mode = PSafeReadWrite
312  )
313  {
314  PSafePtr<ConnClass> connection;
315  for (PSafePtr<OpalConnection> iterConn(connectionsActive, PSafeReference); iterConn != NULL; ++iterConn) {
316  if ((connection = PSafePtrCast<OpalConnection, ConnClass>(iterConn)) != NULL && count-- == 0) {
317  if (!connection.SetSafetyMode(mode))
318  connection.SetNULL();
319  break;
320  }
321  }
322  return connection;
323  }
324 
329  bool Hold(bool hold = true);
330 
335  bool Retrieve() { return Hold(false); }
336 
341  bool IsOnHold(
342  bool fromRemote = false
343  ) const;
344 
377  bool Transfer(
378  const PString & address,
379  OpalConnection * connection = NULL
380  );
382 
394  const OpalConnection & connection
395  );
396 
405  virtual void AdjustMediaFormats(
406  bool local,
407  const OpalConnection & connection,
408  OpalMediaFormatList & mediaFormats
409  ) const;
410 
420  virtual bool OpenSourceMediaStreams(
421  OpalConnection & connection,
422  const OpalMediaType & mediaType,
423  unsigned sessionID = 0,
424  const OpalMediaFormat & preselectedFormat = OpalMediaFormat(),
425 #if OPAL_VIDEO
426  OpalVideoFormat::ContentRole contentRole = OpalVideoFormat::eNoRole,
427 #endif
428  bool transfer = false,
429  bool startPaused = false
430  );
431 
436  virtual bool SelectMediaFormats(
437  const OpalMediaType & mediaType,
438  const OpalMediaFormatList & srcFormats,
439  const OpalMediaFormatList & dstFormats,
440  const OpalMediaFormatList & allFormats,
441  OpalMediaFormat & srcFormat,
442  OpalMediaFormat & dstFormat
443  ) const;
444 
447  virtual void CloseMediaStreams();
449 
457  virtual void OnUserInputString(
458  OpalConnection & connection,
459  const PString & value
460  );
461 
478  virtual void OnUserInputTone(
479  OpalConnection & connection,
480  char tone,
481  int duration
482  );
484 
489  OpalManager & GetManager() const { return manager; }
490 
493  const PString & GetToken() const { return myToken; }
494 
499  const PString & GetPartyA() const { return m_partyA; }
500 
506  const PString & GetPartyB() const { return m_partyB; }
507 
513  void SetPartyB(
514  const PString & b
515  ) { m_partyB = b; }
516 
521  const PString & GetNameA() const { return m_nameA; }
522 
528  const PString & GetNameB() const { return m_nameB; }
529 
534  bool IsNetworkOriginated() const { return m_networkOriginated; }
535 
538  const PString & GetRemoteParty() const { return m_networkOriginated ? m_partyA : m_partyB; }
539 
542  const PString & GetLocalParty() const { return m_networkOriginated ? m_partyB : m_partyA; }
543 
546  const PString & GetRemoteName() const { return m_networkOriginated ? m_nameA : m_nameB; }
547 
550  const PString & GetLocalName() const { return m_networkOriginated ? m_nameB : m_nameA; }
551 
554  const PTime & GetStartTime() const { return m_startTime; }
555 
558  const PTime & GetEstablishedTime() const { return m_establishedTime; }
560 
561 #if OPAL_HAS_MIXER
562 
567  bool StartRecording(
568  const PFilePath & filename,
569  const OpalRecordManager::Options & options = false
570  );
571 
574  bool IsRecording() const;
575 
579  void StopRecording();
580 
583  virtual bool OnStartRecording(
584  const PString & streamId,
585  const OpalMediaFormat & format
586  );
587 
590  virtual void OnStopRecording(
591  const PString & streamId
592  );
593 
596  virtual void OnRecordAudio(
597  const PString & streamId,
598  const RTP_DataFrame & frame
599  );
600 
601 #if OPAL_VIDEO
602 
604  virtual void OnRecordVideo(
605  const PString & streamId,
606  const RTP_DataFrame & frame
607  );
608 #endif
609 #endif // OPAL_HAS_MIXER
610 
611  void InternalOnClear();
612 
613  void SetPartyNames();
614 
615 #if OPAL_T38_CAPABILITY
616  bool IsSwitchingT38() const { return m_T38SwitchState != e_NotSwitchingT38; }
617  bool IsSwitchingToT38() const { return m_T38SwitchState == e_SwitchingToT38; }
618  void ResetSwitchingT38() { m_T38SwitchState = e_NotSwitchingT38; }
619  void SetSwitchingT38(bool to) { m_T38SwitchState = to ? e_SwitchingToT38 : e_SwitchingFromT38; }
620 #endif
621 
622  protected:
624  PSafePtr<OpalConnection> & connection,
625  PSafetyMode mode,
626  const OpalConnection * skipConnection = NULL
627  ) const;
628 
630 
631  PString myToken;
632 
633  PString m_partyA;
634  PString m_partyB;
635  PString m_nameA;
636  PString m_nameB;
638  PTime m_startTime;
643  PAtomicBoolean m_isCleared;
644 
646  std::list<PSyncPoint *> m_endCallSyncPoint;
647 
648  PSafeList<OpalConnection> connectionsActive;
649 
650 #if OPAL_HAS_MIXER
652 #endif
653 
654 #if OPAL_SCRIPT
655  PDECLARE_ScriptFunctionNotifier(OpalCall, ScriptClear);
656 #endif
657 
658 #if OPAL_T38_CAPABILITY
659  enum {
660  e_NotSwitchingT38,
661  e_SwitchingToT38,
662  e_SwitchingFromT38
663  } m_T38SwitchState;
664 #endif
665 
666  //use to add the connection to the call's connection list
667  friend OpalConnection::OpalConnection(OpalCall &, OpalEndPoint &, const PString &, unsigned int, OpalConnection::StringOptions *);
668  //use to remove the connection from the call's connection list
670 
671  P_REMOVE_VIRTUAL_VOID(OnRTPStatistics(const OpalConnection &, const OpalRTPSession &));
672 };
673 
674 
675 #endif // OPAL_OPAL_CALL_H
676 
677 
678 // End of File ///////////////////////////////////////////////////////////////