OPAL  Version 3.10.4
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: 26730 $
00028  * $Author: rjongbloed $
00029  * $Date: 2011-12-02 01:12:02 -0600 (Fri, 02 Dec 2011) $
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 #include <codec/ratectl.h>
00044 
00045 #include <list>
00046 
00047 class OpalTranscoder;
00048 
00060 class OpalMediaPatch : public PObject
00061 {
00062     PCLASSINFO(OpalMediaPatch, PObject);
00063   public:
00069     OpalMediaPatch(
00070       OpalMediaStream & source       
00071     );
00072 
00075     ~OpalMediaPatch();
00077 
00084     void PrintOn(
00085       ostream & strm    
00086     ) const;
00088 
00094     virtual void Start();
00095 
00104     virtual bool OnStartMediaPatch();
00105 
00111     virtual void Close();
00112 
00117     PBoolean AddSink(
00118       const OpalMediaStreamPtr & stream            
00119     );
00120 
00125     void RemoveSink(
00126       const OpalMediaStreamPtr & stream  
00127     );
00128 
00131     OpalMediaStream & GetSource() const { return source; }
00132 
00135     OpalMediaStreamPtr GetSink(PINDEX i = 0) const;
00136 
00139     OpalMediaFormat GetSinkFormat(PINDEX i = 0) const;
00140 
00145     void AddFilter(
00146       const PNotifier & filter,   
00147       const OpalMediaFormat & stage = OpalMediaFormat() 
00148     );
00149 
00152     bool RemoveFilter(
00153       const PNotifier & filter,   
00154       const OpalMediaFormat & stage = OpalMediaFormat() 
00155     );
00156 
00159     virtual void FilterFrame(
00160       RTP_DataFrame & frame,
00161       const OpalMediaFormat & mediaFormat
00162     );
00163 
00173     virtual bool UpdateMediaFormat(
00174       const OpalMediaFormat & mediaFormat  
00175     );
00176 
00186     virtual PBoolean ExecuteCommand(
00187       const OpalMediaCommand & command,   
00188       PBoolean fromSink                       
00189     );
00190 
00193     virtual bool SetPaused(
00194       bool pause    
00195     );
00196 
00199     virtual PBoolean PushFrame(
00200       RTP_DataFrame & frame   
00201     );
00202 
00222     bool SetBypassPatch(
00223       OpalMediaPatch * patch
00224     );
00225 
00228     virtual OpalTranscoder * GetAndLockSinkTranscoder(PINDEX i = 0) const;
00229     virtual void UnLockSinkTranscoder() const;
00230 
00231 #if OPAL_STATISTICS
00232     virtual void GetStatistics(OpalMediaStatistics & statistics, bool fromSink) const;
00233 #endif
00234 
00235 
00236     PDECLARE_NOTIFIER(OpalMediaCommand, OpalMediaPatch, OnMediaCommand);
00237 
00238   protected:
00239                 
00241     virtual void Main();
00242     bool DispatchFrame(RTP_DataFrame & frame);
00243     bool EnableJitterBuffer();
00244 
00245     OpalMediaStream & source;
00246 
00247     class Sink : public PObject {
00248         PCLASSINFO(Sink, PObject);
00249       public:
00250         Sink(OpalMediaPatch & p, const OpalMediaStreamPtr & s);
00251         ~Sink();
00252         bool UpdateMediaFormat(const OpalMediaFormat & mediaFormat);
00253         bool ExecuteCommand(const OpalMediaCommand & command);
00254         bool WriteFrame(RTP_DataFrame & sourceFrame);
00255 #if OPAL_STATISTICS
00256         void GetStatistics(OpalMediaStatistics & statistics, bool fromSource) const;
00257 #endif
00258 
00259         OpalMediaPatch  &  patch;
00260         OpalMediaStreamPtr stream;
00261         OpalTranscoder   * primaryCodec;
00262         OpalTranscoder   * secondaryCodec;
00263         RTP_DataFrameList  intermediateFrames;
00264         RTP_DataFrameList  finalFrames;
00265         bool               writeSuccessful;
00266 
00267         RTP_DataFrame::PayloadTypes m_lastPayloadType;
00268         unsigned                    m_consecutivePayloadTypeMismatches;
00269         bool CannotTranscodeFrame(OpalTranscoder & codec, RTP_DataFrame & frame);
00270 
00271 #if OPAL_VIDEO
00272         void SetRateControlParameters(const OpalMediaFormat & mediaFormat);
00273         bool RateControlExceeded(bool & forceIFrame);
00274         OpalVideoRateController * rateController;
00275 #endif
00276     };
00277     PList<Sink> sinks;
00278 
00279     class Filter : public PObject {
00280         PCLASSINFO(Filter, PObject);
00281       public:
00282         Filter(const PNotifier & n, const OpalMediaFormat & s) : notifier(n), stage(s) { }
00283         PNotifier notifier;
00284         OpalMediaFormat stage;
00285     };
00286     PList<Filter> filters;
00287 
00288     OpalMediaPatch * m_bypassToPatch;
00289     OpalMediaPatch * m_bypassFromPatch;
00290     PSyncPoint       m_bypassEnded;
00291 
00292     class Thread : public PThread {
00293         PCLASSINFO(Thread, PThread);
00294       public:
00295         Thread(OpalMediaPatch & p);
00296         virtual void Main() { patch.Main(); };
00297         OpalMediaPatch & patch;
00298     };
00299 
00300     Thread * patchThread;
00301     PMutex patchThreadMutex;
00302     mutable PReadWriteMutex inUse;
00303 
00304   private:
00305     P_REMOVE_VIRTUAL(bool, OnPatchStart(), false);
00306 };
00307 
00315 class OpalPassiveMediaPatch : public OpalMediaPatch
00316 {
00317     PCLASSINFO(OpalPassiveMediaPatch, OpalMediaPatch);
00318   public:
00319 
00320     OpalPassiveMediaPatch(
00321       OpalMediaStream & source       
00322     );
00323 
00324     virtual void Start();
00325 };
00326 
00327 
00328 #endif // OPAL_OPAL_PATCH_H
00329 
00330 
00331 // End of File ///////////////////////////////////////////////////////////////