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  2005/11/30 13:35:26  csoutheren
00029  * Changed tags for Doxygen
00030  *
00031  * Revision 2.27  2005/09/04 06:23:38  rjongbloed
00032  * Added OpalMediaCommand mechanism (via PNotifier) for media streams
00033  *   and media transcoders to send commands back to remote.
00034  *
00035  * Revision 2.26  2005/08/31 13:19:25  rjongbloed
00036  * Added mechanism for controlling media (especially codecs) including
00037  *   changing the OpalMediaFormat option list (eg bit rate) and a completely
00038  *   new OpalMediaCommand abstraction for things like video fast update.
00039  *
00040  * Revision 2.25  2005/08/20 07:35:22  rjongbloed
00041  * Set video RTP timestamps to value dirived from real time clock.
00042  *
00043  * Revision 2.24  2005/08/04 17:23:38  dsandras
00044  * Added function to determine if a stream is open or not.
00045  *
00046  * Revision 2.23  2005/04/10 20:48:30  dsandras
00047  * Added functions to put an OpalMediaStream on pause.
00048  *
00049  * Revision 2.22  2005/03/12 00:33:27  csoutheren
00050  * Fixed problems with STL compatibility on MSVC 6
00051  * Fixed problems with video streams
00052  * Thanks to Adrian Sietsma
00053  *
00054  * Revision 2.21  2004/12/04 16:35:50  dsandras
00055  * Added a function to get the PChannel back from the OpalMediaStream.
00056  *
00057  * Revision 2.20  2004/10/02 11:50:54  rjongbloed
00058  * Fixed RTP media stream so assures RTP session is open before starting.
00059  *
00060  * Revision 2.19  2004/08/14 07:56:29  rjongbloed
00061  * Major revision to utilise the PSafeCollection classes for the connections and calls.
00062  *
00063  * Revision 2.18  2004/05/17 13:24:18  rjongbloed
00064  * Added silence suppression.
00065  *
00066  * Revision 2.17  2004/03/11 06:54:27  csoutheren
00067  * Added ability to disable SIP or H.323 stacks
00068  *
00069  * Revision 2.16  2003/06/02 02:57:10  rjongbloed
00070  * Moved LID specific media stream class to LID source file.
00071  *
00072  * Revision 2.15  2003/04/16 02:30:21  robertj
00073  * Fixed comments on ReadData() and WriteData() functions.
00074  *
00075  * Revision 2.14  2003/03/17 10:26:59  robertj
00076  * Added video support.
00077  *
00078  * Revision 2.13  2002/11/10 11:33:17  robertj
00079  * Updated to OpenH323 v1.10.3
00080  *
00081  * Revision 2.12  2002/09/16 02:52:35  robertj
00082  * Added #define so can select if #pragma interface/implementation is used on
00083  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00084  *
00085  * Revision 2.11  2002/04/15 08:47:42  robertj
00086  * Fixed problem with mismatched payload type being propagated.
00087  * Fixed correct setting of jitter buffer size in RTP media stream.
00088  *
00089  * Revision 2.10  2002/02/13 02:33:29  robertj
00090  * Added ability for media patch (and transcoders) to handle multiple RTP frames.
00091  * Removed media stream being descended from PChannel, not really useful.
00092  *
00093  * Revision 2.9  2002/02/11 07:39:15  robertj
00094  * Added media bypass for streams between compatible protocols.
00095  *
00096  * Revision 2.8  2002/01/22 05:10:58  robertj
00097  * Removed redundant code
00098  *
00099  * Revision 2.7  2002/01/22 05:09:00  robertj
00100  * Removed payload mismatch detection from RTP media stream.
00101  * Added function to get media patch from media stream.
00102  *
00103  * Revision 2.6  2002/01/14 02:27:32  robertj
00104  * Added ability to turn jitter buffer off in media stream to allow for patches
00105  *   that do not require it.
00106  *
00107  * Revision 2.5  2001/10/15 04:28:35  robertj
00108  * Added delayed start of media patch threads.
00109  *
00110  * Revision 2.4  2001/10/04 05:44:00  craigs
00111  * Changed to start media patch threads in Paused state
00112  *
00113  * Revision 2.3  2001/10/04 00:41:20  robertj
00114  * Removed GetMediaFormats() function as is not useful.
00115  *
00116  * Revision 2.2  2001/08/21 01:10:35  robertj
00117  * Fixed propagation of sound channel buffers through media stream.
00118  *
00119  * Revision 2.1  2001/08/01 05:51:47  robertj
00120  * Made OpalMediaFormatList class global to help with documentation.
00121  *
00122  * Revision 2.0  2001/07/27 15:48:24  robertj
00123  * Conversion of OpenH323 to Open Phone Abstraction Library (OPAL)
00124  *
00125  */
00126 
00127 #ifndef __OPAL_MEDIASTRM_H
00128 #define __OPAL_MEDIASTRM_H
00129 
00130 #ifdef P_USE_PRAGMA
00131 #pragma interface
00132 #endif
00133 
00134 
00135 #include <opal/buildopts.h>
00136 #include <opal/mediafmt.h>
00137 #include <opal/mediacmd.h>
00138 
00139 
00140 class RTP_Session;
00141 class OpalMediaPatch;
00142 class OpalLine;
00143 
00144 
00150 class OpalMediaStream : public PObject
00151 {
00152     PCLASSINFO(OpalMediaStream, PObject);
00153   protected:
00158     OpalMediaStream(
00159       const OpalMediaFormat & mediaFormat, 
00160       unsigned sessionID,                  
00161       BOOL isSource                        
00162     );
00163 
00164   public:
00168     ~OpalMediaStream();
00170 
00171   public:
00178     void PrintOn(
00179       ostream & strm    
00180     ) const;
00182 
00192     virtual OpalMediaFormat GetMediaFormat() const;
00193 
00202     virtual BOOL UpdateMediaFormat(
00203       const OpalMediaFormat & mediaFormat  
00204     );
00205 
00212     virtual BOOL ExecuteCommand(
00213       const OpalMediaCommand & command    
00214     );
00215 
00223     virtual void SetCommandNotifier(
00224       const PNotifier & notifier    
00225     );
00226 
00231     virtual BOOL Open();
00232 
00238     virtual BOOL Start();
00239 
00244     virtual BOOL Close();
00245 
00250     virtual BOOL WritePackets(
00251       RTP_DataFrameList & packets
00252     );
00253 
00259     virtual BOOL ReadPacket(
00260       RTP_DataFrame & packet
00261     );
00262 
00268     virtual BOOL WritePacket(
00269       RTP_DataFrame & packet
00270     );
00271 
00277     virtual BOOL ReadData(
00278       BYTE * data,      
00279       PINDEX size,      
00280       PINDEX & length   
00281     );
00282 
00288     virtual BOOL WriteData(
00289       const BYTE * data,   
00290       PINDEX length,       
00291       PINDEX & written     
00292     );
00293 
00299     virtual BOOL SetDataSize(
00300       PINDEX dataSize  
00301     );
00302 
00306     PINDEX GetDataSize() const { return defaultDataSize; }
00307 
00314     virtual BOOL IsSynchronous() const = 0;
00315 
00319     virtual BOOL RequiresPatchThread() const;
00320 
00325     virtual void EnableJitterBuffer() const;
00327 
00332     BOOL IsSource() const { return isSource; }
00333 
00336     BOOL IsSink() const { return !isSource; }
00337 
00340     unsigned GetSessionID() const { return sessionID; }
00341 
00344     unsigned GetTimestamp() const { return timestamp; }
00345 
00348     void SetTimestamp(unsigned ts) { timestamp = ts; }
00349 
00352     BOOL GetMarker() const { return marker; }
00353 
00356     void SetMarker(BOOL m) { marker = m; }
00357 
00360     BOOL IsPaused() const { return paused; }
00361 
00364     void SetPaused(BOOL p) { paused = p; }
00365 
00368     BOOL IsOpen() { return isOpen; }
00369     
00372     void SetPatch(
00373       OpalMediaPatch * patch  
00374     );
00375 
00378     OpalMediaPatch * GetPatch() const { return patchThread; }
00380 
00381   protected:
00382     OpalMediaFormat mediaFormat;
00383     unsigned        sessionID;
00384     BOOL            paused;
00385     BOOL            isSource;
00386     BOOL            isOpen;
00387     PINDEX          defaultDataSize;
00388     unsigned        timestamp;
00389     BOOL            marker;
00390     unsigned        mismatchedPayloadTypes;
00391 
00392     OpalMediaPatch * patchThread;
00393     PMutex           patchMutex;
00394     PNotifier        commandNotifier;
00395 };
00396 
00397 PLIST(OpalMediaStreamList, OpalMediaStream);
00398 
00399 
00402 class OpalNullMediaStream : public OpalMediaStream
00403 {
00404     PCLASSINFO(OpalNullMediaStream, OpalMediaStream);
00405   public:
00410     OpalNullMediaStream(
00411       const OpalMediaFormat & mediaFormat, 
00412       unsigned sessionID,                  
00413       BOOL isSource                        
00414     );
00416 
00422     virtual BOOL ReadData(
00423       BYTE * data,      
00424       PINDEX size,      
00425       PINDEX & length   
00426     );
00427 
00431     virtual BOOL WriteData(
00432       const BYTE * data,   
00433       PINDEX length,       
00434       PINDEX & written     
00435     );
00436 
00440     virtual BOOL RequiresPatchThread() const;
00441 
00445     virtual BOOL IsSynchronous() const;
00447 };
00448 
00449 
00453 class OpalRTPMediaStream : public OpalMediaStream
00454 {
00455     PCLASSINFO(OpalRTPMediaStream, OpalMediaStream);
00456   public:
00461     OpalRTPMediaStream(
00462       const OpalMediaFormat & mediaFormat, 
00463       BOOL isSource,                       
00464       RTP_Session & rtpSession,    
00465       unsigned minAudioJitterDelay,
00466       unsigned maxAudioJitterDelay 
00467     );
00469 
00476     virtual BOOL Open();
00477 
00482     virtual BOOL Close();
00483 
00487     virtual BOOL ReadPacket(
00488       RTP_DataFrame & packet
00489     );
00490 
00494     virtual BOOL WritePacket(
00495       RTP_DataFrame & packet
00496     );
00497 
00501     virtual BOOL IsSynchronous() const;
00502 
00507     virtual void EnableJitterBuffer() const;
00509 
00510   protected:
00511     RTP_Session & rtpSession;
00512     unsigned      minAudioJitterDelay;
00513     unsigned      maxAudioJitterDelay;
00514 };
00515 
00516 
00517 
00520 class OpalRawMediaStream : public OpalMediaStream
00521 {
00522     PCLASSINFO(OpalRawMediaStream, OpalMediaStream);
00523   protected:
00528     OpalRawMediaStream(
00529       const OpalMediaFormat & mediaFormat, 
00530       unsigned sessionID,                  
00531       BOOL isSource,                       
00532       PChannel * channel,                  
00533       BOOL autoDelete                      
00534     );
00535 
00538     ~OpalRawMediaStream();
00540 
00541   public:
00547     virtual BOOL ReadData(
00548       BYTE * data,      
00549       PINDEX size,      
00550       PINDEX & length   
00551     );
00552 
00556     virtual BOOL WriteData(
00557       const BYTE * data,   
00558       PINDEX length,       
00559       PINDEX & written     
00560     );
00561 
00564     PChannel * GetChannel() { return channel; }
00565     
00566 
00571     virtual BOOL Close();
00573 
00574   protected:
00575     PChannel * channel;
00576     BOOL       autoDelete;
00577 };
00578 
00579 
00580 
00583 class OpalFileMediaStream : public OpalRawMediaStream
00584 {
00585     PCLASSINFO(OpalFileMediaStream, OpalRawMediaStream);
00586   public:
00591     OpalFileMediaStream(
00592       const OpalMediaFormat & mediaFormat, 
00593       unsigned sessionID,                  
00594       BOOL isSource,                       
00595       PFile * file,                        
00596       BOOL autoDelete = TRUE               
00597     );
00598 
00601     OpalFileMediaStream(
00602       const OpalMediaFormat & mediaFormat, 
00603       unsigned sessionID,                  
00604       BOOL isSource,                       
00605       const PFilePath & path               
00606     );
00608 
00614     virtual BOOL IsSynchronous() const;
00616 
00617   protected:
00618     PFile file;
00619 };
00620 
00621 
00625 class OpalAudioMediaStream : public OpalRawMediaStream
00626 {
00627     PCLASSINFO(OpalAudioMediaStream, OpalRawMediaStream);
00628   public:
00633     OpalAudioMediaStream(
00634       const OpalMediaFormat & mediaFormat, 
00635       unsigned sessionID,                  
00636       BOOL isSource,                       
00637       PINDEX buffers,                      
00638       PSoundChannel * channel,             
00639       BOOL autoDelete = TRUE               
00640     );
00641 
00644     OpalAudioMediaStream(
00645       const OpalMediaFormat & mediaFormat, 
00646       unsigned sessionID,                  
00647       BOOL isSource,                       
00648       PINDEX buffers,                      
00649       const PString & deviceName           
00650     );
00652 
00660     virtual BOOL SetDataSize(
00661       PINDEX dataSize  
00662     );
00663 
00667     virtual BOOL IsSynchronous() const;
00669 
00670   protected:
00671     PINDEX soundChannelBuffers;
00672 };
00673 
00674 
00678 class OpalVideoMediaStream : public OpalMediaStream
00679 {
00680     PCLASSINFO(OpalVideoMediaStream, OpalMediaStream);
00681   public:
00686     OpalVideoMediaStream(
00687       const OpalMediaFormat & mediaFormat, 
00688       unsigned sessionID,                  
00689       PVideoInputDevice * inputDevice,     
00690       PVideoOutputDevice * outputDevice,   
00691       BOOL autoDelete = TRUE               
00692     );
00693 
00696     ~OpalVideoMediaStream();
00698 
00706     virtual BOOL Open();
00707 
00713     virtual BOOL ReadData(
00714       BYTE * data,      
00715       PINDEX size,      
00716       PINDEX & length   
00717     );
00718 
00724     virtual BOOL WriteData(
00725       const BYTE * data,   
00726       PINDEX length,       
00727       PINDEX & written     
00728     );
00729 
00733     virtual BOOL IsSynchronous() const;
00734 
00737     virtual BOOL SetDataSize(
00738      PINDEX dataSize  
00739     );
00740 
00742 
00743   protected:
00744     PVideoInputDevice  * inputDevice;
00745     PVideoOutputDevice * outputDevice;
00746     BOOL                 autoDelete;
00747     PTimeInterval        lastGrabTime;
00748 };
00749 
00750 
00751 
00752 #endif //__OPAL_MEDIASTRM_H
00753 
00754 
00755 // End of File ///////////////////////////////////////////////////////////////

Generated on Mon Jan 7 22:31:18 2008 for OPAL by  doxygen 1.4.6