OPAL Version 3.10.4

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files

- File List
- Globals

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: 26730 $
28 * $Author: rjongbloed $
29 * $Date: 2011-12-02 01:12:02 -0600 (Fri, 02 Dec 2011) $
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 PObject
61 {
62 PCLASSINFO(OpalMediaPatch, PObject);
63 public:
69 OpalMediaPatch(
70 OpalMediaStream & source
71 );
72
75 ~OpalMediaPatch();
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 OpalMediaStreamPtr & 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 OpalMediaPatch * patch
224 );
225
228 virtual OpalTranscoder * GetAndLockSinkTranscoder(PINDEX i = 0) const;
229 virtual void UnLockSinkTranscoder() const;
230
231 #if OPAL_STATISTICS
232 virtual void GetStatistics(OpalMediaStatistics & statistics, bool fromSink) const;
233 #endif
234
235
236 PDECLARE_NOTIFIER(OpalMediaCommand, OpalMediaPatch, OnMediaCommand);
237
238 protected:
239
241 virtual void Main();
242 bool DispatchFrame(RTP_DataFrame & frame);
243 bool EnableJitterBuffer();
244
245 OpalMediaStream & source;
246
247 class Sink : public PObject {
248 PCLASSINFO(Sink, PObject);
249 public:
250 Sink(OpalMediaPatch & p, const OpalMediaStreamPtr & s);
251 ~Sink();
252 bool UpdateMediaFormat(const OpalMediaFormat & mediaFormat);
253 bool ExecuteCommand(const OpalMediaCommand & command);
254 bool WriteFrame(RTP_DataFrame & sourceFrame);
255 #if OPAL_STATISTICS
256 void GetStatistics(OpalMediaStatistics & statistics, bool fromSource) const;
257 #endif
258
259 OpalMediaPatch & patch;
260 OpalMediaStreamPtr stream;
261 OpalTranscoder * primaryCodec;
262 OpalTranscoder * secondaryCodec;
263 RTP_DataFrameList intermediateFrames;
264 RTP_DataFrameList finalFrames;
265 bool writeSuccessful;
266
267 RTP_DataFrame::PayloadTypes m_lastPayloadType;
268 unsigned m_consecutivePayloadTypeMismatches;
269 bool CannotTranscodeFrame(OpalTranscoder & codec, RTP_DataFrame & frame);
270
271 #if OPAL_VIDEO
272 void SetRateControlParameters(const OpalMediaFormat & mediaFormat);
273 bool RateControlExceeded(bool & forceIFrame);
274 OpalVideoRateController * rateController;
275 #endif
276 };
277 PList<Sink> sinks;
278
279 class Filter : public PObject {
280 PCLASSINFO(Filter, PObject);
281 public:
282 Filter(const PNotifier & n, const OpalMediaFormat & s) : notifier(n), stage(s) { }
283 PNotifier notifier;
284 OpalMediaFormat stage;
285 };
286 PList<Filter> filters;
287
288 OpalMediaPatch * m_bypassToPatch;
289 OpalMediaPatch * m_bypassFromPatch;
290 PSyncPoint m_bypassEnded;
291
292 class Thread : public PThread {
293 PCLASSINFO(Thread, PThread);
294 public:
295 Thread(OpalMediaPatch & p);
296 virtual void Main() { patch.Main(); };
297 OpalMediaPatch & patch;
298 };
299
300 Thread * patchThread;
301 PMutex patchThreadMutex;
302 mutable PReadWriteMutex inUse;
303
304 private:
305 P_REMOVE_VIRTUAL(bool, OnPatchStart(), false);
306 };
307
315 class OpalPassiveMediaPatch : public OpalMediaPatch
316 {
317 PCLASSINFO(OpalPassiveMediaPatch, OpalMediaPatch);
318 public:
319
320 OpalPassiveMediaPatch(
321 OpalMediaStream & source
322 );
323
324 virtual void Start();
325 };
326
327
328 #endif // OPAL_OPAL_PATCH_H
329
330
331 // End of File ///////////////////////////////////////////////////////////////