transcoders.h

Go to the documentation of this file.
00001 /*
00002  * transcoders.h
00003  *
00004  * Abstractions for converting media from one format to another.
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: transcoders.h,v $
00028  * Revision 2.21.2.1  2006/02/06 04:38:37  csoutheren
00029  * Backported RTP payload mapping fixes from CVS head
00030  *
00031  * Revision 2.22  2006/02/02 07:02:57  csoutheren
00032  * Added RTP payload map to transcoders and connections to allow remote SIP endpoints
00033  * to change the payload type used for outgoing RTP.
00034  *
00035  * Revision 2.21  2005/12/30 14:33:12  dsandras
00036  * Added support for Packet Loss Concealment frames for framed codecs supporting it similarly to what was done for OpenH323.
00037  *
00038  * Revision 2.20  2005/11/30 13:35:26  csoutheren
00039  * Changed tags for Doxygen
00040  *
00041  * Revision 2.19  2005/09/06 12:44:49  rjongbloed
00042  * Many fixes to finalise the video processing: merging remote media
00043  *
00044  * Revision 2.18  2005/09/04 06:23:38  rjongbloed
00045  * Added OpalMediaCommand mechanism (via PNotifier) for media streams
00046  *   and media transcoders to send commands back to remote.
00047  *
00048  * Revision 2.17  2005/09/02 14:31:40  csoutheren
00049  * Use inline function to work around compiler foo in gcc
00050  *
00051  * Revision 2.16  2005/08/31 13:19:25  rjongbloed
00052  * Added mechanism for controlling media (especially codecs) including
00053  *   changing the OpalMediaFormat option list (eg bit rate) and a completely
00054  *   new OpalMediaCommand abstraction for things like video fast update.
00055  *
00056  * Revision 2.15  2005/08/28 07:59:17  rjongbloed
00057  * Converted OpalTranscoder to use factory, requiring sme changes in making sure
00058  *   OpalMediaFormat instances are initialised before use.
00059  *
00060  * Revision 2.14  2005/03/19 04:08:10  csoutheren
00061  * Fixed warnings with gcc snapshot 4.1-20050313
00062  * Updated to configure 2.59
00063  *
00064  * Revision 2.13  2005/02/17 03:25:05  csoutheren
00065  * Added support for audio codecs that consume and produce variable size
00066  * frames, such as G.723.1
00067  *
00068  * Revision 2.12  2004/07/11 12:34:48  rjongbloed
00069  * Added function to get a list of all possible media formats that may be used given
00070  *   a list of media and taking into account all of the registered transcoders.
00071  *
00072  * Revision 2.11  2004/03/22 11:32:41  rjongbloed
00073  * Added new codec type for 16 bit Linear PCM as must distinguish between the internal
00074  *   format used by such things as the sound card and the RTP payload format which
00075  *   is always big endian.
00076  *
00077  * Revision 2.10  2004/03/11 06:54:27  csoutheren
00078  * Added ability to disable SIP or H.323 stacks
00079  *
00080  * Revision 2.9  2004/02/17 08:47:38  csoutheren
00081  * Changed codec loading macros to work with Linux
00082  *
00083  * Revision 2.8  2004/01/18 15:35:20  rjongbloed
00084  * More work on video support
00085  *
00086  * Revision 2.7  2003/06/02 02:59:43  rjongbloed
00087  * Changed transcoder search so uses destination list as preference order.
00088  *
00089  * Revision 2.6  2003/03/24 04:32:11  robertj
00090  * Fixed macro for transcoder with parameter (not used yet!)
00091  * Fixed so OPAL_NO_PARAM can be defined in other modules.
00092  *
00093  * Revision 2.5  2003/03/17 10:26:59  robertj
00094  * Added video support.
00095  *
00096  * Revision 2.4  2002/09/16 02:52:35  robertj
00097  * Added #define so can select if #pragma interface/implementation is used on
00098  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00099  *
00100  * Revision 2.3  2002/02/13 02:30:21  robertj
00101  * Added ability for media patch (and transcoders) to handle multiple RTP frames.
00102  *
00103  * Revision 2.2  2002/01/22 05:07:02  robertj
00104  * Added ability to get input and output media format names from transcoder.
00105  *
00106  * Revision 2.1  2001/08/01 05:52:08  robertj
00107  * Made OpalMediaFormatList class global to help with documentation.
00108  * Added functions to aid in determining if a transcoder can be used to get
00109  *   to another media format.
00110  * Fixed problem with streamed transcoder used in G.711.
00111  *
00112  * Revision 2.0  2001/07/27 15:48:24  robertj
00113  * Conversion of OpenH323 to Open Phone Abstraction Library (OPAL)
00114  *
00115  */
00116 
00117 #ifndef __OPAL_TRANSCODERS_H
00118 #define __OPAL_TRANSCODERS_H
00119 
00120 #ifdef P_USE_PRAGMA
00121 #pragma interface
00122 #endif
00123 
00124 #include <opal/buildopts.h>
00125 
00126 #include <opal/mediafmt.h>
00127 #include <opal/mediacmd.h>
00128 
00129 #include <rtp/rtp.h>
00130 
00131 class RTP_DataFrame;
00132 class OpalTranscoder;
00133 
00134 
00136 
00140 class OpalMediaFormatPair : public PObject
00141 {
00142     PCLASSINFO(OpalMediaFormatPair, PObject);
00143   public:
00148     OpalMediaFormatPair(
00149       const OpalMediaFormat & inputMediaFormat,  
00150       const OpalMediaFormat & outputMediaFormat  
00151     );
00153 
00160     void PrintOn(
00161       ostream & strm    
00162     ) const;
00163 
00175     virtual Comparison Compare(
00176       const PObject & obj   
00177     ) const;
00179 
00184     const OpalMediaFormat & GetInputFormat() const { return inputMediaFormat; }
00185 
00188     const OpalMediaFormat & GetOutputFormat() const { return outputMediaFormat; }
00190 
00191   protected:
00192     OpalMediaFormat inputMediaFormat;
00193     OpalMediaFormat outputMediaFormat;
00194 };
00195 
00196 
00197 typedef PFactory<OpalTranscoder, OpalMediaFormatPair>                      OpalTranscoderFactory;
00198 typedef PFactory<OpalTranscoder, OpalMediaFormatPair>::KeyList_T           OpalTranscoderList;
00199 typedef PFactory<OpalTranscoder, OpalMediaFormatPair>::KeyList_T::iterator OpalTranscoderIterator;
00200 
00201 inline OpalMediaFormatPair OpalCreateMediaFormatPair(const OpalMediaFormat & from, const OpalMediaFormat & to)
00202 { return OpalMediaFormatPair(from, to); }
00203 
00204 #define OPAL_REGISTER_TRANSCODER(cls, input, output) \
00205   OpalTranscoderFactory::Worker<cls> OpalTranscoder_##cls(OpalCreateMediaFormatPair(input, output))
00206 
00207 
00214 class OpalTranscoder : public OpalMediaFormatPair
00215 {
00216     PCLASSINFO(OpalTranscoder, OpalMediaFormatPair);
00217   public:
00222     OpalTranscoder(
00223       const OpalMediaFormat & inputMediaFormat,  
00224       const OpalMediaFormat & outputMediaFormat  
00225     );
00227 
00238     virtual BOOL UpdateOutputMediaFormat(
00239       const OpalMediaFormat & mediaFormat  
00240     );
00241 
00248     virtual BOOL ExecuteCommand(
00249       const OpalMediaCommand & command    
00250     );
00251 
00258     virtual PINDEX GetOptimalDataFrameSize(
00259       BOOL input      
00260     ) const = 0;
00261 
00272     virtual BOOL ConvertFrames(
00273       const RTP_DataFrame & input,  
00274       RTP_DataFrameList & output    
00275     );
00276 
00283     virtual BOOL Convert(
00284       const RTP_DataFrame & input,  
00285       RTP_DataFrame & output        
00286     ) = 0;
00287 
00292     static OpalTranscoder * Create(
00293       const OpalMediaFormat & srcFormat,  
00294       const OpalMediaFormat & dstFormat   
00295     );
00296 
00308     static BOOL SelectFormats(
00309       unsigned sessionID,               
00310       const OpalMediaFormatList & srcFormats, 
00311       const OpalMediaFormatList & dstFormats, 
00312       OpalMediaFormat & srcFormat,      
00313       OpalMediaFormat & dstFormat       
00314     );
00315 
00324     static BOOL FindIntermediateFormat(
00325       const OpalMediaFormat & srcFormat,    
00326       const OpalMediaFormat & dstFormat,    
00327       OpalMediaFormat & intermediateFormat  
00328     );
00329 
00332     static OpalMediaFormatList GetDestinationFormats(
00333       const OpalMediaFormat & srcFormat    
00334     );
00335 
00338     static OpalMediaFormatList GetSourceFormats(
00339       const OpalMediaFormat & dstFormat    
00340     );
00341 
00344     static OpalMediaFormatList GetPossibleFormats(
00345       const OpalMediaFormatList & formats    
00346     );
00348 
00353     PINDEX GetMaxOutputSize() const { return maxOutputSize; }
00354 
00357     void SetMaxOutputSize(
00358       PINDEX size
00359     ) { maxOutputSize = size; }
00360 
00365     void SetCommandNotifier(
00366       const PNotifier & notifier    
00367     ) { commandNotifier = notifier; }
00368 
00373     const PNotifier & GetCommandNotifier() const { return commandNotifier; }
00375 
00376   protected:
00377     PINDEX    maxOutputSize;
00378     bool      outputMediaFormatUpdated;
00379     PNotifier commandNotifier;
00380     PMutex    updateMutex;
00381 
00382     RTP_DataFrame::PayloadMapType payloadTypeMap;
00383 
00384   public:
00385     void SetRTPPayloadMap(const RTP_DataFrame::PayloadMapType & v)
00386     { payloadTypeMap = v; }
00387 
00388     void AddRTPPayloadMapping(RTP_DataFrame::PayloadTypes from, RTP_DataFrame::PayloadTypes to)
00389     { payloadTypeMap.insert(RTP_DataFrame::PayloadMapType::value_type(from, to)); }
00390 };
00391 
00392 
00400 class OpalFramedTranscoder : public OpalTranscoder
00401 {
00402     PCLASSINFO(OpalFramedTranscoder, OpalTranscoder);
00403   public:
00408     OpalFramedTranscoder(
00409       const OpalMediaFormat & inputMediaFormat,  
00410       const OpalMediaFormat & outputMediaFormat, 
00411       PINDEX inputBytesPerFrame,  
00412       PINDEX outputBytesPerFrame  
00413     );
00415 
00424     virtual PINDEX GetOptimalDataFrameSize(
00425       BOOL input      
00426     ) const;
00427 
00434     virtual BOOL Convert(
00435       const RTP_DataFrame & input,  
00436       RTP_DataFrame & output        
00437     );
00438 
00442     virtual BOOL ConvertFrame(
00443       const BYTE * input,   
00444       BYTE * output         
00445     );
00446     virtual BOOL ConvertFrame(
00447       const BYTE * input,   
00448       PINDEX & consumed,    
00449       BYTE * output,        
00450       PINDEX & created      
00451     );
00452     virtual BOOL ConvertSilentFrame(
00453       BYTE * output         
00454     );
00456 
00457   protected:
00458     PINDEX     inputBytesPerFrame;
00459     PINDEX     outputBytesPerFrame;
00460     //PBYTEArray partialFrame;
00461     //PINDEX     partialBytes;
00462 };
00463 
00464 
00472 class OpalStreamedTranscoder : public OpalTranscoder
00473 {
00474     PCLASSINFO(OpalStreamedTranscoder, OpalTranscoder);
00475   public:
00480     OpalStreamedTranscoder(
00481       const OpalMediaFormat & inputMediaFormat,  
00482       const OpalMediaFormat & outputMediaFormat, 
00483       unsigned inputBits,           
00484       unsigned outputBits,          
00485       PINDEX   optimalSamples       
00486     );
00488 
00497     virtual PINDEX GetOptimalDataFrameSize(
00498       BOOL input      
00499     ) const;
00500 
00507     virtual BOOL Convert(
00508       const RTP_DataFrame & input,  
00509       RTP_DataFrame & output        
00510     );
00511 
00518     virtual int ConvertOne(int sample) const = 0;
00520 
00521   protected:
00522     unsigned inputBitsPerSample;
00523     unsigned outputBitsPerSample;
00524     PINDEX   optimalSamples;
00525 };
00526 
00527 
00529 
00530 class Opal_Linear16Mono_PCM : public OpalStreamedTranscoder {
00531   public:
00532     Opal_Linear16Mono_PCM();
00533     virtual int ConvertOne(int sample) const;
00534 };
00535 
00536 
00538 
00539 class Opal_PCM_Linear16Mono : public OpalStreamedTranscoder {
00540   public:
00541     Opal_PCM_Linear16Mono();
00542     virtual int ConvertOne(int sample) const;
00543 };
00544 
00545 
00547 
00548 #define OPAL_REGISTER_L16_MONO() \
00549   OPAL_REGISTER_TRANSCODER(Opal_Linear16Mono_PCM, OpalL16_MONO_8KHZ, OpalPCM16); \
00550   OPAL_REGISTER_TRANSCODER(Opal_PCM_Linear16Mono, OpalPCM16,         OpalL16_MONO_8KHZ)
00551 
00552 
00553 
00554 #endif // __OPAL_TRANSCODERS_H
00555 
00556 
00557 // End of File ///////////////////////////////////////////////////////////////

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