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: 19647 $
00028  * $Author: rjongbloed $
00029  * $Date: 2008-03-03 01:54:25 +0000 (Mon, 03 Mar 2008) $
00030  */
00031 
00032 #ifndef __OPAL_PATCH_H
00033 #define __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 
00045 class OpalTranscoder;
00046 
00047 
00059 class OpalMediaPatch : public PObject
00060 {
00061     PCLASSINFO(OpalMediaPatch, PObject);
00062   public:
00068     OpalMediaPatch(
00069       OpalMediaStream & source       
00070     );
00071 
00074     ~OpalMediaPatch();
00076 
00083     void PrintOn(
00084       ostream & strm    
00085     ) const;
00087 
00093     virtual void Start();
00094 
00100     virtual void Close();
00101 
00106     PBoolean AddSink(
00107       const OpalMediaStreamPtr & stream,            
00108       const RTP_DataFrame::PayloadMapType & rtpMap  
00109     );
00110 
00115     void RemoveSink(
00116       const OpalMediaStreamPtr & stream  
00117     );
00118 
00121     OpalMediaStream & GetSource() const { return source; }
00122 
00125     OpalMediaFormat GetSinkFormat(PINDEX i = 0) const;
00126 
00131     void AddFilter(
00132       const PNotifier & filter,
00133       const OpalMediaFormat & stage = OpalMediaFormat()
00134     );
00135 
00138     PBoolean RemoveFilter(
00139       const PNotifier & filter,
00140       const OpalMediaFormat & stage = OpalMediaFormat()
00141     );
00142 
00145     virtual void FilterFrame(
00146       RTP_DataFrame & frame,
00147       const OpalMediaFormat & mediaFormat
00148     );
00149 
00158     virtual PBoolean UpdateMediaFormat(
00159       const OpalMediaFormat & mediaFormat,  
00160       PBoolean fromSink                         
00161     );
00162 
00170     virtual PBoolean ExecuteCommand(
00171       const OpalMediaCommand & command,   
00172       PBoolean fromSink                       
00173     );
00174 
00182     virtual void SetCommandNotifier(
00183       const PNotifier & notifier,   
00184       PBoolean fromSink                 
00185     );
00186 
00187     virtual PBoolean PushFrame(RTP_DataFrame & /*frame*/) { return PFalse; };
00188 
00191     virtual OpalTranscoder * GetAndLockSinkTranscoder(PINDEX i = 0) const;
00192     virtual void UnLockSinkTranscoder() const;
00193 
00194 #ifdef OPAL_STATISTICS
00195     virtual void GetStatistics(OpalMediaStatistics & statistics) const;
00196 #endif
00197 
00198 
00199   protected:
00200                 
00202     virtual void Main();
00203     bool DispatchFrame(RTP_DataFrame & frame);
00204         
00205     OpalMediaStream & source;
00206 
00207     class Sink : public PObject {
00208         PCLASSINFO(Sink, PObject);
00209       public:
00210         Sink(OpalMediaPatch & p, const OpalMediaStreamPtr & s, const RTP_DataFrame::PayloadMapType & m);
00211         ~Sink();
00212         bool UpdateMediaFormat(const OpalMediaFormat & mediaFormat);
00213         bool ExecuteCommand(const OpalMediaCommand & command);
00214         void SetCommandNotifier(const PNotifier & notifier);
00215         bool WriteFrame(RTP_DataFrame & sourceFrame);
00216 #ifdef OPAL_STATISTICS
00217         void GetStatistics(OpalMediaStatistics & statistics) const;
00218 #endif
00219 
00220         OpalMediaPatch  &  patch;
00221         OpalMediaStreamPtr stream;
00222         RTP_DataFrame::PayloadMapType payloadTypeMap;
00223         OpalTranscoder  * primaryCodec;
00224         OpalTranscoder  * secondaryCodec;
00225         RTP_DataFrameList intermediateFrames;
00226         RTP_DataFrameList finalFrames;
00227         bool              writeSuccessful;
00228     };
00229     PList<Sink> sinks;
00230 
00231     class Filter : public PObject {
00232         PCLASSINFO(Filter, PObject);
00233       public:
00234         Filter(const PNotifier & n, const OpalMediaFormat & s) : notifier(n), stage(s) { }
00235         PNotifier notifier;
00236         OpalMediaFormat stage;
00237     };
00238     PList<Filter> filters;
00239         
00240     class Thread : public PThread {
00241         PCLASSINFO(Thread, PThread);
00242       public:
00243         Thread(OpalMediaPatch & p);
00244         virtual void Main() { patch.Main(); };
00245         OpalMediaPatch & patch;
00246     };
00247 
00248     Thread * patchThread;
00249     PMutex patchThreadMutex;
00250     mutable PMutex inUse;
00251 };
00252 
00260 class OpalPassiveMediaPatch : public OpalMediaPatch
00261 {
00262     PCLASSINFO(OpalPassiveMediaPatch, OpalMediaPatch);
00263   public:
00264 
00265     OpalPassiveMediaPatch(
00266       OpalMediaStream & source       
00267     );
00268 
00269     virtual void Start();
00270     virtual PBoolean PushFrame(RTP_DataFrame & frame);
00271 };
00272 
00273 
00274 #endif // __OPAL_PATCH_H
00275 
00276 
00277 // End of File ///////////////////////////////////////////////////////////////

Generated on Fri Mar 7 07:36:38 2008 for OPAL by  doxygen 1.5.1