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  * $Log: mediastrm.h,v $
00028  * Revision 2.28.2.3  2007/01/15 22:16:42  dsandras
00029  * Backported patches improving stability from HEAD to Phobos.
00030  *
00031  * Revision 2.28.2.2  2006/12/08 06:27:20  csoutheren
00032  * Fix compilation problem caused by bad patch backports
00033  * Allow compilation with latest PWLib
00034  *
00035  * Revision 2.28.2.1  2006/08/07 20:26:27  dsandras
00036  * Backported fix from HEAD.
00037  *
00038  * Revision 2.28  2005/11/30 13:35:26  csoutheren
00039  * Changed tags for Doxygen
00040  *
00041  * Revision 2.27  2005/09/04 06:23:38  rjongbloed
00042  * Added OpalMediaCommand mechanism (via PNotifier) for media streams
00043  *   and media transcoders to send commands back to remote.
00044  *
00045  * Revision 2.26  2005/08/31 13:19:25  rjongbloed
00046  * Added mechanism for controlling media (especially codecs) including
00047  *   changing the OpalMediaFormat option list (eg bit rate) and a completely
00048  *   new OpalMediaCommand abstraction for things like video fast update.
00049  *
00050  * Revision 2.25  2005/08/20 07:35:22  rjongbloed
00051  * Set video RTP timestamps to value dirived from real time clock.
00052  *
00053  * Revision 2.24  2005/08/04 17:23:38  dsandras
00054  * Added function to determine if a stream is open or not.
00055  *
00056  * Revision 2.23  2005/04/10 20:48:30  dsandras
00057  * Added functions to put an OpalMediaStream on pause.
00058  *
00059  * Revision 2.22  2005/03/12 00:33:27  csoutheren
00060  * Fixed problems with STL compatibility on MSVC 6
00061  * Fixed problems with video streams
00062  * Thanks to Adrian Sietsma
00063  *
00064  * Revision 2.21  2004/12/04 16:35:50  dsandras
00065  * Added a function to get the PChannel back from the OpalMediaStream.
00066  *
00067  * Revision 2.20  2004/10/02 11:50:54  rjongbloed
00068  * Fixed RTP media stream so assures RTP session is open before starting.
00069  *
00070  * Revision 2.19  2004/08/14 07:56:29  rjongbloed
00071  * Major revision to utilise the PSafeCollection classes for the connections and calls.
00072  *
00073  * Revision 2.18  2004/05/17 13:24:18  rjongbloed
00074  * Added silence suppression.
00075  *
00076  * Revision 2.17  2004/03/11 06:54:27  csoutheren
00077  * Added ability to disable SIP or H.323 stacks
00078  *
00079  * Revision 2.16  2003/06/02 02:57:10  rjongbloed
00080  * Moved LID specific media stream class to LID source file.
00081  *
00082  * Revision 2.15  2003/04/16 02:30:21  robertj
00083  * Fixed comments on ReadData() and WriteData() functions.
00084  *
00085  * Revision 2.14  2003/03/17 10:26:59  robertj
00086  * Added video support.
00087  *
00088  * Revision 2.13  2002/11/10 11:33:17  robertj
00089  * Updated to OpenH323 v1.10.3
00090  *
00091  * Revision 2.12  2002/09/16 02:52:35  robertj
00092  * Added #define so can select if #pragma interface/implementation is used on
00093  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00094  *
00095  * Revision 2.11  2002/04/15 08:47:42  robertj
00096  * Fixed problem with mismatched payload type being propagated.
00097  * Fixed correct setting of jitter buffer size in RTP media stream.
00098  *
00099  * Revision 2.10  2002/02/13 02:33:29  robertj
00100  * Added ability for media patch (and transcoders) to handle multiple RTP frames.
00101  * Removed media stream being descended from PChannel, not really useful.
00102  *
00103  * Revision 2.9  2002/02/11 07:39:15  robertj
00104  * Added media bypass for streams between compatible protocols.
00105  *
00106  * Revision 2.8  2002/01/22 05:10:58  robertj
00107  * Removed redundant code
00108  *
00109  * Revision 2.7  2002/01/22 05:09:00  robertj
00110  * Removed payload mismatch detection from RTP media stream.
00111  * Added function to get media patch from media stream.
00112  *
00113  * Revision 2.6  2002/01/14 02:27:32  robertj
00114  * Added ability to turn jitter buffer off in media stream to allow for patches
00115  *   that do not require it.
00116  *
00117  * Revision 2.5  2001/10/15 04:28:35  robertj
00118  * Added delayed start of media patch threads.
00119  *
00120  * Revision 2.4  2001/10/04 05:44:00  craigs
00121  * Changed to start media patch threads in Paused state
00122  *
00123  * Revision 2.3  2001/10/04 00:41:20  robertj
00124  * Removed GetMediaFormats() function as is not useful.
00125  *
00126  * Revision 2.2  2001/08/21 01:10:35  robertj
00127  * Fixed propagation of sound channel buffers through media stream.
00128  *
00129  * Revision 2.1  2001/08/01 05:51:47  robertj
00130  * Made OpalMediaFormatList class global to help with documentation.
00131  *
00132  * Revision 2.0  2001/07/27 15:48:24  robertj
00133  * Conversion of OpenH323 to Open Phone Abstraction Library (OPAL)
00134  *
00135  */
00136 
00137 #ifndef __OPAL_MEDIASTRM_H
00138 #define __OPAL_MEDIASTRM_H
00139 
00140 #ifdef P_USE_PRAGMA
00141 #pragma interface
00142 #endif
00143 
00144 
00145 #include <opal/buildopts.h>
00146 #include <opal/mediafmt.h>
00147 #include <opal/mediacmd.h>
00148 
00149 #include <ptlib/sound.h>
00150 #include <ptlib/videoio.h>
00151 
00152 class RTP_Session;
00153 class OpalMediaPatch;
00154 class OpalLine;
00155 
00156 
00162 class OpalMediaStream : public PObject
00163 {
00164     PCLASSINFO(OpalMediaStream, PObject);
00165   protected:
00170     OpalMediaStream(
00171       const OpalMediaFormat & mediaFormat, 
00172       unsigned sessionID,                  
00173       BOOL isSource                        
00174     );
00175 
00176   public:
00180     ~OpalMediaStream();
00182 
00183   public:
00190     void PrintOn(
00191       ostream & strm    
00192     ) const;
00194 
00204     virtual OpalMediaFormat GetMediaFormat() const;
00205 
00214     virtual BOOL UpdateMediaFormat(
00215       const OpalMediaFormat & mediaFormat  
00216     );
00217 
00224     virtual BOOL ExecuteCommand(
00225       const OpalMediaCommand & command    
00226     );
00227 
00235     virtual void SetCommandNotifier(
00236       const PNotifier & notifier    
00237     );
00238 
00243     virtual BOOL Open();
00244 
00250     virtual BOOL Start();
00251 
00256     virtual BOOL Close();
00257 
00262     virtual BOOL WritePackets(
00263       RTP_DataFrameList & packets
00264     );
00265 
00271     virtual BOOL ReadPacket(
00272       RTP_DataFrame & packet
00273     );
00274 
00280     virtual BOOL WritePacket(
00281       RTP_DataFrame & packet
00282     );
00283 
00289     virtual BOOL ReadData(
00290       BYTE * data,      
00291       PINDEX size,      
00292       PINDEX & length   
00293     );
00294 
00300     virtual BOOL WriteData(
00301       const BYTE * data,   
00302       PINDEX length,       
00303       PINDEX & written     
00304     );
00305 
00311     virtual BOOL SetDataSize(
00312       PINDEX dataSize  
00313     );
00314 
00318     PINDEX GetDataSize() const { return defaultDataSize; }
00319 
00326     virtual BOOL IsSynchronous() const = 0;
00327 
00331     virtual BOOL RequiresPatchThread() const;
00332 
00337     virtual void EnableJitterBuffer() const;
00339 
00344     BOOL IsSource() const { return isSource; }
00345 
00348     BOOL IsSink() const { return !isSource; }
00349 
00352     unsigned GetSessionID() const { return sessionID; }
00353 
00356     unsigned GetTimestamp() const { return timestamp; }
00357 
00360     void SetTimestamp(unsigned ts) { timestamp = ts; }
00361 
00364     BOOL GetMarker() const { return marker; }
00365 
00368     void SetMarker(BOOL m) { marker = m; }
00369 
00372     BOOL IsPaused() const { return paused; }
00373 
00376     void SetPaused(BOOL p) { paused = p; }
00377 
00380     BOOL IsOpen() { return isOpen; }
00381     
00384     void SetPatch(
00385       OpalMediaPatch * patch  
00386     );
00387 
00390     OpalMediaPatch * GetPatch() const { return patchThread; }
00392 
00395     void AddFilter(const PNotifier & Filter, const OpalMediaFormat & Stage =  OpalMediaFormat());
00396 
00399     BOOL RemoveFilter(const PNotifier & Filter, const OpalMediaFormat & Stage);
00400 
00403     PMutex &  GetDeleteMutex() const { return deleteMutex; }
00404 
00405   protected:
00406     OpalMediaFormat mediaFormat;
00407     unsigned        sessionID;
00408     BOOL            paused;
00409     BOOL            isSource;
00410     BOOL            isOpen;
00411     PINDEX          defaultDataSize;
00412     unsigned        timestamp;
00413     BOOL            marker;
00414     unsigned        mismatchedPayloadTypes;
00415 
00416     OpalMediaPatch * patchThread;
00417     PMutex           patchMutex;
00418     PNotifier        commandNotifier;
00419 
00420     mutable PMutex  deleteMutex;
00421 };
00422 
00423 PLIST(OpalMediaStreamList, OpalMediaStream);
00424 
00425 
00428 class OpalNullMediaStream : public OpalMediaStream
00429 {
00430     PCLASSINFO(OpalNullMediaStream, OpalMediaStream);
00431   public:
00436     OpalNullMediaStream(
00437       const OpalMediaFormat & mediaFormat, 
00438       unsigned sessionID,                  
00439       BOOL isSource                        
00440     );
00442 
00448     virtual BOOL ReadData(
00449       BYTE * data,      
00450       PINDEX size,      
00451       PINDEX & length   
00452     );
00453 
00457     virtual BOOL WriteData(
00458       const BYTE * data,   
00459       PINDEX length,       
00460       PINDEX & written     
00461     );
00462 
00466     virtual BOOL RequiresPatchThread() const;
00467 
00471     virtual BOOL IsSynchronous() const;
00473 };
00474 
00475 
00479 class OpalRTPMediaStream : public OpalMediaStream
00480 {
00481     PCLASSINFO(OpalRTPMediaStream, OpalMediaStream);
00482   public:
00487     OpalRTPMediaStream(
00488       const OpalMediaFormat & mediaFormat, 
00489       BOOL isSource,                       
00490       RTP_Session & rtpSession,    
00491       unsigned minAudioJitterDelay,
00492       unsigned maxAudioJitterDelay 
00493     );
00495 
00502     virtual BOOL Open();
00503 
00508     virtual BOOL Close();
00509 
00513     virtual BOOL ReadPacket(
00514       RTP_DataFrame & packet
00515     );
00516 
00520     virtual BOOL WritePacket(
00521       RTP_DataFrame & packet
00522     );
00523 
00526     virtual BOOL SetDataSize(
00527       PINDEX dataSize  
00528     );
00529 
00533     virtual BOOL IsSynchronous() const;
00534 
00539     virtual void EnableJitterBuffer() const;
00540 
00543     virtual RTP_Session & GetRtpSession() const
00544     { return rtpSession; }
00545 
00547 
00548   protected:
00549     RTP_Session & rtpSession;
00550     unsigned      minAudioJitterDelay;
00551     unsigned      maxAudioJitterDelay;
00552 };
00553 
00554 
00555 
00558 class OpalRawMediaStream : public OpalMediaStream
00559 {
00560     PCLASSINFO(OpalRawMediaStream, OpalMediaStream);
00561   protected:
00566     OpalRawMediaStream(
00567       const OpalMediaFormat & mediaFormat, 
00568       unsigned sessionID,                  
00569       BOOL isSource,                       
00570       PChannel * channel,                  
00571       BOOL autoDelete                      
00572     );
00573 
00576     ~OpalRawMediaStream();
00578 
00579   public:
00585     virtual BOOL ReadData(
00586       BYTE * data,      
00587       PINDEX size,      
00588       PINDEX & length   
00589     );
00590 
00594     virtual BOOL WriteData(
00595       const BYTE * data,   
00596       PINDEX length,       
00597       PINDEX & written     
00598     );
00599 
00602     PChannel * GetChannel() { return channel; }
00603     
00608     virtual BOOL Close();
00609 
00612     virtual unsigned GetAverageSignalLevel();
00614 
00615   protected:
00616     PChannel * channel;
00617     PMutex     channel_mutex;
00618     BOOL       autoDelete;
00619 
00620     PUInt64    averageSignalSum;
00621     unsigned   averageSignalSamples;
00622     void CollectAverage(const BYTE * buffer, PINDEX size);
00623 };
00624 
00625 
00626 
00629 class OpalFileMediaStream : public OpalRawMediaStream
00630 {
00631     PCLASSINFO(OpalFileMediaStream, OpalRawMediaStream);
00632   public:
00637     OpalFileMediaStream(
00638       const OpalMediaFormat & mediaFormat, 
00639       unsigned sessionID,                  
00640       BOOL isSource,                       
00641       PFile * file,                        
00642       BOOL autoDelete = TRUE               
00643     );
00644 
00647     OpalFileMediaStream(
00648       const OpalMediaFormat & mediaFormat, 
00649       unsigned sessionID,                  
00650       BOOL isSource,                       
00651       const PFilePath & path               
00652     );
00654 
00660     virtual BOOL IsSynchronous() const;
00662 
00663   protected:
00664     PFile file;
00665 };
00666 
00667 class OpalMediaFormat;
00668 class PSoundChannel;
00669 
00673 class OpalAudioMediaStream : public OpalRawMediaStream
00674 {
00675     PCLASSINFO(OpalAudioMediaStream, OpalRawMediaStream);
00676   public:
00681     OpalAudioMediaStream(
00682       const OpalMediaFormat & mediaFormat, 
00683       unsigned sessionID,                  
00684       BOOL isSource,                       
00685       PINDEX buffers,                      
00686       PSoundChannel * channel,             
00687       BOOL autoDelete = TRUE               
00688     );
00689 
00692     OpalAudioMediaStream(
00693       const OpalMediaFormat & mediaFormat, 
00694       unsigned sessionID,                  
00695       BOOL isSource,                       
00696       PINDEX buffers,                      
00697       const PString & deviceName           
00698     );
00700 
00708     virtual BOOL SetDataSize(
00709       PINDEX dataSize  
00710     );
00711 
00715     virtual BOOL IsSynchronous() const;
00717 
00718   protected:
00719     PINDEX soundChannelBuffers;
00720 };
00721 
00722 
00726 class OpalVideoMediaStream : public OpalMediaStream
00727 {
00728     PCLASSINFO(OpalVideoMediaStream, OpalMediaStream);
00729   public:
00734     OpalVideoMediaStream(
00735       const OpalMediaFormat & mediaFormat, 
00736       unsigned sessionID,                  
00737       PVideoInputDevice * inputDevice,     
00738       PVideoOutputDevice * outputDevice,   
00739       BOOL autoDelete = TRUE               
00740     );
00741 
00744     ~OpalVideoMediaStream();
00746 
00754     virtual BOOL Open();
00755 
00761     virtual BOOL ReadData(
00762       BYTE * data,      
00763       PINDEX size,      
00764       PINDEX & length   
00765     );
00766 
00772     virtual BOOL WriteData(
00773       const BYTE * data,   
00774       PINDEX length,       
00775       PINDEX & written     
00776     );
00777 
00781     virtual BOOL IsSynchronous() const;
00782 
00785     virtual BOOL SetDataSize(
00786      PINDEX dataSize  
00787     );
00788 
00790 
00791   protected:
00792     PVideoInputDevice  * inputDevice;
00793     PVideoOutputDevice * outputDevice;
00794     BOOL                 autoDelete;
00795     PTimeInterval        lastGrabTime;
00796 };
00797 
00798 
00799 
00800 #endif //__OPAL_MEDIASTRM_H
00801 
00802 
00803 // End of File ///////////////////////////////////////////////////////////////

Generated on Fri Jan 25 01:20:17 2008 for OPAL by  doxygen 1.5.4