mediastrm.h

Go to the documentation of this file.
00001 /*
00002  * mediastrm.h
00003  *
00004  * Media Stream classes
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_MEDIASTRM_H
00033 #define __OPAL_MEDIASTRM_H
00034 
00035 #ifdef P_USE_PRAGMA
00036 #pragma interface
00037 #endif
00038 
00039 #include <ptclib/delaychan.h>
00040 
00041 #include <opal/buildopts.h>
00042 #include <opal/mediafmt.h>
00043 #include <opal/mediacmd.h>
00044 #include <ptlib/safecoll.h>
00045 #include <ptclib/guid.h>
00046 
00047 
00048 class RTP_Session;
00049 class OpalMediaPatch;
00050 class OpalLine;
00051 class OpalConnection;
00052 class OpalMediaStatistics;
00053 
00054 
00060 class OpalMediaStream : public PSafeObject
00061 {
00062     PCLASSINFO(OpalMediaStream, PSafeObject);
00063   protected:
00068     OpalMediaStream(
00069       OpalConnection & conn,
00070       const OpalMediaFormat & mediaFormat, 
00071       unsigned sessionID,                  
00072       bool isSource                        
00073     );
00074 
00075   public:
00079     ~OpalMediaStream();
00081 
00082   public:
00089     void PrintOn(
00090       ostream & strm    
00091     ) const;
00093 
00103     virtual OpalMediaFormat GetMediaFormat() const;
00104 
00113     virtual PBoolean UpdateMediaFormat(
00114       const OpalMediaFormat & mediaFormat  
00115     );
00116 
00123     virtual PBoolean ExecuteCommand(
00124       const OpalMediaCommand & command    
00125     );
00126 
00134     virtual void SetCommandNotifier(
00135       const PNotifier & notifier    
00136     );
00137 
00142     virtual PBoolean Open();
00143 
00149     virtual PBoolean Start();
00150 
00155     virtual PBoolean Close();
00156 
00160     virtual void OnPatchStart();
00161 
00165     virtual void OnPatchStop();
00166 
00171     virtual PBoolean WritePackets(
00172       RTP_DataFrameList & packets
00173     );
00174 
00180     virtual PBoolean ReadPacket(
00181       RTP_DataFrame & packet
00182     );
00183 
00189     virtual PBoolean WritePacket(
00190       RTP_DataFrame & packet
00191     );
00192 
00198     virtual PBoolean ReadData(
00199       BYTE * data,      
00200       PINDEX size,      
00201       PINDEX & length   
00202     );
00203 
00209     virtual PBoolean WriteData(
00210       const BYTE * data,   
00211       PINDEX length,       
00212       PINDEX & written     
00213     );
00214 
00217     bool PushPacket(
00218       RTP_DataFrame & packet
00219     );
00220 
00226     virtual PBoolean SetDataSize(
00227       PINDEX dataSize  
00228     );
00229 
00233     PINDEX GetDataSize() const { return defaultDataSize; }
00234 
00241     virtual PBoolean IsSynchronous() const = 0;
00242         
00246     virtual PBoolean RequiresPatchThread() const;
00247 
00252     virtual void EnableJitterBuffer() const;
00254 
00259     OpalConnection & GetConnection() const { return connection; }
00260 
00263     bool IsSource() const { return isSource; }
00264 
00267     bool IsSink() const { return !isSource; }
00268 
00271     unsigned GetSessionID() const { return sessionID; }
00272 
00276     PString GetID() const { return identifier; }
00277 
00280     unsigned GetTimestamp() const { return timestamp; }
00281 
00284     void SetTimestamp(unsigned ts) { timestamp = ts; }
00285 
00288     bool GetMarker() const { return marker; }
00289 
00292     void SetMarker(bool m) { marker = m; }
00293 
00296     bool IsPaused() const { return paused; }
00297 
00300     void SetPaused(bool p) { paused = p; }
00301 
00304     bool IsOpen() { return isOpen; }
00305     
00308     virtual PBoolean SetPatch(
00309       OpalMediaPatch * patch  
00310     );
00311 
00318     virtual void RemovePatch(OpalMediaPatch * patch);
00319 
00322     OpalMediaPatch * GetPatch() const { return mediaPatch; }
00323 
00326     void AddFilter(const PNotifier & Filter, const OpalMediaFormat & Stage =  OpalMediaFormat());
00327 
00330     bool RemoveFilter(const PNotifier & Filter, const OpalMediaFormat & Stage);
00331 
00332 #ifdef OPAL_STATISTICS
00333     virtual void GetStatistics(OpalMediaStatistics & statistics) const;
00334 #endif
00335 
00336 
00337   protected:
00338 
00339     virtual void BitRateLimit (PINDEX byteCount, PBoolean mayDelay);
00340 
00341     OpalConnection & connection;
00342     unsigned         sessionID;
00343     PString          identifier;
00344     OpalMediaFormat  mediaFormat;
00345     bool             paused;
00346     bool             isSource;
00347     bool             isOpen;
00348     PINDEX           defaultDataSize;
00349     unsigned         timestamp;
00350     bool             marker;
00351     unsigned         mismatchedPayloadTypes;
00352 
00353     OpalMediaPatch * mediaPatch;
00354     PNotifier        commandNotifier;
00355 
00356     unsigned targetBitRateKbit;
00357     PINDEX totalLength;
00358     PTimeInterval newTime;
00359 };
00360 
00361 typedef PSafePtr<OpalMediaStream> OpalMediaStreamPtr;
00362 
00363 
00366 class OpalNullMediaStream : public OpalMediaStream
00367 {
00368     PCLASSINFO(OpalNullMediaStream, OpalMediaStream);
00369   public:
00374     OpalNullMediaStream(
00375       OpalConnection & conn,
00376       const OpalMediaFormat & mediaFormat, 
00377       unsigned sessionID,                  
00378       bool isSource                        
00379     );
00381 
00387     virtual PBoolean ReadData(
00388       BYTE * data,      
00389       PINDEX size,      
00390       PINDEX & length   
00391     );
00392 
00396     virtual PBoolean WriteData(
00397       const BYTE * data,   
00398       PINDEX length,       
00399       PINDEX & written     
00400     );
00401         
00405     virtual PBoolean RequiresPatchThread() const;
00406 
00410     virtual PBoolean IsSynchronous() const;
00412 
00413 };
00414 
00415 
00419 class OpalRTPMediaStream : public OpalMediaStream
00420 {
00421     PCLASSINFO(OpalRTPMediaStream, OpalMediaStream);
00422   public:
00427     OpalRTPMediaStream(
00428       OpalConnection & conn,
00429       const OpalMediaFormat & mediaFormat, 
00430       bool isSource,                       
00431       RTP_Session & rtpSession,            
00432       unsigned minAudioJitterDelay,        
00433       unsigned maxAudioJitterDelay         
00434     );
00436 
00443     virtual PBoolean Open();
00444 
00449     virtual PBoolean Close();
00450 
00454     virtual PBoolean ReadPacket(
00455       RTP_DataFrame & packet
00456     );
00457 
00461     virtual PBoolean WritePacket(
00462       RTP_DataFrame & packet
00463     );
00464 
00467     virtual PBoolean SetDataSize(
00468       PINDEX dataSize  
00469     );
00470 
00474     virtual PBoolean IsSynchronous() const;
00475 
00480     virtual void EnableJitterBuffer() const;
00481 
00484     virtual RTP_Session & GetRtpSession() const
00485     { return rtpSession; }
00486 
00487 #ifdef OPAL_STATISTICS
00488     virtual void GetStatistics(OpalMediaStatistics & statistics) const;
00489 #endif
00490 
00491 
00492   protected:
00493     RTP_Session & rtpSession;
00494     unsigned      minAudioJitterDelay;
00495     unsigned      maxAudioJitterDelay;
00496 };
00497 
00498 
00499 
00502 class OpalRawMediaStream : public OpalMediaStream
00503 {
00504     PCLASSINFO(OpalRawMediaStream, OpalMediaStream);
00505   protected:
00510     OpalRawMediaStream(
00511       OpalConnection & conn,
00512       const OpalMediaFormat & mediaFormat, 
00513       unsigned sessionID,                  
00514       bool isSource,                       
00515       PChannel * channel,                  
00516       bool autoDelete                      
00517     );
00518 
00521     ~OpalRawMediaStream();
00523 
00524   public:
00530     virtual PBoolean ReadData(
00531       BYTE * data,      
00532       PINDEX size,      
00533       PINDEX & length   
00534     );
00535 
00539     virtual PBoolean WriteData(
00540       const BYTE * data,   
00541       PINDEX length,       
00542       PINDEX & written     
00543     );
00544 
00547     PChannel * GetChannel() { return channel; }
00548     
00553     virtual PBoolean Close();
00554 
00557     virtual unsigned GetAverageSignalLevel();
00559 
00560   protected:
00561     PChannel * channel;
00562     bool       autoDelete;
00563 
00564     PUInt64    averageSignalSum;
00565     unsigned   averageSignalSamples;
00566     PMutex     averagingMutex;
00567     void CollectAverage(const BYTE * buffer, PINDEX size);
00568 };
00569 
00570 
00571 
00574 class OpalFileMediaStream : public OpalRawMediaStream
00575 {
00576     PCLASSINFO(OpalFileMediaStream, OpalRawMediaStream);
00577   public:
00582     OpalFileMediaStream(
00583       OpalConnection &,
00584       const OpalMediaFormat & mediaFormat, 
00585       unsigned sessionID,                  
00586       bool isSource,                       
00587       PFile * file,                        
00588       bool autoDelete = true               
00589     );
00590 
00593     OpalFileMediaStream(
00594       OpalConnection & ,
00595       const OpalMediaFormat & mediaFormat, 
00596       unsigned sessionID,                  
00597       bool isSource,                       
00598       const PFilePath & path               
00599     );
00601 
00607     virtual PBoolean IsSynchronous() const;
00609 
00610     virtual PBoolean ReadData(
00611       BYTE * data,      
00612       PINDEX size,      
00613       PINDEX & length   
00614     );
00615 
00619     virtual PBoolean WriteData(
00620       const BYTE * data,   
00621       PINDEX length,       
00622       PINDEX & written     
00623     );
00624 
00625   protected:
00626     PFile file;
00627     PAdaptiveDelay fileDelay;
00628 };
00629 
00630 #if OPAL_AUDIO
00631 #if P_AUDIO
00632 
00636 class PSoundChannel;
00637 
00638 class OpalAudioMediaStream : public OpalRawMediaStream
00639 {
00640     PCLASSINFO(OpalAudioMediaStream, OpalRawMediaStream);
00641   public:
00646     OpalAudioMediaStream(
00647       OpalConnection & conn,
00648       const OpalMediaFormat & mediaFormat, 
00649       unsigned sessionID,                  
00650       bool isSource,                       
00651       PINDEX buffers,                      
00652       PSoundChannel * channel,             
00653       bool autoDelete = true               
00654     );
00655 
00658     OpalAudioMediaStream(
00659       OpalConnection & conn,
00660       const OpalMediaFormat & mediaFormat, 
00661       unsigned sessionID,                  
00662       bool isSource,                       
00663       PINDEX buffers,                      
00664       const PString & deviceName           
00665     );
00667 
00675     virtual PBoolean SetDataSize(
00676       PINDEX dataSize  
00677     );
00678 
00682     virtual PBoolean IsSynchronous() const;
00684 
00685   protected:
00686     PINDEX soundChannelBuffers;
00687 };
00688 
00689 #endif
00690 
00691 #endif // OPAL_AUDIO
00692 
00693 #if OPAL_VIDEO
00694 
00698 class PVideoInputDevice;
00699 class PVideoOutputDevice;
00700 
00701 class OpalVideoMediaStream : public OpalMediaStream
00702 {
00703     PCLASSINFO(OpalVideoMediaStream, OpalMediaStream);
00704   public:
00709     OpalVideoMediaStream(
00710       OpalConnection & conn,
00711       const OpalMediaFormat & mediaFormat, 
00712       unsigned sessionID,                  
00713       PVideoInputDevice * inputDevice,     
00714       PVideoOutputDevice * outputDevice,   
00715       bool autoDelete = true               
00716     );
00717 
00720     ~OpalVideoMediaStream();
00722 
00730     virtual PBoolean Open();
00731 
00736     virtual PBoolean Close();
00737 
00743     virtual PBoolean ReadData(
00744       BYTE * data,      
00745       PINDEX size,      
00746       PINDEX & length   
00747     );
00748 
00754     virtual PBoolean WriteData(
00755       const BYTE * data,   
00756       PINDEX length,       
00757       PINDEX & written     
00758     );
00759 
00763     virtual PBoolean IsSynchronous() const;
00764 
00767     virtual PBoolean SetDataSize(
00768      PINDEX dataSize  
00769     );
00770 
00773     virtual PVideoInputDevice * GetVideoInputDevice() const {
00774       return inputDevice;
00775     }
00776 
00779     virtual PVideoOutputDevice * GetVideoOutputDevice() const {
00780       return outputDevice;
00781     }
00782 
00784 
00785   protected:
00786     PVideoInputDevice  * inputDevice;
00787     PVideoOutputDevice * outputDevice;
00788     bool                 autoDelete;
00789     PTimeInterval        lastGrabTime;
00790 };
00791 
00792 #endif // OPAL_VIDEO
00793 
00794 class OpalTransportUDP;
00795 
00798 class OpalUDPMediaStream : public OpalMediaStream
00799 {
00800     PCLASSINFO(OpalUDPMediaStream, OpalMediaStream);
00801   public:
00806     OpalUDPMediaStream(
00807       OpalConnection & conn,
00808       const OpalMediaFormat & mediaFormat, 
00809       unsigned sessionID,                  
00810       bool isSource,                       
00811       OpalTransportUDP & transport         
00812     );
00814 
00817 
00821     virtual PBoolean ReadPacket(
00822       RTP_DataFrame & packet
00823     );
00824 
00828     virtual PBoolean WritePacket(
00829       RTP_DataFrame & packet
00830     );
00831 
00835     virtual PBoolean IsSynchronous() const;
00836 
00840     virtual PBoolean Close();
00841 
00843 
00844   private:
00845     OpalTransportUDP & udpTransport;
00846 };
00847 
00848 #endif //__OPAL_MEDIASTRM_H
00849 
00850 
00851 // End of File ///////////////////////////////////////////////////////////////

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