OPAL  Version 3.12.9
mediasession.h
Go to the documentation of this file.
1 /*
2  * mediasession.h
3  *
4  * Media session abstraction
5  *
6  * Open Phone Abstraction Library (OPAL)
7  *
8  * Copyright (C) 2010 Vox Lucida Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Open Phone Abstraction Library.
21  *
22  * The Initial Developer of the Original Code is Vox Lucida Pty. Ltd.
23  *
24  * Contributor(s): ______________________________________.
25  *
26  * $Revision: 29564 $
27  * $Author: rjongbloed $
28  * $Date: 2013-04-25 13:17:56 +1000 (Thu, 25 Apr 2013) $
29  */
30 
31 #ifndef OPAL_OPAL_MEDIASESSION_H
32 #define OPAL_OPAL_MEDIASESSION_H
33 
34 #ifdef P_USE_PRAGMA
35 #pragma interface
36 #endif
37 
38 #include <opal/buildopts.h>
39 
40 #include <opal/transports.h>
41 #include <opal/mediatype.h>
42 
43 
44 class OpalConnection;
45 class OpalMediaStream;
46 class OpalMediaFormat;
49 
50 
51 #if OPAL_STATISTICS
52 
55 class OpalMediaStatistics : public PObject
56 {
57  PCLASSINFO(OpalMediaStatistics, PObject);
58  public:
60 
61  // General info (typicallly from RTP)
62  PTime m_startTime;
63  PUInt64 m_totalBytes;
64  unsigned m_totalPackets;
65  unsigned m_packetsLost;
67  unsigned m_packetsTooLate;
68  unsigned m_packetOverruns;
72 
73  // Audio
74  unsigned m_averageJitter;
75  unsigned m_maximumJitter;
77 
78 #if OPAL_VIDEO
79  // Video
80  unsigned m_totalFrames;
81  unsigned m_keyFrames;
82  int m_quality; // -1 is none, 0 is very good > 0 is progressively worse
83 #endif
84 
85  // Fax
86 #if OPAL_FAX
87  enum {
92  };
98  };
99  friend ostream & operator<<(ostream & strm, FaxCompression compression);
100  struct Fax {
101  Fax();
102 
103  int m_result; // -2=not started, -1=progress, 0=success, >0=ended with error
104  char m_phase; // 'A', 'B', 'D'
105  int m_bitRate; // e.g. 14400, 9600
106  FaxCompression m_compression; // 0=N/A, 1=T.4 1d, 2=T.4 2d, 3=T.6
111  int m_imageSize; // In bytes
112  int m_resolutionX; // Pixels per inch
113  int m_resolutionY; // Pixels per inch
116  int m_badRows; // Total number of bad rows
117  int m_mostBadRows; // Longest run of bad rows
119 
120  PString m_stationId; // Remote station identifier
121  PString m_errorText;
122  } m_fax;
123 #endif // OPAL_FAX
124 };
125 
126 #endif
127 
128 
131 class OpalMediaCryptoKeyInfo : public PObject {
132  protected:
133  OpalMediaCryptoKeyInfo(const OpalMediaCryptoSuite & cryptoSuite) : m_cryptoSuite(cryptoSuite) { }
134 
135  public:
137 
138  virtual bool IsValid() const = 0;
139  virtual void Randomise() = 0;
140  virtual bool FromString(const PString & str) = 0;
141  virtual PString ToString() const = 0;
142 
144 
145  void SetTag(const PString & tag) { m_tag = tag; }
146  const PString & GetTag() const { return m_tag; }
147 
148  protected:
150  PString m_tag;
151 };
152 
153 typedef PList<OpalMediaCryptoKeyInfo> OpalMediaCryptoKeyList;
154 
155 
159 class OpalMediaCryptoSuite : public PObject
160 {
161  PCLASSINFO(OpalMediaCryptoSuite, PObject);
162  protected:
164 
165  public:
166  static const PCaselessString & ClearText();
167 
168  virtual const PCaselessString & GetFactoryName() const = 0;
169  virtual bool Supports(const PCaselessString & proto) const = 0;
170  virtual bool ChangeSessionType(PCaselessString & mediaSession) const = 0;
171 
172  virtual const char * GetDescription() const = 0;
173 
174  virtual OpalMediaCryptoKeyInfo * CreateKeyInfo() const = 0;
175 };
176 
177 typedef PFactory<OpalMediaCryptoSuite, PCaselessString> OpalMediaCryptoSuiteFactory;
178 
179 
182 class OpalMediaSession : public PSafeObject
183 {
184  PCLASSINFO(OpalMediaSession, PSafeObject);
185  public:
187  struct Init {
189  OpalConnection & connection,
190  unsigned sessionId,
191  const OpalMediaType & mediaType,
192  bool remoteBehindNAT
193  ) : m_connection(connection)
194  , m_sessionId(sessionId)
195  , m_mediaType(mediaType)
196  , m_remoteBehindNAT(remoteBehindNAT)
197  { }
198 
199 
201  unsigned m_sessionId;
204  };
205 
206  protected:
207  OpalMediaSession(const Init & init);
208 
209  public:
210  virtual const PCaselessString & GetSessionType() const = 0;
211  virtual bool Open(const PString & localInterface, const OpalTransportAddress & remoteAddress, bool isMediaAddress);
212  virtual bool IsOpen() const;
213  virtual bool Close();
214  virtual OpalTransportAddress GetLocalAddress(bool isMediaAddress = true) const;
215  virtual OpalTransportAddress GetRemoteAddress(bool isMediaAddress = true) const;
216  virtual bool SetRemoteAddress(const OpalTransportAddress & remoteAddress, bool isMediaAddress = true);
217 
218  typedef PList<PChannel> Transport;
219  virtual void AttachTransport(Transport & transport);
220  virtual Transport DetachTransport();
221 
223  virtual void SetExternalTransport(const OpalTransportAddressArray & transports);
224 
225 #if OPAL_SIP
227 #endif
228 
230  const OpalMediaFormat & mediaFormat,
231  unsigned sessionID,
232  bool isSource
233  ) = 0;
234 
235 #if OPAL_STATISTICS
236  virtual void GetStatistics(OpalMediaStatistics & statistics, bool receiver) const;
237 #endif
238 
239  void OfferCryptoSuite(const PString & cryptoSuite);
241 
242  virtual bool ApplyCryptoKey(
243  OpalMediaCryptoKeyList & keys,
244  bool rx
245  );
246 
247 
248  unsigned GetSessionID() const { return m_sessionId; }
249  const OpalMediaType & GetMediaType() const { return m_mediaType; }
250 
251  protected:
253  unsigned m_sessionId; // unique session ID
254  OpalMediaType m_mediaType; // media type for session
256 
258 
259  private:
260  OpalMediaSession(const OpalMediaSession & other) : PSafeObject(other), m_connection(other.m_connection) { }
261  void operator=(const OpalMediaSession &) { }
262 
263  P_REMOVE_VIRTUAL(bool, Open(const PString &), false);
264  P_REMOVE_VIRTUAL(OpalTransportAddress, GetLocalMediaAddress() const, 0);
265  P_REMOVE_VIRTUAL(OpalTransportAddress, GetRemoteMediaAddress() const, 0);
266  P_REMOVE_VIRTUAL(bool, SetRemoteMediaAddress(const OpalTransportAddress &), false);
267  P_REMOVE_VIRTUAL(OpalTransportAddress, GetRemoteControlAddress() const, 0);
268  P_REMOVE_VIRTUAL(bool, SetRemoteControlAddress(const OpalTransportAddress &), false);
269 };
270 
271 
272 typedef PParamFactory<OpalMediaSession, const OpalMediaSession::Init &, PCaselessString> OpalMediaSessionFactory;
273 
274 #ifdef OPAL_SRTP
275 PFACTORY_LOAD(OpalSRTPSession);
276 #endif
277 
278 
279 #endif // OPAL_OPAL_MEDIASESSION_H