patch.h

Go to the documentation of this file.
00001 /*
00002  * patch.h
00003  *
00004  * Media stream patch thread.
00005  *
00006  * Open Phone Abstraction Library (OPAL)
00007  * Formally known as the Open H323 project.
00008  *
00009  * Copyright (c) 2001 Equivalence Pty. Ltd.
00010  *
00011  * The contents of this file are subject to the Mozilla Public License
00012  * Version 1.0 (the "License"); you may not use this file except in
00013  * compliance with the License. You may obtain a copy of the License at
00014  * http://www.mozilla.org/MPL/
00015  *
00016  * Software distributed under the License is distributed on an "AS IS"
00017  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00018  * the License for the specific language governing rights and limitations
00019  * under the License.
00020  *
00021  * The Original Code is Open Phone Abstraction Library.
00022  *
00023  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00024  *
00025  * Contributor(s): ______________________________________.
00026  *
00027  * $Revision: 21283 $
00028  * $Author: rjongbloed $
00029  * $Date: 2008-10-11 07:10:58 +0000 (Sat, 11 Oct 2008) $
00030  */
00031 
00032 #ifndef OPAL_OPAL_PATCH_H
00033 #define OPAL_OPAL_PATCH_H
00034 
00035 #ifdef P_USE_PRAGMA
00036 #pragma interface
00037 #endif
00038 
00039 #include <opal/buildopts.h>
00040 
00041 #include <opal/mediastrm.h>
00042 #include <opal/mediacmd.h>
00043 
00044 #include <list>
00045 
00046 
00047 class OpalTranscoder;
00048 
00049 
00061 class OpalMediaPatch : public PObject
00062 {
00063     PCLASSINFO(OpalMediaPatch, PObject);
00064   public:
00070     OpalMediaPatch(
00071       OpalMediaStream & source       
00072     );
00073 
00076     ~OpalMediaPatch();
00078 
00085     void PrintOn(
00086       ostream & strm    
00087     ) const;
00089 
00095     virtual void Start();
00096 
00102     virtual void Close();
00103 
00108     PBoolean AddSink(
00109       const OpalMediaStreamPtr & stream            
00110     );
00111 
00116     void RemoveSink(
00117       const OpalMediaStreamPtr & stream  
00118     );
00119 
00122     OpalMediaStream & GetSource() const { return source; }
00123 
00126     OpalMediaStreamPtr GetSink(PINDEX i = 0) const;
00127 
00130     OpalMediaFormat GetSinkFormat(PINDEX i = 0) const;
00131 
00136     void AddFilter(
00137       const PNotifier & filter,
00138       const OpalMediaFormat & stage = OpalMediaFormat()
00139     );
00140 
00143     PBoolean RemoveFilter(
00144       const PNotifier & filter,
00145       const OpalMediaFormat & stage = OpalMediaFormat()
00146     );
00147 
00150     virtual void FilterFrame(
00151       RTP_DataFrame & frame,
00152       const OpalMediaFormat & mediaFormat
00153     );
00154 
00164     virtual bool UpdateMediaFormat(
00165       const OpalMediaFormat & mediaFormat  
00166     );
00167 
00175     virtual PBoolean ExecuteCommand(
00176       const OpalMediaCommand & command,   
00177       PBoolean fromSink                       
00178     );
00179 
00187     virtual void SetCommandNotifier(
00188       const PNotifier & notifier,   
00189       PBoolean fromSink                 
00190     );
00191 
00192     virtual PBoolean PushFrame(RTP_DataFrame & /*frame*/) { return PFalse; };
00193 
00196     virtual OpalTranscoder * GetAndLockSinkTranscoder(PINDEX i = 0) const;
00197     virtual void UnLockSinkTranscoder() const;
00198 
00199 #if OPAL_STATISTICS
00200     virtual void GetStatistics(OpalMediaStatistics & statistics) const;
00201 #endif
00202 
00203 
00204   protected:
00205                 
00207     virtual void Main();
00208     bool DispatchFrame(RTP_DataFrame & frame);
00209         
00210     OpalMediaStream & source;
00211 
00212     class Sink : public PObject {
00213         PCLASSINFO(Sink, PObject);
00214       public:
00215         Sink(OpalMediaPatch & p, const OpalMediaStreamPtr & s);
00216         ~Sink();
00217         bool UpdateMediaFormat(const OpalMediaFormat & mediaFormat);
00218         bool ExecuteCommand(const OpalMediaCommand & command);
00219         void SetCommandNotifier(const PNotifier & notifier);
00220         bool WriteFrame(RTP_DataFrame & sourceFrame);
00221 #if OPAL_STATISTICS
00222         void GetStatistics(OpalMediaStatistics & statistics) const;
00223 #endif
00224 
00225         OpalMediaPatch  &  patch;
00226         OpalMediaStreamPtr stream;
00227         OpalTranscoder  * primaryCodec;
00228         OpalTranscoder  * secondaryCodec;
00229         RTP_DataFrameList intermediateFrames;
00230         RTP_DataFrameList finalFrames;
00231         bool              writeSuccessful;
00232 
00233 #if OPAL_VIDEO
00234         void SetRateControlParameters(const OpalMediaFormat & mediaFormat);
00235         bool RateControlExceeded(const PTimeInterval & currentTime);
00236 
00237         bool          rcEnabled;
00238         unsigned      rcByteRate;
00239         unsigned      rcWindowSize;
00240         unsigned      rcMaxConsecutiveFramesSkip;
00241         unsigned      rcConsecutiveFramesSkipped;
00242         PTimeInterval rcLastTime;
00243         PINDEX        rcTotalSize;
00244         
00245         struct FrameInfo {
00246           PTimeInterval time;
00247           PINDEX        size;
00248         };
00249         std::list<FrameInfo> frameInfoList;
00250 #endif
00251     };
00252     PList<Sink> sinks;
00253 
00254     class Filter : public PObject {
00255         PCLASSINFO(Filter, PObject);
00256       public:
00257         Filter(const PNotifier & n, const OpalMediaFormat & s) : notifier(n), stage(s) { }
00258         PNotifier notifier;
00259         OpalMediaFormat stage;
00260     };
00261     PList<Filter> filters;
00262         
00263     class Thread : public PThread {
00264         PCLASSINFO(Thread, PThread);
00265       public:
00266         Thread(OpalMediaPatch & p);
00267         virtual void Main() { patch.Main(); };
00268         OpalMediaPatch & patch;
00269     };
00270 
00271     Thread * patchThread;
00272     PMutex patchThreadMutex;
00273     mutable PReadWriteMutex inUse;
00274 };
00275 
00283 class OpalPassiveMediaPatch : public OpalMediaPatch
00284 {
00285     PCLASSINFO(OpalPassiveMediaPatch, OpalMediaPatch);
00286   public:
00287 
00288     OpalPassiveMediaPatch(
00289       OpalMediaStream & source       
00290     );
00291 
00292     virtual void Start();
00293     virtual PBoolean PushFrame(RTP_DataFrame & frame);
00294 };
00295 
00296 
00297 #endif // OPAL_OPAL_PATCH_H
00298 
00299 
00300 // End of File ///////////////////////////////////////////////////////////////

Generated on Mon Feb 23 02:01:38 2009 for OPAL by  doxygen 1.5.1