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.1  2006/08/07 20:26:27  dsandras
00029  * Backported fix from HEAD.
00030  *
00031  * Revision 2.28  2005/11/30 13:35:26  csoutheren
00032  * Changed tags for Doxygen
00033  *
00034  * Revision 2.27  2005/09/04 06:23:38  rjongbloed
00035  * Added OpalMediaCommand mechanism (via PNotifier) for media streams
00036  *   and media transcoders to send commands back to remote.
00037  *
00038  * Revision 2.26  2005/08/31 13:19:25  rjongbloed
00039  * Added mechanism for controlling media (especially codecs) including
00040  *   changing the OpalMediaFormat option list (eg bit rate) and a completely
00041  *   new OpalMediaCommand abstraction for things like video fast update.
00042  *
00043  * Revision 2.25  2005/08/20 07:35:22  rjongbloed
00044  * Set video RTP timestamps to value dirived from real time clock.
00045  *
00046  * Revision 2.24  2005/08/04 17:23:38  dsandras
00047  * Added function to determine if a stream is open or not.
00048  *
00049  * Revision 2.23  2005/04/10 20:48:30  dsandras
00050  * Added functions to put an OpalMediaStream on pause.
00051  *
00052  * Revision 2.22  2005/03/12 00:33:27  csoutheren
00053  * Fixed problems with STL compatibility on MSVC 6
00054  * Fixed problems with video streams
00055  * Thanks to Adrian Sietsma
00056  *
00057  * Revision 2.21  2004/12/04 16:35:50  dsandras
00058  * Added a function to get the PChannel back from the OpalMediaStream.
00059  *
00060  * Revision 2.20  2004/10/02 11:50:54  rjongbloed
00061  * Fixed RTP media stream so assures RTP session is open before starting.
00062  *
00063  * Revision 2.19  2004/08/14 07:56:29  rjongbloed
00064  * Major revision to utilise the PSafeCollection classes for the connections and calls.
00065  *
00066  * Revision 2.18  2004/05/17 13:24:18  rjongbloed
00067  * Added silence suppression.
00068  *
00069  * Revision 2.17  2004/03/11 06:54:27  csoutheren
00070  * Added ability to disable SIP or H.323 stacks
00071  *
00072  * Revision 2.16  2003/06/02 02:57:10  rjongbloed
00073  * Moved LID specific media stream class to LID source file.
00074  *
00075  * Revision 2.15  2003/04/16 02:30:21  robertj
00076  * Fixed comments on ReadData() and WriteData() functions.
00077  *
00078  * Revision 2.14  2003/03/17 10:26:59  robertj
00079  * Added video support.
00080  *
00081  * Revision 2.13  2002/11/10 11:33:17  robertj
00082  * Updated to OpenH323 v1.10.3
00083  *
00084  * Revision 2.12  2002/09/16 02:52:35  robertj
00085  * Added #define so can select if #pragma interface/implementation is used on
00086  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00087  *
00088  * Revision 2.11  2002/04/15 08:47:42  robertj
00089  * Fixed problem with mismatched payload type being propagated.
00090  * Fixed correct setting of jitter buffer size in RTP media stream.
00091  *
00092  * Revision 2.10  2002/02/13 02:33:29  robertj
00093  * Added ability for media patch (and transcoders) to handle multiple RTP frames.
00094  * Removed media stream being descended from PChannel, not really useful.
00095  *
00096  * Revision 2.9  2002/02/11 07:39:15  robertj
00097  * Added media bypass for streams between compatible protocols.
00098  *
00099  * Revision 2.8  2002/01/22 05:10:58  robertj
00100  * Removed redundant code
00101  *
00102  * Revision 2.7  2002/01/22 05:09:00  robertj
00103  * Removed payload mismatch detection from RTP media stream.
00104  * Added function to get media patch from media stream.
00105  *
00106  * Revision 2.6  2002/01/14 02:27:32  robertj
00107  * Added ability to turn jitter buffer off in media stream to allow for patches
00108  *   that do not require it.
00109  *
00110  * Revision 2.5  2001/10/15 04:28:35  robertj
00111  * Added delayed start of media patch threads.
00112  *
00113  * Revision 2.4  2001/10/04 05:44:00  craigs
00114  * Changed to start media patch threads in Paused state
00115  *
00116  * Revision 2.3  2001/10/04 00:41:20  robertj
00117  * Removed GetMediaFormats() function as is not useful.
00118  *
00119  * Revision 2.2  2001/08/21 01:10:35  robertj
00120  * Fixed propagation of sound channel buffers through media stream.
00121  *
00122  * Revision 2.1  2001/08/01 05:51:47  robertj
00123  * Made OpalMediaFormatList class global to help with documentation.
00124  *
00125  * Revision 2.0  2001/07/27 15:48:24  robertj
00126  * Conversion of OpenH323 to Open Phone Abstraction Library (OPAL)
00127  *
00128  */
00129 
00130 #ifndef __OPAL_MEDIASTRM_H
00131 #define __OPAL_MEDIASTRM_H
00132 
00133 #ifdef P_USE_PRAGMA
00134 #pragma interface
00135 #endif
00136 
00137 
00138 #include <opal/buildopts.h>
00139 #include <opal/mediafmt.h>
00140 #include <opal/mediacmd.h>
00141 
00142 
00143 class RTP_Session;
00144 class OpalMediaPatch;
00145 class OpalLine;
00146 
00147 
00153 class OpalMediaStream : public PObject
00154 {
00155     PCLASSINFO(OpalMediaStream, PObject);
00156   protected:
00161     OpalMediaStream(
00162       const OpalMediaFormat & mediaFormat, 
00163       unsigned sessionID,                  
00164       BOOL isSource                        
00165     );
00166 
00167   public:
00171     ~OpalMediaStream();
00173 
00174   public:
00181     void PrintOn(
00182       ostream & strm    
00183     ) const;
00185 
00195     virtual OpalMediaFormat GetMediaFormat() const;
00196 
00205     virtual BOOL UpdateMediaFormat(
00206       const OpalMediaFormat & mediaFormat  
00207     );
00208 
00215     virtual BOOL ExecuteCommand(
00216       const OpalMediaCommand & command    
00217     );
00218 
00226     virtual void SetCommandNotifier(
00227       const PNotifier & notifier    
00228     );
00229 
00234     virtual BOOL Open();
00235 
00241     virtual BOOL Start();
00242 
00247     virtual BOOL Close();
00248 
00253     virtual BOOL WritePackets(
00254       RTP_DataFrameList & packets
00255     );
00256 
00262     virtual BOOL ReadPacket(
00263       RTP_DataFrame & packet
00264     );
00265 
00271     virtual BOOL WritePacket(
00272       RTP_DataFrame & packet
00273     );
00274 
00280     virtual BOOL ReadData(
00281       BYTE * data,      
00282       PINDEX size,      
00283       PINDEX & length   
00284     );
00285 
00291     virtual BOOL WriteData(
00292       const BYTE * data,   
00293       PINDEX length,       
00294       PINDEX & written     
00295     );
00296 
00302     virtual BOOL SetDataSize(
00303       PINDEX dataSize  
00304     );
00305 
00309     PINDEX GetDataSize() const { return defaultDataSize; }
00310 
00317     virtual BOOL IsSynchronous() const = 0;
00318 
00322     virtual BOOL RequiresPatchThread() const;
00323 
00328     virtual void EnableJitterBuffer() const;
00330 
00335     BOOL IsSource() const { return isSource; }
00336 
00339     BOOL IsSink() const { return !isSource; }
00340 
00343     unsigned GetSessionID() const { return sessionID; }
00344 
00347     unsigned GetTimestamp() const { return timestamp; }
00348 
00351     void SetTimestamp(unsigned ts) { timestamp = ts; }
00352 
00355     BOOL GetMarker() const { return marker; }
00356 
00359     void SetMarker(BOOL m) { marker = m; }
00360 
00363     BOOL IsPaused() const { return paused; }
00364 
00367     void SetPaused(BOOL p) { paused = p; }
00368 
00371     BOOL IsOpen() { return isOpen; }
00372     
00375     void SetPatch(
00376       OpalMediaPatch * patch  
00377     );
00378 
00381     OpalMediaPatch * GetPatch() const { return patchThread; }
00383 
00386     PMutex &  GetDeleteMutex() const { return deleteMutex; }
00387 
00388   protected:
00389     OpalMediaFormat mediaFormat;
00390     unsigned        sessionID;
00391     BOOL            paused;
00392     BOOL            isSource;
00393     BOOL            isOpen;
00394     PINDEX          defaultDataSize;
00395     unsigned        timestamp;
00396     BOOL            marker;
00397     unsigned        mismatchedPayloadTypes;
00398 
00399     OpalMediaPatch * patchThread;
00400     PMutex           patchMutex;
00401     PNotifier        commandNotifier;
00402 
00403     mutable PMutex  deleteMutex;
00404 };
00405 
00406 PLIST(OpalMediaStreamList, OpalMediaStream);
00407 
00408 
00411 class OpalNullMediaStream : public OpalMediaStream
00412 {
00413     PCLASSINFO(OpalNullMediaStream, OpalMediaStream);
00414   public:
00419     OpalNullMediaStream(
00420       const OpalMediaFormat & mediaFormat, 
00421       unsigned sessionID,                  
00422       BOOL isSource                        
00423     );
00425 
00431     virtual BOOL ReadData(
00432       BYTE * data,      
00433       PINDEX size,      
00434       PINDEX & length   
00435     );
00436 
00440     virtual BOOL WriteData(
00441       const BYTE * data,   
00442       PINDEX length,       
00443       PINDEX & written     
00444     );
00445 
00449     virtual BOOL RequiresPatchThread() const;
00450 
00454     virtual BOOL IsSynchronous() const;
00456 };
00457 
00458 
00462 class OpalRTPMediaStream : public OpalMediaStream
00463 {
00464     PCLASSINFO(OpalRTPMediaStream, OpalMediaStream);
00465   public:
00470     OpalRTPMediaStream(
00471       const OpalMediaFormat & mediaFormat, 
00472       BOOL isSource,                       
00473       RTP_Session & rtpSession,    
00474       unsigned minAudioJitterDelay,
00475       unsigned maxAudioJitterDelay 
00476     );
00478 
00485     virtual BOOL Open();
00486 
00491     virtual BOOL Close();
00492 
00496     virtual BOOL ReadPacket(
00497       RTP_DataFrame & packet
00498     );
00499 
00503     virtual BOOL WritePacket(
00504       RTP_DataFrame & packet
00505     );
00506 
00510     virtual BOOL IsSynchronous() const;
00511 
00516     virtual void EnableJitterBuffer() const;
00518 
00519   protected:
00520     RTP_Session & rtpSession;
00521     unsigned      minAudioJitterDelay;
00522     unsigned      maxAudioJitterDelay;
00523 };
00524 
00525 
00526 
00529 class OpalRawMediaStream : public OpalMediaStream
00530 {
00531     PCLASSINFO(OpalRawMediaStream, OpalMediaStream);
00532   protected:
00537     OpalRawMediaStream(
00538       const OpalMediaFormat & mediaFormat, 
00539       unsigned sessionID,                  
00540       BOOL isSource,                       
00541       PChannel * channel,                  
00542       BOOL autoDelete                      
00543     );
00544 
00547     ~OpalRawMediaStream();
00549 
00550   public:
00556     virtual BOOL ReadData(
00557       BYTE * data,      
00558       PINDEX size,      
00559       PINDEX & length   
00560     );
00561 
00565     virtual BOOL WriteData(
00566       const BYTE * data,   
00567       PINDEX length,       
00568       PINDEX & written     
00569     );
00570 
00573     PChannel * GetChannel() { return channel; }
00574     
00575 
00580     virtual BOOL Close();
00582 
00583   protected:
00584     PChannel * channel;
00585     BOOL       autoDelete;
00586 };
00587 
00588 
00589 
00592 class OpalFileMediaStream : public OpalRawMediaStream
00593 {
00594     PCLASSINFO(OpalFileMediaStream, OpalRawMediaStream);
00595   public:
00600     OpalFileMediaStream(
00601       const OpalMediaFormat & mediaFormat, 
00602       unsigned sessionID,                  
00603       BOOL isSource,                       
00604       PFile * file,                        
00605       BOOL autoDelete = TRUE               
00606     );
00607 
00610     OpalFileMediaStream(
00611       const OpalMediaFormat & mediaFormat, 
00612       unsigned sessionID,                  
00613       BOOL isSource,                       
00614       const PFilePath & path               
00615     );
00617 
00623     virtual BOOL IsSynchronous() const;
00625 
00626   protected:
00627     PFile file;
00628 };
00629 
00630 
00634 class OpalAudioMediaStream : public OpalRawMediaStream
00635 {
00636     PCLASSINFO(OpalAudioMediaStream, OpalRawMediaStream);
00637   public:
00642     OpalAudioMediaStream(
00643       const OpalMediaFormat & mediaFormat, 
00644       unsigned sessionID,                  
00645       BOOL isSource,                       
00646       PINDEX buffers,                      
00647       PSoundChannel * channel,             
00648       BOOL autoDelete = TRUE               
00649     );
00650 
00653     OpalAudioMediaStream(
00654       const OpalMediaFormat & mediaFormat, 
00655       unsigned sessionID,                  
00656       BOOL isSource,                       
00657       PINDEX buffers,                      
00658       const PString & deviceName           
00659     );
00661 
00669     virtual BOOL SetDataSize(
00670       PINDEX dataSize  
00671     );
00672 
00676     virtual BOOL IsSynchronous() const;
00678 
00679   protected:
00680     PINDEX soundChannelBuffers;
00681 };
00682 
00683 
00687 class OpalVideoMediaStream : public OpalMediaStream
00688 {
00689     PCLASSINFO(OpalVideoMediaStream, OpalMediaStream);
00690   public:
00695     OpalVideoMediaStream(
00696       const OpalMediaFormat & mediaFormat, 
00697       unsigned sessionID,                  
00698       PVideoInputDevice * inputDevice,     
00699       PVideoOutputDevice * outputDevice,   
00700       BOOL autoDelete = TRUE               
00701     );
00702 
00705     ~OpalVideoMediaStream();
00707 
00715     virtual BOOL Open();
00716 
00722     virtual BOOL ReadData(
00723       BYTE * data,      
00724       PINDEX size,      
00725       PINDEX & length   
00726     );
00727 
00733     virtual BOOL WriteData(
00734       const BYTE * data,   
00735       PINDEX length,       
00736       PINDEX & written     
00737     );
00738 
00742     virtual BOOL IsSynchronous() const;
00743 
00746     virtual BOOL SetDataSize(
00747      PINDEX dataSize  
00748     );
00749 
00751 
00752   protected:
00753     PVideoInputDevice  * inputDevice;
00754     PVideoOutputDevice * outputDevice;
00755     BOOL                 autoDelete;
00756     PTimeInterval        lastGrabTime;
00757 };
00758 
00759 
00760 
00761 #endif //__OPAL_MEDIASTRM_H
00762 
00763 
00764 // End of File ///////////////////////////////////////////////////////////////

Generated on Mon Sep 25 16:20:09 2006 for OPAL by  doxygen 1.4.7