OPAL  Version 3.12.5
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: 29572 $
28  * $Author: rjongbloed $
29  * $Date: 2013-04-24 23:28:21 -0500 (Wed, 24 Apr 2013) $
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/buildopts.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();
330 
335  bool Retrieve();
336 
341  bool IsOnHold() const;
342 
375  bool Transfer(
376  const PString & address,
377  OpalConnection * connection = NULL
378  );
380 
392  const OpalConnection & connection
393  );
394 
403  virtual void AdjustMediaFormats(
404  bool local,
405  const OpalConnection & connection,
406  OpalMediaFormatList & mediaFormats
407  ) const;
408 
418  virtual bool OpenSourceMediaStreams(
419  OpalConnection & connection,
420  const OpalMediaType & mediaType,
421  unsigned sessionID = 0,
422  const OpalMediaFormat & preselectedFormat = OpalMediaFormat(),
423 #if OPAL_VIDEO
424  OpalVideoFormat::ContentRole contentRole = OpalVideoFormat::eNoRole,
425 #endif
426  bool transfer = false
427  );
428 
433  virtual bool SelectMediaFormats(
434  const OpalMediaType & mediaType,
435  const OpalMediaFormatList & srcFormats,
436  const OpalMediaFormatList & dstFormats,
437  const OpalMediaFormatList & allFormats,
438  OpalMediaFormat & srcFormat,
439  OpalMediaFormat & dstFormat
440  ) const;
441 
444  virtual void StartMediaStreams();
445 
448  virtual void CloseMediaStreams();
450 
458  virtual void OnUserInputString(
459  OpalConnection & connection,
460  const PString & value
461  );
462 
471  virtual void OnUserInputTone(
472  OpalConnection & connection,
473  char tone,
474  int duration
475  );
477 
482  OpalManager & GetManager() const { return manager; }
483 
486  const PString & GetToken() const { return myToken; }
487 
492  const PString & GetPartyA() const { return m_partyA; }
493 
499  const PString & GetPartyB() const { return m_partyB; }
500 
506  void SetPartyB(
507  const PString & b
508  ) { m_partyB = b; }
509 
514  const PString & GetNameA() const { return m_nameA; }
515 
521  const PString & GetNameB() const { return m_nameB; }
522 
527  bool IsNetworkOriginated() const { return m_networkOriginated; }
528 
531  const PString & GetRemoteParty() const { return m_networkOriginated ? m_partyA : m_partyB; }
532 
535  const PString & GetLocalParty() const { return m_networkOriginated ? m_partyB : m_partyA; }
536 
539  const PString & GetRemoteName() const { return m_networkOriginated ? m_nameA : m_nameB; }
540 
543  const PString & GetLocalName() const { return m_networkOriginated ? m_nameB : m_nameA; }
544 
547  const PTime & GetStartTime() const { return m_startTime; }
548 
551  const PTime & GetEstablishedTime() const { return m_establishedTime; }
553 
554 #if OPAL_HAS_MIXER
555 
560  bool StartRecording(
561  const PFilePath & filename,
562  const OpalRecordManager::Options & options = false
563  );
564 
567  bool IsRecording() const;
568 
572  void StopRecording();
573 
576  virtual bool OnStartRecording(
577  const PString & streamId,
578  const OpalMediaFormat & format
579  );
580 
583  virtual void OnStopRecording(
584  const PString & streamId
585  );
586 
589  virtual void OnRecordAudio(
590  const PString & streamId,
591  const RTP_DataFrame & frame
592  );
593 
594 #if OPAL_VIDEO
595 
597  virtual void OnRecordVideo(
598  const PString & streamId,
599  const RTP_DataFrame & frame
600  );
601 #endif
602 #endif // OPAL_HAS_MIXER
603 
604  void InternalOnClear();
605 
606  void SetPartyNames();
607 
608 #if OPAL_T38_CAPABILITY
609  bool IsSwitchingT38() const { return m_T38SwitchState != e_NotSwitchingT38; }
610  bool IsSwitchingToT38() const { return m_T38SwitchState == e_SwitchingToT38; }
611  void ResetSwitchingT38() { m_T38SwitchState = e_NotSwitchingT38; }
612  void SetSwitchingT38(bool to) { m_T38SwitchState = to ? e_SwitchingToT38 : e_SwitchingFromT38; }
613 #endif
614 
615  protected:
617  PSafePtr<OpalConnection> & connection,
618  PSafetyMode mode,
619  const OpalConnection * skipConnection = NULL
620  ) const;
621 
623 
624  PString myToken;
625 
626  PString m_partyA;
627  PString m_partyB;
628  PString m_nameA;
629  PString m_nameB;
631  PTime m_startTime;
635  PAtomicBoolean m_isCleared;
636 
638  std::list<PSyncPoint *> m_endCallSyncPoint;
639 
640  PSafeList<OpalConnection> connectionsActive;
641 
642 #if OPAL_HAS_MIXER
644 #endif
645 
646 #if OPAL_SCRIPT
647  PDECLARE_ScriptFunctionNotifier(OpalCall, ScriptClear);
648 #endif
649 
650 #if OPAL_T38_CAPABILITY
651  enum {
652  e_NotSwitchingT38,
653  e_SwitchingToT38,
654  e_SwitchingFromT38
655  } m_T38SwitchState;
656 #endif
657 
658  //use to add the connection to the call's connection list
659  friend OpalConnection::OpalConnection(OpalCall &, OpalEndPoint &, const PString &, unsigned int, OpalConnection::StringOptions *);
660  //use to remove the connection from the call's connection list
662 
663  P_REMOVE_VIRTUAL_VOID(OnRTPStatistics(const OpalConnection &, const OpalRTPSession &));
664 };
665 
666 
667 #endif // OPAL_OPAL_CALL_H
668 
669 
670 // End of File ///////////////////////////////////////////////////////////////