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  * $Log: patch.h,v $
00028  * Revision 2.17  2007/09/05 13:43:04  csoutheren
00029  * Applied 1748637 - RTP payload translation
00030  * Thanks to Borko Jandras
00031  *
00032  * Revision 2.16  2007/08/01 08:37:46  csoutheren
00033  * Add function to lock sink transcoders so options can be set
00034  *
00035  * Revision 2.15  2007/02/12 02:44:27  csoutheren
00036  * Start of support for ZRTP
00037  *
00038  * Revision 2.14  2007/02/05 19:43:17  dsandras
00039  * Added additional mutex to prevent temporary deadlock when nothing is
00040  * received on the remote media stream during the establishment phase.
00041  *
00042  * Revision 2.13  2007/01/25 11:48:11  hfriederich
00043  * OpalMediaPatch code refactorization.
00044  * Split into OpalMediaPatch (using a thread) and OpalPassiveMediaPatch
00045  * (not using a thread). Also adds the possibility for source streams
00046  * to push frames down to the sink streams instead of having a patch
00047  * thread around.
00048  *
00049  * Revision 2.12  2006/06/30 01:33:43  csoutheren
00050  * Add function to get patch sink media format
00051  *
00052  * Revision 2.11  2006/02/02 07:02:57  csoutheren
00053  * Added RTP payload map to transcoders and connections to allow remote SIP endpoints
00054  * to change the payload type used for outgoing RTP.
00055  *
00056  * Revision 2.10  2005/11/30 13:35:26  csoutheren
00057  * Changed tags for Doxygen
00058  *
00059  * Revision 2.9  2005/11/07 06:34:52  csoutheren
00060  * Changed PMutex to PTimedMutex
00061  *
00062  * Revision 2.8  2005/09/04 06:23:38  rjongbloed
00063  * Added OpalMediaCommand mechanism (via PNotifier) for media streams
00064  *   and media transcoders to send commands back to remote.
00065  *
00066  * Revision 2.7  2005/08/31 13:19:25  rjongbloed
00067  * Added mechanism for controlling media (especially codecs) including
00068  *   changing the OpalMediaFormat option list (eg bit rate) and a completely
00069  *   new OpalMediaCommand abstraction for things like video fast update.
00070  *
00071  * Revision 2.6  2004/08/15 10:10:27  rjongbloed
00072  * Fixed possible deadlock when closing media patch
00073  *
00074  * Revision 2.5  2004/08/14 07:56:29  rjongbloed
00075  * Major revision to utilise the PSafeCollection classes for the connections and calls.
00076  *
00077  * Revision 2.4  2004/03/11 06:54:27  csoutheren
00078  * Added ability to disable SIP or H.323 stacks
00079  *
00080  * Revision 2.3  2003/03/17 10:26:59  robertj
00081  * Added video support.
00082  *
00083  * Revision 2.2  2002/09/16 02:52:35  robertj
00084  * Added #define so can select if #pragma interface/implementation is used on
00085  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00086  *
00087  * Revision 2.1  2002/01/22 05:07:49  robertj
00088  * Added filter functions to media patch.
00089  *
00090  * Revision 2.0  2001/07/27 15:48:24  robertj
00091  * Conversion of OpenH323 to Open Phone Abstraction Library (OPAL)
00092  *
00093  */
00094 
00095 #ifndef __OPAL_PATCH_H
00096 #define __OPAL_PATCH_H
00097 
00098 #ifdef P_USE_PRAGMA
00099 #pragma interface
00100 #endif
00101 
00102 #include <opal/buildopts.h>
00103 
00104 #include <opal/mediafmt.h>
00105 #include <opal/mediacmd.h>
00106 
00107 
00108 class OpalMediaStream;
00109 class OpalTranscoder;
00110 
00111 
00123 class OpalMediaPatch : public PObject
00124 {
00125     PCLASSINFO(OpalMediaPatch, PObject);
00126   public:
00132     OpalMediaPatch(
00133       OpalMediaStream & source       
00134     );
00135 
00138     ~OpalMediaPatch();
00140 
00147     void PrintOn(
00148       ostream & strm    
00149     ) const;
00151 
00157     virtual void Start();
00158 
00164     virtual void Close();
00165 
00170     BOOL AddSink(
00171       OpalMediaStream * stream,                     
00172       const RTP_DataFrame::PayloadMapType & rtpMap  
00173     );
00174 
00179     void RemoveSink(
00180       OpalMediaStream * stream  
00181     );
00182 
00185     OpalMediaStream & GetSource() const { return source; }
00186 
00189     OpalMediaFormat GetSinkFormat(PINDEX i = 0) const;
00190 
00195     void AddFilter(
00196       const PNotifier & filter,
00197       const OpalMediaFormat & stage = OpalMediaFormat()
00198     );
00199 
00202     BOOL RemoveFilter(
00203       const PNotifier & filter,
00204       const OpalMediaFormat & stage = OpalMediaFormat()
00205     );
00206 
00209     virtual void FilterFrame(
00210       RTP_DataFrame & frame,
00211       const OpalMediaFormat & mediaFormat
00212     );
00213 
00222     virtual BOOL UpdateMediaFormat(
00223       const OpalMediaFormat & mediaFormat,  
00224       BOOL fromSink                         
00225     );
00226 
00234     virtual BOOL ExecuteCommand(
00235       const OpalMediaCommand & command,   
00236       BOOL fromSink                       
00237     );
00238 
00246     virtual void SetCommandNotifier(
00247       const PNotifier & notifier,   
00248       BOOL fromSink                 
00249     );
00250 
00251     virtual BOOL PushFrame(RTP_DataFrame & /*frame*/) { return FALSE; };
00252 
00255     virtual OpalTranscoder * GetAndLockSinkTranscoder(PINDEX i = 0) const;
00256     virtual void UnLockSinkTranscoder() const;
00258 
00259   protected:
00260                 
00262     virtual void Main();
00263     void DispatchFrame(RTP_DataFrame & frame);
00264         
00265     OpalMediaStream & source;
00266 
00267     class Sink : public PObject {
00268         PCLASSINFO(Sink, PObject);
00269       public:
00270         Sink(OpalMediaPatch & p, OpalMediaStream * s, const RTP_DataFrame::PayloadMapType & m);
00271         ~Sink();
00272         bool UpdateMediaFormat(const OpalMediaFormat & mediaFormat);
00273         bool ExecuteCommand(const OpalMediaCommand & command);
00274         void SetCommandNotifier(const PNotifier & notifier);
00275         bool WriteFrame(RTP_DataFrame & sourceFrame);
00276 
00277         OpalMediaPatch  & patch;
00278         OpalMediaStream * stream;
00279         RTP_DataFrame::PayloadMapType payloadTypeMap;
00280         OpalTranscoder  * primaryCodec;
00281         OpalTranscoder  * secondaryCodec;
00282         RTP_DataFrameList intermediateFrames;
00283         RTP_DataFrameList finalFrames;
00284         bool              writeSuccessful;
00285     };
00286     PList<Sink> sinks;
00287 
00288     class Filter : public PObject {
00289         PCLASSINFO(Filter, PObject);
00290       public:
00291         Filter(const PNotifier & n, const OpalMediaFormat & s) : notifier(n), stage(s) { }
00292         PNotifier notifier;
00293         OpalMediaFormat stage;
00294     };
00295     PList<Filter> filters;
00296         
00297     class Thread : public PThread {
00298         PCLASSINFO(Thread, PThread);
00299       public:
00300         Thread(OpalMediaPatch & p);
00301         virtual void Main() { patch.Main(); };
00302         OpalMediaPatch & patch;
00303     };
00304 
00305     Thread * patchThread;
00306     PMutex patchThreadMutex;
00307     mutable PTimedMutex inUse;
00308 };
00309 
00317 class OpalPassiveMediaPatch : public OpalMediaPatch
00318 {
00319     PCLASSINFO(OpalPassiveMediaPatch, OpalMediaPatch);
00320   public:
00321 
00322     OpalPassiveMediaPatch(
00323       OpalMediaStream & source       
00324     );
00325 
00326     virtual void Start();
00327     virtual BOOL PushFrame(RTP_DataFrame & frame);
00328 };
00329 
00330 
00331 #endif // __OPAL_PATCH_H
00332 
00333 
00334 // End of File ///////////////////////////////////////////////////////////////

Generated on Fri Mar 7 06:33:40 2008 for OPAL by  doxygen 1.5.1