OPAL  Version 3.12.9
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: 30573 $
28  * $Author: rjongbloed $
29  * $Date: 2013-09-26 13:20:43 +1000 (Thu, 26 Sep 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 CloseMediaStreams();
446 
454  virtual void OnUserInputString(
455  OpalConnection & connection,
456  const PString & value
457  );
458 
467  virtual void OnUserInputTone(
468  OpalConnection & connection,
469  char tone,
470  int duration
471  );
473 
478  OpalManager & GetManager() const { return manager; }
479 
482  const PString & GetToken() const { return myToken; }
483 
488  const PString & GetPartyA() const { return m_partyA; }
489 
495  const PString & GetPartyB() const { return m_partyB; }
496 
502  void SetPartyB(
503  const PString & b
504  ) { m_partyB = b; }
505 
510  const PString & GetNameA() const { return m_nameA; }
511 
517  const PString & GetNameB() const { return m_nameB; }
518 
523  bool IsNetworkOriginated() const { return m_networkOriginated; }
524 
527  const PString & GetRemoteParty() const { return m_networkOriginated ? m_partyA : m_partyB; }
528 
531  const PString & GetLocalParty() const { return m_networkOriginated ? m_partyB : m_partyA; }
532 
535  const PString & GetRemoteName() const { return m_networkOriginated ? m_nameA : m_nameB; }
536 
539  const PString & GetLocalName() const { return m_networkOriginated ? m_nameB : m_nameA; }
540 
543  const PTime & GetStartTime() const { return m_startTime; }
544 
547  const PTime & GetEstablishedTime() const { return m_establishedTime; }
549 
550 #if OPAL_HAS_MIXER
551 
556  bool StartRecording(
557  const PFilePath & filename,
558  const OpalRecordManager::Options & options = false
559  );
560 
563  bool IsRecording() const;
564 
568  void StopRecording();
569 
572  virtual bool OnStartRecording(
573  const PString & streamId,
574  const OpalMediaFormat & format
575  );
576 
579  virtual void OnStopRecording(
580  const PString & streamId
581  );
582 
585  virtual void OnRecordAudio(
586  const PString & streamId,
587  const RTP_DataFrame & frame
588  );
589 
590 #if OPAL_VIDEO
591 
593  virtual void OnRecordVideo(
594  const PString & streamId,
595  const RTP_DataFrame & frame
596  );
597 #endif
598 #endif // OPAL_HAS_MIXER
599 
600  void InternalOnClear();
601 
602  void SetPartyNames();
603 
604 #if OPAL_T38_CAPABILITY
605  bool IsSwitchingT38() const { return m_T38SwitchState != e_NotSwitchingT38; }
606  bool IsSwitchingToT38() const { return m_T38SwitchState == e_SwitchingToT38; }
607  void ResetSwitchingT38() { m_T38SwitchState = e_NotSwitchingT38; }
608  void SetSwitchingT38(bool to) { m_T38SwitchState = to ? e_SwitchingToT38 : e_SwitchingFromT38; }
609 #endif
610 
611  protected:
613  PSafePtr<OpalConnection> & connection,
614  PSafetyMode mode,
615  const OpalConnection * skipConnection = NULL
616  ) const;
617 
619 
620  PString myToken;
621 
622  PString m_partyA;
623  PString m_partyB;
624  PString m_nameA;
625  PString m_nameB;
627  PTime m_startTime;
631  PAtomicBoolean m_isCleared;
632 
634  std::list<PSyncPoint *> m_endCallSyncPoint;
635 
636  PSafeList<OpalConnection> connectionsActive;
637 
638 #if OPAL_HAS_MIXER
640 #endif
641 
642 #if OPAL_SCRIPT
643  PDECLARE_ScriptFunctionNotifier(OpalCall, ScriptClear);
644 #endif
645 
646 #if OPAL_T38_CAPABILITY
647  enum {
648  e_NotSwitchingT38,
649  e_SwitchingToT38,
650  e_SwitchingFromT38
651  } m_T38SwitchState;
652 #endif
653 
654  //use to add the connection to the call's connection list
655  friend OpalConnection::OpalConnection(OpalCall &, OpalEndPoint &, const PString &, unsigned int, OpalConnection::StringOptions *);
656  //use to remove the connection from the call's connection list
658 
659  P_REMOVE_VIRTUAL_VOID(OnRTPStatistics(const OpalConnection &, const OpalRTPSession &));
660 };
661 
662 
663 #endif // OPAL_OPAL_CALL_H
664 
665 
666 // End of File ///////////////////////////////////////////////////////////////