OPAL  Version 3.12.9
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: 29334 $
28  * $Author: rjongbloed $
29  * $Date: 2013-03-27 14:08:07 +1100 (Wed, 27 Mar 2013) $
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/buildopts.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:
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 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 PBoolean ExecuteCommand(
187  const OpalMediaCommand & command,
188  PBoolean fromSink
189  );
190 
193  virtual bool SetPaused(
194  bool pause
195  );
196 
199  virtual PBoolean PushFrame(
200  RTP_DataFrame & frame
201  );
202 
222  bool SetBypassPatch(
223  const OpalMediaPatchPtr & patch
224  );
225 
228  virtual OpalTranscoder * GetAndLockSinkTranscoder(PINDEX i = 0) const;
229  virtual void UnLockSinkTranscoder() const;
230 
231  virtual bool ResetTranscoders();
232  bool EnableJitterBuffer(bool enab = true);
233 
234 #if OPAL_STATISTICS
235  virtual void GetStatistics(OpalMediaStatistics & statistics, bool fromSink) const;
236 #endif
237 
238 
239  protected:
240  PDECLARE_NOTIFIER(OpalMediaCommand, OpalMediaPatch, InternalOnMediaCommand1);
242 
244  virtual void Main();
245  void StopThread();
246  bool DispatchFrame(RTP_DataFrame & frame);
247 
249 
250  class Sink : public PObject {
251  PCLASSINFO(Sink, PObject);
252  public:
253  Sink(OpalMediaPatch & p, const OpalMediaStreamPtr & s);
254  ~Sink();
255  bool CreateTranscoders();
256  bool UpdateMediaFormat(const OpalMediaFormat & mediaFormat);
257  bool ExecuteCommand(const OpalMediaCommand & command);
258  bool WriteFrame(RTP_DataFrame & sourceFrame);
259 #if OPAL_STATISTICS
260  void GetStatistics(OpalMediaStatistics & statistics, bool fromSource) const;
261 #endif
262 
267  RTP_DataFrameList intermediateFrames;
268  RTP_DataFrameList finalFrames;
270 
273  bool CannotTranscodeFrame(OpalTranscoder & codec, RTP_DataFrame & frame);
274 
275 #if OPAL_VIDEO
276  void SetRateControlParameters(const OpalMediaFormat & mediaFormat);
277  bool RateControlExceeded(bool & forceIFrame);
279 #endif
280  };
281  PList<Sink> sinks;
282 
283  class Filter : public PObject {
284  PCLASSINFO(Filter, PObject);
285  public:
286  Filter(const PNotifier & n, const OpalMediaFormat & s) : notifier(n), stage(s) { }
287  PNotifier notifier;
289  };
290  PList<Filter> filters;
291 
292  OpalMediaPatchPtr m_bypassToPatch;
293  OpalMediaPatchPtr m_bypassFromPatch;
294  PSyncPoint m_bypassEnded;
295 
296  PThread * patchThread;
298 
299  private:
300  P_REMOVE_VIRTUAL(bool, OnPatchStart(), false);
301 };
302 
311 {
313  public:
314 
316  OpalMediaStream & source
317  );
318 
319  virtual void Start();
320 
321  protected:
322  bool m_started;
323 };
324 
325 
326 #endif // OPAL_OPAL_PATCH_H
327 
328 
329 // End of File ///////////////////////////////////////////////////////////////