OPAL  Version 3.14.3
patch.h
Go to the documentation of this file.
1 /*
2  * patch.h
3  *
4  * Media stream patch thread.
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: 32132 $
28  * $Author: rjongbloed $
29  * $Date: 2014-06-11 17:31:56 +1000 (Wed, 11 Jun 2014) $
30  */
31 
32 #ifndef OPAL_OPAL_PATCH_H
33 #define OPAL_OPAL_PATCH_H
34 
35 #ifdef P_USE_PRAGMA
36 #pragma interface
37 #endif
38 
39 #include <opal_config.h>
40 
41 #include <opal/mediastrm.h>
42 #include <opal/mediacmd.h>
43 #include <codec/ratectl.h>
44 
45 #include <list>
46 
47 class OpalTranscoder;
48 
60 class OpalMediaPatch : public PSafeObject
61 {
62  PCLASSINFO(OpalMediaPatch, PObject);
63  public:
70  OpalMediaStream & source
71  );
72 
77 
84  void PrintOn(
85  ostream & strm
86  ) const;
88 
94  virtual void Start();
95 
104  virtual bool OnStartMediaPatch();
105 
111  virtual void Close();
112 
117  PBoolean AddSink(
118  const OpalMediaStreamPtr & stream
119  );
120 
125  void RemoveSink(
126  const OpalMediaStream & stream
127  );
128 
131  OpalMediaStream & GetSource() const { return m_source; }
132 
135  OpalMediaStreamPtr GetSink(PINDEX i = 0) const;
136 
139  OpalMediaFormat GetSinkFormat(PINDEX i = 0) const;
140 
145  void AddFilter(
146  const PNotifier & filter,
147  const OpalMediaFormat & stage = OpalMediaFormat()
148  );
149 
152  bool RemoveFilter(
153  const PNotifier & filter,
154  const OpalMediaFormat & stage = OpalMediaFormat()
155  );
156 
159  virtual void FilterFrame(
160  RTP_DataFrame & frame,
161  const OpalMediaFormat & mediaFormat
162  );
163 
173  virtual bool UpdateMediaFormat(
174  const OpalMediaFormat & mediaFormat
175  );
176 
186  virtual bool ExecuteCommand(
187  const OpalMediaCommand & command
188  );
189 
192  virtual bool InternalSetPaused(
193  bool pause,
194  bool fromUser
195  );
196 
199  virtual PBoolean PushFrame(
200  RTP_DataFrame & frame
201  );
202 
222  bool SetBypassPatch(
223  const OpalMediaPatchPtr & patch
224  );
225 
226  bool IsBypassed() const { return m_bypassToPatch != NULL || m_bypassFromPatch != NULL; }
227 
230  virtual OpalTranscoder * GetAndLockSinkTranscoder(PINDEX i = 0) const;
231  virtual void UnLockSinkTranscoder() const;
232 
233  virtual bool ResetTranscoders();
234  bool EnableJitterBuffer(bool enab = true);
235 
236 #if OPAL_STATISTICS
237  virtual void GetStatistics(OpalMediaStatistics & statistics, bool fromSink) const;
238 #endif
239 
240 
241  protected:
242  PDECLARE_NOTIFIER(OpalMediaCommand, OpalMediaPatch, InternalOnMediaCommand1);
244 
245  bool CanStart() const;
246 
248  virtual void Main();
249  void StopThread();
250  bool DispatchFrame(RTP_DataFrame & frame);
251 
253 
254  class Sink : public PObject {
255  PCLASSINFO(Sink, PObject);
256  public:
257  Sink(OpalMediaPatch & p, const OpalMediaStreamPtr & s);
258  ~Sink();
259  bool CreateTranscoders();
260  bool UpdateMediaFormat(const OpalMediaFormat & mediaFormat);
261  bool ExecuteCommand(const OpalMediaCommand & command);
262  bool WriteFrame(RTP_DataFrame & sourceFrame, bool bypassing);
263 #if OPAL_STATISTICS
264  void GetStatistics(OpalMediaStatistics & statistics, bool fromSource) const;
265 #endif
266 
271  RTP_DataFrameList m_intermediateFrames;
272  RTP_DataFrameList m_finalFrames;
274 
275 #if OPAL_VIDEO
276  void SetRateControlParameters(const OpalMediaFormat & mediaFormat);
277  bool RateControlExceeded(bool & forceIFrame);
279 
282  unsigned m_videoFrames;
283  unsigned m_keyFrames;
284 #endif
285  };
286  PList<Sink> m_sinks;
287 
288  class Filter : public PObject {
289  PCLASSINFO(Filter, PObject);
290  public:
291  Filter(const PNotifier & n, const OpalMediaFormat & s) : m_notifier(n), m_stage(s) { }
292 
293  PNotifier m_notifier;
295  };
296  PList<Filter> m_filters;
297 
298  OpalMediaPatchPtr m_bypassToPatch;
299  OpalMediaPatchPtr m_bypassFromPatch;
300  PSyncPoint m_bypassEnded;
301 
302  PThread * m_patchThread;
304 
306 
307  private:
308  P_REMOVE_VIRTUAL(bool, OnPatchStart(), false);
309 };
310 
319 {
321  public:
322 
324  OpalMediaStream & source
325  );
326 
327  virtual void Start();
328  virtual void Close();
329 
330  protected:
331  bool m_started;
332 };
333 
334 
335 #endif // OPAL_OPAL_PATCH_H
336 
337 
338 // End of File ///////////////////////////////////////////////////////////////