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.48  2007/09/26 03:45:38  rjongbloed
00029  * Added missing const in member variable access function.
00030  *
00031  * Revision 2.47  2007/09/05 13:23:39  csoutheren
00032  * Applied 1704162 - Opal mediastrm.cxx added IsOpen check to SetPatch
00033  * Thanks to Drazen Dimoti
00034  *
00035  * Revision 2.46  2007/05/16 10:45:17  dsandras
00036  * Added 2 new functions to the API thanks to Matthias Schneider <ma30002000
00037  * yahoo de>. Thanks!
00038  *
00039  * Revision 2.45  2007/05/09 01:39:19  csoutheren
00040  * Remove redundant patch for NULL source streams
00041  *
00042  * Revision 2.44  2007/05/02 04:13:21  csoutheren
00043  * Add delay to OpalFileMediaStream::ReadData and OpalFileMediaStream::WriteData
00044  *
00045  * Revision 2.43  2007/04/26 07:01:01  csoutheren
00046  * Add extra code to deal with getting media formats from connections early enough to do proper
00047  * gatewaying between calls. The SIP and H.323 code need to have the handing of the remote
00048  * and local formats standardized, but this will do for now
00049  *
00050  * Revision 2.42  2007/04/19 06:34:12  csoutheren
00051  * Applied 1703206 - OpalVideoFastUpdatePicture over SIP
00052  * Thanks to Josh Mahonin
00053  *
00054  * Revision 2.41  2007/03/29 05:15:48  csoutheren
00055  * Pass OpalConnection to OpalMediaSream constructor
00056  * Add ID to OpalMediaStreams so that transcoders can match incoming and outgoing codecs
00057  *
00058  * Revision 2.40  2007/01/25 11:48:11  hfriederich
00059  * OpalMediaPatch code refactorization.
00060  * Split into OpalMediaPatch (using a thread) and OpalPassiveMediaPatch
00061  * (not using a thread). Also adds the possibility for source streams
00062  * to push frames down to the sink streams instead of having a patch
00063  * thread around.
00064  *
00065  * Revision 2.39  2006/12/08 05:39:29  csoutheren
00066  * Remove warnings under Windows
00067  *
00068  * Revision 2.38  2006/12/08 05:13:10  csoutheren
00069  * Applied 1603783 - To allow media streams to handle more then one patch
00070  * Thanks to jmatela
00071  *
00072  * Revision 2.37  2006/10/11 01:15:15  csoutheren
00073  * Applied 1552449 - Always use max RTP buffer size
00074  * Thanks to Simon Zwahlen
00075  *
00076  * Revision 2.36  2006/10/10 07:18:18  csoutheren
00077  * Allow compilation with and without various options
00078  *
00079  * Revision 2.35  2006/08/29 08:47:43  rjongbloed
00080  * Added functions to get average audio signal level from audio streams in
00081  *   suitable connection types.
00082  *
00083  * Revision 2.34  2006/08/28 00:06:10  csoutheren
00084  * Applied 1545107 - MediaStream - safe access to patch for adding a filter
00085  * Thanks to Drazen Dimoti
00086  *
00087  * Revision 2.33  2006/08/26 08:19:52  hfriederich
00088  * Add getter method for the RTP Session
00089  *
00090  * Revision 2.32  2006/07/14 05:24:49  csoutheren
00091  * Applied 1509232 - Fix for a bug in OpalMediaPatch::Close method
00092  * Thanks to Borko Jandras
00093  *
00094  * Revision 2.31  2006/07/14 04:22:42  csoutheren
00095  * Applied 1517397 - More Phobos stability fix
00096  * Thanks to Dinis Rosario
00097  *
00098  * Revision 2.30  2006/07/09 10:18:28  csoutheren
00099  * Applied 1517393 - Opal T.38
00100  * Thanks to Drazen Dimoti
00101  *
00102  * Revision 2.29  2006/06/21 04:54:15  csoutheren
00103  * Fixed build with latest PWLib
00104  *
00105  * Revision 2.28  2005/11/30 13:35:26  csoutheren
00106  * Changed tags for Doxygen
00107  *
00108  * Revision 2.27  2005/09/04 06:23:38  rjongbloed
00109  * Added OpalMediaCommand mechanism (via PNotifier) for media streams
00110  *   and media transcoders to send commands back to remote.
00111  *
00112  * Revision 2.26  2005/08/31 13:19:25  rjongbloed
00113  * Added mechanism for controlling media (especially codecs) including
00114  *   changing the OpalMediaFormat option list (eg bit rate) and a completely
00115  *   new OpalMediaCommand abstraction for things like video fast update.
00116  *
00117  * Revision 2.25  2005/08/20 07:35:22  rjongbloed
00118  * Set video RTP timestamps to value dirived from real time clock.
00119  *
00120  * Revision 2.24  2005/08/04 17:23:38  dsandras
00121  * Added function to determine if a stream is open or not.
00122  *
00123  * Revision 2.23  2005/04/10 20:48:30  dsandras
00124  * Added functions to put an OpalMediaStream on pause.
00125  *
00126  * Revision 2.22  2005/03/12 00:33:27  csoutheren
00127  * Fixed problems with STL compatibility on MSVC 6
00128  * Fixed problems with video streams
00129  * Thanks to Adrian Sietsma
00130  *
00131  * Revision 2.21  2004/12/04 16:35:50  dsandras
00132  * Added a function to get the PChannel back from the OpalMediaStream.
00133  *
00134  * Revision 2.20  2004/10/02 11:50:54  rjongbloed
00135  * Fixed RTP media stream so assures RTP session is open before starting.
00136  *
00137  * Revision 2.19  2004/08/14 07:56:29  rjongbloed
00138  * Major revision to utilise the PSafeCollection classes for the connections and calls.
00139  *
00140  * Revision 2.18  2004/05/17 13:24:18  rjongbloed
00141  * Added silence suppression.
00142  *
00143  * Revision 2.17  2004/03/11 06:54:27  csoutheren
00144  * Added ability to disable SIP or H.323 stacks
00145  *
00146  * Revision 2.16  2003/06/02 02:57:10  rjongbloed
00147  * Moved LID specific media stream class to LID source file.
00148  *
00149  * Revision 2.15  2003/04/16 02:30:21  robertj
00150  * Fixed comments on ReadData() and WriteData() functions.
00151  *
00152  * Revision 2.14  2003/03/17 10:26:59  robertj
00153  * Added video support.
00154  *
00155  * Revision 2.13  2002/11/10 11:33:17  robertj
00156  * Updated to OpenH323 v1.10.3
00157  *
00158  * Revision 2.12  2002/09/16 02:52:35  robertj
00159  * Added #define so can select if #pragma interface/implementation is used on
00160  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00161  *
00162  * Revision 2.11  2002/04/15 08:47:42  robertj
00163  * Fixed problem with mismatched payload type being propagated.
00164  * Fixed correct setting of jitter buffer size in RTP media stream.
00165  *
00166  * Revision 2.10  2002/02/13 02:33:29  robertj
00167  * Added ability for media patch (and transcoders) to handle multiple RTP frames.
00168  * Removed media stream being descended from PChannel, not really useful.
00169  *
00170  * Revision 2.9  2002/02/11 07:39:15  robertj
00171  * Added media bypass for streams between compatible protocols.
00172  *
00173  * Revision 2.8  2002/01/22 05:10:58  robertj
00174  * Removed redundant code
00175  *
00176  * Revision 2.7  2002/01/22 05:09:00  robertj
00177  * Removed payload mismatch detection from RTP media stream.
00178  * Added function to get media patch from media stream.
00179  *
00180  * Revision 2.6  2002/01/14 02:27:32  robertj
00181  * Added ability to turn jitter buffer off in media stream to allow for patches
00182  *   that do not require it.
00183  *
00184  * Revision 2.5  2001/10/15 04:28:35  robertj
00185  * Added delayed start of media patch threads.
00186  *
00187  * Revision 2.4  2001/10/04 05:44:00  craigs
00188  * Changed to start media patch threads in Paused state
00189  *
00190  * Revision 2.3  2001/10/04 00:41:20  robertj
00191  * Removed GetMediaFormats() function as is not useful.
00192  *
00193  * Revision 2.2  2001/08/21 01:10:35  robertj
00194  * Fixed propagation of sound channel buffers through media stream.
00195  *
00196  * Revision 2.1  2001/08/01 05:51:47  robertj
00197  * Made OpalMediaFormatList class global to help with documentation.
00198  *
00199  * Revision 2.0  2001/07/27 15:48:24  robertj
00200  * Conversion of OpenH323 to Open Phone Abstraction Library (OPAL)
00201  *
00202  */
00203 
00204 #ifndef __OPAL_MEDIASTRM_H
00205 #define __OPAL_MEDIASTRM_H
00206 
00207 #ifdef P_USE_PRAGMA
00208 #pragma interface
00209 #endif
00210 
00211 #include <ptclib/delaychan.h>
00212 
00213 #include <opal/buildopts.h>
00214 #include <opal/mediafmt.h>
00215 #include <opal/mediacmd.h>
00216 #include <ptclib/guid.h>
00217 
00218 
00219 class RTP_Session;
00220 class OpalMediaPatch;
00221 class OpalLine;
00222 class OpalConnection;
00223 
00224 
00230 class OpalMediaStream : public PObject
00231 {
00232     PCLASSINFO(OpalMediaStream, PObject);
00233   protected:
00238     OpalMediaStream(
00239       OpalConnection & conn,
00240       const OpalMediaFormat & mediaFormat, 
00241       unsigned sessionID,                  
00242       BOOL isSource                        
00243     );
00244 
00245   public:
00249     ~OpalMediaStream();
00251 
00252   public:
00259     void PrintOn(
00260       ostream & strm    
00261     ) const;
00263 
00273     virtual OpalMediaFormat GetMediaFormat() const;
00274 
00283     virtual BOOL UpdateMediaFormat(
00284       const OpalMediaFormat & mediaFormat  
00285     );
00286 
00293     virtual BOOL ExecuteCommand(
00294       const OpalMediaCommand & command    
00295     );
00296 
00304     virtual void SetCommandNotifier(
00305       const PNotifier & notifier    
00306     );
00307 
00312     virtual BOOL Open();
00313 
00319     virtual BOOL Start();
00320 
00325     virtual BOOL Close();
00326         
00330     virtual void OnPatchStart() {};
00331 
00336     virtual BOOL WritePackets(
00337       RTP_DataFrameList & packets
00338     );
00339 
00345     virtual BOOL ReadPacket(
00346       RTP_DataFrame & packet
00347     );
00348 
00354     virtual BOOL WritePacket(
00355       RTP_DataFrame & packet
00356     );
00357 
00363     virtual BOOL ReadData(
00364       BYTE * data,      
00365       PINDEX size,      
00366       PINDEX & length   
00367     );
00368 
00374     virtual BOOL WriteData(
00375       const BYTE * data,   
00376       PINDEX length,       
00377       PINDEX & written     
00378     );
00379 
00382     BOOL PushPacket(
00383       RTP_DataFrame & packet
00384     );
00385 
00391     virtual BOOL SetDataSize(
00392       PINDEX dataSize  
00393     );
00394 
00398     PINDEX GetDataSize() const { return defaultDataSize; }
00399 
00406     virtual BOOL IsSynchronous() const = 0;
00407         
00411     virtual BOOL RequiresPatch() const;
00412 
00416     virtual BOOL RequiresPatchThread() const;
00417 
00422     virtual void EnableJitterBuffer() const;
00424 
00429     BOOL IsSource() const { return isSource; }
00430 
00433     BOOL IsSink() const { return !isSource; }
00434 
00437     unsigned GetSessionID() const { return sessionID; }
00438 
00441     unsigned GetTimestamp() const { return timestamp; }
00442 
00445     void SetTimestamp(unsigned ts) { timestamp = ts; }
00446 
00449     BOOL GetMarker() const { return marker; }
00450 
00453     void SetMarker(BOOL m) { marker = m; }
00454 
00457     BOOL IsPaused() const { return paused; }
00458 
00461     void SetPaused(BOOL p) { paused = p; }
00462 
00465     BOOL IsOpen() { return isOpen; }
00466     
00469     virtual BOOL SetPatch(
00470       OpalMediaPatch * patch  
00471     );
00472 
00479     virtual void RemovePatch(OpalMediaPatch * patch);
00480 
00483     OpalMediaPatch * GetPatch() const { return mediaPatch; }
00484 
00487     void AddFilter(const PNotifier & Filter, const OpalMediaFormat & Stage =  OpalMediaFormat());
00488 
00491     BOOL RemoveFilter(const PNotifier & Filter, const OpalMediaFormat & Stage);
00492 
00494 
00497     PMutex &  GetDeleteMutex() const { return deleteMutex; }
00498 
00502     PString GetID() const
00503     { return id; }
00504 
00505     virtual BOOL IsNull() const
00506     { return FALSE; }
00507 
00508   protected:
00509     OpalMediaFormat mediaFormat;
00510     unsigned        sessionID;
00511     BOOL                  paused;
00512     BOOL            isSource;
00513     BOOL            isOpen;
00514     PINDEX          defaultDataSize;
00515     unsigned        timestamp;
00516     BOOL            marker;
00517     unsigned        mismatchedPayloadTypes;
00518 
00519     OpalMediaPatch * mediaPatch;
00520     PMutex           patchMutex;
00521     PNotifier        commandNotifier;
00522 
00523     mutable PMutex  deleteMutex;
00524 
00525     PString id;   
00526 };
00527 
00528 PLIST(OpalMediaStreamList, OpalMediaStream);
00529 
00530 
00533 class OpalNullMediaStream : public OpalMediaStream
00534 {
00535     PCLASSINFO(OpalNullMediaStream, OpalMediaStream);
00536   public:
00541     OpalNullMediaStream(
00542       OpalConnection & conn,
00543       const OpalMediaFormat & mediaFormat, 
00544       unsigned sessionID,                  
00545       BOOL isSource                        
00546     );
00548 
00554     virtual BOOL ReadData(
00555       BYTE * data,      
00556       PINDEX size,      
00557       PINDEX & length   
00558     );
00559 
00563     virtual BOOL WriteData(
00564       const BYTE * data,   
00565       PINDEX length,       
00566       PINDEX & written     
00567     );
00568         
00572     virtual BOOL RequiresPatch() const;
00573 
00577     virtual BOOL RequiresPatchThread() const;
00578 
00582     virtual BOOL IsSynchronous() const;
00584 
00585 };
00586 
00587 
00591 class OpalRTPMediaStream : public OpalMediaStream
00592 {
00593     PCLASSINFO(OpalRTPMediaStream, OpalMediaStream);
00594   public:
00599     OpalRTPMediaStream(
00600       OpalConnection & conn,
00601       const OpalMediaFormat & mediaFormat, 
00602       BOOL isSource,                       
00603       RTP_Session & rtpSession,    
00604       unsigned minAudioJitterDelay,
00605       unsigned maxAudioJitterDelay 
00606     );
00608 
00615     virtual BOOL Open();
00616 
00621     virtual BOOL Close();
00622 
00626     virtual BOOL ReadPacket(
00627       RTP_DataFrame & packet
00628     );
00629 
00633     virtual BOOL WritePacket(
00634       RTP_DataFrame & packet
00635     );
00636 
00639     virtual BOOL SetDataSize(
00640       PINDEX dataSize  
00641     );
00642 
00646     virtual BOOL IsSynchronous() const;
00647 
00652     virtual void EnableJitterBuffer() const;
00653 
00656     virtual RTP_Session & GetRtpSession() const
00657     { return rtpSession; }
00658 
00659 #if OPAL_VIDEO
00660 
00664     virtual void OnPatchStart();
00665 
00669     PDECLARE_NOTIFIER(OpalMediaCommand, OpalRTPMediaStream, OnMediaCommand);
00670 #endif
00671 
00673 
00674   protected:
00675     RTP_Session & rtpSession;
00676     unsigned      minAudioJitterDelay;
00677     unsigned      maxAudioJitterDelay;
00678 };
00679 
00680 
00681 
00684 class OpalRawMediaStream : public OpalMediaStream
00685 {
00686     PCLASSINFO(OpalRawMediaStream, OpalMediaStream);
00687   protected:
00692     OpalRawMediaStream(
00693       OpalConnection & conn,
00694       const OpalMediaFormat & mediaFormat, 
00695       unsigned sessionID,                  
00696       BOOL isSource,                       
00697       PChannel * channel,                  
00698       BOOL autoDelete                      
00699     );
00700 
00703     ~OpalRawMediaStream();
00705 
00706   public:
00712     virtual BOOL ReadData(
00713       BYTE * data,      
00714       PINDEX size,      
00715       PINDEX & length   
00716     );
00717 
00721     virtual BOOL WriteData(
00722       const BYTE * data,   
00723       PINDEX length,       
00724       PINDEX & written     
00725     );
00726 
00729     PChannel * GetChannel() { return channel; }
00730     
00735     virtual BOOL Close();
00736 
00739     virtual unsigned GetAverageSignalLevel();
00741 
00742   protected:
00743     PChannel * channel;
00744     PMutex     channel_mutex;
00745     BOOL       autoDelete;
00746 
00747     PUInt64    averageSignalSum;
00748     unsigned   averageSignalSamples;
00749     void CollectAverage(const BYTE * buffer, PINDEX size);
00750 };
00751 
00752 
00753 
00756 class OpalFileMediaStream : public OpalRawMediaStream
00757 {
00758     PCLASSINFO(OpalFileMediaStream, OpalRawMediaStream);
00759   public:
00764     OpalFileMediaStream(
00765       OpalConnection &,
00766       const OpalMediaFormat & mediaFormat, 
00767       unsigned sessionID,                  
00768       BOOL isSource,                       
00769       PFile * file,                        
00770       BOOL autoDelete = TRUE               
00771     );
00772 
00775     OpalFileMediaStream(
00776       OpalConnection & ,
00777       const OpalMediaFormat & mediaFormat, 
00778       unsigned sessionID,                  
00779       BOOL isSource,                       
00780       const PFilePath & path               
00781     );
00783 
00789     virtual BOOL IsSynchronous() const;
00791 
00792     virtual BOOL ReadData(
00793       BYTE * data,      
00794       PINDEX size,      
00795       PINDEX & length   
00796     );
00797 
00801     virtual BOOL WriteData(
00802       const BYTE * data,   
00803       PINDEX length,       
00804       PINDEX & written     
00805     );
00806 
00807   protected:
00808     PFile file;
00809     PAdaptiveDelay fileDelay;
00810 };
00811 
00812 #if OPAL_AUDIO
00813 #if P_AUDIO
00814 
00818 class PSoundChannel;
00819 
00820 class OpalAudioMediaStream : public OpalRawMediaStream
00821 {
00822     PCLASSINFO(OpalAudioMediaStream, OpalRawMediaStream);
00823   public:
00828     OpalAudioMediaStream(
00829       OpalConnection & conn,
00830       const OpalMediaFormat & mediaFormat, 
00831       unsigned sessionID,                  
00832       BOOL isSource,                       
00833       PINDEX buffers,                      
00834       PSoundChannel * channel,             
00835       BOOL autoDelete = TRUE               
00836     );
00837 
00840     OpalAudioMediaStream(
00841       OpalConnection & conn,
00842       const OpalMediaFormat & mediaFormat, 
00843       unsigned sessionID,                  
00844       BOOL isSource,                       
00845       PINDEX buffers,                      
00846       const PString & deviceName           
00847     );
00849 
00857     virtual BOOL SetDataSize(
00858       PINDEX dataSize  
00859     );
00860 
00864     virtual BOOL IsSynchronous() const;
00866 
00867   protected:
00868     PINDEX soundChannelBuffers;
00869 };
00870 
00871 #endif
00872 
00873 #endif // OPAL_AUDIO
00874 
00875 #if OPAL_VIDEO
00876 
00880 class PVideoInputDevice;
00881 class PVideoOutputDevice;
00882 
00883 class OpalVideoMediaStream : public OpalMediaStream
00884 {
00885     PCLASSINFO(OpalVideoMediaStream, OpalMediaStream);
00886   public:
00891     OpalVideoMediaStream(
00892       OpalConnection & conn,
00893       const OpalMediaFormat & mediaFormat, 
00894       unsigned sessionID,                  
00895       PVideoInputDevice * inputDevice,     
00896       PVideoOutputDevice * outputDevice,   
00897       BOOL autoDelete = TRUE               
00898     );
00899 
00902     ~OpalVideoMediaStream();
00904 
00912     virtual BOOL Open();
00913 
00919     virtual BOOL ReadData(
00920       BYTE * data,      
00921       PINDEX size,      
00922       PINDEX & length   
00923     );
00924 
00930     virtual BOOL WriteData(
00931       const BYTE * data,   
00932       PINDEX length,       
00933       PINDEX & written     
00934     );
00935 
00939     virtual BOOL IsSynchronous() const;
00940 
00943     virtual BOOL SetDataSize(
00944      PINDEX dataSize  
00945     );
00946 
00949     virtual PVideoInputDevice * GetVideoInputDevice() const {
00950       return inputDevice;
00951     }
00952 
00955     virtual PVideoOutputDevice * GetVideoOutputDevice() const {
00956       return outputDevice;
00957     }
00958 
00960 
00961   protected:
00962     PVideoInputDevice  * inputDevice;
00963     PVideoOutputDevice * outputDevice;
00964     BOOL                 autoDelete;
00965     PTimeInterval        lastGrabTime;
00966 };
00967 
00968 #endif // OPAL_VIDEO
00969 
00970 class OpalTransportUDP;
00971 
00974 class OpalUDPMediaStream : public OpalMediaStream
00975 {
00976     PCLASSINFO(OpalUDPMediaStream, OpalMediaStream);
00977   public:
00982     OpalUDPMediaStream(
00983       OpalConnection & conn,
00984       const OpalMediaFormat & mediaFormat, 
00985       unsigned sessionID,                  
00986       BOOL isSource,                       
00987       OpalTransportUDP & transport         
00988     );
00990 
00993 
00997     virtual BOOL ReadPacket(
00998       RTP_DataFrame & packet
00999     );
01000 
01004     virtual BOOL WritePacket(
01005       RTP_DataFrame & packet
01006     );
01007 
01011     virtual BOOL IsSynchronous() const;
01012 
01016     virtual BOOL Close();
01017 
01019 
01020   private:
01021     OpalTransportUDP & udpTransport;
01022 };
01023 
01024 #endif //__OPAL_MEDIASTRM_H
01025 
01026 
01027 // End of File ///////////////////////////////////////////////////////////////

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